@coffre/ui 0.1.17 → 0.2.0
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/README.md +23 -3
- package/dist/{server/_coffre/assets/affordances-CKANXDTG.js → chunks/affordances-DAvsVz7u.js} +12 -7
- package/dist/chunks/affordances-DAvsVz7u.js.map +1 -0
- package/dist/chunks/directory-CSjWWUQ1.js +370 -0
- package/dist/chunks/directory-CSjWWUQ1.js.map +1 -0
- package/dist/{server/_coffre/assets/grants-DdKT11Ny.js → chunks/grants-saMQagmG.js} +41 -39
- package/dist/chunks/grants-saMQagmG.js.map +1 -0
- package/dist/chunks/icons-D-PfAfnH.js +203 -0
- package/dist/chunks/icons-D-PfAfnH.js.map +1 -0
- package/dist/chunks/mounted-jJmqqV_n.js +17 -0
- package/dist/chunks/mounted-jJmqqV_n.js.map +1 -0
- package/dist/{server/_coffre/assets/offboarding-CRz-K82H.js → chunks/offboarding-C6l30DZR.js} +70 -69
- package/dist/chunks/offboarding-C6l30DZR.js.map +1 -0
- package/dist/chunks/page-C5HcNqf2.js +190 -0
- package/dist/chunks/page-C5HcNqf2.js.map +1 -0
- package/dist/chunks/page-route-Drfw7lmn.js +20 -0
- package/dist/chunks/page-route-Drfw7lmn.js.map +1 -0
- package/dist/{server/_coffre/assets/principal-page-C-EFwJQw.js → chunks/principal-page-D_91OA0l.js} +105 -103
- package/dist/chunks/principal-page-D_91OA0l.js.map +1 -0
- package/dist/{server/_coffre/assets → chunks}/project-environments-lEzFHUt4.js +2 -0
- package/dist/chunks/project-environments-lEzFHUt4.js.map +1 -0
- package/dist/chunks/queries-CQ81o4so.js +376 -0
- package/dist/chunks/queries-CQ81o4so.js.map +1 -0
- package/dist/{server/_coffre/assets/row-state-C2P57xT1.js → chunks/row-state-0PsrEzOL.js} +22 -21
- package/dist/chunks/row-state-0PsrEzOL.js.map +1 -0
- package/dist/{server/_coffre/assets → chunks}/signin-errors-BEFlVDbQ.js +2 -0
- package/dist/chunks/signin-errors-BEFlVDbQ.js.map +1 -0
- package/dist/chunks/theme-B2vQolVR.js +86 -0
- package/dist/chunks/theme-B2vQolVR.js.map +1 -0
- package/dist/chunks/ui-DixXLQvQ.js +405 -0
- package/dist/chunks/ui-DixXLQvQ.js.map +1 -0
- package/dist/{server/_coffre/assets/use-action-B-xpvVRO.js → chunks/use-action-CWsg_YWU.js} +8 -6
- package/dist/chunks/use-action-CWsg_YWU.js.map +1 -0
- package/dist/{server/_coffre/assets/use-change-C8BCf3oU.js → chunks/use-change-c6CeLRin.js} +10 -474
- package/dist/chunks/use-change-c6CeLRin.js.map +1 -0
- package/dist/chunks/use-shell-jxd7Tzd-.js +26 -0
- package/dist/chunks/use-shell-jxd7Tzd-.js.map +1 -0
- package/dist/{server/_coffre/assets → chunks}/validation-BQtqPe2V.js +2 -0
- package/dist/chunks/validation-BQtqPe2V.js.map +1 -0
- package/dist/index.d.ts +386 -18
- package/dist/index.js +1147 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/account.d.ts +9 -0
- package/dist/pages/account.js +334 -0
- package/dist/pages/account.js.map +1 -0
- package/dist/pages/audit.d.ts +3 -0
- package/dist/{server/_coffre/assets/audit-qB9G2AQJ.js → pages/audit.js} +102 -100
- package/dist/pages/audit.js.map +1 -0
- package/dist/pages/device-login.d.ts +9 -0
- package/dist/pages/device-login.js +211 -0
- package/dist/pages/device-login.js.map +1 -0
- package/dist/pages/environment.d.ts +3 -0
- package/dist/{server/_coffre/assets/projects._project._environment-C6uybzeU.js → pages/environment.js} +323 -469
- package/dist/pages/environment.js.map +1 -0
- package/dist/pages/login.d.ts +10 -0
- package/dist/pages/login.js +104 -0
- package/dist/pages/login.js.map +1 -0
- package/dist/pages/project.d.ts +2 -0
- package/dist/{server/_coffre/assets/projects._project.index-3CXwkyTh.js → pages/project.js} +223 -225
- package/dist/pages/project.js.map +1 -0
- package/dist/pages/projects.d.ts +3 -0
- package/dist/{server/_coffre/assets/projects.index-iSoBpRFz.js → pages/projects.js} +83 -81
- package/dist/pages/projects.js.map +1 -0
- package/dist/pages/settings.d.ts +3 -0
- package/dist/{server/_coffre/assets/settings-BDQTF5XW.js → pages/settings.js} +20 -18
- package/dist/pages/settings.js.map +1 -0
- package/dist/pages/token.d.ts +3 -0
- package/dist/{server/_coffre/assets/tokens._token-CrBMpcbN.js → pages/token.js} +195 -265
- package/dist/pages/token.js.map +1 -0
- package/dist/pages/tokens.d.ts +3 -0
- package/dist/pages/tokens.js +39 -0
- package/dist/pages/tokens.js.map +1 -0
- package/dist/pages/unregistered.d.ts +8 -0
- package/dist/pages/unregistered.js +54 -0
- package/dist/pages/unregistered.js.map +1 -0
- package/dist/pages/user.d.ts +3 -0
- package/dist/pages/user.js +16 -0
- package/dist/pages/user.js.map +1 -0
- package/dist/pages/users.d.ts +3 -0
- package/dist/pages/users.js +39 -0
- package/dist/pages/users.js.map +1 -0
- package/dist/project-BqIy8gYR.d.ts +5 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +52 -0
- package/package.json +36 -21
- package/src/assets/icon.svg +1 -0
- package/src/components/affordances.ts +10 -4
- package/src/components/command-palette.tsx +229 -203
- package/src/components/directory.tsx +34 -38
- package/src/components/principal.tsx +7 -3
- package/src/components/shell.tsx +89 -127
- package/src/components/theme.tsx +14 -81
- package/src/components/ui.tsx +97 -68
- package/src/index.ts +29 -0
- package/src/layout.tsx +113 -0
- package/src/lib/coffre.ts +8 -4
- package/src/lib/mounted.ts +13 -0
- package/src/lib/page-context.ts +31 -0
- package/src/lib/page-route.ts +22 -0
- package/src/lib/preferences.tsx +46 -0
- package/src/options.ts +240 -0
- package/src/{routes → pages}/account.tsx +7 -24
- package/src/{routes → pages}/audit.tsx +5 -16
- package/src/{routes/auth.device.tsx → pages/device-login.tsx} +8 -21
- package/src/{routes/projects.$project.$environment.tsx → pages/environment.tsx} +43 -52
- package/src/{routes → pages}/login.tsx +5 -16
- package/src/{routes/projects.$project.index.tsx → pages/project.tsx} +38 -50
- package/src/{routes/projects.index.tsx → pages/projects.tsx} +2 -7
- package/src/{routes → pages}/settings.tsx +3 -10
- package/src/{routes/tokens.$token.tsx → pages/token.tsx} +6 -7
- package/src/{routes/tokens.index.tsx → pages/tokens.tsx} +3 -8
- package/src/{routes → pages}/unregistered.tsx +1 -6
- package/src/pages/user.tsx +10 -0
- package/src/{routes/users.index.tsx → pages/users.tsx} +3 -8
- package/src/register.ts +55 -0
- package/src/router.tsx +31 -62
- package/src/styles/globals.css +104 -46
- package/src/vite.ts +78 -0
- package/dist/client/.assetsignore +0 -2
- package/dist/client/_coffre/assets/account-BoLGAxbD.js +0 -2
- package/dist/client/_coffre/assets/account-CnnuRTDB.js +0 -1
- package/dist/client/_coffre/assets/affordances-CEafRJcN.js +0 -1
- package/dist/client/_coffre/assets/audit-CHSvKLWX.js +0 -1
- package/dist/client/_coffre/assets/audit-Cn4hmS4u.js +0 -2
- package/dist/client/_coffre/assets/auth.device-Co5vrpaA.js +0 -2
- package/dist/client/_coffre/assets/auth.device-DAlqWacc.js +0 -1
- package/dist/client/_coffre/assets/directory-H8Eh3MnS.js +0 -1
- package/dist/client/_coffre/assets/dist-Braunv_x.js +0 -1
- package/dist/client/_coffre/assets/globals-CpMrgkV6.css +0 -1
- package/dist/client/_coffre/assets/grants-DPDxJXU1.js +0 -1
- package/dist/client/_coffre/assets/icons-Dc_-t0lp.js +0 -1
- package/dist/client/_coffre/assets/index-sUCIXRgJ.js +0 -12
- package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/client/_coffre/assets/link-DBINMwm6.js +0 -1
- package/dist/client/_coffre/assets/login-BZFYfL1Y.js +0 -1
- package/dist/client/_coffre/assets/login-CYCKWTOD.js +0 -2
- package/dist/client/_coffre/assets/offboarding-Bwpftp3g.js +0 -1
- package/dist/client/_coffre/assets/page-C_hnzdaR.js +0 -1
- package/dist/client/_coffre/assets/preload-helper-CLkO85Nq.js +0 -1
- package/dist/client/_coffre/assets/principal-page-DLho8TSJ.js +0 -1
- package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +0 -1
- package/dist/client/_coffre/assets/projects._project._environment-DHRRvQw0.js +0 -3
- package/dist/client/_coffre/assets/projects._project._environment-TLI-RjBZ.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-BO-8FZIY.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-DGl921dP.js +0 -1
- package/dist/client/_coffre/assets/projects.index-BDn7Bhoo.js +0 -1
- package/dist/client/_coffre/assets/row-state-DJ-KLamZ.js +0 -1
- package/dist/client/_coffre/assets/settings-q9G1QvR_.js +0 -1
- package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +0 -1
- package/dist/client/_coffre/assets/suspense-O8sP0mEC.js +0 -1
- package/dist/client/_coffre/assets/tokens._token-B_qczpT9.js +0 -2
- package/dist/client/_coffre/assets/tokens._token-T-sqwMbz.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-CcXSZnAG.js +0 -1
- package/dist/client/_coffre/assets/ui-BXP2IqrW.js +0 -46
- package/dist/client/_coffre/assets/unregistered-D2JXJ90x.js +0 -1
- package/dist/client/_coffre/assets/use-action-BpzKWhgg.js +0 -1
- package/dist/client/_coffre/assets/use-change-CKj3Inq9.js +0 -1
- package/dist/client/_coffre/assets/use-shell-W0SusPkz.js +0 -1
- package/dist/client/_coffre/assets/useQuery-B-lxFSES.js +0 -1
- package/dist/client/_coffre/assets/useSuspenseQuery-BZ-nzHST.js +0 -1
- package/dist/client/_coffre/assets/users._user-Bb3BGYHl.js +0 -1
- package/dist/client/_coffre/assets/users._user-DXmvKrzE.js +0 -2
- package/dist/client/_coffre/assets/users.index-BvzP3qwW.js +0 -1
- package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +0 -1
- package/dist/server/.vite/manifest.json +0 -668
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-GsKnGGRy.js +0 -162
- package/dist/server/_coffre/assets/account-CV-a2IU2.js +0 -329
- package/dist/server/_coffre/assets/account-hk6wcIXU.js +0 -162
- package/dist/server/_coffre/assets/async-local-storage-C10uQtMM.js +0 -3108
- package/dist/server/_coffre/assets/audit-C1_Ej6YB.js +0 -31
- package/dist/server/_coffre/assets/auth.device-6JRrWbSV.js +0 -210
- package/dist/server/_coffre/assets/auth.device-CLoAxC2T.js +0 -29
- package/dist/server/_coffre/assets/directory-B-_rqsPx.js +0 -371
- package/dist/server/_coffre/assets/dist-CnnV3t2g.js +0 -908
- package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +0 -5
- package/dist/server/_coffre/assets/globals-CpMrgkV6.css +0 -1
- package/dist/server/_coffre/assets/icons-DOFT-eWB.js +0 -1704
- package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +0 -480
- package/dist/server/_coffre/assets/link-42ZWdjzZ.js +0 -422
- package/dist/server/_coffre/assets/login-DRKUKkaW.js +0 -22
- package/dist/server/_coffre/assets/login-DnwxVl4Y.js +0 -102
- package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +0 -56
- package/dist/server/_coffre/assets/page-D6n45dcK.js +0 -3561
- package/dist/server/_coffre/assets/projects._project._environment-CS8DdSMY.js +0 -48
- package/dist/server/_coffre/assets/projects._project.index-BGfcNpj0.js +0 -23
- package/dist/server/_coffre/assets/react-dom-bBoJXlK2.js +0 -1718
- package/dist/server/_coffre/assets/router-9BTgJhWG.js +0 -2322
- package/dist/server/_coffre/assets/start-DR3rN0St.js +0 -4
- package/dist/server/_coffre/assets/suspense-C-2QfDd2.js +0 -602
- package/dist/server/_coffre/assets/tokens._token-rY86Cjgp.js +0 -10
- package/dist/server/_coffre/assets/tokens.index-Bq5qDW9q.js +0 -37
- package/dist/server/_coffre/assets/ui-Cc0CGMtr.js +0 -14881
- package/dist/server/_coffre/assets/unregistered-D9ZKLOPJ.js +0 -53
- package/dist/server/_coffre/assets/use-shell-DwOzEi87.js +0 -462
- package/dist/server/_coffre/assets/useQuery-CTe86qFq.js +0 -8
- package/dist/server/_coffre/assets/useRouter-CaUSUNsw.js +0 -473
- package/dist/server/_coffre/assets/useSuspenseQuery-CSoHzrMb.js +0 -117
- package/dist/server/_coffre/assets/users._user-BmLKYeo_.js +0 -10
- package/dist/server/_coffre/assets/users._user-BmiHwQx3.js +0 -14
- package/dist/server/_coffre/assets/users.index-BiEax90r.js +0 -37
- package/dist/server/index.js +0 -13911
- package/src/assets/favicon-32.png +0 -0
- package/src/components/agentation.tsx +0 -34
- package/src/entry.ts +0 -19
- package/src/routeTree.gen.ts +0 -367
- package/src/routes/__root.tsx +0 -169
- package/src/routes/access.tsx +0 -11
- package/src/routes/index.tsx +0 -15
- package/src/routes/users.$user.tsx +0 -13
- package/src/types.ts +0 -21
|
@@ -1,3561 +0,0 @@
|
|
|
1
|
-
import { r as require_jsx_runtime, t as useRouter } from "./useRouter-CaUSUNsw.js";
|
|
2
|
-
//#region ../client/dist/index.js
|
|
3
|
-
/** The API's error shape, `{ error, message }`, with the HTTP status. */
|
|
4
|
-
var COFFRE_ERROR = Symbol.for("@coffre/client:CoffreError");
|
|
5
|
-
var CoffreError = class extends Error {
|
|
6
|
-
/**
|
|
7
|
-
* `@coffre/ui`'s prebuilt pages bundle a copy of this class, and a page is
|
|
8
|
-
* handed a client the server made with this package's. So `instanceof`
|
|
9
|
-
* asks for the mark every copy leaves, rather than for this copy's prototype.
|
|
10
|
-
*/
|
|
11
|
-
static [Symbol.hasInstance](value) {
|
|
12
|
-
return typeof value === "object" && value !== null && COFFRE_ERROR in value;
|
|
13
|
-
}
|
|
14
|
-
[COFFRE_ERROR] = true;
|
|
15
|
-
status;
|
|
16
|
-
code;
|
|
17
|
-
/** The vault's own code when it refused: `no_grant`, `removed`, `bulk_limit`, ... */
|
|
18
|
-
reason;
|
|
19
|
-
constructor(status, code, message, reason) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = "CoffreError";
|
|
22
|
-
this.status = status;
|
|
23
|
-
this.code = code;
|
|
24
|
-
this.reason = reason;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
/** `market/prod/KEY` as route parameters. */
|
|
28
|
-
function place(path) {
|
|
29
|
-
const [project = "", environment = "", key = ""] = path.replace(/^\/+|\/+$/g, "").split("/");
|
|
30
|
-
return {
|
|
31
|
-
project,
|
|
32
|
-
environment,
|
|
33
|
-
key
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function createClient(options) {
|
|
37
|
-
const origin = options.url.replace(/\/+$/, "");
|
|
38
|
-
const transport = options.transport ?? ((request) => fetch(request));
|
|
39
|
-
async function send(method, path, input) {
|
|
40
|
-
const url = new URL(`${origin}/api${path}`);
|
|
41
|
-
const headers = new Headers(await options.headers?.());
|
|
42
|
-
let body;
|
|
43
|
-
if (method === "GET") {
|
|
44
|
-
for (const [name, value] of Object.entries(input ?? {})) if (value !== void 0 && value !== null) url.searchParams.set(name, String(value));
|
|
45
|
-
} else if (input !== void 0) {
|
|
46
|
-
headers.set("content-type", "application/json");
|
|
47
|
-
body = JSON.stringify(input);
|
|
48
|
-
}
|
|
49
|
-
const response = await transport(new Request(url, {
|
|
50
|
-
method,
|
|
51
|
-
headers,
|
|
52
|
-
body
|
|
53
|
-
}));
|
|
54
|
-
const payload = await response.json().catch(() => null);
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
const error = payload;
|
|
57
|
-
throw new CoffreError(response.status, typeof error?.error === "string" ? error.error : "http_error", typeof error?.message === "string" ? error.message : `request failed with status ${response.status}`, typeof error?.reason === "string" ? error.reason : void 0);
|
|
58
|
-
}
|
|
59
|
-
return payload;
|
|
60
|
-
}
|
|
61
|
-
/** A route key and its parameters as a method and a path. */
|
|
62
|
-
function address(key, params) {
|
|
63
|
-
const [method, pattern] = key.split(" ");
|
|
64
|
-
return [method, pattern.replace(/:(\w+)/g, (_, name) => encodeURIComponent(params[name]))];
|
|
65
|
-
}
|
|
66
|
-
/** Any route by its key: `call('GET /secrets/:project/:environment', { project, environment })`. */
|
|
67
|
-
async function call(key, ...[params, input]) {
|
|
68
|
-
const [method, path] = address(key, params);
|
|
69
|
-
return await send(method, path, input);
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
call,
|
|
73
|
-
/** How this instance signs people in. Answers anyone, signed in or not. */
|
|
74
|
-
auth: () => send("GET", "/auth", void 0),
|
|
75
|
-
/** Who I am, and every place I can reach. */
|
|
76
|
-
me: () => call("GET /me", {}),
|
|
77
|
-
projects: {
|
|
78
|
-
/** With their environments. */
|
|
79
|
-
list: () => call("GET /projects", {}),
|
|
80
|
-
create: (project, input) => call("PUT /projects/:project", { project }, input),
|
|
81
|
-
update: (project, patch) => call("PATCH /projects/:project", { project }, patch)
|
|
82
|
-
},
|
|
83
|
-
environments: {
|
|
84
|
-
create: (path, input) => call("PUT /projects/:project/:environment", place(path), input),
|
|
85
|
-
update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch)
|
|
86
|
-
},
|
|
87
|
-
secrets: {
|
|
88
|
-
/** Keys, versions and who changed what; never values. */
|
|
89
|
-
list: (path) => call("GET /secrets/:project/:environment", place(path)),
|
|
90
|
-
/** Decrypts one secret, or every secret in an environment. Logged in your name. */
|
|
91
|
-
reveal: (path) => call("POST /reveals", {}, { path }),
|
|
92
|
-
/** One transaction, a version and an audit entry per key; `null` archives. */
|
|
93
|
-
set: (path, values) => call("PATCH /secrets/:project/:environment", place(path), values),
|
|
94
|
-
/**
|
|
95
|
-
* What `set` would do to each key, `added`, `changed`, `unchanged` or
|
|
96
|
-
* `archived`, and nothing else: no value comes back and nothing is
|
|
97
|
-
* written. Comparing opens the current values, logged as reads.
|
|
98
|
-
*/
|
|
99
|
-
dryRun: (path, values) => {
|
|
100
|
-
const [method, route] = address("PATCH /secrets/:project/:environment", place(path));
|
|
101
|
-
return send(method, `${route}?dryRun=1`, values);
|
|
102
|
-
},
|
|
103
|
-
history: (path) => call("GET /secrets/:project/:environment/:key/versions", place(path)),
|
|
104
|
-
/** A new version holding the old one's value. */
|
|
105
|
-
restore: (path, version) => call("POST /secrets/:project/:environment/:key/restore", place(path), { version }),
|
|
106
|
-
rename: (path, key) => call("PATCH /secrets/:project/:environment/:key", place(path), { key }),
|
|
107
|
-
update: (path, patch) => call("PATCH /secrets/:project/:environment/:key", place(path), patch)
|
|
108
|
-
},
|
|
109
|
-
members: {
|
|
110
|
-
/** People and tokens, their role and their access; at a place, those who reach it. */
|
|
111
|
-
list: (path) => call("GET /members", {}, { path }),
|
|
112
|
-
/** What they hold, and what to rotate if they leave. */
|
|
113
|
-
get: (member) => call("GET /members/:member", { member }),
|
|
114
|
-
add: (member, input = {}) => call("PUT /members/:member", { member }, input),
|
|
115
|
-
/** Offboards; returns what to rotate. */
|
|
116
|
-
remove: (member) => call("DELETE /members/:member", { member })
|
|
117
|
-
},
|
|
118
|
-
tokens: {
|
|
119
|
-
list: (member) => call("GET /members/:member/tokens", { member }),
|
|
120
|
-
/** The value is in the answer, and only there. */
|
|
121
|
-
issue: (member, input) => call("POST /members/:member/tokens", { member }, input),
|
|
122
|
-
revoke: (member, id) => call("DELETE /members/:member/tokens/:id", {
|
|
123
|
-
member,
|
|
124
|
-
id
|
|
125
|
-
})
|
|
126
|
-
},
|
|
127
|
-
/** Trust bindings: which CI runs may sign in as a service, by their platform's ID token. */
|
|
128
|
-
bindings: {
|
|
129
|
-
list: (member) => call("GET /members/:member/bindings", { member }),
|
|
130
|
-
/** The binding as it would be saved, the keys its issuer names, and what it replaces; writes nothing. */
|
|
131
|
-
preview: (member, input) => {
|
|
132
|
-
const [method, route] = address("POST /members/:member/bindings", { member });
|
|
133
|
-
return send(method, `${route}?dryRun=1`, input);
|
|
134
|
-
},
|
|
135
|
-
create: (member, input) => call("POST /members/:member/bindings", { member }, input),
|
|
136
|
-
remove: (member, id) => call("DELETE /members/:member/bindings/:id", {
|
|
137
|
-
member,
|
|
138
|
-
id
|
|
139
|
-
}),
|
|
140
|
-
/** A public GitHub repository's or GitLab project's IDs, which bindings name. */
|
|
141
|
-
lookup: (input) => call("GET /workloads/lookup", {}, input)
|
|
142
|
-
},
|
|
143
|
-
access: {
|
|
144
|
-
/** What they should hold at each place; the server applies the difference. `null` revokes. */
|
|
145
|
-
set: (member, access) => call("PATCH /access/:member", { member }, access) },
|
|
146
|
-
/** Where I am signed in. Only where coffre runs its own sign-in. */
|
|
147
|
-
sessions: {
|
|
148
|
-
list: () => call("GET /sessions", {}),
|
|
149
|
-
revoke: (id) => call("DELETE /sessions/:id", { id })
|
|
150
|
-
},
|
|
151
|
-
/** The accounts I sign in with. */
|
|
152
|
-
identities: {
|
|
153
|
-
list: () => call("GET /identities", {}),
|
|
154
|
-
unlink: (id) => call("DELETE /identities/:id", { id })
|
|
155
|
-
},
|
|
156
|
-
/** A `coffre login` waiting for someone to approve it, by the code it shows. */
|
|
157
|
-
deviceLogins: {
|
|
158
|
-
get: (code) => call("GET /device-logins/:code", { code }),
|
|
159
|
-
decide: (code, approve) => call("POST /device-logins/:code", { code }, { approve })
|
|
160
|
-
},
|
|
161
|
-
audit: {
|
|
162
|
-
list: (query = {}) => call("GET /audit", {}, query),
|
|
163
|
-
verify: () => call("GET /audit/verification", {}),
|
|
164
|
-
/** What an escrowed key is checked against: public material, owners and root admins only. */
|
|
165
|
-
keys: () => call("GET /audit/keys", {})
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* What writing these entries (a parsed `.env` file) would do, from a dry run
|
|
171
|
-
* of the write: the server compares, so no value leaves it, and the values it
|
|
172
|
-
* opens to compare are logged as reads. `changes` is what to pass to
|
|
173
|
-
* `secrets.set`: the keys that differ, so an unchanged value does not become
|
|
174
|
-
* a new version.
|
|
175
|
-
*/
|
|
176
|
-
async function planImport(coffre, path, entries) {
|
|
177
|
-
const values = Object.create(null);
|
|
178
|
-
for (const { key, value } of entries) values[key] = value;
|
|
179
|
-
const [listed, compared] = await Promise.allSettled([coffre.secrets.list(path), coffre.secrets.dryRun(path, { ...values })]);
|
|
180
|
-
if (listed.status === "rejected") throw listed.reason;
|
|
181
|
-
if (compared.status === "rejected") throw compared.reason;
|
|
182
|
-
const [{ keys }, dryRun] = [listed.value, compared.value];
|
|
183
|
-
const versions = new Map(keys.map((entry) => [entry.key, entry.version]));
|
|
184
|
-
const plan = [];
|
|
185
|
-
const changes = Object.create(null);
|
|
186
|
-
for (const [key, value] of Object.entries(values)) {
|
|
187
|
-
const action = dryRun.keys[key];
|
|
188
|
-
plan.push({
|
|
189
|
-
key,
|
|
190
|
-
action,
|
|
191
|
-
version: versions.get(key) ?? null
|
|
192
|
-
});
|
|
193
|
-
if (action !== "unchanged") changes[key] = value;
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
plan,
|
|
197
|
-
changes: { ...changes }
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/timeoutManager.js
|
|
202
|
-
var defaultTimeoutProvider = {
|
|
203
|
-
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
204
|
-
clearTimeout: (timeoutId) => clearTimeout(timeoutId),
|
|
205
|
-
setInterval: (callback, delay) => setInterval(callback, delay),
|
|
206
|
-
clearInterval: (intervalId) => clearInterval(intervalId)
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* Allows customization of how timeouts are created.
|
|
210
|
-
*
|
|
211
|
-
* @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
|
|
212
|
-
* and `gcTime`. The default TimeoutManager provider uses the platform's global
|
|
213
|
-
* `setTimeout` implementation, which is known to have scalability issues with
|
|
214
|
-
* thousands of timeouts on the event loop.
|
|
215
|
-
*
|
|
216
|
-
* If you hit this limitation, consider providing a custom TimeoutProvider that
|
|
217
|
-
* coalesces timeouts.
|
|
218
|
-
*/
|
|
219
|
-
var TimeoutManager = class {
|
|
220
|
-
#provider = defaultTimeoutProvider;
|
|
221
|
-
#providerCalled = false;
|
|
222
|
-
/**
|
|
223
|
-
* `setTimeoutProvider` can be used to set a custom implementation of the
|
|
224
|
-
* `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` functions,
|
|
225
|
-
* called a `TimeoutProvider`.
|
|
226
|
-
*
|
|
227
|
-
* This may be useful if you notice event loop performance issues with
|
|
228
|
-
* thousands of queries. A custom TimeoutProvider could also support timer
|
|
229
|
-
* delays longer than the global `setTimeout` maximum delay value of about
|
|
230
|
-
* 24 days.
|
|
231
|
-
*
|
|
232
|
-
* It is important to call `setTimeoutProvider` before creating a
|
|
233
|
-
* QueryClient or queries, so that the same provider is used consistently
|
|
234
|
-
* for all timers in the application, since different TimeoutProviders
|
|
235
|
-
* cannot cancel each others' timers.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* import { timeoutManager, QueryClient } from '@tanstack/query-core'
|
|
240
|
-
* import { CustomTimeoutProvider } from './CustomTimeoutProvider'
|
|
241
|
-
*
|
|
242
|
-
* timeoutManager.setTimeoutProvider(new CustomTimeoutProvider())
|
|
243
|
-
*
|
|
244
|
-
* export const queryClient = new QueryClient()
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
setTimeoutProvider(provider) {
|
|
248
|
-
this.#provider = provider;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* `setTimeout` schedules a callback to run after approximately `delay`
|
|
252
|
-
* milliseconds, like the global `setTimeout` function. The callback can be
|
|
253
|
-
* canceled with `clearTimeout`.
|
|
254
|
-
*
|
|
255
|
-
* It returns a timer ID, which may be a number or an object that can be
|
|
256
|
-
* coerced to a number via `Symbol.toPrimitive`.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```ts
|
|
260
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
261
|
-
*
|
|
262
|
-
* const timeoutId = timeoutManager.setTimeout(
|
|
263
|
-
* () => console.log('ran at:', new Date()),
|
|
264
|
-
* 1000,
|
|
265
|
-
* )
|
|
266
|
-
*
|
|
267
|
-
* const timeoutIdNumber: number = Number(timeoutId)
|
|
268
|
-
* ```
|
|
269
|
-
*/
|
|
270
|
-
setTimeout(callback, delay) {
|
|
271
|
-
return this.#provider.setTimeout(callback, delay);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,
|
|
275
|
-
* like the global `clearTimeout` function. It should be called with a
|
|
276
|
-
* timer ID returned by `setTimeout`.
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```ts
|
|
280
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
281
|
-
*
|
|
282
|
-
* const timeoutId = timeoutManager.setTimeout(
|
|
283
|
-
* () => console.log('ran at:', new Date()),
|
|
284
|
-
* 1000,
|
|
285
|
-
* )
|
|
286
|
-
*
|
|
287
|
-
* timeoutManager.clearTimeout(timeoutId)
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
clearTimeout(timeoutId) {
|
|
291
|
-
this.#provider.clearTimeout(timeoutId);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* `setInterval` schedules a callback to be called approximately every
|
|
295
|
-
* `delay` milliseconds, like the global `setInterval` function.
|
|
296
|
-
*
|
|
297
|
-
* Like `setTimeout`, it returns a timer ID, which may be a number or an
|
|
298
|
-
* object that can be coerced to a number via `Symbol.toPrimitive`.
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
303
|
-
*
|
|
304
|
-
* const intervalId = timeoutManager.setInterval(
|
|
305
|
-
* () => console.log('ran at:', new Date()),
|
|
306
|
-
* 1000,
|
|
307
|
-
* )
|
|
308
|
-
* ```
|
|
309
|
-
*/
|
|
310
|
-
setInterval(callback, delay) {
|
|
311
|
-
return this.#provider.setInterval(callback, delay);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* `clearInterval` can be used to cancel an interval, like the global
|
|
315
|
-
* `clearInterval` function. It should be called with an interval ID
|
|
316
|
-
* returned by `setInterval`.
|
|
317
|
-
*
|
|
318
|
-
* @example
|
|
319
|
-
* ```ts
|
|
320
|
-
* import { timeoutManager } from '@tanstack/query-core'
|
|
321
|
-
*
|
|
322
|
-
* const intervalId = timeoutManager.setInterval(
|
|
323
|
-
* () => console.log('ran at:', new Date()),
|
|
324
|
-
* 1000,
|
|
325
|
-
* )
|
|
326
|
-
*
|
|
327
|
-
* timeoutManager.clearInterval(intervalId)
|
|
328
|
-
* ```
|
|
329
|
-
*/
|
|
330
|
-
clearInterval(intervalId) {
|
|
331
|
-
this.#provider.clearInterval(intervalId);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
/**
|
|
335
|
-
* Singleton instance of {@link TimeoutManager}, used throughout TanStack Query to schedule and cancel timers.
|
|
336
|
-
*/
|
|
337
|
-
var timeoutManager = new TimeoutManager();
|
|
338
|
-
/**
|
|
339
|
-
* In many cases code wants to delay to the next event loop tick; this is not
|
|
340
|
-
* mediated by {@link timeoutManager}.
|
|
341
|
-
*
|
|
342
|
-
* This function is provided to make auditing the `tanstack/query-core` for
|
|
343
|
-
* incorrect use of system `setTimeout` easier.
|
|
344
|
-
*/
|
|
345
|
-
function systemSetTimeoutZero(callback) {
|
|
346
|
-
setTimeout(callback, 0);
|
|
347
|
-
}
|
|
348
|
-
//#endregion
|
|
349
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/utils.js
|
|
350
|
-
/** @deprecated
|
|
351
|
-
* use `environmentManager.isServer()` instead.
|
|
352
|
-
*/
|
|
353
|
-
var isServer$1 = typeof window === "undefined" || "Deno" in globalThis;
|
|
354
|
-
function noop() {}
|
|
355
|
-
function functionalUpdate(updater, input) {
|
|
356
|
-
return typeof updater === "function" ? updater(input) : updater;
|
|
357
|
-
}
|
|
358
|
-
function isValidTimeout(value) {
|
|
359
|
-
return typeof value === "number" && value >= 0 && value !== Infinity;
|
|
360
|
-
}
|
|
361
|
-
function timeUntilStale(updatedAt, staleTime) {
|
|
362
|
-
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
363
|
-
}
|
|
364
|
-
function resolveQueryValue(value, query) {
|
|
365
|
-
return typeof value === "function" ? value(query) : value;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Checks whether a query matches the given {@link QueryFilters}.
|
|
369
|
-
* Every filter that is specified must match; filters that are left unspecified are ignored.
|
|
370
|
-
*
|
|
371
|
-
* @example
|
|
372
|
-
* ```ts
|
|
373
|
-
* const queryCache = queryClient.getQueryCache()
|
|
374
|
-
*
|
|
375
|
-
* const matchingQueries = queryCache
|
|
376
|
-
* .getAll()
|
|
377
|
-
* .filter((query) => matchQuery({ queryKey: ['posts'] }, query))
|
|
378
|
-
* ```
|
|
379
|
-
*/
|
|
380
|
-
function matchQuery(filters, query) {
|
|
381
|
-
const { type = "all", exact, fetchStatus, predicate, queryKey, stale } = filters;
|
|
382
|
-
if (queryKey) {
|
|
383
|
-
if (exact) {
|
|
384
|
-
if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) return false;
|
|
385
|
-
} else if (!partialMatchKey(query.queryKey, queryKey)) return false;
|
|
386
|
-
}
|
|
387
|
-
if (type !== "all") {
|
|
388
|
-
const isActive = query.isActive();
|
|
389
|
-
if (type === "active" && !isActive) return false;
|
|
390
|
-
if (type === "inactive" && isActive) return false;
|
|
391
|
-
}
|
|
392
|
-
if (typeof stale === "boolean" && query.isStale() !== stale) return false;
|
|
393
|
-
if (fetchStatus && fetchStatus !== query.state.fetchStatus) return false;
|
|
394
|
-
if (predicate && !predicate(query)) return false;
|
|
395
|
-
return true;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Checks whether a mutation matches the given {@link MutationFilters}.
|
|
399
|
-
* Every filter that is specified must match; filters that are left unspecified are ignored.
|
|
400
|
-
* If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.
|
|
401
|
-
*
|
|
402
|
-
* @example
|
|
403
|
-
* ```ts
|
|
404
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
405
|
-
*
|
|
406
|
-
* const matchingMutations = mutationCache
|
|
407
|
-
* .getAll()
|
|
408
|
-
* .filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
function matchMutation(filters, mutation) {
|
|
412
|
-
const { exact, status, predicate, mutationKey } = filters;
|
|
413
|
-
if (mutationKey) {
|
|
414
|
-
if (!mutation.options.mutationKey) return false;
|
|
415
|
-
if (exact) {
|
|
416
|
-
if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) return false;
|
|
417
|
-
} else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) return false;
|
|
418
|
-
}
|
|
419
|
-
if (status && mutation.state.status !== status) return false;
|
|
420
|
-
if (predicate && !predicate(mutation)) return false;
|
|
421
|
-
return true;
|
|
422
|
-
}
|
|
423
|
-
function hashQueryKeyByOptions(queryKey, options) {
|
|
424
|
-
return (options?.queryKeyHashFn || hashKey)(queryKey);
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Default query & mutation keys hash function.
|
|
428
|
-
* Hashes the value into a stable hash.
|
|
429
|
-
*
|
|
430
|
-
* @example
|
|
431
|
-
* ```ts
|
|
432
|
-
* // Object keys are sorted, so key order doesn't affect the hash:
|
|
433
|
-
* hashKey(['todos', { page: 1, filter: 'done' }]) // === '["todos",{"filter":"done","page":1}]'
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
function hashKey(queryKey) {
|
|
437
|
-
return JSON.stringify(queryKey, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
|
|
438
|
-
result[key] = val[key];
|
|
439
|
-
return result;
|
|
440
|
-
}, {}) : val);
|
|
441
|
-
}
|
|
442
|
-
function partialMatchKey(a, b) {
|
|
443
|
-
if (a === b) return true;
|
|
444
|
-
if (typeof a !== typeof b) return false;
|
|
445
|
-
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
446
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
447
|
-
if (b.length > a.length) return false;
|
|
448
|
-
for (let i = 0; i < b.length; i++) if (!partialMatchKey(a[i], b[i])) return false;
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
const bKeys = Object.keys(b);
|
|
452
|
-
for (const key of bKeys) if (!partialMatchKey(a[key], b[key])) return false;
|
|
453
|
-
return true;
|
|
454
|
-
}
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
|
458
|
-
function replaceEqualDeep(a, b, depth = 0) {
|
|
459
|
-
if (a === b) return a;
|
|
460
|
-
if (depth > 500) return b;
|
|
461
|
-
const array = isPlainArray(a) && isPlainArray(b);
|
|
462
|
-
if (!array && !(isPlainObject(a) && isPlainObject(b))) return b;
|
|
463
|
-
const aSize = (array ? a : Object.keys(a)).length;
|
|
464
|
-
const bItems = array ? b : Object.keys(b);
|
|
465
|
-
const bSize = bItems.length;
|
|
466
|
-
const copy = array ? new Array(bSize) : {};
|
|
467
|
-
let equalItems = 0;
|
|
468
|
-
for (let i = 0; i < bSize; i++) {
|
|
469
|
-
const key = array ? i : bItems[i];
|
|
470
|
-
const aItem = a[key];
|
|
471
|
-
const bItem = b[key];
|
|
472
|
-
if (aItem === bItem) {
|
|
473
|
-
copy[key] = aItem;
|
|
474
|
-
if (array ? i < aSize : hasOwn.call(a, key)) equalItems++;
|
|
475
|
-
continue;
|
|
476
|
-
}
|
|
477
|
-
if (aItem === null || bItem === null || typeof aItem !== "object" || typeof bItem !== "object") {
|
|
478
|
-
copy[key] = bItem;
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
const v = replaceEqualDeep(aItem, bItem, depth + 1);
|
|
482
|
-
copy[key] = v;
|
|
483
|
-
if (v === aItem) equalItems++;
|
|
484
|
-
}
|
|
485
|
-
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Shallow compare objects.
|
|
489
|
-
*/
|
|
490
|
-
function shallowEqualObjects(a, b) {
|
|
491
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) return false;
|
|
492
|
-
for (const key in a) if (a[key] !== b[key]) return false;
|
|
493
|
-
return true;
|
|
494
|
-
}
|
|
495
|
-
function isPlainArray(value) {
|
|
496
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
497
|
-
}
|
|
498
|
-
function isPlainObject(o) {
|
|
499
|
-
if (!hasObjectPrototype(o)) return false;
|
|
500
|
-
const objectPrototype = Object.getPrototypeOf(o);
|
|
501
|
-
const ctor = objectPrototype?.constructor;
|
|
502
|
-
if (ctor === void 0) return true;
|
|
503
|
-
if (typeof ctor !== "function") return false;
|
|
504
|
-
const prot = ctor.prototype;
|
|
505
|
-
if (!hasObjectPrototype(prot)) return false;
|
|
506
|
-
if (!prot.hasOwnProperty("isPrototypeOf")) return false;
|
|
507
|
-
if (objectPrototype !== Object.prototype) return false;
|
|
508
|
-
return true;
|
|
509
|
-
}
|
|
510
|
-
function hasObjectPrototype(o) {
|
|
511
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
512
|
-
}
|
|
513
|
-
function sleep(timeout) {
|
|
514
|
-
return new Promise((resolve) => {
|
|
515
|
-
timeoutManager.setTimeout(resolve, timeout);
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
function replaceData(prevData, data, options) {
|
|
519
|
-
if (typeof options.structuralSharing === "function") return options.structuralSharing(prevData, data);
|
|
520
|
-
else if (options.structuralSharing !== false) return replaceEqualDeep(prevData, data);
|
|
521
|
-
return data;
|
|
522
|
-
}
|
|
523
|
-
function addToEnd(items, item, max = 0) {
|
|
524
|
-
const newItems = [...items, item];
|
|
525
|
-
return max && newItems.length > max ? newItems.slice(1) : newItems;
|
|
526
|
-
}
|
|
527
|
-
function addToStart(items, item, max = 0) {
|
|
528
|
-
const newItems = [item, ...items];
|
|
529
|
-
return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Sentinel value that can be passed as a query's `queryFn` to conditionally disable the query (equivalent
|
|
533
|
-
* to `enabled: false`) while preserving full type inference for the query's data. Unlike `enabled: false`,
|
|
534
|
-
* a query disabled via `skipToken` cannot be triggered with `refetch`.
|
|
535
|
-
*
|
|
536
|
-
* @example
|
|
537
|
-
* ```ts
|
|
538
|
-
* new QueryObserver(queryClient, {
|
|
539
|
-
* queryKey: ['post', postId],
|
|
540
|
-
* queryFn: postId != null ? () => fetchPost(postId) : skipToken,
|
|
541
|
-
* })
|
|
542
|
-
* ```
|
|
543
|
-
*/
|
|
544
|
-
var skipToken = Symbol();
|
|
545
|
-
function ensureQueryFn(options, fetchOptions) {
|
|
546
|
-
if (!options.queryFn && fetchOptions?.initialPromise) return () => fetchOptions.initialPromise;
|
|
547
|
-
if (!options.queryFn || options.queryFn === skipToken) return () => Promise.reject(/* @__PURE__ */ new Error(`Missing queryFn: '${options.queryHash}'`));
|
|
548
|
-
return options.queryFn;
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Resolves a `throwOnError` option to a boolean.
|
|
552
|
-
* If `throwOnError` is a function, it is called with `params` (e.g. the error and, depending on the caller,
|
|
553
|
-
* additional context such as the query or mutation) and its result is returned, allowing the throwing
|
|
554
|
-
* behavior to be decided per error. Otherwise, `throwOnError` itself is coerced to a boolean (`undefined`
|
|
555
|
-
* resolves to `false`).
|
|
556
|
-
*
|
|
557
|
-
* @example
|
|
558
|
-
* ```ts
|
|
559
|
-
* const throwOnError =
|
|
560
|
-
* query.state.error && typeof options.throwOnError === 'function'
|
|
561
|
-
* ? shouldThrowError(options.throwOnError, [query.state.error, query])
|
|
562
|
-
* : options.throwOnError
|
|
563
|
-
* ```
|
|
564
|
-
*/
|
|
565
|
-
function shouldThrowError(throwOnError, params) {
|
|
566
|
-
if (typeof throwOnError === "function") return throwOnError(...params);
|
|
567
|
-
return !!throwOnError;
|
|
568
|
-
}
|
|
569
|
-
function addConsumeAwareSignal(object, getSignal, onCancelled) {
|
|
570
|
-
let consumed = false;
|
|
571
|
-
let signal;
|
|
572
|
-
Object.defineProperty(object, "signal", {
|
|
573
|
-
enumerable: true,
|
|
574
|
-
get: () => {
|
|
575
|
-
signal ??= getSignal();
|
|
576
|
-
if (consumed) return signal;
|
|
577
|
-
consumed = true;
|
|
578
|
-
if (signal.aborted) onCancelled();
|
|
579
|
-
else signal.addEventListener("abort", onCancelled, { once: true });
|
|
580
|
-
return signal;
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
return object;
|
|
584
|
-
}
|
|
585
|
-
//#endregion
|
|
586
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/environmentManager.js
|
|
587
|
-
var isServerFn = () => isServer$1;
|
|
588
|
-
/**
|
|
589
|
-
* Returns whether the current runtime should be treated as a server environment.
|
|
590
|
-
*/
|
|
591
|
-
var isServer = () => isServerFn();
|
|
592
|
-
//#endregion
|
|
593
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/subscribable.js
|
|
594
|
-
var Subscribable = class {
|
|
595
|
-
constructor() {
|
|
596
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
597
|
-
this.subscribe = this.subscribe.bind(this);
|
|
598
|
-
}
|
|
599
|
-
subscribe(listener) {
|
|
600
|
-
this.listeners.add(listener);
|
|
601
|
-
this.onSubscribe();
|
|
602
|
-
return () => {
|
|
603
|
-
this.listeners.delete(listener);
|
|
604
|
-
this.onUnsubscribe();
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
hasListeners() {
|
|
608
|
-
return this.listeners.size > 0;
|
|
609
|
-
}
|
|
610
|
-
onSubscribe() {}
|
|
611
|
-
onUnsubscribe() {}
|
|
612
|
-
};
|
|
613
|
-
//#endregion
|
|
614
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/focusManager.js
|
|
615
|
-
/**
|
|
616
|
-
* The `FocusManager` manages the focus state within TanStack Query.
|
|
617
|
-
*
|
|
618
|
-
* It can be used to change the default event listeners or to manually change the focus state.
|
|
619
|
-
*/
|
|
620
|
-
var FocusManager = class extends Subscribable {
|
|
621
|
-
#focused;
|
|
622
|
-
#cleanup;
|
|
623
|
-
#setup;
|
|
624
|
-
constructor() {
|
|
625
|
-
super();
|
|
626
|
-
this.#setup = (onFocus) => {
|
|
627
|
-
if (typeof window !== "undefined" && window.addEventListener) {
|
|
628
|
-
const listener = () => onFocus();
|
|
629
|
-
window.addEventListener("visibilitychange", listener, false);
|
|
630
|
-
return () => {
|
|
631
|
-
window.removeEventListener("visibilitychange", listener);
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
onSubscribe() {
|
|
637
|
-
if (!this.#cleanup) this.setEventListener(this.#setup);
|
|
638
|
-
}
|
|
639
|
-
onUnsubscribe() {
|
|
640
|
-
if (!this.hasListeners()) {
|
|
641
|
-
this.#cleanup?.();
|
|
642
|
-
this.#cleanup = void 0;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* `setEventListener` can be used to set a custom event listener that will
|
|
647
|
-
* be used to determine the focus state. The provided `setup` function
|
|
648
|
-
* receives a `setFocused` callback: call it with a `boolean` to manually
|
|
649
|
-
* set the focus state, or with no arguments to re-evaluate the current
|
|
650
|
-
* focus state and notify subscribers.
|
|
651
|
-
*
|
|
652
|
-
* @example
|
|
653
|
-
* ```ts
|
|
654
|
-
* import { focusManager } from '@tanstack/query-core'
|
|
655
|
-
*
|
|
656
|
-
* focusManager.setEventListener((handleFocus) => {
|
|
657
|
-
* const listener = () => handleFocus()
|
|
658
|
-
* // Listen to visibilitychange
|
|
659
|
-
* if (typeof window !== 'undefined' && window.addEventListener) {
|
|
660
|
-
* window.addEventListener('visibilitychange', listener, false)
|
|
661
|
-
* }
|
|
662
|
-
*
|
|
663
|
-
* return () => {
|
|
664
|
-
* // Be sure to unsubscribe if a new handler is set
|
|
665
|
-
* window.removeEventListener('visibilitychange', listener)
|
|
666
|
-
* }
|
|
667
|
-
* })
|
|
668
|
-
* ```
|
|
669
|
-
*/
|
|
670
|
-
setEventListener(setup) {
|
|
671
|
-
this.#setup = setup;
|
|
672
|
-
this.#cleanup?.();
|
|
673
|
-
this.#cleanup = setup((focused) => {
|
|
674
|
-
if (typeof focused === "boolean") this.setFocused(focused);
|
|
675
|
-
else this.onFocus();
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* `setFocused` can be used to manually set the focus state. Set `undefined`
|
|
680
|
-
* to fall back to the default focus check.
|
|
681
|
-
*
|
|
682
|
-
* @example
|
|
683
|
-
* ```ts
|
|
684
|
-
* import { focusManager } from '@tanstack/query-core'
|
|
685
|
-
*
|
|
686
|
-
* // Set focused
|
|
687
|
-
* focusManager.setFocused(true)
|
|
688
|
-
*
|
|
689
|
-
* // Set unfocused
|
|
690
|
-
* focusManager.setFocused(false)
|
|
691
|
-
*
|
|
692
|
-
* // Fallback to the default focus check
|
|
693
|
-
* focusManager.setFocused(undefined)
|
|
694
|
-
* ```
|
|
695
|
-
*/
|
|
696
|
-
setFocused(focused) {
|
|
697
|
-
if (this.#focused !== focused) {
|
|
698
|
-
this.#focused = focused;
|
|
699
|
-
this.onFocus();
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* `onFocus` notifies all subscribed listeners with the current focus state.
|
|
704
|
-
*/
|
|
705
|
-
onFocus() {
|
|
706
|
-
const isFocused = this.isFocused();
|
|
707
|
-
this.listeners.forEach((listener) => {
|
|
708
|
-
listener(isFocused);
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* `isFocused` can be used to get the current focus state.
|
|
713
|
-
*/
|
|
714
|
-
isFocused() {
|
|
715
|
-
if (typeof this.#focused === "boolean") return this.#focused;
|
|
716
|
-
return globalThis.document?.visibilityState !== "hidden";
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
/**
|
|
720
|
-
* Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
|
|
721
|
-
*/
|
|
722
|
-
var focusManager = new FocusManager();
|
|
723
|
-
//#endregion
|
|
724
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/notifyManager.js
|
|
725
|
-
/**
|
|
726
|
-
* Default scheduling function used by the notify manager.
|
|
727
|
-
* Schedules the callback with the system's `setTimeout(callback, 0)`.
|
|
728
|
-
*/
|
|
729
|
-
var defaultScheduler = systemSetTimeoutZero;
|
|
730
|
-
function createNotifyManager() {
|
|
731
|
-
let queue = [];
|
|
732
|
-
let transactions = 0;
|
|
733
|
-
let notifyFn = (callback) => {
|
|
734
|
-
callback();
|
|
735
|
-
};
|
|
736
|
-
let batchNotifyFn = (callback) => {
|
|
737
|
-
callback();
|
|
738
|
-
};
|
|
739
|
-
let scheduleFn = defaultScheduler;
|
|
740
|
-
const schedule = (callback) => {
|
|
741
|
-
if (transactions) queue.push(callback);
|
|
742
|
-
else scheduleFn(() => {
|
|
743
|
-
notifyFn(callback);
|
|
744
|
-
});
|
|
745
|
-
};
|
|
746
|
-
const flush = () => {
|
|
747
|
-
const originalQueue = queue;
|
|
748
|
-
queue = [];
|
|
749
|
-
if (originalQueue.length) scheduleFn(() => {
|
|
750
|
-
batchNotifyFn(() => {
|
|
751
|
-
originalQueue.forEach((callback) => {
|
|
752
|
-
notifyFn(callback);
|
|
753
|
-
});
|
|
754
|
-
});
|
|
755
|
-
});
|
|
756
|
-
};
|
|
757
|
-
return {
|
|
758
|
-
/**
|
|
759
|
-
* Batches all updates scheduled inside the passed callback.
|
|
760
|
-
* This is mainly used internally to optimize query client updating.
|
|
761
|
-
* Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
|
|
762
|
-
* The return value of `callback` is passed through.
|
|
763
|
-
*/
|
|
764
|
-
batch: (callback) => {
|
|
765
|
-
let result;
|
|
766
|
-
transactions++;
|
|
767
|
-
try {
|
|
768
|
-
result = callback();
|
|
769
|
-
} finally {
|
|
770
|
-
transactions--;
|
|
771
|
-
if (!transactions) flush();
|
|
772
|
-
}
|
|
773
|
-
return result;
|
|
774
|
-
},
|
|
775
|
-
/**
|
|
776
|
-
* All calls to the wrapped function will be batched.
|
|
777
|
-
*/
|
|
778
|
-
batchCalls: (callback) => {
|
|
779
|
-
return (...args) => {
|
|
780
|
-
schedule(() => {
|
|
781
|
-
callback(...args);
|
|
782
|
-
});
|
|
783
|
-
};
|
|
784
|
-
},
|
|
785
|
-
/**
|
|
786
|
-
* Schedules a function to be run on the next batch.
|
|
787
|
-
* By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
|
|
788
|
-
*/
|
|
789
|
-
schedule,
|
|
790
|
-
/**
|
|
791
|
-
* Use this method to set a custom notify function.
|
|
792
|
-
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
793
|
-
*/
|
|
794
|
-
setNotifyFunction: (fn) => {
|
|
795
|
-
notifyFn = fn;
|
|
796
|
-
},
|
|
797
|
-
/**
|
|
798
|
-
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
799
|
-
* Framework adapters use this to plug in their own batching primitive, so that a single query
|
|
800
|
-
* update only triggers one re-render instead of one per subscriber.
|
|
801
|
-
*
|
|
802
|
-
* @example
|
|
803
|
-
* ```ts
|
|
804
|
-
* import { notifyManager } from '@tanstack/query-core'
|
|
805
|
-
* import { batch } from 'solid-js'
|
|
806
|
-
*
|
|
807
|
-
* notifyManager.setBatchNotifyFunction(batch)
|
|
808
|
-
* ```
|
|
809
|
-
*/
|
|
810
|
-
setBatchNotifyFunction: (fn) => {
|
|
811
|
-
batchNotifyFn = fn;
|
|
812
|
-
},
|
|
813
|
-
/**
|
|
814
|
-
* Configures a custom callback that schedules when the next batch runs.
|
|
815
|
-
* The default behavior is `setTimeout(callback, 0)`.
|
|
816
|
-
*
|
|
817
|
-
* @example
|
|
818
|
-
* ```ts
|
|
819
|
-
* import { notifyManager } from '@tanstack/query-core'
|
|
820
|
-
*
|
|
821
|
-
* // Schedule batches in the next microtask
|
|
822
|
-
* notifyManager.setScheduler(queueMicrotask)
|
|
823
|
-
*
|
|
824
|
-
* // Schedule batches before the next frame is rendered
|
|
825
|
-
* notifyManager.setScheduler(requestAnimationFrame)
|
|
826
|
-
*
|
|
827
|
-
* // Schedule batches some time in the future
|
|
828
|
-
* notifyManager.setScheduler((cb) => setTimeout(cb, 10))
|
|
829
|
-
* ```
|
|
830
|
-
*/
|
|
831
|
-
setScheduler: (fn) => {
|
|
832
|
-
scheduleFn = fn;
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Handles scheduling and batching callbacks in TanStack Query.
|
|
838
|
-
*/
|
|
839
|
-
var notifyManager = createNotifyManager();
|
|
840
|
-
//#endregion
|
|
841
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/onlineManager.js
|
|
842
|
-
/**
|
|
843
|
-
* The `OnlineManager` manages the online state within TanStack Query. It can
|
|
844
|
-
* be used to change the default event listeners or to manually change the
|
|
845
|
-
* online state.
|
|
846
|
-
*
|
|
847
|
-
* By default, the `onlineManager` assumes an active network connection, and
|
|
848
|
-
* listens to the `online` and `offline` events on the `window` object to
|
|
849
|
-
* detect changes.
|
|
850
|
-
*/
|
|
851
|
-
var OnlineManager = class extends Subscribable {
|
|
852
|
-
#online = true;
|
|
853
|
-
#cleanup;
|
|
854
|
-
#setup;
|
|
855
|
-
constructor() {
|
|
856
|
-
super();
|
|
857
|
-
this.#setup = (onOnline) => {
|
|
858
|
-
if (typeof window !== "undefined" && window.addEventListener) {
|
|
859
|
-
const onlineListener = () => onOnline(true);
|
|
860
|
-
const offlineListener = () => onOnline(false);
|
|
861
|
-
window.addEventListener("online", onlineListener, false);
|
|
862
|
-
window.addEventListener("offline", offlineListener, false);
|
|
863
|
-
return () => {
|
|
864
|
-
window.removeEventListener("online", onlineListener);
|
|
865
|
-
window.removeEventListener("offline", offlineListener);
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
onSubscribe() {
|
|
871
|
-
if (!this.#cleanup) this.setEventListener(this.#setup);
|
|
872
|
-
}
|
|
873
|
-
onUnsubscribe() {
|
|
874
|
-
if (!this.hasListeners()) {
|
|
875
|
-
this.#cleanup?.();
|
|
876
|
-
this.#cleanup = void 0;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* `setEventListener` can be used to set a custom event listener that will
|
|
881
|
-
* be used to determine the online state. The provided `setup` function
|
|
882
|
-
* receives a `setOnline` callback that should be called with a `boolean`
|
|
883
|
-
* whenever the online state changes.
|
|
884
|
-
*
|
|
885
|
-
* @example
|
|
886
|
-
* ```ts
|
|
887
|
-
* import NetInfo from '@react-native-community/netinfo'
|
|
888
|
-
* import { onlineManager } from '@tanstack/query-core'
|
|
889
|
-
*
|
|
890
|
-
* onlineManager.setEventListener((setOnline) => {
|
|
891
|
-
* return NetInfo.addEventListener((state) => {
|
|
892
|
-
* setOnline(!!state.isConnected)
|
|
893
|
-
* })
|
|
894
|
-
* })
|
|
895
|
-
* ```
|
|
896
|
-
*/
|
|
897
|
-
setEventListener(setup) {
|
|
898
|
-
this.#setup = setup;
|
|
899
|
-
this.#cleanup?.();
|
|
900
|
-
this.#cleanup = setup(this.setOnline.bind(this));
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* `setOnline` can be used to manually set the online state.
|
|
904
|
-
*
|
|
905
|
-
* @example
|
|
906
|
-
* ```ts
|
|
907
|
-
* import { onlineManager } from '@tanstack/query-core'
|
|
908
|
-
*
|
|
909
|
-
* // Set to online
|
|
910
|
-
* onlineManager.setOnline(true)
|
|
911
|
-
*
|
|
912
|
-
* // Set to offline
|
|
913
|
-
* onlineManager.setOnline(false)
|
|
914
|
-
* ```
|
|
915
|
-
*/
|
|
916
|
-
setOnline(online) {
|
|
917
|
-
if (this.#online !== online) {
|
|
918
|
-
this.#online = online;
|
|
919
|
-
this.listeners.forEach((listener) => {
|
|
920
|
-
listener(online);
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* `isOnline` can be used to get the current online state.
|
|
926
|
-
*/
|
|
927
|
-
isOnline() {
|
|
928
|
-
return this.#online;
|
|
929
|
-
}
|
|
930
|
-
};
|
|
931
|
-
/**
|
|
932
|
-
* Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.
|
|
933
|
-
*/
|
|
934
|
-
var onlineManager = new OnlineManager();
|
|
935
|
-
//#endregion
|
|
936
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/retryer.js
|
|
937
|
-
function defaultRetryDelay(failureCount) {
|
|
938
|
-
return Math.min(1e3 * 2 ** failureCount, 3e4);
|
|
939
|
-
}
|
|
940
|
-
function canFetch(networkMode) {
|
|
941
|
-
return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via
|
|
945
|
-
* `query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch
|
|
946
|
-
* started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead
|
|
947
|
-
* resolve with the promise of the fetch that triggered the cancellation.
|
|
948
|
-
* @example
|
|
949
|
-
* ```ts
|
|
950
|
-
* query.cancel()
|
|
951
|
-
*
|
|
952
|
-
* try {
|
|
953
|
-
* await query.promise
|
|
954
|
-
* } catch (error) {
|
|
955
|
-
* if (error instanceof CancelledError) {
|
|
956
|
-
* // the fetch was cancelled, e.g. via `query.cancel()`
|
|
957
|
-
* }
|
|
958
|
-
* }
|
|
959
|
-
* ```
|
|
960
|
-
*/
|
|
961
|
-
var CancelledError = class extends Error {
|
|
962
|
-
constructor(options) {
|
|
963
|
-
super("CancelledError");
|
|
964
|
-
this.revert = options?.revert;
|
|
965
|
-
this.silent = options?.silent;
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
function createRetryer(config) {
|
|
969
|
-
let isRetryCancelled = false;
|
|
970
|
-
let failureCount = 0;
|
|
971
|
-
let continueFn;
|
|
972
|
-
let status = "pending";
|
|
973
|
-
let promiseResolve;
|
|
974
|
-
let promiseReject;
|
|
975
|
-
const promise = new Promise((resolve, reject) => {
|
|
976
|
-
promiseResolve = resolve;
|
|
977
|
-
promiseReject = reject;
|
|
978
|
-
});
|
|
979
|
-
promise.catch(noop);
|
|
980
|
-
const isResolved = () => status !== "pending";
|
|
981
|
-
const cancel = (cancelOptions) => {
|
|
982
|
-
if (!isResolved()) {
|
|
983
|
-
const error = new CancelledError(cancelOptions);
|
|
984
|
-
reject(error);
|
|
985
|
-
config.onCancel?.(error);
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
const cancelRetry = () => {
|
|
989
|
-
isRetryCancelled = true;
|
|
990
|
-
};
|
|
991
|
-
const continueRetry = () => {
|
|
992
|
-
isRetryCancelled = false;
|
|
993
|
-
};
|
|
994
|
-
const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
|
|
995
|
-
const canStart = () => canFetch(config.networkMode) && config.canRun();
|
|
996
|
-
const resolve = (value) => {
|
|
997
|
-
if (!isResolved()) {
|
|
998
|
-
continueFn?.();
|
|
999
|
-
status = "resolved";
|
|
1000
|
-
promiseResolve(value);
|
|
1001
|
-
}
|
|
1002
|
-
};
|
|
1003
|
-
const reject = (value) => {
|
|
1004
|
-
if (!isResolved()) {
|
|
1005
|
-
continueFn?.();
|
|
1006
|
-
status = "rejected";
|
|
1007
|
-
promiseReject(value);
|
|
1008
|
-
}
|
|
1009
|
-
};
|
|
1010
|
-
const pause = () => {
|
|
1011
|
-
return new Promise((continueResolve) => {
|
|
1012
|
-
continueFn = (value) => {
|
|
1013
|
-
if (isResolved() || canContinue()) continueResolve(value);
|
|
1014
|
-
};
|
|
1015
|
-
config.onPause?.();
|
|
1016
|
-
}).then(() => {
|
|
1017
|
-
continueFn = void 0;
|
|
1018
|
-
if (!isResolved()) config.onContinue?.();
|
|
1019
|
-
});
|
|
1020
|
-
};
|
|
1021
|
-
const run = () => {
|
|
1022
|
-
if (isResolved()) return;
|
|
1023
|
-
let promiseOrValue;
|
|
1024
|
-
const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
|
|
1025
|
-
try {
|
|
1026
|
-
promiseOrValue = initialPromise ?? config.fn();
|
|
1027
|
-
} catch (error) {
|
|
1028
|
-
promiseOrValue = Promise.reject(error);
|
|
1029
|
-
}
|
|
1030
|
-
Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
|
|
1031
|
-
if (isResolved()) return;
|
|
1032
|
-
const retry = config.retry ?? (isServer() ? 0 : 3);
|
|
1033
|
-
const retryDelay = config.retryDelay ?? defaultRetryDelay;
|
|
1034
|
-
const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
|
|
1035
|
-
const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
|
|
1036
|
-
if (isRetryCancelled || !shouldRetry) {
|
|
1037
|
-
reject(error);
|
|
1038
|
-
return;
|
|
1039
|
-
}
|
|
1040
|
-
failureCount++;
|
|
1041
|
-
config.onFail?.(failureCount, error);
|
|
1042
|
-
sleep(delay).then(() => {
|
|
1043
|
-
return canContinue() ? void 0 : pause();
|
|
1044
|
-
}).then(() => {
|
|
1045
|
-
if (isRetryCancelled) reject(error);
|
|
1046
|
-
else run();
|
|
1047
|
-
});
|
|
1048
|
-
});
|
|
1049
|
-
};
|
|
1050
|
-
return {
|
|
1051
|
-
promise,
|
|
1052
|
-
status: () => status,
|
|
1053
|
-
cancel,
|
|
1054
|
-
continue: () => {
|
|
1055
|
-
continueFn?.();
|
|
1056
|
-
return promise;
|
|
1057
|
-
},
|
|
1058
|
-
cancelRetry,
|
|
1059
|
-
continueRetry,
|
|
1060
|
-
canStart,
|
|
1061
|
-
start: () => {
|
|
1062
|
-
if (canStart()) run();
|
|
1063
|
-
else pause().then(run);
|
|
1064
|
-
return promise;
|
|
1065
|
-
}
|
|
1066
|
-
};
|
|
1067
|
-
}
|
|
1068
|
-
//#endregion
|
|
1069
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/removable.js
|
|
1070
|
-
var Removable = class {
|
|
1071
|
-
#gcTimeout;
|
|
1072
|
-
destroy() {
|
|
1073
|
-
this.clearGcTimeout();
|
|
1074
|
-
}
|
|
1075
|
-
scheduleGc() {
|
|
1076
|
-
this.clearGcTimeout();
|
|
1077
|
-
if (isValidTimeout(this.gcTime)) this.#gcTimeout = timeoutManager.setTimeout(() => {
|
|
1078
|
-
this.optionalRemove();
|
|
1079
|
-
}, this.gcTime);
|
|
1080
|
-
}
|
|
1081
|
-
updateGcTime(newGcTime) {
|
|
1082
|
-
this.gcTime = Math.max(this.gcTime || 0, newGcTime ?? (isServer() ? Infinity : 3e5));
|
|
1083
|
-
}
|
|
1084
|
-
clearGcTimeout() {
|
|
1085
|
-
if (this.#gcTimeout !== void 0) {
|
|
1086
|
-
timeoutManager.clearTimeout(this.#gcTimeout);
|
|
1087
|
-
this.#gcTimeout = void 0;
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
};
|
|
1091
|
-
//#endregion
|
|
1092
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
|
|
1093
|
-
function infiniteQueryBehavior(pages) {
|
|
1094
|
-
return { onFetch: (context, query) => {
|
|
1095
|
-
const options = context.options;
|
|
1096
|
-
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
|
|
1097
|
-
const oldPages = context.state.data?.pages || [];
|
|
1098
|
-
const oldPageParams = context.state.data?.pageParams || [];
|
|
1099
|
-
let result = {
|
|
1100
|
-
pages: [],
|
|
1101
|
-
pageParams: []
|
|
1102
|
-
};
|
|
1103
|
-
let currentPage = 0;
|
|
1104
|
-
const fetchFn = async () => {
|
|
1105
|
-
let cancelled = false;
|
|
1106
|
-
const addSignalProperty = (object) => {
|
|
1107
|
-
addConsumeAwareSignal(object, () => context.signal, () => cancelled = true);
|
|
1108
|
-
};
|
|
1109
|
-
const queryFn = ensureQueryFn(context.options, context.fetchOptions);
|
|
1110
|
-
const fetchPage = async (data, param, previous) => {
|
|
1111
|
-
if (cancelled) return Promise.reject(context.signal.reason);
|
|
1112
|
-
if (param == null && data.pages.length) return Promise.resolve(data);
|
|
1113
|
-
const createQueryFnContext = () => {
|
|
1114
|
-
const queryFnContext = {
|
|
1115
|
-
client: context.client,
|
|
1116
|
-
queryKey: context.queryKey,
|
|
1117
|
-
pageParam: param,
|
|
1118
|
-
direction: previous ? "backward" : "forward",
|
|
1119
|
-
meta: context.options.meta
|
|
1120
|
-
};
|
|
1121
|
-
addSignalProperty(queryFnContext);
|
|
1122
|
-
return queryFnContext;
|
|
1123
|
-
};
|
|
1124
|
-
const queryFnContext = createQueryFnContext();
|
|
1125
|
-
const page = await queryFn(queryFnContext);
|
|
1126
|
-
const { maxPages } = context.options;
|
|
1127
|
-
const addTo = previous ? addToStart : addToEnd;
|
|
1128
|
-
return {
|
|
1129
|
-
pages: addTo(data.pages, page, maxPages),
|
|
1130
|
-
pageParams: addTo(data.pageParams, param, maxPages)
|
|
1131
|
-
};
|
|
1132
|
-
};
|
|
1133
|
-
if (direction && oldPages.length) {
|
|
1134
|
-
const previous = direction === "backward";
|
|
1135
|
-
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
1136
|
-
const oldData = {
|
|
1137
|
-
pages: oldPages,
|
|
1138
|
-
pageParams: oldPageParams
|
|
1139
|
-
};
|
|
1140
|
-
result = await fetchPage(oldData, pageParamFn(options, oldData), previous);
|
|
1141
|
-
} else {
|
|
1142
|
-
const remainingPages = pages ?? oldPages.length;
|
|
1143
|
-
do {
|
|
1144
|
-
const param = currentPage === 0 ? oldPageParams[0] ?? options.initialPageParam : getNextPageParam(options, result);
|
|
1145
|
-
if (currentPage > 0 && param == null) break;
|
|
1146
|
-
result = await fetchPage(result, param);
|
|
1147
|
-
currentPage++;
|
|
1148
|
-
} while (currentPage < remainingPages);
|
|
1149
|
-
}
|
|
1150
|
-
return result;
|
|
1151
|
-
};
|
|
1152
|
-
if (context.options.persister) context.fetchFn = () => {
|
|
1153
|
-
return context.options.persister?.(fetchFn, {
|
|
1154
|
-
client: context.client,
|
|
1155
|
-
queryKey: context.queryKey,
|
|
1156
|
-
meta: context.options.meta,
|
|
1157
|
-
signal: context.signal
|
|
1158
|
-
}, query);
|
|
1159
|
-
};
|
|
1160
|
-
else context.fetchFn = fetchFn;
|
|
1161
|
-
} };
|
|
1162
|
-
}
|
|
1163
|
-
function getNextPageParam(options, { pages, pageParams }) {
|
|
1164
|
-
const lastIndex = pages.length - 1;
|
|
1165
|
-
return pages.length > 0 ? options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams) : void 0;
|
|
1166
|
-
}
|
|
1167
|
-
function getPreviousPageParam(options, { pages, pageParams }) {
|
|
1168
|
-
return pages.length > 0 ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0;
|
|
1169
|
-
}
|
|
1170
|
-
//#endregion
|
|
1171
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/query.js
|
|
1172
|
-
/**
|
|
1173
|
-
* Represents a single cached query. A `Query` holds the query's key, options,
|
|
1174
|
-
* state (data/error/status), and the observers currently subscribed to it.
|
|
1175
|
-
*
|
|
1176
|
-
* Instances are created and managed internally by `QueryCache`; application
|
|
1177
|
-
* code typically interacts with queries indirectly through `QueryClient` or
|
|
1178
|
-
* a framework hook like `useQuery`. Direct access to a `Query` instance is
|
|
1179
|
-
* possible via `queryCache.find()`/`findAll()` for inspecting cache state.
|
|
1180
|
-
*
|
|
1181
|
-
* @example
|
|
1182
|
-
* ```ts
|
|
1183
|
-
* const queryCache = queryClient.getQueryCache()
|
|
1184
|
-
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
1185
|
-
*
|
|
1186
|
-
* if (query) {
|
|
1187
|
-
* console.log(query.state.dataUpdatedAt)
|
|
1188
|
-
* }
|
|
1189
|
-
* ```
|
|
1190
|
-
*/
|
|
1191
|
-
var Query = class extends Removable {
|
|
1192
|
-
#queryType;
|
|
1193
|
-
#initialState;
|
|
1194
|
-
#revertState;
|
|
1195
|
-
#cache;
|
|
1196
|
-
#client;
|
|
1197
|
-
#retryer;
|
|
1198
|
-
#defaultOptions;
|
|
1199
|
-
#abortSignalConsumed;
|
|
1200
|
-
constructor(config) {
|
|
1201
|
-
super();
|
|
1202
|
-
this.#abortSignalConsumed = false;
|
|
1203
|
-
this.#defaultOptions = config.defaultOptions;
|
|
1204
|
-
this.setOptions(config.options);
|
|
1205
|
-
this.observers = [];
|
|
1206
|
-
this.#client = config.client;
|
|
1207
|
-
this.#cache = this.#client.getQueryCache();
|
|
1208
|
-
this.queryKey = config.queryKey;
|
|
1209
|
-
this.queryHash = config.queryHash;
|
|
1210
|
-
this.#initialState = getDefaultState$1(this.options);
|
|
1211
|
-
this.state = config.state ?? this.#initialState;
|
|
1212
|
-
this.scheduleGc();
|
|
1213
|
-
}
|
|
1214
|
-
/**
|
|
1215
|
-
* The `meta` object passed in the query's options, if any.
|
|
1216
|
-
*/
|
|
1217
|
-
get meta() {
|
|
1218
|
-
return this.options.meta;
|
|
1219
|
-
}
|
|
1220
|
-
/** @internal */
|
|
1221
|
-
get queryType() {
|
|
1222
|
-
return this.#queryType;
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* The promise for the currently in-flight fetch, if the query is fetching.
|
|
1226
|
-
* `undefined` when the query is not fetching.
|
|
1227
|
-
*/
|
|
1228
|
-
get promise() {
|
|
1229
|
-
return this.#retryer?.promise;
|
|
1230
|
-
}
|
|
1231
|
-
/** @internal */
|
|
1232
|
-
setOptions(options) {
|
|
1233
|
-
this.options = {
|
|
1234
|
-
...this.#defaultOptions,
|
|
1235
|
-
...options
|
|
1236
|
-
};
|
|
1237
|
-
if (options?._type) this.#queryType = options._type;
|
|
1238
|
-
this.updateGcTime(this.options.gcTime);
|
|
1239
|
-
if (this.state && this.state.data === void 0) {
|
|
1240
|
-
const defaultState = getDefaultState$1(this.options);
|
|
1241
|
-
if (defaultState.data !== void 0) {
|
|
1242
|
-
this.setState(successState(defaultState.data, defaultState.dataUpdatedAt));
|
|
1243
|
-
this.#initialState = defaultState;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
optionalRemove() {
|
|
1248
|
-
if (!this.observers.length && this.state.fetchStatus === "idle") this.#cache.remove(this);
|
|
1249
|
-
}
|
|
1250
|
-
/** @internal */
|
|
1251
|
-
setData(newData, options) {
|
|
1252
|
-
const data = replaceData(this.state.data, newData, this.options);
|
|
1253
|
-
this.#dispatch({
|
|
1254
|
-
data,
|
|
1255
|
-
type: "success",
|
|
1256
|
-
dataUpdatedAt: options?.updatedAt,
|
|
1257
|
-
manual: options?.manual
|
|
1258
|
-
});
|
|
1259
|
-
return data;
|
|
1260
|
-
}
|
|
1261
|
-
/**
|
|
1262
|
-
* Merges the given partial state directly into this query's state, notifying observers. Used
|
|
1263
|
-
* by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a
|
|
1264
|
-
* user manually trigger a loading/error state or edit the cached data.
|
|
1265
|
-
*/
|
|
1266
|
-
setState(state) {
|
|
1267
|
-
this.#dispatch({
|
|
1268
|
-
type: "setState",
|
|
1269
|
-
state
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
/**
|
|
1273
|
-
* Cancels the query's currently in-flight fetch, if any.
|
|
1274
|
-
* - Returns a promise that resolves once the cancellation has settled.
|
|
1275
|
-
* - If no fetch is in progress, resolves immediately.
|
|
1276
|
-
*
|
|
1277
|
-
* @example
|
|
1278
|
-
* ```ts
|
|
1279
|
-
* await query.cancel()
|
|
1280
|
-
* ```
|
|
1281
|
-
*/
|
|
1282
|
-
cancel(options) {
|
|
1283
|
-
const promise = this.#retryer?.promise;
|
|
1284
|
-
this.#retryer?.cancel(options);
|
|
1285
|
-
return promise ? promise.then(noop).catch(noop) : Promise.resolve();
|
|
1286
|
-
}
|
|
1287
|
-
/**
|
|
1288
|
-
* Clears the query's garbage collection timeout and silently cancels any
|
|
1289
|
-
* in-flight fetch. Called by `QueryCache` when the query is removed from
|
|
1290
|
-
* the cache.
|
|
1291
|
-
*
|
|
1292
|
-
* @see {@link Query#cancel}
|
|
1293
|
-
*/
|
|
1294
|
-
destroy() {
|
|
1295
|
-
super.destroy();
|
|
1296
|
-
this.cancel({ silent: true });
|
|
1297
|
-
}
|
|
1298
|
-
/** @internal */
|
|
1299
|
-
get resetState() {
|
|
1300
|
-
return this.#initialState;
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Resets the query back to its initial state (the state it had when it was
|
|
1304
|
-
* first created, e.g. any `initialData`), destroying it first to cancel any
|
|
1305
|
-
* in-flight fetch.
|
|
1306
|
-
*/
|
|
1307
|
-
reset() {
|
|
1308
|
-
this.destroy();
|
|
1309
|
-
this.setState(this.resetState);
|
|
1310
|
-
}
|
|
1311
|
-
/**
|
|
1312
|
-
* Returns `true` if the query has at least one observer for which `enabled`
|
|
1313
|
-
* does not resolve to `false`.
|
|
1314
|
-
*/
|
|
1315
|
-
isActive() {
|
|
1316
|
-
return this.observers.some((observer) => resolveQueryValue(observer.options.enabled, this) !== false);
|
|
1317
|
-
}
|
|
1318
|
-
/**
|
|
1319
|
-
* Returns `true` if the query is disabled, meaning it will not fetch
|
|
1320
|
-
* automatically.
|
|
1321
|
-
* - If the query has observers, it is disabled when none of them are active
|
|
1322
|
-
* (see `isActive`).
|
|
1323
|
-
* - If the query has no observers, it is disabled when its `queryFn` is
|
|
1324
|
-
* `skipToken` or it has never been fetched.
|
|
1325
|
-
*/
|
|
1326
|
-
isDisabled() {
|
|
1327
|
-
if (this.getObserversCount() > 0) return !this.isActive();
|
|
1328
|
-
return this.options.queryFn === skipToken || !this.isFetched();
|
|
1329
|
-
}
|
|
1330
|
-
/**
|
|
1331
|
-
* Returns `true` if the query has been fetched, i.e. it has resolved with
|
|
1332
|
-
* either data or an error at least once.
|
|
1333
|
-
*/
|
|
1334
|
-
isFetched() {
|
|
1335
|
-
return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* Returns `true` if the query has at least one observer configured with
|
|
1339
|
-
* `staleTime: 'static'`, meaning it is treated as never stale.
|
|
1340
|
-
*/
|
|
1341
|
-
isStatic() {
|
|
1342
|
-
if (this.getObserversCount() > 0) return this.observers.some((observer) => resolveQueryValue(observer.options.staleTime, this) === "static");
|
|
1343
|
-
return false;
|
|
1344
|
-
}
|
|
1345
|
-
/**
|
|
1346
|
-
* Returns `true` if the query is stale.
|
|
1347
|
-
* - If the query has observers, defers to whether any observer's current
|
|
1348
|
-
* result reports `isStale` (which accounts for each observer's own
|
|
1349
|
-
* `staleTime` and `enabled` state).
|
|
1350
|
-
* - If the query has no observers, it is considered stale when it has no
|
|
1351
|
-
* data or has been invalidated.
|
|
1352
|
-
*
|
|
1353
|
-
* @see {@link Query#isStaleByTime}
|
|
1354
|
-
* @example
|
|
1355
|
-
* ```ts
|
|
1356
|
-
* if (query.isStale()) {
|
|
1357
|
-
* // refetch or otherwise treat the cached data as outdated
|
|
1358
|
-
* }
|
|
1359
|
-
* ```
|
|
1360
|
-
*/
|
|
1361
|
-
isStale() {
|
|
1362
|
-
if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale);
|
|
1363
|
-
return this.state.data === void 0 || this.state.isInvalidated;
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* Returns `true` if the query's data is stale relative to the given
|
|
1367
|
-
* `staleTime` (defaults to `0`).
|
|
1368
|
-
* - A query with no data is always stale.
|
|
1369
|
-
* - `staleTime: 'static'` is never stale.
|
|
1370
|
-
* - An invalidated query is always stale.
|
|
1371
|
-
* - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.
|
|
1372
|
-
*
|
|
1373
|
-
* @see {@link Query#isStale}
|
|
1374
|
-
* @example
|
|
1375
|
-
* ```ts
|
|
1376
|
-
* const isStale = query.isStaleByTime(1000 * 60)
|
|
1377
|
-
* ```
|
|
1378
|
-
*/
|
|
1379
|
-
isStaleByTime(staleTime = 0) {
|
|
1380
|
-
if (this.state.data === void 0) return true;
|
|
1381
|
-
if (staleTime === "static") return false;
|
|
1382
|
-
if (this.state.isInvalidated) return true;
|
|
1383
|
-
return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
|
|
1384
|
-
}
|
|
1385
|
-
/** @internal */
|
|
1386
|
-
onFocus() {
|
|
1387
|
-
this.observers.find((x) => x.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: false });
|
|
1388
|
-
this.#retryer?.continue();
|
|
1389
|
-
}
|
|
1390
|
-
/** @internal */
|
|
1391
|
-
onOnline() {
|
|
1392
|
-
this.observers.find((x) => x.shouldFetchOnReconnect())?.refetch({ cancelRefetch: false });
|
|
1393
|
-
this.#retryer?.continue();
|
|
1394
|
-
}
|
|
1395
|
-
/** @internal */
|
|
1396
|
-
addObserver(observer) {
|
|
1397
|
-
if (!this.observers.includes(observer)) {
|
|
1398
|
-
this.observers.push(observer);
|
|
1399
|
-
this.clearGcTimeout();
|
|
1400
|
-
this.#cache.notify({
|
|
1401
|
-
type: "observerAdded",
|
|
1402
|
-
query: this,
|
|
1403
|
-
observer
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
/** @internal */
|
|
1408
|
-
removeObserver(observer) {
|
|
1409
|
-
const index = this.observers.indexOf(observer);
|
|
1410
|
-
if (index !== -1) {
|
|
1411
|
-
this.observers.splice(index, 1);
|
|
1412
|
-
if (!this.observers.length) {
|
|
1413
|
-
if (this.#retryer) if (this.#abortSignalConsumed || this.state.fetchStatus === "paused" && this.state.status === "pending") this.#retryer.cancel({ revert: true });
|
|
1414
|
-
else this.#retryer.cancelRetry();
|
|
1415
|
-
this.scheduleGc();
|
|
1416
|
-
}
|
|
1417
|
-
this.#cache.notify({
|
|
1418
|
-
type: "observerRemoved",
|
|
1419
|
-
query: this,
|
|
1420
|
-
observer
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
/**
|
|
1425
|
-
* Returns the number of observers currently subscribed to this query.
|
|
1426
|
-
*
|
|
1427
|
-
* @example
|
|
1428
|
-
* ```ts
|
|
1429
|
-
* if (query.getObserversCount() === 0) {
|
|
1430
|
-
* // no component is currently watching this query
|
|
1431
|
-
* }
|
|
1432
|
-
* ```
|
|
1433
|
-
*/
|
|
1434
|
-
getObserversCount() {
|
|
1435
|
-
return this.observers.length;
|
|
1436
|
-
}
|
|
1437
|
-
/**
|
|
1438
|
-
* Marks the query as invalidated, unless it is already invalidated. This
|
|
1439
|
-
* updates `state.isInvalidated` and notifies observers, but does not by
|
|
1440
|
-
* itself trigger a refetch.
|
|
1441
|
-
*
|
|
1442
|
-
* @example
|
|
1443
|
-
* ```ts
|
|
1444
|
-
* query.invalidate()
|
|
1445
|
-
* ```
|
|
1446
|
-
*/
|
|
1447
|
-
invalidate() {
|
|
1448
|
-
if (!this.state.isInvalidated) this.#dispatch({ type: "invalidate" });
|
|
1449
|
-
}
|
|
1450
|
-
/**
|
|
1451
|
-
* Fetches the query, i.e. runs its `queryFn` (through any configured
|
|
1452
|
-
* retryer/behavior) and updates the query's state with the result.
|
|
1453
|
-
* - If a fetch is already in flight, returns its promise instead of
|
|
1454
|
-
* starting a new one, unless `fetchOptions.cancelRefetch` is set and the
|
|
1455
|
-
* query already has data, in which case the current fetch is silently
|
|
1456
|
-
* cancelled first.
|
|
1457
|
-
* - If `options` is passed, it replaces the query's current options
|
|
1458
|
-
* before fetching.
|
|
1459
|
-
*/
|
|
1460
|
-
async fetch(options, fetchOptions) {
|
|
1461
|
-
if (this.state.fetchStatus !== "idle" && this.#retryer?.status() !== "rejected") {
|
|
1462
|
-
if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) this.cancel({ silent: true });
|
|
1463
|
-
else if (this.#retryer) {
|
|
1464
|
-
this.#retryer.continueRetry();
|
|
1465
|
-
return this.#retryer.promise;
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
if (options) this.setOptions(options);
|
|
1469
|
-
if (!this.options.queryFn) {
|
|
1470
|
-
const observer = this.observers.find((x) => x.options.queryFn);
|
|
1471
|
-
if (observer) this.setOptions(observer.options);
|
|
1472
|
-
}
|
|
1473
|
-
const abortController = new AbortController();
|
|
1474
|
-
const addSignalProperty = (object) => {
|
|
1475
|
-
Object.defineProperty(object, "signal", {
|
|
1476
|
-
enumerable: true,
|
|
1477
|
-
get: () => {
|
|
1478
|
-
this.#abortSignalConsumed = true;
|
|
1479
|
-
return abortController.signal;
|
|
1480
|
-
}
|
|
1481
|
-
});
|
|
1482
|
-
};
|
|
1483
|
-
const fetchFn = () => {
|
|
1484
|
-
const queryFn = ensureQueryFn(this.options, fetchOptions);
|
|
1485
|
-
const createQueryFnContext = () => {
|
|
1486
|
-
const queryFnContext = {
|
|
1487
|
-
client: this.#client,
|
|
1488
|
-
queryKey: this.queryKey,
|
|
1489
|
-
meta: this.meta
|
|
1490
|
-
};
|
|
1491
|
-
addSignalProperty(queryFnContext);
|
|
1492
|
-
return queryFnContext;
|
|
1493
|
-
};
|
|
1494
|
-
const queryFnContext = createQueryFnContext();
|
|
1495
|
-
this.#abortSignalConsumed = false;
|
|
1496
|
-
if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this);
|
|
1497
|
-
return queryFn(queryFnContext);
|
|
1498
|
-
};
|
|
1499
|
-
const createFetchContext = () => {
|
|
1500
|
-
const context = {
|
|
1501
|
-
fetchOptions,
|
|
1502
|
-
options: this.options,
|
|
1503
|
-
queryKey: this.queryKey,
|
|
1504
|
-
client: this.#client,
|
|
1505
|
-
state: this.state,
|
|
1506
|
-
fetchFn
|
|
1507
|
-
};
|
|
1508
|
-
addSignalProperty(context);
|
|
1509
|
-
return context;
|
|
1510
|
-
};
|
|
1511
|
-
const context = createFetchContext();
|
|
1512
|
-
(this.#queryType === "infinite" ? infiniteQueryBehavior(this.options.pages) : this.options.behavior)?.onFetch(context, this);
|
|
1513
|
-
this.#revertState = this.state;
|
|
1514
|
-
if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) this.#dispatch({
|
|
1515
|
-
type: "fetch",
|
|
1516
|
-
meta: context.fetchOptions?.meta
|
|
1517
|
-
});
|
|
1518
|
-
const retryer = this.#retryer = createRetryer({
|
|
1519
|
-
initialPromise: fetchOptions?.initialPromise,
|
|
1520
|
-
fn: context.fetchFn,
|
|
1521
|
-
onCancel: (error) => {
|
|
1522
|
-
if (error instanceof CancelledError && error.revert) this.setState({
|
|
1523
|
-
...this.#revertState,
|
|
1524
|
-
fetchStatus: "idle"
|
|
1525
|
-
});
|
|
1526
|
-
abortController.abort();
|
|
1527
|
-
},
|
|
1528
|
-
onFail: (failureCount, error) => {
|
|
1529
|
-
this.#dispatch({
|
|
1530
|
-
type: "failed",
|
|
1531
|
-
failureCount,
|
|
1532
|
-
error
|
|
1533
|
-
});
|
|
1534
|
-
},
|
|
1535
|
-
onPause: () => {
|
|
1536
|
-
this.#dispatch({ type: "pause" });
|
|
1537
|
-
},
|
|
1538
|
-
onContinue: () => {
|
|
1539
|
-
this.#dispatch({ type: "continue" });
|
|
1540
|
-
},
|
|
1541
|
-
retry: context.options.retry,
|
|
1542
|
-
retryDelay: context.options.retryDelay,
|
|
1543
|
-
networkMode: context.options.networkMode,
|
|
1544
|
-
canRun: () => true
|
|
1545
|
-
});
|
|
1546
|
-
try {
|
|
1547
|
-
const data = await retryer.start();
|
|
1548
|
-
if (data === void 0) throw new Error(`${this.queryHash} data is undefined`);
|
|
1549
|
-
this.setData(data);
|
|
1550
|
-
this.#cache.config.onSuccess?.(data, this);
|
|
1551
|
-
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
1552
|
-
return data;
|
|
1553
|
-
} catch (error) {
|
|
1554
|
-
if (error instanceof CancelledError) {
|
|
1555
|
-
if (error.silent) return this.#retryer.promise;
|
|
1556
|
-
else if (error.revert) {
|
|
1557
|
-
if (this.state.data === void 0) throw error;
|
|
1558
|
-
return this.state.data;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
this.#dispatch({
|
|
1562
|
-
type: "error",
|
|
1563
|
-
error
|
|
1564
|
-
});
|
|
1565
|
-
this.#cache.config.onError?.(error, this);
|
|
1566
|
-
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
1567
|
-
throw error;
|
|
1568
|
-
} finally {
|
|
1569
|
-
if (this.#retryer === retryer) this.#retryer = void 0;
|
|
1570
|
-
this.scheduleGc();
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
#dispatch(action) {
|
|
1574
|
-
const reducer = (state) => {
|
|
1575
|
-
switch (action.type) {
|
|
1576
|
-
case "failed": return {
|
|
1577
|
-
...state,
|
|
1578
|
-
fetchFailureCount: action.failureCount,
|
|
1579
|
-
fetchFailureReason: action.error
|
|
1580
|
-
};
|
|
1581
|
-
case "pause": return {
|
|
1582
|
-
...state,
|
|
1583
|
-
fetchStatus: "paused"
|
|
1584
|
-
};
|
|
1585
|
-
case "continue": return {
|
|
1586
|
-
...state,
|
|
1587
|
-
fetchStatus: "fetching"
|
|
1588
|
-
};
|
|
1589
|
-
case "fetch": return {
|
|
1590
|
-
...state,
|
|
1591
|
-
...fetchState(state.data, this.options),
|
|
1592
|
-
fetchMeta: action.meta ?? null
|
|
1593
|
-
};
|
|
1594
|
-
case "success":
|
|
1595
|
-
const newState = {
|
|
1596
|
-
...state,
|
|
1597
|
-
...successState(action.data, action.dataUpdatedAt),
|
|
1598
|
-
dataUpdateCount: state.dataUpdateCount + 1,
|
|
1599
|
-
...!action.manual && {
|
|
1600
|
-
fetchStatus: "idle",
|
|
1601
|
-
fetchFailureCount: 0,
|
|
1602
|
-
fetchFailureReason: null
|
|
1603
|
-
}
|
|
1604
|
-
};
|
|
1605
|
-
this.#revertState = action.manual ? newState : void 0;
|
|
1606
|
-
return newState;
|
|
1607
|
-
case "error":
|
|
1608
|
-
const error = action.error;
|
|
1609
|
-
return {
|
|
1610
|
-
...state,
|
|
1611
|
-
error,
|
|
1612
|
-
errorUpdateCount: state.errorUpdateCount + 1,
|
|
1613
|
-
errorUpdatedAt: Date.now(),
|
|
1614
|
-
fetchFailureCount: state.fetchFailureCount + 1,
|
|
1615
|
-
fetchFailureReason: error,
|
|
1616
|
-
fetchStatus: "idle",
|
|
1617
|
-
status: "error",
|
|
1618
|
-
isInvalidated: true
|
|
1619
|
-
};
|
|
1620
|
-
case "invalidate": return {
|
|
1621
|
-
...state,
|
|
1622
|
-
isInvalidated: true
|
|
1623
|
-
};
|
|
1624
|
-
case "setState": return {
|
|
1625
|
-
...state,
|
|
1626
|
-
...action.state
|
|
1627
|
-
};
|
|
1628
|
-
}
|
|
1629
|
-
};
|
|
1630
|
-
this.state = reducer(this.state);
|
|
1631
|
-
notifyManager.batch(() => {
|
|
1632
|
-
this.observers.slice().forEach((observer) => {
|
|
1633
|
-
observer.onQueryUpdate();
|
|
1634
|
-
});
|
|
1635
|
-
this.#cache.notify({
|
|
1636
|
-
query: this,
|
|
1637
|
-
type: "updated",
|
|
1638
|
-
action
|
|
1639
|
-
});
|
|
1640
|
-
});
|
|
1641
|
-
}
|
|
1642
|
-
};
|
|
1643
|
-
function fetchState(data, options) {
|
|
1644
|
-
return {
|
|
1645
|
-
fetchFailureCount: 0,
|
|
1646
|
-
fetchFailureReason: null,
|
|
1647
|
-
fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
|
|
1648
|
-
...data === void 0 && {
|
|
1649
|
-
error: null,
|
|
1650
|
-
status: "pending"
|
|
1651
|
-
}
|
|
1652
|
-
};
|
|
1653
|
-
}
|
|
1654
|
-
function successState(data, dataUpdatedAt) {
|
|
1655
|
-
return {
|
|
1656
|
-
data,
|
|
1657
|
-
dataUpdatedAt: dataUpdatedAt ?? Date.now(),
|
|
1658
|
-
error: null,
|
|
1659
|
-
isInvalidated: false,
|
|
1660
|
-
status: "success"
|
|
1661
|
-
};
|
|
1662
|
-
}
|
|
1663
|
-
function getDefaultState$1(options) {
|
|
1664
|
-
const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
|
|
1665
|
-
const hasData = data !== void 0;
|
|
1666
|
-
const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
|
|
1667
|
-
return {
|
|
1668
|
-
data,
|
|
1669
|
-
dataUpdateCount: 0,
|
|
1670
|
-
dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
|
|
1671
|
-
error: null,
|
|
1672
|
-
errorUpdateCount: 0,
|
|
1673
|
-
errorUpdatedAt: 0,
|
|
1674
|
-
fetchFailureCount: 0,
|
|
1675
|
-
fetchFailureReason: null,
|
|
1676
|
-
fetchMeta: null,
|
|
1677
|
-
isInvalidated: false,
|
|
1678
|
-
status: hasData ? "success" : "pending",
|
|
1679
|
-
fetchStatus: "idle"
|
|
1680
|
-
};
|
|
1681
|
-
}
|
|
1682
|
-
//#endregion
|
|
1683
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/mutation.js
|
|
1684
|
-
/**
|
|
1685
|
-
* Represents a single mutation attempt. A `Mutation` holds the mutation's
|
|
1686
|
-
* options, state (data/error/status), and the `MutationObserver`s currently
|
|
1687
|
-
* subscribed to it.
|
|
1688
|
-
*
|
|
1689
|
-
* Instances are created and managed internally by `MutationCache`; application
|
|
1690
|
-
* code typically interacts with mutations indirectly through `QueryClient` or
|
|
1691
|
-
* a framework hook like `useMutation`. Direct access to a `Mutation` instance
|
|
1692
|
-
* is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.
|
|
1693
|
-
*
|
|
1694
|
-
* @example
|
|
1695
|
-
* ```ts
|
|
1696
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
1697
|
-
*
|
|
1698
|
-
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
1699
|
-
* ```
|
|
1700
|
-
*/
|
|
1701
|
-
var Mutation = class extends Removable {
|
|
1702
|
-
#client;
|
|
1703
|
-
#observers;
|
|
1704
|
-
#mutationCache;
|
|
1705
|
-
#retryer;
|
|
1706
|
-
constructor(config) {
|
|
1707
|
-
super();
|
|
1708
|
-
this.#client = config.client;
|
|
1709
|
-
this.mutationId = config.mutationId;
|
|
1710
|
-
this.#mutationCache = config.mutationCache;
|
|
1711
|
-
this.#observers = [];
|
|
1712
|
-
this.state = config.state || getDefaultState();
|
|
1713
|
-
this.setOptions(config.options);
|
|
1714
|
-
this.scheduleGc();
|
|
1715
|
-
}
|
|
1716
|
-
/** @internal */
|
|
1717
|
-
setOptions(options) {
|
|
1718
|
-
this.options = options;
|
|
1719
|
-
this.updateGcTime(this.options.gcTime);
|
|
1720
|
-
}
|
|
1721
|
-
/**
|
|
1722
|
-
* The `meta` object passed in the mutation's options, if any.
|
|
1723
|
-
*/
|
|
1724
|
-
get meta() {
|
|
1725
|
-
return this.options.meta;
|
|
1726
|
-
}
|
|
1727
|
-
/** @internal */
|
|
1728
|
-
addObserver(observer) {
|
|
1729
|
-
if (!this.#observers.includes(observer)) {
|
|
1730
|
-
this.#observers.push(observer);
|
|
1731
|
-
this.clearGcTimeout();
|
|
1732
|
-
this.#mutationCache.notify({
|
|
1733
|
-
type: "observerAdded",
|
|
1734
|
-
mutation: this,
|
|
1735
|
-
observer
|
|
1736
|
-
});
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
/** @internal */
|
|
1740
|
-
removeObserver(observer) {
|
|
1741
|
-
this.#observers = this.#observers.filter((x) => x !== observer);
|
|
1742
|
-
this.scheduleGc();
|
|
1743
|
-
this.#mutationCache.notify({
|
|
1744
|
-
type: "observerRemoved",
|
|
1745
|
-
mutation: this,
|
|
1746
|
-
observer
|
|
1747
|
-
});
|
|
1748
|
-
}
|
|
1749
|
-
optionalRemove() {
|
|
1750
|
-
if (!this.#observers.length) if (this.state.status === "pending") this.scheduleGc();
|
|
1751
|
-
else this.#mutationCache.remove(this);
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Resumes a mutation that is currently paused or was restored from a
|
|
1755
|
-
* dehydrated, still-`pending` state.
|
|
1756
|
-
*
|
|
1757
|
-
* - If this mutation has an active retryer (it paused mid-attempt, e.g. due
|
|
1758
|
-
* to the network mode or scope-based queuing), its retryer is resumed.
|
|
1759
|
-
* - Otherwise, if the mutation's status is still `pending` (e.g. it was
|
|
1760
|
-
* dehydrated while an attempt was in flight and never got a retryer in
|
|
1761
|
-
* this instance), `execute` is called again with the last known variables.
|
|
1762
|
-
* - Otherwise the mutation has already settled and this resolves immediately
|
|
1763
|
-
* without running anything again.
|
|
1764
|
-
*
|
|
1765
|
-
* @example
|
|
1766
|
-
* ```ts
|
|
1767
|
-
* // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()
|
|
1768
|
-
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
1769
|
-
* await mutation?.continue()
|
|
1770
|
-
* ```
|
|
1771
|
-
*
|
|
1772
|
-
* @see {@link Mutation#execute}
|
|
1773
|
-
*/
|
|
1774
|
-
continue() {
|
|
1775
|
-
return this.#retryer?.continue() ?? (this.state.status === "pending" ? this.execute(this.state.variables) : Promise.resolve());
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Runs the mutation function for the given variables through a retryer, and
|
|
1779
|
-
* drives the mutation's state and lifecycle callbacks through to settlement.
|
|
1780
|
-
*
|
|
1781
|
-
* If this mutation's state is already `pending` when `execute` is called
|
|
1782
|
-
* (i.e. it was restored, still in-flight, from a dehydrated state), the
|
|
1783
|
-
* `onMutate` step is skipped and a `continue` action is dispatched to
|
|
1784
|
-
* unpause it; otherwise a `pending` action is dispatched first, then the
|
|
1785
|
-
* mutation cache's `onMutate` and the mutation's own `onMutate` option are
|
|
1786
|
-
* awaited in that order, and the resulting context is stored.
|
|
1787
|
-
*
|
|
1788
|
-
* The mutation function is then run (subject to `retry`/`retryDelay`/
|
|
1789
|
-
* `networkMode`, and to the mutation cache's scope-based serialization).
|
|
1790
|
-
* On success, the cache's `onSuccess`/`onSettled` callbacks run before the
|
|
1791
|
-
* mutation's own `onSuccess`/`onSettled` options, a `success` action is
|
|
1792
|
-
* dispatched, and the resolved data is returned. On failure, the same
|
|
1793
|
-
* cache-then-option ordering is used for `onError`/`onSettled`, but each of
|
|
1794
|
-
* those four callbacks is individually caught so that a throwing callback
|
|
1795
|
-
* cannot mask the original error; an `error` action is then dispatched and
|
|
1796
|
-
* the original error is re-thrown.
|
|
1797
|
-
*
|
|
1798
|
-
* @example
|
|
1799
|
-
* ```ts
|
|
1800
|
-
* // Called internally by `MutationObserver.mutate` and `Mutation.continue` —
|
|
1801
|
-
* // applications normally trigger mutations through those, not this method.
|
|
1802
|
-
* const data = await mutation.execute(variables)
|
|
1803
|
-
* ```
|
|
1804
|
-
*
|
|
1805
|
-
* @see {@link Mutation#continue}
|
|
1806
|
-
*/
|
|
1807
|
-
async execute(variables) {
|
|
1808
|
-
const onContinue = () => {
|
|
1809
|
-
this.#dispatch({ type: "continue" });
|
|
1810
|
-
};
|
|
1811
|
-
const mutationFnContext = {
|
|
1812
|
-
client: this.#client,
|
|
1813
|
-
meta: this.options.meta,
|
|
1814
|
-
mutationKey: this.options.mutationKey
|
|
1815
|
-
};
|
|
1816
|
-
const retryer = this.#retryer = createRetryer({
|
|
1817
|
-
fn: () => {
|
|
1818
|
-
if (!this.options.mutationFn) return Promise.reject(/* @__PURE__ */ new Error("No mutationFn found"));
|
|
1819
|
-
return this.options.mutationFn(variables, mutationFnContext);
|
|
1820
|
-
},
|
|
1821
|
-
onFail: (failureCount, error) => {
|
|
1822
|
-
this.#dispatch({
|
|
1823
|
-
type: "failed",
|
|
1824
|
-
failureCount,
|
|
1825
|
-
error
|
|
1826
|
-
});
|
|
1827
|
-
},
|
|
1828
|
-
onPause: () => {
|
|
1829
|
-
this.#dispatch({ type: "pause" });
|
|
1830
|
-
},
|
|
1831
|
-
onContinue,
|
|
1832
|
-
retry: this.options.retry ?? 0,
|
|
1833
|
-
retryDelay: this.options.retryDelay,
|
|
1834
|
-
networkMode: this.options.networkMode,
|
|
1835
|
-
canRun: () => this.#mutationCache.canRun(this)
|
|
1836
|
-
});
|
|
1837
|
-
const restored = this.state.status === "pending";
|
|
1838
|
-
const isPaused = !retryer.canStart();
|
|
1839
|
-
try {
|
|
1840
|
-
if (restored) onContinue();
|
|
1841
|
-
else {
|
|
1842
|
-
this.#dispatch({
|
|
1843
|
-
type: "pending",
|
|
1844
|
-
variables,
|
|
1845
|
-
isPaused
|
|
1846
|
-
});
|
|
1847
|
-
if (this.#mutationCache.config.onMutate) await this.#mutationCache.config.onMutate(variables, this, mutationFnContext);
|
|
1848
|
-
const context = await this.options.onMutate?.(variables, mutationFnContext);
|
|
1849
|
-
if (context !== this.state.context) this.#dispatch({
|
|
1850
|
-
type: "pending",
|
|
1851
|
-
context,
|
|
1852
|
-
variables,
|
|
1853
|
-
isPaused
|
|
1854
|
-
});
|
|
1855
|
-
}
|
|
1856
|
-
const data = await retryer.start();
|
|
1857
|
-
await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this, mutationFnContext);
|
|
1858
|
-
await this.options.onSuccess?.(data, variables, this.state.context, mutationFnContext);
|
|
1859
|
-
await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this, mutationFnContext);
|
|
1860
|
-
await this.options.onSettled?.(data, null, variables, this.state.context, mutationFnContext);
|
|
1861
|
-
this.#dispatch({
|
|
1862
|
-
type: "success",
|
|
1863
|
-
data
|
|
1864
|
-
});
|
|
1865
|
-
return data;
|
|
1866
|
-
} catch (error) {
|
|
1867
|
-
try {
|
|
1868
|
-
await this.#mutationCache.config.onError?.(error, variables, this.state.context, this, mutationFnContext);
|
|
1869
|
-
} catch (e) {
|
|
1870
|
-
Promise.reject(e);
|
|
1871
|
-
}
|
|
1872
|
-
try {
|
|
1873
|
-
await this.options.onError?.(error, variables, this.state.context, mutationFnContext);
|
|
1874
|
-
} catch (e) {
|
|
1875
|
-
Promise.reject(e);
|
|
1876
|
-
}
|
|
1877
|
-
try {
|
|
1878
|
-
await this.#mutationCache.config.onSettled?.(void 0, error, this.state.variables, this.state.context, this, mutationFnContext);
|
|
1879
|
-
} catch (e) {
|
|
1880
|
-
Promise.reject(e);
|
|
1881
|
-
}
|
|
1882
|
-
try {
|
|
1883
|
-
await this.options.onSettled?.(void 0, error, variables, this.state.context, mutationFnContext);
|
|
1884
|
-
} catch (e) {
|
|
1885
|
-
Promise.reject(e);
|
|
1886
|
-
}
|
|
1887
|
-
this.#dispatch({
|
|
1888
|
-
type: "error",
|
|
1889
|
-
error
|
|
1890
|
-
});
|
|
1891
|
-
throw error;
|
|
1892
|
-
} finally {
|
|
1893
|
-
if (this.#retryer === retryer) this.#retryer = void 0;
|
|
1894
|
-
this.#mutationCache.runNext(this);
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
#dispatch(action) {
|
|
1898
|
-
const reducer = (state) => {
|
|
1899
|
-
switch (action.type) {
|
|
1900
|
-
case "failed": return {
|
|
1901
|
-
...state,
|
|
1902
|
-
failureCount: action.failureCount,
|
|
1903
|
-
failureReason: action.error
|
|
1904
|
-
};
|
|
1905
|
-
case "pause": return {
|
|
1906
|
-
...state,
|
|
1907
|
-
isPaused: true
|
|
1908
|
-
};
|
|
1909
|
-
case "continue": return {
|
|
1910
|
-
...state,
|
|
1911
|
-
isPaused: false
|
|
1912
|
-
};
|
|
1913
|
-
case "pending": return {
|
|
1914
|
-
...state,
|
|
1915
|
-
context: action.context,
|
|
1916
|
-
data: void 0,
|
|
1917
|
-
failureCount: 0,
|
|
1918
|
-
failureReason: null,
|
|
1919
|
-
error: null,
|
|
1920
|
-
isPaused: action.isPaused,
|
|
1921
|
-
status: "pending",
|
|
1922
|
-
variables: action.variables,
|
|
1923
|
-
submittedAt: Date.now()
|
|
1924
|
-
};
|
|
1925
|
-
case "success": return {
|
|
1926
|
-
...state,
|
|
1927
|
-
data: action.data,
|
|
1928
|
-
failureCount: 0,
|
|
1929
|
-
failureReason: null,
|
|
1930
|
-
error: null,
|
|
1931
|
-
status: "success",
|
|
1932
|
-
isPaused: false
|
|
1933
|
-
};
|
|
1934
|
-
case "error": return {
|
|
1935
|
-
...state,
|
|
1936
|
-
data: void 0,
|
|
1937
|
-
error: action.error,
|
|
1938
|
-
failureCount: state.failureCount + 1,
|
|
1939
|
-
failureReason: action.error,
|
|
1940
|
-
isPaused: false,
|
|
1941
|
-
status: "error"
|
|
1942
|
-
};
|
|
1943
|
-
}
|
|
1944
|
-
};
|
|
1945
|
-
this.state = reducer(this.state);
|
|
1946
|
-
notifyManager.batch(() => {
|
|
1947
|
-
this.#observers.forEach((observer) => {
|
|
1948
|
-
observer.onMutationUpdate(action);
|
|
1949
|
-
});
|
|
1950
|
-
this.#mutationCache.notify({
|
|
1951
|
-
mutation: this,
|
|
1952
|
-
type: "updated",
|
|
1953
|
-
action
|
|
1954
|
-
});
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
};
|
|
1958
|
-
function getDefaultState() {
|
|
1959
|
-
return {
|
|
1960
|
-
context: void 0,
|
|
1961
|
-
data: void 0,
|
|
1962
|
-
error: null,
|
|
1963
|
-
failureCount: 0,
|
|
1964
|
-
failureReason: null,
|
|
1965
|
-
isPaused: false,
|
|
1966
|
-
status: "idle",
|
|
1967
|
-
variables: void 0,
|
|
1968
|
-
submittedAt: 0
|
|
1969
|
-
};
|
|
1970
|
-
}
|
|
1971
|
-
//#endregion
|
|
1972
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/mutationCache.js
|
|
1973
|
-
/**
|
|
1974
|
-
* The `MutationCache` is the storage for mutations.
|
|
1975
|
-
*
|
|
1976
|
-
* Normally, you will not interact with the `MutationCache` directly and instead use a
|
|
1977
|
-
* `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of
|
|
1978
|
-
* safe/known updates to the cache, such as mutations being added, removed, or updated.
|
|
1979
|
-
*
|
|
1980
|
-
* @example
|
|
1981
|
-
* ```ts
|
|
1982
|
-
* const unsubscribe = mutationCache.subscribe((event) => {
|
|
1983
|
-
* console.log(event.type, event.mutation)
|
|
1984
|
-
* })
|
|
1985
|
-
* ```
|
|
1986
|
-
*/
|
|
1987
|
-
var MutationCache = class extends Subscribable {
|
|
1988
|
-
#mutations;
|
|
1989
|
-
#scopes;
|
|
1990
|
-
#mutationId;
|
|
1991
|
-
constructor(config = {}) {
|
|
1992
|
-
super();
|
|
1993
|
-
this.config = config;
|
|
1994
|
-
this.#mutations = /* @__PURE__ */ new Set();
|
|
1995
|
-
this.#scopes = /* @__PURE__ */ new Map();
|
|
1996
|
-
this.#mutationId = 0;
|
|
1997
|
-
}
|
|
1998
|
-
/** @internal */
|
|
1999
|
-
build(client, options, state) {
|
|
2000
|
-
const mutation = new Mutation({
|
|
2001
|
-
client,
|
|
2002
|
-
mutationCache: this,
|
|
2003
|
-
mutationId: ++this.#mutationId,
|
|
2004
|
-
options: client.defaultMutationOptions(options),
|
|
2005
|
-
state
|
|
2006
|
-
});
|
|
2007
|
-
this.add(mutation);
|
|
2008
|
-
return mutation;
|
|
2009
|
-
}
|
|
2010
|
-
/** @internal */
|
|
2011
|
-
add(mutation) {
|
|
2012
|
-
this.#mutations.add(mutation);
|
|
2013
|
-
const scope = scopeFor(mutation);
|
|
2014
|
-
if (typeof scope === "string") {
|
|
2015
|
-
const scopedMutations = this.#scopes.get(scope);
|
|
2016
|
-
if (scopedMutations) scopedMutations.push(mutation);
|
|
2017
|
-
else this.#scopes.set(scope, [mutation]);
|
|
2018
|
-
}
|
|
2019
|
-
this.notify({
|
|
2020
|
-
type: "added",
|
|
2021
|
-
mutation
|
|
2022
|
-
});
|
|
2023
|
-
}
|
|
2024
|
-
/** @internal */
|
|
2025
|
-
remove(mutation) {
|
|
2026
|
-
if (this.#mutations.delete(mutation)) {
|
|
2027
|
-
const scope = scopeFor(mutation);
|
|
2028
|
-
if (typeof scope === "string") {
|
|
2029
|
-
const scopedMutations = this.#scopes.get(scope);
|
|
2030
|
-
if (scopedMutations) {
|
|
2031
|
-
if (scopedMutations.length > 1) {
|
|
2032
|
-
const index = scopedMutations.indexOf(mutation);
|
|
2033
|
-
if (index !== -1) scopedMutations.splice(index, 1);
|
|
2034
|
-
} else if (scopedMutations[0] === mutation) this.#scopes.delete(scope);
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
this.notify({
|
|
2039
|
-
type: "removed",
|
|
2040
|
-
mutation
|
|
2041
|
-
});
|
|
2042
|
-
}
|
|
2043
|
-
/** @internal */
|
|
2044
|
-
canRun(mutation) {
|
|
2045
|
-
const scope = scopeFor(mutation);
|
|
2046
|
-
if (typeof scope === "string") {
|
|
2047
|
-
const firstPendingMutation = this.#scopes.get(scope)?.find((m) => m.state.status === "pending");
|
|
2048
|
-
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
2049
|
-
} else return true;
|
|
2050
|
-
}
|
|
2051
|
-
/** @internal */
|
|
2052
|
-
runNext(mutation) {
|
|
2053
|
-
const scope = scopeFor(mutation);
|
|
2054
|
-
if (typeof scope === "string") return (this.#scopes.get(scope)?.find((m) => m !== mutation && m.state.isPaused))?.continue() ?? Promise.resolve();
|
|
2055
|
-
else return Promise.resolve();
|
|
2056
|
-
}
|
|
2057
|
-
/**
|
|
2058
|
-
* Removes all mutations from the cache.
|
|
2059
|
-
*
|
|
2060
|
-
* @example
|
|
2061
|
-
* ```ts
|
|
2062
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
2063
|
-
*
|
|
2064
|
-
* mutationCache.clear()
|
|
2065
|
-
* ```
|
|
2066
|
-
*/
|
|
2067
|
-
clear() {
|
|
2068
|
-
notifyManager.batch(() => {
|
|
2069
|
-
this.#mutations.forEach((mutation) => {
|
|
2070
|
-
this.notify({
|
|
2071
|
-
type: "removed",
|
|
2072
|
-
mutation
|
|
2073
|
-
});
|
|
2074
|
-
});
|
|
2075
|
-
this.#mutations.clear();
|
|
2076
|
-
this.#scopes.clear();
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* Returns all mutations within the cache.
|
|
2081
|
-
*
|
|
2082
|
-
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2083
|
-
* information about a mutation in rare scenarios.
|
|
2084
|
-
*
|
|
2085
|
-
* @example
|
|
2086
|
-
* ```ts
|
|
2087
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
2088
|
-
*
|
|
2089
|
-
* const mutations = mutationCache.getAll()
|
|
2090
|
-
* ```
|
|
2091
|
-
*/
|
|
2092
|
-
getAll() {
|
|
2093
|
-
return Array.from(this.#mutations);
|
|
2094
|
-
}
|
|
2095
|
-
/**
|
|
2096
|
-
* A slightly more advanced method that can be used to get an existing mutation instance from
|
|
2097
|
-
* the cache. If the mutation does not exist, `undefined` is returned.
|
|
2098
|
-
*
|
|
2099
|
-
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2100
|
-
* information about a mutation in rare scenarios.
|
|
2101
|
-
*
|
|
2102
|
-
* @see {@link MutationCache#findAll}
|
|
2103
|
-
* @example
|
|
2104
|
-
* ```ts
|
|
2105
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
2106
|
-
*
|
|
2107
|
-
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
2108
|
-
* ```
|
|
2109
|
-
*/
|
|
2110
|
-
find(filters) {
|
|
2111
|
-
const defaultedFilters = {
|
|
2112
|
-
exact: true,
|
|
2113
|
-
...filters
|
|
2114
|
-
};
|
|
2115
|
-
return this.getAll().find((mutation) => matchMutation(defaultedFilters, mutation));
|
|
2116
|
-
}
|
|
2117
|
-
/**
|
|
2118
|
-
* An even more advanced method that can be used to get existing mutation instances from the
|
|
2119
|
-
* cache that match the given filters. If no mutations match, an empty array is returned.
|
|
2120
|
-
*
|
|
2121
|
-
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2122
|
-
* information about mutations in rare scenarios.
|
|
2123
|
-
*
|
|
2124
|
-
* @see {@link MutationCache#find}
|
|
2125
|
-
* @example
|
|
2126
|
-
* ```ts
|
|
2127
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
2128
|
-
*
|
|
2129
|
-
* const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })
|
|
2130
|
-
* ```
|
|
2131
|
-
*/
|
|
2132
|
-
findAll(filters = {}) {
|
|
2133
|
-
return this.getAll().filter((mutation) => matchMutation(filters, mutation));
|
|
2134
|
-
}
|
|
2135
|
-
/** @internal */
|
|
2136
|
-
notify(event) {
|
|
2137
|
-
notifyManager.batch(() => {
|
|
2138
|
-
this.listeners.forEach((listener) => {
|
|
2139
|
-
listener(event);
|
|
2140
|
-
});
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
/** @internal */
|
|
2144
|
-
resumePausedMutations() {
|
|
2145
|
-
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
2146
|
-
return notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(noop))));
|
|
2147
|
-
}
|
|
2148
|
-
};
|
|
2149
|
-
function scopeFor(mutation) {
|
|
2150
|
-
return mutation.options.scope?.id;
|
|
2151
|
-
}
|
|
2152
|
-
//#endregion
|
|
2153
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/queryCache.js
|
|
2154
|
-
/**
|
|
2155
|
-
* The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta
|
|
2156
|
-
* information, and state of the queries it contains.
|
|
2157
|
-
*
|
|
2158
|
-
* Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`
|
|
2159
|
-
* for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of
|
|
2160
|
-
* safe/known updates to the cache, such as queries being added, removed, or updated — updates made
|
|
2161
|
-
* outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do
|
|
2162
|
-
* not notify subscribers.
|
|
2163
|
-
*
|
|
2164
|
-
* @example
|
|
2165
|
-
* ```ts
|
|
2166
|
-
* const unsubscribe = queryCache.subscribe((event) => {
|
|
2167
|
-
* console.log(event.type, event.query)
|
|
2168
|
-
* })
|
|
2169
|
-
* ```
|
|
2170
|
-
*/
|
|
2171
|
-
var QueryCache = class extends Subscribable {
|
|
2172
|
-
#queries;
|
|
2173
|
-
constructor(config = {}) {
|
|
2174
|
-
super();
|
|
2175
|
-
this.config = config;
|
|
2176
|
-
this.#queries = /* @__PURE__ */ new Map();
|
|
2177
|
-
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or
|
|
2180
|
-
* builds and adds a new one to the cache if none exists yet. Used by framework adapters and
|
|
2181
|
-
* plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
|
|
2182
|
-
* the reactive `QueryObserver` machinery.
|
|
2183
|
-
*
|
|
2184
|
-
* @example
|
|
2185
|
-
* ```ts
|
|
2186
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2187
|
-
*
|
|
2188
|
-
* const query = queryCache.build(queryClient, {
|
|
2189
|
-
* queryKey: ['posts'],
|
|
2190
|
-
* queryFn: fetchPosts,
|
|
2191
|
-
* })
|
|
2192
|
-
* ```
|
|
2193
|
-
*/
|
|
2194
|
-
build(client, options, state) {
|
|
2195
|
-
const queryKey = options.queryKey;
|
|
2196
|
-
const queryHash = options.queryHash ?? hashQueryKeyByOptions(queryKey, options);
|
|
2197
|
-
let query = this.get(queryHash);
|
|
2198
|
-
if (!query) {
|
|
2199
|
-
query = new Query({
|
|
2200
|
-
client,
|
|
2201
|
-
queryKey,
|
|
2202
|
-
queryHash,
|
|
2203
|
-
options: client.defaultQueryOptions(options),
|
|
2204
|
-
state,
|
|
2205
|
-
defaultOptions: client.getQueryDefaults(queryKey)
|
|
2206
|
-
});
|
|
2207
|
-
this.add(query);
|
|
2208
|
-
}
|
|
2209
|
-
return query;
|
|
2210
|
-
}
|
|
2211
|
-
/** @internal */
|
|
2212
|
-
add(query) {
|
|
2213
|
-
if (!this.#queries.has(query.queryHash)) {
|
|
2214
|
-
this.#queries.set(query.queryHash, query);
|
|
2215
|
-
this.notify({
|
|
2216
|
-
type: "added",
|
|
2217
|
-
query
|
|
2218
|
-
});
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
/**
|
|
2222
|
-
* Destroys the given `Query` and removes it from the cache, notifying subscribers with a
|
|
2223
|
-
* `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
|
|
2224
|
-
* (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
|
|
2225
|
-
* removals across `QueryCache` instances.
|
|
2226
|
-
*
|
|
2227
|
-
* @example
|
|
2228
|
-
* ```ts
|
|
2229
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2230
|
-
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
2231
|
-
*
|
|
2232
|
-
* if (query) {
|
|
2233
|
-
* queryCache.remove(query)
|
|
2234
|
-
* }
|
|
2235
|
-
* ```
|
|
2236
|
-
*/
|
|
2237
|
-
remove(query) {
|
|
2238
|
-
const queryInMap = this.#queries.get(query.queryHash);
|
|
2239
|
-
if (queryInMap) {
|
|
2240
|
-
query.destroy();
|
|
2241
|
-
if (queryInMap === query) this.#queries.delete(query.queryHash);
|
|
2242
|
-
this.notify({
|
|
2243
|
-
type: "removed",
|
|
2244
|
-
query
|
|
2245
|
-
});
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
/**
|
|
2249
|
-
* Removes all queries from the cache.
|
|
2250
|
-
*
|
|
2251
|
-
* @example
|
|
2252
|
-
* ```ts
|
|
2253
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2254
|
-
*
|
|
2255
|
-
* queryCache.clear()
|
|
2256
|
-
* ```
|
|
2257
|
-
*/
|
|
2258
|
-
clear() {
|
|
2259
|
-
notifyManager.batch(() => {
|
|
2260
|
-
this.getAll().forEach((query) => {
|
|
2261
|
-
this.remove(query);
|
|
2262
|
-
});
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
/**
|
|
2266
|
-
* Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none
|
|
2267
|
-
* exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
|
|
2268
|
-
* than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
|
|
2269
|
-
* to look up directly.
|
|
2270
|
-
*
|
|
2271
|
-
* @example
|
|
2272
|
-
* ```ts
|
|
2273
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2274
|
-
* const queryHash = hashKey(['posts'])
|
|
2275
|
-
*
|
|
2276
|
-
* const query = queryCache.get(queryHash)
|
|
2277
|
-
* ```
|
|
2278
|
-
*/
|
|
2279
|
-
get(queryHash) {
|
|
2280
|
-
return this.#queries.get(queryHash);
|
|
2281
|
-
}
|
|
2282
|
-
/**
|
|
2283
|
-
* Returns all queries within the cache.
|
|
2284
|
-
*
|
|
2285
|
-
* @example
|
|
2286
|
-
* ```ts
|
|
2287
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2288
|
-
*
|
|
2289
|
-
* const queries = queryCache.getAll()
|
|
2290
|
-
* ```
|
|
2291
|
-
*/
|
|
2292
|
-
getAll() {
|
|
2293
|
-
return [...this.#queries.values()];
|
|
2294
|
-
}
|
|
2295
|
-
/**
|
|
2296
|
-
* A slightly more advanced method that can be used to get an existing query instance from the
|
|
2297
|
-
* cache. This instance not only contains all the state for the query, but all of the instances,
|
|
2298
|
-
* and underlying guts of the query as well. If the query does not exist, `undefined` is
|
|
2299
|
-
* returned.
|
|
2300
|
-
*
|
|
2301
|
-
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2302
|
-
* information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
|
|
2303
|
-
* decide whether a query is fresh enough to be used as an initial value).
|
|
2304
|
-
*
|
|
2305
|
-
* @see {@link QueryCache#findAll}
|
|
2306
|
-
* @example
|
|
2307
|
-
* ```ts
|
|
2308
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2309
|
-
*
|
|
2310
|
-
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
2311
|
-
* ```
|
|
2312
|
-
*/
|
|
2313
|
-
find(filters) {
|
|
2314
|
-
const defaultedFilters = {
|
|
2315
|
-
exact: true,
|
|
2316
|
-
...filters
|
|
2317
|
-
};
|
|
2318
|
-
return this.getAll().find((query) => matchQuery(defaultedFilters, query));
|
|
2319
|
-
}
|
|
2320
|
-
/**
|
|
2321
|
-
* An even more advanced method that can be used to get existing query instances from the cache
|
|
2322
|
-
* that partially match a query key. If no queries match, an empty array is returned.
|
|
2323
|
-
*
|
|
2324
|
-
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2325
|
-
* information about queries in rare scenarios.
|
|
2326
|
-
*
|
|
2327
|
-
* @see {@link QueryCache#find}
|
|
2328
|
-
* @example
|
|
2329
|
-
* ```ts
|
|
2330
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2331
|
-
*
|
|
2332
|
-
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
2333
|
-
* ```
|
|
2334
|
-
*/
|
|
2335
|
-
findAll(filters = {}) {
|
|
2336
|
-
const queries = this.getAll();
|
|
2337
|
-
return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
|
|
2338
|
-
}
|
|
2339
|
-
/** @internal */
|
|
2340
|
-
notify(event) {
|
|
2341
|
-
notifyManager.batch(() => {
|
|
2342
|
-
this.listeners.forEach((listener) => {
|
|
2343
|
-
listener(event);
|
|
2344
|
-
});
|
|
2345
|
-
});
|
|
2346
|
-
}
|
|
2347
|
-
/** @internal */
|
|
2348
|
-
onFocus() {
|
|
2349
|
-
notifyManager.batch(() => {
|
|
2350
|
-
this.getAll().forEach((query) => {
|
|
2351
|
-
query.onFocus();
|
|
2352
|
-
});
|
|
2353
|
-
});
|
|
2354
|
-
}
|
|
2355
|
-
/** @internal */
|
|
2356
|
-
onOnline() {
|
|
2357
|
-
notifyManager.batch(() => {
|
|
2358
|
-
this.getAll().forEach((query) => {
|
|
2359
|
-
query.onOnline();
|
|
2360
|
-
});
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
};
|
|
2364
|
-
//#endregion
|
|
2365
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.103.1/node_modules/@tanstack/query-core/build/modern/queryClient.js
|
|
2366
|
-
/**
|
|
2367
|
-
* `QueryClient` is used to interact with a cache of queries and mutations. It owns a
|
|
2368
|
-
* `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds
|
|
2369
|
-
* the default options that are applied to queries and mutations created through it.
|
|
2370
|
-
*
|
|
2371
|
-
* @example
|
|
2372
|
-
* ```ts
|
|
2373
|
-
* const queryClient = new QueryClient({
|
|
2374
|
-
* defaultOptions: {
|
|
2375
|
-
* queries: {
|
|
2376
|
-
* staleTime: Infinity,
|
|
2377
|
-
* },
|
|
2378
|
-
* },
|
|
2379
|
-
* })
|
|
2380
|
-
*
|
|
2381
|
-
* await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })
|
|
2382
|
-
* ```
|
|
2383
|
-
*/
|
|
2384
|
-
var QueryClient = class {
|
|
2385
|
-
#queryCache;
|
|
2386
|
-
#mutationCache;
|
|
2387
|
-
#defaultOptions;
|
|
2388
|
-
#queryDefaults;
|
|
2389
|
-
#mutationDefaults;
|
|
2390
|
-
#mountCount;
|
|
2391
|
-
#unsubscribeFocus;
|
|
2392
|
-
#unsubscribeOnline;
|
|
2393
|
-
constructor(config = {}) {
|
|
2394
|
-
this.#queryCache = config.queryCache || new QueryCache();
|
|
2395
|
-
this.#mutationCache = config.mutationCache || new MutationCache();
|
|
2396
|
-
this.#defaultOptions = config.defaultOptions || {};
|
|
2397
|
-
this.#queryDefaults = /* @__PURE__ */ new Map();
|
|
2398
|
-
this.#mutationDefaults = /* @__PURE__ */ new Map();
|
|
2399
|
-
this.#mountCount = 0;
|
|
2400
|
-
}
|
|
2401
|
-
/**
|
|
2402
|
-
* Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start
|
|
2403
|
-
* listening for focus/online events and resume paused mutations. Ref-counted via an internal
|
|
2404
|
-
* mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down
|
|
2405
|
-
* the shared listeners until the last one unmounts.
|
|
2406
|
-
*/
|
|
2407
|
-
mount() {
|
|
2408
|
-
this.#mountCount++;
|
|
2409
|
-
if (this.#mountCount !== 1) return;
|
|
2410
|
-
this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {
|
|
2411
|
-
if (focused) {
|
|
2412
|
-
await this.resumePausedMutations();
|
|
2413
|
-
this.#queryCache.onFocus();
|
|
2414
|
-
}
|
|
2415
|
-
});
|
|
2416
|
-
this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {
|
|
2417
|
-
if (online) {
|
|
2418
|
-
await this.resumePausedMutations();
|
|
2419
|
-
this.#queryCache.onOnline();
|
|
2420
|
-
}
|
|
2421
|
-
});
|
|
2422
|
-
}
|
|
2423
|
-
/**
|
|
2424
|
-
* The inverse of {@link QueryClient#mount} — called by a framework adapter's
|
|
2425
|
-
* `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online
|
|
2426
|
-
* listeners once the mount count returns to `0`.
|
|
2427
|
-
*/
|
|
2428
|
-
unmount() {
|
|
2429
|
-
this.#mountCount--;
|
|
2430
|
-
if (this.#mountCount !== 0) return;
|
|
2431
|
-
this.#unsubscribeFocus?.();
|
|
2432
|
-
this.#unsubscribeFocus = void 0;
|
|
2433
|
-
this.#unsubscribeOnline?.();
|
|
2434
|
-
this.#unsubscribeOnline = void 0;
|
|
2435
|
-
}
|
|
2436
|
-
/**
|
|
2437
|
-
* Returns the number of queries in the cache that are currently fetching, optionally
|
|
2438
|
-
* matching a set of filters. This includes background-fetching, loading new pages, and
|
|
2439
|
-
* loading more infinite query results.
|
|
2440
|
-
*
|
|
2441
|
-
* @example
|
|
2442
|
-
* ```ts
|
|
2443
|
-
* if (queryClient.isFetching()) {
|
|
2444
|
-
* console.log('At least one query is fetching!')
|
|
2445
|
-
* }
|
|
2446
|
-
* ```
|
|
2447
|
-
*/
|
|
2448
|
-
isFetching(filters) {
|
|
2449
|
-
return this.#queryCache.findAll({
|
|
2450
|
-
...filters,
|
|
2451
|
-
fetchStatus: "fetching"
|
|
2452
|
-
}).length;
|
|
2453
|
-
}
|
|
2454
|
-
/**
|
|
2455
|
-
* Returns the number of mutations in the cache that are currently pending, optionally
|
|
2456
|
-
* matching a set of filters.
|
|
2457
|
-
*
|
|
2458
|
-
* @example
|
|
2459
|
-
* ```ts
|
|
2460
|
-
* if (queryClient.isMutating()) {
|
|
2461
|
-
* console.log('At least one mutation is pending!')
|
|
2462
|
-
* }
|
|
2463
|
-
* ```
|
|
2464
|
-
*/
|
|
2465
|
-
isMutating(filters) {
|
|
2466
|
-
return this.#mutationCache.findAll({
|
|
2467
|
-
...filters,
|
|
2468
|
-
status: "pending"
|
|
2469
|
-
}).length;
|
|
2470
|
-
}
|
|
2471
|
-
/**
|
|
2472
|
-
* Imperative (non-reactive) way to retrieve data for a QueryKey.
|
|
2473
|
-
* Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
|
|
2474
|
-
*
|
|
2475
|
-
* Hint: Do not use this function inside a component, because it won't receive updates.
|
|
2476
|
-
* Use `useQuery` to create a `QueryObserver` that subscribes to changes.
|
|
2477
|
-
*
|
|
2478
|
-
* @see {@link QueryClient#getQueriesData}
|
|
2479
|
-
*/
|
|
2480
|
-
getQueryData(queryKey) {
|
|
2481
|
-
const options = this.defaultQueryOptions({ queryKey });
|
|
2482
|
-
return this.#queryCache.get(options.queryHash)?.state.data;
|
|
2483
|
-
}
|
|
2484
|
-
/**
|
|
2485
|
-
* @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
2486
|
-
*/
|
|
2487
|
-
ensureQueryData(options) {
|
|
2488
|
-
const defaultedOptions = this.defaultQueryOptions(options);
|
|
2489
|
-
const query = this.#queryCache.build(this, defaultedOptions);
|
|
2490
|
-
const cachedData = query.state.data;
|
|
2491
|
-
if (cachedData === void 0) return this.fetchQuery(options);
|
|
2492
|
-
if (options.revalidateIfStale && query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))) this.prefetchQuery(defaultedOptions);
|
|
2493
|
-
return Promise.resolve(cachedData);
|
|
2494
|
-
}
|
|
2495
|
-
/**
|
|
2496
|
-
* Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.
|
|
2497
|
-
* Only queries matching the given filters are returned; if none match, an empty array is
|
|
2498
|
-
* returned.
|
|
2499
|
-
*
|
|
2500
|
-
* Because the matched queries can hold data of different shapes (e.g. a broad filter can match
|
|
2501
|
-
* queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather
|
|
2502
|
-
* than being inferred. Passing a more specific type is a convenience for call sites that know
|
|
2503
|
-
* every matched query holds the same shape — it is not checked against the actual cache
|
|
2504
|
-
* contents.
|
|
2505
|
-
*
|
|
2506
|
-
* @see {@link QueryClient#getQueryData}
|
|
2507
|
-
* @example
|
|
2508
|
-
* ```ts
|
|
2509
|
-
* const data = queryClient.getQueriesData({ queryKey: ['posts'] })
|
|
2510
|
-
* ```
|
|
2511
|
-
*/
|
|
2512
|
-
getQueriesData(filters) {
|
|
2513
|
-
return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {
|
|
2514
|
-
return [queryKey, state.data];
|
|
2515
|
-
});
|
|
2516
|
-
}
|
|
2517
|
-
/**
|
|
2518
|
-
* Synchronous way to immediately update a query's cached data. If the updater (or the value
|
|
2519
|
-
* passed) resolves to `undefined`, the cache is left untouched and no query is created;
|
|
2520
|
-
* otherwise, if the query does not exist yet, it will be created. To update multiple queries
|
|
2521
|
-
* at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.
|
|
2522
|
-
*
|
|
2523
|
-
* Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
|
|
2524
|
-
* via {@link QueryClient#getQueryData}, in place.
|
|
2525
|
-
*
|
|
2526
|
-
* @param queryKey - The query key to set data for.
|
|
2527
|
-
* @param updater - Either the new data, or a function that receives the current data (which
|
|
2528
|
-
* may be `undefined`) and returns the new data.
|
|
2529
|
-
*
|
|
2530
|
-
* @example
|
|
2531
|
-
* ```ts
|
|
2532
|
-
* queryClient.setQueryData(['posts'], newPosts)
|
|
2533
|
-
*
|
|
2534
|
-
* // Or, using an updater function that receives the current data:
|
|
2535
|
-
* queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])
|
|
2536
|
-
* ```
|
|
2537
|
-
*/
|
|
2538
|
-
setQueryData(queryKey, updater, options) {
|
|
2539
|
-
const defaultedOptions = this.defaultQueryOptions({ queryKey });
|
|
2540
|
-
const prevData = this.#queryCache.get(defaultedOptions.queryHash)?.state.data;
|
|
2541
|
-
const data = functionalUpdate(updater, prevData);
|
|
2542
|
-
if (data === void 0) return;
|
|
2543
|
-
return this.#queryCache.build(this, defaultedOptions).setData(data, {
|
|
2544
|
-
...options,
|
|
2545
|
-
manual: true
|
|
2546
|
-
});
|
|
2547
|
-
}
|
|
2548
|
-
/**
|
|
2549
|
-
* Synchronous way to immediately update the cached data of multiple queries at once, using
|
|
2550
|
-
* filters or partial query key matching. Only queries that already exist and match the given
|
|
2551
|
-
* filters are updated; no new cache entries are created. Internally this calls
|
|
2552
|
-
* {@link QueryClient#setQueryData} for each matching query.
|
|
2553
|
-
*
|
|
2554
|
-
* @example
|
|
2555
|
-
* ```ts
|
|
2556
|
-
* queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>
|
|
2557
|
-
* oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,
|
|
2558
|
-
* )
|
|
2559
|
-
* ```
|
|
2560
|
-
*/
|
|
2561
|
-
setQueriesData(filters, updater, options) {
|
|
2562
|
-
return notifyManager.batch(() => this.#queryCache.findAll(filters).map(({ queryKey }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
|
|
2563
|
-
}
|
|
2564
|
-
/**
|
|
2565
|
-
* Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
|
|
2566
|
-
* exist, `undefined` is returned.
|
|
2567
|
-
*
|
|
2568
|
-
* @example
|
|
2569
|
-
* ```ts
|
|
2570
|
-
* const state = queryClient.getQueryState(['posts'])
|
|
2571
|
-
* console.log(state?.dataUpdatedAt)
|
|
2572
|
-
* ```
|
|
2573
|
-
*/
|
|
2574
|
-
getQueryState(queryKey) {
|
|
2575
|
-
const options = this.defaultQueryOptions({ queryKey });
|
|
2576
|
-
return this.#queryCache.get(options.queryHash)?.state;
|
|
2577
|
-
}
|
|
2578
|
-
/**
|
|
2579
|
-
* Removes queries from the cache that match the given filters. Unlike
|
|
2580
|
-
* {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
|
|
2581
|
-
* matching queries from the cache instead of refetching them. Without filters, every query in
|
|
2582
|
-
* the cache is removed.
|
|
2583
|
-
*
|
|
2584
|
-
* @example
|
|
2585
|
-
* ```ts
|
|
2586
|
-
* queryClient.removeQueries({ queryKey: ['posts'], exact: true })
|
|
2587
|
-
* ```
|
|
2588
|
-
*/
|
|
2589
|
-
removeQueries(filters) {
|
|
2590
|
-
const queryCache = this.#queryCache;
|
|
2591
|
-
notifyManager.batch(() => {
|
|
2592
|
-
queryCache.findAll(filters).forEach((query) => {
|
|
2593
|
-
queryCache.remove(query);
|
|
2594
|
-
});
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
/**
|
|
2598
|
-
* Resets queries matching the given filters back to their initial state (e.g. any
|
|
2599
|
-
* `initialData`), notifying subscribers rather than removing them. Active queries among the
|
|
2600
|
-
* matched set are then refetched, and the returned promise resolves once that refetch settles.
|
|
2601
|
-
*
|
|
2602
|
-
* @example
|
|
2603
|
-
* ```ts
|
|
2604
|
-
* await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
|
|
2605
|
-
* ```
|
|
2606
|
-
*/
|
|
2607
|
-
resetQueries(filters, options) {
|
|
2608
|
-
const queryCache = this.#queryCache;
|
|
2609
|
-
return notifyManager.batch(() => {
|
|
2610
|
-
const matched = queryCache.findAll(filters);
|
|
2611
|
-
const queriesToRefetch = new Set(matched);
|
|
2612
|
-
matched.forEach((query) => {
|
|
2613
|
-
query.reset();
|
|
2614
|
-
});
|
|
2615
|
-
return this.refetchQueries({
|
|
2616
|
-
type: "active",
|
|
2617
|
-
predicate: (query) => queriesToRefetch.has(query)
|
|
2618
|
-
}, options);
|
|
2619
|
-
});
|
|
2620
|
-
}
|
|
2621
|
-
/**
|
|
2622
|
-
* Cancels outgoing fetches for queries matching the given filters. Most useful when performing
|
|
2623
|
-
* optimistic updates, since any outgoing refetch that resolves afterwards would otherwise
|
|
2624
|
-
* overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is
|
|
2625
|
-
* reverted to its state before the outgoing fetch started.
|
|
2626
|
-
*
|
|
2627
|
-
* The returned promise never rejects, even if individual cancellations fail.
|
|
2628
|
-
*
|
|
2629
|
-
* @example
|
|
2630
|
-
* ```ts
|
|
2631
|
-
* await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
|
|
2632
|
-
* ```
|
|
2633
|
-
*/
|
|
2634
|
-
cancelQueries(filters, cancelOptions = {}) {
|
|
2635
|
-
const defaultedCancelOptions = {
|
|
2636
|
-
revert: true,
|
|
2637
|
-
...cancelOptions
|
|
2638
|
-
};
|
|
2639
|
-
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions)));
|
|
2640
|
-
return Promise.all(promises).then(noop).catch(noop);
|
|
2641
|
-
}
|
|
2642
|
-
/**
|
|
2643
|
-
* Marks queries matching the given filters as invalidated. Unlike
|
|
2644
|
-
* {@link QueryClient#removeQueries}, invalidated queries stay in the cache.
|
|
2645
|
-
*
|
|
2646
|
-
* Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
|
|
2647
|
-
* {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
|
|
2648
|
-
* `filters.type`, otherwise `'active'`.
|
|
2649
|
-
*
|
|
2650
|
-
* @example
|
|
2651
|
-
* ```ts
|
|
2652
|
-
* await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
|
|
2653
|
-
* ```
|
|
2654
|
-
*/
|
|
2655
|
-
invalidateQueries(filters, options = {}) {
|
|
2656
|
-
return notifyManager.batch(() => {
|
|
2657
|
-
this.#queryCache.findAll(filters).forEach((query) => {
|
|
2658
|
-
query.invalidate();
|
|
2659
|
-
});
|
|
2660
|
-
if (filters?.refetchType === "none") return Promise.resolve();
|
|
2661
|
-
return this.refetchQueries({
|
|
2662
|
-
...filters,
|
|
2663
|
-
type: filters?.refetchType ?? filters?.type ?? "active"
|
|
2664
|
-
}, options);
|
|
2665
|
-
});
|
|
2666
|
-
}
|
|
2667
|
-
/**
|
|
2668
|
-
* Refetches queries matching the given filters, regardless of whether they are stale. Without
|
|
2669
|
-
* filters, every query in the cache is refetched. Queries that are disabled, or static (only
|
|
2670
|
-
* have observers with a static `staleTime`), are never refetched.
|
|
2671
|
-
*
|
|
2672
|
-
* By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
|
|
2673
|
-
* one starts. The returned promise resolves once all matching queries have settled; it does
|
|
2674
|
-
* not reject on individual query failures unless `throwOnError` is set.
|
|
2675
|
-
*
|
|
2676
|
-
* @example
|
|
2677
|
-
* ```ts
|
|
2678
|
-
* // refetch all active queries partially matching a query key:
|
|
2679
|
-
* await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
|
|
2680
|
-
* ```
|
|
2681
|
-
*/
|
|
2682
|
-
refetchQueries(filters, options = {}) {
|
|
2683
|
-
const fetchOptions = {
|
|
2684
|
-
...options,
|
|
2685
|
-
cancelRefetch: options.cancelRefetch ?? true
|
|
2686
|
-
};
|
|
2687
|
-
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
|
|
2688
|
-
let promise = query.fetch(void 0, fetchOptions);
|
|
2689
|
-
if (!fetchOptions.throwOnError) promise = promise.catch(noop);
|
|
2690
|
-
return query.state.fetchStatus === "paused" ? Promise.resolve() : promise;
|
|
2691
|
-
}));
|
|
2692
|
-
return Promise.all(promises).then(noop);
|
|
2693
|
-
}
|
|
2694
|
-
/**
|
|
2695
|
-
* Asynchronous method to fetch and cache a query, resolving with the data or throwing with
|
|
2696
|
-
* the error.
|
|
2697
|
-
*
|
|
2698
|
-
* If the query already exists in the cache and its data is not stale (per the given
|
|
2699
|
-
* `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched
|
|
2700
|
-
* and the promise resolves once the fetch settles. If a `select` function is provided, it is
|
|
2701
|
-
* applied to the data in both cases (cached or freshly fetched) before it is returned.
|
|
2702
|
-
*
|
|
2703
|
-
* Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless
|
|
2704
|
-
* explicitly configured, since there is no component to catch a thrown error and retry through
|
|
2705
|
-
* re-render.
|
|
2706
|
-
*
|
|
2707
|
-
* The accepted options are `QueryObserverOptions` minus the fields that only make sense for a
|
|
2708
|
-
* reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,
|
|
2709
|
-
* `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,
|
|
2710
|
-
* `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this
|
|
2711
|
-
* method's options.
|
|
2712
|
-
*
|
|
2713
|
-
* This method replaces the deprecated `fetchQuery`, and — combined with
|
|
2714
|
-
* `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
|
|
2715
|
-
*
|
|
2716
|
-
* @example
|
|
2717
|
-
* ```ts
|
|
2718
|
-
* try {
|
|
2719
|
-
* const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })
|
|
2720
|
-
* } catch (error) {
|
|
2721
|
-
* console.log(error)
|
|
2722
|
-
* }
|
|
2723
|
-
* ```
|
|
2724
|
-
*/
|
|
2725
|
-
async query(options) {
|
|
2726
|
-
const defaultedOptions = this.defaultQueryOptions(options);
|
|
2727
|
-
if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
|
|
2728
|
-
const query = this.#queryCache.build(this, defaultedOptions);
|
|
2729
|
-
const queryData = query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query)) ? await query.fetch(defaultedOptions) : query.state.data;
|
|
2730
|
-
const select = defaultedOptions.select;
|
|
2731
|
-
if (select) return select(queryData);
|
|
2732
|
-
return queryData;
|
|
2733
|
-
}
|
|
2734
|
-
/**
|
|
2735
|
-
* @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
|
|
2736
|
-
*/
|
|
2737
|
-
fetchQuery(options) {
|
|
2738
|
-
const defaultedOptions = this.defaultQueryOptions(options);
|
|
2739
|
-
if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
|
|
2740
|
-
const query = this.#queryCache.build(this, defaultedOptions);
|
|
2741
|
-
return query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query)) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
|
|
2742
|
-
}
|
|
2743
|
-
/**
|
|
2744
|
-
* @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
2745
|
-
*/
|
|
2746
|
-
prefetchQuery(options) {
|
|
2747
|
-
return this.fetchQuery(options).then(noop).catch(noop);
|
|
2748
|
-
}
|
|
2749
|
-
/**
|
|
2750
|
-
* Asynchronous method to fetch and cache an infinite query, resolving with an
|
|
2751
|
-
* {@link InfiniteData} object or throwing with the error.
|
|
2752
|
-
*
|
|
2753
|
-
* Behaves like {@link QueryClient#query}, accepting the same options (minus
|
|
2754
|
-
* `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /
|
|
2755
|
-
* `getNextPageParam` pair used to refetch a fixed number of pages from the start.
|
|
2756
|
-
*
|
|
2757
|
-
* This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
|
|
2758
|
-
* `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
|
|
2759
|
-
*
|
|
2760
|
-
* @example
|
|
2761
|
-
* ```ts
|
|
2762
|
-
* try {
|
|
2763
|
-
* const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })
|
|
2764
|
-
* console.log(data.pages)
|
|
2765
|
-
* } catch (error) {
|
|
2766
|
-
* console.log(error)
|
|
2767
|
-
* }
|
|
2768
|
-
* ```
|
|
2769
|
-
*/
|
|
2770
|
-
infiniteQuery(options) {
|
|
2771
|
-
options._type = "infinite";
|
|
2772
|
-
return this.query(options);
|
|
2773
|
-
}
|
|
2774
|
-
/**
|
|
2775
|
-
* @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
|
|
2776
|
-
*/
|
|
2777
|
-
fetchInfiniteQuery(options) {
|
|
2778
|
-
options._type = "infinite";
|
|
2779
|
-
return this.fetchQuery(options);
|
|
2780
|
-
}
|
|
2781
|
-
/**
|
|
2782
|
-
* @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
2783
|
-
*/
|
|
2784
|
-
prefetchInfiniteQuery(options) {
|
|
2785
|
-
return this.fetchInfiniteQuery(options).then(noop).catch(noop);
|
|
2786
|
-
}
|
|
2787
|
-
/**
|
|
2788
|
-
* @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
2789
|
-
*/
|
|
2790
|
-
ensureInfiniteQueryData(options) {
|
|
2791
|
-
options._type = "infinite";
|
|
2792
|
-
return this.ensureQueryData(options);
|
|
2793
|
-
}
|
|
2794
|
-
/**
|
|
2795
|
-
* Resumes mutations that were paused because there was no network connection. Does nothing
|
|
2796
|
-
* (resolving immediately) if the client is currently offline.
|
|
2797
|
-
*
|
|
2798
|
-
* @example
|
|
2799
|
-
* ```ts
|
|
2800
|
-
* import { QueryClient } from '@tanstack/query-core'
|
|
2801
|
-
*
|
|
2802
|
-
* const queryClient = new QueryClient()
|
|
2803
|
-
* await queryClient.resumePausedMutations()
|
|
2804
|
-
* ```
|
|
2805
|
-
*/
|
|
2806
|
-
resumePausedMutations() {
|
|
2807
|
-
if (onlineManager.isOnline()) return this.#mutationCache.resumePausedMutations();
|
|
2808
|
-
return Promise.resolve();
|
|
2809
|
-
}
|
|
2810
|
-
/**
|
|
2811
|
-
* Returns the query cache this client is connected to.
|
|
2812
|
-
*
|
|
2813
|
-
* @example
|
|
2814
|
-
* ```ts
|
|
2815
|
-
* import { QueryClient } from '@tanstack/query-core'
|
|
2816
|
-
*
|
|
2817
|
-
* const queryClient = new QueryClient()
|
|
2818
|
-
* const queryCache = queryClient.getQueryCache()
|
|
2819
|
-
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
2820
|
-
* ```
|
|
2821
|
-
*/
|
|
2822
|
-
getQueryCache() {
|
|
2823
|
-
return this.#queryCache;
|
|
2824
|
-
}
|
|
2825
|
-
/**
|
|
2826
|
-
* Returns the mutation cache this client is connected to.
|
|
2827
|
-
*
|
|
2828
|
-
* @example
|
|
2829
|
-
* ```ts
|
|
2830
|
-
* import { QueryClient } from '@tanstack/query-core'
|
|
2831
|
-
*
|
|
2832
|
-
* const queryClient = new QueryClient()
|
|
2833
|
-
* const mutationCache = queryClient.getMutationCache()
|
|
2834
|
-
* const mutations = mutationCache.findAll({ status: 'pending' })
|
|
2835
|
-
* ```
|
|
2836
|
-
*/
|
|
2837
|
-
getMutationCache() {
|
|
2838
|
-
return this.#mutationCache;
|
|
2839
|
-
}
|
|
2840
|
-
/**
|
|
2841
|
-
* Returns the default options that were set when creating the client, or via
|
|
2842
|
-
* {@link QueryClient#setDefaultOptions}.
|
|
2843
|
-
*
|
|
2844
|
-
* @example
|
|
2845
|
-
* ```ts
|
|
2846
|
-
* import { QueryClient } from '@tanstack/query-core'
|
|
2847
|
-
*
|
|
2848
|
-
* const queryClient = new QueryClient()
|
|
2849
|
-
* const defaultOptions = queryClient.getDefaultOptions()
|
|
2850
|
-
* ```
|
|
2851
|
-
*/
|
|
2852
|
-
getDefaultOptions() {
|
|
2853
|
-
return this.#defaultOptions;
|
|
2854
|
-
}
|
|
2855
|
-
/**
|
|
2856
|
-
* Dynamically sets the default options for this client, overwriting any previously defined
|
|
2857
|
-
* default options.
|
|
2858
|
-
*
|
|
2859
|
-
* @see {@link QueryClient#getDefaultOptions}
|
|
2860
|
-
* @example
|
|
2861
|
-
* ```ts
|
|
2862
|
-
* import { QueryClient } from '@tanstack/query-core'
|
|
2863
|
-
*
|
|
2864
|
-
* const queryClient = new QueryClient()
|
|
2865
|
-
* queryClient.setDefaultOptions({
|
|
2866
|
-
* queries: {
|
|
2867
|
-
* staleTime: Infinity,
|
|
2868
|
-
* },
|
|
2869
|
-
* })
|
|
2870
|
-
* ```
|
|
2871
|
-
*/
|
|
2872
|
-
setDefaultOptions(options) {
|
|
2873
|
-
this.#defaultOptions = options;
|
|
2874
|
-
}
|
|
2875
|
-
/**
|
|
2876
|
-
* Sets default options for queries whose query key partially matches the given `queryKey`.
|
|
2877
|
-
*
|
|
2878
|
-
* If several registered query defaults match a given query key, they are merged together in
|
|
2879
|
-
* registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
|
|
2880
|
-
* most generic key to the least generic one — more specific defaults should be registered
|
|
2881
|
-
* after more generic ones so they take precedence.
|
|
2882
|
-
*
|
|
2883
|
-
* @example
|
|
2884
|
-
* ```ts
|
|
2885
|
-
* queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
|
|
2886
|
-
*
|
|
2887
|
-
* await queryClient.query({ queryKey: ['posts'] })
|
|
2888
|
-
* ```
|
|
2889
|
-
*/
|
|
2890
|
-
setQueryDefaults(queryKey, options) {
|
|
2891
|
-
this.#queryDefaults.set(hashKey(queryKey), {
|
|
2892
|
-
queryKey,
|
|
2893
|
-
defaultOptions: options
|
|
2894
|
-
});
|
|
2895
|
-
}
|
|
2896
|
-
/**
|
|
2897
|
-
* Returns the default options registered for queries whose query key partially matches the
|
|
2898
|
-
* given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
|
|
2899
|
-
* match, they are merged together in registration order.
|
|
2900
|
-
*
|
|
2901
|
-
* @example
|
|
2902
|
-
* ```ts
|
|
2903
|
-
* const defaultOptions = queryClient.getQueryDefaults(['posts'])
|
|
2904
|
-
* ```
|
|
2905
|
-
*/
|
|
2906
|
-
getQueryDefaults(queryKey) {
|
|
2907
|
-
const defaults = [...this.#queryDefaults.values()];
|
|
2908
|
-
const result = {};
|
|
2909
|
-
defaults.forEach((queryDefault) => {
|
|
2910
|
-
if (partialMatchKey(queryKey, queryDefault.queryKey)) Object.assign(result, queryDefault.defaultOptions);
|
|
2911
|
-
});
|
|
2912
|
-
return result;
|
|
2913
|
-
}
|
|
2914
|
-
/**
|
|
2915
|
-
* Sets default options for mutations whose mutation key partially matches the given
|
|
2916
|
-
* `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
|
|
2917
|
-
* matters when several registered defaults match the same mutation key.
|
|
2918
|
-
*
|
|
2919
|
-
* @see {@link QueryClient#getMutationDefaults}
|
|
2920
|
-
* @example
|
|
2921
|
-
* ```ts
|
|
2922
|
-
* queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })
|
|
2923
|
-
* ```
|
|
2924
|
-
*/
|
|
2925
|
-
setMutationDefaults(mutationKey, options) {
|
|
2926
|
-
this.#mutationDefaults.set(hashKey(mutationKey), {
|
|
2927
|
-
mutationKey,
|
|
2928
|
-
defaultOptions: options
|
|
2929
|
-
});
|
|
2930
|
-
}
|
|
2931
|
-
/**
|
|
2932
|
-
* Returns the default options registered for mutations whose mutation key partially matches
|
|
2933
|
-
* the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
|
|
2934
|
-
* defaults match, they are merged together in registration order.
|
|
2935
|
-
*
|
|
2936
|
-
* @example
|
|
2937
|
-
* ```ts
|
|
2938
|
-
* const defaultOptions = queryClient.getMutationDefaults(['addPost'])
|
|
2939
|
-
* ```
|
|
2940
|
-
*/
|
|
2941
|
-
getMutationDefaults(mutationKey) {
|
|
2942
|
-
const defaults = [...this.#mutationDefaults.values()];
|
|
2943
|
-
const result = {};
|
|
2944
|
-
defaults.forEach((queryDefault) => {
|
|
2945
|
-
if (partialMatchKey(mutationKey, queryDefault.mutationKey)) Object.assign(result, queryDefault.defaultOptions);
|
|
2946
|
-
});
|
|
2947
|
-
return result;
|
|
2948
|
-
}
|
|
2949
|
-
/**
|
|
2950
|
-
* Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
|
|
2951
|
-
* caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the
|
|
2952
|
-
* given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options
|
|
2953
|
-
* on top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
2954
|
-
*/
|
|
2955
|
-
defaultQueryOptions(options) {
|
|
2956
|
-
if (options._defaulted) return options;
|
|
2957
|
-
const defaultedOptions = {
|
|
2958
|
-
...this.#defaultOptions.queries,
|
|
2959
|
-
...this.getQueryDefaults(options.queryKey),
|
|
2960
|
-
...options,
|
|
2961
|
-
_defaulted: true
|
|
2962
|
-
};
|
|
2963
|
-
if (!defaultedOptions.queryHash) defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
|
|
2964
|
-
if (defaultedOptions.refetchOnReconnect === void 0) defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always";
|
|
2965
|
-
if (defaultedOptions.throwOnError === void 0) defaultedOptions.throwOnError = !!defaultedOptions.suspense;
|
|
2966
|
-
if (!defaultedOptions.networkMode && defaultedOptions.persister) defaultedOptions.networkMode = "offlineFirst";
|
|
2967
|
-
if (defaultedOptions.queryFn === skipToken) defaultedOptions.enabled = false;
|
|
2968
|
-
return defaultedOptions;
|
|
2969
|
-
}
|
|
2970
|
-
/**
|
|
2971
|
-
* The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
|
|
2972
|
-
* adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the
|
|
2973
|
-
* given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options
|
|
2974
|
-
* on top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
2975
|
-
*/
|
|
2976
|
-
defaultMutationOptions(options) {
|
|
2977
|
-
if (options?._defaulted) return options;
|
|
2978
|
-
return {
|
|
2979
|
-
...this.#defaultOptions.mutations,
|
|
2980
|
-
...options?.mutationKey && this.getMutationDefaults(options.mutationKey),
|
|
2981
|
-
...options,
|
|
2982
|
-
_defaulted: true
|
|
2983
|
-
};
|
|
2984
|
-
}
|
|
2985
|
-
/**
|
|
2986
|
-
* Clears both the query cache and the mutation cache this client is connected to.
|
|
2987
|
-
*
|
|
2988
|
-
* @example
|
|
2989
|
-
* ```ts
|
|
2990
|
-
* import { QueryClient } from '@tanstack/query-core'
|
|
2991
|
-
*
|
|
2992
|
-
* const queryClient = new QueryClient()
|
|
2993
|
-
* queryClient.clear()
|
|
2994
|
-
* ```
|
|
2995
|
-
*/
|
|
2996
|
-
clear() {
|
|
2997
|
-
this.#queryCache.clear();
|
|
2998
|
-
this.#mutationCache.clear();
|
|
2999
|
-
}
|
|
3000
|
-
};
|
|
3001
|
-
//#endregion
|
|
3002
|
-
//#region ../../node_modules/.pnpm/@tanstack+react-query@5.103.1_react@19.2.7/node_modules/@tanstack/react-query/build/modern/queryOptions.js
|
|
3003
|
-
function queryOptions(options) {
|
|
3004
|
-
return options;
|
|
3005
|
-
}
|
|
3006
|
-
//#endregion
|
|
3007
|
-
//#region src/lib/capabilities.ts
|
|
3008
|
-
var NONE = {
|
|
3009
|
-
canManageGrants: false,
|
|
3010
|
-
canReadAudit: false,
|
|
3011
|
-
canCreateProject: false
|
|
3012
|
-
};
|
|
3013
|
-
function deriveUiCapabilities(me, projects) {
|
|
3014
|
-
if (me === null) return NONE;
|
|
3015
|
-
const canManageInstance = me.instanceRole === "owner" || me.instanceRole === "root-admin";
|
|
3016
|
-
return {
|
|
3017
|
-
canManageGrants: canManageInstance,
|
|
3018
|
-
canReadAudit: me.canReadAudit,
|
|
3019
|
-
canCreateProject: canManageInstance
|
|
3020
|
-
};
|
|
3021
|
-
}
|
|
3022
|
-
/** Secret values are available only where the API reports secret.read. */
|
|
3023
|
-
function canRevealSecrets(permissions) {
|
|
3024
|
-
return permissions.includes("secret.read");
|
|
3025
|
-
}
|
|
3026
|
-
//#endregion
|
|
3027
|
-
//#region src/lib/coffre.ts
|
|
3028
|
-
/**
|
|
3029
|
-
* The API as whoever is looking at the page. In the browser this is plain
|
|
3030
|
-
* `fetch` to `/api`, carrying the session cookie; mutations call it straight
|
|
3031
|
-
* from event handlers, and loaders read through `context.client`.
|
|
3032
|
-
*/
|
|
3033
|
-
function useCoffre() {
|
|
3034
|
-
return useRouter().options.context.client;
|
|
3035
|
-
}
|
|
3036
|
-
/** A refusal the page words itself, shown as it is. */
|
|
3037
|
-
var Refusal = class extends Error {};
|
|
3038
|
-
/** The HTTP status of an API error; undefined when the request never got an answer. */
|
|
3039
|
-
function statusOf(error) {
|
|
3040
|
-
return error instanceof CoffreError ? error.status : void 0;
|
|
3041
|
-
}
|
|
3042
|
-
/** What to tell the person when a call fails. */
|
|
3043
|
-
function failureMessage(error) {
|
|
3044
|
-
if (error instanceof Refusal) return error.message;
|
|
3045
|
-
if (!(error instanceof CoffreError)) return "The request could not be sent. Nothing was changed.";
|
|
3046
|
-
if (error.status === 401) return "Your session has ended. Sign in again, then retry.";
|
|
3047
|
-
if (error.code === "cross_origin") return "coffre refused a change that did not come from this page. Reload, then retry.";
|
|
3048
|
-
if (error.status === 403) return "You hold no grant that covers this. Someone with grant.manage on the project can add one.";
|
|
3049
|
-
if (error.status === 404) return "Not found. It may have been renamed or archived.";
|
|
3050
|
-
if (error.status === 400 || error.status === 409) return error.message;
|
|
3051
|
-
return "coffre is unavailable. Nothing was read or written.";
|
|
3052
|
-
}
|
|
3053
|
-
function uiFailure(error) {
|
|
3054
|
-
return {
|
|
3055
|
-
ok: false,
|
|
3056
|
-
error: failureMessage(error),
|
|
3057
|
-
signedOut: statusOf(error) === 401
|
|
3058
|
-
};
|
|
3059
|
-
}
|
|
3060
|
-
/** A loader's answer: what it read, or what to say instead. */
|
|
3061
|
-
async function uiResult(operation) {
|
|
3062
|
-
try {
|
|
3063
|
-
return {
|
|
3064
|
-
ok: true,
|
|
3065
|
-
...await operation()
|
|
3066
|
-
};
|
|
3067
|
-
} catch (error) {
|
|
3068
|
-
return uiFailure(error);
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
/** How the API names a member: `user:ada@acme.example`, `token:ci-deploy`. */
|
|
3072
|
-
function memberRef(principalType, principalId) {
|
|
3073
|
-
return `${principalType === "user" ? "user" : "token"}:${principalId}`;
|
|
3074
|
-
}
|
|
3075
|
-
//#endregion
|
|
3076
|
-
//#region src/lib/queries.ts
|
|
3077
|
-
/**
|
|
3078
|
-
* Every read the pages make, cached by TanStack Query: one cache per request
|
|
3079
|
-
* on the server, whose reads the page carries to the browser's, and one in the
|
|
3080
|
-
* browser for the whole visit.
|
|
3081
|
-
*
|
|
3082
|
-
* How fresh a page is. A read is reused for `FRESH_MS`, refetched when the
|
|
3083
|
-
* window regains focus, and refetched at once by any change made here, which
|
|
3084
|
-
* names what it touches (`affects`), so your own changes always show.
|
|
3085
|
-
* Someone else's change shows within that window. Nothing is decided on a
|
|
3086
|
-
* cached read: the server authorizes every call, so a stale screen can offer
|
|
3087
|
-
* an action the server then refuses, never grant one. The audit log and the
|
|
3088
|
-
* chain's verification are the exception, read fresh on every visit: their
|
|
3089
|
-
* whole point is to be current.
|
|
3090
|
-
*/
|
|
3091
|
-
var FRESH_MS = 1e4;
|
|
3092
|
-
function createQueryClient() {
|
|
3093
|
-
return new QueryClient({ defaultOptions: { queries: {
|
|
3094
|
-
staleTime: FRESH_MS,
|
|
3095
|
-
refetchOnWindowFocus: true,
|
|
3096
|
-
retry: false
|
|
3097
|
-
} } });
|
|
3098
|
-
}
|
|
3099
|
-
/**
|
|
3100
|
-
* The keys, which `affects` names too. A project's keys start with it, so
|
|
3101
|
-
* one invalidation covers everything read under it.
|
|
3102
|
-
*/
|
|
3103
|
-
var keys = {
|
|
3104
|
-
me: ["me"],
|
|
3105
|
-
auth: ["auth"],
|
|
3106
|
-
projects: ["projects"],
|
|
3107
|
-
grants: (project) => ["grants", project],
|
|
3108
|
-
secrets: ({ project, environment }) => [
|
|
3109
|
-
"secrets",
|
|
3110
|
-
project,
|
|
3111
|
-
environment
|
|
3112
|
-
],
|
|
3113
|
-
directory: ["directory"],
|
|
3114
|
-
report: (member) => ["report", member],
|
|
3115
|
-
credentials: (member) => ["credentials", member],
|
|
3116
|
-
bindings: (member) => ["bindings", member],
|
|
3117
|
-
identities: ["identities"],
|
|
3118
|
-
sessions: ["sessions"],
|
|
3119
|
-
audit: ["audit"]
|
|
3120
|
-
};
|
|
3121
|
-
/** One member's grants, as rows. */
|
|
3122
|
-
function grantRows(members) {
|
|
3123
|
-
return members.flatMap((member) => member.grants.map((grant) => ({
|
|
3124
|
-
id: grant.id,
|
|
3125
|
-
principalType: member.principalType,
|
|
3126
|
-
principalId: member.principalId,
|
|
3127
|
-
role: grant.role,
|
|
3128
|
-
roleName: grant.roleName,
|
|
3129
|
-
permissions: grant.permissions,
|
|
3130
|
-
scope: grant.environment === null ? "project" : "environment",
|
|
3131
|
-
environmentSlug: grant.environment,
|
|
3132
|
-
expiresAt: grant.expiresAt
|
|
3133
|
-
})));
|
|
3134
|
-
}
|
|
3135
|
-
function listDirectory(client) {
|
|
3136
|
-
return uiResult(async () => {
|
|
3137
|
-
const { members, removed } = await client.members.list();
|
|
3138
|
-
return {
|
|
3139
|
-
principals: members.map(({ principalType, principalId, instanceRole, isRootAdmin, tampered }) => ({
|
|
3140
|
-
principalType,
|
|
3141
|
-
principalId,
|
|
3142
|
-
instanceRole,
|
|
3143
|
-
isRootAdmin,
|
|
3144
|
-
tampered
|
|
3145
|
-
})),
|
|
3146
|
-
removed
|
|
3147
|
-
};
|
|
3148
|
-
});
|
|
3149
|
-
}
|
|
3150
|
-
var readProjects = (client) => uiResult(() => client.projects.list());
|
|
3151
|
-
var queries = {
|
|
3152
|
-
/** Who is looking; null when nobody is signed in. */
|
|
3153
|
-
me: (client) => queryOptions({
|
|
3154
|
-
queryKey: keys.me,
|
|
3155
|
-
queryFn: async () => {
|
|
3156
|
-
try {
|
|
3157
|
-
return await client.me();
|
|
3158
|
-
} catch (error) {
|
|
3159
|
-
if (statusOf(error) === 401) return null;
|
|
3160
|
-
throw error;
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
3163
|
-
}),
|
|
3164
|
-
/** How this instance signs people in. */
|
|
3165
|
-
auth: (client) => queryOptions({
|
|
3166
|
-
queryKey: keys.auth,
|
|
3167
|
-
queryFn: () => client.auth()
|
|
3168
|
-
}),
|
|
3169
|
-
/** The projects you can see, each with its distinct secret count. */
|
|
3170
|
-
projects: (client) => queryOptions({
|
|
3171
|
-
queryKey: keys.projects,
|
|
3172
|
-
queryFn: () => readProjects(client)
|
|
3173
|
-
}),
|
|
3174
|
-
/** Who holds what in a project, for those who manage its access. */
|
|
3175
|
-
grants: (client, project) => queryOptions({
|
|
3176
|
-
queryKey: keys.grants(project),
|
|
3177
|
-
queryFn: () => uiResult(async () => ({ grants: grantRows((await client.members.list(project)).members) }))
|
|
3178
|
-
}),
|
|
3179
|
-
secrets: (client, place) => queryOptions({
|
|
3180
|
-
queryKey: keys.secrets(place),
|
|
3181
|
-
queryFn: () => uiResult(() => client.secrets.list(`${place.project}/${place.environment}`))
|
|
3182
|
-
}),
|
|
3183
|
-
/**
|
|
3184
|
-
* Everyone in the directory, and who was removed. The API shows grant
|
|
3185
|
-
* managers the members of their projects; the directory pages stay the
|
|
3186
|
-
* owners' own, and asking for anyone else would only log a refusal, so
|
|
3187
|
-
* nobody else is asked.
|
|
3188
|
-
*/
|
|
3189
|
-
directory: (client, owner) => queryOptions({
|
|
3190
|
-
queryKey: [...keys.directory, { owner }],
|
|
3191
|
-
queryFn: () => owner ? listDirectory(client) : Promise.resolve({
|
|
3192
|
-
ok: false,
|
|
3193
|
-
error: "Only owners can manage users and service accounts.",
|
|
3194
|
-
signedOut: false
|
|
3195
|
-
})
|
|
3196
|
-
}),
|
|
3197
|
-
/** What one member can reach and has seen; null for anyone but owners, who alone may ask. */
|
|
3198
|
-
report: (client, member, owner) => queryOptions({
|
|
3199
|
-
queryKey: [...keys.report(member), { owner }],
|
|
3200
|
-
queryFn: () => owner ? uiResult(async () => {
|
|
3201
|
-
try {
|
|
3202
|
-
return { report: await client.members.get(member) };
|
|
3203
|
-
} catch (error) {
|
|
3204
|
-
if (statusOf(error) === 404) return { report: null };
|
|
3205
|
-
throw error;
|
|
3206
|
-
}
|
|
3207
|
-
}) : Promise.resolve(null)
|
|
3208
|
-
}),
|
|
3209
|
-
/**
|
|
3210
|
-
* A token's credentials; null where they cannot be listed. Only owners
|
|
3211
|
-
* issue and see them, and only coffre's own sign-in issues any.
|
|
3212
|
-
*/
|
|
3213
|
-
credentials: (client, member, allowed) => queryOptions({
|
|
3214
|
-
queryKey: [...keys.credentials(member), { allowed }],
|
|
3215
|
-
queryFn: () => allowed ? uiResult(() => client.tokens.list(member)) : Promise.resolve(null)
|
|
3216
|
-
}),
|
|
3217
|
-
/**
|
|
3218
|
-
* A token's trust bindings: the CI runs that may sign in as it. Null for
|
|
3219
|
-
* anyone but an owner; a failure where the deployment trusts no workloads,
|
|
3220
|
-
* which the page reads as nothing to show. Whether it does is not public.
|
|
3221
|
-
*/
|
|
3222
|
-
bindings: (client, member, allowed) => queryOptions({
|
|
3223
|
-
queryKey: [...keys.bindings(member), { allowed }],
|
|
3224
|
-
queryFn: () => allowed ? uiResult(() => client.bindings.list(member)) : Promise.resolve(null)
|
|
3225
|
-
}),
|
|
3226
|
-
/** The accounts you sign in with, under coffre's own sign-in. */
|
|
3227
|
-
identities: (client) => queryOptions({
|
|
3228
|
-
queryKey: keys.identities,
|
|
3229
|
-
queryFn: () => uiResult(() => client.identities.list())
|
|
3230
|
-
}),
|
|
3231
|
-
/** Where you are signed in, under coffre's own sign-in. */
|
|
3232
|
-
sessions: (client) => queryOptions({
|
|
3233
|
-
queryKey: keys.sessions,
|
|
3234
|
-
queryFn: () => uiResult(() => client.sessions.list())
|
|
3235
|
-
}),
|
|
3236
|
-
/** A page of the log, as filtered: always read fresh. */
|
|
3237
|
-
auditEntries: (client, search) => queryOptions({
|
|
3238
|
-
queryKey: [
|
|
3239
|
-
...keys.audit,
|
|
3240
|
-
"entries",
|
|
3241
|
-
search
|
|
3242
|
-
],
|
|
3243
|
-
staleTime: 0,
|
|
3244
|
-
queryFn: () => uiResult(() => client.audit.list({
|
|
3245
|
-
limit: 200,
|
|
3246
|
-
decision: search.decision,
|
|
3247
|
-
actor: search.actorId,
|
|
3248
|
-
detail: search.detail
|
|
3249
|
-
}))
|
|
3250
|
-
}),
|
|
3251
|
-
/**
|
|
3252
|
-
* Whether the log holds: verified on every visit, and never waited for.
|
|
3253
|
-
* It re-reads the whole log, so it takes as long as the log is long; the
|
|
3254
|
-
* page shows the entries first and the verdict when it comes.
|
|
3255
|
-
*/
|
|
3256
|
-
auditChain: (client) => queryOptions({
|
|
3257
|
-
queryKey: [...keys.audit, "chain"],
|
|
3258
|
-
staleTime: 0,
|
|
3259
|
-
queryFn: () => verifyChain(client)
|
|
3260
|
-
})
|
|
3261
|
-
};
|
|
3262
|
-
/**
|
|
3263
|
-
* Whether the log holds, or why that is not known. Verifying is for owners:
|
|
3264
|
-
* anyone else reads their projects' part of the log, and a part cannot be
|
|
3265
|
-
* checked as a chain, so for them it is a fact about the page, not a fault.
|
|
3266
|
-
*/
|
|
3267
|
-
async function verifyChain(client) {
|
|
3268
|
-
try {
|
|
3269
|
-
const result = await client.audit.verify();
|
|
3270
|
-
return result.ok ? {
|
|
3271
|
-
integrity: "intact",
|
|
3272
|
-
through: result.through,
|
|
3273
|
-
entries: result.entries,
|
|
3274
|
-
checkpoint: result.checkpoint,
|
|
3275
|
-
pending: result.pending ?? 0
|
|
3276
|
-
} : {
|
|
3277
|
-
integrity: "broken",
|
|
3278
|
-
through: result.through,
|
|
3279
|
-
failedAtSeq: result.failedAtSeq,
|
|
3280
|
-
author: result.author,
|
|
3281
|
-
reason: result.reason
|
|
3282
|
-
};
|
|
3283
|
-
} catch (error) {
|
|
3284
|
-
const status = statusOf(error);
|
|
3285
|
-
if (status === 403) return { integrity: "owners-only" };
|
|
3286
|
-
return {
|
|
3287
|
-
integrity: "unknown",
|
|
3288
|
-
problem: status === void 0 ? "the request never got an answer" : `the request failed with HTTP ${status}`
|
|
3289
|
-
};
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
/**
|
|
3293
|
-
* Who is looking, how this instance signs people in, and the projects they
|
|
3294
|
-
* can see: what the shell needs on every screen. For someone signed out or
|
|
3295
|
-
* not yet a member the project list is refused, and they get the sign-in or
|
|
3296
|
-
* closed-door page.
|
|
3297
|
-
*/
|
|
3298
|
-
function shellOf(auth, me, projects) {
|
|
3299
|
-
const listed = projects.ok ? projects.projects : [];
|
|
3300
|
-
const member = me?.registered === true ? me : null;
|
|
3301
|
-
return {
|
|
3302
|
-
auth,
|
|
3303
|
-
principal: me === null ? null : me.principal,
|
|
3304
|
-
instanceRole: member?.instanceRole ?? null,
|
|
3305
|
-
projects: listed,
|
|
3306
|
-
capabilities: deriveUiCapabilities(member, listed),
|
|
3307
|
-
registrationRequired: me !== null && !me.registered,
|
|
3308
|
-
/** The deployment's version and migrations: told to owners and root admins only. */
|
|
3309
|
-
instance: member?.instance ?? null,
|
|
3310
|
-
/** A member the vault refuses: their record failed its integrity check. */
|
|
3311
|
-
accessTampered: me?.tampered === true
|
|
3312
|
-
};
|
|
3313
|
-
}
|
|
3314
|
-
/**
|
|
3315
|
-
* The shell, as every loader reads it: from the cache while fresh, so a
|
|
3316
|
-
* child route never asks again for what the root has.
|
|
3317
|
-
*/
|
|
3318
|
-
async function loadShell(queryClient, client) {
|
|
3319
|
-
const [auth, me, projects] = await Promise.all([
|
|
3320
|
-
queryClient.fetchQuery(queries.auth(client)),
|
|
3321
|
-
queryClient.fetchQuery(queries.me(client)),
|
|
3322
|
-
queryClient.fetchQuery(queries.projects(client))
|
|
3323
|
-
]);
|
|
3324
|
-
return shellOf(auth, me, projects);
|
|
3325
|
-
}
|
|
3326
|
-
/**
|
|
3327
|
-
* One project and, when you manage its access, its grants. A project that is
|
|
3328
|
-
* not there for you fails with no message: the page words that itself.
|
|
3329
|
-
*/
|
|
3330
|
-
function projectOf(projects, slug) {
|
|
3331
|
-
if (!projects.ok) return projects;
|
|
3332
|
-
const project = projects.projects.find((entry) => entry.slug === slug);
|
|
3333
|
-
if (project === void 0) return {
|
|
3334
|
-
ok: false,
|
|
3335
|
-
error: null
|
|
3336
|
-
};
|
|
3337
|
-
return {
|
|
3338
|
-
ok: true,
|
|
3339
|
-
project,
|
|
3340
|
-
managesAccess: project.permissions.includes("grant.manage")
|
|
3341
|
-
};
|
|
3342
|
-
}
|
|
3343
|
-
/** What a project page reads: the project list, and its grants when you manage them. */
|
|
3344
|
-
async function loadProject(queryClient, client, slug) {
|
|
3345
|
-
const found = projectOf(await queryClient.fetchQuery(queries.projects(client)), slug);
|
|
3346
|
-
if (found.ok && found.managesAccess) await queryClient.fetchQuery(queries.grants(client, slug));
|
|
3347
|
-
}
|
|
3348
|
-
/** The directory pages' read: the directory, for owners. */
|
|
3349
|
-
async function loadDirectory(queryClient, client) {
|
|
3350
|
-
const shell = await loadShell(queryClient, client);
|
|
3351
|
-
return queryClient.fetchQuery(queries.directory(client, shell.capabilities.canManageGrants));
|
|
3352
|
-
}
|
|
3353
|
-
/**
|
|
3354
|
-
* Everything one user's or token's page reads: the report (owners only), the
|
|
3355
|
-
* grants of every project where you manage access, and a token's
|
|
3356
|
-
* credentials. There is no "grants of this member" call, so each project you
|
|
3357
|
-
* manage is asked for its grants and the page keeps this member's. Projects
|
|
3358
|
-
* where you do not hold grant.manage are skipped rather than asked: the
|
|
3359
|
-
* refusal would land in the audit log as a denial in your name.
|
|
3360
|
-
*/
|
|
3361
|
-
async function loadPrincipal(queryClient, client, principalType, principalId) {
|
|
3362
|
-
const shell = await loadShell(queryClient, client);
|
|
3363
|
-
const member = memberRef(principalType, principalId);
|
|
3364
|
-
const owner = shell.capabilities.canManageGrants;
|
|
3365
|
-
await Promise.all([
|
|
3366
|
-
queryClient.fetchQuery(queries.report(client, member, owner)),
|
|
3367
|
-
principalType === "service" ? queryClient.fetchQuery(queries.credentials(client, member, owner && shell.auth.signin !== null)) : null,
|
|
3368
|
-
principalType === "service" ? queryClient.fetchQuery(queries.bindings(client, member, owner && shell.auth.signin !== null)) : null,
|
|
3369
|
-
...managedProjects(shell.projects).map((project) => queryClient.fetchQuery(queries.grants(client, project.slug)))
|
|
3370
|
-
]);
|
|
3371
|
-
}
|
|
3372
|
-
function managedProjects(projects) {
|
|
3373
|
-
return projects.filter((project) => project.permissions.includes("grant.manage"));
|
|
3374
|
-
}
|
|
3375
|
-
/**
|
|
3376
|
-
* What each change touches, which `useAction` refetches when it lands. Every
|
|
3377
|
-
* change also lands in the audit log, which is always read fresh.
|
|
3378
|
-
*/
|
|
3379
|
-
var affects = {
|
|
3380
|
-
/** A project or environment made, renamed or archived: the tree, and where you hold access. */
|
|
3381
|
-
places: () => [keys.projects, keys.me],
|
|
3382
|
-
/** Secrets written, renamed, restored or archived: the environment and the counts. */
|
|
3383
|
-
secrets: (place) => [keys.secrets(place), keys.projects],
|
|
3384
|
-
/**
|
|
3385
|
-
* Someone's access in a project changed: its grants, their report, and, as
|
|
3386
|
-
* it may be your own, what you can see.
|
|
3387
|
-
*/
|
|
3388
|
-
access: (project, member) => [
|
|
3389
|
-
keys.grants(project),
|
|
3390
|
-
keys.report(member),
|
|
3391
|
-
keys.projects,
|
|
3392
|
-
keys.me
|
|
3393
|
-
],
|
|
3394
|
-
/** Someone let in: the directory. */
|
|
3395
|
-
admission: () => [keys.directory],
|
|
3396
|
-
/**
|
|
3397
|
-
* An instance role changed: the directory, their report, and, as it may be
|
|
3398
|
-
* your own, what you can see and do.
|
|
3399
|
-
*/
|
|
3400
|
-
role: (member) => [
|
|
3401
|
-
keys.directory,
|
|
3402
|
-
keys.report(member),
|
|
3403
|
-
keys.me,
|
|
3404
|
-
keys.projects
|
|
3405
|
-
],
|
|
3406
|
-
/** Someone removed: the directory, their report, and every project's grants, which removal ends. */
|
|
3407
|
-
removal: (member) => [
|
|
3408
|
-
keys.directory,
|
|
3409
|
-
keys.report(member),
|
|
3410
|
-
["grants"]
|
|
3411
|
-
],
|
|
3412
|
-
credentials: (member) => [keys.credentials(member)],
|
|
3413
|
-
bindings: (member) => [keys.bindings(member)],
|
|
3414
|
-
/** Unlinking an account also ends the sessions it signed in. */
|
|
3415
|
-
identities: () => [keys.identities, keys.sessions],
|
|
3416
|
-
sessions: () => [keys.sessions]
|
|
3417
|
-
};
|
|
3418
|
-
/**
|
|
3419
|
-
* Refetch what a change touched: at once where it is on screen, on next use
|
|
3420
|
-
* elsewhere. Every change lands in the audit log, so the log and its
|
|
3421
|
-
* verification are always among them.
|
|
3422
|
-
*/
|
|
3423
|
-
async function refresh(queryClient, touched) {
|
|
3424
|
-
await Promise.all([...touched, keys.audit].map((queryKey) => queryClient.invalidateQueries({ queryKey })));
|
|
3425
|
-
}
|
|
3426
|
-
//#endregion
|
|
3427
|
-
//#region src/components/tile.tsx
|
|
3428
|
-
var import_jsx_runtime = require_jsx_runtime();
|
|
3429
|
-
var HUES = [
|
|
3430
|
-
"blue",
|
|
3431
|
-
"green",
|
|
3432
|
-
"amber",
|
|
3433
|
-
"violet"
|
|
3434
|
-
];
|
|
3435
|
-
/** The same name always lands on the same tint, on every screen (FNV-1a). */
|
|
3436
|
-
function tileHue(name) {
|
|
3437
|
-
let hash = 2166136261;
|
|
3438
|
-
for (const char of name) hash = Math.imul(hash ^ char.charCodeAt(0), 16777619) >>> 0;
|
|
3439
|
-
return HUES[hash % HUES.length];
|
|
3440
|
-
}
|
|
3441
|
-
/**
|
|
3442
|
-
* A letter on a tint, standing in for a project wherever its name appears.
|
|
3443
|
-
*
|
|
3444
|
-
* It is a recognition aid, not information: the name is always beside it, so
|
|
3445
|
-
* the tile is hidden from assistive technology.
|
|
3446
|
-
*/
|
|
3447
|
-
function Tile({ name, size = "sm" }) {
|
|
3448
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3449
|
-
className: `tile tile-${tileHue(name)}${size === "lg" ? " tile-lg" : ""}`,
|
|
3450
|
-
"aria-hidden": true,
|
|
3451
|
-
children: name.slice(0, 1)
|
|
3452
|
-
});
|
|
3453
|
-
}
|
|
3454
|
-
//#endregion
|
|
3455
|
-
//#region src/components/page.tsx
|
|
3456
|
-
/**
|
|
3457
|
-
* The head of every page: an optional project tile, the title with a muted
|
|
3458
|
-
* aside, one line of description or facts, and the page's own actions.
|
|
3459
|
-
*
|
|
3460
|
-
* Where you are is already in the top bar's path, so the head does not repeat
|
|
3461
|
-
* it; it says what this page is.
|
|
3462
|
-
*/
|
|
3463
|
-
function PageHeader({ tile, lead, title, aside, description, meta, actions }) {
|
|
3464
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
|
|
3465
|
-
className: "page-head",
|
|
3466
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3467
|
-
className: "page-head-text",
|
|
3468
|
-
children: [
|
|
3469
|
-
tile !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tile, {
|
|
3470
|
-
name: tile,
|
|
3471
|
-
size: "lg"
|
|
3472
|
-
}),
|
|
3473
|
-
lead,
|
|
3474
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3475
|
-
style: { minWidth: 0 },
|
|
3476
|
-
children: [
|
|
3477
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h1", {
|
|
3478
|
-
className: "page-title",
|
|
3479
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: title }), aside !== void 0 && aside !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3480
|
-
className: "page-title-aside",
|
|
3481
|
-
children: aside
|
|
3482
|
-
})]
|
|
3483
|
-
}),
|
|
3484
|
-
description !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3485
|
-
className: "page-desc",
|
|
3486
|
-
children: description
|
|
3487
|
-
}),
|
|
3488
|
-
meta !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3489
|
-
className: "page-meta",
|
|
3490
|
-
children: meta
|
|
3491
|
-
})
|
|
3492
|
-
]
|
|
3493
|
-
})
|
|
3494
|
-
]
|
|
3495
|
-
}), actions !== void 0 && actions !== false && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3496
|
-
className: "page-actions",
|
|
3497
|
-
children: actions
|
|
3498
|
-
})]
|
|
3499
|
-
});
|
|
3500
|
-
}
|
|
3501
|
-
/** A bordered panel with a titled head; tables inside it run edge to edge. */
|
|
3502
|
-
function Card({ title, description, actions, children, labelledBy, tone }) {
|
|
3503
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
|
|
3504
|
-
className: `card${tone === "danger" ? " card-danger" : ""}`,
|
|
3505
|
-
"aria-labelledby": labelledBy,
|
|
3506
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3507
|
-
className: "card-head",
|
|
3508
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
|
|
3509
|
-
className: "card-title",
|
|
3510
|
-
id: labelledBy,
|
|
3511
|
-
children: title
|
|
3512
|
-
}), description !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3513
|
-
className: "card-desc",
|
|
3514
|
-
children: description
|
|
3515
|
-
})] }), actions]
|
|
3516
|
-
}), children]
|
|
3517
|
-
});
|
|
3518
|
-
}
|
|
3519
|
-
/** One labelled fact in a card's `dl.facts`. */
|
|
3520
|
-
function Fact({ label, children }) {
|
|
3521
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3522
|
-
className: "fact",
|
|
3523
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: label }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children })]
|
|
3524
|
-
});
|
|
3525
|
-
}
|
|
3526
|
-
/**
|
|
3527
|
-
* A page that cannot be shown: no access, no such thing, or no session.
|
|
3528
|
-
*
|
|
3529
|
-
* It says which page, why in a sentence, and offers the one useful way out.
|
|
3530
|
-
*/
|
|
3531
|
-
function ClosedDoor({ icon, label, title, children, actions }) {
|
|
3532
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3533
|
-
className: "closed",
|
|
3534
|
-
role: "status",
|
|
3535
|
-
children: [
|
|
3536
|
-
icon !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3537
|
-
className: "closed-icon",
|
|
3538
|
-
"aria-hidden": true,
|
|
3539
|
-
children: icon
|
|
3540
|
-
}),
|
|
3541
|
-
label !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3542
|
-
className: "closed-label",
|
|
3543
|
-
children: label
|
|
3544
|
-
}),
|
|
3545
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
|
|
3546
|
-
className: "closed-title",
|
|
3547
|
-
children: title
|
|
3548
|
-
}),
|
|
3549
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3550
|
-
className: "closed-body",
|
|
3551
|
-
children
|
|
3552
|
-
}),
|
|
3553
|
-
actions !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3554
|
-
className: "closed-actions",
|
|
3555
|
-
children: actions
|
|
3556
|
-
})
|
|
3557
|
-
]
|
|
3558
|
-
});
|
|
3559
|
-
}
|
|
3560
|
-
//#endregion
|
|
3561
|
-
export { isServer as A, timeoutManager as B, useCoffre as C, notifyManager as D, fetchState as E, replaceEqualDeep as F, createClient as H, resolveQueryValue as I, shallowEqualObjects as L, isValidTimeout as M, noop as N, focusManager as O, replaceData as P, shouldThrowError as R, uiResult as S, getDefaultState as T, planImport as U, CoffreError as V, shellOf as _, Tile as a, memberRef as b, keys as c, loadProject as d, loadShell as f, refresh as g, queries as h, PageHeader as i, hashKey as j, Subscribable as k, loadDirectory as l, projectOf as m, ClosedDoor as n, affects as o, managedProjects as p, Fact as r, createQueryClient as s, Card as t, loadPrincipal as u, Refusal as v, canRevealSecrets as w, statusOf as x, failureMessage as y, timeUntilStale as z };
|