@alxia/react-router 0.31.0 → 0.32.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 CHANGED
@@ -1057,8 +1057,8 @@ import { RouterLink } from '@alxia/react-router/link';
1057
1057
  ## A fetcher's fresh answer
1058
1058
 
1059
1059
  A keyed fetcher outlives its page, so a `useEffect` on its data replays an
1060
- earlier visit's answer on remount. `@alxia/react-router/fetcher` (`react` is
1061
- its only import) calls your handler once per new answer:
1060
+ earlier visit's answer on remount. `@alxia/react-router/fetcher` (`react` and
1061
+ `react-router` are its imports) calls your handler once per new answer:
1062
1062
 
1063
1063
  ```tsx
1064
1064
  import { useJsonFetcher } from '@alxia/react-router/errors';
@@ -1068,6 +1068,20 @@ const { fetcher } = useJsonFetcher<typeof action>('save');
1068
1068
  const answer = useFetcherAnswer(fetcher, (result) => toast(result.message));
1069
1069
  ```
1070
1070
 
1071
+ A resource route loaded for what is typed (a typeahead, a preview): one load
1072
+ after a pause, from a minimum length, the previous answer kept (`stale`) until
1073
+ the new one lands, and a retry:
1074
+
1075
+ ```tsx
1076
+ import { useDebouncedFetcher } from '@alxia/react-router/fetcher';
1077
+
1078
+ const { data, stale, state, retry } = useDebouncedFetcher<Found>(
1079
+ typed,
1080
+ (q) => `/suggest?${new URLSearchParams({ q })}`,
1081
+ { minLength: 2, delayMs: 250 },
1082
+ );
1083
+ ```
1084
+
1071
1085
  See the [fetcher guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md).
1072
1086
 
1073
1087
  ## A list whose state is the URL
@@ -1267,7 +1281,7 @@ From `@alxia/react-router/errors` (`react-router` is its only package import, an
1267
1281
  | `CatalogueMessage`, `CatalogueMessages`, `ParamKind`, `MessageFormat`, `MessageValues` | one API message with the kind of each argument (`TEXT`, `NUMBER`, `DATE`, `PLURAL`, `SELECT`), a language's messages by code, and the formatter's type |
1268
1282
  | `apiCodeResolver(messages, { translate, language, codeOf?, isApiCode? })`, `ApiCodeResolver`, `ApiCodeResolverOptions`, `CodeIssueLike` | the `{ translate, codeOf }` a form's `useCodeResolver(schema, resolver)` takes: a check's API code is worded as the API words it, any other key by the app's translator; `CodeIssueLike` is the issue a custom `codeOf` receives |
1269
1283
  | `ApiMessagesProvider({ messages, value, children })`, `ApiMessagesProviderProps` | `messages` is the store and `value` the root loader's data; fills the store in the browser from the root's data before the children render; a server render writes nothing. A function with no JSX, so no React import |
1270
- | `createApiErrors({ messages, unavailable, refused?, byCode?, reword?, isApiCode? })`, `ApiErrors`, `ApiErrorsOptions`, `FetcherResultOptions` | what a page says of a refusal, in a language: `apiErrorMessage(error, language)` (the catalogue's text of the code, else the API's message; `refused` replaces it for an error with no API code and `byCode` words given codes, such as a query's limits; `reword(text, error, { code, values, language })` words a family of codes once, on the final text of the catalogue, the API or `byCode`, returning `undefined` to keep it), `fieldErrors(error, language)` by input path, `translateCode(code, fallback, language, values?)`, `unavailableMessage(language)` and `apiRefusal(error, language)`; for an action, `fetcherResult(language, about, run, options?)` (`{ ok: true, …about, …value }`, or `{ ok: false, …about, error }` with the refusal's status; `options` is `FetcherResultOptions`: the `route` options plus `reword(error)`, the message of this call, or `undefined` to keep the worded one), `fetcherRefusal(error, language, route?)` (the refusal, or the thrown route error) and `submitForm(language, run, fieldOf, route?)` (`{ ok: true, value }`, or a `FormErrors` with the refusal's status); `route` is the `RouteErrorOptions` of the `routeError` they throw through |
1284
+ | `createApiErrors({ messages, unavailable, refused?, byCode?, reword?, isApiCode? })`, `ApiErrors`, `ApiErrorsOptions`, `FetcherResultOptions` | what a page says of a refusal, in a language: `apiErrorMessage(error, language)` (the catalogue's text of the code, else the API's message; `refused` replaces it for an error with no API code and `byCode` words given codes, such as a query's limits; `reword(text, error, { code, values, language })` words a family of codes once, on the final text of the catalogue, the API or `byCode`, returning `undefined` to keep it), `fieldErrors(error, language)` by input path, `translateCode(code, fallback, language, values?)`, `unavailableMessage(language)` and `apiRefusal(error, language)`; for an action, `fetcherResult(language, about, run, options?)` (`{ ok: true, …about, …value }`, or `{ ok: false, …about, error }` with the refusal's status; `options` is `FetcherResultOptions`: the `route` options plus `reword(error: ApiErrorLike)`, called for an API's own refusal only: the message of this call, or `undefined` to keep the worded one), `fetcherRefusal(error, language, route?)` (the refusal, or the thrown route error) and `submitForm(language, run, fieldOf, route?)` (`{ ok: true, value }`, or a `FormErrors` with the refusal's status); `route` is the `RouteErrorOptions` of the `routeError` they throw through |
1271
1285
  | `apiCallFailure(error, { api, operation?, requestId?, signal?, passedThrough?, log? })`, `CallFailureOptions` | what a failed call to the API becomes, for a loader or an action to throw, logged with the request id: an `ApiError` as it is (with `requestId`), a `Response` of its own status for a 401, 403 or 404 without a GraphQL body, a 503 `Response` with no body for an unreachable, slow, garbled or aborted call (the reason is in the log), any other error as it is; the log lines start with `api`, and a `log` that throws never replaces the outcome. It recognises `@nxgt/graphql-client`'s errors by `name`, not `instanceof` |
1272
1286
  | `operationName(document)`, `DocumentLike` | the name of the operation a document holds, for the log (else `query`, `mutation` or `subscription`); a structural `{ definitions }`, so `graphql`'s `DocumentNode` fits |
1273
1287
  | `createErrorCatalogue({ messages, languages, read, versions, ttlMs, clientCodes, retryMs?, firstReadWaitMs?, log? })`, `ErrorCatalogue`, `ErrorCatalogueOptions`, `CatalogueReply` | keeps the API's error catalogue in the store: `fresh(language, now?)` and `freshAll(now?)` (a cold language is awaited for `firstReadWaitMs`, 1500 by default, and read once however many requests ask; a held one is served, and its version checked in the background once per `ttlMs`, a number or a getter; only a language whose version moved is read again; a failure is retried after `retryMs`, 5000 by default), `warm()` for startup, `clientMessages()` (the `clientCodes` the browser words itself, by language, for the root's loader), and, for tests, `reset()`, `heldVersion(language)`, `settled()` and the `now` parameters. `read` and `versions` are the app's calls to its API |
@@ -1359,11 +1373,12 @@ From `@alxia/react-router/link` (`react` and `react-router` are its only imports
1359
1373
  | --- | --- |
1360
1374
  | `RouterLink`, `RouterLinkProps` | React Router's `Link` as a UI library's link component: takes `href` (or `to`), spreads `className`, `children`, `ref` and every anchor prop onto the `<a>`, keeps `Link`'s own props (`replace`, `prefetch`, `reloadDocument`, ...) |
1361
1375
 
1362
- From `@alxia/react-router/fetcher` (`react` is its only import; it renders on the server):
1376
+ From `@alxia/react-router/fetcher` (`react` and `react-router` are its imports; it renders on the server):
1363
1377
 
1364
1378
  | export | |
1365
1379
  | --- | --- |
1366
1380
  | `useFetcherAnswer(fetcher, onAnswer?)`, `AnswerSource` | `onAnswer(answer)` once per answer that arrives while the fetcher is idle and differs from the last one seen (the data present at mount counts as seen); the handler is read from a ref; returns the latest answer handed over, `undefined` before the first |
1381
+ | `useDebouncedFetcher(value, to, { delayMs?, minLength?, enabled?, key?, keep? }?)`, `DebouncedFetcher`, `DebouncedFetcherOptions`, `DebouncedFetcherState` | a resource route loaded for what is typed: one `fetcher.load` after `delayMs` (250) without a change and from `minLength` (1) trimmed characters; `to` is a URL or `(value) => url`; returns `{ data, stale, state, retry }`: `data` is the answer for the value as it stands, else the previous one with `stale` set; `state` is `'idle' \| 'waiting' \| 'loading' \| 'done'`; `keep(answer)` filters what may stay as the stale answer; `retry()` (stable) asks again at once |
1367
1382
 
1368
1383
  From `@alxia/react-router/subscription` (no import, no peer):
1369
1384
 
@@ -1389,7 +1404,7 @@ The `alxia-react-router` bin, run with `bunx`:
1389
1404
  - [Installable and offline](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/pwa.md): what the subpaths hold, the worker's contract, the worker, what it caches, the offline page, building the worker with `alxia()` or `buildWorker`, the hooks in React, registering the worker and offering an update, serving the worker's script, the web app manifest, and clearing at sign-out.
1390
1405
  - [An API's refusals](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/errors.md): what `/errors` holds, recognising an API error, the request id, the page a request is for, the catalogue store, the form checks in the API's words, the provider, wording a refusal, loaders and the error page, actions, JSON actions and CSRF, and keeping the catalogue fresh.
1391
1406
  - [A BFF session](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/session.md): redirects that stay on the site, the cookies, the sign-in route, the second factor, the viewer and sign-out, the step-up, and the pages a mail's link opens.
1392
- - [A fetcher's fresh answer](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md): `useFetcherAnswer`: a handler called once per new answer of a keyed fetcher, not for the data it held at mount.
1407
+ - [A fetcher's fresh answer](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md): `useFetcherAnswer`: a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useDebouncedFetcher`: a resource route loaded for what is typed.
1393
1408
  - [Lists whose state is the URL](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/lists.md): `useSearchChange`, `useSameRouteLoading`, `usePagedRows`: a search that drops the cursor, a skeleton for the same page reloading, a load-more button.
1394
1409
  - [Subscriptions for a BFF](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/subscriptions.md): exposing a GraphQL subscription to the browser through a resource route: the allow-list, the session's bearer, the headers, the heartbeat, abort and rate limits.
1395
1410
  - [Troubleshooting](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md): each message, and the traps that print none.
@@ -86,8 +86,8 @@ export interface ApiErrors<L extends string> {
86
86
  * Runs the mutation of an action a fetcher posted to: `{ ok: true }` with
87
87
  * `about` and the mutation's value, or `{ ok: false, error }` with `about`
88
88
  * and the refusal's message, answered with its HTTP status. `options.reword`
89
- * words the refusal of this call from the caught error (`undefined` keeps
90
- * the worded message).
89
+ * words the refusal of this call from the caught API error (`undefined`
90
+ * keeps the worded message); it is not called for an unreachable API.
91
91
  */
92
92
  fetcherResult<About extends object, Value extends object = Record<never, never>>(language: L, about: About, run: () => Promise<Value>, options?: FetcherResultOptions): Promise<({
93
93
  ok: true;
@@ -1,3 +1,4 @@
1
+ import { type ApiErrorLike } from './api-error';
1
2
  import type { ApiErrors, ApiRefusal } from './api-errors';
2
3
  import { type RouteErrorOptions } from './route-error';
3
4
  /**
@@ -11,9 +12,11 @@ export interface FetcherResultOptions extends RouteErrorOptions {
11
12
  /**
12
13
  * Words the refusal of this call: given the caught API error, the message
13
14
  * to answer, or `undefined` to keep the worded one. The status is the
14
- * refusal's. Not called for what is thrown to the error page.
15
+ * refusal's. Called for an API's own refusal only: not for an API it
16
+ * cannot reach or any other failure, nor for what is thrown to the error
17
+ * page.
15
18
  */
16
- reword?: (error: unknown) => string | undefined;
19
+ reword?: (error: ApiErrorLike) => string | undefined;
17
20
  }
18
21
  /**
19
22
  * Runs the mutation of an action a fetcher posted to: `{ ok: true }` with
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher-result.d.ts","sourceRoot":"","sources":["../../src/errors/fetcher-result.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,eAAe,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC9C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EACxC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,EACX,KAAK,CAAC,EAAE,iBAAiB,GACvB,UAAU,CAOZ;AAED,uFAAuF;AACvF,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC9D;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;CAChD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAClC,CAAC,SAAS,MAAM,EAChB,KAAK,SAAS,MAAM,EACpB,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE3C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EACxC,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,EACzB,OAAO,CAAC,EAAE,oBAAoB;;;;;;6BAoB9B"}
1
+ {"version":3,"file":"fetcher-result.d.ts","sourceRoot":"","sources":["../../src/errors/fetcher-result.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,eAAe,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC9C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EACxC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,EACX,KAAK,CAAC,EAAE,iBAAiB,GACvB,UAAU,CAOZ;AAED,uFAAuF;AACvF,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC9D;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;CACrD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAClC,CAAC,SAAS,MAAM,EAChB,KAAK,SAAS,MAAM,EACpB,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE3C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EACxC,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,EACzB,OAAO,CAAC,EAAE,oBAAoB;;;;;;6BAsB9B"}
@@ -76,7 +76,7 @@ async function fetcherResult(errors, language, about, run, options) {
76
76
  return data({
77
77
  ok: false,
78
78
  ...about,
79
- error: options?.reword?.(error) ?? message
79
+ error: (isApiErrorLike2(error) ? options?.reword?.(error) : undefined) ?? message
80
80
  }, { status });
81
81
  }
82
82
  }
@@ -542,5 +542,5 @@ export {
542
542
  waitMinutes2 as waitMinutes
543
543
  };
544
544
 
545
- //# debugId=3CE5151D954C426164756E2164756E21
545
+ //# debugId=BCEFF30EF289759264756E2164756E21
546
546
  //# sourceMappingURL=index.js.map
@@ -4,10 +4,10 @@
4
4
  "sourcesContent": [
5
5
  "import type { ApiMessages } from './messages';\n\n/** The part of a zod issue a code reads, by shape (`@nxgt/material-core`'s `CodeIssue`). */\nexport type CodeIssueLike = {\n\treadonly code: string;\n\t/** A custom issue's params: `.refine(…, { params: { code } })`. */\n\treadonly params?: Record<string, unknown> | undefined;\n\treadonly input?: unknown;\n\treadonly origin?: string | undefined;\n\treadonly minimum?: unknown;\n\treadonly maximum?: unknown;\n\treadonly expected?: unknown;\n\treadonly message?: string | undefined;\n};\n\n/** An API error code (`<module>.errors.<slug>`, the module in kebab-case or camelCase), as opposed to a GraphQL one (`BAD_USER_INPUT`). */\nexport const API_CODE = /^[a-z][a-zA-Z0-9-]*\\.errors\\.[a-z0-9-]+$/;\n\nexport interface ApiCodeResolverOptions<L extends string> {\n\t/**\n\t * The app's translator, for every key that is not an API code. Method\n\t * syntax: the app's own `Translate<LocaleKey>` is accepted.\n\t */\n\ttranslate(\n\t\tkey: string,\n\t\tcontext?: Readonly<Record<string, unknown>>,\n\t\tlanguage?: L | (() => L),\n\t): string;\n\t/** The page's language, when a call names none. */\n\tlanguage(): L;\n\t/** Which code an issue carries; the issue's `params.code` by default. */\n\tcodeOf?(issue: CodeIssueLike): string | undefined;\n\t/** Whether a key is an API code; `<module>.errors.<slug>` by default. */\n\tisApiCode?(key: string): boolean;\n}\n\n/** What `@nxgt/material`'s `useCodeResolver(schema, resolver)` takes. */\nexport interface ApiCodeResolver<L extends string> {\n\ttranslate: (\n\t\tkey: string,\n\t\tcontext?: Readonly<Record<string, unknown>>,\n\t\tlanguage?: L | (() => L),\n\t) => string;\n\tcodeOf: (issue: CodeIssueLike) => string | undefined;\n}\n\nfunction paramsCode(issue: CodeIssueLike) {\n\tconst code = (issue.params as { code?: unknown } | undefined)?.code;\n\treturn typeof code === 'string' ? code : undefined;\n}\n\n/**\n * The words of what a form's checks ask for: a refinement carrying an API\n * code in `params.code` reads exactly as the API words it (from the\n * catalogue `messages` holds), any other key takes the app's translator, and\n * a code the catalogue lacks comes back as it is, so the form library words\n * the issue with its own locale instead. Both functions are stable: a\n * resolver is made once per schema and language, so build this once, at\n * module scope.\n */\nexport function apiCodeResolver<L extends string>(\n\tmessages: ApiMessages<L>,\n\toptions: ApiCodeResolverOptions<L>,\n): ApiCodeResolver<L> {\n\tconst isApiCode = (key: string) =>\n\t\toptions.isApiCode ? options.isApiCode(key) : API_CODE.test(key);\n\treturn {\n\t\ttranslate(key, context, provideLanguage) {\n\t\t\tif (!isApiCode(key))\n\t\t\t\treturn options.translate(key, context, provideLanguage);\n\t\t\tconst language =\n\t\t\t\ttypeof provideLanguage === 'function'\n\t\t\t\t\t? provideLanguage()\n\t\t\t\t\t: (provideLanguage ?? options.language());\n\t\t\treturn messages.apiMessage(key, context, language) ?? key;\n\t\t},\n\t\tcodeOf(issue) {\n\t\t\treturn options.codeOf ? options.codeOf(issue) : paramsCode(issue);\n\t\t},\n\t};\n}\n",
6
6
  "import { isApiErrorLike } from './api-error';\nimport type { ApiErrors } from './api-errors';\n\n/** The API's refusal of `error`, or `undefined` when it is not one. */\nexport function refusalOf<L extends string>(\n\terrors: Pick<ApiErrors<L>, 'apiErrorMessage' | 'unavailableMessage'>,\n\terror: unknown,\n\tlanguage: L,\n): ReturnType<ApiErrors<L>['apiRefusal']> {\n\tif (isApiErrorLike(error)) {\n\t\treturn {\n\t\t\tmessage: errors.apiErrorMessage(error, language),\n\t\t\tstatus: error.status,\n\t\t};\n\t}\n\tif (error instanceof Response && error.status === 503) {\n\t\treturn { message: errors.unavailableMessage(language), status: 503 };\n\t}\n\treturn undefined;\n}\n\n/** The worded message of each field an API error names, by field path. */\nexport function fieldErrorsOf<L extends string>(\n\terrors: Pick<ApiErrors<L>, 'apiErrorMessage' | 'translateCode'>,\n\terror: Parameters<ApiErrors<L>['fieldErrors']>[0],\n\tlanguage: L,\n): ReturnType<ApiErrors<L>['fieldErrors']> {\n\tconst extensions = error.errors[0]?.extensions;\n\tconst fields = Array.isArray(extensions?.fields) ? extensions.fields : [];\n\tif (!fields.length && extensions?.field) {\n\t\treturn { [extensions.field]: errors.apiErrorMessage(error, language) };\n\t}\n\treturn Object.fromEntries(\n\t\tfields.map(({ path, code, message, params }) => [\n\t\t\tpath,\n\t\t\terrors.translateCode(code, message, language, params),\n\t\t]),\n\t);\n}\n",
7
- "import { data } from 'react-router';\nimport { isApiErrorLike } from './api-error';\nimport type { ApiErrors, ApiRefusal } from './api-errors';\nimport { type RouteErrorOptions, routeError } from './route-error';\n\n/**\n * A fetcher's refusal: the API's (`apiRefusal`), an unreachable API's too,\n * so the page stays where it was. A 401 (the session caller redirects\n * first) or any other failure is thrown, for the error page.\n */\nexport function fetcherRefusal<L extends string>(\n\terrors: Pick<ApiErrors<L>, 'apiRefusal'>,\n\terror: unknown,\n\tlanguage: L,\n\troute?: RouteErrorOptions,\n): ApiRefusal {\n\tconst refusal =\n\t\tisApiErrorLike(error) && error.status === 401\n\t\t\t? undefined\n\t\t\t: errors.apiRefusal(error, language);\n\tif (!refusal) throw routeError(error, route);\n\treturn refusal;\n}\n\n/** What `fetcherResult` takes after `run`: `routeError`'s options, and a rewording. */\nexport interface FetcherResultOptions extends RouteErrorOptions {\n\t/**\n\t * Words the refusal of this call: given the caught API error, the message\n\t * to answer, or `undefined` to keep the worded one. The status is the\n\t * refusal's. Not called for what is thrown to the error page.\n\t */\n\treword?: (error: unknown) => string | undefined;\n}\n\n/**\n * Runs the mutation of an action a fetcher posted to: `{ ok: true }` with\n * `about` and the mutation's value, or the refusal (`fetcherRefusal`) as a\n * worded `error`, with its HTTP status, for a toast or a form message.\n */\nexport async function fetcherResult<\n\tL extends string,\n\tAbout extends object,\n\tValue extends object = Record<never, never>,\n>(\n\terrors: Pick<ApiErrors<L>, 'apiRefusal'>,\n\tlanguage: L,\n\tabout: About,\n\trun: () => Promise<Value>,\n\toptions?: FetcherResultOptions,\n) {\n\ttry {\n\t\treturn { ok: true as const, ...about, ...(await run()) };\n\t} catch (error) {\n\t\tconst { message, status } = fetcherRefusal(\n\t\t\terrors,\n\t\t\terror,\n\t\t\tlanguage,\n\t\t\toptions,\n\t\t);\n\t\treturn data(\n\t\t\t{\n\t\t\t\tok: false as const,\n\t\t\t\t...about,\n\t\t\t\terror: options?.reword?.(error) ?? message,\n\t\t\t},\n\t\t\t{ status },\n\t\t);\n\t}\n}\n",
7
+ "import { data } from 'react-router';\nimport { type ApiErrorLike, isApiErrorLike } from './api-error';\nimport type { ApiErrors, ApiRefusal } from './api-errors';\nimport { type RouteErrorOptions, routeError } from './route-error';\n\n/**\n * A fetcher's refusal: the API's (`apiRefusal`), an unreachable API's too,\n * so the page stays where it was. A 401 (the session caller redirects\n * first) or any other failure is thrown, for the error page.\n */\nexport function fetcherRefusal<L extends string>(\n\terrors: Pick<ApiErrors<L>, 'apiRefusal'>,\n\terror: unknown,\n\tlanguage: L,\n\troute?: RouteErrorOptions,\n): ApiRefusal {\n\tconst refusal =\n\t\tisApiErrorLike(error) && error.status === 401\n\t\t\t? undefined\n\t\t\t: errors.apiRefusal(error, language);\n\tif (!refusal) throw routeError(error, route);\n\treturn refusal;\n}\n\n/** What `fetcherResult` takes after `run`: `routeError`'s options, and a rewording. */\nexport interface FetcherResultOptions extends RouteErrorOptions {\n\t/**\n\t * Words the refusal of this call: given the caught API error, the message\n\t * to answer, or `undefined` to keep the worded one. The status is the\n\t * refusal's. Called for an API's own refusal only: not for an API it\n\t * cannot reach or any other failure, nor for what is thrown to the error\n\t * page.\n\t */\n\treword?: (error: ApiErrorLike) => string | undefined;\n}\n\n/**\n * Runs the mutation of an action a fetcher posted to: `{ ok: true }` with\n * `about` and the mutation's value, or the refusal (`fetcherRefusal`) as a\n * worded `error`, with its HTTP status, for a toast or a form message.\n */\nexport async function fetcherResult<\n\tL extends string,\n\tAbout extends object,\n\tValue extends object = Record<never, never>,\n>(\n\terrors: Pick<ApiErrors<L>, 'apiRefusal'>,\n\tlanguage: L,\n\tabout: About,\n\trun: () => Promise<Value>,\n\toptions?: FetcherResultOptions,\n) {\n\ttry {\n\t\treturn { ok: true as const, ...about, ...(await run()) };\n\t} catch (error) {\n\t\tconst { message, status } = fetcherRefusal(\n\t\t\terrors,\n\t\t\terror,\n\t\t\tlanguage,\n\t\t\toptions,\n\t\t);\n\t\treturn data(\n\t\t\t{\n\t\t\t\tok: false as const,\n\t\t\t\t...about,\n\t\t\t\terror:\n\t\t\t\t\t(isApiErrorLike(error) ? options?.reword?.(error) : undefined) ??\n\t\t\t\t\tmessage,\n\t\t\t},\n\t\t\t{ status },\n\t\t);\n\t}\n}\n",
8
8
  "import { data } from 'react-router';\nimport { isApiErrorLike } from './api-error';\nimport type { ApiErrors } from './api-errors';\nimport type { FormErrors } from './form-errors';\nimport { type RouteErrorOptions, routeError } from './route-error';\n\n/**\n * Runs a form's mutation. An `ApiError` becomes the form's errors: each\n * refused field (`extensions.fields`, or the one `extensions.field` names)\n * under the form field `fieldOf` names (else on the form), and any other\n * code as the form's message. A 404 about none of the form's fields (the\n * record itself is gone), a 401 and other failures go to the error page.\n */\nexport async function submitForm<L extends string, T>(\n\terrors: Pick<ApiErrors<L>, 'apiErrorMessage' | 'fieldErrors'>,\n\tlanguage: L,\n\trun: () => Promise<T>,\n\tfieldOf: (path: string) => string | undefined,\n\troute?: RouteErrorOptions,\n): Promise<{ ok: true; value: T } | ReturnType<typeof data<FormErrors>>> {\n\ttry {\n\t\treturn { ok: true, value: await run() };\n\t} catch (error) {\n\t\tif (!isApiErrorLike(error) || error.status === 401) {\n\t\t\tthrow routeError(error, route);\n\t\t}\n\t\tconst field = error.errors[0]?.extensions?.field;\n\t\tif (error.status === 404 && !(field && fieldOf(field))) {\n\t\t\tthrow routeError(error, route);\n\t\t}\n\t\tconst byField: Record<string, string> = {};\n\t\tconst unplaced: string[] = [];\n\t\tfor (const [path, message] of Object.entries(\n\t\t\terrors.fieldErrors(error, language),\n\t\t)) {\n\t\t\tconst field = fieldOf(path);\n\t\t\tif (field) byField[field] = message;\n\t\t\telse unplaced.push(message);\n\t\t}\n\t\tconst formError =\n\t\t\tObject.keys(byField).length && !unplaced.length\n\t\t\t\t? undefined\n\t\t\t\t: [errors.apiErrorMessage(error, language), ...unplaced].join(' ');\n\t\treturn data({ fieldErrors: byField, formError }, { status: error.status });\n\t}\n}\n",
9
9
  "import { valuesOf } from './api-error';\nimport type { ApiErrors, ApiErrorsOptions } from './api-errors';\nimport { API_CODE } from './code-resolver';\nimport { fieldErrorsOf, refusalOf } from './describe-refusal';\nimport { fetcherRefusal, fetcherResult } from './fetcher-result';\nimport { submitForm } from './submit-form';\n\nexport function describeApiErrors<L extends string>({\n\tmessages,\n\tunavailable,\n\trefused,\n\treword,\n\tbyCode = {},\n\tisApiCode = (code) => API_CODE.test(code),\n}: ApiErrorsOptions<L>): ApiErrors<L> {\n\tconst translateCode: ApiErrors<L>['translateCode'] = (\n\t\tcode,\n\t\tfallback,\n\t\tlanguage,\n\t\tvalues,\n\t) => {\n\t\tif (!code) return fallback;\n\t\treturn messages.apiMessage(code, values, language) ?? fallback;\n\t};\n\n\tconst apiErrorMessage: ApiErrors<L>['apiErrorMessage'] = (\n\t\terror,\n\t\tlanguage,\n\t) => {\n\t\tconst code = error.code;\n\t\tif (refused && (!code || !isApiCode(code))) return refused(language);\n\t\tconst own = code && Object.hasOwn(byCode, code) ? byCode[code] : undefined;\n\t\tconst values = valuesOf(error.errors[0]?.extensions);\n\t\tconst text = own\n\t\t\t? own(error, language)\n\t\t\t: translateCode(code, error.message, language, values);\n\t\tif (!reword || !code) return text;\n\t\treturn (\n\t\t\treword(text, error, { code, values: values ?? {}, language }) ?? text\n\t\t);\n\t};\n\n\tconst unavailableMessage = (language: L) => unavailable(language);\n\n\tconst apiRefusal: ApiErrors<L>['apiRefusal'] = (error, language) =>\n\t\trefusalOf({ apiErrorMessage, unavailableMessage }, error, language);\n\n\tconst fieldErrors: ApiErrors<L>['fieldErrors'] = (error, language) =>\n\t\tfieldErrorsOf({ apiErrorMessage, translateCode }, error, language);\n\n\tconst parts = { apiRefusal, apiErrorMessage, fieldErrors };\n\n\treturn {\n\t\ttranslateCode,\n\t\tapiErrorMessage,\n\t\tunavailableMessage,\n\t\tfieldErrors,\n\t\tapiRefusal,\n\t\tfetcherRefusal: (error, language, route) =>\n\t\t\tfetcherRefusal(parts, error, language, route),\n\t\tfetcherResult: (language, about, run, options) =>\n\t\t\tfetcherResult(parts, language, about, run, options),\n\t\tsubmitForm: (language, run, fieldOf, route) =>\n\t\t\tsubmitForm(parts, language, run, fieldOf, route),\n\t};\n}\n",
10
- "import type { data } from 'react-router';\nimport type { ApiErrorLike } from './api-error';\nimport { describeApiErrors } from './describe';\nimport type { FetcherResultOptions } from './fetcher-result';\nimport type { FormErrors } from './form-errors';\nimport type { ApiMessages } from './messages';\nimport type { RouteErrorOptions } from './route-error';\n\n/** A refused call, as a page says it: the message, and the HTTP status to answer. */\nexport type ApiRefusal = { message: string; status: number };\n\nexport interface ApiErrorsOptions<L extends string> {\n\t/** The catalogue the API's codes are worded from. */\n\tmessages: ApiMessages<L>;\n\t/**\n\t * The app's own word for an API it cannot reach (a 503 `Response`): not\n\t * an API error, so never one of the catalogue's codes.\n\t */\n\tunavailable(language: L): string;\n\t/**\n\t * The app's generic refusal, said for an error with no API code (a raw\n\t * `BAD_USER_INPUT` before the API's validation layer), never the raw\n\t * message. Without it, such an error says the message the API sent.\n\t */\n\trefused?(language: L): string;\n\t/**\n\t * An app's own wording for given codes, such as the API's request limits\n\t * (depth, cost, introspection), whose params differ and name no field.\n\t * Checked after `refused`, before the catalogue.\n\t */\n\tbyCode?: Readonly<\n\t\tRecord<string, (error: ApiErrorLike, language: L) => string>\n\t>;\n\t/**\n\t * Words a whole family of codes once, after the text is worded. It runs\n\t * on the final text `apiErrorMessage` (so `apiRefusal`, `fetcherResult`,\n\t * `fetcherRefusal`, `submitForm` and a single `extensions.field`) says\n\t * for an error with a code, whichever produced it: the catalogue, the\n\t * API's own message, or `byCode`. It does not run on `refused`'s text, on\n\t * `unavailable`'s (a network failure), on `translateCode` nor on the\n\t * entries of `extensions.fields`. `values` are the merged values the\n\t * catalogue formats with (`extensions` and `extensions.params`, params\n\t * winning). Return the text to show, or `undefined` to keep `text`.\n\t */\n\treword?(\n\t\ttext: string,\n\t\terror: ApiErrorLike,\n\t\tcontext: {\n\t\t\tcode: string;\n\t\t\tvalues: Readonly<Record<string, unknown>>;\n\t\t\tlanguage: L;\n\t\t},\n\t): string | undefined;\n\t/** Whether a code is an API code; `<module>.errors.<slug>` by default. */\n\tisApiCode?(code: string): boolean;\n}\n\n/** What a page says of an API's refusals, in a language. */\nexport interface ApiErrors<L extends string> {\n\t/**\n\t * The catalogue's text of an API code in `language`, else `fallback` (the\n\t * message the API already worded). `values` are the message's arguments\n\t * (`extensions.params`).\n\t */\n\ttranslateCode(\n\t\tcode: string | undefined,\n\t\tfallback: string,\n\t\tlanguage: L,\n\t\tvalues?: Readonly<Record<string, unknown>>,\n\t): string;\n\t/**\n\t * What to show for an API error: `refused` for an error with no API code,\n\t * when given; else `byCode`'s wording of its code; else the catalogue's\n\t * text; else the message the API already worded.\n\t */\n\tapiErrorMessage(error: ApiErrorLike, language: L): string;\n\t/**\n\t * The message of each refused field, by input path, ready for a form: the\n\t * entries of `extensions.fields`, else the one field `extensions.field`\n\t * names, with the error's own message. Empty for neither.\n\t */\n\tfieldErrors(error: ApiErrorLike, language: L): Record<string, string>;\n\t/** `unavailable`, in `language`. */\n\tunavailableMessage(language: L): string;\n\t/**\n\t * What a failed call says to the user: an API refusal's message and its\n\t * status, or an API it cannot reach (a 503 `Response`: the unavailable\n\t * word). Undefined for anything else, which the caller rethrows.\n\t */\n\tapiRefusal(error: unknown, language: L): ApiRefusal | undefined;\n\t/**\n\t * A fetcher's refusal: `apiRefusal`'s, so the page stays where it was. A\n\t * 401 (the session caller redirects first) or any other failure is\n\t * thrown, through `routeError`, for the error page.\n\t */\n\tfetcherRefusal(\n\t\terror: unknown,\n\t\tlanguage: L,\n\t\troute?: RouteErrorOptions,\n\t): ApiRefusal;\n\t/**\n\t * Runs the mutation of an action a fetcher posted to: `{ ok: true }` with\n\t * `about` and the mutation's value, or `{ ok: false, error }` with `about`\n\t * and the refusal's message, answered with its HTTP status. `options.reword`\n\t * words the refusal of this call from the caught error (`undefined` keeps\n\t * the worded message).\n\t */\n\tfetcherResult<\n\t\tAbout extends object,\n\t\tValue extends object = Record<never, never>,\n\t>(\n\t\tlanguage: L,\n\t\tabout: About,\n\t\trun: () => Promise<Value>,\n\t\toptions?: FetcherResultOptions,\n\t): Promise<\n\t\t| ({ ok: true } & About & Value)\n\t\t| ReturnType<typeof data<{ ok: false; error: string } & About>>\n\t>;\n\t/**\n\t * Runs a form's mutation: `{ ok: true, value }`, or the form's errors\n\t * (`fieldErrors` under the form field `fieldOf` names an input path by,\n\t * and a `formError` for the rest) with the refusal's status. A 404 about\n\t * none of the form's fields, a 401 and other failures are thrown for the\n\t * error page, through `routeError` (with `route`).\n\t */\n\tsubmitForm<T>(\n\t\tlanguage: L,\n\t\trun: () => Promise<T>,\n\t\tfieldOf: (path: string) => string | undefined,\n\t\troute?: RouteErrorOptions,\n\t): Promise<{ ok: true; value: T } | ReturnType<typeof data<FormErrors>>>;\n}\n\n/**\n * The wording of an API's refusals for the languages `L`, from the\n * catalogue `messages` holds. Make one per app, beside its `createApiMessages`.\n */\nexport function createApiErrors<L extends string>(\n\toptions: ApiErrorsOptions<L>,\n): ApiErrors<L> {\n\treturn describeApiErrors(options);\n}\n",
10
+ "import type { data } from 'react-router';\nimport type { ApiErrorLike } from './api-error';\nimport { describeApiErrors } from './describe';\nimport type { FetcherResultOptions } from './fetcher-result';\nimport type { FormErrors } from './form-errors';\nimport type { ApiMessages } from './messages';\nimport type { RouteErrorOptions } from './route-error';\n\n/** A refused call, as a page says it: the message, and the HTTP status to answer. */\nexport type ApiRefusal = { message: string; status: number };\n\nexport interface ApiErrorsOptions<L extends string> {\n\t/** The catalogue the API's codes are worded from. */\n\tmessages: ApiMessages<L>;\n\t/**\n\t * The app's own word for an API it cannot reach (a 503 `Response`): not\n\t * an API error, so never one of the catalogue's codes.\n\t */\n\tunavailable(language: L): string;\n\t/**\n\t * The app's generic refusal, said for an error with no API code (a raw\n\t * `BAD_USER_INPUT` before the API's validation layer), never the raw\n\t * message. Without it, such an error says the message the API sent.\n\t */\n\trefused?(language: L): string;\n\t/**\n\t * An app's own wording for given codes, such as the API's request limits\n\t * (depth, cost, introspection), whose params differ and name no field.\n\t * Checked after `refused`, before the catalogue.\n\t */\n\tbyCode?: Readonly<\n\t\tRecord<string, (error: ApiErrorLike, language: L) => string>\n\t>;\n\t/**\n\t * Words a whole family of codes once, after the text is worded. It runs\n\t * on the final text `apiErrorMessage` (so `apiRefusal`, `fetcherResult`,\n\t * `fetcherRefusal`, `submitForm` and a single `extensions.field`) says\n\t * for an error with a code, whichever produced it: the catalogue, the\n\t * API's own message, or `byCode`. It does not run on `refused`'s text, on\n\t * `unavailable`'s (a network failure), on `translateCode` nor on the\n\t * entries of `extensions.fields`. `values` are the merged values the\n\t * catalogue formats with (`extensions` and `extensions.params`, params\n\t * winning). Return the text to show, or `undefined` to keep `text`.\n\t */\n\treword?(\n\t\ttext: string,\n\t\terror: ApiErrorLike,\n\t\tcontext: {\n\t\t\tcode: string;\n\t\t\tvalues: Readonly<Record<string, unknown>>;\n\t\t\tlanguage: L;\n\t\t},\n\t): string | undefined;\n\t/** Whether a code is an API code; `<module>.errors.<slug>` by default. */\n\tisApiCode?(code: string): boolean;\n}\n\n/** What a page says of an API's refusals, in a language. */\nexport interface ApiErrors<L extends string> {\n\t/**\n\t * The catalogue's text of an API code in `language`, else `fallback` (the\n\t * message the API already worded). `values` are the message's arguments\n\t * (`extensions.params`).\n\t */\n\ttranslateCode(\n\t\tcode: string | undefined,\n\t\tfallback: string,\n\t\tlanguage: L,\n\t\tvalues?: Readonly<Record<string, unknown>>,\n\t): string;\n\t/**\n\t * What to show for an API error: `refused` for an error with no API code,\n\t * when given; else `byCode`'s wording of its code; else the catalogue's\n\t * text; else the message the API already worded.\n\t */\n\tapiErrorMessage(error: ApiErrorLike, language: L): string;\n\t/**\n\t * The message of each refused field, by input path, ready for a form: the\n\t * entries of `extensions.fields`, else the one field `extensions.field`\n\t * names, with the error's own message. Empty for neither.\n\t */\n\tfieldErrors(error: ApiErrorLike, language: L): Record<string, string>;\n\t/** `unavailable`, in `language`. */\n\tunavailableMessage(language: L): string;\n\t/**\n\t * What a failed call says to the user: an API refusal's message and its\n\t * status, or an API it cannot reach (a 503 `Response`: the unavailable\n\t * word). Undefined for anything else, which the caller rethrows.\n\t */\n\tapiRefusal(error: unknown, language: L): ApiRefusal | undefined;\n\t/**\n\t * A fetcher's refusal: `apiRefusal`'s, so the page stays where it was. A\n\t * 401 (the session caller redirects first) or any other failure is\n\t * thrown, through `routeError`, for the error page.\n\t */\n\tfetcherRefusal(\n\t\terror: unknown,\n\t\tlanguage: L,\n\t\troute?: RouteErrorOptions,\n\t): ApiRefusal;\n\t/**\n\t * Runs the mutation of an action a fetcher posted to: `{ ok: true }` with\n\t * `about` and the mutation's value, or `{ ok: false, error }` with `about`\n\t * and the refusal's message, answered with its HTTP status. `options.reword`\n\t * words the refusal of this call from the caught API error (`undefined`\n\t * keeps the worded message); it is not called for an unreachable API.\n\t */\n\tfetcherResult<\n\t\tAbout extends object,\n\t\tValue extends object = Record<never, never>,\n\t>(\n\t\tlanguage: L,\n\t\tabout: About,\n\t\trun: () => Promise<Value>,\n\t\toptions?: FetcherResultOptions,\n\t): Promise<\n\t\t| ({ ok: true } & About & Value)\n\t\t| ReturnType<typeof data<{ ok: false; error: string } & About>>\n\t>;\n\t/**\n\t * Runs a form's mutation: `{ ok: true, value }`, or the form's errors\n\t * (`fieldErrors` under the form field `fieldOf` names an input path by,\n\t * and a `formError` for the rest) with the refusal's status. A 404 about\n\t * none of the form's fields, a 401 and other failures are thrown for the\n\t * error page, through `routeError` (with `route`).\n\t */\n\tsubmitForm<T>(\n\t\tlanguage: L,\n\t\trun: () => Promise<T>,\n\t\tfieldOf: (path: string) => string | undefined,\n\t\troute?: RouteErrorOptions,\n\t): Promise<{ ok: true; value: T } | ReturnType<typeof data<FormErrors>>>;\n}\n\n/**\n * The wording of an API's refusals for the languages `L`, from the\n * catalogue `messages` holds. Make one per app, beside its `createApiMessages`.\n */\nexport function createApiErrors<L extends string>(\n\toptions: ApiErrorsOptions<L>,\n): ApiErrors<L> {\n\treturn describeApiErrors(options);\n}\n",
11
11
  "/** The methods of a `console` a report goes through. */\nexport type LogMethod = 'warn' | 'error';\n\n/**\n * A log whose methods can throw without breaking what reports through\n * them: a broken app log must not turn a handled failure into a rejection.\n */\nexport function quietLog<M extends LogMethod>(\n\tlog: Pick<Console, M>,\n\tmethods: readonly M[],\n): Pick<Console, M> {\n\tconst quiet = {} as Pick<Console, M>;\n\tfor (const method of methods) {\n\t\tquiet[method] = ((...args: unknown[]) => {\n\t\t\ttry {\n\t\t\t\t(log[method] as (...args: unknown[]) => void)(...args);\n\t\t\t} catch {\n\t\t\t\t// Swallowed on purpose: see above.\n\t\t\t}\n\t\t}) as Pick<Console, M>[M];\n\t}\n\treturn quiet;\n}\n",
12
12
  "import { isApiErrorLike, isStatusError, isUnavailableError } from './api-error';\nimport { quietLog } from './log';\nimport { REQUEST_ID_HEADER } from './request-id';\n\n/** The statuses an API's gateway or auth layer may answer without a GraphQL body. */\nconst PASSED_THROUGH: ReadonlySet<number> = new Set([401, 403, 404]);\n\n/** The statuses a `Response` cannot carry a body with. */\nconst NO_BODY: ReadonlySet<number> = new Set([101, 204, 205, 304]);\n\nexport interface CallFailureOptions {\n\t/** What a log line names the API by, such as `my-api https://api.example.com/graphql`. */\n\tapi: string;\n\t/** The operation's name, for the log (`operationName(document)`). */\n\toperation?: string;\n\t/** The `x-request-id` the API answered, when it did (`requestIdOf(response)`). */\n\trequestId?: string;\n\t/** The incoming request's signal: an aborted call is answered 503. */\n\tsignal?: AbortSignal;\n\t/** The statuses without a GraphQL body that become a `Response` of their own; 401, 403 and 404 by default. */\n\tpassedThrough?: ReadonlySet<number>;\n\t/** Where the lines go; `console` by default. */\n\tlog?: Pick<Console, 'warn' | 'error'>;\n}\n\n/**\n * What a call became once it failed, for a loader or an action to throw: the\n * `ApiError` as it is (carrying `requestId`), a `Response` of the API's own\n * status for a 401, 403 or 404 without a GraphQL body, a 503 `Response` (with no body; the reason is in the log) for an\n * unreachable, slow, garbled or aborted API, and any other error as it is.\n * Every case it recognises is logged with the request id, when the API gave one, and never\n * the headers, the variables nor a token; the id rides on the `ApiError` as\n * `requestId` and on a `Response` as `x-request-id`, where `routeError` reads\n * it.\n *\n * It recognises `@nxgt/graphql-client`'s errors by their `name`, never with\n * `instanceof`, so it needs no import of the client and holds across two\n * copies of it.\n */\nexport function apiCallFailure(\n\terror: unknown,\n\t{\n\t\tapi,\n\t\toperation = 'operation',\n\t\trequestId,\n\t\tsignal,\n\t\tpassedThrough = PASSED_THROUGH,\n\t\tlog: appLog = console,\n\t}: CallFailureOptions,\n): unknown {\n\tconst log = quietLog(appLog, ['warn', 'error']);\n\tconst call = `${api}: ${operation}${requestId ? ` (request ${requestId})` : ''}`;\n\tconst headers: Record<string, string> = requestId\n\t\t? { [REQUEST_ID_HEADER]: requestId }\n\t\t: {};\n\tconst unavailable = (reason: string, cause?: unknown): Response => {\n\t\tlog.error(`${call} ${reason}`, cause ?? '');\n\t\treturn new Response(null, { status: 503, headers });\n\t};\n\tif (isApiErrorLike(error)) {\n\t\t// The client's `ApiError.requestId` is writable, though the structural type marks it readonly.\n\t\tif (requestId) (error as { requestId?: string }).requestId = requestId;\n\t\tconst line = `${call} answered ${error.status}${error.code ? ` ${error.code}` : ''}`;\n\t\tif (error.status >= 500) log.error(line);\n\t\telse log.warn(line);\n\t\treturn error;\n\t}\n\tif (isStatusError(error)) {\n\t\tif (passedThrough.has(error.status)) {\n\t\t\tlog.warn(`${call} answered ${error.status}`);\n\t\t\tconst statusText =\n\t\t\t\ttypeof error.statusText === 'string' ? error.statusText : '';\n\t\t\tif (NO_BODY.has(error.status)) {\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: error.status,\n\t\t\t\t\tstatusText,\n\t\t\t\t\theaders,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new Response(statusText, {\n\t\t\t\tstatus: error.status,\n\t\t\t\tstatusText,\n\t\t\t\theaders,\n\t\t\t});\n\t\t}\n\t\treturn unavailable(`answered ${error.status} without GraphQL`, error.body);\n\t}\n\tif (isUnavailableError(error)) return unavailable(error.reason, error.cause);\n\tif (signal?.aborted) return unavailable('aborted', error);\n\treturn error;\n}\n\n/** A document, as far as `operationName` reads it: `graphql`'s `DocumentNode` fits. */\nexport interface DocumentLike {\n\treadonly definitions: readonly {\n\t\treadonly kind: string;\n\t\treadonly operation?: string | undefined;\n\t\treadonly name?: { readonly value: string } | undefined;\n\t}[];\n}\n\n/**\n * The name of the operation a document holds, for a log line: its name, else\n * its kind (`query`, `mutation`, `subscription`), else `operation`.\n */\nexport function operationName(document: DocumentLike): string {\n\tfor (const definition of document.definitions) {\n\t\tif (definition.kind === 'OperationDefinition') {\n\t\t\treturn definition.name?.value ?? definition.operation ?? 'operation';\n\t\t}\n\t}\n\treturn 'operation';\n}\n",
13
13
  "import type { Held } from './catalogue-read';\n\n/** What the TTL check needs: the reader's state and the app's own calls. */\nexport interface CheckContext<L extends string> {\n\treader: {\n\t\theld: Map<L, Held>;\n\t\tload(language: L, now: number): Promise<void>;\n\t};\n\tversions(): Promise<Partial<Record<L, string>>>;\n\tttl(): number;\n\tretryMs: number;\n\tlog: Pick<Console, 'error'>;\n}\n\n/**\n * Asks the versions in one call and reads again the messages of each\n * language that moved. An API that cannot be reached keeps the messages\n * held (stale, still worded) and is asked again after `retryMs`.\n */\nexport async function checkVersions<L extends string>(\n\t{ reader, versions, ttl, retryMs, log }: CheckContext<L>,\n\tnow: number,\n) {\n\ttry {\n\t\tconst latest = await versions();\n\t\tfor (const [language, entry] of [...reader.held]) {\n\t\t\tif (latest[language] !== entry.version) {\n\t\t\t\tawait reader.load(language, now);\n\t\t\t} else {\n\t\t\t\tentry.checkedAt = now;\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tlog.error(\n\t\t\t'alxia-react-router: the error catalogue was not checked, keeping what is held',\n\t\t\terror,\n\t\t);\n\t\tfor (const entry of reader.held.values()) {\n\t\t\tentry.checkedAt = now - ttl() + retryMs;\n\t\t}\n\t}\n}\n\n/**\n * The TTL, whose getter is the app's: one that throws, or that is not a\n * finite number of at least 0, is logged and `fallback` is used.\n */\nexport function safeTtl(\n\tttlMs: number | (() => number),\n\tfallback: number,\n\tlog: Pick<Console, 'error'>,\n) {\n\treturn () => {\n\t\ttry {\n\t\t\tconst ttl = typeof ttlMs === 'function' ? ttlMs() : ttlMs;\n\t\t\tif (typeof ttl === 'number' && Number.isFinite(ttl) && ttl >= 0) {\n\t\t\t\treturn ttl;\n\t\t\t}\n\t\t\tlog.error('alxia-react-router: ttlMs is not a duration, using retryMs');\n\t\t} catch (error) {\n\t\t\tlog.error('alxia-react-router: ttlMs threw, using retryMs', error);\n\t\t}\n\t\treturn fallback;\n\t};\n}\n",
@@ -19,7 +19,7 @@
19
19
  "import type { ReactNode } from 'react';\nimport type { ApiMessages, CatalogueMessages } from './messages';\n\nexport interface ApiMessagesProviderProps<L extends string> {\n\t/** The store `apiCodeResolver` reads. */\n\tmessages: ApiMessages<L>;\n\t/** The messages the root's data carries, by language. */\n\tvalue: Readonly<Record<L, CatalogueMessages>> | undefined;\n\tchildren: ReactNode;\n}\n\n/**\n * Fills the browser's catalogue with the messages the root's data carries\n * (the few its forms word), before the children render: `apiCodeResolver`\n * reads them synchronously. A server render writes nothing: the server's\n * store holds the whole, fresher catalogue, and a render's data may be older\n * than it. It is a plain function (no JSX, no React runtime): use it as\n * `ApiMessagesProvider({ messages, value, children })` from a component, or\n * as an element's type.\n */\nexport function ApiMessagesProvider<L extends string>({\n\tmessages,\n\tvalue,\n\tchildren,\n}: ApiMessagesProviderProps<L>): ReactNode {\n\tconst inBrowser =\n\t\ttypeof (globalThis as { document?: unknown }).document !== 'undefined';\n\tif (value && inBrowser) {\n\t\tfor (const [language, held] of Object.entries<CatalogueMessages>(value)) {\n\t\t\tmessages.add(language as L, held);\n\t\t}\n\t}\n\treturn children;\n}\n",
20
20
  "import { type FetcherWithComponents, useFetcher } from 'react-router';\n\n/** What a fetcher can post as JSON. */\nexport type JsonBody = Parameters<FetcherWithComponents<unknown>['submit']>[0];\n\n/**\n * A fetcher posting JSON to its page's action (which reads it with\n * `readJson`, and answers `fetcherResult` or the like): `post` sends a\n * body, `busy` while it is in flight. `key` shares the fetcher between the\n * form that posts and the component that reads the answer; `action` posts to\n * another route's action instead (a resource route's, such as a\n * `notifications/poll`). `post` takes the target of one call as its second\n * argument (a list's rows each post to their own record's action).\n */\nexport function useJsonFetcher<Action, Body extends JsonBody = JsonBody>(\n\tkey?: string,\n\taction?: string,\n): {\n\tfetcher: ReturnType<typeof useFetcher<Action>>;\n\tpost(body: Body, to?: string): Promise<void>;\n\tbusy: boolean;\n} {\n\tconst fetcher = useFetcher<Action>(key ? { key } : undefined);\n\tconst post = (body: Body, to = action) =>\n\t\tfetcher.submit(body, {\n\t\t\tmethod: 'post',\n\t\t\tencType: 'application/json',\n\t\t\t...(to ? { action: to } : {}),\n\t\t});\n\treturn { fetcher, post, busy: fetcher.state !== 'idle' };\n}\n"
21
21
  ],
22
- "mappings": ";;;;;;;;;;;;;;;;;AAgBO,IAAM,WAAW;AA8BxB,SAAS,UAAU,CAAC,OAAsB;AAAA,EACzC,MAAM,OAAQ,MAAM,QAA2C;AAAA,EAC/D,OAAO,OAAO,SAAS,WAAW,OAAO;AA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A,MACP,WAAW,MAAM;AAAA;AAAA,IAElB;AAAA,IACA,QAAQ;AAAA,IACR,UAAU,CAAC,MAAM,QAAQ,UAAU;AAAA,MAClC,MAAM,QAAQ,UAAU,UAAU,IAAI;AAAA,MACtC,OAAO,QAAQ,YAAY,OAAO,QAAQ,QAAQ,IAAI;AAAA;AAAA,EAExD;AAAA;;AC3GM,SAAS,mBAAqC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,GAC0C;AAAA,EAC1C,MAAM,YACL,OAAQ,WAAsC,aAAa;AAAA,EAC5D,IAAI,SAAS,WAAW;AAAA,IACvB,YAAY,UAAU,SAAS,OAAO,QAA2B,KAAK,GAAG;AAAA,MACxE,SAAS,IAAI,UAAe,IAAI;AAAA,IACjC;AAAA,EACD;AAAA,EACA,OAAO;AAAA;;AChCR;AAcO,SAAS,cAAwD,CACvE,KACA,QAKC;AAAA,EACD,MAAM,UAAU,WAAmB,MAAM,EAAE,IAAI,IAAI,SAAS;AAAA,EAC5D,MAAM,OAAO,CAAC,MAAY,KAAK,WAC9B,QAAQ,OAAO,MAAM;AAAA,IACpB,QAAQ;AAAA,IACR,SAAS;AAAA,OACL,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;AAAA,EAC5B,CAAC;AAAA,EACF,OAAO,EAAE,SAAS,MAAM,MAAM,QAAQ,UAAU,OAAO;AAAA;",
23
+ "debugId": "BCEFF30EF289759264756E2164756E21",
24
24
  "names": []
25
25
  }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `@alxia/react-router/fetcher`: the hooks around a React Router fetcher's
3
- * answers. `react` is its only import (a fetcher is read structurally), and
4
- * every hook renders on the server.
3
+ * answers. `react` and `react-router` are its imports, and every hook renders
4
+ * on the server (a load starts in the browser only).
5
5
  */
6
+ export { type DebouncedFetcher, type DebouncedFetcherOptions, type DebouncedFetcherState, useDebouncedFetcher, } from './use-debounced-fetcher';
6
7
  export { type AnswerSource, useFetcherAnswer } from './use-fetcher-answer';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,12 +1,65 @@
1
+ // src/fetcher/use-debounced-fetcher.ts
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { useFetcher } from "react-router";
4
+ function useDebouncedFetcher(value, to, options = {}) {
5
+ const { delayMs = 250, minLength = 1, enabled = true, key, keep } = options;
6
+ const keepRef = useRef(keep);
7
+ keepRef.current = keep;
8
+ const fetcher = useFetcher(key === undefined ? undefined : { key });
9
+ const load = useRef(fetcher.load);
10
+ load.current = fetcher.load;
11
+ const text = value.trim();
12
+ const url = enabled && text.length >= minLength ? typeof to === "function" ? to(text) : to : null;
13
+ const [loaded, setLoaded] = useState(null);
14
+ const previous = useRef(undefined);
15
+ useEffect(() => {
16
+ if (url === null) {
17
+ previous.current = undefined;
18
+ setLoaded(null);
19
+ return;
20
+ }
21
+ const timer = setTimeout(() => {
22
+ setLoaded(url);
23
+ load.current(url);
24
+ }, delayMs);
25
+ return () => clearTimeout(timer);
26
+ }, [url, text, delayMs]);
27
+ const current = url !== null && loaded === url && fetcher.state === "idle" && fetcher.data !== undefined;
28
+ const answer = current ? fetcher.data : undefined;
29
+ useEffect(() => {
30
+ if (answer === undefined || answer === null)
31
+ return;
32
+ if (keepRef.current?.(answer) ?? true)
33
+ previous.current = answer;
34
+ }, [answer]);
35
+ const data = current ? answer : url === null ? undefined : previous.current;
36
+ let state;
37
+ if (url === null)
38
+ state = "idle";
39
+ else if (loaded !== url)
40
+ state = "waiting";
41
+ else
42
+ state = fetcher.state === "idle" ? "done" : "loading";
43
+ const urlRef = useRef(url);
44
+ urlRef.current = url;
45
+ const retry = useCallback(() => {
46
+ const now = urlRef.current;
47
+ if (now === null)
48
+ return;
49
+ setLoaded(now);
50
+ load.current(now);
51
+ }, []);
52
+ return { data, stale: state !== "done" && data !== undefined, state, retry };
53
+ }
1
54
  // src/fetcher/use-fetcher-answer.ts
2
- import { useEffect, useRef, useState } from "react";
55
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
3
56
  function useFetcherAnswer(fetcher, onAnswer) {
4
- const seen = useRef(fetcher.data);
5
- const handler = useRef(onAnswer);
57
+ const seen = useRef2(fetcher.data);
58
+ const handler = useRef2(onAnswer);
6
59
  handler.current = onAnswer;
7
- const [latest, setLatest] = useState(undefined);
60
+ const [latest, setLatest] = useState2(undefined);
8
61
  const answer = fetcher.state === "idle" ? fetcher.data : undefined;
9
- useEffect(() => {
62
+ useEffect2(() => {
10
63
  if (answer === undefined || answer === null || answer === seen.current) {
11
64
  return;
12
65
  }
@@ -17,8 +70,9 @@ function useFetcherAnswer(fetcher, onAnswer) {
17
70
  return latest;
18
71
  }
19
72
  export {
73
+ useDebouncedFetcher,
20
74
  useFetcherAnswer
21
75
  };
22
76
 
23
- //# debugId=16BED3793BD03C8664756E2164756E21
77
+ //# debugId=FE85A7EF01A4F72B64756E2164756E21
24
78
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/fetcher/use-fetcher-answer.ts"],
3
+ "sources": ["../src/fetcher/use-debounced-fetcher.ts", "../src/fetcher/use-fetcher-answer.ts"],
4
4
  "sourcesContent": [
5
+ "import { useCallback, useEffect, useRef, useState } from 'react';\nimport { useFetcher } from 'react-router';\n\n/** What `useFetcher<Data>` hands back as `data` (`Data` may be `typeof loader`). */\ntype FetcherData<Data> = ReturnType<typeof useFetcher<Data>>['data'];\n\n/** What `useDebouncedFetcher` is doing for the value typed. */\nexport type DebouncedFetcherState =\n\t/** Nothing to ask: disabled, or the value is shorter than `minLength`. */\n\t| 'idle'\n\t/** The value changed and the pause after the last change is running. */\n\t| 'waiting'\n\t/** The resource route is loading. */\n\t| 'loading'\n\t/** The route answered for the value as it stands. */\n\t| 'done';\n\nexport interface DebouncedFetcherOptions<Data = unknown> {\n\t/** Pause after the last change before the route is asked. Default 250. */\n\treadonly delayMs?: number;\n\t/** The trimmed value must have this many characters. Default 1. */\n\treadonly minLength?: number;\n\t/** `false` asks nothing and forgets the previous answer. Default `true`. */\n\treadonly enabled?: boolean;\n\t/** The fetcher's key, to share it with another component. */\n\treadonly key?: string;\n\t/**\n\t * Which answers may be kept as the stale `data` while the next value waits\n\t * or loads. Default: all. An answer it refuses (a failure) is still `data`\n\t * while it is the current one, but is never shown as the previous one: after a refused answer, the stale\n\t * data is the last *kept* answer, not the refused one.\n\t */\n\treadonly keep?: (data: NonNullable<FetcherData<Data>>) => boolean;\n}\n\nexport interface DebouncedFetcher<Data> {\n\t/**\n\t * The route's answer for the value as it stands, else (`stale`) the last\n\t * answer for an earlier value, kept until the new one lands. `undefined`\n\t * before any answer, and again once the hook goes `idle`.\n\t */\n\treadonly data: FetcherData<Data>;\n\t/** `data` answers an earlier value (or none is current yet). */\n\treadonly stale: boolean;\n\treadonly state: DebouncedFetcherState;\n\t/** Asks the route again for the value as it stands, without waiting. */\n\treadonly retry: () => void;\n}\n\n/**\n * A resource route loaded through a fetcher for a value that changes as the\n * user types. After `delayMs` without a change, and from `minLength`\n * characters, it calls `fetcher.load` once (a newer load cancels the\n * previous one). An answer only counts for the value it was asked for: while\n * a newer value waits or loads, `data` is the previous answer with `stale`\n * set, and an answer for an older value is never returned as current.\n * `to` is the route's URL, or a function of the trimmed value that builds it\n * (a string without a function is loaded as it is, the value being only the\n * trigger). A refusal the route answers as data is `data` like any answer.\n */\nexport function useDebouncedFetcher<Data>(\n\tvalue: string,\n\tto: string | ((value: string) => string),\n\toptions: DebouncedFetcherOptions<Data> = {},\n): DebouncedFetcher<Data> {\n\tconst { delayMs = 250, minLength = 1, enabled = true, key, keep } = options;\n\tconst keepRef = useRef(keep);\n\tkeepRef.current = keep;\n\tconst fetcher = useFetcher<Data>(key === undefined ? undefined : { key });\n\tconst load = useRef(fetcher.load);\n\tload.current = fetcher.load;\n\tconst text = value.trim();\n\tconst url =\n\t\tenabled && text.length >= minLength\n\t\t\t? typeof to === 'function'\n\t\t\t\t? to(text)\n\t\t\t\t: to\n\t\t\t: null;\n\t// The URL the fetcher was last told to load.\n\tconst [loaded, setLoaded] = useState<string | null>(null);\n\tconst previous = useRef<FetcherData<Data>>(undefined);\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: the URL and the value are the trigger; `load` is read from a ref\n\tuseEffect(() => {\n\t\tif (url === null) {\n\t\t\tprevious.current = undefined;\n\t\t\tsetLoaded(null);\n\t\t\treturn;\n\t\t}\n\t\tconst timer = setTimeout(() => {\n\t\t\tsetLoaded(url);\n\t\t\tvoid load.current(url);\n\t\t}, delayMs);\n\t\treturn () => clearTimeout(timer);\n\t}, [url, text, delayMs]);\n\n\tconst current =\n\t\turl !== null &&\n\t\tloaded === url &&\n\t\tfetcher.state === 'idle' &&\n\t\tfetcher.data !== undefined;\n\tconst answer = current ? fetcher.data : undefined;\n\tuseEffect(() => {\n\t\tif (answer === undefined || answer === null) return;\n\t\tif (keepRef.current?.(answer) ?? true) previous.current = answer;\n\t}, [answer]);\n\n\tconst data = current ? answer : url === null ? undefined : previous.current;\n\tlet state: DebouncedFetcherState;\n\tif (url === null) state = 'idle';\n\telse if (loaded !== url) state = 'waiting';\n\telse state = fetcher.state === 'idle' ? 'done' : 'loading';\n\n\tconst urlRef = useRef(url);\n\turlRef.current = url;\n\tconst retry = useCallback(() => {\n\t\tconst now = urlRef.current;\n\t\tif (now === null) return;\n\t\tsetLoaded(now);\n\t\tvoid load.current(now);\n\t}, []);\n\treturn { data, stale: state !== 'done' && data !== undefined, state, retry };\n}\n",
5
6
  "import { useEffect, useRef, useState } from 'react';\n\n/** What the hook reads of a React Router fetcher. */\nexport interface AnswerSource<Data> {\n\treadonly state: string;\n\treadonly data: Data | undefined;\n}\n\n/**\n * The answers a fetcher gives, one at a time. A keyed fetcher outlives its\n * component, so the data it holds when the component mounts is an earlier\n * visit's, not this one's. `onAnswer` is called once for each answer that\n * arrives while the fetcher is idle and is another object than the last one\n * seen (the data present at mount counts as seen). The handler is read from\n * a ref, so a new function each render never re-fires it. Returns the latest\n * answer handed over, `undefined` until one arrives.\n */\nexport function useFetcherAnswer<Data>(\n\tfetcher: AnswerSource<Data>,\n\tonAnswer?: (answer: Data) => void,\n): Data | undefined {\n\tconst seen = useRef(fetcher.data);\n\tconst handler = useRef(onAnswer);\n\thandler.current = onAnswer;\n\tconst [latest, setLatest] = useState<Data | undefined>(undefined);\n\tconst answer = fetcher.state === 'idle' ? fetcher.data : undefined;\n\tuseEffect(() => {\n\t\tif (answer === undefined || answer === null || answer === seen.current) {\n\t\t\treturn;\n\t\t}\n\t\tseen.current = answer;\n\t\tsetLatest(answer);\n\t\thandler.current?.(answer);\n\t}, [answer]);\n\treturn latest;\n}\n"
6
7
  ],
7
- "mappings": ";AAAA;AAiBO,SAAS,gBAAsB,CACrC,SACA,UACmB;AAAA,EACnB,MAAM,OAAO,OAAO,QAAQ,IAAI;AAAA,EAChC,MAAM,UAAU,OAAO,QAAQ;AAAA,EAC/B,QAAQ,UAAU;AAAA,EAClB,OAAO,QAAQ,aAAa,SAA2B,SAAS;AAAA,EAChE,MAAM,SAAS,QAAQ,UAAU,SAAS,QAAQ,OAAO;AAAA,EACzD,UAAU,MAAM;AAAA,IACf,IAAI,WAAW,aAAa,WAAW,QAAQ,WAAW,KAAK,SAAS;AAAA,MACvE;AAAA,IACD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
@@ -0,0 +1,57 @@
1
+ import { useFetcher } from 'react-router';
2
+ /** What `useFetcher<Data>` hands back as `data` (`Data` may be `typeof loader`). */
3
+ type FetcherData<Data> = ReturnType<typeof useFetcher<Data>>['data'];
4
+ /** What `useDebouncedFetcher` is doing for the value typed. */
5
+ export type DebouncedFetcherState =
6
+ /** Nothing to ask: disabled, or the value is shorter than `minLength`. */
7
+ 'idle'
8
+ /** The value changed and the pause after the last change is running. */
9
+ | 'waiting'
10
+ /** The resource route is loading. */
11
+ | 'loading'
12
+ /** The route answered for the value as it stands. */
13
+ | 'done';
14
+ export interface DebouncedFetcherOptions<Data = unknown> {
15
+ /** Pause after the last change before the route is asked. Default 250. */
16
+ readonly delayMs?: number;
17
+ /** The trimmed value must have this many characters. Default 1. */
18
+ readonly minLength?: number;
19
+ /** `false` asks nothing and forgets the previous answer. Default `true`. */
20
+ readonly enabled?: boolean;
21
+ /** The fetcher's key, to share it with another component. */
22
+ readonly key?: string;
23
+ /**
24
+ * Which answers may be kept as the stale `data` while the next value waits
25
+ * or loads. Default: all. An answer it refuses (a failure) is still `data`
26
+ * while it is the current one, but is never shown as the previous one: after a refused answer, the stale
27
+ * data is the last *kept* answer, not the refused one.
28
+ */
29
+ readonly keep?: (data: NonNullable<FetcherData<Data>>) => boolean;
30
+ }
31
+ export interface DebouncedFetcher<Data> {
32
+ /**
33
+ * The route's answer for the value as it stands, else (`stale`) the last
34
+ * answer for an earlier value, kept until the new one lands. `undefined`
35
+ * before any answer, and again once the hook goes `idle`.
36
+ */
37
+ readonly data: FetcherData<Data>;
38
+ /** `data` answers an earlier value (or none is current yet). */
39
+ readonly stale: boolean;
40
+ readonly state: DebouncedFetcherState;
41
+ /** Asks the route again for the value as it stands, without waiting. */
42
+ readonly retry: () => void;
43
+ }
44
+ /**
45
+ * A resource route loaded through a fetcher for a value that changes as the
46
+ * user types. After `delayMs` without a change, and from `minLength`
47
+ * characters, it calls `fetcher.load` once (a newer load cancels the
48
+ * previous one). An answer only counts for the value it was asked for: while
49
+ * a newer value waits or loads, `data` is the previous answer with `stale`
50
+ * set, and an answer for an older value is never returned as current.
51
+ * `to` is the route's URL, or a function of the trimmed value that builds it
52
+ * (a string without a function is loaded as it is, the value being only the
53
+ * trigger). A refusal the route answers as data is `data` like any answer.
54
+ */
55
+ export declare function useDebouncedFetcher<Data>(value: string, to: string | ((value: string) => string), options?: DebouncedFetcherOptions<Data>): DebouncedFetcher<Data>;
56
+ export {};
57
+ //# sourceMappingURL=use-debounced-fetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-debounced-fetcher.d.ts","sourceRoot":"","sources":["../../src/fetcher/use-debounced-fetcher.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,oFAAoF;AACpF,KAAK,WAAW,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,+DAA+D;AAC/D,MAAM,MAAM,qBAAqB;AAChC,0EAA0E;AACxE,MAAM;AACR,wEAAwE;GACtE,SAAS;AACX,qCAAqC;GACnC,SAAS;AACX,qDAAqD;GACnD,MAAM,CAAC;AAEV,MAAM,WAAW,uBAAuB,CAAC,IAAI,GAAG,OAAO;IACtD,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,OAAO,CAAC;CAClE;AAED,MAAM,WAAW,gBAAgB,CAAC,IAAI;IACrC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;IACtC,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EACvC,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,EACxC,OAAO,GAAE,uBAAuB,CAAC,IAAI,CAAM,GACzC,gBAAgB,CAAC,IAAI,CAAC,CA0DxB"}
package/docs/README.md CHANGED
@@ -21,7 +21,7 @@ installable and usable offline, wording an API's refusals, the BFF session, a Gr
21
21
  | [An API's refusals](guide/errors.md) | wording a GraphQL API's refusals for the pages: recognising an `ApiError`, the request id, the page a request is for, the catalogue store, the form checks in the API's words, the provider, and the loaders, the error page and the actions that answer with it, the JSON actions with their CSRF check and fetcher hook, calling the API from a loader (`apiCallFailure`), and keeping the catalogue fresh (`@alxia/react-router/errors`) |
22
22
  | [A BFF session](guide/session.md) | redirecting after sign-in to a page of the site and nowhere else, the sign-in pages' paths, the session's cookies, the sign-in flow (where an answer lands, a refused code, the viewer, sign-out; `@alxia/react-router/session`), the pages a mail's link opens (a magic link, a password reset: `authLinks`), the page's hooks (sign-out, a mail link's parameter, a one-code field; `@alxia/react-router/session/react`), the step-up route's signed-out handling (`onSignedOut`), and the step-up's state and the props it gives the UI (`@alxia/react-router/session/model`) |
23
23
  | [Links through React Router](guide/link.md) | `RouterLink`, React Router's `Link` as the link component of a UI library that hands `href` and spreads anchor props; `@alxia/react-router/link` |
24
- | [A fetcher's fresh answer](guide/fetcher.md) | `useFetcherAnswer`, a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `@alxia/react-router/fetcher` |
24
+ | [A fetcher's fresh answer](guide/fetcher.md) | `useFetcherAnswer`, a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useDebouncedFetcher`, a resource route loaded for what is typed (pause, minimum length, stale answer kept, retry); `@alxia/react-router/fetcher` |
25
25
  | [Lists whose state is the URL](guide/lists.md) | a search and filters in the address bar that drop the cursor (`useSearchChange`), a skeleton while the same page reloads (`useSameRouteLoading`), and a load-more button that appends pages by cursor and keeps the rows when one fails (`usePagedRows`); `@alxia/react-router/lists` |
26
26
  | [Subscriptions for a BFF](guide/subscriptions.md) | showing a GraphQL subscription in the browser without giving it the API's token or a way to write a document: a resource route with a map of operation names to the server's documents, the same-site check, the bearer from the session, extra upstream headers, a heartbeat, abort propagation, size limits and a 429 passed through with `retryAfter` (`@alxia/react-router/subscription`) |
27
27
  | [Troubleshooting](troubleshooting.md) | something went wrong and you have the message, or a page streams, hydrates or reads its context unlike you expected |
@@ -506,9 +506,10 @@ with `about` and the value `run` resolved, or `{ ok: false, error }` with
506
506
  unreachable API (a 503 `Response`) is worded too.
507
507
 
508
508
  A module that words one of its API errors its own way passes `reword` as the
509
- last argument: it receives the caught error and returns the message to answer,
510
- or `undefined` to keep the worded one. The status stays the refusal's, and
511
- `reword` is not called for what goes to the error page.
509
+ last argument: it receives the caught API error (an `ApiErrorLike`) and returns
510
+ the message to answer, or `undefined` to keep the worded one. The status stays
511
+ the refusal's. `reword` is called for the API's own refusals only: not for an
512
+ unreachable API or another failure, and not for what goes to the error page.
512
513
 
513
514
  ```ts
514
515
  import { apiErrors } from './api-errors';
@@ -519,7 +520,7 @@ declare function renameTodo(input: unknown): Promise<{ title: string }>;
519
520
  export const rename = (input: unknown) =>
520
521
  apiErrors.fetcherResult('en', { intent: 'rename' }, () => renameTodo(input), {
521
522
  reword: (error) =>
522
- error instanceof Error && error.message.includes('taken')
523
+ error.code === 'todos.errors.title-taken'
523
524
  ? 'Pick another title.'
524
525
  : undefined,
525
526
  });
@@ -4,9 +4,11 @@ A page that posts JSON through a keyed fetcher (`useJsonFetcher('save')`) often
4
4
  reacts to each answer once: a toast, a form error. A keyed fetcher outlives its
5
5
  component, so its data from an earlier visit is still there when the component
6
6
  mounts again, and a plain `useEffect` on `fetcher.data` reacts to it as if it
7
- were new. `@alxia/react-router/fetcher` holds the hook that tells them apart.
8
- `react` is its only import (the fetcher is read structurally), and it renders
9
- on the server.
7
+ were new. `@alxia/react-router/fetcher` holds the hook that tells them apart
8
+ (`useFetcherAnswer`, which reads the fetcher structurally) and the one that
9
+ loads a resource route for what the user types (`useDebouncedFetcher`, below).
10
+ `react` is its only import, plus `react-router` for `useDebouncedFetcher`, and
11
+ both render on the server.
10
12
 
11
13
  ```tsx
12
14
  import { useJsonFetcher } from '@alxia/react-router/errors';
@@ -38,3 +40,59 @@ export function SaveForm() {
38
40
  two objects are two answers, and so is a reloading `fetcher.load`, which
39
41
  hands a new object each time. An answer that comes back as the object seen
40
42
  before (A, B, then A again) is a new answer once B was seen.
43
+
44
+ ## Typeahead: `useDebouncedFetcher(value, to, options?)`
45
+
46
+ A search box, a suggestion list or a preview loads a resource route for what
47
+ the user types. The pattern is always the same: wait for a pause after the last
48
+ keystroke, ask from a minimum length, never act on an answer for older words,
49
+ keep the previous answer on screen while the next one loads, offer a retry.
50
+
51
+ ```tsx
52
+ import { useDebouncedFetcher } from '@alxia/react-router/fetcher';
53
+
54
+ type SuggestAnswer = { items: string[] } | { failed: true };
55
+
56
+ export function Suggestions({ typed }: { typed: string }) {
57
+ const { data, stale, state, retry } = useDebouncedFetcher<SuggestAnswer>(
58
+ typed,
59
+ (q) => `/suggest?${new URLSearchParams({ q })}`,
60
+ { minLength: 2, delayMs: 250, keep: (answer) => !('failed' in answer) },
61
+ );
62
+ if (state === 'idle') return null;
63
+ return (
64
+ <div aria-busy={state !== 'done'} style={{ opacity: stale ? 0.5 : 1 }}>
65
+ {data && 'items' in data ? <List items={data.items} /> : <Spinner />}
66
+ {data && 'failed' in data ? <button onClick={retry}>Try again</button> : null}
67
+ </div>
68
+ );
69
+ }
70
+ ```
71
+
72
+ - `value` is the text typed; it is trimmed, and nothing is asked below
73
+ `minLength` (default 1). `to` is the route's URL, or a function of the
74
+ trimmed value that builds it (a plain string is loaded as it is, the value
75
+ only triggering it).
76
+ - After `delayMs` (default 250) without a change, one `fetcher.load` is made;
77
+ a newer load cancels the previous one.
78
+ - `data` is the route's answer for the value as it stands. While a newer value
79
+ waits or loads it is the previous answer and `stale` is `true`; an answer
80
+ for an older value is never returned as current. It is `undefined` before
81
+ the first answer and again once the hook is `idle`.
82
+ - `state` is `'idle'` (disabled or too short), `'waiting'` (the pause is
83
+ running), `'loading'` or `'done'`.
84
+ - `retry()` asks again for the value as it stands, without the pause; it is
85
+ the same function on every render. The route answers `{ failed: true }` on a
86
+ failure (for example with `orFailed` from `/lists`) rather than throwing,
87
+ which is what gives the retry button something to show (see
88
+ [troubleshooting](../troubleshooting.md)).
89
+ - `keep(answer)` (default: keep all) decides which answers may stay as the
90
+ stale `data` while the next value waits or loads; refuse the failed ones so
91
+ a failure is shown once, as the current answer, never dimmed as a previous
92
+ one. After a refused answer, the stale data is the last *kept* answer, not
93
+ the refused one.
94
+ - A refusal the route answers as data (`{ failed: true }`) is `data` like any
95
+ answer. A route that throws goes to the route's error boundary, as with any
96
+ fetcher.
97
+ - `enabled: false` asks nothing and forgets the previous answer (a closed
98
+ dialog); `key` shares the fetcher with another component.
@@ -584,6 +584,25 @@ export async function loader({ request }: Route.LoaderArgs) {
584
584
 
585
585
  The rows stay, `error` is `true`, and `loadMore` retries.
586
586
 
587
+ ### A debounced load lands on the route's `ErrorBoundary`
588
+
589
+ **When:** the resource route behind `useDebouncedFetcher` throws (or throws a `Response`) and the whole page is replaced by its `ErrorBoundary` instead of showing the previous suggestions with a retry.
590
+
591
+ **Why:** React Router sends the error of a fetcher's load to the route's boundary. `useDebouncedFetcher` only sees what the fetcher answers, so a failure it can show with `retry` has to be an answer.
592
+
593
+ **Fix:** answer `{ failed: true }` instead of throwing, for example with `orFailed(q, run)` from `@alxia/react-router/lists` (any non-empty value as its first argument makes it answer `{ failed: true }` on an error), and pass `keep` so a failure is never shown as the previous answer:
594
+
595
+ ```ts
596
+ export function loader({ request }: Route.LoaderArgs) {
597
+ const q = new URL(request.url).searchParams.get('q');
598
+ return orFailed(q, () => suggest(q));
599
+ }
600
+ // in the component
601
+ const { data, retry } = useDebouncedFetcher<typeof loader>(typed, toUrl, {
602
+ keep: (answer) => !('failed' in answer),
603
+ });
604
+ ```
605
+
587
606
  ### The client's files are served uncompressed
588
607
 
589
608
  A response for a script, a stylesheet or an SVG has no `Content-Encoding`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alxia/react-router",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "alxia as the server of a React Router framework app: server rendering behind the app's hooks, loaders reading its typed context, the client's assets served; the code with no UI an installable app shares (`/pwa`), its hooks (`/pwa/react`), `noCache` for the worker's script (`/pwa/server`), the service worker on Workbox (`/pwa/worker`) and its build (`/pwa/build`), an API's refusals worded for the page (`/errors`), the BFF session: cookies, sign-in, step-up and mail links (`/session`), its page hooks (`/session/react`) and what it shares with the page (`/session/model`), a GraphQL subscription relayed to the browser over SSE (`/subscription`), the page's CSP nonce and inline boot scripts (`/document`) and a streaming `entry.server` (`/entry`)",
5
5
  "license": "MIT",
6
6
  "type": "module",