@uniqbit/mate-core 1.0.0-canary.2 → 1.0.0-canary.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/claude-plugin/hooks/hooks.json +21 -1
- package/claude-plugin/hooks/session-attention.mjs +10 -0
- package/claude-plugin/hooks/session-end.mjs +9 -0
- package/claude-plugin/hooks/session-guidance.mjs +1 -1
- package/opencode-plugin/src/server.ts +13 -2
- package/opencode-plugin/src/tui.tsx +1 -1
- package/opencode-plugin/tui.tsx +2 -1
- package/package.json +1 -1
- package/src/cli/commands/artifact/delivery/archive.ts +2 -2
- package/src/cli/commands/artifact/delivery/link.ts +22 -5
- package/src/cli/commands/artifact/delivery/output.ts +9 -1
- package/src/cli/commands/artifact/finish/openspec.ts +1 -3
- package/src/cli/commands/companion/companion.ts +1 -1
- package/src/cli/commands/companion/link.ts +36 -4
- package/src/cli/commands/companion/open.ts +40 -12
- package/src/cli/commands/doctor.ts +122 -0
- package/src/cli/commands/session/prepare.ts +32 -4
- package/src/cli/commands/session/registry.ts +90 -0
- package/src/cli/commands/studio/companion-removal.ts +79 -0
- package/src/cli/commands/studio/mate-inventory.ts +1 -1
- package/src/cli/commands/studio/payload.ts +12 -1
- package/src/cli/commands/studio/server.ts +39 -16
- package/src/cli/commands/studio/services.ts +20 -0
- package/src/cli/commands/studio/skill-files.ts +133 -0
- package/src/cli/commands/studio/vault.ts +218 -44
- package/src/cli/commands/studio/views/model.ts +0 -5
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +255 -4
- package/src/cli/commands/unwrap.ts +8 -0
- package/src/cli/commands/update.ts +26 -8
- package/src/cli/commands/vscode/setup.ts +155 -0
- package/src/cli/commands/vscode/vsix.ts +73 -0
- package/src/cli/commands/working/cleanup.ts +34 -10
- package/src/cli/commands/working/worktree.ts +58 -8
- package/src/cli/commands/wrap.ts +33 -7
- package/src/cli/main.ts +9 -2
- package/src/cli/usage.ts +6 -1
- package/src/hooks/companion-instructions.ts +19 -11
- package/src/hooks/hook-io.ts +15 -0
- package/src/hooks/session-banner.ts +5 -3
- package/src/hooks/session-end.ts +10 -0
- package/src/hooks/session-guidance.ts +10 -6
- package/src/hooks/session-prepare.ts +47 -31
- package/src/hooks/session-register.ts +199 -0
- package/src/hooks/tokensave-route.ts +7 -3
- package/src/hooks/validate-artifact-path.ts +9 -2
- package/src/lib/delivery/archive-change.ts +0 -1
- package/src/lib/delivery/branches.ts +15 -0
- package/src/lib/delivery/record-delivery.ts +94 -39
- package/src/lib/delivery/record.ts +30 -28
- package/src/lib/delivery/refresh.ts +37 -17
- package/src/lib/delivery/resolve-branch.ts +258 -37
- package/src/lib/factory/outcomes/index.ts +11 -1
- package/src/lib/factory/runtime.ts +10 -1
- package/src/lib/opencode-server.ts +238 -0
- package/src/lib/orchestrator/adapters/claude.ts +147 -2
- package/src/lib/orchestrator/adapters/opencode.ts +53 -2
- package/src/lib/orchestrator/checkout-adoption.ts +125 -0
- package/src/lib/orchestrator/companion-registry-store.ts +6 -2
- package/src/lib/orchestrator/editor.ts +2 -2
- package/src/lib/orchestrator/framework-context.ts +26 -14
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +15 -2
- package/src/lib/orchestrator/projection-claude-links.ts +52 -5
- package/src/lib/orchestrator/projection-claude-skills.ts +28 -2
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/registry-checkouts.ts +177 -0
- package/src/lib/orchestrator/repository-link.ts +216 -57
- package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
- package/src/lib/orchestrator/session-context-link.ts +11 -5
- package/src/lib/orchestrator/session-prepare.ts +36 -6
- package/src/lib/orchestrator/types.ts +5 -0
- package/src/lib/orchestrator/workspace-inventory.ts +5 -1
- package/src/lib/public-npm.ts +17 -0
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +285 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/workset/record.ts +20 -0
- package/src/lib/workset/worktree.ts +85 -17
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +3 -1
- package/src/opencode/companion-policy.ts +2 -2
- package/src/opencode/projected-guidance.ts +2 -1
- package/src/opencode/session-register.ts +176 -0
- package/src/opencode/tui.tsx +19 -29
- package/src/runtime/claude-delivery-plan.ts +14 -3
- package/src/runtime/current-branch.ts +10 -0
- package/src/runtime/env.ts +13 -7
- package/src/runtime/git-layout.ts +164 -17
- package/src/runtime/launch-env-guard.ts +65 -0
- package/src/runtime/opencode-server-record.ts +136 -0
- package/src/runtime/projection.ts +40 -6
- package/src/runtime/repo-local.ts +6 -1
- package/src/runtime/serving-claude-wrap.ts +28 -0
- package/src/runtime/session-context.ts +4 -3
- package/src/runtime/session-registry.ts +434 -0
- package/src/runtime/tokensave-route.ts +10 -5
- package/src/runtime/wrap-state.ts +31 -0
- package/src/studio.ts +2 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +49 -21
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +0 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +2 -8
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +1 -3
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +2 -4
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +49 -21
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +0 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +2 -8
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +1 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +2 -4
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +404 -30
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -3
- package/src/tools/setup/providers/claude-plugin-hooks.ts +26 -0
- package/src/tools/setup/providers/claude.ts +21 -1
- package/studio-dist/client/assets/app-CdPiFv59.css +2 -0
- package/studio-dist/client/assets/button-BIIHE0EQ.js +3 -0
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +1 -0
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +1 -0
- package/studio-dist/client/assets/factory-BZy0E8ty.js +4 -0
- package/studio-dist/client/assets/index-B3wkMzjA.js +40 -0
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +1 -0
- package/studio-dist/client/assets/panel-CbajlC3p.js +1 -0
- package/studio-dist/client/assets/{prepaint-CD5OpmTM.js → prepaint-CwSrpdFA.js} +7 -4
- package/studio-dist/client/assets/react-CN2GSx7x.js +1 -0
- package/studio-dist/client/assets/reports-DllhYQ5_.js +1 -0
- package/studio-dist/client/assets/routes-COm-G3mK.js +1 -0
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +1 -0
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +1 -0
- package/studio-dist/client/assets/steps-DFsH3Neu.js +1 -0
- package/studio-dist/client/assets/vault-B2q1nBY5.js +1 -0
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +1 -0
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +1 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-BQKuMdJW.js → __23tanstack-start-server-fn-resolver-M2GBs8s3.js} +179 -9
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +35 -25
- package/studio-dist/server/assets/button-CIJqAhni.js +11929 -0
- package/studio-dist/server/assets/{companion-view-aBady57v.js → companion-view-DISASvdJ.js} +13 -7
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +15 -0
- package/studio-dist/server/assets/delivery-path-C29fBynY.js +654 -0
- package/studio-dist/server/assets/{factory-DT3UzHlh.js → factory-DGPmNGbo.js} +1 -0
- package/studio-dist/server/assets/{factory-D6xnjedJ.js → factory-DUTa0eDs.js} +317 -530
- package/studio-dist/server/assets/markdown-view-Bn7xPdks.js +86 -0
- package/studio-dist/server/assets/panel-3Jmn4awF.js +169 -0
- package/studio-dist/server/assets/{prepaint-BMke0fo1.js → prepaint-DJfTQ_VH.js} +6 -2
- package/studio-dist/server/assets/{react-COs0LHn-.js → react-Ce6dj15C.js} +4 -9
- package/studio-dist/server/assets/reports-C06RXVE2.js +18 -0
- package/studio-dist/server/assets/reports-D6YMqhnO.js +142 -0
- package/studio-dist/server/assets/router-C8MGqlAY.js +13713 -0
- package/studio-dist/server/assets/routes-BcFgvqf7.js +622 -0
- package/studio-dist/server/assets/{shell-CboT2f66.js → shell-DS3wUexh.js} +1 -0
- package/studio-dist/server/assets/skills-BEnOxiDl.js +266 -0
- package/studio-dist/server/assets/skills-CtrBAtX3.js +28 -0
- package/studio-dist/server/assets/specs-C8rv34-5.js +211 -0
- package/studio-dist/server/assets/{start-BW5ovN0k.js → start-h3ICWwd2.js} +4 -1
- package/studio-dist/server/assets/steps-Dq_CwY_s.js +181 -0
- package/studio-dist/server/assets/{vault-BGulVoNh.js → vault-BmWnryh3.js} +16 -1
- package/studio-dist/server/assets/vault-Fvxt2Tzl.js +1032 -0
- package/studio-dist/server/assets/{views-Bd7cRr27.js → views-BgYa-za2.js} +1 -3
- package/studio-dist/server/assets/warnings-DzR6fyZh.js +23 -0
- package/studio-dist/server/assets/workflow-liRYecHk.js +73 -0
- package/studio-dist/server/server.js +3 -157
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +0 -1
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +0 -1
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +0 -4
- package/studio-dist/client/assets/index-n6uo_92S.js +0 -40
- package/studio-dist/client/assets/queries-CN3JwMBX.js +0 -1
- package/studio-dist/client/assets/react-CabXf2Ds.js +0 -1
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +0 -1
- package/studio-dist/client/assets/reports-C01RsnMA.js +0 -1
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +0 -1
- package/studio-dist/client/assets/skills-CihQganl.js +0 -1
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +0 -1
- package/studio-dist/client/assets/specs-D24_35_K.js +0 -1
- package/studio-dist/client/assets/studio-DKxfi691.css +0 -1
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +0 -3
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +0 -1
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +0 -1
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +0 -1
- package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +0 -778
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +0 -107
- package/studio-dist/server/assets/report-time-DAfzln-N.js +0 -8
- package/studio-dist/server/assets/reports-BnUNJVtx.js +0 -126
- package/studio-dist/server/assets/router-BH--drIx.js +0 -4298
- package/studio-dist/server/assets/routes-khSDK1bV.js +0 -361
- package/studio-dist/server/assets/skills-MWYnWoKs.js +0 -106
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +0 -16
- package/studio-dist/server/assets/specs-DE3w8hZP.js +0 -155
- package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +0 -3365
- package/studio-dist/server/assets/vault-CuyyhLyB.js +0 -832
- package/studio-dist/server/assets/warnings-BH05rOuG.js +0 -15
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +0 -42
|
@@ -1,3365 +0,0 @@
|
|
|
1
|
-
import { i as __toESM } from "./rolldown-runtime-DYf_mQCB.js";
|
|
2
|
-
import { A as require_react, D as trimPathRight, E as trimPathLeft, O as rootRouteId, S as invariant, T as removeTrailingSlash, l as require_jsx_runtime, n as useMatch, s as useRouter, t as getServerFnById, u as reactUse, w as cleanPath } from "./__23tanstack-start-server-fn-resolver-BQKuMdJW.js";
|
|
3
|
-
import { f as TSS_SERVER_FUNCTION, t as createServerFn, y as redirect } from "./createServerFn-F5sAOF8V.js";
|
|
4
|
-
import { a as deepEqual, c as functionalUpdate$1, f as isDangerousProtocol, l as getUrlScheme, p as isModuleNotFoundError } from "./utils-C9CX1kcy.js";
|
|
5
|
-
import { l as COMPANION_DIGEST_PATTERN } from "./studio-BeltxxKt.js";
|
|
6
|
-
import { t as OUTCOME_ACTIONS } from "./actions-Bvgj9eb8.js";
|
|
7
|
-
import { n as validateStudioSearch } from "./search-JAKurDNh.js";
|
|
8
|
-
// ../../node_modules/.bun/@tanstack+router-core@1.171.39/node_modules/@tanstack/router-core/dist/esm/route.js
|
|
9
|
-
var BaseRoute = class {
|
|
10
|
-
get to() {
|
|
11
|
-
return this._to;
|
|
12
|
-
}
|
|
13
|
-
get id() {
|
|
14
|
-
return this._id;
|
|
15
|
-
}
|
|
16
|
-
get path() {
|
|
17
|
-
return this._path;
|
|
18
|
-
}
|
|
19
|
-
get fullPath() {
|
|
20
|
-
return this._fullPath;
|
|
21
|
-
}
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this.init = (originalIndex) => {
|
|
24
|
-
this.originalIndex = originalIndex;
|
|
25
|
-
this._branch = void 0;
|
|
26
|
-
const options = this.options;
|
|
27
|
-
const isRoot = !options?.path && !options?.id;
|
|
28
|
-
this.parentRoute = this.options.getParentRoute?.();
|
|
29
|
-
if (isRoot) this._path = rootRouteId;
|
|
30
|
-
else if (!this.parentRoute) invariant();
|
|
31
|
-
let path = isRoot ? rootRouteId : options?.path;
|
|
32
|
-
if (path && path !== "/") path = trimPathLeft(path);
|
|
33
|
-
const customId = options?.id || path;
|
|
34
|
-
const id = isRoot ? rootRouteId : cleanPath((this.parentRoute.id === "__root__" ? "" : this.parentRoute.id) + "/" + (customId ?? ""));
|
|
35
|
-
if (path === "__root__") path = "/";
|
|
36
|
-
const fullPath = id === "__root__" ? "/" : path === void 0 ? this.parentRoute.fullPath : cleanPath(this.parentRoute.fullPath + "/" + path);
|
|
37
|
-
this._path = path;
|
|
38
|
-
this._id = id;
|
|
39
|
-
this._fullPath = fullPath;
|
|
40
|
-
this._to = trimPathRight(fullPath);
|
|
41
|
-
};
|
|
42
|
-
this.addChildren = (children) => {
|
|
43
|
-
return this._addFileChildren(children);
|
|
44
|
-
};
|
|
45
|
-
this._addFileChildren = (children) => {
|
|
46
|
-
if (Array.isArray(children)) this.children = children;
|
|
47
|
-
if (typeof children === "object" && children !== null) this.children = Object.values(children);
|
|
48
|
-
return this;
|
|
49
|
-
};
|
|
50
|
-
this._addFileTypes = () => {
|
|
51
|
-
return this;
|
|
52
|
-
};
|
|
53
|
-
this.updateLoader = (options) => {
|
|
54
|
-
Object.assign(this.options, options);
|
|
55
|
-
return this;
|
|
56
|
-
};
|
|
57
|
-
this.update = (options) => {
|
|
58
|
-
Object.assign(this.options, options);
|
|
59
|
-
return this;
|
|
60
|
-
};
|
|
61
|
-
this.lazy = (lazyFn) => {
|
|
62
|
-
this.lazyFn = lazyFn;
|
|
63
|
-
return this;
|
|
64
|
-
};
|
|
65
|
-
this.redirect = (opts) => redirect({
|
|
66
|
-
from: this.fullPath,
|
|
67
|
-
...opts
|
|
68
|
-
});
|
|
69
|
-
this.options = options || {};
|
|
70
|
-
this.isRoot = !options?.getParentRoute;
|
|
71
|
-
if (options?.id && options?.path) throw new Error(`Route cannot have both an 'id' and a 'path' option.`);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var BaseRootRoute = class extends BaseRoute {
|
|
75
|
-
constructor(options) {
|
|
76
|
-
super(options);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useLoaderData.js
|
|
80
|
-
/**
|
|
81
|
-
* Read and select the current route's loader data with type‑safety.
|
|
82
|
-
*
|
|
83
|
-
* Options:
|
|
84
|
-
* - `from`/`strict`: Choose which route's data to read and strictness
|
|
85
|
-
* - `select`: Map the loader data to a derived value
|
|
86
|
-
* - `structuralSharing`: Enable structural sharing for stable references
|
|
87
|
-
*
|
|
88
|
-
* @returns The loader data (or selected value) for the matched route.
|
|
89
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDataHook
|
|
90
|
-
*/
|
|
91
|
-
function useLoaderData(opts) {
|
|
92
|
-
return useMatch({
|
|
93
|
-
from: opts.from,
|
|
94
|
-
strict: opts.strict,
|
|
95
|
-
structuralSharing: opts.structuralSharing,
|
|
96
|
-
select: (match) => {
|
|
97
|
-
return opts.select ? opts.select(match.loaderData) : match.loaderData;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useLoaderDeps.js
|
|
102
|
-
/**
|
|
103
|
-
* Read and select the current route's loader dependencies object.
|
|
104
|
-
*
|
|
105
|
-
* Options:
|
|
106
|
-
* - `from`: Choose which route's loader deps to read
|
|
107
|
-
* - `select`: Map the deps to a derived value
|
|
108
|
-
* - `structuralSharing`: Enable structural sharing for stable references
|
|
109
|
-
*
|
|
110
|
-
* @returns The loader deps (or selected value) for the matched route.
|
|
111
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDepsHook
|
|
112
|
-
*/
|
|
113
|
-
function useLoaderDeps(opts) {
|
|
114
|
-
const { select, ...rest } = opts;
|
|
115
|
-
return useMatch({
|
|
116
|
-
...rest,
|
|
117
|
-
select: (match) => {
|
|
118
|
-
return select ? select(match.loaderDeps) : match.loaderDeps;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useParams.js
|
|
123
|
-
/**
|
|
124
|
-
* Access the current route's path parameters with type-safety.
|
|
125
|
-
*
|
|
126
|
-
* Options:
|
|
127
|
-
* - `from`/`strict`: Specify the matched route and whether to enforce strict typing
|
|
128
|
-
* - `select`: Project the params object to a derived value for memoized renders
|
|
129
|
-
* - `structuralSharing`: Enable structural sharing for stable references
|
|
130
|
-
* - `shouldThrow`: Throw if the route is not found in strict contexts
|
|
131
|
-
*
|
|
132
|
-
* @returns The params object (or selected value) for the matched route.
|
|
133
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook
|
|
134
|
-
*/
|
|
135
|
-
function useParams(opts) {
|
|
136
|
-
return useMatch({
|
|
137
|
-
from: opts.from,
|
|
138
|
-
shouldThrow: opts.shouldThrow,
|
|
139
|
-
structuralSharing: opts.structuralSharing,
|
|
140
|
-
strict: opts.strict,
|
|
141
|
-
select: (match) => {
|
|
142
|
-
const params = opts.strict === false ? match.params : match._strictParams;
|
|
143
|
-
return opts.select ? opts.select(params) : params;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useSearch.js
|
|
148
|
-
/**
|
|
149
|
-
* Read and select the current route's search parameters with type-safety.
|
|
150
|
-
*
|
|
151
|
-
* Options:
|
|
152
|
-
* - `from`/`strict`: Control which route's search is read and how strictly it's typed
|
|
153
|
-
* - `select`: Map the search object to a derived value for render optimization
|
|
154
|
-
* - `structuralSharing`: Enable structural sharing for stable references
|
|
155
|
-
* - `shouldThrow`: Throw when the route is not found (strict contexts)
|
|
156
|
-
*
|
|
157
|
-
* @returns The search object (or selected value) for the matched route.
|
|
158
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
|
|
159
|
-
*/
|
|
160
|
-
function useSearch(opts) {
|
|
161
|
-
return useMatch({
|
|
162
|
-
from: opts.from,
|
|
163
|
-
strict: opts.strict,
|
|
164
|
-
shouldThrow: opts.shouldThrow,
|
|
165
|
-
structuralSharing: opts.structuralSharing,
|
|
166
|
-
select: (match) => {
|
|
167
|
-
return opts.select ? opts.select(match.search) : match.search;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useNavigate.js
|
|
172
|
-
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
173
|
-
/**
|
|
174
|
-
* Imperative navigation hook.
|
|
175
|
-
*
|
|
176
|
-
* Returns a stable `navigate(options)` function to change the current location
|
|
177
|
-
* programmatically. Prefer the `Link` component for user-initiated navigation,
|
|
178
|
-
* and use this hook from effects, callbacks, or handlers where imperative
|
|
179
|
-
* navigation is required.
|
|
180
|
-
*
|
|
181
|
-
* Options:
|
|
182
|
-
* - `from`: Optional route base used to resolve relative `to` paths.
|
|
183
|
-
*
|
|
184
|
-
* @returns A function that accepts `NavigateOptions`.
|
|
185
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useNavigateHook
|
|
186
|
-
*/
|
|
187
|
-
function useNavigate(_defaultOpts) {
|
|
188
|
-
const router = useRouter();
|
|
189
|
-
return import_react.useCallback((options) => {
|
|
190
|
-
return router.navigate({
|
|
191
|
-
...options,
|
|
192
|
-
from: options.from ?? _defaultOpts?.from
|
|
193
|
-
});
|
|
194
|
-
}, [_defaultOpts?.from, router]);
|
|
195
|
-
}
|
|
196
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useRouteContext.js
|
|
197
|
-
function useRouteContext(opts) {
|
|
198
|
-
return useMatch({
|
|
199
|
-
...opts,
|
|
200
|
-
select: (match) => opts.select ? opts.select(match.context) : match.context
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/link.js
|
|
204
|
-
var import_jsx_runtime = require_jsx_runtime();
|
|
205
|
-
function resolveExternalLink(to, protocolAllowlist) {
|
|
206
|
-
const scheme = typeof to === "string" && getUrlScheme(to);
|
|
207
|
-
if (!scheme) return;
|
|
208
|
-
if (!protocolAllowlist.has(scheme)) return null;
|
|
209
|
-
return to;
|
|
210
|
-
}
|
|
211
|
-
function resolveIsActive(location, next, activeOptions, basepath) {
|
|
212
|
-
const currentPath = removeTrailingSlash(location.pathname, basepath);
|
|
213
|
-
const nextPath = removeTrailingSlash(next.pathname, basepath);
|
|
214
|
-
if (activeOptions?.exact ? currentPath !== nextPath : !(currentPath.startsWith(nextPath) && (currentPath.length === nextPath.length || currentPath[nextPath.length] === "/"))) return false;
|
|
215
|
-
if (activeOptions?.includeSearch ?? true) {
|
|
216
|
-
if (!deepEqual(location.search, next.search, !activeOptions?.exact, activeOptions?.explicitUndefined)) return false;
|
|
217
|
-
}
|
|
218
|
-
return !activeOptions?.includeHash || location.hash === next.hash;
|
|
219
|
-
}
|
|
220
|
-
function useLinkProps(options, forwardedRef, host) {
|
|
221
|
-
return getServerLinkProps(useRouter(), options, forwardedRef, host);
|
|
222
|
-
}
|
|
223
|
-
var STATIC_EMPTY_OBJECT = {};
|
|
224
|
-
var STATIC_ACTIVE_OBJECT = { className: "active" };
|
|
225
|
-
var ROUTER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
226
|
-
"to",
|
|
227
|
-
"params",
|
|
228
|
-
"search",
|
|
229
|
-
"hash",
|
|
230
|
-
"state",
|
|
231
|
-
"mask",
|
|
232
|
-
"from",
|
|
233
|
-
"unsafeRelative",
|
|
234
|
-
"reloadDocument",
|
|
235
|
-
"preload",
|
|
236
|
-
"preloadDelay",
|
|
237
|
-
"preloadIntentProximity",
|
|
238
|
-
"hashScrollIntoView",
|
|
239
|
-
"replace",
|
|
240
|
-
"startTransition",
|
|
241
|
-
"resetScroll",
|
|
242
|
-
"viewTransition",
|
|
243
|
-
"ignoreBlocker",
|
|
244
|
-
"activeProps",
|
|
245
|
-
"inactiveProps",
|
|
246
|
-
"activeOptions",
|
|
247
|
-
"_asChild"
|
|
248
|
-
]);
|
|
249
|
-
function collectElementProps(options, host) {
|
|
250
|
-
const props = {};
|
|
251
|
-
for (const key in options) {
|
|
252
|
-
if (ROUTER_OPTION_KEYS.has(key) || key === "type" && host !== void 0 || key === "disabled" && host === "a") continue;
|
|
253
|
-
props[key] = options[key];
|
|
254
|
-
}
|
|
255
|
-
return props;
|
|
256
|
-
}
|
|
257
|
-
function applyLinkState(props, options, isActive, href, linkDisabled, host) {
|
|
258
|
-
const { activeProps, inactiveProps, className, style, target } = options;
|
|
259
|
-
const stateProps = functionalUpdate$1(isActive ? activeProps : inactiveProps, {}) ?? (isActive ? STATIC_ACTIVE_OBJECT : STATIC_EMPTY_OBJECT);
|
|
260
|
-
Object.assign(props, stateProps);
|
|
261
|
-
props.href = href;
|
|
262
|
-
if (host !== "a") props.disabled = linkDisabled;
|
|
263
|
-
props.target = target;
|
|
264
|
-
const stateStyle = stateProps.style;
|
|
265
|
-
if (style || stateStyle) props.style = style && stateStyle ? {
|
|
266
|
-
...style,
|
|
267
|
-
...stateStyle
|
|
268
|
-
} : style || stateStyle;
|
|
269
|
-
const stateClassName = stateProps.className;
|
|
270
|
-
if (className || stateClassName) props.className = className ? stateClassName ? `${className} ${stateClassName}` : className : stateClassName;
|
|
271
|
-
if (linkDisabled) {
|
|
272
|
-
props.role = "link";
|
|
273
|
-
props["aria-disabled"] = true;
|
|
274
|
-
}
|
|
275
|
-
if (isActive) {
|
|
276
|
-
props["data-status"] = "active";
|
|
277
|
-
props["aria-current"] = "page";
|
|
278
|
-
}
|
|
279
|
-
return props;
|
|
280
|
-
}
|
|
281
|
-
function getServerLinkProps(router, options, forwardedRef, host) {
|
|
282
|
-
const { to, disabled, activeOptions } = options;
|
|
283
|
-
const directExternalLink = resolveExternalLink(to, router.protocolAllowlist);
|
|
284
|
-
const next = directExternalLink === void 0 ? router.buildLocation(options) : void 0;
|
|
285
|
-
const hrefOption = next ? getHrefOption(next, router, disabled) : directExternalLink ?? void 0;
|
|
286
|
-
const linkDisabled = disabled || !hrefOption;
|
|
287
|
-
const externalLink = directExternalLink ?? (hrefOption && getUrlScheme(hrefOption) ? hrefOption : void 0);
|
|
288
|
-
const props = collectElementProps(options, host);
|
|
289
|
-
props.ref = forwardedRef;
|
|
290
|
-
if (externalLink) {
|
|
291
|
-
props.href = externalLink;
|
|
292
|
-
return props;
|
|
293
|
-
}
|
|
294
|
-
return applyLinkState(props, options, !!next && !(!disabled && !hrefOption) && !activeOptions?.includeHash && resolveIsActive(router.stores.location.get(), next, activeOptions, router.basepath), hrefOption, linkDisabled, host);
|
|
295
|
-
}
|
|
296
|
-
function getHrefOption(next, router, disabled) {
|
|
297
|
-
if (disabled) return;
|
|
298
|
-
const location = next.maskedLocation ?? next;
|
|
299
|
-
const href = location.external ? location.publicHref : router.history.createHref(location.publicHref) || "/";
|
|
300
|
-
if ((location.external || href !== location.publicHref) && isDangerousProtocol(href, router.protocolAllowlist)) return;
|
|
301
|
-
return href;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* A strongly-typed anchor component for declarative navigation.
|
|
305
|
-
* Handles path, search, hash and state updates with optional route preloading
|
|
306
|
-
* and active-state styling.
|
|
307
|
-
*
|
|
308
|
-
* Props:
|
|
309
|
-
* - `preload`: Controls route preloading (eg. 'intent', 'render', 'viewport', true/false)
|
|
310
|
-
* - `preloadDelay`: Delay in ms before preloading on focus, hover, or viewport entry
|
|
311
|
-
* - `activeProps`/`inactiveProps`: Additional props merged when link is active/inactive
|
|
312
|
-
* - `resetScroll`/`hashScrollIntoView`: Control scroll behavior on navigation
|
|
313
|
-
* - `viewTransition`/`startTransition`: Use View Transitions/React transitions for navigation
|
|
314
|
-
* - `ignoreBlocker`: Bypass registered blockers
|
|
315
|
-
*
|
|
316
|
-
* @returns An anchor-like element that navigates without full page reloads.
|
|
317
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/linkComponent
|
|
318
|
-
*/
|
|
319
|
-
var Link = import_react.memo(import_react.forwardRef((props, ref) => {
|
|
320
|
-
const host = props._asChild || "a";
|
|
321
|
-
const linkProps = useLinkProps(props, ref, host);
|
|
322
|
-
const children = typeof props.children === "function" ? props.children({ isActive: linkProps["data-status"] === "active" }) : props.children;
|
|
323
|
-
return import_react.createElement(host, linkProps, children);
|
|
324
|
-
}), areLinkPropsEqual);
|
|
325
|
-
function areLinkPropsEqual(prev, next) {
|
|
326
|
-
let extraKeys = 0;
|
|
327
|
-
for (const key in next) {
|
|
328
|
-
extraKeys++;
|
|
329
|
-
if (prev[key] === next[key]) continue;
|
|
330
|
-
if (!ROUTER_OPTION_KEYS.has(key) || !deepEqual(prev[key], next[key], false, true)) return false;
|
|
331
|
-
}
|
|
332
|
-
for (const _key in prev) extraKeys--;
|
|
333
|
-
return extraKeys === 0;
|
|
334
|
-
}
|
|
335
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/route.js
|
|
336
|
-
var Route = class extends BaseRoute {
|
|
337
|
-
/**
|
|
338
|
-
* @deprecated Use the `createRoute` function instead.
|
|
339
|
-
*/
|
|
340
|
-
constructor(options) {
|
|
341
|
-
super(options);
|
|
342
|
-
this.useMatch = (opts) => {
|
|
343
|
-
return useMatch({
|
|
344
|
-
...opts,
|
|
345
|
-
from: this.id
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
this.useRouteContext = (opts) => {
|
|
349
|
-
return useRouteContext({
|
|
350
|
-
...opts,
|
|
351
|
-
from: this.id
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
this.useSearch = (opts) => {
|
|
355
|
-
return useSearch({
|
|
356
|
-
...opts,
|
|
357
|
-
from: this.id
|
|
358
|
-
});
|
|
359
|
-
};
|
|
360
|
-
this.useParams = (opts) => {
|
|
361
|
-
return useParams({
|
|
362
|
-
...opts,
|
|
363
|
-
from: this.id
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
this.useLoaderDeps = (opts) => {
|
|
367
|
-
return useLoaderDeps({
|
|
368
|
-
...opts,
|
|
369
|
-
from: this.id
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
|
-
this.useLoaderData = (opts) => {
|
|
373
|
-
return useLoaderData({
|
|
374
|
-
...opts,
|
|
375
|
-
from: this.id
|
|
376
|
-
});
|
|
377
|
-
};
|
|
378
|
-
this.useNavigate = () => {
|
|
379
|
-
return useNavigate({ from: this.fullPath });
|
|
380
|
-
};
|
|
381
|
-
this.Link = import_react.forwardRef((props, ref) => {
|
|
382
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
|
|
383
|
-
ref,
|
|
384
|
-
from: this.fullPath,
|
|
385
|
-
...props
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
/**
|
|
391
|
-
* Creates a non-root Route instance for code-based routing.
|
|
392
|
-
*
|
|
393
|
-
* Use this to define a route that will be composed into a route tree
|
|
394
|
-
* (typically via a parent route's `addChildren`). If you're using file-based
|
|
395
|
-
* routing, prefer `createFileRoute`.
|
|
396
|
-
*
|
|
397
|
-
* @param options Route options (path, component, loader, context, etc.).
|
|
398
|
-
* @returns A Route instance to be attached to the route tree.
|
|
399
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouteFunction
|
|
400
|
-
*/
|
|
401
|
-
function createRoute(options) {
|
|
402
|
-
return new Route(options);
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Creates a root route factory that requires a router context type.
|
|
406
|
-
*
|
|
407
|
-
* Use when your root route expects `context` to be provided to `createRouter`.
|
|
408
|
-
* The returned function behaves like `createRootRoute` but enforces a context type.
|
|
409
|
-
*
|
|
410
|
-
* @returns A factory function to configure and return a root route.
|
|
411
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRootRouteWithContextFunction
|
|
412
|
-
*/
|
|
413
|
-
function createRootRouteWithContext() {
|
|
414
|
-
return (options) => {
|
|
415
|
-
return createRootRoute(options);
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
var RootRoute = class extends BaseRootRoute {
|
|
419
|
-
/**
|
|
420
|
-
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
421
|
-
*/
|
|
422
|
-
constructor(options) {
|
|
423
|
-
super(options);
|
|
424
|
-
this.useMatch = (opts) => {
|
|
425
|
-
return useMatch({
|
|
426
|
-
...opts,
|
|
427
|
-
from: this.id
|
|
428
|
-
});
|
|
429
|
-
};
|
|
430
|
-
this.useRouteContext = (opts) => {
|
|
431
|
-
return useRouteContext({
|
|
432
|
-
...opts,
|
|
433
|
-
from: this.id
|
|
434
|
-
});
|
|
435
|
-
};
|
|
436
|
-
this.useSearch = (opts) => {
|
|
437
|
-
return useSearch({
|
|
438
|
-
...opts,
|
|
439
|
-
from: this.id
|
|
440
|
-
});
|
|
441
|
-
};
|
|
442
|
-
this.useParams = (opts) => {
|
|
443
|
-
return useParams({
|
|
444
|
-
...opts,
|
|
445
|
-
from: this.id
|
|
446
|
-
});
|
|
447
|
-
};
|
|
448
|
-
this.useLoaderDeps = (opts) => {
|
|
449
|
-
return useLoaderDeps({
|
|
450
|
-
...opts,
|
|
451
|
-
from: this.id
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
this.useLoaderData = (opts) => {
|
|
455
|
-
return useLoaderData({
|
|
456
|
-
...opts,
|
|
457
|
-
from: this.id
|
|
458
|
-
});
|
|
459
|
-
};
|
|
460
|
-
this.useNavigate = () => {
|
|
461
|
-
return useNavigate({ from: this.fullPath });
|
|
462
|
-
};
|
|
463
|
-
this.Link = import_react.forwardRef((props, ref) => {
|
|
464
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
|
|
465
|
-
ref,
|
|
466
|
-
from: this.fullPath,
|
|
467
|
-
...props
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
/**
|
|
473
|
-
* Creates a root Route instance used to build your route tree.
|
|
474
|
-
*
|
|
475
|
-
* Typically paired with `createRouter({ routeTree })`. If you need to require
|
|
476
|
-
* a typed router context, use `createRootRouteWithContext` instead.
|
|
477
|
-
*
|
|
478
|
-
* @param options Root route options (component, error, pending, etc.).
|
|
479
|
-
* @returns A root route instance.
|
|
480
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRootRouteFunction
|
|
481
|
-
*/
|
|
482
|
-
function createRootRoute(options) {
|
|
483
|
-
return new RootRoute(options);
|
|
484
|
-
}
|
|
485
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/fileRoute.js
|
|
486
|
-
/**
|
|
487
|
-
* Creates a file-based Route factory for a given path.
|
|
488
|
-
*
|
|
489
|
-
* Used by TanStack Router's file-based routing to associate a file with a
|
|
490
|
-
* route. The returned function accepts standard route options. In normal usage
|
|
491
|
-
* the `path` string is inserted and maintained by the `tsr` generator.
|
|
492
|
-
*
|
|
493
|
-
* @param path File path literal for the route (usually auto-generated).
|
|
494
|
-
* @returns A function that accepts Route options and returns a Route instance.
|
|
495
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction
|
|
496
|
-
*/
|
|
497
|
-
function createFileRoute(path) {
|
|
498
|
-
return (options) => {
|
|
499
|
-
const route = createRoute(options);
|
|
500
|
-
route.isRoot = false;
|
|
501
|
-
return route;
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/lazyRouteComponent.js
|
|
505
|
-
/**
|
|
506
|
-
* Wrap a dynamic import to create a route component that supports
|
|
507
|
-
* `.preload()` and friendly reload-on-module-missing behavior.
|
|
508
|
-
*
|
|
509
|
-
* @param importer Function returning a module promise
|
|
510
|
-
* @param exportName Named export to use (default: `default`)
|
|
511
|
-
* @returns A lazy route component compatible with TanStack Router
|
|
512
|
-
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/lazyRouteComponentFunction
|
|
513
|
-
*/
|
|
514
|
-
function lazyRouteComponent(importer, exportName) {
|
|
515
|
-
let loadPromise;
|
|
516
|
-
let comp;
|
|
517
|
-
let error;
|
|
518
|
-
const load = () => {
|
|
519
|
-
if (!loadPromise) {
|
|
520
|
-
error = void 0;
|
|
521
|
-
loadPromise = importer().then((res) => {
|
|
522
|
-
comp = res[exportName ?? "default"];
|
|
523
|
-
}).catch((err) => {
|
|
524
|
-
loadPromise = void 0;
|
|
525
|
-
error = err;
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
return loadPromise;
|
|
529
|
-
};
|
|
530
|
-
const lazyComp = function Lazy(props) {
|
|
531
|
-
if (error) {
|
|
532
|
-
if (isModuleNotFoundError(error) && false);
|
|
533
|
-
throw error;
|
|
534
|
-
}
|
|
535
|
-
if (!comp) {
|
|
536
|
-
if (reactUse) reactUse(load());
|
|
537
|
-
else throw load();
|
|
538
|
-
}
|
|
539
|
-
return import_react.createElement(comp, props);
|
|
540
|
-
};
|
|
541
|
-
lazyComp.preload = load;
|
|
542
|
-
return lazyComp;
|
|
543
|
-
}
|
|
544
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js
|
|
545
|
-
/**
|
|
546
|
-
* The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
|
|
547
|
-
*/
|
|
548
|
-
var QueryClientContext = import_react.createContext(void 0);
|
|
549
|
-
/**
|
|
550
|
-
* The `useQueryClient` hook returns the current `QueryClient` instance.
|
|
551
|
-
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
552
|
-
* be used.
|
|
553
|
-
* @returns The current `QueryClient` instance.
|
|
554
|
-
* @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
555
|
-
* component tree.
|
|
556
|
-
*/
|
|
557
|
-
var useQueryClient = (queryClient) => {
|
|
558
|
-
const client = import_react.useContext(QueryClientContext);
|
|
559
|
-
if (queryClient) return queryClient;
|
|
560
|
-
if (!client) throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
561
|
-
return client;
|
|
562
|
-
};
|
|
563
|
-
/**
|
|
564
|
-
* Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
|
|
565
|
-
* calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
|
|
566
|
-
* focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
|
|
567
|
-
* comes back online).
|
|
568
|
-
* @param props - The `client` to provide, and the `children` that get access to it.
|
|
569
|
-
* @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
|
|
570
|
-
* @example
|
|
571
|
-
* ```tsx
|
|
572
|
-
* import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
573
|
-
*
|
|
574
|
-
* const queryClient = new QueryClient()
|
|
575
|
-
*
|
|
576
|
-
* function App() {
|
|
577
|
-
* return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
|
|
578
|
-
* }
|
|
579
|
-
* ```
|
|
580
|
-
*/
|
|
581
|
-
var QueryClientProvider = ({ client, children }) => {
|
|
582
|
-
import_react.useEffect(() => {
|
|
583
|
-
client.mount();
|
|
584
|
-
return () => {
|
|
585
|
-
client.unmount();
|
|
586
|
-
};
|
|
587
|
-
}, [client]);
|
|
588
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QueryClientContext.Provider, {
|
|
589
|
-
value: client,
|
|
590
|
-
children
|
|
591
|
-
});
|
|
592
|
-
};
|
|
593
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/timeoutManager.js
|
|
594
|
-
var defaultTimeoutProvider = {
|
|
595
|
-
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
596
|
-
clearTimeout: (timeoutId) => clearTimeout(timeoutId),
|
|
597
|
-
setInterval: (callback, delay) => setInterval(callback, delay),
|
|
598
|
-
clearInterval: (intervalId) => clearInterval(intervalId)
|
|
599
|
-
};
|
|
600
|
-
/**
|
|
601
|
-
* Allows customization of how timeouts are created.
|
|
602
|
-
*
|
|
603
|
-
* `@tanstack/query-core` makes liberal use of timeouts to implement `staleTime`
|
|
604
|
-
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
605
|
-
* `setTimeout` implementation, which is known to have scalability issues with
|
|
606
|
-
* thousands of timeouts on the event loop.
|
|
607
|
-
*
|
|
608
|
-
* If you hit this limitation, consider providing a custom TimeoutProvider that
|
|
609
|
-
* coalesces timeouts.
|
|
610
|
-
*/
|
|
611
|
-
var TimeoutManager = class {
|
|
612
|
-
#provider = defaultTimeoutProvider;
|
|
613
|
-
#providerCalled = false;
|
|
614
|
-
/**
|
|
615
|
-
* `setTimeoutProvider` can be used to set a custom implementation of the
|
|
616
|
-
* `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` functions,
|
|
617
|
-
* called a `TimeoutProvider`.
|
|
618
|
-
*
|
|
619
|
-
* This may be useful if you notice event loop performance issues with
|
|
620
|
-
* thousands of queries. A custom TimeoutProvider could also support timer
|
|
621
|
-
* delays longer than the global `setTimeout` maximum delay value of about
|
|
622
|
-
* 24 days.
|
|
623
|
-
*
|
|
624
|
-
* It is important to call `setTimeoutProvider` before creating a
|
|
625
|
-
* QueryClient or queries, so that the same provider is used consistently
|
|
626
|
-
* for all timers in the application, since different TimeoutProviders
|
|
627
|
-
* cannot cancel each others' timers.
|
|
628
|
-
* @param provider - The `TimeoutProvider` to use for all timers from now on.
|
|
629
|
-
* @example
|
|
630
|
-
* ```ts
|
|
631
|
-
* import { timeoutManager, QueryClient } from '@tanstack/query-core'
|
|
632
|
-
* import { CustomTimeoutProvider } from './CustomTimeoutProvider'
|
|
633
|
-
*
|
|
634
|
-
* timeoutManager.setTimeoutProvider(new CustomTimeoutProvider())
|
|
635
|
-
*
|
|
636
|
-
* export const queryClient = new QueryClient()
|
|
637
|
-
* ```
|
|
638
|
-
*/
|
|
639
|
-
setTimeoutProvider(provider) {
|
|
640
|
-
this.#provider = provider;
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* `setTimeout` schedules a callback to run after approximately `delay`
|
|
644
|
-
* milliseconds, like the global `setTimeout` function. The callback can be
|
|
645
|
-
* canceled with `clearTimeout`.
|
|
646
|
-
*
|
|
647
|
-
* It returns a timer ID, which may be a number or an object that can be
|
|
648
|
-
* coerced to a number via `Symbol.toPrimitive`.
|
|
649
|
-
* @param callback - The function to call when the timeout elapses.
|
|
650
|
-
* @param delay - The time to wait before calling `callback`, in milliseconds.
|
|
651
|
-
* @returns The timer ID, to pass to {@link TimeoutManager#clearTimeout}.
|
|
652
|
-
* @example
|
|
653
|
-
* ```ts
|
|
654
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
655
|
-
*
|
|
656
|
-
* const timeoutId = timeoutManager.setTimeout(
|
|
657
|
-
* () => console.log('ran at:', new Date()),
|
|
658
|
-
* 1000,
|
|
659
|
-
* )
|
|
660
|
-
*
|
|
661
|
-
* const timeoutIdNumber: number = Number(timeoutId)
|
|
662
|
-
* ```
|
|
663
|
-
*/
|
|
664
|
-
setTimeout(callback, delay) {
|
|
665
|
-
return this.#provider.setTimeout(callback, delay);
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,
|
|
669
|
-
* like the global `clearTimeout` function. It should be called with a
|
|
670
|
-
* timer ID returned by `setTimeout`.
|
|
671
|
-
* @param timeoutId - The timer ID returned by `setTimeout`, or `undefined`.
|
|
672
|
-
* @example
|
|
673
|
-
* ```ts
|
|
674
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
675
|
-
*
|
|
676
|
-
* const timeoutId = timeoutManager.setTimeout(
|
|
677
|
-
* () => console.log('ran at:', new Date()),
|
|
678
|
-
* 1000,
|
|
679
|
-
* )
|
|
680
|
-
*
|
|
681
|
-
* timeoutManager.clearTimeout(timeoutId)
|
|
682
|
-
* ```
|
|
683
|
-
*/
|
|
684
|
-
clearTimeout(timeoutId) {
|
|
685
|
-
this.#provider.clearTimeout(timeoutId);
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* `setInterval` schedules a callback to be called approximately every
|
|
689
|
-
* `delay` milliseconds, like the global `setInterval` function.
|
|
690
|
-
*
|
|
691
|
-
* Like `setTimeout`, it returns a timer ID, which may be a number or an
|
|
692
|
-
* object that can be coerced to a number via `Symbol.toPrimitive`.
|
|
693
|
-
* @param callback - The function to call on every interval.
|
|
694
|
-
* @param delay - The time between calls, in milliseconds.
|
|
695
|
-
* @returns The timer ID, to pass to {@link TimeoutManager#clearInterval}.
|
|
696
|
-
* @example
|
|
697
|
-
* ```ts
|
|
698
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
699
|
-
*
|
|
700
|
-
* const intervalId = timeoutManager.setInterval(
|
|
701
|
-
* () => console.log('ran at:', new Date()),
|
|
702
|
-
* 1000,
|
|
703
|
-
* )
|
|
704
|
-
* ```
|
|
705
|
-
*/
|
|
706
|
-
setInterval(callback, delay) {
|
|
707
|
-
return this.#provider.setInterval(callback, delay);
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* `clearInterval` can be used to cancel an interval, like the global
|
|
711
|
-
* `clearInterval` function. It should be called with an interval ID
|
|
712
|
-
* returned by `setInterval`.
|
|
713
|
-
* @param intervalId - The timer ID returned by `setInterval`, or `undefined`.
|
|
714
|
-
* @example
|
|
715
|
-
* ```ts
|
|
716
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
717
|
-
*
|
|
718
|
-
* const intervalId = timeoutManager.setInterval(
|
|
719
|
-
* () => console.log('ran at:', new Date()),
|
|
720
|
-
* 1000,
|
|
721
|
-
* )
|
|
722
|
-
*
|
|
723
|
-
* timeoutManager.clearInterval(intervalId)
|
|
724
|
-
* ```
|
|
725
|
-
*/
|
|
726
|
-
clearInterval(intervalId) {
|
|
727
|
-
this.#provider.clearInterval(intervalId);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
/**
|
|
731
|
-
* Singleton instance of {@link TimeoutManager}, used throughout TanStack Query to schedule and cancel timers.
|
|
732
|
-
*/
|
|
733
|
-
var timeoutManager = new TimeoutManager();
|
|
734
|
-
/**
|
|
735
|
-
* In many cases code wants to delay to the next event loop tick; this is not
|
|
736
|
-
* mediated by {@link timeoutManager}.
|
|
737
|
-
*
|
|
738
|
-
* This function is provided to make auditing the `tanstack/query-core` for
|
|
739
|
-
* incorrect use of system `setTimeout` easier.
|
|
740
|
-
* @param callback - The function to call on the next event loop tick.
|
|
741
|
-
*/
|
|
742
|
-
function systemSetTimeoutZero(callback) {
|
|
743
|
-
setTimeout(callback, 0);
|
|
744
|
-
}
|
|
745
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/utils.js
|
|
746
|
-
/**
|
|
747
|
-
* @deprecated use `environmentManager.isServer()` instead.
|
|
748
|
-
*/
|
|
749
|
-
var isServer$1 = typeof window === "undefined" || "Deno" in globalThis;
|
|
750
|
-
function noop() {}
|
|
751
|
-
/**
|
|
752
|
-
* Resolves an {@link Updater}: calls it with `input` if it is a function, otherwise returns it as
|
|
753
|
-
* is.
|
|
754
|
-
* @param updater - The new value, or a function that receives `input` and returns the new value.
|
|
755
|
-
* @param input - The current value, passed to `updater` if it is a function.
|
|
756
|
-
* @returns The new value.
|
|
757
|
-
*/
|
|
758
|
-
function functionalUpdate(updater, input) {
|
|
759
|
-
return typeof updater === "function" ? updater(input) : updater;
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* Checks whether a value can be used as a timeout: a non-negative, finite number.
|
|
763
|
-
* @param value - The value to check.
|
|
764
|
-
* @returns `true` if `value` is a number that is `>= 0` and not `Infinity`.
|
|
765
|
-
*/
|
|
766
|
-
function isValidTimeout(value) {
|
|
767
|
-
return typeof value === "number" && value >= 0 && value !== Infinity;
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Calculates how long until data updated at `updatedAt` becomes stale.
|
|
771
|
-
* @param updatedAt - The timestamp, in milliseconds, at which the data was last updated.
|
|
772
|
-
* @param staleTime - The time, in milliseconds, after which data is considered stale. Defaults to
|
|
773
|
-
* `0`.
|
|
774
|
-
* @returns The remaining time in milliseconds, or `0` if the data is already stale.
|
|
775
|
-
*/
|
|
776
|
-
function timeUntilStale(updatedAt, staleTime) {
|
|
777
|
-
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Resolves an option that can be given either as a value or as a function of the query, such as
|
|
781
|
-
* `staleTime`.
|
|
782
|
-
* @param value - The option value, or a function that receives `query` and returns the value.
|
|
783
|
-
* @param query - The query passed to `value` if it is a function.
|
|
784
|
-
* @returns The resolved value, or `undefined` if `value` is `undefined`.
|
|
785
|
-
*/
|
|
786
|
-
function resolveQueryValue(value, query) {
|
|
787
|
-
return typeof value === "function" ? value(query) : value;
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Checks whether a query matches the given {@link QueryFilters}.
|
|
791
|
-
* Every filter that is specified must match; filters that are left unspecified are ignored.
|
|
792
|
-
* @param filters - The filters to check the query against.
|
|
793
|
-
* @param query - The query to check.
|
|
794
|
-
* @returns `true` if the query matches every specified filter.
|
|
795
|
-
* @example
|
|
796
|
-
* ```ts
|
|
797
|
-
* const queryCache = queryClient.getQueryCache()
|
|
798
|
-
*
|
|
799
|
-
* const matchingQueries = queryCache
|
|
800
|
-
* .getAll()
|
|
801
|
-
* .filter((query) => matchQuery({ queryKey: ['posts'] }, query))
|
|
802
|
-
* ```
|
|
803
|
-
*/
|
|
804
|
-
function matchQuery(filters, query) {
|
|
805
|
-
const { type = "all", exact, fetchStatus, predicate, queryKey, stale } = filters;
|
|
806
|
-
if (queryKey) {
|
|
807
|
-
if (exact) {
|
|
808
|
-
if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) return false;
|
|
809
|
-
} else if (!partialMatchKey(query.queryKey, queryKey)) return false;
|
|
810
|
-
}
|
|
811
|
-
if (type !== "all") {
|
|
812
|
-
const isActive = query.isActive();
|
|
813
|
-
if (type === "active" && !isActive) return false;
|
|
814
|
-
if (type === "inactive" && isActive) return false;
|
|
815
|
-
}
|
|
816
|
-
if (typeof stale === "boolean" && query.isStale() !== stale) return false;
|
|
817
|
-
if (fetchStatus && fetchStatus !== query.state.fetchStatus) return false;
|
|
818
|
-
if (predicate && !predicate(query)) return false;
|
|
819
|
-
return true;
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Checks whether a mutation matches the given {@link MutationFilters}.
|
|
823
|
-
* Every filter that is specified must match; filters that are left unspecified are ignored.
|
|
824
|
-
* If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.
|
|
825
|
-
* @param filters - The filters to check the mutation against.
|
|
826
|
-
* @param mutation - The mutation to check.
|
|
827
|
-
* @returns `true` if the mutation matches every specified filter.
|
|
828
|
-
* @example
|
|
829
|
-
* ```ts
|
|
830
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
831
|
-
*
|
|
832
|
-
* const matchingMutations = mutationCache
|
|
833
|
-
* .getAll()
|
|
834
|
-
* .filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))
|
|
835
|
-
* ```
|
|
836
|
-
*/
|
|
837
|
-
function matchMutation(filters, mutation) {
|
|
838
|
-
const { exact, status, predicate, mutationKey } = filters;
|
|
839
|
-
if (mutationKey) {
|
|
840
|
-
if (!mutation.options.mutationKey) return false;
|
|
841
|
-
if (exact) {
|
|
842
|
-
if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) return false;
|
|
843
|
-
} else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) return false;
|
|
844
|
-
}
|
|
845
|
-
if (status && mutation.state.status !== status) return false;
|
|
846
|
-
if (predicate && !predicate(mutation)) return false;
|
|
847
|
-
return true;
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Hashes a query key with the query's `queryKeyHashFn` option, falling back to {@link hashKey}.
|
|
851
|
-
* @param queryKey - The query key to hash.
|
|
852
|
-
* @param options - The query options that may provide a custom `queryKeyHashFn`.
|
|
853
|
-
* @returns The query hash, a string that identifies the query in the cache.
|
|
854
|
-
*/
|
|
855
|
-
function hashQueryKeyByOptions(queryKey, options) {
|
|
856
|
-
return (options?.queryKeyHashFn || hashKey)(queryKey);
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Default query & mutation keys hash function.
|
|
860
|
-
* Hashes the value into a stable hash.
|
|
861
|
-
* @param queryKey - The query or mutation key to hash.
|
|
862
|
-
* @returns The stable hash of the key, as a JSON string.
|
|
863
|
-
* @example
|
|
864
|
-
* ```ts
|
|
865
|
-
* // Object keys are sorted, so key order doesn't affect the hash:
|
|
866
|
-
* hashKey(['todos', { page: 1, filter: 'done' }]) // === '["todos",{"filter":"done","page":1}]'
|
|
867
|
-
* ```
|
|
868
|
-
*/
|
|
869
|
-
function hashKey(queryKey) {
|
|
870
|
-
return JSON.stringify(queryKey, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
|
|
871
|
-
result[key] = val[key];
|
|
872
|
-
return result;
|
|
873
|
-
}, {}) : val);
|
|
874
|
-
}
|
|
875
|
-
function partialMatchKey(a, b) {
|
|
876
|
-
if (a === b) return true;
|
|
877
|
-
if (typeof a !== typeof b) return false;
|
|
878
|
-
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
879
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
880
|
-
if (b.length > a.length) return false;
|
|
881
|
-
for (let i = 0; i < b.length; i++) if (!partialMatchKey(a[i], b[i])) return false;
|
|
882
|
-
return true;
|
|
883
|
-
}
|
|
884
|
-
const bKeys = Object.keys(b);
|
|
885
|
-
for (const key of bKeys) if (!partialMatchKey(a[key], b[key])) return false;
|
|
886
|
-
return true;
|
|
887
|
-
}
|
|
888
|
-
return false;
|
|
889
|
-
}
|
|
890
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
|
891
|
-
function replaceEqualDeep(a, b, depth = 0) {
|
|
892
|
-
if (a === b) return a;
|
|
893
|
-
if (depth > 500) return b;
|
|
894
|
-
const array = isPlainArray(a) && isPlainArray(b);
|
|
895
|
-
if (!array && !(isPlainObject(a) && isPlainObject(b))) return b;
|
|
896
|
-
const aSize = (array ? a : Object.keys(a)).length;
|
|
897
|
-
const bItems = array ? b : Object.keys(b);
|
|
898
|
-
const bSize = bItems.length;
|
|
899
|
-
const copy = array ? new Array(bSize) : {};
|
|
900
|
-
let equalItems = 0;
|
|
901
|
-
for (let i = 0; i < bSize; i++) {
|
|
902
|
-
const key = array ? i : bItems[i];
|
|
903
|
-
const aItem = a[key];
|
|
904
|
-
const bItem = b[key];
|
|
905
|
-
if (aItem === bItem) {
|
|
906
|
-
copy[key] = aItem;
|
|
907
|
-
if (array ? i < aSize : hasOwn.call(a, key)) equalItems++;
|
|
908
|
-
continue;
|
|
909
|
-
}
|
|
910
|
-
if (aItem === null || bItem === null || typeof aItem !== "object" || typeof bItem !== "object") {
|
|
911
|
-
copy[key] = bItem;
|
|
912
|
-
continue;
|
|
913
|
-
}
|
|
914
|
-
const v = replaceEqualDeep(aItem, bItem, depth + 1);
|
|
915
|
-
copy[key] = v;
|
|
916
|
-
if (v === aItem) equalItems++;
|
|
917
|
-
}
|
|
918
|
-
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Shallow compare objects.
|
|
922
|
-
* @param a - The first object.
|
|
923
|
-
* @param b - The second object, or `undefined`.
|
|
924
|
-
* @returns `true` if both objects have the same keys, with strictly equal values for each key.
|
|
925
|
-
*/
|
|
926
|
-
function shallowEqualObjects(a, b) {
|
|
927
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) return false;
|
|
928
|
-
for (const key of Object.keys(a)) if (!hasOwn.call(b, key) || a[key] !== b[key]) return false;
|
|
929
|
-
return true;
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* Checks whether a value is an array with no holes and no extra properties.
|
|
933
|
-
* @param value - The value to check.
|
|
934
|
-
* @returns `true` if `value` is an array whose number of own keys equals its `length`.
|
|
935
|
-
*/
|
|
936
|
-
function isPlainArray(value) {
|
|
937
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Checks whether a value is a plain object, e.g. created with an object literal or
|
|
941
|
-
* `Object.create(null)`.
|
|
942
|
-
* @param o - The value to check.
|
|
943
|
-
* @returns `true` if `o` is a plain object.
|
|
944
|
-
*/
|
|
945
|
-
function isPlainObject(o) {
|
|
946
|
-
if (!hasObjectPrototype(o)) return false;
|
|
947
|
-
const objectPrototype = Object.getPrototypeOf(o);
|
|
948
|
-
const ctor = objectPrototype?.constructor;
|
|
949
|
-
if (ctor === void 0) return true;
|
|
950
|
-
if (typeof ctor !== "function") return false;
|
|
951
|
-
const prot = ctor.prototype;
|
|
952
|
-
if (!hasObjectPrototype(prot)) return false;
|
|
953
|
-
if (!prot.hasOwnProperty("isPrototypeOf")) return false;
|
|
954
|
-
if (objectPrototype !== Object.prototype) return false;
|
|
955
|
-
return true;
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Checks whether a value's `Object.prototype.toString` tag is `[object Object]`.
|
|
959
|
-
* @param o - The value to check.
|
|
960
|
-
* @returns `true` if the tag is `[object Object]`.
|
|
961
|
-
*/
|
|
962
|
-
function hasObjectPrototype(o) {
|
|
963
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* Waits for the given time, using the configured {@link timeoutManager}.
|
|
967
|
-
* @param timeout - The time to wait, in milliseconds.
|
|
968
|
-
* @returns A promise that resolves after `timeout` milliseconds.
|
|
969
|
-
*/
|
|
970
|
-
function sleep(timeout) {
|
|
971
|
-
return new Promise((resolve) => {
|
|
972
|
-
timeoutManager.setTimeout(resolve, timeout);
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* Applies a query's `structuralSharing` option when writing new data.
|
|
977
|
-
* @param prevData - The previously cached data.
|
|
978
|
-
* @param data - The new data.
|
|
979
|
-
* @param options - The query options, whose `structuralSharing` decides how the data is merged.
|
|
980
|
-
* @returns The result of a custom `structuralSharing` function, `data` with its unchanged parts
|
|
981
|
-
* replaced by those of `prevData` by default, or `data` as is if `structuralSharing` is `false`.
|
|
982
|
-
* @throws {Error} The error from the default structural sharing, e.g. when the data is not JSON serializable.
|
|
983
|
-
* Outside production, it is also logged to the console.
|
|
984
|
-
*/
|
|
985
|
-
function replaceData(prevData, data, options) {
|
|
986
|
-
if (typeof options.structuralSharing === "function") return options.structuralSharing(prevData, data);
|
|
987
|
-
else if (options.structuralSharing !== false) return replaceEqualDeep(prevData, data);
|
|
988
|
-
return data;
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* Returns a new array with `item` added at the end. If that makes the array longer than `max`,
|
|
992
|
-
* excess items are removed from the start.
|
|
993
|
-
* @param items - The current items.
|
|
994
|
-
* @param item - The value to append.
|
|
995
|
-
* @param max - The maximum number of items to keep. `0` (the default) means no limit.
|
|
996
|
-
* @returns A new array with `item` added.
|
|
997
|
-
*/
|
|
998
|
-
function addToEnd(items, item, max = 0) {
|
|
999
|
-
const newItems = [...items, item];
|
|
1000
|
-
return max && newItems.length > max ? newItems.slice(-max) : newItems;
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* Returns a new array with `item` added at the start. If that makes the array longer than `max`,
|
|
1004
|
-
* excess items are removed from the end.
|
|
1005
|
-
* @param items - The current items.
|
|
1006
|
-
* @param item - The value to prepend.
|
|
1007
|
-
* @param max - The maximum number of items to keep. `0` (the default) means no limit.
|
|
1008
|
-
* @returns A new array with `item` added.
|
|
1009
|
-
*/
|
|
1010
|
-
function addToStart(items, item, max = 0) {
|
|
1011
|
-
const newItems = [item, ...items];
|
|
1012
|
-
return max && newItems.length > max ? newItems.slice(0, max) : newItems;
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Sentinel value that can be passed as a query's `queryFn` to conditionally disable the query (equivalent
|
|
1016
|
-
* to `enabled: false`) while preserving full type inference for the query's data. Unlike `enabled: false`,
|
|
1017
|
-
* a query disabled via `skipToken` cannot be triggered with `refetch`.
|
|
1018
|
-
* @example
|
|
1019
|
-
* ```ts
|
|
1020
|
-
* new QueryObserver(queryClient, {
|
|
1021
|
-
* queryKey: ['post', postId],
|
|
1022
|
-
* queryFn: postId != null ? () => fetchPost(postId) : skipToken,
|
|
1023
|
-
* })
|
|
1024
|
-
* ```
|
|
1025
|
-
*/
|
|
1026
|
-
var skipToken = Symbol();
|
|
1027
|
-
/**
|
|
1028
|
-
* Returns the function to call for a fetch. If there is no `queryFn` but the fetch was started from
|
|
1029
|
-
* an `initialPromise`, that promise is returned instead. If there is no usable `queryFn` (missing or
|
|
1030
|
-
* {@link skipToken}), the returned function rejects with a `Missing queryFn` error.
|
|
1031
|
-
* @param options - The query options with the `queryFn`, and the `queryHash` used in error messages.
|
|
1032
|
-
* @param fetchOptions - The fetch options, which may carry an `initialPromise`.
|
|
1033
|
-
* @returns The function to call for the fetch.
|
|
1034
|
-
*/
|
|
1035
|
-
function ensureQueryFn(options, fetchOptions) {
|
|
1036
|
-
if (!options.queryFn && fetchOptions?.initialPromise) return () => fetchOptions.initialPromise;
|
|
1037
|
-
if (!options.queryFn || options.queryFn === skipToken) return () => Promise.reject(/* @__PURE__ */ new Error(`Missing queryFn: '${options.queryHash}'`));
|
|
1038
|
-
return options.queryFn;
|
|
1039
|
-
}
|
|
1040
|
-
/**
|
|
1041
|
-
* Resolves a `throwOnError` option to a boolean.
|
|
1042
|
-
* If `throwOnError` is a function, it is called with `params` (e.g. the error and, depending on the caller,
|
|
1043
|
-
* additional context such as the query or mutation) and its result is returned, allowing the throwing
|
|
1044
|
-
* behavior to be decided per error. Otherwise, `throwOnError` itself is coerced to a boolean (`undefined`
|
|
1045
|
-
* resolves to `false`).
|
|
1046
|
-
* @param throwOnError - The `throwOnError` option: a boolean, a function that decides per error, or
|
|
1047
|
-
* `undefined`.
|
|
1048
|
-
* @param params - The arguments passed to `throwOnError` if it is a function.
|
|
1049
|
-
* @returns Whether the error should be thrown.
|
|
1050
|
-
* @example
|
|
1051
|
-
* ```ts
|
|
1052
|
-
* const throwOnError =
|
|
1053
|
-
* query.state.error && typeof options.throwOnError === 'function'
|
|
1054
|
-
* ? shouldThrowError(options.throwOnError, [query.state.error, query])
|
|
1055
|
-
* : options.throwOnError
|
|
1056
|
-
* ```
|
|
1057
|
-
*/
|
|
1058
|
-
function shouldThrowError(throwOnError, params) {
|
|
1059
|
-
if (typeof throwOnError === "function") return throwOnError(...params);
|
|
1060
|
-
return !!throwOnError;
|
|
1061
|
-
}
|
|
1062
|
-
var fetchSignal = Symbol();
|
|
1063
|
-
/**
|
|
1064
|
-
* Adds a lazy `signal` getter to an object, such as a query function context. The first time
|
|
1065
|
-
* `signal` is read, `onCancelled` is registered for the signal's `abort` event (or called right
|
|
1066
|
-
* away if it is already aborted), so cancellation is only tracked when the signal is actually used.
|
|
1067
|
-
* @param object - The object to add the `signal` property to.
|
|
1068
|
-
* @param getSignal - Returns the `AbortSignal`. Called once, when `signal` is first read.
|
|
1069
|
-
* @param onCancelled - Called when the signal is aborted, if `signal` was read.
|
|
1070
|
-
* @param internalSignal - The fetch signal to forward without consuming the getter.
|
|
1071
|
-
* @returns The same object, with the `signal` property added.
|
|
1072
|
-
*/
|
|
1073
|
-
function addConsumeAwareSignal(object, getSignal, onCancelled, internalSignal) {
|
|
1074
|
-
let consumed = false;
|
|
1075
|
-
let signal;
|
|
1076
|
-
Object.defineProperties(object, {
|
|
1077
|
-
[fetchSignal]: { value: internalSignal },
|
|
1078
|
-
signal: {
|
|
1079
|
-
enumerable: true,
|
|
1080
|
-
get: () => {
|
|
1081
|
-
signal ??= getSignal();
|
|
1082
|
-
if (consumed) return signal;
|
|
1083
|
-
consumed = true;
|
|
1084
|
-
if (signal.aborted) onCancelled();
|
|
1085
|
-
else signal.addEventListener("abort", onCancelled, { once: true });
|
|
1086
|
-
return signal;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
return object;
|
|
1091
|
-
}
|
|
1092
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/environmentManager.js
|
|
1093
|
-
var isServerFn = () => isServer$1;
|
|
1094
|
-
/**
|
|
1095
|
-
* Returns whether the current runtime should be treated as a server environment.
|
|
1096
|
-
* @returns `true` if the runtime is treated as a server.
|
|
1097
|
-
*/
|
|
1098
|
-
var isServer = () => isServerFn();
|
|
1099
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/subscribable.js
|
|
1100
|
-
/**
|
|
1101
|
-
* The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
|
|
1102
|
-
* the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
|
|
1103
|
-
* Subclasses decide what a listener receives and when it is called.
|
|
1104
|
-
*/
|
|
1105
|
-
var Subscribable = class {
|
|
1106
|
-
constructor() {
|
|
1107
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
1108
|
-
this.subscribe = this.subscribe.bind(this);
|
|
1109
|
-
}
|
|
1110
|
-
/**
|
|
1111
|
-
* Registers a listener to be called on every update this object notifies about. Returns a function
|
|
1112
|
-
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
1113
|
-
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
1114
|
-
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
1115
|
-
* @returns A function that removes the listener.
|
|
1116
|
-
* @example
|
|
1117
|
-
* ```ts
|
|
1118
|
-
* const unsubscribe = subscribable.subscribe(() => {
|
|
1119
|
-
* // react to the update
|
|
1120
|
-
* })
|
|
1121
|
-
*
|
|
1122
|
-
* unsubscribe()
|
|
1123
|
-
* ```
|
|
1124
|
-
*/
|
|
1125
|
-
subscribe(listener) {
|
|
1126
|
-
this.listeners.add(listener);
|
|
1127
|
-
this.onSubscribe();
|
|
1128
|
-
return () => {
|
|
1129
|
-
this.listeners.delete(listener);
|
|
1130
|
-
this.onUnsubscribe();
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
1135
|
-
* @returns `true` if at least one listener is registered.
|
|
1136
|
-
*/
|
|
1137
|
-
hasListeners() {
|
|
1138
|
-
return this.listeners.size > 0;
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Called after a listener is added. Does nothing here; subclasses override it, e.g. to start
|
|
1142
|
-
* tracking what they observe once the first listener subscribes.
|
|
1143
|
-
*/
|
|
1144
|
-
onSubscribe() {}
|
|
1145
|
-
/**
|
|
1146
|
-
* Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up
|
|
1147
|
-
* once the last listener unsubscribes.
|
|
1148
|
-
*/
|
|
1149
|
-
onUnsubscribe() {}
|
|
1150
|
-
};
|
|
1151
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/focusManager.js
|
|
1152
|
-
/**
|
|
1153
|
-
* The `FocusManager` manages the focus state within TanStack Query.
|
|
1154
|
-
*
|
|
1155
|
-
* It can be used to change the default event listeners or to manually change the focus state.
|
|
1156
|
-
*/
|
|
1157
|
-
var FocusManager = class extends Subscribable {
|
|
1158
|
-
#focused;
|
|
1159
|
-
#cleanup;
|
|
1160
|
-
#setup;
|
|
1161
|
-
constructor() {
|
|
1162
|
-
super();
|
|
1163
|
-
this.#setup = (onFocus) => {
|
|
1164
|
-
if (typeof window !== "undefined" && window.addEventListener) {
|
|
1165
|
-
const listener = () => onFocus();
|
|
1166
|
-
window.addEventListener("visibilitychange", listener, false);
|
|
1167
|
-
return () => {
|
|
1168
|
-
window.removeEventListener("visibilitychange", listener);
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
};
|
|
1172
|
-
}
|
|
1173
|
-
onSubscribe() {
|
|
1174
|
-
if (!this.#cleanup) this.setEventListener(this.#setup);
|
|
1175
|
-
}
|
|
1176
|
-
onUnsubscribe() {
|
|
1177
|
-
if (!this.hasListeners()) {
|
|
1178
|
-
this.#cleanup?.();
|
|
1179
|
-
this.#cleanup = void 0;
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
/**
|
|
1183
|
-
* `setEventListener` can be used to set a custom event listener that will
|
|
1184
|
-
* be used to determine the focus state. The provided `setup` function
|
|
1185
|
-
* receives a `setFocused` callback: call it with a `boolean` to manually
|
|
1186
|
-
* set the focus state, or with no arguments to re-evaluate the current
|
|
1187
|
-
* focus state and notify subscribers.
|
|
1188
|
-
* @param setup - Receives the `setFocused` callback, registers the event listener, and may return
|
|
1189
|
-
* a cleanup function that is called when the listener is replaced or no longer needed.
|
|
1190
|
-
* @example
|
|
1191
|
-
* ```ts
|
|
1192
|
-
* import { focusManager } from '@tanstack/query-core'
|
|
1193
|
-
*
|
|
1194
|
-
* focusManager.setEventListener((handleFocus) => {
|
|
1195
|
-
* const listener = () => handleFocus()
|
|
1196
|
-
* // Listen to visibilitychange
|
|
1197
|
-
* if (typeof window !== 'undefined' && window.addEventListener) {
|
|
1198
|
-
* window.addEventListener('visibilitychange', listener, false)
|
|
1199
|
-
* }
|
|
1200
|
-
*
|
|
1201
|
-
* return () => {
|
|
1202
|
-
* // Be sure to unsubscribe if a new handler is set
|
|
1203
|
-
* window.removeEventListener('visibilitychange', listener)
|
|
1204
|
-
* }
|
|
1205
|
-
* })
|
|
1206
|
-
* ```
|
|
1207
|
-
*/
|
|
1208
|
-
setEventListener(setup) {
|
|
1209
|
-
this.#setup = setup;
|
|
1210
|
-
this.#cleanup?.();
|
|
1211
|
-
this.#cleanup = setup((focused) => {
|
|
1212
|
-
if (typeof focused === "boolean") this.setFocused(focused);
|
|
1213
|
-
else this.onFocus();
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
/**
|
|
1217
|
-
* `setFocused` can be used to manually set the focus state. Set `undefined`
|
|
1218
|
-
* to fall back to the default focus check.
|
|
1219
|
-
* @param focused - The focus state, or `undefined` to use the default focus check.
|
|
1220
|
-
* @example
|
|
1221
|
-
* ```ts
|
|
1222
|
-
* import { focusManager } from '@tanstack/query-core'
|
|
1223
|
-
*
|
|
1224
|
-
* // Set focused
|
|
1225
|
-
* focusManager.setFocused(true)
|
|
1226
|
-
*
|
|
1227
|
-
* // Set unfocused
|
|
1228
|
-
* focusManager.setFocused(false)
|
|
1229
|
-
*
|
|
1230
|
-
* // Fallback to the default focus check
|
|
1231
|
-
* focusManager.setFocused(undefined)
|
|
1232
|
-
* ```
|
|
1233
|
-
*/
|
|
1234
|
-
setFocused(focused) {
|
|
1235
|
-
if (this.#focused !== focused) {
|
|
1236
|
-
this.#focused = focused;
|
|
1237
|
-
this.onFocus();
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
/**
|
|
1241
|
-
* `onFocus` notifies all subscribed listeners with the current focus state.
|
|
1242
|
-
*/
|
|
1243
|
-
onFocus() {
|
|
1244
|
-
const isFocused = this.isFocused();
|
|
1245
|
-
this.listeners.forEach((listener) => {
|
|
1246
|
-
listener(isFocused);
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
/**
|
|
1250
|
-
* `isFocused` can be used to get the current focus state.
|
|
1251
|
-
* @returns The focus state set with `setFocused`, or otherwise whether the document is visible.
|
|
1252
|
-
*/
|
|
1253
|
-
isFocused() {
|
|
1254
|
-
if (typeof this.#focused === "boolean") return this.#focused;
|
|
1255
|
-
return globalThis.document?.visibilityState !== "hidden";
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
/**
|
|
1259
|
-
* Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
|
|
1260
|
-
*/
|
|
1261
|
-
var focusManager = new FocusManager();
|
|
1262
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/notifyManager.js
|
|
1263
|
-
/**
|
|
1264
|
-
* Default scheduling function used by the notify manager.
|
|
1265
|
-
* Schedules the callback with the system's `setTimeout(callback, 0)`.
|
|
1266
|
-
*/
|
|
1267
|
-
var defaultScheduler = systemSetTimeoutZero;
|
|
1268
|
-
/**
|
|
1269
|
-
* Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
|
|
1270
|
-
* single instance of it, exported as {@link notifyManager}.
|
|
1271
|
-
* @returns A new notify manager.
|
|
1272
|
-
*/
|
|
1273
|
-
function createNotifyManager() {
|
|
1274
|
-
let queue = [];
|
|
1275
|
-
let transactions = 0;
|
|
1276
|
-
let notifyFn = (callback) => {
|
|
1277
|
-
callback();
|
|
1278
|
-
};
|
|
1279
|
-
let batchNotifyFn = (callback) => {
|
|
1280
|
-
callback();
|
|
1281
|
-
};
|
|
1282
|
-
let scheduleFn = defaultScheduler;
|
|
1283
|
-
const schedule = (callback) => {
|
|
1284
|
-
if (transactions) queue.push(callback);
|
|
1285
|
-
else scheduleFn(() => {
|
|
1286
|
-
notifyFn(callback);
|
|
1287
|
-
});
|
|
1288
|
-
};
|
|
1289
|
-
const flush = () => {
|
|
1290
|
-
const originalQueue = queue;
|
|
1291
|
-
queue = [];
|
|
1292
|
-
if (originalQueue.length) scheduleFn(() => {
|
|
1293
|
-
batchNotifyFn(() => {
|
|
1294
|
-
originalQueue.forEach((callback) => {
|
|
1295
|
-
notifyFn(callback);
|
|
1296
|
-
});
|
|
1297
|
-
});
|
|
1298
|
-
});
|
|
1299
|
-
};
|
|
1300
|
-
return {
|
|
1301
|
-
/**
|
|
1302
|
-
* Batches all updates scheduled inside the passed callback.
|
|
1303
|
-
* This is mainly used internally to optimize query client updating.
|
|
1304
|
-
* Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
|
|
1305
|
-
* The return value of `callback` is passed through.
|
|
1306
|
-
* @param callback - The function to run in the batch.
|
|
1307
|
-
* @returns The return value of `callback`.
|
|
1308
|
-
*/
|
|
1309
|
-
batch: (callback) => {
|
|
1310
|
-
let result;
|
|
1311
|
-
transactions++;
|
|
1312
|
-
try {
|
|
1313
|
-
result = callback();
|
|
1314
|
-
} finally {
|
|
1315
|
-
transactions--;
|
|
1316
|
-
if (!transactions) flush();
|
|
1317
|
-
}
|
|
1318
|
-
return result;
|
|
1319
|
-
},
|
|
1320
|
-
/**
|
|
1321
|
-
* All calls to the wrapped function will be batched.
|
|
1322
|
-
* @param callback - The function to wrap.
|
|
1323
|
-
* @returns A function that schedules a call to `callback` with the given arguments.
|
|
1324
|
-
*/
|
|
1325
|
-
batchCalls: (callback) => {
|
|
1326
|
-
return (...args) => {
|
|
1327
|
-
schedule(() => {
|
|
1328
|
-
callback(...args);
|
|
1329
|
-
});
|
|
1330
|
-
};
|
|
1331
|
-
},
|
|
1332
|
-
/**
|
|
1333
|
-
* Schedules a function to be run on the next batch.
|
|
1334
|
-
* By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
|
|
1335
|
-
*/
|
|
1336
|
-
schedule,
|
|
1337
|
-
/**
|
|
1338
|
-
* Use this method to set a custom notify function.
|
|
1339
|
-
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
1340
|
-
* @param fn - Receives each notification callback and must call it.
|
|
1341
|
-
*/
|
|
1342
|
-
setNotifyFunction: (fn) => {
|
|
1343
|
-
notifyFn = fn;
|
|
1344
|
-
},
|
|
1345
|
-
/**
|
|
1346
|
-
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
1347
|
-
* Framework adapters use this to plug in their own batching primitive, so that a single query
|
|
1348
|
-
* update only triggers one re-render instead of one per subscriber.
|
|
1349
|
-
* @param fn - Receives a function that runs a batch of notifications and must call it.
|
|
1350
|
-
* @example
|
|
1351
|
-
* ```ts
|
|
1352
|
-
* import { notifyManager } from '@tanstack/query-core'
|
|
1353
|
-
* import { batch } from 'solid-js'
|
|
1354
|
-
*
|
|
1355
|
-
* notifyManager.setBatchNotifyFunction(batch)
|
|
1356
|
-
* ```
|
|
1357
|
-
*/
|
|
1358
|
-
setBatchNotifyFunction: (fn) => {
|
|
1359
|
-
batchNotifyFn = fn;
|
|
1360
|
-
},
|
|
1361
|
-
/**
|
|
1362
|
-
* Configures a custom callback that schedules when the next batch runs.
|
|
1363
|
-
* The default behavior is `setTimeout(callback, 0)`.
|
|
1364
|
-
* @param fn - Receives a callback that runs the next batch, and schedules it.
|
|
1365
|
-
* @example
|
|
1366
|
-
* ```ts
|
|
1367
|
-
* import { notifyManager } from '@tanstack/query-core'
|
|
1368
|
-
*
|
|
1369
|
-
* // Schedule batches in the next microtask
|
|
1370
|
-
* notifyManager.setScheduler(queueMicrotask)
|
|
1371
|
-
*
|
|
1372
|
-
* // Schedule batches before the next frame is rendered
|
|
1373
|
-
* notifyManager.setScheduler(requestAnimationFrame)
|
|
1374
|
-
*
|
|
1375
|
-
* // Schedule batches some time in the future
|
|
1376
|
-
* notifyManager.setScheduler((cb) => setTimeout(cb, 10))
|
|
1377
|
-
* ```
|
|
1378
|
-
*/
|
|
1379
|
-
setScheduler: (fn) => {
|
|
1380
|
-
scheduleFn = fn;
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
|
-
/**
|
|
1385
|
-
* Handles scheduling and batching callbacks in TanStack Query.
|
|
1386
|
-
*/
|
|
1387
|
-
var notifyManager = createNotifyManager();
|
|
1388
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/onlineManager.js
|
|
1389
|
-
/**
|
|
1390
|
-
* The `OnlineManager` manages the online state within TanStack Query. It can
|
|
1391
|
-
* be used to change the default event listeners or to manually change the
|
|
1392
|
-
* online state.
|
|
1393
|
-
*
|
|
1394
|
-
* By default, the `onlineManager` assumes an active network connection, and
|
|
1395
|
-
* listens to the `online` and `offline` events on the `window` object to
|
|
1396
|
-
* detect changes.
|
|
1397
|
-
*/
|
|
1398
|
-
var OnlineManager = class extends Subscribable {
|
|
1399
|
-
#online = true;
|
|
1400
|
-
#cleanup;
|
|
1401
|
-
#setup;
|
|
1402
|
-
constructor() {
|
|
1403
|
-
super();
|
|
1404
|
-
this.#setup = (onOnline) => {
|
|
1405
|
-
if (typeof window !== "undefined" && window.addEventListener) {
|
|
1406
|
-
const onlineListener = () => onOnline(true);
|
|
1407
|
-
const offlineListener = () => onOnline(false);
|
|
1408
|
-
window.addEventListener("online", onlineListener, false);
|
|
1409
|
-
window.addEventListener("offline", offlineListener, false);
|
|
1410
|
-
return () => {
|
|
1411
|
-
window.removeEventListener("online", onlineListener);
|
|
1412
|
-
window.removeEventListener("offline", offlineListener);
|
|
1413
|
-
};
|
|
1414
|
-
}
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
onSubscribe() {
|
|
1418
|
-
if (!this.#cleanup) this.setEventListener(this.#setup);
|
|
1419
|
-
}
|
|
1420
|
-
onUnsubscribe() {
|
|
1421
|
-
if (!this.hasListeners()) {
|
|
1422
|
-
this.#cleanup?.();
|
|
1423
|
-
this.#cleanup = void 0;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
/**
|
|
1427
|
-
* `setEventListener` can be used to set a custom event listener that will
|
|
1428
|
-
* be used to determine the online state. The provided `setup` function
|
|
1429
|
-
* receives a `setOnline` callback that should be called with a `boolean`
|
|
1430
|
-
* whenever the online state changes.
|
|
1431
|
-
* @param setup - Receives the `setOnline` callback, registers the event listener, and may return
|
|
1432
|
-
* a cleanup function that is called when the listener is replaced or no longer needed.
|
|
1433
|
-
* @example
|
|
1434
|
-
* ```ts
|
|
1435
|
-
* import NetInfo from '@react-native-community/netinfo'
|
|
1436
|
-
* import { onlineManager } from '@tanstack/query-core'
|
|
1437
|
-
*
|
|
1438
|
-
* onlineManager.setEventListener((setOnline) => {
|
|
1439
|
-
* return NetInfo.addEventListener((state) => {
|
|
1440
|
-
* setOnline(!!state.isConnected)
|
|
1441
|
-
* })
|
|
1442
|
-
* })
|
|
1443
|
-
* ```
|
|
1444
|
-
*/
|
|
1445
|
-
setEventListener(setup) {
|
|
1446
|
-
this.#setup = setup;
|
|
1447
|
-
this.#cleanup?.();
|
|
1448
|
-
this.#cleanup = setup(this.setOnline.bind(this));
|
|
1449
|
-
}
|
|
1450
|
-
/**
|
|
1451
|
-
* `setOnline` can be used to manually set the online state.
|
|
1452
|
-
* @param online - The online state.
|
|
1453
|
-
* @example
|
|
1454
|
-
* ```ts
|
|
1455
|
-
* import { onlineManager } from '@tanstack/query-core'
|
|
1456
|
-
*
|
|
1457
|
-
* // Set to online
|
|
1458
|
-
* onlineManager.setOnline(true)
|
|
1459
|
-
*
|
|
1460
|
-
* // Set to offline
|
|
1461
|
-
* onlineManager.setOnline(false)
|
|
1462
|
-
* ```
|
|
1463
|
-
*/
|
|
1464
|
-
setOnline(online) {
|
|
1465
|
-
if (this.#online !== online) {
|
|
1466
|
-
this.#online = online;
|
|
1467
|
-
this.listeners.forEach((listener) => {
|
|
1468
|
-
listener(online);
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
/**
|
|
1473
|
-
* `isOnline` can be used to get the current online state.
|
|
1474
|
-
* @returns `true` if online.
|
|
1475
|
-
*/
|
|
1476
|
-
isOnline() {
|
|
1477
|
-
return this.#online;
|
|
1478
|
-
}
|
|
1479
|
-
};
|
|
1480
|
-
/**
|
|
1481
|
-
* Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.
|
|
1482
|
-
*/
|
|
1483
|
-
var onlineManager = new OnlineManager();
|
|
1484
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/retryer.js
|
|
1485
|
-
/**
|
|
1486
|
-
* The default `retryDelay`: doubles with every failure, starting at 1 second, up to 30 seconds.
|
|
1487
|
-
* @param failureCount - The number of failures so far.
|
|
1488
|
-
* @returns The delay before the next retry, in milliseconds.
|
|
1489
|
-
*/
|
|
1490
|
-
function defaultRetryDelay(failureCount) {
|
|
1491
|
-
return Math.min(1e3 * 2 ** failureCount, 3e4);
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Checks whether a fetch can run for the given network mode.
|
|
1495
|
-
* @param networkMode - The `networkMode` option. Defaults to `'online'`.
|
|
1496
|
-
* @returns `true` if the network mode is not `'online'`, or if it is and the client is online.
|
|
1497
|
-
*/
|
|
1498
|
-
function canFetch(networkMode) {
|
|
1499
|
-
return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via
|
|
1503
|
-
* `query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch
|
|
1504
|
-
* started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead
|
|
1505
|
-
* resolve with the promise of the fetch that triggered the cancellation.
|
|
1506
|
-
* @example
|
|
1507
|
-
* ```ts
|
|
1508
|
-
* query.cancel()
|
|
1509
|
-
*
|
|
1510
|
-
* try {
|
|
1511
|
-
* await query.promise
|
|
1512
|
-
* } catch (error) {
|
|
1513
|
-
* if (error instanceof CancelledError) {
|
|
1514
|
-
* // the fetch was cancelled, e.g. via `query.cancel()`
|
|
1515
|
-
* }
|
|
1516
|
-
* }
|
|
1517
|
-
* ```
|
|
1518
|
-
*/
|
|
1519
|
-
var CancelledError = class extends Error {
|
|
1520
|
-
constructor(options) {
|
|
1521
|
-
super("CancelledError");
|
|
1522
|
-
this.revert = options?.revert;
|
|
1523
|
-
this.silent = options?.silent;
|
|
1524
|
-
}
|
|
1525
|
-
};
|
|
1526
|
-
/**
|
|
1527
|
-
* Creates a retryer, which runs a function and retries it on failure according to the `retry` and
|
|
1528
|
-
* `retryDelay` options. It pauses while the network mode doesn't allow fetching or `canRun` returns
|
|
1529
|
-
* `false`, and can be cancelled. Queries and mutations use it to run their `queryFn` and
|
|
1530
|
-
* `mutationFn`.
|
|
1531
|
-
* @param config - The function to run, the retry options, and the callbacks for failures, pausing,
|
|
1532
|
-
* continuing, and cancellation.
|
|
1533
|
-
* @returns The retryer, whose `promise` settles with the result of the function.
|
|
1534
|
-
*/
|
|
1535
|
-
function createRetryer(config) {
|
|
1536
|
-
let isRetryCancelled = false;
|
|
1537
|
-
let failureCount = 0;
|
|
1538
|
-
let continueFn;
|
|
1539
|
-
let status = "pending";
|
|
1540
|
-
let promiseResolve;
|
|
1541
|
-
let promiseReject;
|
|
1542
|
-
const promise = new Promise((resolve, reject) => {
|
|
1543
|
-
promiseResolve = resolve;
|
|
1544
|
-
promiseReject = reject;
|
|
1545
|
-
});
|
|
1546
|
-
promise.catch(noop);
|
|
1547
|
-
const isResolved = () => status !== "pending";
|
|
1548
|
-
const cancel = (cancelOptions) => {
|
|
1549
|
-
if (!isResolved()) {
|
|
1550
|
-
const error = new CancelledError(cancelOptions);
|
|
1551
|
-
reject(error);
|
|
1552
|
-
config.onCancel?.(error);
|
|
1553
|
-
}
|
|
1554
|
-
};
|
|
1555
|
-
const cancelRetry = () => {
|
|
1556
|
-
isRetryCancelled = true;
|
|
1557
|
-
};
|
|
1558
|
-
const continueRetry = () => {
|
|
1559
|
-
isRetryCancelled = false;
|
|
1560
|
-
};
|
|
1561
|
-
const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
|
|
1562
|
-
const canStart = () => canFetch(config.networkMode) && config.canRun();
|
|
1563
|
-
const resolve = (value) => {
|
|
1564
|
-
if (!isResolved()) {
|
|
1565
|
-
continueFn?.();
|
|
1566
|
-
status = "resolved";
|
|
1567
|
-
promiseResolve(value);
|
|
1568
|
-
}
|
|
1569
|
-
};
|
|
1570
|
-
const reject = (value) => {
|
|
1571
|
-
if (!isResolved()) {
|
|
1572
|
-
continueFn?.();
|
|
1573
|
-
status = "rejected";
|
|
1574
|
-
promiseReject(value);
|
|
1575
|
-
}
|
|
1576
|
-
};
|
|
1577
|
-
const pause = (canResume) => {
|
|
1578
|
-
return new Promise((continueResolve) => {
|
|
1579
|
-
continueFn = (value) => {
|
|
1580
|
-
if (isResolved() || canResume()) continueResolve(value);
|
|
1581
|
-
};
|
|
1582
|
-
config.onPause?.();
|
|
1583
|
-
}).then(() => {
|
|
1584
|
-
continueFn = void 0;
|
|
1585
|
-
if (!isResolved()) config.onContinue?.();
|
|
1586
|
-
});
|
|
1587
|
-
};
|
|
1588
|
-
const run = () => {
|
|
1589
|
-
if (isResolved()) return;
|
|
1590
|
-
let promiseOrValue;
|
|
1591
|
-
const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
|
|
1592
|
-
try {
|
|
1593
|
-
promiseOrValue = initialPromise ?? config.fn();
|
|
1594
|
-
} catch (error) {
|
|
1595
|
-
promiseOrValue = Promise.reject(error);
|
|
1596
|
-
}
|
|
1597
|
-
Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
|
|
1598
|
-
if (isResolved()) return;
|
|
1599
|
-
const retry = config.retry ?? (isServer() ? 0 : 3);
|
|
1600
|
-
const retryDelay = config.retryDelay ?? defaultRetryDelay;
|
|
1601
|
-
const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
|
|
1602
|
-
const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
|
|
1603
|
-
if (isRetryCancelled || !shouldRetry) {
|
|
1604
|
-
reject(error);
|
|
1605
|
-
return;
|
|
1606
|
-
}
|
|
1607
|
-
failureCount++;
|
|
1608
|
-
config.onFail?.(failureCount, error);
|
|
1609
|
-
sleep(delay).then(() => {
|
|
1610
|
-
return isResolved() || canContinue() ? void 0 : pause(canContinue);
|
|
1611
|
-
}).then(() => {
|
|
1612
|
-
if (isRetryCancelled) reject(error);
|
|
1613
|
-
else run();
|
|
1614
|
-
});
|
|
1615
|
-
});
|
|
1616
|
-
};
|
|
1617
|
-
return {
|
|
1618
|
-
promise,
|
|
1619
|
-
status: () => status,
|
|
1620
|
-
cancel,
|
|
1621
|
-
continue: () => {
|
|
1622
|
-
continueFn?.();
|
|
1623
|
-
return promise;
|
|
1624
|
-
},
|
|
1625
|
-
cancelRetry,
|
|
1626
|
-
continueRetry,
|
|
1627
|
-
canStart,
|
|
1628
|
-
start: () => {
|
|
1629
|
-
if (canStart()) run();
|
|
1630
|
-
else pause(canStart).then(run);
|
|
1631
|
-
return promise;
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
}
|
|
1635
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/removable.js
|
|
1636
|
-
/**
|
|
1637
|
-
* The base class for cache entries that are garbage collected once nothing is using them —
|
|
1638
|
-
* `Query` and `Mutation` both extend it. `gcTime` controls how long an unused entry is kept.
|
|
1639
|
-
*/
|
|
1640
|
-
var Removable = class {
|
|
1641
|
-
#gcTimeout;
|
|
1642
|
-
/**
|
|
1643
|
-
* Clears the pending garbage collection timeout, so the entry is no longer scheduled for removal.
|
|
1644
|
-
* A subclass may override this to release what it holds on to as well — `Query` also cancels any
|
|
1645
|
-
* in-flight fetch.
|
|
1646
|
-
*/
|
|
1647
|
-
destroy() {
|
|
1648
|
-
this.clearGcTimeout();
|
|
1649
|
-
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Schedules the entry to be removed from its cache after `gcTime`, replacing any timeout scheduled
|
|
1652
|
-
* before. Nothing is scheduled if `gcTime` is `Infinity`.
|
|
1653
|
-
*/
|
|
1654
|
-
scheduleGc() {
|
|
1655
|
-
this.clearGcTimeout();
|
|
1656
|
-
if (isValidTimeout(this.gcTime)) this.#gcTimeout = timeoutManager.setTimeout(() => {
|
|
1657
|
-
this.optionalRemove();
|
|
1658
|
-
}, this.gcTime);
|
|
1659
|
-
}
|
|
1660
|
-
/**
|
|
1661
|
-
* Updates `gcTime`, keeping the longest one seen so far. Without a value, it defaults to 5 minutes
|
|
1662
|
-
* on the client and `Infinity` on the server.
|
|
1663
|
-
* @param newGcTime - The `gcTime` from the latest options, if any.
|
|
1664
|
-
*/
|
|
1665
|
-
updateGcTime(newGcTime) {
|
|
1666
|
-
this.gcTime = Math.max(this.gcTime || 0, newGcTime ?? (isServer() ? Infinity : 3e5));
|
|
1667
|
-
}
|
|
1668
|
-
/**
|
|
1669
|
-
* Cancels the scheduled removal, if there is one.
|
|
1670
|
-
*/
|
|
1671
|
-
clearGcTimeout() {
|
|
1672
|
-
if (this.#gcTimeout !== void 0) {
|
|
1673
|
-
timeoutManager.clearTimeout(this.#gcTimeout);
|
|
1674
|
-
this.#gcTimeout = void 0;
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
};
|
|
1678
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
|
|
1679
|
-
/**
|
|
1680
|
-
* Creates the behavior that fetches the pages of an infinite query: the next or previous page for
|
|
1681
|
-
* `fetchNextPage`/`fetchPreviousPage`, or all pages again from the start on a refetch.
|
|
1682
|
-
* @param pages - The number of pages to fetch from the start when all pages are fetched again,
|
|
1683
|
-
* e.g. from the `pages` option of `queryClient.infiniteQuery`. Defaults to the number of cached
|
|
1684
|
-
* pages.
|
|
1685
|
-
* @returns The query behavior to set on an infinite query.
|
|
1686
|
-
*/
|
|
1687
|
-
function infiniteQueryBehavior(pages) {
|
|
1688
|
-
return { onFetch: (context, query) => {
|
|
1689
|
-
const options = context.options;
|
|
1690
|
-
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
|
|
1691
|
-
const oldPages = context.state.data?.pages || [];
|
|
1692
|
-
const oldPageParams = context.state.data?.pageParams || [];
|
|
1693
|
-
let result = {
|
|
1694
|
-
pages: [],
|
|
1695
|
-
pageParams: []
|
|
1696
|
-
};
|
|
1697
|
-
let currentPage = 0;
|
|
1698
|
-
const fetchFn = async () => {
|
|
1699
|
-
let cancelled = false;
|
|
1700
|
-
const signalContext = context;
|
|
1701
|
-
const addSignalProperty = (object) => {
|
|
1702
|
-
addConsumeAwareSignal(object, () => context.signal, () => cancelled = true, signalContext[fetchSignal]);
|
|
1703
|
-
};
|
|
1704
|
-
const queryFn = ensureQueryFn(context.options, context.fetchOptions);
|
|
1705
|
-
const fetchPage = async (data, param, previous) => {
|
|
1706
|
-
if (cancelled) return Promise.reject(context.signal.reason);
|
|
1707
|
-
if (param == null && data.pages.length) return Promise.resolve(data);
|
|
1708
|
-
const createQueryFnContext = () => {
|
|
1709
|
-
const queryFnContext = {
|
|
1710
|
-
client: context.client,
|
|
1711
|
-
queryKey: context.queryKey,
|
|
1712
|
-
pageParam: param,
|
|
1713
|
-
direction: previous ? "backward" : "forward",
|
|
1714
|
-
meta: context.options.meta
|
|
1715
|
-
};
|
|
1716
|
-
addSignalProperty(queryFnContext);
|
|
1717
|
-
return queryFnContext;
|
|
1718
|
-
};
|
|
1719
|
-
const queryFnContext = createQueryFnContext();
|
|
1720
|
-
const page = await queryFn(queryFnContext);
|
|
1721
|
-
const { maxPages } = context.options;
|
|
1722
|
-
const addTo = previous ? addToStart : addToEnd;
|
|
1723
|
-
return {
|
|
1724
|
-
pages: addTo(data.pages, page, maxPages),
|
|
1725
|
-
pageParams: addTo(data.pageParams, param, maxPages)
|
|
1726
|
-
};
|
|
1727
|
-
};
|
|
1728
|
-
if (direction && oldPages.length) {
|
|
1729
|
-
const previous = direction === "backward";
|
|
1730
|
-
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
1731
|
-
const oldData = {
|
|
1732
|
-
pages: oldPages,
|
|
1733
|
-
pageParams: oldPageParams
|
|
1734
|
-
};
|
|
1735
|
-
result = await fetchPage(oldData, pageParamFn(options, oldData), previous);
|
|
1736
|
-
} else {
|
|
1737
|
-
const remainingPages = pages ?? oldPages.length;
|
|
1738
|
-
do {
|
|
1739
|
-
const param = currentPage === 0 ? oldPageParams[0] === void 0 ? options.initialPageParam : oldPageParams[0] : getNextPageParam(options, result);
|
|
1740
|
-
if (currentPage > 0 && param == null) break;
|
|
1741
|
-
result = await fetchPage(result, param);
|
|
1742
|
-
currentPage++;
|
|
1743
|
-
} while (currentPage < remainingPages);
|
|
1744
|
-
}
|
|
1745
|
-
return result;
|
|
1746
|
-
};
|
|
1747
|
-
if (context.options.persister) context.fetchFn = () => {
|
|
1748
|
-
return context.options.persister?.(fetchFn, {
|
|
1749
|
-
client: context.client,
|
|
1750
|
-
queryKey: context.queryKey,
|
|
1751
|
-
meta: context.options.meta,
|
|
1752
|
-
signal: context.signal
|
|
1753
|
-
}, query);
|
|
1754
|
-
};
|
|
1755
|
-
else context.fetchFn = fetchFn;
|
|
1756
|
-
} };
|
|
1757
|
-
}
|
|
1758
|
-
/**
|
|
1759
|
-
* Computes the page param of the page after the last one, with the `getNextPageParam` option.
|
|
1760
|
-
* @param options - The infinite query options.
|
|
1761
|
-
* @param data - The current pages and page params.
|
|
1762
|
-
* @returns The next page param, or `undefined` if there are no pages yet.
|
|
1763
|
-
*/
|
|
1764
|
-
function getNextPageParam(options, { pages, pageParams }) {
|
|
1765
|
-
const lastIndex = pages.length - 1;
|
|
1766
|
-
return pages.length > 0 ? options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams) : void 0;
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* Computes the page param of the page before the first one, with the `getPreviousPageParam`
|
|
1770
|
-
* option.
|
|
1771
|
-
* @param options - The infinite query options.
|
|
1772
|
-
* @param data - The current pages and page params.
|
|
1773
|
-
* @returns The previous page param, or `undefined` if there are no pages yet or no
|
|
1774
|
-
* `getPreviousPageParam` option.
|
|
1775
|
-
*/
|
|
1776
|
-
function getPreviousPageParam(options, { pages, pageParams }) {
|
|
1777
|
-
return pages.length > 0 ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0;
|
|
1778
|
-
}
|
|
1779
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/query.js
|
|
1780
|
-
/**
|
|
1781
|
-
* Represents a single cached query. A `Query` holds the query's key, options,
|
|
1782
|
-
* state (data/error/status), and the observers currently subscribed to it.
|
|
1783
|
-
*
|
|
1784
|
-
* Instances are created and managed internally by `QueryCache`; application
|
|
1785
|
-
* code typically interacts with queries indirectly through `QueryClient` or
|
|
1786
|
-
* a framework hook like `useQuery`. Direct access to a `Query` instance is
|
|
1787
|
-
* possible via `queryCache.find()`/`findAll()` for inspecting cache state.
|
|
1788
|
-
* @example
|
|
1789
|
-
* ```ts
|
|
1790
|
-
* const queryCache = queryClient.getQueryCache()
|
|
1791
|
-
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
1792
|
-
*
|
|
1793
|
-
* if (query) {
|
|
1794
|
-
* console.log(query.state.dataUpdatedAt)
|
|
1795
|
-
* }
|
|
1796
|
-
* ```
|
|
1797
|
-
*/
|
|
1798
|
-
var Query = class extends Removable {
|
|
1799
|
-
#queryType;
|
|
1800
|
-
#initialState;
|
|
1801
|
-
#revertState;
|
|
1802
|
-
#cache;
|
|
1803
|
-
#client;
|
|
1804
|
-
#retryer;
|
|
1805
|
-
#fetchPromise;
|
|
1806
|
-
#defaultOptions;
|
|
1807
|
-
#abortSignalConsumed;
|
|
1808
|
-
constructor(config) {
|
|
1809
|
-
super();
|
|
1810
|
-
this.#abortSignalConsumed = false;
|
|
1811
|
-
this.#defaultOptions = config.defaultOptions;
|
|
1812
|
-
this.setOptions(config.options);
|
|
1813
|
-
this.observers = [];
|
|
1814
|
-
this.#client = config.client;
|
|
1815
|
-
this.#cache = this.#client.getQueryCache();
|
|
1816
|
-
this.queryKey = config.queryKey;
|
|
1817
|
-
this.queryHash = config.queryHash;
|
|
1818
|
-
this.#initialState = getDefaultState(this.options);
|
|
1819
|
-
this.state = config.state ?? this.#initialState;
|
|
1820
|
-
this.scheduleGc();
|
|
1821
|
-
}
|
|
1822
|
-
/**
|
|
1823
|
-
* The `meta` object passed in the query's options, if any.
|
|
1824
|
-
* @returns The query's `meta`, or `undefined` if none was set.
|
|
1825
|
-
*/
|
|
1826
|
-
get meta() {
|
|
1827
|
-
return this.options.meta;
|
|
1828
|
-
}
|
|
1829
|
-
/**
|
|
1830
|
-
* `'infinite'` for an infinite query, otherwise `undefined`.
|
|
1831
|
-
* @internal
|
|
1832
|
-
* @returns The type of the query, set from the `_type` option (e.g. `'infinite'`).
|
|
1833
|
-
*/
|
|
1834
|
-
get queryType() {
|
|
1835
|
-
return this.#queryType;
|
|
1836
|
-
}
|
|
1837
|
-
/**
|
|
1838
|
-
* The promise for the currently in-flight fetch, if the query is fetching.
|
|
1839
|
-
* `undefined` when the query is not fetching.
|
|
1840
|
-
* @returns The promise of the in-flight fetch, or `undefined`.
|
|
1841
|
-
*/
|
|
1842
|
-
get promise() {
|
|
1843
|
-
return this.#retryer?.promise;
|
|
1844
|
-
}
|
|
1845
|
-
/**
|
|
1846
|
-
* Replaces the query's options and applies their `gcTime`. If the query has no data yet, it gets
|
|
1847
|
-
* the `initialData` from the new options, if any.
|
|
1848
|
-
* @internal
|
|
1849
|
-
* @param options - The new query options, merged on top of the query's default options.
|
|
1850
|
-
*/
|
|
1851
|
-
setOptions(options) {
|
|
1852
|
-
this.options = {
|
|
1853
|
-
...this.#defaultOptions,
|
|
1854
|
-
...options
|
|
1855
|
-
};
|
|
1856
|
-
if (options?._type) this.#queryType = options._type;
|
|
1857
|
-
this.updateGcTime(this.options.gcTime);
|
|
1858
|
-
if (this.state && this.state.data === void 0) {
|
|
1859
|
-
const defaultState = getDefaultState(this.options);
|
|
1860
|
-
if (defaultState.data !== void 0) {
|
|
1861
|
-
this.setState(successState(defaultState.data, defaultState.dataUpdatedAt));
|
|
1862
|
-
this.#initialState = defaultState;
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
optionalRemove() {
|
|
1867
|
-
if (!this.observers.length && this.state.fetchStatus === "idle") this.#cache.remove(this);
|
|
1868
|
-
}
|
|
1869
|
-
/**
|
|
1870
|
-
* Writes new data to the query and marks it as successfully fetched.
|
|
1871
|
-
* @internal
|
|
1872
|
-
* @param newData - The data to write. Structural sharing with the current data is applied.
|
|
1873
|
-
* @param options - Set `updatedAt` to override the timestamp, and `manual` to mark the write as
|
|
1874
|
-
* manual (e.g. from `queryClient.setQueryData`).
|
|
1875
|
-
* @returns The data that was written.
|
|
1876
|
-
*/
|
|
1877
|
-
setData(newData, options) {
|
|
1878
|
-
const data = replaceData(this.state.data, newData, this.options);
|
|
1879
|
-
this.#dispatch({
|
|
1880
|
-
data,
|
|
1881
|
-
type: "success",
|
|
1882
|
-
dataUpdatedAt: options?.updatedAt,
|
|
1883
|
-
manual: options?.manual
|
|
1884
|
-
});
|
|
1885
|
-
return data;
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Merges the given partial state directly into this query's state, notifying observers. Used
|
|
1889
|
-
* by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a
|
|
1890
|
-
* user manually trigger a loading/error state or edit the cached data.
|
|
1891
|
-
* @param state - The partial state to merge into the query's state.
|
|
1892
|
-
*/
|
|
1893
|
-
setState(state) {
|
|
1894
|
-
this.#dispatch({
|
|
1895
|
-
type: "setState",
|
|
1896
|
-
state
|
|
1897
|
-
});
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
* Cancels the query's currently in-flight fetch, if any.
|
|
1901
|
-
* - Returns a promise that resolves once the cancellation has settled.
|
|
1902
|
-
* - If no fetch is in progress, resolves immediately.
|
|
1903
|
-
* @param options - Set `revert` to restore the state from before the fetch started, and `silent`
|
|
1904
|
-
* to suppress the cancellation error when a new fetch replaces the cancelled one.
|
|
1905
|
-
* @returns A promise that resolves once the cancellation has settled.
|
|
1906
|
-
* @example
|
|
1907
|
-
* ```ts
|
|
1908
|
-
* await query.cancel()
|
|
1909
|
-
* ```
|
|
1910
|
-
*/
|
|
1911
|
-
cancel(options) {
|
|
1912
|
-
const promise = this.#retryer?.promise;
|
|
1913
|
-
this.#retryer?.cancel(options);
|
|
1914
|
-
return promise ? promise.then(noop).catch(noop) : Promise.resolve();
|
|
1915
|
-
}
|
|
1916
|
-
/**
|
|
1917
|
-
* Clears the query's garbage collection timeout and silently cancels any
|
|
1918
|
-
* in-flight fetch. Called by `QueryCache` when the query is removed from
|
|
1919
|
-
* the cache.
|
|
1920
|
-
* @see {@link Query#cancel}
|
|
1921
|
-
*/
|
|
1922
|
-
destroy() {
|
|
1923
|
-
super.destroy();
|
|
1924
|
-
this.cancel({ silent: true });
|
|
1925
|
-
}
|
|
1926
|
-
/**
|
|
1927
|
-
* The state the query was created with.
|
|
1928
|
-
* @internal
|
|
1929
|
-
* @returns The state the query had when it was first created, used by {@link Query#reset}.
|
|
1930
|
-
*/
|
|
1931
|
-
get resetState() {
|
|
1932
|
-
return this.#initialState;
|
|
1933
|
-
}
|
|
1934
|
-
/**
|
|
1935
|
-
* Resets the query back to its initial state (the state it had when it was
|
|
1936
|
-
* first created, e.g. any `initialData`), destroying it first to cancel any
|
|
1937
|
-
* in-flight fetch.
|
|
1938
|
-
*/
|
|
1939
|
-
reset() {
|
|
1940
|
-
this.destroy();
|
|
1941
|
-
this.setState(this.resetState);
|
|
1942
|
-
}
|
|
1943
|
-
/**
|
|
1944
|
-
* Returns `true` if the query has at least one observer for which `enabled`
|
|
1945
|
-
* does not resolve to `false`.
|
|
1946
|
-
* @returns `true` if the query has an enabled observer.
|
|
1947
|
-
*/
|
|
1948
|
-
isActive() {
|
|
1949
|
-
return this.observers.some((observer) => resolveQueryValue(observer.options.enabled, this) !== false);
|
|
1950
|
-
}
|
|
1951
|
-
/**
|
|
1952
|
-
* Returns `true` if the query is disabled, meaning it will not fetch
|
|
1953
|
-
* automatically.
|
|
1954
|
-
* - If the query has observers, it is disabled when none of them are active
|
|
1955
|
-
* (see `isActive`).
|
|
1956
|
-
* - If the query has no observers, it is disabled when its `queryFn` is
|
|
1957
|
-
* `skipToken` or it has never been fetched.
|
|
1958
|
-
* @returns `true` if the query is disabled.
|
|
1959
|
-
*/
|
|
1960
|
-
isDisabled() {
|
|
1961
|
-
if (this.getObserversCount() > 0) return !this.isActive();
|
|
1962
|
-
return this.options.queryFn === skipToken || !this.isFetched();
|
|
1963
|
-
}
|
|
1964
|
-
/**
|
|
1965
|
-
* Returns `true` if the query has been fetched, i.e. it has resolved with
|
|
1966
|
-
* either data or an error at least once.
|
|
1967
|
-
* @returns `true` if the query has been fetched.
|
|
1968
|
-
*/
|
|
1969
|
-
isFetched() {
|
|
1970
|
-
return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
|
|
1971
|
-
}
|
|
1972
|
-
/**
|
|
1973
|
-
* Returns `true` if the query has data and at least one observer configured with
|
|
1974
|
-
* `staleTime: 'static'`, meaning it is treated as never stale.
|
|
1975
|
-
* @returns `true` if the query is static.
|
|
1976
|
-
*/
|
|
1977
|
-
isStatic() {
|
|
1978
|
-
if (this.state.data === void 0) return false;
|
|
1979
|
-
if (this.getObserversCount() > 0) return this.observers.some((observer) => resolveQueryValue(observer.options.staleTime, this) === "static");
|
|
1980
|
-
return false;
|
|
1981
|
-
}
|
|
1982
|
-
/**
|
|
1983
|
-
* Returns `true` if the query is stale.
|
|
1984
|
-
* - If the query has observers, defers to whether any observer's current
|
|
1985
|
-
* result reports `isStale` (which accounts for each observer's own
|
|
1986
|
-
* `staleTime` and `enabled` state).
|
|
1987
|
-
* - If the query has no observers, it is considered stale when it has no
|
|
1988
|
-
* data or has been invalidated.
|
|
1989
|
-
* @returns `true` if the query is stale.
|
|
1990
|
-
* @see {@link Query#isStaleByTime}
|
|
1991
|
-
* @example
|
|
1992
|
-
* ```ts
|
|
1993
|
-
* if (query.isStale()) {
|
|
1994
|
-
* // refetch or otherwise treat the cached data as outdated
|
|
1995
|
-
* }
|
|
1996
|
-
* ```
|
|
1997
|
-
*/
|
|
1998
|
-
isStale() {
|
|
1999
|
-
if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale);
|
|
2000
|
-
return this.state.data === void 0 || this.state.isInvalidated;
|
|
2001
|
-
}
|
|
2002
|
-
/**
|
|
2003
|
-
* Returns `true` if the query's data is stale relative to the given
|
|
2004
|
-
* `staleTime` (defaults to `0`).
|
|
2005
|
-
* - A query with no data is always stale.
|
|
2006
|
-
* - `staleTime: 'static'` is never stale.
|
|
2007
|
-
* - An invalidated query is always stale.
|
|
2008
|
-
* - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.
|
|
2009
|
-
* @param staleTime - The time, in milliseconds, after which data is considered stale, or
|
|
2010
|
-
* `'static'` to never treat existing data as stale. A query without data is stale either way.
|
|
2011
|
-
* @returns `true` if the query's data is stale.
|
|
2012
|
-
* @see {@link Query#isStale}
|
|
2013
|
-
* @example
|
|
2014
|
-
* ```ts
|
|
2015
|
-
* const isStale = query.isStaleByTime(60 * 1000)
|
|
2016
|
-
* ```
|
|
2017
|
-
*/
|
|
2018
|
-
isStaleByTime(staleTime = 0) {
|
|
2019
|
-
if (this.state.data === void 0) return true;
|
|
2020
|
-
if (staleTime === "static") return false;
|
|
2021
|
-
if (this.state.isInvalidated) return true;
|
|
2022
|
-
return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
|
|
2023
|
-
}
|
|
2024
|
-
/**
|
|
2025
|
-
* Refetches the query when the window regains focus, if an observer wants that, and continues a
|
|
2026
|
-
* paused fetch.
|
|
2027
|
-
* @internal
|
|
2028
|
-
*/
|
|
2029
|
-
onFocus() {
|
|
2030
|
-
this.observers.find((x) => x.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: false });
|
|
2031
|
-
this.#retryer?.continue();
|
|
2032
|
-
}
|
|
2033
|
-
/**
|
|
2034
|
-
* Refetches the query when the app reconnects, if an observer wants that, and continues a paused
|
|
2035
|
-
* fetch.
|
|
2036
|
-
* @internal
|
|
2037
|
-
*/
|
|
2038
|
-
onOnline() {
|
|
2039
|
-
this.observers.find((x) => x.shouldFetchOnReconnect())?.refetch({ cancelRefetch: false });
|
|
2040
|
-
this.#retryer?.continue();
|
|
2041
|
-
}
|
|
2042
|
-
/**
|
|
2043
|
-
* Subscribes an observer to the query and stops its garbage collection.
|
|
2044
|
-
* @internal
|
|
2045
|
-
* @param observer - The observer to add. Adding an observer that is already subscribed does
|
|
2046
|
-
* nothing.
|
|
2047
|
-
*/
|
|
2048
|
-
addObserver(observer) {
|
|
2049
|
-
if (!this.observers.includes(observer)) {
|
|
2050
|
-
this.observers.push(observer);
|
|
2051
|
-
this.clearGcTimeout();
|
|
2052
|
-
this.#cache.notify({
|
|
2053
|
-
type: "observerAdded",
|
|
2054
|
-
query: this,
|
|
2055
|
-
observer
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
/**
|
|
2060
|
-
* Unsubscribes an observer from the query.
|
|
2061
|
-
* @internal
|
|
2062
|
-
* @param observer - The observer to remove. When the last observer is removed, the in-flight
|
|
2063
|
-
* fetch is cancelled if its abort signal was consumed (otherwise only its retries are stopped),
|
|
2064
|
-
* and garbage collection is scheduled.
|
|
2065
|
-
*/
|
|
2066
|
-
removeObserver(observer) {
|
|
2067
|
-
const index = this.observers.indexOf(observer);
|
|
2068
|
-
if (index !== -1) {
|
|
2069
|
-
this.observers.splice(index, 1);
|
|
2070
|
-
if (!this.observers.length) {
|
|
2071
|
-
if (this.#retryer) {
|
|
2072
|
-
if (this.#abortSignalConsumed || this.state.fetchStatus === "paused" && this.state.status === "pending") this.#retryer.cancel({ revert: true });
|
|
2073
|
-
else this.#retryer.cancelRetry();
|
|
2074
|
-
}
|
|
2075
|
-
this.scheduleGc();
|
|
2076
|
-
}
|
|
2077
|
-
this.#cache.notify({
|
|
2078
|
-
type: "observerRemoved",
|
|
2079
|
-
query: this,
|
|
2080
|
-
observer
|
|
2081
|
-
});
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
/**
|
|
2085
|
-
* Returns the number of observers currently subscribed to this query.
|
|
2086
|
-
* @returns The number of observers.
|
|
2087
|
-
* @example
|
|
2088
|
-
* ```ts
|
|
2089
|
-
* if (query.getObserversCount() === 0) {
|
|
2090
|
-
* // no component is currently watching this query
|
|
2091
|
-
* }
|
|
2092
|
-
* ```
|
|
2093
|
-
*/
|
|
2094
|
-
getObserversCount() {
|
|
2095
|
-
return this.observers.length;
|
|
2096
|
-
}
|
|
2097
|
-
/**
|
|
2098
|
-
* Marks the query as invalidated, unless it is already invalidated. This
|
|
2099
|
-
* updates `state.isInvalidated` and notifies observers, but does not by
|
|
2100
|
-
* itself trigger a refetch.
|
|
2101
|
-
* @example
|
|
2102
|
-
* ```ts
|
|
2103
|
-
* query.invalidate()
|
|
2104
|
-
* ```
|
|
2105
|
-
*/
|
|
2106
|
-
invalidate() {
|
|
2107
|
-
if (!this.state.isInvalidated) this.#dispatch({ type: "invalidate" });
|
|
2108
|
-
}
|
|
2109
|
-
/**
|
|
2110
|
-
* Fetches the query, i.e. runs its `queryFn` (through any configured
|
|
2111
|
-
* retryer/behavior) and updates the query's state with the result.
|
|
2112
|
-
* - If a fetch is already in flight, returns its promise instead of
|
|
2113
|
-
* starting a new one, unless `fetchOptions.cancelRefetch` is set and the
|
|
2114
|
-
* query already has data, in which case the current fetch is silently
|
|
2115
|
-
* cancelled first.
|
|
2116
|
-
* - If `options` is passed, it replaces the query's current options
|
|
2117
|
-
* before fetching.
|
|
2118
|
-
* @param options - Query options that replace the query's current options before fetching. They
|
|
2119
|
-
* are not applied when an in-flight fetch is reused.
|
|
2120
|
-
* @param fetchOptions - Set `cancelRefetch` to cancel an in-flight fetch first (only if the query
|
|
2121
|
-
* already has data), and `meta` to pass extra information to the query's behavior.
|
|
2122
|
-
* @returns A promise that resolves with the fetched data, or rejects with the fetch error. If the
|
|
2123
|
-
* fetch is cancelled with `revert` while the query has data, it resolves with the restored data
|
|
2124
|
-
* instead.
|
|
2125
|
-
*/
|
|
2126
|
-
async fetch(options, fetchOptions) {
|
|
2127
|
-
if (this.state.fetchStatus !== "idle" && this.#retryer?.status() !== "rejected") {
|
|
2128
|
-
if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) this.cancel({ silent: true });
|
|
2129
|
-
else if (this.#retryer && this.#fetchPromise) {
|
|
2130
|
-
this.#retryer.continueRetry();
|
|
2131
|
-
return this.#fetchPromise;
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
if (options) this.setOptions(options);
|
|
2135
|
-
if (!this.options.queryFn) {
|
|
2136
|
-
const observer = this.observers.find((x) => x.options.queryFn);
|
|
2137
|
-
if (observer) this.setOptions(observer.options);
|
|
2138
|
-
}
|
|
2139
|
-
const abortController = new AbortController();
|
|
2140
|
-
const addSignalProperty = (object) => {
|
|
2141
|
-
Object.defineProperties(object, {
|
|
2142
|
-
[fetchSignal]: {
|
|
2143
|
-
value: abortController.signal,
|
|
2144
|
-
enumerable: true
|
|
2145
|
-
},
|
|
2146
|
-
signal: {
|
|
2147
|
-
enumerable: true,
|
|
2148
|
-
get: () => {
|
|
2149
|
-
this.#abortSignalConsumed = true;
|
|
2150
|
-
return abortController.signal;
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
});
|
|
2154
|
-
};
|
|
2155
|
-
const fetchFn = () => {
|
|
2156
|
-
const queryFn = ensureQueryFn(this.options, fetchOptions);
|
|
2157
|
-
const createQueryFnContext = () => {
|
|
2158
|
-
const queryFnContext = {
|
|
2159
|
-
client: this.#client,
|
|
2160
|
-
queryKey: this.queryKey,
|
|
2161
|
-
meta: this.meta
|
|
2162
|
-
};
|
|
2163
|
-
addSignalProperty(queryFnContext);
|
|
2164
|
-
return queryFnContext;
|
|
2165
|
-
};
|
|
2166
|
-
const queryFnContext = createQueryFnContext();
|
|
2167
|
-
this.#abortSignalConsumed = false;
|
|
2168
|
-
if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this);
|
|
2169
|
-
return queryFn(queryFnContext);
|
|
2170
|
-
};
|
|
2171
|
-
const createFetchContext = () => {
|
|
2172
|
-
const context = {
|
|
2173
|
-
fetchOptions,
|
|
2174
|
-
options: this.options,
|
|
2175
|
-
queryKey: this.queryKey,
|
|
2176
|
-
client: this.#client,
|
|
2177
|
-
state: this.state,
|
|
2178
|
-
fetchFn
|
|
2179
|
-
};
|
|
2180
|
-
addSignalProperty(context);
|
|
2181
|
-
return context;
|
|
2182
|
-
};
|
|
2183
|
-
const context = createFetchContext();
|
|
2184
|
-
(this.#queryType === "infinite" ? infiniteQueryBehavior(this.options.pages) : this.options.behavior)?.onFetch(context, this);
|
|
2185
|
-
this.#revertState = this.state;
|
|
2186
|
-
if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) this.#dispatch({
|
|
2187
|
-
type: "fetch",
|
|
2188
|
-
meta: context.fetchOptions?.meta
|
|
2189
|
-
});
|
|
2190
|
-
const retryer = this.#retryer = createRetryer({
|
|
2191
|
-
initialPromise: fetchOptions?.initialPromise,
|
|
2192
|
-
fn: context.fetchFn,
|
|
2193
|
-
onCancel: (error) => {
|
|
2194
|
-
if (error instanceof CancelledError && error.revert) this.setState({
|
|
2195
|
-
...this.#revertState,
|
|
2196
|
-
fetchStatus: "idle"
|
|
2197
|
-
});
|
|
2198
|
-
abortController.abort();
|
|
2199
|
-
},
|
|
2200
|
-
onFail: (failureCount, error) => {
|
|
2201
|
-
this.#dispatch({
|
|
2202
|
-
type: "failed",
|
|
2203
|
-
failureCount,
|
|
2204
|
-
error
|
|
2205
|
-
});
|
|
2206
|
-
},
|
|
2207
|
-
onPause: () => {
|
|
2208
|
-
this.#dispatch({ type: "pause" });
|
|
2209
|
-
},
|
|
2210
|
-
onContinue: () => {
|
|
2211
|
-
this.#dispatch({ type: "continue" });
|
|
2212
|
-
},
|
|
2213
|
-
retry: context.options.retry,
|
|
2214
|
-
retryDelay: context.options.retryDelay,
|
|
2215
|
-
networkMode: context.options.networkMode,
|
|
2216
|
-
canRun: () => true
|
|
2217
|
-
});
|
|
2218
|
-
const fetchPromise = (async () => {
|
|
2219
|
-
try {
|
|
2220
|
-
const data = await retryer.promise;
|
|
2221
|
-
if (data === void 0) throw new Error(`${this.queryHash} data is undefined`);
|
|
2222
|
-
this.setData(data);
|
|
2223
|
-
this.#cache.config.onSuccess?.(data, this);
|
|
2224
|
-
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
2225
|
-
return data;
|
|
2226
|
-
} catch (error) {
|
|
2227
|
-
if (error instanceof CancelledError) {
|
|
2228
|
-
if (error.silent) {
|
|
2229
|
-
if (this.#retryer !== retryer && this.#fetchPromise) return this.#fetchPromise;
|
|
2230
|
-
throw error;
|
|
2231
|
-
} else if (error.revert) {
|
|
2232
|
-
if (this.state.data === void 0) throw error;
|
|
2233
|
-
return this.state.data;
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
this.#dispatch({
|
|
2237
|
-
type: "error",
|
|
2238
|
-
error
|
|
2239
|
-
});
|
|
2240
|
-
this.#cache.config.onError?.(error, this);
|
|
2241
|
-
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
2242
|
-
throw error;
|
|
2243
|
-
} finally {
|
|
2244
|
-
if (this.#retryer === retryer) {
|
|
2245
|
-
this.#retryer = void 0;
|
|
2246
|
-
this.#fetchPromise = void 0;
|
|
2247
|
-
}
|
|
2248
|
-
this.scheduleGc();
|
|
2249
|
-
}
|
|
2250
|
-
})();
|
|
2251
|
-
this.#fetchPromise = fetchPromise;
|
|
2252
|
-
retryer.start();
|
|
2253
|
-
return fetchPromise;
|
|
2254
|
-
}
|
|
2255
|
-
#dispatch(action) {
|
|
2256
|
-
const reducer = (state) => {
|
|
2257
|
-
switch (action.type) {
|
|
2258
|
-
case "failed": return {
|
|
2259
|
-
...state,
|
|
2260
|
-
fetchFailureCount: action.failureCount,
|
|
2261
|
-
fetchFailureReason: action.error
|
|
2262
|
-
};
|
|
2263
|
-
case "pause": return {
|
|
2264
|
-
...state,
|
|
2265
|
-
fetchStatus: "paused"
|
|
2266
|
-
};
|
|
2267
|
-
case "continue": return {
|
|
2268
|
-
...state,
|
|
2269
|
-
fetchStatus: "fetching"
|
|
2270
|
-
};
|
|
2271
|
-
case "fetch": return {
|
|
2272
|
-
...state,
|
|
2273
|
-
...fetchState(state.data, this.options),
|
|
2274
|
-
fetchMeta: action.meta ?? null
|
|
2275
|
-
};
|
|
2276
|
-
case "success":
|
|
2277
|
-
const newState = {
|
|
2278
|
-
...state,
|
|
2279
|
-
...successState(action.data, action.dataUpdatedAt),
|
|
2280
|
-
dataUpdateCount: state.dataUpdateCount + 1,
|
|
2281
|
-
...!action.manual && {
|
|
2282
|
-
fetchStatus: "idle",
|
|
2283
|
-
fetchFailureCount: 0,
|
|
2284
|
-
fetchFailureReason: null
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
this.#revertState = action.manual ? newState : void 0;
|
|
2288
|
-
return newState;
|
|
2289
|
-
case "error":
|
|
2290
|
-
const error = action.error;
|
|
2291
|
-
return {
|
|
2292
|
-
...state,
|
|
2293
|
-
error,
|
|
2294
|
-
errorUpdateCount: state.errorUpdateCount + 1,
|
|
2295
|
-
errorUpdatedAt: Date.now(),
|
|
2296
|
-
fetchFailureCount: state.fetchFailureCount + 1,
|
|
2297
|
-
fetchFailureReason: error,
|
|
2298
|
-
fetchStatus: "idle",
|
|
2299
|
-
status: "error",
|
|
2300
|
-
isInvalidated: true
|
|
2301
|
-
};
|
|
2302
|
-
case "invalidate": return {
|
|
2303
|
-
...state,
|
|
2304
|
-
isInvalidated: true
|
|
2305
|
-
};
|
|
2306
|
-
case "setState": return {
|
|
2307
|
-
...state,
|
|
2308
|
-
...action.state
|
|
2309
|
-
};
|
|
2310
|
-
}
|
|
2311
|
-
};
|
|
2312
|
-
this.state = reducer(this.state);
|
|
2313
|
-
notifyManager.batch(() => {
|
|
2314
|
-
this.observers.slice().forEach((observer) => {
|
|
2315
|
-
observer.onQueryUpdate();
|
|
2316
|
-
});
|
|
2317
|
-
this.#cache.notify({
|
|
2318
|
-
query: this,
|
|
2319
|
-
type: "updated",
|
|
2320
|
-
action
|
|
2321
|
-
});
|
|
2322
|
-
});
|
|
2323
|
-
}
|
|
2324
|
-
};
|
|
2325
|
-
/**
|
|
2326
|
-
* Returns the state changes applied when a query starts fetching.
|
|
2327
|
-
* @param data - The query's current data. If it is `undefined`, the query is also reset to
|
|
2328
|
-
* `'pending'` with no error.
|
|
2329
|
-
* @param options - The query options, whose `networkMode` decides whether the query is `'fetching'`
|
|
2330
|
-
* or `'paused'`.
|
|
2331
|
-
* @returns The partial query state for a starting fetch.
|
|
2332
|
-
*/
|
|
2333
|
-
function fetchState(data, options) {
|
|
2334
|
-
return {
|
|
2335
|
-
fetchFailureCount: 0,
|
|
2336
|
-
fetchFailureReason: null,
|
|
2337
|
-
fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
|
|
2338
|
-
...data === void 0 && {
|
|
2339
|
-
error: null,
|
|
2340
|
-
status: "pending"
|
|
2341
|
-
}
|
|
2342
|
-
};
|
|
2343
|
-
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Returns the state changes applied when a query receives data.
|
|
2346
|
-
* @param data - The new data.
|
|
2347
|
-
* @param dataUpdatedAt - The timestamp the data is recorded with. Defaults to the current time.
|
|
2348
|
-
* @returns The partial query state for a successful update.
|
|
2349
|
-
*/
|
|
2350
|
-
function successState(data, dataUpdatedAt) {
|
|
2351
|
-
return {
|
|
2352
|
-
data,
|
|
2353
|
-
dataUpdatedAt: dataUpdatedAt ?? Date.now(),
|
|
2354
|
-
error: null,
|
|
2355
|
-
isInvalidated: false,
|
|
2356
|
-
status: "success"
|
|
2357
|
-
};
|
|
2358
|
-
}
|
|
2359
|
-
/**
|
|
2360
|
-
* Returns the initial state of a query, based on its `initialData` and `initialDataUpdatedAt`
|
|
2361
|
-
* options.
|
|
2362
|
-
* @param options - The query options.
|
|
2363
|
-
* @returns The initial query state: `'success'` if `initialData` is set, otherwise `'pending'`.
|
|
2364
|
-
*/
|
|
2365
|
-
function getDefaultState(options) {
|
|
2366
|
-
const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
|
|
2367
|
-
const hasData = data !== void 0;
|
|
2368
|
-
const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
|
|
2369
|
-
return {
|
|
2370
|
-
data,
|
|
2371
|
-
dataUpdateCount: 0,
|
|
2372
|
-
dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
|
|
2373
|
-
error: null,
|
|
2374
|
-
errorUpdateCount: 0,
|
|
2375
|
-
errorUpdatedAt: 0,
|
|
2376
|
-
fetchFailureCount: 0,
|
|
2377
|
-
fetchFailureReason: null,
|
|
2378
|
-
fetchMeta: null,
|
|
2379
|
-
isInvalidated: false,
|
|
2380
|
-
status: hasData ? "success" : "pending",
|
|
2381
|
-
fetchStatus: "idle"
|
|
2382
|
-
};
|
|
2383
|
-
}
|
|
2384
|
-
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/queryObserver.js
|
|
2385
|
-
/**
|
|
2386
|
-
* A `QueryObserver` watches a single query in the `QueryCache` and computes a
|
|
2387
|
-
* `QueryObserverResult` from its state, recomputing and notifying subscribers
|
|
2388
|
-
* whenever the underlying query (or the observer's options) changes. It is
|
|
2389
|
-
* the primitive that framework adapters (e.g. `useQuery`) build their hooks
|
|
2390
|
-
* on top of, but it can also be used directly to observe and switch between
|
|
2391
|
-
* queries outside of any framework.
|
|
2392
|
-
* @example
|
|
2393
|
-
* ```ts
|
|
2394
|
-
* const observer = new QueryObserver(queryClient, {
|
|
2395
|
-
* queryKey: ['posts'],
|
|
2396
|
-
* queryFn: fetchPosts,
|
|
2397
|
-
* })
|
|
2398
|
-
*
|
|
2399
|
-
* const unsubscribe = observer.subscribe((result) => {
|
|
2400
|
-
* console.log(result.data)
|
|
2401
|
-
* })
|
|
2402
|
-
* ```
|
|
2403
|
-
*/
|
|
2404
|
-
var QueryObserver = class extends Subscribable {
|
|
2405
|
-
#client;
|
|
2406
|
-
#currentQuery = void 0;
|
|
2407
|
-
#currentQueryInitialState = void 0;
|
|
2408
|
-
#currentResult = void 0;
|
|
2409
|
-
#currentResultState;
|
|
2410
|
-
#currentResultOptions;
|
|
2411
|
-
#selectError;
|
|
2412
|
-
#selectFn;
|
|
2413
|
-
#selectResult;
|
|
2414
|
-
#lastQueryWithDefinedData;
|
|
2415
|
-
#staleTimeoutId;
|
|
2416
|
-
#refetchIntervalId;
|
|
2417
|
-
#currentRefetchInterval;
|
|
2418
|
-
#trackedProps = /* @__PURE__ */ new Set();
|
|
2419
|
-
constructor(client, options) {
|
|
2420
|
-
super();
|
|
2421
|
-
this.options = options;
|
|
2422
|
-
this.#client = client;
|
|
2423
|
-
this.#selectError = null;
|
|
2424
|
-
this.bindMethods();
|
|
2425
|
-
this.setOptions(options);
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Binds the methods of the result (`refetch`) to the observer, so they keep working when destructured
|
|
2429
|
-
* from it. Subclasses override it to bind their own result methods as well.
|
|
2430
|
-
*/
|
|
2431
|
-
bindMethods() {
|
|
2432
|
-
this.refetch = this.refetch.bind(this);
|
|
2433
|
-
}
|
|
2434
|
-
onSubscribe() {
|
|
2435
|
-
if (this.listeners.size === 1) {
|
|
2436
|
-
this.#currentQuery.addObserver(this);
|
|
2437
|
-
if (shouldFetchOnMount(this.#currentQuery, this.options)) this.#executeFetch();
|
|
2438
|
-
else this.updateResult();
|
|
2439
|
-
this.#updateTimers();
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
onUnsubscribe() {
|
|
2443
|
-
if (!this.hasListeners()) this.destroy();
|
|
2444
|
-
}
|
|
2445
|
-
/**
|
|
2446
|
-
* Returns whether the observed query is currently stale and configured
|
|
2447
|
-
* (via the `refetchOnReconnect` option) to refetch when the network
|
|
2448
|
-
* reconnects.
|
|
2449
|
-
* @returns `true` if the observer should refetch the query on reconnect.
|
|
2450
|
-
*/
|
|
2451
|
-
shouldFetchOnReconnect() {
|
|
2452
|
-
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
|
|
2453
|
-
}
|
|
2454
|
-
/**
|
|
2455
|
-
* Returns whether the observed query is currently stale and configured
|
|
2456
|
-
* (via the `refetchOnWindowFocus` option) to refetch when the window
|
|
2457
|
-
* regains focus.
|
|
2458
|
-
* @returns `true` if the observer should refetch the query on window focus.
|
|
2459
|
-
*/
|
|
2460
|
-
shouldFetchOnWindowFocus() {
|
|
2461
|
-
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
2462
|
-
}
|
|
2463
|
-
/**
|
|
2464
|
-
* Stops observing the current query: clears all listeners, cancels the
|
|
2465
|
-
* stale and refetch-interval timers, and removes this observer from the
|
|
2466
|
-
* query it was observing.
|
|
2467
|
-
*/
|
|
2468
|
-
destroy() {
|
|
2469
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
2470
|
-
this.#clearStaleTimeout();
|
|
2471
|
-
this.#clearRefetchInterval();
|
|
2472
|
-
this.#currentQuery.removeObserver(this);
|
|
2473
|
-
}
|
|
2474
|
-
/**
|
|
2475
|
-
* Updates the observer's options. This will re-resolve the query being
|
|
2476
|
-
* observed (switching to a different query if the `queryKey` changed),
|
|
2477
|
-
* trigger a fetch if the new options require one and the observer has
|
|
2478
|
-
* subscribers, recompute the current result, and reschedule the stale and
|
|
2479
|
-
* refetch-interval timers as needed.
|
|
2480
|
-
* @param options - The new observer options. They are defaulted with {@link
|
|
2481
|
-
* QueryClient#defaultQueryOptions} before being applied.
|
|
2482
|
-
* @throws {Error} If `enabled` is neither a boolean nor a function.
|
|
2483
|
-
* @example
|
|
2484
|
-
* ```ts
|
|
2485
|
-
* observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
|
|
2486
|
-
* // later: switch to a different query, reusing the same observer
|
|
2487
|
-
* observer.setOptions({ queryKey: ['posts', 2], queryFn: () => fetchPost(2) })
|
|
2488
|
-
* ```
|
|
2489
|
-
*/
|
|
2490
|
-
setOptions(options) {
|
|
2491
|
-
const prevOptions = this.options;
|
|
2492
|
-
const prevQuery = this.#currentQuery;
|
|
2493
|
-
this.options = this.#client.defaultQueryOptions(options);
|
|
2494
|
-
if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof resolveQueryValue(this.options.enabled, this.#currentQuery) !== "boolean") throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
|
|
2495
|
-
this.#updateQuery();
|
|
2496
|
-
this.#currentQuery.setOptions(this.options);
|
|
2497
|
-
if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) this.#client.getQueryCache().notify({
|
|
2498
|
-
type: "observerOptionsUpdated",
|
|
2499
|
-
query: this.#currentQuery,
|
|
2500
|
-
observer: this
|
|
2501
|
-
});
|
|
2502
|
-
const mounted = this.hasListeners();
|
|
2503
|
-
if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) this.#executeFetch();
|
|
2504
|
-
this.updateResult();
|
|
2505
|
-
if (mounted && (this.#currentQuery !== prevQuery || resolveQueryValue(this.options.enabled, this.#currentQuery) !== resolveQueryValue(prevOptions.enabled, this.#currentQuery) || resolveQueryValue(this.options.staleTime, this.#currentQuery) !== resolveQueryValue(prevOptions.staleTime, this.#currentQuery))) this.#updateStaleTimeout();
|
|
2506
|
-
const nextRefetchInterval = this.#computeRefetchInterval();
|
|
2507
|
-
if (mounted && (this.#currentQuery !== prevQuery || resolveQueryValue(this.options.enabled, this.#currentQuery) !== resolveQueryValue(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) this.#updateRefetchInterval(nextRefetchInterval);
|
|
2508
|
-
}
|
|
2509
|
-
/**
|
|
2510
|
-
* Computes the result the observer would produce for the given (already-defaulted) options
|
|
2511
|
-
* right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
|
|
2512
|
-
* subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
|
|
2513
|
-
* returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
|
|
2514
|
-
* @param options - The defaulted observer options to compute the result for.
|
|
2515
|
-
* @returns The result for the given options.
|
|
2516
|
-
*/
|
|
2517
|
-
getOptimisticResult(options) {
|
|
2518
|
-
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
2519
|
-
const result = this.createResult(query, options);
|
|
2520
|
-
if (!shallowEqualObjects(this.getCurrentResult(), result)) {
|
|
2521
|
-
this.#currentResult = result;
|
|
2522
|
-
this.#currentResultOptions = this.options;
|
|
2523
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
2524
|
-
}
|
|
2525
|
-
return result;
|
|
2526
|
-
}
|
|
2527
|
-
/**
|
|
2528
|
-
* Returns the most recently computed `QueryObserverResult` for the
|
|
2529
|
-
* observed query. This is a point-in-time read; to be notified of updates
|
|
2530
|
-
* as they happen, subscribe to the observer instead (its inherited
|
|
2531
|
-
* `subscribe` method).
|
|
2532
|
-
* @returns The observer's latest result.
|
|
2533
|
-
* @example
|
|
2534
|
-
* ```ts
|
|
2535
|
-
* const result = observer.getCurrentResult()
|
|
2536
|
-
* console.log(result.status, result.data)
|
|
2537
|
-
* ```
|
|
2538
|
-
*/
|
|
2539
|
-
getCurrentResult() {
|
|
2540
|
-
return this.#currentResult;
|
|
2541
|
-
}
|
|
2542
|
-
/**
|
|
2543
|
-
* Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via
|
|
2544
|
-
* {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
|
|
2545
|
-
* adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
|
|
2546
|
-
* properties you actually read" behavior.
|
|
2547
|
-
* @param result - The result to wrap.
|
|
2548
|
-
* @param onPropTracked - Called with the name of each property that is read.
|
|
2549
|
-
* @returns A proxy of `result` that tracks property reads.
|
|
2550
|
-
*/
|
|
2551
|
-
trackResult(result, onPropTracked) {
|
|
2552
|
-
return new Proxy(result, { get: (target, key) => {
|
|
2553
|
-
this.trackProp(key);
|
|
2554
|
-
onPropTracked?.(key);
|
|
2555
|
-
return Reflect.get(target, key);
|
|
2556
|
-
} });
|
|
2557
|
-
}
|
|
2558
|
-
/**
|
|
2559
|
-
* Records that the given `QueryObserverResult` property was read, so a subsequent update only
|
|
2560
|
-
* notifies this observer if a tracked property actually changed. Normally called indirectly via
|
|
2561
|
-
* {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
|
|
2562
|
-
* access themselves (e.g. through their own reactivity system) instead of via the proxy.
|
|
2563
|
-
* @param key - The name of the property that was read.
|
|
2564
|
-
*/
|
|
2565
|
-
trackProp(key) {
|
|
2566
|
-
this.#trackedProps.add(key);
|
|
2567
|
-
}
|
|
2568
|
-
/**
|
|
2569
|
-
* Returns the `Query` instance this observer is currently observing.
|
|
2570
|
-
* @returns The observed query.
|
|
2571
|
-
*/
|
|
2572
|
-
getCurrentQuery() {
|
|
2573
|
-
return this.#currentQuery;
|
|
2574
|
-
}
|
|
2575
|
-
/**
|
|
2576
|
-
* Refetches the observed query and returns a promise that resolves with
|
|
2577
|
-
* the resulting `QueryObserverResult`.
|
|
2578
|
-
* @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
|
|
2579
|
-
* it, and `throwOnError` to `true` to reject when the refetch fails.
|
|
2580
|
-
* @returns A promise that resolves with the result after the refetch.
|
|
2581
|
-
* @example
|
|
2582
|
-
* ```ts
|
|
2583
|
-
* const result = await observer.refetch({ cancelRefetch: false })
|
|
2584
|
-
* console.log(result.data)
|
|
2585
|
-
* ```
|
|
2586
|
-
*/
|
|
2587
|
-
refetch({ ...options } = {}) {
|
|
2588
|
-
return this.fetch({ ...options });
|
|
2589
|
-
}
|
|
2590
|
-
/**
|
|
2591
|
-
* Fetches a query defined by the given options without affecting this
|
|
2592
|
-
* observer's own tracked query or result, and returns a promise that
|
|
2593
|
-
* resolves with the `QueryObserverResult` for that fetch. This is useful
|
|
2594
|
-
* for prefetching data that another observer (e.g. a query about to be
|
|
2595
|
-
* navigated to) will need, ahead of time.
|
|
2596
|
-
* @param options - The observer options of the query to fetch.
|
|
2597
|
-
* @returns A promise that resolves with the result for the fetched query.
|
|
2598
|
-
* @example
|
|
2599
|
-
* ```ts
|
|
2600
|
-
* const result = await observer.fetchOptimistic({
|
|
2601
|
-
* queryKey: ['posts', 2],
|
|
2602
|
-
* queryFn: () => fetchPost(2),
|
|
2603
|
-
* })
|
|
2604
|
-
* console.log(result.data)
|
|
2605
|
-
* ```
|
|
2606
|
-
*/
|
|
2607
|
-
fetchOptimistic(options) {
|
|
2608
|
-
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2609
|
-
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
|
|
2610
|
-
let unsubscribe = () => {};
|
|
2611
|
-
let resolveEarly;
|
|
2612
|
-
const cachePromise = new Promise((resolve) => {
|
|
2613
|
-
resolveEarly = resolve;
|
|
2614
|
-
unsubscribe = this.#client.getQueryCache().subscribe((event) => {
|
|
2615
|
-
if (event.type === "updated" && event.query.queryHash === query.queryHash && query.state.data !== void 0) {
|
|
2616
|
-
unsubscribe();
|
|
2617
|
-
resolve(this.createResult(query, defaultedOptions));
|
|
2618
|
-
}
|
|
2619
|
-
});
|
|
2620
|
-
});
|
|
2621
|
-
return Promise.race([query.fetch(defaultedOptions).then(() => {
|
|
2622
|
-
const result = this.createResult(query, defaultedOptions);
|
|
2623
|
-
resolveEarly?.(result);
|
|
2624
|
-
return result;
|
|
2625
|
-
}).finally(() => {
|
|
2626
|
-
unsubscribe();
|
|
2627
|
-
}), cachePromise]);
|
|
2628
|
-
}
|
|
2629
|
-
/**
|
|
2630
|
-
* Fetches the observed query and updates the result once the fetch settles. Used by `refetch` and,
|
|
2631
|
-
* in `InfiniteQueryObserver`, to fetch more pages.
|
|
2632
|
-
* @param fetchOptions - Options for this fetch. `cancelRefetch` defaults to `true`.
|
|
2633
|
-
* @returns A promise that resolves with the updated result.
|
|
2634
|
-
*/
|
|
2635
|
-
fetch(fetchOptions) {
|
|
2636
|
-
return this.#executeFetch({
|
|
2637
|
-
...fetchOptions,
|
|
2638
|
-
cancelRefetch: fetchOptions.cancelRefetch ?? true
|
|
2639
|
-
}).then(() => {
|
|
2640
|
-
this.updateResult();
|
|
2641
|
-
return this.#currentResult;
|
|
2642
|
-
});
|
|
2643
|
-
}
|
|
2644
|
-
#executeFetch(fetchOptions) {
|
|
2645
|
-
this.#updateQuery();
|
|
2646
|
-
let promise = this.#currentQuery.fetch(this.options, fetchOptions);
|
|
2647
|
-
if (!fetchOptions?.throwOnError) promise = promise.catch(noop);
|
|
2648
|
-
return promise;
|
|
2649
|
-
}
|
|
2650
|
-
#shouldScheduleTimer(timeout) {
|
|
2651
|
-
return !isServer() && resolveQueryValue(this.options.enabled, this.#currentQuery) !== false && isValidTimeout(timeout);
|
|
2652
|
-
}
|
|
2653
|
-
#updateStaleTimeout() {
|
|
2654
|
-
this.#clearStaleTimeout();
|
|
2655
|
-
const staleTime = resolveQueryValue(this.options.staleTime, this.#currentQuery);
|
|
2656
|
-
if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) return;
|
|
2657
|
-
const timeout = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) + 1;
|
|
2658
|
-
this.#staleTimeoutId = timeoutManager.setTimeout(() => {
|
|
2659
|
-
if (!this.#currentResult.isStale) this.updateResult();
|
|
2660
|
-
}, timeout);
|
|
2661
|
-
}
|
|
2662
|
-
#computeRefetchInterval() {
|
|
2663
|
-
return resolveQueryValue(this.options.refetchInterval, this.#currentQuery) ?? false;
|
|
2664
|
-
}
|
|
2665
|
-
#updateRefetchInterval(nextInterval) {
|
|
2666
|
-
this.#clearRefetchInterval();
|
|
2667
|
-
this.#currentRefetchInterval = nextInterval;
|
|
2668
|
-
if (this.#currentRefetchInterval === 0 || !this.#shouldScheduleTimer(this.#currentRefetchInterval)) return;
|
|
2669
|
-
this.#refetchIntervalId = timeoutManager.setInterval(() => {
|
|
2670
|
-
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) this.#executeFetch();
|
|
2671
|
-
}, this.#currentRefetchInterval);
|
|
2672
|
-
}
|
|
2673
|
-
#updateTimers() {
|
|
2674
|
-
this.#updateStaleTimeout();
|
|
2675
|
-
this.#updateRefetchInterval(this.#computeRefetchInterval());
|
|
2676
|
-
}
|
|
2677
|
-
#clearStaleTimeout() {
|
|
2678
|
-
if (this.#staleTimeoutId !== void 0) {
|
|
2679
|
-
timeoutManager.clearTimeout(this.#staleTimeoutId);
|
|
2680
|
-
this.#staleTimeoutId = void 0;
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
#clearRefetchInterval() {
|
|
2684
|
-
if (this.#refetchIntervalId !== void 0) {
|
|
2685
|
-
timeoutManager.clearInterval(this.#refetchIntervalId);
|
|
2686
|
-
this.#refetchIntervalId = void 0;
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
/**
|
|
2690
|
-
* Computes the result for a query and options from the query's state, applying `select`,
|
|
2691
|
-
* `placeholderData`, and the derived flags. Subclasses override it to add their own fields.
|
|
2692
|
-
* @param query - The query to compute the result for.
|
|
2693
|
-
* @param options - The observer options to compute the result with.
|
|
2694
|
-
* @returns The computed result.
|
|
2695
|
-
*/
|
|
2696
|
-
createResult(query, options) {
|
|
2697
|
-
const prevQuery = this.#currentQuery;
|
|
2698
|
-
const prevOptions = this.options;
|
|
2699
|
-
const prevResult = this.#currentResult;
|
|
2700
|
-
const prevResultState = this.#currentResultState;
|
|
2701
|
-
const prevResultOptions = this.#currentResultOptions;
|
|
2702
|
-
const queryInitialState = query !== prevQuery ? query.state : this.#currentQueryInitialState;
|
|
2703
|
-
const { state } = query;
|
|
2704
|
-
let newState = { ...state };
|
|
2705
|
-
let isPlaceholderData = false;
|
|
2706
|
-
let data;
|
|
2707
|
-
if (options._optimisticResults) {
|
|
2708
|
-
const mounted = this.hasListeners();
|
|
2709
|
-
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
2710
|
-
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
2711
|
-
if (fetchOnMount || fetchOptionally) newState = {
|
|
2712
|
-
...newState,
|
|
2713
|
-
...fetchState(state.data, query.options)
|
|
2714
|
-
};
|
|
2715
|
-
if (options._optimisticResults === "isRestoring") newState.fetchStatus = "idle";
|
|
2716
|
-
}
|
|
2717
|
-
let { error, errorUpdatedAt, status } = newState;
|
|
2718
|
-
data = newState.data;
|
|
2719
|
-
let skipSelect = false;
|
|
2720
|
-
if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
|
|
2721
|
-
let placeholderData;
|
|
2722
|
-
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
2723
|
-
placeholderData = prevResult.data;
|
|
2724
|
-
skipSelect = true;
|
|
2725
|
-
} else placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
|
|
2726
|
-
if (placeholderData !== void 0) {
|
|
2727
|
-
status = "success";
|
|
2728
|
-
data = replaceData(prevResult?.data, placeholderData, options);
|
|
2729
|
-
isPlaceholderData = true;
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
if (options.select && data !== void 0 && !skipSelect) {
|
|
2733
|
-
if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) data = this.#selectResult;
|
|
2734
|
-
else try {
|
|
2735
|
-
this.#selectFn = options.select;
|
|
2736
|
-
data = options.select(data);
|
|
2737
|
-
data = replaceData(prevResult?.data, data, options);
|
|
2738
|
-
this.#selectResult = data;
|
|
2739
|
-
this.#selectError = null;
|
|
2740
|
-
} catch (selectError) {
|
|
2741
|
-
this.#selectError = selectError;
|
|
2742
|
-
}
|
|
2743
|
-
} else if (data === void 0) this.#selectError = null;
|
|
2744
|
-
if (this.#selectError) {
|
|
2745
|
-
error = this.#selectError;
|
|
2746
|
-
data = this.#selectResult;
|
|
2747
|
-
errorUpdatedAt = Date.now();
|
|
2748
|
-
status = "error";
|
|
2749
|
-
isPlaceholderData = false;
|
|
2750
|
-
}
|
|
2751
|
-
const isFetching = newState.fetchStatus === "fetching";
|
|
2752
|
-
const isPending = status === "pending";
|
|
2753
|
-
const isError = status === "error";
|
|
2754
|
-
const isLoading = isPending && isFetching;
|
|
2755
|
-
const hasData = data !== void 0;
|
|
2756
|
-
return {
|
|
2757
|
-
status,
|
|
2758
|
-
fetchStatus: newState.fetchStatus,
|
|
2759
|
-
isPending,
|
|
2760
|
-
isSuccess: status === "success",
|
|
2761
|
-
isError,
|
|
2762
|
-
isInitialLoading: isLoading,
|
|
2763
|
-
isLoading,
|
|
2764
|
-
data,
|
|
2765
|
-
dataUpdatedAt: newState.dataUpdatedAt,
|
|
2766
|
-
error,
|
|
2767
|
-
errorUpdatedAt,
|
|
2768
|
-
failureCount: newState.fetchFailureCount,
|
|
2769
|
-
failureReason: newState.fetchFailureReason,
|
|
2770
|
-
errorUpdateCount: newState.errorUpdateCount,
|
|
2771
|
-
isFetched: query.isFetched(),
|
|
2772
|
-
isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
2773
|
-
isFetching,
|
|
2774
|
-
isRefetching: isFetching && !isPending,
|
|
2775
|
-
isLoadingError: isError && !hasData,
|
|
2776
|
-
isPaused: newState.fetchStatus === "paused",
|
|
2777
|
-
isPlaceholderData,
|
|
2778
|
-
isRefetchError: isError && hasData,
|
|
2779
|
-
isStale: isStale(query, options),
|
|
2780
|
-
refetch: this.refetch,
|
|
2781
|
-
isEnabled: resolveQueryValue(options.enabled, query) !== false
|
|
2782
|
-
};
|
|
2783
|
-
}
|
|
2784
|
-
/**
|
|
2785
|
-
* Recomputes and stores the current result from the current query/options, notifying listeners
|
|
2786
|
-
* if it changed. Framework adapters call this right after subscribing to make sure no query
|
|
2787
|
-
* update was missed in the gap between creating the observer and subscribing to it.
|
|
2788
|
-
*/
|
|
2789
|
-
updateResult() {
|
|
2790
|
-
const prevResult = this.#currentResult;
|
|
2791
|
-
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
2792
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
2793
|
-
this.#currentResultOptions = this.options;
|
|
2794
|
-
if (this.#currentResultState.data !== void 0) this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
2795
|
-
if (shallowEqualObjects(nextResult, prevResult)) return;
|
|
2796
|
-
this.#currentResult = nextResult;
|
|
2797
|
-
const shouldNotifyListeners = () => {
|
|
2798
|
-
if (!prevResult) return true;
|
|
2799
|
-
const { notifyOnChangeProps } = this.options;
|
|
2800
|
-
const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
|
|
2801
|
-
if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) return true;
|
|
2802
|
-
if (this.options.throwOnError && this.#currentResult.error !== prevResult.error) return true;
|
|
2803
|
-
for (const key of notifyOnChangePropsValue ?? this.#trackedProps) if (this.#currentResult[key] !== prevResult[key]) return true;
|
|
2804
|
-
return false;
|
|
2805
|
-
};
|
|
2806
|
-
const notifyListeners = shouldNotifyListeners();
|
|
2807
|
-
notifyManager.batch(() => {
|
|
2808
|
-
if (notifyListeners) this.listeners.forEach((listener) => {
|
|
2809
|
-
listener(this.#currentResult);
|
|
2810
|
-
});
|
|
2811
|
-
this.#client.getQueryCache().notify({
|
|
2812
|
-
query: this.#currentQuery,
|
|
2813
|
-
type: "observerResultsUpdated"
|
|
2814
|
-
});
|
|
2815
|
-
});
|
|
2816
|
-
}
|
|
2817
|
-
#updateQuery() {
|
|
2818
|
-
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
2819
|
-
if (query === this.#currentQuery) return;
|
|
2820
|
-
const prevQuery = this.#currentQuery;
|
|
2821
|
-
this.#currentQuery = query;
|
|
2822
|
-
this.#currentQueryInitialState = query.state;
|
|
2823
|
-
if (this.hasListeners()) {
|
|
2824
|
-
prevQuery?.removeObserver(this);
|
|
2825
|
-
query.addObserver(this);
|
|
2826
|
-
}
|
|
2827
|
-
}
|
|
2828
|
-
/**
|
|
2829
|
-
* Updates the observer's result when the observed query changes, and reschedules its timers if it
|
|
2830
|
-
* has listeners.
|
|
2831
|
-
* @internal
|
|
2832
|
-
*/
|
|
2833
|
-
onQueryUpdate() {
|
|
2834
|
-
this.updateResult();
|
|
2835
|
-
if (this.hasListeners()) this.#updateTimers();
|
|
2836
|
-
}
|
|
2837
|
-
};
|
|
2838
|
-
/**
|
|
2839
|
-
* Checks whether a query has no data yet and should do its initial load when an observer mounts.
|
|
2840
|
-
* @param query - The query to check.
|
|
2841
|
-
* @param options - The observer options.
|
|
2842
|
-
* @returns `true` if the query is enabled, has no data, and isn't in an error state with
|
|
2843
|
-
* `retryOnMount: false`.
|
|
2844
|
-
*/
|
|
2845
|
-
function shouldLoadOnMount(query, options) {
|
|
2846
|
-
return resolveQueryValue(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && resolveQueryValue(options.retryOnMount, query) === false);
|
|
2847
|
-
}
|
|
2848
|
-
/**
|
|
2849
|
-
* Checks whether a query should fetch when an observer mounts: either for its initial load, or
|
|
2850
|
-
* because it has data and `refetchOnMount` asks for a refetch.
|
|
2851
|
-
* @param query - The query to check.
|
|
2852
|
-
* @param options - The observer options.
|
|
2853
|
-
* @returns `true` if the query should fetch on mount.
|
|
2854
|
-
*/
|
|
2855
|
-
function shouldFetchOnMount(query, options) {
|
|
2856
|
-
return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
|
|
2857
|
-
}
|
|
2858
|
-
/**
|
|
2859
|
-
* Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or
|
|
2860
|
-
* `refetchOnReconnect` option.
|
|
2861
|
-
* @param query - The query to check.
|
|
2862
|
-
* @param options - The observer options.
|
|
2863
|
-
* @param field - The value of the option to check.
|
|
2864
|
-
* @returns `true` if the query is enabled, not static, and the option is `'always'`, or is not
|
|
2865
|
-
* `false` and the query is stale.
|
|
2866
|
-
*/
|
|
2867
|
-
function shouldFetchOn(query, options, field) {
|
|
2868
|
-
if (resolveQueryValue(options.enabled, query) !== false && resolveQueryValue(options.staleTime, query) !== "static") {
|
|
2869
|
-
const value = resolveQueryValue(field, query);
|
|
2870
|
-
return value === "always" || value !== false && isStale(query, options);
|
|
2871
|
-
}
|
|
2872
|
-
return false;
|
|
2873
|
-
}
|
|
2874
|
-
/**
|
|
2875
|
-
* Checks whether a query should fetch after the observer's options change.
|
|
2876
|
-
* @param query - The query observed with the new options.
|
|
2877
|
-
* @param prevQuery - The query observed with the previous options.
|
|
2878
|
-
* @param options - The new observer options.
|
|
2879
|
-
* @param prevOptions - The previous observer options.
|
|
2880
|
-
* @returns `true` if the query changed or was disabled before, it isn't a suspense query in an
|
|
2881
|
-
* error state, and it is stale.
|
|
2882
|
-
*/
|
|
2883
|
-
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
|
|
2884
|
-
return (query !== prevQuery || resolveQueryValue(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
|
|
2885
|
-
}
|
|
2886
|
-
/**
|
|
2887
|
-
* Checks whether a query is stale for the given observer options.
|
|
2888
|
-
* @param query - The query to check.
|
|
2889
|
-
* @param options - The observer options, whose `enabled` and `staleTime` are used.
|
|
2890
|
-
* @returns `true` if the query is enabled and its data is stale for `staleTime`.
|
|
2891
|
-
*/
|
|
2892
|
-
function isStale(query, options) {
|
|
2893
|
-
return resolveQueryValue(options.enabled, query) !== false && query.isStaleByTime(resolveQueryValue(options.staleTime, query));
|
|
2894
|
-
}
|
|
2895
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/IsRestoringProvider.js
|
|
2896
|
-
var IsRestoringContext = import_react.createContext(false);
|
|
2897
|
-
/**
|
|
2898
|
-
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
2899
|
-
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
2900
|
-
* race conditions between the restore and mounting queries.
|
|
2901
|
-
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
2902
|
-
*/
|
|
2903
|
-
var useIsRestoring = () => import_react.useContext(IsRestoringContext);
|
|
2904
|
-
IsRestoringContext.Provider;
|
|
2905
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js
|
|
2906
|
-
/**
|
|
2907
|
-
* Creates the value shared through the boundary's context, which tracks whether a reset was
|
|
2908
|
-
* requested.
|
|
2909
|
-
* @returns The `clearReset`, `isReset`, and `reset` functions of the boundary.
|
|
2910
|
-
*/
|
|
2911
|
-
function createValue() {
|
|
2912
|
-
let isReset = false;
|
|
2913
|
-
return {
|
|
2914
|
-
/**
|
|
2915
|
-
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
2916
|
-
*/
|
|
2917
|
-
clearReset: () => {
|
|
2918
|
-
isReset = false;
|
|
2919
|
-
},
|
|
2920
|
-
/**
|
|
2921
|
-
* Resets any query errors within the boundary, so queries know they can try again.
|
|
2922
|
-
*/
|
|
2923
|
-
reset: () => {
|
|
2924
|
-
isReset = true;
|
|
2925
|
-
},
|
|
2926
|
-
/**
|
|
2927
|
-
* Returns whether the boundary has been reset and not yet cleared.
|
|
2928
|
-
* @returns `true` if the boundary has been reset and not yet cleared.
|
|
2929
|
-
*/
|
|
2930
|
-
isReset: () => {
|
|
2931
|
-
return isReset;
|
|
2932
|
-
}
|
|
2933
|
-
};
|
|
2934
|
-
}
|
|
2935
|
-
var QueryErrorResetBoundaryContext = import_react.createContext(createValue());
|
|
2936
|
-
/**
|
|
2937
|
-
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
2938
|
-
* defined it will reset them globally.
|
|
2939
|
-
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
2940
|
-
* @example
|
|
2941
|
-
* ```tsx
|
|
2942
|
-
* import { ErrorBoundary } from 'react-error-boundary'
|
|
2943
|
-
* import { useQueryErrorResetBoundary } from '@tanstack/react-query'
|
|
2944
|
-
*
|
|
2945
|
-
* function App({ children }: { children: React.ReactNode }) {
|
|
2946
|
-
* const { reset } = useQueryErrorResetBoundary()
|
|
2947
|
-
*
|
|
2948
|
-
* return (
|
|
2949
|
-
* <ErrorBoundary
|
|
2950
|
-
* onReset={reset}
|
|
2951
|
-
* fallbackRender={({ resetErrorBoundary }) => (
|
|
2952
|
-
* <div>
|
|
2953
|
-
* There was an error!
|
|
2954
|
-
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
2955
|
-
* </div>
|
|
2956
|
-
* )}
|
|
2957
|
-
* >
|
|
2958
|
-
* {children}
|
|
2959
|
-
* </ErrorBoundary>
|
|
2960
|
-
* )
|
|
2961
|
-
* }
|
|
2962
|
-
* ```
|
|
2963
|
-
*/
|
|
2964
|
-
var useQueryErrorResetBoundary = () => import_react.useContext(QueryErrorResetBoundaryContext);
|
|
2965
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js
|
|
2966
|
-
/**
|
|
2967
|
-
* Turns off `retryOnMount` for a query that throws its errors (with `suspense` or `throwOnError`),
|
|
2968
|
-
* unless the error boundary has been reset, so a remount doesn't retry the failed query before the
|
|
2969
|
-
* user resets the boundary. Mutates the options.
|
|
2970
|
-
* @param options - The defaulted query options to adjust.
|
|
2971
|
-
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
2972
|
-
* @param query - The query, used to evaluate a `throwOnError` function against its error.
|
|
2973
|
-
*/
|
|
2974
|
-
var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary, query) => {
|
|
2975
|
-
const throwOnError = query?.state.status === "error" && typeof options.throwOnError === "function" ? shouldThrowError(options.throwOnError, [query.state.error, query]) : options.throwOnError;
|
|
2976
|
-
if (options.suspense || throwOnError) {
|
|
2977
|
-
if (!errorResetBoundary.isReset()) options.retryOnMount = false;
|
|
2978
|
-
}
|
|
2979
|
-
};
|
|
2980
|
-
/**
|
|
2981
|
-
* Clears the reset state of the error boundary after the component mounts, so later errors are
|
|
2982
|
-
* thrown to the boundary again.
|
|
2983
|
-
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
2984
|
-
*/
|
|
2985
|
-
var useClearResetErrorBoundary = (errorResetBoundary) => {
|
|
2986
|
-
import_react.useEffect(() => {
|
|
2987
|
-
errorResetBoundary.clearReset();
|
|
2988
|
-
}, [errorResetBoundary]);
|
|
2989
|
-
};
|
|
2990
|
-
/**
|
|
2991
|
-
* Checks whether the query error should be thrown to the nearest error boundary: the query errored
|
|
2992
|
-
* and isn't fetching, the boundary hasn't been reset, and either `suspense` is enabled with no data
|
|
2993
|
-
* or `throwOnError` says so.
|
|
2994
|
-
* @param params - The observer `result`, the `errorResetBoundary`, the `throwOnError` option, the
|
|
2995
|
-
* `query`, and the `suspense` option.
|
|
2996
|
-
* @returns `true` if the error should be thrown.
|
|
2997
|
-
*/
|
|
2998
|
-
var getHasError = ({ result, errorResetBoundary, throwOnError, query, suspense }) => {
|
|
2999
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || shouldThrowError(throwOnError, [result.error, query]));
|
|
3000
|
-
};
|
|
3001
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/suspense.js
|
|
3002
|
-
/**
|
|
3003
|
-
* The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
|
|
3004
|
-
* only if the query has no data to show.
|
|
3005
|
-
* @param _error - The error of the query. Unused.
|
|
3006
|
-
* @param query - The query that errored.
|
|
3007
|
-
* @returns `true` if the query has no data.
|
|
3008
|
-
*/
|
|
3009
|
-
var defaultThrowOnError = (_error, query) => query.state.data === void 0;
|
|
3010
|
-
/**
|
|
3011
|
-
* Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
|
|
3012
|
-
* component that remounts after suspending doesn't refetch right away or find the query garbage
|
|
3013
|
-
* collected. A `'static'` `staleTime` is kept as is. Mutates the options.
|
|
3014
|
-
* @param defaultedOptions - The defaulted query options to adjust.
|
|
3015
|
-
*/
|
|
3016
|
-
var ensureSuspenseTimers = (defaultedOptions) => {
|
|
3017
|
-
if (defaultedOptions.suspense) {
|
|
3018
|
-
const MIN_SUSPENSE_TIME_MS = 1e3;
|
|
3019
|
-
const clamp = (value) => value === "static" ? value : Math.max(value ?? MIN_SUSPENSE_TIME_MS, MIN_SUSPENSE_TIME_MS);
|
|
3020
|
-
const originalStaleTime = defaultedOptions.staleTime;
|
|
3021
|
-
defaultedOptions.staleTime = typeof originalStaleTime === "function" ? (...args) => clamp(originalStaleTime(...args)) : clamp(originalStaleTime);
|
|
3022
|
-
if (typeof defaultedOptions.gcTime === "number") defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, MIN_SUSPENSE_TIME_MS);
|
|
3023
|
-
}
|
|
3024
|
-
};
|
|
3025
|
-
/**
|
|
3026
|
-
* Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
|
|
3027
|
-
* @param defaultedOptions - The defaulted query options, if any.
|
|
3028
|
-
* @param result - The current result of the observer.
|
|
3029
|
-
* @returns `true` if the component should suspend.
|
|
3030
|
-
*/
|
|
3031
|
-
var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
|
|
3032
|
-
/**
|
|
3033
|
-
* Fetches the query for a suspending component, without affecting the observer's own result. If
|
|
3034
|
-
* the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
|
|
3035
|
-
* @param defaultedOptions - The defaulted query options to fetch with.
|
|
3036
|
-
* @param observer - The observer of the query.
|
|
3037
|
-
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
3038
|
-
* @returns A promise that resolves once the fetch settles. It never rejects.
|
|
3039
|
-
*/
|
|
3040
|
-
var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
|
|
3041
|
-
errorResetBoundary.clearReset();
|
|
3042
|
-
});
|
|
3043
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/useBaseQuery.js
|
|
3044
|
-
/**
|
|
3045
|
-
* Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
|
|
3046
|
-
* `useSuspenseInfiniteQuery`.
|
|
3047
|
-
* @param options - The options passed to the calling hook.
|
|
3048
|
-
* @param Observer - The observer class from query-core (`QueryObserver` or
|
|
3049
|
-
* `InfiniteQueryObserver`).
|
|
3050
|
-
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
|
|
3051
|
-
* context will be used.
|
|
3052
|
-
* @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
|
|
3053
|
-
* set.
|
|
3054
|
-
* @throws {Error} If `options` is not an object (outside production), or the query error when it should be
|
|
3055
|
-
* thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
|
|
3056
|
-
*/
|
|
3057
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
3058
|
-
const isRestoring = useIsRestoring();
|
|
3059
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
3060
|
-
const client = useQueryClient(queryClient);
|
|
3061
|
-
const defaultedOptions = client.defaultQueryOptions(options);
|
|
3062
|
-
const query = client.getQueryCache().get(defaultedOptions.queryHash);
|
|
3063
|
-
const subscribed = options.subscribed !== false;
|
|
3064
|
-
defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : subscribed ? "optimistic" : void 0;
|
|
3065
|
-
ensureSuspenseTimers(defaultedOptions);
|
|
3066
|
-
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query);
|
|
3067
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
3068
|
-
const [observer] = import_react.useState(() => new Observer(client, defaultedOptions));
|
|
3069
|
-
const result = observer.getOptimisticResult(defaultedOptions);
|
|
3070
|
-
import_react.useEffect(() => {
|
|
3071
|
-
observer.setOptions(defaultedOptions);
|
|
3072
|
-
}, [defaultedOptions, observer]);
|
|
3073
|
-
const shouldSubscribe = !isRestoring && subscribed;
|
|
3074
|
-
import_react.useSyncExternalStore(import_react.useCallback((onStoreChange) => {
|
|
3075
|
-
const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;
|
|
3076
|
-
observer.updateResult();
|
|
3077
|
-
return unsubscribe;
|
|
3078
|
-
}, [observer, shouldSubscribe]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
3079
|
-
if (shouldSuspend(defaultedOptions, result)) throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
3080
|
-
if (getHasError({
|
|
3081
|
-
result,
|
|
3082
|
-
errorResetBoundary,
|
|
3083
|
-
throwOnError: defaultedOptions.throwOnError,
|
|
3084
|
-
query,
|
|
3085
|
-
suspense: defaultedOptions.suspense
|
|
3086
|
-
})) throw result.error;
|
|
3087
|
-
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
3088
|
-
}
|
|
3089
|
-
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/queryOptions.js
|
|
3090
|
-
function queryOptions(options) {
|
|
3091
|
-
return options;
|
|
3092
|
-
}
|
|
3093
|
-
// ../mate-core/src/cli/commands/studio/routes.ts
|
|
3094
|
-
/** A hosted report's HTML is served at this prefix plus its id. */
|
|
3095
|
-
var REPORT_VIEW_PREFIX = "/studio/reports/";
|
|
3096
|
-
/** Prefix of a Workset's run log routes. */
|
|
3097
|
-
var FACTORY_WORKSETS_ROUTE = "/api/factory/worksets";
|
|
3098
|
-
/**
|
|
3099
|
-
* The Agents panel: `GET` the Workset agent credential's status, `PUT` `{kind, value}`
|
|
3100
|
-
* to set it, `DELETE` to clear one set in Studio. Factory mode only.
|
|
3101
|
-
*/
|
|
3102
|
-
var FACTORY_CREDENTIAL_ROUTE = "/api/factory/credential";
|
|
3103
|
-
/** `GET` a Workset's bounded run log as text. */
|
|
3104
|
-
function factoryLogRoute(id) {
|
|
3105
|
-
return `${FACTORY_WORKSETS_ROUTE}/${encodeURIComponent(id)}/log`;
|
|
3106
|
-
}
|
|
3107
|
-
/** Server-sent events: a Workset's run log replayed, then followed live. */
|
|
3108
|
-
function factoryLogStreamRoute(id) {
|
|
3109
|
-
return `${factoryLogRoute(id)}/stream`;
|
|
3110
|
-
}
|
|
3111
|
-
/** One event stream per page: board, reports and markdown tree changes for a companion. */
|
|
3112
|
-
var STUDIO_EVENTS_ROUTE = "/api/events";
|
|
3113
|
-
/** The terminal's WASM core, loaded by Studio's bundled terminal from Studio itself. */
|
|
3114
|
-
var TERMINAL_WASM = `/studio/terminal/wterm.wasm`;
|
|
3115
|
-
/** The terminal's WebSocket, and its session list and end calls. */
|
|
3116
|
-
var TERMINAL_SOCKET_ROUTE = "/api/terminal";
|
|
3117
|
-
var TERMINAL_SESSIONS_ROUTE = "/api/terminal/sessions";
|
|
3118
|
-
var TERMINAL_SESSIONS_END_ROUTE = "/api/terminal/sessions/end";
|
|
3119
|
-
// src/lib/agent-credential.ts
|
|
3120
|
-
/**
|
|
3121
|
-
* The Agents panel's calls to the factory credential route. Only the status is cached;
|
|
3122
|
-
* an entered value goes in one request body and is never kept, keyed or put in an address.
|
|
3123
|
-
*/
|
|
3124
|
-
var agentCredentialKey = ["agent-credential"];
|
|
3125
|
-
async function call(method, route, body) {
|
|
3126
|
-
const response = await fetch(route, {
|
|
3127
|
-
method,
|
|
3128
|
-
credentials: "same-origin",
|
|
3129
|
-
headers: {
|
|
3130
|
-
accept: "application/json",
|
|
3131
|
-
"content-type": "application/json"
|
|
3132
|
-
},
|
|
3133
|
-
...body ? { body: JSON.stringify(body) } : {}
|
|
3134
|
-
});
|
|
3135
|
-
if (!response.ok) {
|
|
3136
|
-
const refusal = await response.json().catch(() => null);
|
|
3137
|
-
throw new Error(refusal?.reason ?? `status ${response.status}`);
|
|
3138
|
-
}
|
|
3139
|
-
return await response.json();
|
|
3140
|
-
}
|
|
3141
|
-
var agentCredentialQuery = () => ({
|
|
3142
|
-
queryKey: agentCredentialKey,
|
|
3143
|
-
queryFn: () => call("GET", FACTORY_CREDENTIAL_ROUTE)
|
|
3144
|
-
});
|
|
3145
|
-
var setAgentCredential = (kind, value) => call("PUT", FACTORY_CREDENTIAL_ROUTE, {
|
|
3146
|
-
kind,
|
|
3147
|
-
value
|
|
3148
|
-
});
|
|
3149
|
-
var clearAgentCredential = () => call("DELETE", FACTORY_CREDENTIAL_ROUTE);
|
|
3150
|
-
// ../../node_modules/.bun/@tanstack+start-server-core@1.169.45/node_modules/@tanstack/start-server-core/dist/esm/createSsrRpc.js
|
|
3151
|
-
var createSsrRpc = (functionId) => {
|
|
3152
|
-
const url = "/_serverFn/" + functionId;
|
|
3153
|
-
const serverFnMeta = { id: functionId };
|
|
3154
|
-
const fn = async (...args) => {
|
|
3155
|
-
return (await getServerFnById(functionId, { origin: "server" }))(...args);
|
|
3156
|
-
};
|
|
3157
|
-
return Object.assign(fn, {
|
|
3158
|
-
url,
|
|
3159
|
-
serverFnMeta,
|
|
3160
|
-
[TSS_SERVER_FUNCTION]: true
|
|
3161
|
-
});
|
|
3162
|
-
};
|
|
3163
|
-
// src/server/factory.ts
|
|
3164
|
-
/** What the Factory reads from the companion payload; nothing else crosses to the browser. */
|
|
3165
|
-
/** Board actions a person can take: core's Outcome actions, plus `create`, which needs no runner. */
|
|
3166
|
-
var FACTORY_ACTIONS = ["create", ...OUTCOME_ACTIONS];
|
|
3167
|
-
var MAX_FIELD = 65536;
|
|
3168
|
-
function validate(input) {
|
|
3169
|
-
if (typeof input?.companion !== "string" || !COMPANION_DIGEST_PATTERN.test(input.companion)) throw new Error("no registered companion was selected");
|
|
3170
|
-
if (!FACTORY_ACTIONS.includes(input.action)) throw new Error(`unknown factory action ${JSON.stringify(input.action)}`);
|
|
3171
|
-
if (input.action !== "create" && typeof input.id !== "string") throw new Error("the action names no Outcome");
|
|
3172
|
-
const fields = {};
|
|
3173
|
-
for (const [name, value] of Object.entries(input.fields ?? {})) if (typeof value === "string" && value.length <= MAX_FIELD) fields[name] = value;
|
|
3174
|
-
return {
|
|
3175
|
-
companion: input.companion,
|
|
3176
|
-
action: input.action,
|
|
3177
|
-
id: input.id,
|
|
3178
|
-
fields
|
|
3179
|
-
};
|
|
3180
|
-
}
|
|
3181
|
-
/** One Outcome action, checked by core's services exactly as the old form posts were. */
|
|
3182
|
-
var runFactoryAction = createServerFn({ method: "POST" }).validator(validate).handler(createSsrRpc("b0ff357be654d7d833a4f9550953dda5e215e97cdc5b21639aef40d8a2401c4f"));
|
|
3183
|
-
/** The Factory's view model: the companion payload, its runs and sessions, at one moment. */
|
|
3184
|
-
var getFactory = createServerFn({ method: "GET" }).validator((input) => {
|
|
3185
|
-
if (!COMPANION_DIGEST_PATTERN.test(input?.companion ?? "")) throw new Error("no registered companion was selected");
|
|
3186
|
-
return { companion: input.companion };
|
|
3187
|
-
}).handler(createSsrRpc("332ea72d0b70383661ce66a3228167cb05dc752e7269134a11855d1329c936aa"));
|
|
3188
|
-
// src/server/shell.ts
|
|
3189
|
-
/** `refresh` collects the companion again; every other call reads the held snapshot. */
|
|
3190
|
-
var getShell = createServerFn({ method: "GET" }).validator((input) => ({
|
|
3191
|
-
...validateStudioSearch(input),
|
|
3192
|
-
...input.refresh === true ? { refresh: true } : {}
|
|
3193
|
-
})).handler(createSsrRpc("b4cd58adfccec803b6c97478c78656e3acf554351ec97ef0ce550a10e235ebce"));
|
|
3194
|
-
// src/server/vault.ts
|
|
3195
|
-
var MAX_CONTENT = 5242880;
|
|
3196
|
-
function companionOf(input) {
|
|
3197
|
-
if (typeof input?.companion !== "string" || !COMPANION_DIGEST_PATTERN.test(input.companion)) throw new Error("no registered companion was selected");
|
|
3198
|
-
return input.companion;
|
|
3199
|
-
}
|
|
3200
|
-
var text = (value) => typeof value === "string" && value.length > 0 && value.length <= 4096 ? value : void 0;
|
|
3201
|
-
/** The vault page; core resolves every path against the selected companion. */
|
|
3202
|
-
var getVault = createServerFn({ method: "GET" }).validator((input) => ({
|
|
3203
|
-
companion: companionOf(input),
|
|
3204
|
-
path: text(input.path),
|
|
3205
|
-
dir: text(input.dir),
|
|
3206
|
-
refresh: input.refresh === true,
|
|
3207
|
-
wait: input.wait === true
|
|
3208
|
-
})).handler(createSsrRpc("cc0685774bfb5205a762c25bdd4b959c1f541584df4b67aac816fe529fa37c87"));
|
|
3209
|
-
var getVaultChildren = createServerFn({ method: "GET" }).validator((input) => {
|
|
3210
|
-
const dir = text(input.dir);
|
|
3211
|
-
if (!dir) throw new Error("the request names no folder");
|
|
3212
|
-
return {
|
|
3213
|
-
companion: companionOf(input),
|
|
3214
|
-
dir
|
|
3215
|
-
};
|
|
3216
|
-
}).handler(createSsrRpc("7564d662d1e0ede6133407d7dde8d613b3b11718bc4f95160680342deeaf9cfd"));
|
|
3217
|
-
var getVaultMatches = createServerFn({ method: "GET" }).validator((input) => ({
|
|
3218
|
-
companion: companionOf(input),
|
|
3219
|
-
query: typeof input.query === "string" ? input.query.slice(0, 200) : ""
|
|
3220
|
-
})).handler(createSsrRpc("99f4d57911b5959a331ed18424ab13369de22f8b2b142a146ea967742dfbc997"));
|
|
3221
|
-
/** A save; a stale token comes back as a conflict carrying the current content and token. */
|
|
3222
|
-
var saveVaultFile = createServerFn({ method: "POST" }).validator((input) => {
|
|
3223
|
-
const path = text(input.path);
|
|
3224
|
-
if (!path) throw new Error("save requires a path");
|
|
3225
|
-
if (typeof input.content !== "string" || input.content.length > MAX_CONTENT) throw new Error("save requires content within the size limit");
|
|
3226
|
-
return {
|
|
3227
|
-
companion: companionOf(input),
|
|
3228
|
-
path,
|
|
3229
|
-
content: input.content,
|
|
3230
|
-
token: text(input.token)
|
|
3231
|
-
};
|
|
3232
|
-
}).handler(createSsrRpc("63d1e2171062e2d082e16522c162963c4da2a71c447f69f0937bd6e5e10b73ba"));
|
|
3233
|
-
// src/server/views.ts
|
|
3234
|
-
var VIEWS = /* @__PURE__ */ new Set([
|
|
3235
|
-
"dashboard",
|
|
3236
|
-
"workflow",
|
|
3237
|
-
"skills",
|
|
3238
|
-
"specs"
|
|
3239
|
-
]);
|
|
3240
|
-
var getCompanionView = createServerFn({ method: "GET" }).validator((input) => {
|
|
3241
|
-
if (!VIEWS.has(input?.view)) throw new Error("unknown view");
|
|
3242
|
-
const search = validateStudioSearch(input);
|
|
3243
|
-
if (!search.companion || !COMPANION_DIGEST_PATTERN.test(search.companion)) throw new Error("no registered companion was selected");
|
|
3244
|
-
return {
|
|
3245
|
-
...search,
|
|
3246
|
-
view: input.view
|
|
3247
|
-
};
|
|
3248
|
-
}).handler(createSsrRpc("a09876e9d912d4f3edfe004081679f011fcebe77cfe1b2b25cf6f3e6f1eafc6a"));
|
|
3249
|
-
// src/lib/studio-queries.ts
|
|
3250
|
-
/**
|
|
3251
|
-
* Every companion-scoped Studio query, and which of them each trigger makes stale. Keys start
|
|
3252
|
-
* with the companion digest (`null` when none is selected), so one prefix is one companion.
|
|
3253
|
-
*/
|
|
3254
|
-
var keys = {
|
|
3255
|
-
companion: (companion) => [companion],
|
|
3256
|
-
shell: (companion) => [companion, "shell"],
|
|
3257
|
-
views: (companion) => [companion, "view"],
|
|
3258
|
-
factory: (companion) => [companion, "factory"],
|
|
3259
|
-
vault: (companion) => [companion, "vault"],
|
|
3260
|
-
vaultViews: (companion) => [
|
|
3261
|
-
companion,
|
|
3262
|
-
"vault",
|
|
3263
|
-
"view"
|
|
3264
|
-
],
|
|
3265
|
-
reports: (companion) => [companion, "reports"]
|
|
3266
|
-
};
|
|
3267
|
-
/** Per file and per filter, so unbounded; dropped a while after their last use. */
|
|
3268
|
-
var VAULT_GC_MS = 3e5;
|
|
3269
|
-
var shellQuery = (search) => queryOptions({
|
|
3270
|
-
queryKey: [...keys.shell(search.companion ?? null), search.studioMode ?? null],
|
|
3271
|
-
queryFn: () => getShell({ data: search })
|
|
3272
|
-
});
|
|
3273
|
-
var companionViewQuery = (view, search) => queryOptions({
|
|
3274
|
-
queryKey: [
|
|
3275
|
-
...keys.views(search.companion ?? null),
|
|
3276
|
-
view,
|
|
3277
|
-
search.studioMode ?? null
|
|
3278
|
-
],
|
|
3279
|
-
queryFn: () => getCompanionView({ data: {
|
|
3280
|
-
...search,
|
|
3281
|
-
view
|
|
3282
|
-
} })
|
|
3283
|
-
});
|
|
3284
|
-
var factoryQuery = (companion) => queryOptions({
|
|
3285
|
-
queryKey: keys.factory(companion),
|
|
3286
|
-
queryFn: () => getFactory({ data: { companion } }),
|
|
3287
|
-
refetchInterval: 3e4
|
|
3288
|
-
});
|
|
3289
|
-
var vaultQuery = (companion, search, wait = false) => queryOptions({
|
|
3290
|
-
queryKey: [
|
|
3291
|
-
...keys.vaultViews(companion),
|
|
3292
|
-
search.path ?? null,
|
|
3293
|
-
search.dir ?? null,
|
|
3294
|
-
wait
|
|
3295
|
-
],
|
|
3296
|
-
queryFn: () => getVault({ data: {
|
|
3297
|
-
companion,
|
|
3298
|
-
path: search.path,
|
|
3299
|
-
dir: search.dir,
|
|
3300
|
-
wait
|
|
3301
|
-
} }),
|
|
3302
|
-
gcTime: VAULT_GC_MS
|
|
3303
|
-
});
|
|
3304
|
-
var vaultChildrenQuery = (companion, dir) => queryOptions({
|
|
3305
|
-
queryKey: [
|
|
3306
|
-
...keys.vault(companion),
|
|
3307
|
-
"children",
|
|
3308
|
-
dir
|
|
3309
|
-
],
|
|
3310
|
-
queryFn: () => getVaultChildren({ data: {
|
|
3311
|
-
companion,
|
|
3312
|
-
dir
|
|
3313
|
-
} })
|
|
3314
|
-
});
|
|
3315
|
-
var vaultMatchesQuery = (companion, query) => queryOptions({
|
|
3316
|
-
queryKey: [
|
|
3317
|
-
...keys.vault(companion),
|
|
3318
|
-
"matches",
|
|
3319
|
-
query
|
|
3320
|
-
],
|
|
3321
|
-
queryFn: () => getVaultMatches({ data: {
|
|
3322
|
-
companion,
|
|
3323
|
-
query
|
|
3324
|
-
} }),
|
|
3325
|
-
gcTime: VAULT_GC_MS
|
|
3326
|
-
});
|
|
3327
|
-
var reportsQuery = (companion) => queryOptions({
|
|
3328
|
-
queryKey: keys.reports(companion),
|
|
3329
|
-
queryFn: async () => {
|
|
3330
|
-
const response = await fetch(`/api/reports?companion=${encodeURIComponent(companion)}`, { headers: { accept: "application/json" } });
|
|
3331
|
-
if (!response.ok) throw new Error(`status ${response.status}`);
|
|
3332
|
-
return (await response.json()).reports ?? [];
|
|
3333
|
-
}
|
|
3334
|
-
});
|
|
3335
|
-
async function stale(queryClient, ...queryKeys) {
|
|
3336
|
-
await Promise.all(queryKeys.map((queryKey) => queryClient.invalidateQueries({ queryKey })));
|
|
3337
|
-
}
|
|
3338
|
-
/** After a server event for `companion`; views refetch in place (design D7). */
|
|
3339
|
-
async function afterEvent(queryClient, companion, type) {
|
|
3340
|
-
if (type === "board") {
|
|
3341
|
-
if (queryClient.getQueryCache().find({ queryKey: keys.factory(companion) })?.isActive()) {
|
|
3342
|
-
await stale(queryClient, keys.factory(companion));
|
|
3343
|
-
await stale(queryClient, keys.shell(companion), keys.views(companion));
|
|
3344
|
-
} else await stale(queryClient, keys.factory(companion), keys.shell(companion), keys.views(companion));
|
|
3345
|
-
} else if (type === "reports") await stale(queryClient, keys.reports(companion));
|
|
3346
|
-
}
|
|
3347
|
-
var afterFactoryAction = (queryClient, companion) => stale(queryClient, keys.factory(companion));
|
|
3348
|
-
/** The refresh answer is shown at once; the companion's other vault reads follow. */
|
|
3349
|
-
function afterVaultRefresh(queryClient, companion, search, fresh) {
|
|
3350
|
-
const shown = vaultQuery(companion, search).queryKey;
|
|
3351
|
-
queryClient.setQueryData(shown, fresh);
|
|
3352
|
-
const answered = hashKey(shown);
|
|
3353
|
-
return queryClient.invalidateQueries({
|
|
3354
|
-
queryKey: keys.vault(companion),
|
|
3355
|
-
predicate: (query) => query.queryHash !== answered
|
|
3356
|
-
});
|
|
3357
|
-
}
|
|
3358
|
-
/** After the open file changed on disk or was saved. */
|
|
3359
|
-
var afterVaultFileChange = (queryClient, companion) => stale(queryClient, keys.vaultViews(companion));
|
|
3360
|
-
/**
|
|
3361
|
-
* After Refresh collected `companion` again; other companions keep what they hold. The agent
|
|
3362
|
-
* credential is not companion data but may change out of band; terminal sessions are polled.
|
|
3363
|
-
*/
|
|
3364
|
-
var afterRefresh = (queryClient, companion) => stale(queryClient, keys.companion(companion ?? null), agentCredentialKey);
|
|
3365
|
-
export { createFileRoute as $, defaultThrowOnError as A, hashKey as B, TERMINAL_SESSIONS_END_ROUTE as C, factoryLogRoute as D, TERMINAL_WASM as E, onlineManager as F, partialMatchKey as G, matchMutation as H, notifyManager as I, shouldThrowError as J, resolveQueryValue as K, focusManager as L, Query as M, Removable as N, factoryLogStreamRoute as O, createRetryer as P, lazyRouteComponent as Q, Subscribable as R, STUDIO_EVENTS_ROUTE as S, TERMINAL_SOCKET_ROUTE as T, matchQuery as U, hashQueryKeyByOptions as V, noop as W, QueryClientProvider as X, skipToken as Y, useQueryClient as Z, agentCredentialKey as _, afterVaultRefresh as a, setAgentCredential as b, reportsQuery as c, vaultMatchesQuery as d, createRootRouteWithContext as et, vaultQuery as f, runFactoryAction as g, getShell as h, afterVaultFileChange as i, QueryObserver as j, useBaseQuery as k, shellQuery as l, saveVaultFile as m, afterFactoryAction as n, useNavigate as nt, companionViewQuery as o, getVault as p, shallowEqualObjects as q, afterRefresh as r, factoryQuery as s, afterEvent as t, Link as tt, vaultChildrenQuery as u, agentCredentialQuery as v, TERMINAL_SESSIONS_ROUTE as w, REPORT_VIEW_PREFIX as x, clearAgentCredential as y, functionalUpdate as z };
|