gemi 0.128.0 → 0.130.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/dist/{chunk-0mp9tck6.js → chunk-0ryswty9.js} +20 -20
- package/dist/{chunk-0mp9tck6.js.map → chunk-0ryswty9.js.map} +5 -4
- package/dist/{chunk-df0mekds.js → chunk-13agap7z.js} +1 -1
- package/dist/{chunk-qz0da20r.js → chunk-7ynnce4b.js} +1 -1
- package/dist/{chunk-wzfvwvz0.js → chunk-jj1ppnnk.js} +2 -2
- package/dist/{chunk-wzfvwvz0.js.map → chunk-jj1ppnnk.js.map} +1 -1
- package/dist/{chunk-tchte4dv.js → chunk-xtqhagxz.js} +2 -2
- package/dist/{chunk-tchte4dv.js.map → chunk-xtqhagxz.js.map} +1 -1
- package/dist/chunks/MutationError-DuKqBW8o.js +199 -0
- package/dist/chunks/MutationError-DuKqBW8o.js.map +1 -0
- package/dist/chunks/RealtimeClient-DsWbFRC7.js +553 -0
- package/dist/chunks/RealtimeClient-DsWbFRC7.js.map +1 -0
- package/dist/chunks/{ThemeProvider-BIrCSrFY.js → ThemeProvider-gWqXjGh-.js} +173 -578
- package/dist/chunks/ThemeProvider-gWqXjGh-.js.map +1 -0
- package/dist/chunks/channelKey-CIhHpX6x.js +10 -0
- package/dist/chunks/channelKey-CIhHpX6x.js.map +1 -0
- package/dist/chunks/fetchFileRequest-BSrgYnAy.js +57 -0
- package/dist/chunks/fetchFileRequest-BSrgYnAy.js.map +1 -0
- package/dist/chunks/live-CUdMhXHL.js +88 -0
- package/dist/chunks/live-CUdMhXHL.js.map +1 -0
- package/dist/chunks/mutationExtras-CtY-X9m7.js +115 -0
- package/dist/chunks/mutationExtras-CtY-X9m7.js.map +1 -0
- package/dist/chunks/subscriptionStream-CULcRbx0.js +166 -0
- package/dist/chunks/subscriptionStream-CULcRbx0.js.map +1 -0
- package/dist/client/MutationError.d.ts +7 -9
- package/dist/client/MutationError.d.ts.map +1 -1
- package/dist/client/QueryResource.d.ts +3 -11
- package/dist/client/QueryResource.d.ts.map +1 -1
- package/dist/client/fetchFile.d.ts +4 -7
- package/dist/client/fetchFile.d.ts.map +1 -1
- package/dist/client/fetchFileRequest.d.ts +14 -0
- package/dist/client/fetchFileRequest.d.ts.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +201 -664
- package/dist/client/index.js.map +1 -1
- package/dist/client/init.d.ts +1 -1
- package/dist/client/init.d.ts.map +1 -1
- package/dist/client/lazyModule.d.ts +32 -0
- package/dist/client/lazyModule.d.ts.map +1 -0
- package/dist/client/mutationErrorHelpers.d.ts +11 -0
- package/dist/client/mutationErrorHelpers.d.ts.map +1 -0
- package/dist/client/mutationExtras.d.ts +3 -0
- package/dist/client/mutationExtras.d.ts.map +1 -0
- package/dist/client/mutationModules.d.ts +17 -0
- package/dist/client/mutationModules.d.ts.map +1 -0
- package/dist/client/queryUpdates.d.ts +22 -0
- package/dist/client/queryUpdates.d.ts.map +1 -0
- package/dist/client/realtime/FakeSocket.d.ts +1 -1
- package/dist/client/realtime/FakeSocket.d.ts.map +1 -1
- package/dist/client/realtime/RealtimeClient.d.ts +7 -18
- package/dist/client/realtime/RealtimeClient.d.ts.map +1 -1
- package/dist/client/realtime/channelKey.d.ts +4 -0
- package/dist/client/realtime/channelKey.d.ts.map +1 -0
- package/dist/client/realtime/live.d.ts +31 -0
- package/dist/client/realtime/live.d.ts.map +1 -0
- package/dist/client/realtime/loader.d.ts +56 -0
- package/dist/client/realtime/loader.d.ts.map +1 -0
- package/dist/client/realtime/useChannelSubscription.d.ts +1 -1
- package/dist/client/realtime/useChannelSubscription.d.ts.map +1 -1
- package/dist/client/subscriptionStream.d.ts +36 -0
- package/dist/client/subscriptionStream.d.ts.map +1 -0
- package/dist/client/useChannel.d.ts +1 -13
- package/dist/client/useChannel.d.ts.map +1 -1
- package/dist/client/useMutation.d.ts +1 -1
- package/dist/client/useMutation.d.ts.map +1 -1
- package/dist/client/useQuery.d.ts +1 -1
- package/dist/client/useQuery.d.ts.map +1 -1
- package/dist/client/useSetQueryData.d.ts +4 -17
- package/dist/client/useSetQueryData.d.ts.map +1 -1
- package/dist/client/useSubscription.d.ts +5 -10
- package/dist/client/useSubscription.d.ts.map +1 -1
- package/dist/facades/index.js +1 -1
- package/dist/http/index.js +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/kernel/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/services/broadcast/protocol.d.ts +1 -2
- package/dist/services/broadcast/protocol.d.ts.map +1 -1
- package/dist/services/broadcast/socketHeader.d.ts +9 -0
- package/dist/services/broadcast/socketHeader.d.ts.map +1 -0
- package/dist/services/index.js +2 -2
- package/dist/services/index.js.map +1 -1
- package/dist/testing/Page.d.ts.map +1 -1
- package/dist/testing/index.js +4 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/ThemeProvider-BIrCSrFY.js.map +0 -1
- /package/dist/{chunk-df0mekds.js.map → chunk-13agap7z.js.map} +0 -0
- /package/dist/{chunk-qz0da20r.js.map → chunk-7ynnce4b.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ba as y}from"./chunk-kk18xqgc.js";import{createElement as q}from"react";function z(i,n){let p=Object.keys(n).sort((s,g)=>g.length-s.length).map((s)=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),b=new RegExp(p.join("|"),"g");return i.replace(b,(s)=>n[s])}async function L(i,n,p=[],b){let s=[...p.map((t)=>`${i}/views/${t}.tsx`),b?`${i}/views/${b}.tsx`:`${i}/views/RootLayout.tsx`],g=new Set;for(let t of s){let u=n.moduleGraph.getModulesByFile(t);if(u)for(let x of u)g.add(x)}let e=[],l=[],r={};for(let t of g)if(t)for(let u of t.importedModules){if(u.file.includes("module.css"))r[u.file]=u.ssrTransformResult.map.sourcesContent.join("");if(u.file.includes(".css"))l.push(u.file)}for(let t of l){let u=await n.transformRequest(t+"?direct"),x=t.includes("module.css"),k="";if(x)k=z(r[t],u.default);e.push({isDev:!0,id:t,content:x?k:u.code})}return e.map((t,u)=>{return q("style",{key:u,type:"text/css","data-vite-dev-id":t.id,dangerouslySetInnerHTML:{__html:t.content}})})}async function _(i=[]){return i.map((n,p)=>{return q("style",{key:p,id:n?.id,type:"text/css",dangerouslySetInnerHTML:{__html:n.content}})})}import{existsSync as J}from"fs";import{basename as N}from"path";import{networkInterfaces as O}from"os";var v={name:"gemi",version:"0.
|
|
2
|
+
import{Ba as y}from"./chunk-kk18xqgc.js";import{createElement as q}from"react";function z(i,n){let p=Object.keys(n).sort((s,g)=>g.length-s.length).map((s)=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),b=new RegExp(p.join("|"),"g");return i.replace(b,(s)=>n[s])}async function L(i,n,p=[],b){let s=[...p.map((t)=>`${i}/views/${t}.tsx`),b?`${i}/views/${b}.tsx`:`${i}/views/RootLayout.tsx`],g=new Set;for(let t of s){let u=n.moduleGraph.getModulesByFile(t);if(u)for(let x of u)g.add(x)}let e=[],l=[],r={};for(let t of g)if(t)for(let u of t.importedModules){if(u.file.includes("module.css"))r[u.file]=u.ssrTransformResult.map.sourcesContent.join("");if(u.file.includes(".css"))l.push(u.file)}for(let t of l){let u=await n.transformRequest(t+"?direct"),x=t.includes("module.css"),k="";if(x)k=z(r[t],u.default);e.push({isDev:!0,id:t,content:x?k:u.code})}return e.map((t,u)=>{return q("style",{key:u,type:"text/css","data-vite-dev-id":t.id,dangerouslySetInnerHTML:{__html:t.content}})})}async function _(i=[]){return i.map((n,p)=>{return q("style",{key:p,id:n?.id,type:"text/css",dangerouslySetInnerHTML:{__html:n.content}})})}import{existsSync as J}from"fs";import{basename as N}from"path";import{networkInterfaces as O}from"os";var v={name:"gemi",version:"0.130.0",private:!1,license:"MIT",author:"Enes Tufekci <enes@gemijs.dev>",repository:{type:"git",url:"git+https://github.com/nstfkc/gemi.git",directory:"packages/gemi"},bin:{gemi:"./dist/bin/gemi.js","gemi-orm-generator":"./dist/bin/orm-generator.js"},files:["dist/**/*","ide/typescript-plugin/package.json","skills/**/*"],module:!0,exports:{"./http":"./http/index.ts","./client":"./client/index.ts","./ai":"./ai/index.ts","./ai/client":"./ai/client/index.ts","./testing":"./testing/index.ts","./app":"./app/index.ts","./facades":"./facades/index.ts","./email":"./email/index.ts","./vite":"./dist/vite/index.mjs","./kernel":"./kernel/index.ts","./services":"./services/index.ts","./i18n":"./i18n/index.ts","./dictionary":"./i18n/dictionaryRuntime.ts","./server":"./server/index.ts","./config":"./config/index.ts","./container":"./container/index.ts","./foundation":"./foundation/index.ts","./database":"./database/index.ts","./orm":"./orm/index.ts","./support":"./support/index.ts","./console/run":"./console/run.ts","./queue/work":"./services/queue/work.ts","./stats/route-table":"./stats/route-table.ts","./ide/typescript-plugin":"./ide/typescript-plugin/index.ts","./bun/preload":"./bun/preload.ts","./bun/plugin":"./bun/plugin.ts","./vitest":"./vitest/index.ts"},scripts:{lint:"oxlint",typecheck:"tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.browser.json && tsc --noEmit -p ide/typescript-plugin/tsconfig.json",build:"NODE_ENV=production bun run build:core && bun run build:bin && bun run build:types && bun run build:client && bun run build:plugin && bun run build:ts-plugin && bun run build:client-types && bun run build:augmentation","build:core":"bun ./scripts/build.ts","build:bin":"bun build --outdir=./dist/bin --target=bun --external=vite --external=react-dom --external=react/jsx-runtime --external=bun --external=sharp --external=@azure/storage-blob --external=typescript --sourcemap ./bin/gemi.ts ./bin/orm-generator.ts && bun ./scripts/prepare-bin.ts","build:client":"rm -rf dist/client dist/testing dist/ai/client dist/chunks && vite build -c vite.client.config.mts","build:plugin":"vite build -c vite.plugin.config.mts","build:ts-plugin":"bun ./scripts/build-ts-plugin.ts","build:types":"tsc -p tsconfig.build.json","build:client-types":"tsc -p tsconfig.browser.json",test:"bun --bun x vitest","test:types":"vitest run --typecheck.only","test:live":"bun --bun x vitest run ai/live","test:packaging":"bun --bun x vitest run --config vitest.packaging.config.ts","build:publish":"bun scripts/build-publish.ts",prepublishOnly:"echo 'Do not publish from this directory \u2014 its exports point at TS source. Run: bun run build:publish, then publish from .publish/' && exit 1","build:augmentation":"bun ./scripts/wire-augmentation.ts"},dependencies:{"@aws-sdk/client-s3":"^3.629.0","@aws-sdk/s3-request-presigner":"^3.629.0","ast-types":"^0.14.2",commander:"^12.1.0",history:"^5.3.0","jsx-email":"2.0.0-rc2.1","magic-string":"^0.30.17",open:"^10.1.0","react-error-boundary":"^6.0.0",recast:"^0.23.9",resend:"^6.12.3",satori:"^0.12.2","temporal-polyfill":"^0.2.5","twitter-api-v2":"^1.20.2","urlpattern-polyfill":"^10.0.0",uuid:"^9.0.1"},devDependencies:{"@babel/parser":"^7.25.4","@prisma/generator-helper":"^6.5.0","@repo/typescript-config":"*","@testing-library/react":"^16.3.2","@types/bun":"^1.3.14","@types/eslint":"^8.56.5","@types/node":"^20.11.24","@types/react":"^19.0.2","@types/react-dom":"^19.0.2",eslint:"^8.57.0",jsdom:"^30.0.1",oxlint:"^1.39.0",postgres:"^3.4.5",react:"19.2.3","react-dom":"19.2.3",typescript:"^5.7.3",vitest:"^4.0.0"},peerDependencies:{"@azure/storage-blob":"^12.28.0",react:">=19","react-dom":">=19",sharp:"^0.34.2",typescript:">=5",vite:"^8.0.0",postgres:"^3.4.0"},peerDependenciesMeta:{"@azure/storage-blob":{optional:!0},typescript:{optional:!0},postgres:{optional:!0}}};var Q=[" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551","\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551","\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551","\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551"," \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D"],W=Boolean(process.stdout.isTTY)&&!process.env.NO_COLOR,c=(i,n)=>W?`\x1B[${i}m${n}\x1B[0m`:n,X=(i)=>c("1",i),d=(i)=>c("2",i),j=(i)=>c("36",i),Y=(i)=>c("32",i),Z=(i)=>c("35",i);function $(){return v.version??"?"}function f(i){for(let n of Object.values(O()))for(let p of n??[])if((p.family==="IPv4"||p.family===4)&&!p.internal)return`http://${p.address}:${i}`;return null}function H(i){return y(i).filter((n)=>J(n)).map((n)=>N(n))}function T(i){let{port:n,rootDir:p}=i,b=`http://localhost:${n}`,s=f(n),g=H(p),e=(r,t)=>` ${Y("\u279C")} ${X(r.padEnd(9))}${t}`,l=["",...Q.map((r)=>Z(r)),"",` ${d("gemi")} ${j(`v${$()}`)}`,"",e("Local:",j(b)),e("Network:",s?j(s):d("unavailable")),e("Env:",g.length?g.join(", "):d("none")),""];console.log(l.join(`
|
|
3
3
|
`))}function I(i=process.env.SERVER_IDLE_TIMEOUT){if(i===void 0||i.trim()==="")return 10;let n=Number(i.trim());if(!Number.isInteger(n)||n<0||n>255)throw Error(`SERVER_IDLE_TIMEOUT must be a whole number of seconds from 0 to 255 (0 disables the timeout), got ${JSON.stringify(i)}.`);return n}
|
|
4
4
|
export{L as R,_ as S,T,I as U};
|
|
5
5
|
|
|
6
|
-
//# debugId=
|
|
6
|
+
//# debugId=1F5F6DD3E5726AE964756E2164756E21
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
"/**\n * Bun's default, and what both servers use when `SERVER_IDLE_TIMEOUT` is unset.\n */\nexport const DEFAULT_SERVER_IDLE_TIMEOUT = 10;\n\n/**\n * The `idleTimeout` (seconds) both `gemi dev` and `gemi start` pass to\n * `Bun.serve`, from `SERVER_IDLE_TIMEOUT` (#787).\n *\n * One reader for both servers, so a long-poll that works under `gemi start`\n * also works under `gemi dev`. Before this, only `httpProd` read the variable\n * and the dev server always ran at Bun's 10 seconds.\n *\n * It is the time a connection may stay silent, a response that has not started\n * included, before Bun closes it; `0` disables it. It does not apply to an\n * upgraded websocket (the HMR relay included), which has its own\n * `websocket.idleTimeout`.\n *\n * Unset or blank means the default. Anything that is not a whole number from 0\n * to 255 (Bun's own limits) fails the boot with the variable's name, instead\n * of Bun's \"expects idleTimeout to be an integer\", which does not say where the\n * value came from.\n */\nexport function serverIdleTimeout(raw: string | undefined = process.env.SERVER_IDLE_TIMEOUT): number {\n if (raw === undefined || raw.trim() === \"\") return DEFAULT_SERVER_IDLE_TIMEOUT;\n\n const seconds = Number(raw.trim());\n if (!Number.isInteger(seconds) || seconds < 0 || seconds > 255) {\n throw new Error(\n `SERVER_IDLE_TIMEOUT must be a whole number of seconds from 0 to 255 ` +\n `(0 disables the timeout), got ${JSON.stringify(raw)}.`,\n );\n }\n return seconds;\n}\n"
|
|
8
8
|
],
|
|
9
9
|
"mappings": ";yCAAA,wBAAS,cAGT,SAAS,CAAc,CAAC,EAAc,EAAwC,CAC5E,IAAM,EAAc,OAAO,KAAK,CAAM,EACnC,KAAK,CAAC,EAAG,IAAM,EAAE,OAAS,EAAE,MAAM,EAClC,IAAI,CAAC,IAAQ,EAAI,QAAQ,sBAAuB,MAAM,CAAC,EAGpD,EAAQ,IAAI,OAA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AAQ,CAAI,CAAC,EAClC,GACA,KAAK,EAAI,MAAM,KAAK,EAAK,IAAI,EAAY,GAAG,IAC5C,GACA,EAAI,SAAU,EAAK,CAAK,CAAC,EACzB,EAAI,WAAY,EAAU,EAAK,CAAO,EAAI,EAAI,aAAa,CAAC,EAC5D,EAAI,OAAQ,EAAI,OAAS,EAAI,KAAK,IAAI,EAAI,EAAI,MAAM,CAAC,EACrD,EACF,EAEA,QAAQ,IAAI,EAAI,KAAK;AAAA,CAAI,CAAC,EC/CrB,SAAS,CAAiB,CAAC,EAA0B,QAAQ,IAAI,oBAA6B,CACnG,GAAI,IAAQ,QAAa,EAAI,KAAK,IAAM,GAAI,MArBH,IAuBzC,IAAM,EAAU,OAAO,EAAI,KAAK,CAAC,EACjC,GAAI,CAAC,OAAO,UAAU,CAAO,GAAK,EAAU,GAAK,EAAU,IACzD,MAAU,MACR,qGACmC,KAAK,UAAU,CAAG,IACvD,EAEF,OAAO",
|
|
10
|
-
"debugId": "
|
|
10
|
+
"debugId": "1F5F6DD3E5726AE964756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
//#region http/refusal.ts
|
|
2
|
+
/**
|
|
3
|
+
* The kind a status stands for, for a refusal that does not name one: an app's
|
|
4
|
+
* own `RequestBreakerError`, or an older server's `{ message }`. Any other 4xx
|
|
5
|
+
* is a `form_error`, a message about this request for `<FormError>` to show.
|
|
6
|
+
*/
|
|
7
|
+
function refusalKindForStatus(status) {
|
|
8
|
+
if (status === 401) return "authentication";
|
|
9
|
+
if (status === 403) return "permission";
|
|
10
|
+
if (status === 404) return "not_found";
|
|
11
|
+
if (status === 416) return "range_not_satisfiable";
|
|
12
|
+
if (status === 429) return "rate_limit";
|
|
13
|
+
if (status >= 500) return "server_error";
|
|
14
|
+
return "form_error";
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region client/MutationError.ts
|
|
18
|
+
var LEGACY_MESSAGES = {
|
|
19
|
+
"Authentication error": "authentication",
|
|
20
|
+
"Not authorized": "authorization",
|
|
21
|
+
"Insufficient permissions": "permission",
|
|
22
|
+
"Invalid CSRF token": "csrf",
|
|
23
|
+
"Internal Server Error": "server_error",
|
|
24
|
+
Forbidden: "permission",
|
|
25
|
+
"Not found": "not_found",
|
|
26
|
+
"Rate limit exceeded": "rate_limit"
|
|
27
|
+
};
|
|
28
|
+
/** @internal */
|
|
29
|
+
function isObject(error) {
|
|
30
|
+
return typeof error === "object" && error !== null;
|
|
31
|
+
}
|
|
32
|
+
function legacyKind(message, status) {
|
|
33
|
+
return LEGACY_MESSAGES[message] ?? (status === 401 ? "authorization" : refusalKindForStatus(status));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The `MutationError` a non-2xx response's parsed body stands for.
|
|
37
|
+
*
|
|
38
|
+
* gemi's own error bodies are `{ error }`, and the value under `error` is what
|
|
39
|
+
* is handed over. An app's body without one —
|
|
40
|
+
* `HttpResponse.json({ message: "Taken" }, { status: 409 })` — is handed over
|
|
41
|
+
* whole. A body with no content (`null`) becomes a refusal naming the status.
|
|
42
|
+
*
|
|
43
|
+
* What is handed over carries `status`, and a `kind` when it has a `message`:
|
|
44
|
+
* a bare string, which servers before 0.88 sent for most refusals, becomes
|
|
45
|
+
* `{ kind, message, status }`, and so does a `{ message }` without a kind.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
function mutationErrorFromBody(body, status) {
|
|
50
|
+
const error = isObject(body) && "error" in body && body.error != null ? body.error : body;
|
|
51
|
+
if (error == null) return {
|
|
52
|
+
kind: refusalKindForStatus(status),
|
|
53
|
+
message: `Request failed with status ${status}`,
|
|
54
|
+
status
|
|
55
|
+
};
|
|
56
|
+
if (typeof error === "string") return {
|
|
57
|
+
kind: legacyKind(error, status),
|
|
58
|
+
message: error,
|
|
59
|
+
status
|
|
60
|
+
};
|
|
61
|
+
if (!isObject(error) || error instanceof Error) return error;
|
|
62
|
+
const withStatus = {
|
|
63
|
+
...error,
|
|
64
|
+
status: typeof error.status === "number" ? error.status : status
|
|
65
|
+
};
|
|
66
|
+
if (typeof error.kind !== "string" && typeof error.message === "string") return {
|
|
67
|
+
...withStatus,
|
|
68
|
+
kind: refusalKindForStatus(withStatus.status)
|
|
69
|
+
};
|
|
70
|
+
return withStatus;
|
|
71
|
+
}
|
|
72
|
+
function kindOf(error) {
|
|
73
|
+
if (typeof error === "string") return LEGACY_MESSAGES[error];
|
|
74
|
+
if (!isObject(error) || error instanceof Error) return void 0;
|
|
75
|
+
if (typeof error.kind === "string") return error.kind;
|
|
76
|
+
if (typeof error.status === "number") return refusalKindForStatus(error.status);
|
|
77
|
+
return typeof error.message === "string" ? LEGACY_MESSAGES[error.message] : void 0;
|
|
78
|
+
}
|
|
79
|
+
/** Field messages, as `<ValidationErrors>` renders them. */
|
|
80
|
+
function isValidationError(error) {
|
|
81
|
+
return isObject(error) && error.kind === "validation_error";
|
|
82
|
+
}
|
|
83
|
+
/** A form-level message, as `<FormError>` renders it. */
|
|
84
|
+
function isFormError(error) {
|
|
85
|
+
return isObject(error) && error.kind === "form_error";
|
|
86
|
+
}
|
|
87
|
+
/** No signed-in user: `AuthenticationError` (401). */
|
|
88
|
+
function isAuthenticationError(error) {
|
|
89
|
+
return kindOf(error) === "authentication";
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A signed-in user who may not do this: `InsufficientPermissionsError` (403),
|
|
93
|
+
* `AuthorizationError` (401) or a policy denial (403), whatever message it was
|
|
94
|
+
* thrown with.
|
|
95
|
+
*/
|
|
96
|
+
function isPermissionError(error) {
|
|
97
|
+
const kind = kindOf(error);
|
|
98
|
+
return kind === "permission" || kind === "authorization";
|
|
99
|
+
}
|
|
100
|
+
/** The CSRF cookie is missing or stale (403). A reload fixes it. */
|
|
101
|
+
function isCsrfError(error) {
|
|
102
|
+
return kindOf(error) === "csrf";
|
|
103
|
+
}
|
|
104
|
+
/** A missing record, file or route (404). */
|
|
105
|
+
function isNotFoundError(error) {
|
|
106
|
+
return kindOf(error) === "not_found";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `RateLimitMiddleware` or `RateLimiter.enforce` refused the request (429).
|
|
110
|
+
* `retryAfter` (ms) says when to try again, when the server sent it.
|
|
111
|
+
*/
|
|
112
|
+
function isRateLimitError(error) {
|
|
113
|
+
return kindOf(error) === "rate_limit";
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The server failed (a 500, under `gemi dev` too), or answered something that
|
|
117
|
+
* is not JSON.
|
|
118
|
+
*/
|
|
119
|
+
function isServerError(error) {
|
|
120
|
+
return kindOf(error) === "server_error" || error instanceof SyntaxError;
|
|
121
|
+
}
|
|
122
|
+
/** The request got no answer: offline, DNS, CORS, a dropped connection. */
|
|
123
|
+
function isNetworkError(error) {
|
|
124
|
+
return error instanceof TypeError;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Which of the guards above `error` passes, for a `switch` over all of them.
|
|
128
|
+
* `"unknown"` is everything else: a 416, an error body of the app's own shape.
|
|
129
|
+
*/
|
|
130
|
+
function mutationErrorKind(error) {
|
|
131
|
+
if (isValidationError(error)) return "validation";
|
|
132
|
+
if (isFormError(error)) return "form";
|
|
133
|
+
if (isAuthenticationError(error)) return "authentication";
|
|
134
|
+
if (isPermissionError(error)) return "permission";
|
|
135
|
+
if (isCsrfError(error)) return "csrf";
|
|
136
|
+
if (isNotFoundError(error)) return "not_found";
|
|
137
|
+
if (isRateLimitError(error)) return "rate_limit";
|
|
138
|
+
if (isServerError(error)) return "server";
|
|
139
|
+
if (isNetworkError(error)) return "network";
|
|
140
|
+
return "unknown";
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* An error answered with `status`: a route's typed error from
|
|
144
|
+
* `HttpResponse.error(status, body)` / `httpError`, narrowed to the members
|
|
145
|
+
* of `error`'s type with that status.
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* onError: (error) => {
|
|
149
|
+
* if (isHttpError(error, 410)) toast(error.message);
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* At run time it checks the status alone, so gemi's own refusals with the
|
|
154
|
+
* same status (a 404 `not_found`, a 429 `rate_limit`) pass it too; pick a
|
|
155
|
+
* status gemi does not use for its own errors, or check `kind` after it.
|
|
156
|
+
*/
|
|
157
|
+
function isHttpError(error, status) {
|
|
158
|
+
return isObject(error) && !(error instanceof Error) && error.status === status;
|
|
159
|
+
}
|
|
160
|
+
var FALLBACK_MESSAGE = "Something went wrong. Try again.";
|
|
161
|
+
function unwrapQueryError(error) {
|
|
162
|
+
if (error instanceof Error && error.name === "QueryError" && "body" in error) {
|
|
163
|
+
const { body, status } = error;
|
|
164
|
+
return body == null ? error : mutationErrorFromBody(body, status);
|
|
165
|
+
}
|
|
166
|
+
return error;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* `error.list(fallback)` for any value: an error kept from a mutation, a
|
|
170
|
+
* `useQuery` `QueryError` (its body is read), or anything else.
|
|
171
|
+
*
|
|
172
|
+
* Kept in step with `list` in `./mutationErrorHelpers`, which the mutation
|
|
173
|
+
* hooks load on first use (#915) and so cannot share this code: an app's
|
|
174
|
+
* bundler would put it back in the entry chunk. `MutationError.helpers.test`
|
|
175
|
+
* runs the same cases through both.
|
|
176
|
+
*/
|
|
177
|
+
function mutationErrorList(error, fallback = FALLBACK_MESSAGE) {
|
|
178
|
+
const value = unwrapQueryError(error);
|
|
179
|
+
if (isValidationError(value)) {
|
|
180
|
+
const messages = Object.values(value.messages ?? {}).flat().filter((message) => typeof message === "string" && message !== "");
|
|
181
|
+
return messages.length > 0 ? messages : [fallback];
|
|
182
|
+
}
|
|
183
|
+
if (isObject(value) && !(value instanceof Error) && value.kind !== "server_error" && typeof value.message === "string" && value.message !== "") return [value.message];
|
|
184
|
+
return [fallback];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* `error.field(name)` for any value: a validation error's messages for
|
|
188
|
+
* `name` (a `QueryError`'s body is read), `[]` for anything else.
|
|
189
|
+
*/
|
|
190
|
+
function mutationErrorField(error, name) {
|
|
191
|
+
const value = unwrapQueryError(error);
|
|
192
|
+
if (!isValidationError(value)) return [];
|
|
193
|
+
const messages = value.messages?.[name];
|
|
194
|
+
return Array.isArray(messages) ? [...messages] : [];
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
export { isNetworkError as a, isPermissionError as c, isValidationError as d, mutationErrorField as f, mutationErrorList as h, isHttpError as i, isRateLimitError as l, mutationErrorKind as m, isCsrfError as n, isNotFoundError as o, mutationErrorFromBody as p, isFormError as r, isObject as s, isAuthenticationError as t, isServerError as u };
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=MutationError-DuKqBW8o.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationError-DuKqBW8o.js","names":[],"sources":["../../http/refusal.ts","../../client/MutationError.ts"],"sourcesContent":["/**\n * The shape of a refusal on the wire: the `error` field of a non-2xx `/api`\n * answer, for every refusal gemi sends.\n *\n * It was a bare string for most of them (`\"Not authorized\"`, `\"Invalid CSRF\n * token\"`, a 500's message) and `{ message }` for the rest. A string carries no\n * status, so a client could only classify the framework's default messages: an\n * `AuthorizationError` thrown with a message of its own, the rule the skill\n * teaches, was `\"unknown\"`, and apps compared strings (issue #673).\n *\n * Shared by the server, which builds it, and the client, which reads it and\n * wraps an older server's bare strings into it, so this module imports nothing.\n */\n\n/**\n * Which refusal this is. `validation_error` and `form_error` predate the rest\n * and keep their spelling, and `server_error` is the kind `useUpload` already\n * reported for a failed upload, so a 500 has one name wherever it comes from.\n */\nexport type RefusalKind =\n /** No signed-in user: `AuthenticationError` (401). */\n | \"authentication\"\n /** `AuthorizationError` (401): a known user refused this action. */\n | \"authorization\"\n /** `InsufficientPermissionsError` (403) or a policy denial (403). */\n | \"permission\"\n /** `InvalidCSRFTokenError` (403): the CSRF cookie is missing or stale. */\n | \"csrf\"\n /** A missing record, file or route (404). */\n | \"not_found\"\n /** A `Range` the object cannot satisfy (416). */\n | \"range_not_satisfiable\"\n /** `RateLimitMiddleware` or `RateLimiter.enforce` refused the request (429). */\n | \"rate_limit\"\n /** An unhandled exception (500). */\n | \"server_error\"\n /** A single form-level message, which `<FormError>` renders. */\n | \"form_error\"\n /** `ValidationError` (400). Carries `messages` instead of `message`. */\n | \"validation_error\";\n\n/** A refusal's `error`, apart from `validation_error`, which has `messages`. */\nexport type Refusal<K extends RefusalKind = Exclude<RefusalKind, \"validation_error\">> = {\n kind: K;\n message: string;\n status: number;\n /**\n * `rate_limit` only: milliseconds until a retry can succeed, when the\n * limiter knew (the `rate-limit` middleware, `RateLimiter.enforce`).\n */\n retryAfter?: number;\n};\n\n/**\n * The kind a status stands for, for a refusal that does not name one: an app's\n * own `RequestBreakerError`, or an older server's `{ message }`. Any other 4xx\n * is a `form_error`, a message about this request for `<FormError>` to show.\n */\nexport function refusalKindForStatus(status: number): Exclude<RefusalKind, \"validation_error\"> {\n if (status === 401) return \"authentication\";\n if (status === 403) return \"permission\";\n if (status === 404) return \"not_found\";\n if (status === 416) return \"range_not_satisfiable\";\n if (status === 429) return \"rate_limit\";\n if (status >= 500) return \"server_error\";\n return \"form_error\";\n}\n","import { refusalKindForStatus, type RefusalKind } from \"../http/refusal\";\n\n/**\n * What a failed mutation hands `onError` and puts in `error` — `useMutation`\n * and its `usePost`/`usePut`/`usePatch`/`useDelete` shorthands, `useUpload`,\n * and `<Form onError>`.\n *\n * It was typed `any` on `<Form>` and on the hooks' `error`, and as a union of\n * `kind`s the server never sent (`not_authorized`, `insufficient_permissions`)\n * on the hooks' `onError`. Apps sniffed the shape themselves, and got it wrong\n * as easily as right. This is the shape the framework actually produces,\n * member by member, read off the server's error payloads and the client's\n * fetch code (issue #626).\n *\n * Since 0.88 every refusal is an object with a `kind`, its `message` and the\n * `status` it came with (issue #673). Most refusals were a bare string before,\n * which carried no status, so a refusal thrown with a message of its own could\n * not be told apart from any other string. A server older than 0.85 still sends\n * those strings; the client wraps them into the same object, so the guards and\n * `error.message` work against either.\n */\n\n/** A server-side `ValidationError` (400): messages keyed by field. */\nexport interface MutationValidationError {\n kind: \"validation_error\";\n messages: Record<string, string[]>;\n status?: number;\n}\n\n/**\n * A single form-level message, which `<FormError>` renders: a\n * `RequestBreakerError` of the app's own, or any other 4xx that answered a\n * message without a kind of its own.\n */\nexport interface MutationFormError {\n kind: \"form_error\";\n message: string;\n status?: number;\n}\n\n/**\n * The server failed: an unhandled exception (500; under `gemi dev` the message\n * is the exception's), or a failed `useUpload` whose body was not JSON.\n */\nexport interface MutationServerError {\n kind: \"server_error\";\n message: string;\n status?: number;\n}\n\n/** The refusals other than the three above. */\nexport type MutationRefusalKind = Exclude<\n RefusalKind,\n \"validation_error\" | \"form_error\" | \"server_error\"\n>;\n\n/**\n * A refusal: `authentication` (401), `authorization` (`AuthorizationError`,\n * 401), `permission` (`InsufficientPermissionsError` or a policy, 403), `csrf`\n * (403), `not_found` (404), `range_not_satisfiable` (416) or `rate_limit`\n * (429). `message` is the one it was thrown with.\n */\nexport interface MutationRefusal<K extends MutationRefusalKind = MutationRefusalKind> {\n kind: K;\n message: string;\n status: number;\n /**\n * `rate_limit` only: milliseconds until a retry can succeed, when the\n * server's limiter knew (the `rate-limit` middleware, `RateLimiter.enforce`).\n */\n retryAfter?: number;\n}\n\n/**\n * @deprecated A `{ message }` body is wrapped into a `MutationRefusal` or\n * `MutationFormError` since 0.88, and `MutationError` no longer includes this.\n */\nexport interface MutationMessageError {\n kind?: undefined;\n message: string;\n}\n\n/**\n * Every value `onError` receives and `error` holds for a request gemi's server\n * answered, or failed to reach:\n *\n * - `MutationValidationError`, `MutationFormError`, `MutationServerError`,\n * `MutationRefusal` — tagged with `kind`, and (from the server) `status`.\n * - `Error` — raised in the browser: a `TypeError` when the request never got\n * an answer (offline, DNS, CORS), a `SyntaxError` when the answer was not\n * JSON (a proxy's HTML error page, say). A throw from an `onSuccess` of\n * yours is reported through `onError` as well, as whatever it threw.\n *\n * Never a string since 0.88. A cancelled request is not an error: `onCanceled`\n * runs and `error` stays `null`. A route's typed errors — the bodies its\n * handler answers with `HttpResponse.error(status, body)` / `httpError` — are\n * added to this union on its hooks and `<Form>` (`MutationError | E`). Any\n * other error body of the route's own shape is outside this type: a body with an `error` field\n * (`HttpResponse.json({ error }, { status: 409 })`) hands over that field, as\n * gemi's own errors do, and any other body is handed over whole. Either is\n * given a `kind` (from the status) and the `status` when it is an object with\n * a string `message` and no `kind`, and becomes one when it is a string.\n */\nexport type MutationError =\n | MutationValidationError\n | MutationFormError\n | MutationServerError\n | MutationRefusal\n | Error;\n\n/** What `mutationErrorKind` answers, one per guard below. */\nexport type MutationErrorKind =\n | \"validation\"\n | \"form\"\n | \"authentication\"\n | \"permission\"\n | \"csrf\"\n | \"not_found\"\n | \"rate_limit\"\n | \"server\"\n | \"network\"\n | \"unknown\";\n\n// What a server before 0.88 sent: the framework's own messages, as bare\n// strings, or as `{ message }`. Read so a client on 0.85 classifies an older\n// server's refusals during a rolling deploy. Remove in 0.86.\nconst LEGACY_MESSAGES: Record<string, RefusalKind> = {\n \"Authentication error\": \"authentication\",\n \"Not authorized\": \"authorization\",\n \"Insufficient permissions\": \"permission\",\n \"Invalid CSRF token\": \"csrf\",\n \"Internal Server Error\": \"server_error\",\n Forbidden: \"permission\",\n \"Not found\": \"not_found\",\n \"Rate limit exceeded\": \"rate_limit\",\n};\n\n/** @internal */\nexport function isObject(error: unknown): error is Record<string, unknown> {\n return typeof error === \"object\" && error !== null;\n}\n\n// A bare string from a server before 0.88. Its own message names the kind when\n// it is one of the framework's; otherwise the status does, and a 401 with a\n// message of its own can only be an `AuthorizationError` — an\n// `AuthenticationError` always says \"Authentication error\".\nfunction legacyKind(message: string, status: number): RefusalKind {\n return (\n LEGACY_MESSAGES[message] ?? (status === 401 ? \"authorization\" : refusalKindForStatus(status))\n );\n}\n\n/**\n * The `MutationError` a non-2xx response's parsed body stands for.\n *\n * gemi's own error bodies are `{ error }`, and the value under `error` is what\n * is handed over. An app's body without one —\n * `HttpResponse.json({ message: \"Taken\" }, { status: 409 })` — is handed over\n * whole. A body with no content (`null`) becomes a refusal naming the status.\n *\n * What is handed over carries `status`, and a `kind` when it has a `message`:\n * a bare string, which servers before 0.88 sent for most refusals, becomes\n * `{ kind, message, status }`, and so does a `{ message }` without a kind.\n *\n * @internal\n */\nexport function mutationErrorFromBody(body: unknown, status: number): MutationError {\n const error = isObject(body) && \"error\" in body && body.error != null ? body.error : body;\n if (error == null) {\n return {\n kind: refusalKindForStatus(status),\n message: `Request failed with status ${status}`,\n status,\n } as MutationError;\n }\n if (typeof error === \"string\") {\n return { kind: legacyKind(error, status), message: error, status } as MutationError;\n }\n if (!isObject(error) || error instanceof Error) {\n return error as MutationError;\n }\n const withStatus = { ...error, status: typeof error.status === \"number\" ? error.status : status };\n if (typeof error.kind !== \"string\" && typeof error.message === \"string\") {\n return {\n ...withStatus,\n // The status alone places an older server's `{ message }` bodies (403\n // \"Forbidden\", 404, 429), and it is what an app's own body means.\n kind: refusalKindForStatus(withStatus.status),\n } as MutationError;\n }\n return withStatus as MutationError;\n}\n\n// The kind a value stands for: its `kind`; else, for an object that has none,\n// its `status`; else one of the framework's old messages, as a bare string or\n// `{ message }`, for a body handed to a guard straight off an older server.\nfunction kindOf(error: unknown): string | undefined {\n if (typeof error === \"string\") return LEGACY_MESSAGES[error];\n if (!isObject(error) || error instanceof Error) return undefined;\n if (typeof error.kind === \"string\") return error.kind;\n if (typeof error.status === \"number\") return refusalKindForStatus(error.status);\n return typeof error.message === \"string\" ? LEGACY_MESSAGES[error.message] : undefined;\n}\n\n// The guards read `kind`, falling back to `status`, and accept the bare\n// strings and `{ message }` bodies of a server before 0.88 for one minor. What\n// the hooks hand over is already wrapped, so those fallbacks only matter for a\n// body passed in by hand.\n\n/** Field messages, as `<ValidationErrors>` renders them. */\nexport function isValidationError(\n error: unknown,\n): error is MutationValidationError {\n return isObject(error) && error.kind === \"validation_error\";\n}\n\n/** A form-level message, as `<FormError>` renders it. */\nexport function isFormError(error: unknown): error is MutationFormError {\n return isObject(error) && error.kind === \"form_error\";\n}\n\n/** No signed-in user: `AuthenticationError` (401). */\nexport function isAuthenticationError(\n error: unknown,\n): error is MutationRefusal<\"authentication\"> {\n return kindOf(error) === \"authentication\";\n}\n\n/**\n * A signed-in user who may not do this: `InsufficientPermissionsError` (403),\n * `AuthorizationError` (401) or a policy denial (403), whatever message it was\n * thrown with.\n */\nexport function isPermissionError(\n error: unknown,\n): error is MutationRefusal<\"permission\" | \"authorization\"> {\n const kind = kindOf(error);\n return kind === \"permission\" || kind === \"authorization\";\n}\n\n/** The CSRF cookie is missing or stale (403). A reload fixes it. */\nexport function isCsrfError(error: unknown): error is MutationRefusal<\"csrf\"> {\n return kindOf(error) === \"csrf\";\n}\n\n/** A missing record, file or route (404). */\nexport function isNotFoundError(\n error: unknown,\n): error is MutationRefusal<\"not_found\"> {\n return kindOf(error) === \"not_found\";\n}\n\n/**\n * `RateLimitMiddleware` or `RateLimiter.enforce` refused the request (429).\n * `retryAfter` (ms) says when to try again, when the server sent it.\n */\nexport function isRateLimitError(\n error: unknown,\n): error is MutationRefusal<\"rate_limit\"> {\n return kindOf(error) === \"rate_limit\";\n}\n\n/**\n * The server failed (a 500, under `gemi dev` too), or answered something that\n * is not JSON.\n */\nexport function isServerError(\n error: unknown,\n): error is MutationServerError | SyntaxError {\n return kindOf(error) === \"server_error\" || error instanceof SyntaxError;\n}\n\n/** The request got no answer: offline, DNS, CORS, a dropped connection. */\nexport function isNetworkError(error: unknown): error is TypeError {\n return error instanceof TypeError;\n}\n\n/**\n * Which of the guards above `error` passes, for a `switch` over all of them.\n * `\"unknown\"` is everything else: a 416, an error body of the app's own shape.\n */\nexport function mutationErrorKind(error: unknown): MutationErrorKind {\n if (isValidationError(error)) return \"validation\";\n if (isFormError(error)) return \"form\";\n if (isAuthenticationError(error)) return \"authentication\";\n if (isPermissionError(error)) return \"permission\";\n if (isCsrfError(error)) return \"csrf\";\n if (isNotFoundError(error)) return \"not_found\";\n if (isRateLimitError(error)) return \"rate_limit\";\n if (isServerError(error)) return \"server\";\n if (isNetworkError(error)) return \"network\";\n return \"unknown\";\n}\n\n/**\n * The members of `E` answered with status `S`. When none of them names it — an\n * `unknown`, or a `MutationError` alone — `E` with that status, rather than\n * `never`.\n */\nexport type HttpErrorWithStatus<E, S extends number> = [Extract<E, { status: S }>] extends [never]\n ? E & { status: S }\n : Extract<E, { status: S }>;\n\n/**\n * An error answered with `status`: a route's typed error from\n * `HttpResponse.error(status, body)` / `httpError`, narrowed to the members\n * of `error`'s type with that status.\n *\n * ```ts\n * onError: (error) => {\n * if (isHttpError(error, 410)) toast(error.message);\n * }\n * ```\n *\n * At run time it checks the status alone, so gemi's own refusals with the\n * same status (a 404 `not_found`, a 429 `rate_limit`) pass it too; pick a\n * status gemi does not use for its own errors, or check `kind` after it.\n */\nexport function isHttpError<E, S extends number>(\n error: E,\n status: S,\n): error is HttpErrorWithStatus<E, S> {\n return isObject(error) && !(error instanceof Error) && error.status === status;\n}\n\n/**\n * What every error the mutation hooks hand over carries (issue #890): the\n * messages to show a person, without flattening `messages` by hand.\n */\nexport interface MutationErrorHelpers {\n /**\n * The failure in words, as a flat list that is never empty: a validation\n * error's messages, every field's in the order the server sent them; the\n * `message` of any other error the server meant for a person (a form error,\n * a refusal, a route's typed error); else `[fallback]` — for a server error,\n * whose message is an exception's under `gemi dev`, and for the browser's\n * own errors (no answer, an answer that was not JSON).\n *\n * `fallback` defaults to `\"Something went wrong. Try again.\"`.\n */\n list(fallback?: string): string[];\n /** A validation error's messages for the field `name`; `[]` otherwise. */\n field(name: string): string[];\n}\n\n/**\n * `T` with the helpers, member by member. A member that has a `list` or\n * `field` of its own — a route's typed error body with a `field` key — keeps\n * it, and does not get that helper.\n */\nexport type WithMutationErrorHelpers<T> = T extends object\n ? T & Omit<MutationErrorHelpers, keyof T>\n : T;\n\nconst FALLBACK_MESSAGE = \"Something went wrong. Try again.\";\n\n// A `QueryError`'s refusal, read as the mutation hooks read a body. Read by\n// shape, not `instanceof`, so a copy of the class from another bundle works.\nfunction unwrapQueryError(error: unknown): unknown {\n if (error instanceof Error && error.name === \"QueryError\" && \"body\" in error) {\n const { body, status } = error as Error & { body: unknown; status: number };\n return body == null ? error : mutationErrorFromBody(body, status);\n }\n return error;\n}\n\n/**\n * `error.list(fallback)` for any value: an error kept from a mutation, a\n * `useQuery` `QueryError` (its body is read), or anything else.\n *\n * Kept in step with `list` in `./mutationErrorHelpers`, which the mutation\n * hooks load on first use (#915) and so cannot share this code: an app's\n * bundler would put it back in the entry chunk. `MutationError.helpers.test`\n * runs the same cases through both.\n */\nexport function mutationErrorList(\n error: unknown,\n fallback: string = FALLBACK_MESSAGE,\n): string[] {\n const value = unwrapQueryError(error);\n if (isValidationError(value)) {\n const messages = Object.values(value.messages ?? {})\n .flat()\n .filter((message) => typeof message === \"string\" && message !== \"\");\n return messages.length > 0 ? messages : [fallback];\n }\n if (\n isObject(value) &&\n !(value instanceof Error) &&\n value.kind !== \"server_error\" &&\n typeof value.message === \"string\" &&\n value.message !== \"\"\n ) {\n return [value.message];\n }\n return [fallback];\n}\n\n/**\n * `error.field(name)` for any value: a validation error's messages for\n * `name` (a `QueryError`'s body is read), `[]` for anything else.\n */\nexport function mutationErrorField(error: unknown, name: string): string[] {\n const value = unwrapQueryError(error);\n if (!isValidationError(value)) return [];\n const messages = value.messages?.[name];\n return Array.isArray(messages) ? [...messages] : [];\n}\n"],"mappings":";;;;;;AA0DA,SAAgB,qBAAqB,QAA0D;CAC7F,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,UAAU,KAAK,OAAO;CAC1B,OAAO;AACT;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