@softistx/alxia-react-router 0.83.1 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -10
- package/dist/chunks/{index-6jf7zpxz.js → index-97e6pc48.js} +7 -6
- package/dist/chunks/index-97e6pc48.js.map +11 -0
- package/dist/chunks/{index-5gqcpyyg.js → index-nc5af0fn.js} +15 -4
- package/dist/chunks/index-nc5af0fn.js.map +10 -0
- package/dist/chunks/index-q0ks955b.js +10 -0
- package/dist/chunks/{index-59vhfj6n.js.map → index-q0ks955b.js.map} +2 -2
- package/dist/chunks/index-wyypkfdv.js.map +1 -1
- package/dist/errors/api-error.d.ts +4 -4
- package/dist/errors/api-error.d.ts.map +1 -1
- package/dist/errors/call-failure.d.ts +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/pwa/build/build-worker.d.ts +9 -2
- package/dist/pwa/build/build-worker.d.ts.map +1 -1
- package/dist/pwa/build/index.js +1 -1
- package/dist/pwa/build/precache.d.ts +3 -2
- package/dist/pwa/build/precache.d.ts.map +1 -1
- package/dist/pwa/index.d.ts +1 -1
- package/dist/pwa/index.d.ts.map +1 -1
- package/dist/pwa/index.js +1 -1
- package/dist/pwa/model/precache-list.d.ts +12 -2
- package/dist/pwa/model/precache-list.d.ts.map +1 -1
- package/dist/pwa/worker/index.d.ts +1 -0
- package/dist/pwa/worker/index.d.ts.map +1 -1
- package/dist/pwa/worker/index.js +5 -5
- package/dist/pwa/worker/index.js.map +2 -2
- package/dist/subscription/react/index.d.ts +1 -1
- package/dist/subscription/react/index.js +2 -2
- package/dist/subscription/react/index.js.map +2 -2
- package/dist/subscription/react/use-live-subscription.d.ts +1 -1
- package/dist/subscription/react/use-live-subscription.d.ts.map +1 -1
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +1 -1
- package/dist/vite/index.js.map +1 -1
- package/docs/guide/errors.md +5 -5
- package/docs/guide/pwa.md +33 -5
- package/docs/guide/subscriptions.md +2 -2
- package/docs/roadmap.md +5 -0
- package/docs/troubleshooting.md +25 -1
- package/package.json +5 -5
- package/dist/chunks/index-59vhfj6n.js +0 -10
- package/dist/chunks/index-5gqcpyyg.js.map +0 -10
- package/dist/chunks/index-6jf7zpxz.js.map +0 -11
package/README.md
CHANGED
|
@@ -38,6 +38,18 @@ own app, and make four changes.
|
|
|
38
38
|
bun add @softistx/alxia @softistx/alxia-react-router
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
The `@softistx` scope is restricted on npmjs and is read with a token. Point
|
|
42
|
+
Bun at it in `bunfig.toml`, with the token in an environment variable (here
|
|
43
|
+
`NPM_TOKEN`):
|
|
44
|
+
|
|
45
|
+
```toml
|
|
46
|
+
[install.scopes]
|
|
47
|
+
"@softistx" = { url = "https://registry.npmjs.org", token = "$NPM_TOKEN" }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A 401 or 404 on install means the token is missing
|
|
51
|
+
([troubleshooting](docs/troubleshooting.md#get-httpsregistrynpmjsorgsoftistx---401-or-404-on-a-softistx-package)).
|
|
52
|
+
|
|
41
53
|
**2. Add the plugin** to `vite.config.ts`. It can go anywhere in `plugins`:
|
|
42
54
|
|
|
43
55
|
```diff
|
|
@@ -97,7 +109,7 @@ client's files and the app's middlewares. So does React Router's prerendering.
|
|
|
97
109
|
optional peer, for `/vite`; `react` 19 is an optional peer, for `/pwa/react`, `/fetcher`, `/lists`, `/navigation` and `/oauth/react`; `jose` 6 is an optional peer, for `/oidc`. The six `workbox-*`
|
|
98
110
|
packages (`workbox-core`, `workbox-expiration`, `workbox-navigation-preload`,
|
|
99
111
|
`workbox-precaching`, `workbox-routing`, `workbox-strategies`) are optional
|
|
100
|
-
peers too, for `/pwa/worker` (the [PWA section](#installable-and-offline-pwa) has the install line). `@softistx/alxia-proxy` is an optional peer, for `/mcp` (`bun add @softistx/alxia-proxy`); `/mcp` also reads `@softistx/alxia`'s `MCP_RELAY_PATHS`. `react-hook-form` (7.55 or later) is an optional peer: `SectionForm`, the form `useSectionSave` and `useRowSave` take from `/fetcher`, is the shape of its `useForm()` result. `/errors` imports `react-router`, a required peer that is already installed. The package declares no dependency.
|
|
112
|
+
peers too, for `/pwa/worker` (the [PWA section](#installable-and-offline-pwa) has the install line). `@softistx/alxia-proxy` is an optional peer, for `/mcp` (`bun add @softistx/alxia-proxy`); `/mcp` also reads `@softistx/alxia`'s `MCP_RELAY_PATHS`. `react-hook-form` (7.55 or later) is an optional peer: `SectionForm`, the form `useSectionSave` and `useRowSave` take from `/fetcher`, is the shape of its `useForm()` result. `@softistx/graphql-client` (`^0.9.0`) is an optional peer, for `/subscription/react` (`bun add @softistx/graphql-client`). `/errors` imports `react-router`, a required peer that is already installed. The package declares no dependency.
|
|
101
113
|
|
|
102
114
|
Its `typescript` peer is 6 or 7. The template's TypeScript 5.9 typechecks,
|
|
103
115
|
but `bun add` warns about it; `bun add -d typescript@^6` silences the
|
|
@@ -739,7 +751,7 @@ With `app/service-worker.ts` in the app, `react-router build` writes
|
|
|
739
751
|
client build, with the precache list written in, and there is no script to
|
|
740
752
|
add. It needs Bun (`bun --bun react-router build`, or a `bunfig.toml` with
|
|
741
753
|
`[run] bun = true`). `alxia({ worker: 'app/pwa/worker.ts' })` names another file
|
|
742
|
-
and `alxia({ worker: false })` builds none.
|
|
754
|
+
and `alxia({ worker: false })` builds none. `alxia({ worker: { precacheRoutes: 'root' } })` (e.g. `plugins: [reactRouter(), alxia({ worker: { precacheRoutes: 'root' } })]`) precaches only the client entry and the root route, leaving the other routes' code to be cached when visited (`"all"` by default; a `RegExp` or `(routeId) => boolean` adds routes).
|
|
743
755
|
|
|
744
756
|
The worker bundles Workbox, whose six packages are optional peers:
|
|
745
757
|
|
|
@@ -866,7 +878,7 @@ banner and the rest.
|
|
|
866
878
|
## An API's refusals, worded for the page
|
|
867
879
|
|
|
868
880
|
`@softistx/alxia-react-router/errors` has no UI; its one runtime import is `react-router`, never `@softistx/alxia`. It
|
|
869
|
-
holds the shape of a GraphQL API's refusal, declared structurally (no `@
|
|
881
|
+
holds the shape of a GraphQL API's refusal, declared structurally (no `@softistx/graphql-client` at
|
|
870
882
|
runtime), a REST API's RFC 9457 problem reply (`problemError`), the request id an API echoes, the page a request is for, the
|
|
871
883
|
catalogue of the API's messages an app keeps, the words of a form's checks,
|
|
872
884
|
the provider that fills the catalogue in the browser, the wording of a refusal, the loaders and actions that answer with it, the JSON actions (CSRF check) with their fetcher hook, and what a failed call to the API becomes (`apiCallFailure`):
|
|
@@ -1158,7 +1170,7 @@ for the rules, the options and the errors.
|
|
|
1158
1170
|
### Keep it alive in the page: `useLiveSubscription`
|
|
1159
1171
|
|
|
1160
1172
|
`@softistx/alxia-react-router/subscription/react` is the browser side. It wraps
|
|
1161
|
-
`useSubscription` of `@
|
|
1173
|
+
`useSubscription` of `@softistx/graphql-client/react` (an optional peer, `^0.9.0`,
|
|
1162
1174
|
under a `GraphQLProvider`) and owns what a long-lived stream needs: reconnect
|
|
1163
1175
|
with a growing wait (1 s doubling to 30 s), a stop on a 401 or any 4xx repeating
|
|
1164
1176
|
cannot change, a 429's `retryAfter` honoured, events older than the highest
|
|
@@ -1769,9 +1781,9 @@ From `@softistx/alxia-react-router/pwa`:
|
|
|
1769
1781
|
| `Caching`, `RequestFacts`, `CachingOptions` | its types |
|
|
1770
1782
|
| `isStorable(response)` | whether a response may be stored: a full, same-origin, `public` 200 of a script, style, font or image, not varying on who asks |
|
|
1771
1783
|
| `parseBrowserManifest(source)` | React Router's browser manifest, read from `build/client/assets/manifest-*.js` |
|
|
1772
|
-
| `precacheList(manifest)` | the hashed scripts and stylesheets every route
|
|
1784
|
+
| `precacheList(manifest, routes?)` | the hashed scripts and stylesheets the routes need (every route, or the `routes` kept: `'root'`, a RegExp or a predicate over route ids), as Workbox precache entries |
|
|
1773
1785
|
| `assetPrecache(files, include, base?)` | the entries of the files in `build/client/assets` that a regex of yours matches, such as fonts |
|
|
1774
|
-
| `BrowserManifest`, `PrecacheEntry` | their types |
|
|
1786
|
+
| `BrowserManifest`, `PrecacheEntry`, `PrecacheRoutes` | their types |
|
|
1775
1787
|
| `fontPrecachePattern(families)` | the `precacheAssets` regex for `<family>-<8 hash chars>.woff2` files, from the file-name stems you keep offline (`['inter-latin', 'display-latin-wght-normal']`); a stem matches whole, regex characters are escaped, throws on an empty list |
|
|
1776
1788
|
| `themeColorHex(token)`, `themeColors(tokens)` | a theme colour token (`#rgb`, `#rrggbb` or `oklch(L C H)`) as the `#rrggbb` a manifest `themeColor` and a `theme-color` meta need; `themeColors` converts a record of tokens and keeps its keys |
|
|
1777
1789
|
| `clearAppCaches(contract)` | deletes the caches the worker filled but the offline page; for sign-out. Does nothing without Cache Storage |
|
|
@@ -1812,6 +1824,7 @@ From `@softistx/alxia-react-router/pwa/worker` (the six `workbox-*` packages, op
|
|
|
1812
1824
|
| --- | --- |
|
|
1813
1825
|
| `startWorker(options)` | the worker's strategies: the precache route, `NetworkOnly` for a page load with the precached offline page as its fallback, `CacheFirst` for hashed bundles, `StaleWhileRevalidate` for other static files (both storing only what `isStorable` accepts), the obsolete caches swept on `activate`, and `SKIP_WAITING` applied |
|
|
1814
1826
|
| `WorkerOptions` | `contract` (required), `caching`, `assets`, `static`, `navigationPreload`, `precache` |
|
|
1827
|
+
| `injectedPrecache()` | the precache list the build wrote into the worker, or `undefined`; filter it and pass the result as `WorkerOptions.precache` |
|
|
1815
1828
|
| `ExpirationOptions` | `{ maxEntries?, maxAgeSeconds? }` |
|
|
1816
1829
|
|
|
1817
1830
|
From `@softistx/alxia-react-router/pwa/build` (Bun; Node's built-ins its only imports):
|
|
@@ -1819,14 +1832,14 @@ From `@softistx/alxia-react-router/pwa/build` (Bun; Node's built-ins its only im
|
|
|
1819
1832
|
| export | |
|
|
1820
1833
|
| --- | --- |
|
|
1821
1834
|
| `buildWorker(options)` | bundles the worker into `build/client/service-worker.js` with its precache list (the offline page by its content, every route's code, `precacheAssets`), after `react-router build` |
|
|
1822
|
-
| `BuildWorkerOptions` | `file` (required), `root`, `client`, `contract`, `offline`, `precacheAssets`, `minify` |
|
|
1835
|
+
| `BuildWorkerOptions` | `file` (required), `root`, `client`, `contract`, `offline`, `precacheRoutes`, `precacheAssets`, `minify` |
|
|
1823
1836
|
| `WorkerBuild` | `{ file, precache, precacheBytes, bytes }` |
|
|
1824
1837
|
|
|
1825
1838
|
From `@softistx/alxia-react-router/errors` (`react-router` is its only package import, and never `@softistx/alxia`):
|
|
1826
1839
|
|
|
1827
1840
|
| export | |
|
|
1828
1841
|
| --- | --- |
|
|
1829
|
-
| `isApiErrorLike(error)` | whether `error` is an `@
|
|
1842
|
+
| `isApiErrorLike(error)` | whether `error` is an `@softistx/graphql-client` `ApiError`, like the client's `isApiError`, plus a numeric `status`, which `ApiErrorLike` promises; it holds across two copies of the client |
|
|
1830
1843
|
| `isStaleVersion(error)` | whether `error` is an API's refusal of an out-of-date update: an `ApiErrorLike` with status 409 whose `code` ends with `.errors.stale-version`; false for any other value |
|
|
1831
1844
|
| `ApiErrorLike`, `ApiErrorEntryLike`, `ApiErrorExtensionsLike`, `ApiErrorParamsLike`, `ApiFieldErrorLike` | the shape of the refusal: `errors`, `code`, `status`, `requestId?`, and each error's `extensions` (`code`, `params`, `fields`, `field`, `minutes`, `retryAfter`) |
|
|
1832
1845
|
| `waitMinutes(extensions)` | the minutes of a throttle's wait: `minutes` (at least one), else `retryAfter` rounded up |
|
|
@@ -1845,7 +1858,7 @@ From `@softistx/alxia-react-router/errors` (`react-router` is its only package i
|
|
|
1845
1858
|
| `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 |
|
|
1846
1859
|
| `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 |
|
|
1847
1860
|
| `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); `formRefusal(error, language, fieldOf, route?)` (`{ error, fieldErrors, status }` for a fetcher form: each field issue under the form field `fieldOf` names, `error` empty when every issue found its field); `route` is the `RouteErrorOptions` of the `routeError` they throw through |
|
|
1848
|
-
| `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 `@
|
|
1861
|
+
| `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 `@softistx/graphql-client`'s errors by `name`, not `instanceof` |
|
|
1849
1862
|
| `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 |
|
|
1850
1863
|
| `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 |
|
|
1851
1864
|
| `ApiRefusal` | `{ message, status }`: a failed call as a page says it; what `apiRefusal` returns for an API refusal (its status) or an unreachable API (503), else `undefined` |
|
|
@@ -2027,7 +2040,7 @@ From `@softistx/alxia-react-router/subscription` (no import, no peer):
|
|
|
2027
2040
|
| --- | --- |
|
|
2028
2041
|
| `createSubscriptionProxy({ endpoint, allow, getToken, headers?, origin?, heartbeatMs?, fetch? })`, `SubscriptionProxy`, `SubscriptionProxyOptions`, `SubscriptionArgs` | a resource route's `loader` (GET) and `action` (POST) relaying GraphQL subscriptions over SSE (graphql-sse's distinct connections mode). `allow` is `{ [operationName]: document }`: the proxy sends its own document, the client's `query` and `extensions` are ignored and an unknown name is a 403. Both methods refuse a cross-site request (403) and a POST that is not JSON (415); 401 without a token; 400 for a malformed or oversize request (body 64 KiB, query string and variables 16 KiB); the bearer and `headers` upstream (`headers(request, { request, context, params })`: a function gets the route's context, which never leaves it), a heartbeat comment every `heartbeatMs` (15000), the upstream aborted with the client, a pulled relay with a 1 MiB cap per event, an upstream 429 passed on with `Retry-After` and `retryAfter`, 502 for an upstream failure |
|
|
2029
2042
|
|
|
2030
|
-
From `@softistx/alxia-react-router/subscription/react` (imports `react` and `@
|
|
2043
|
+
From `@softistx/alxia-react-router/subscription/react` (imports `react` and `@softistx/graphql-client/react`, an optional peer):
|
|
2031
2044
|
|
|
2032
2045
|
| export | |
|
|
2033
2046
|
| --- | --- |
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PRECACHE_DEFINE
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-q0ks955b.js";
|
|
4
4
|
import {
|
|
5
5
|
parseBrowserManifest2,
|
|
6
6
|
precacheList2,
|
|
7
7
|
assetPrecache2
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-nc5af0fn.js";
|
|
9
9
|
import {
|
|
10
10
|
SERVICE_WORKER_URL2,
|
|
11
11
|
OFFLINE_URL2
|
|
@@ -32,7 +32,7 @@ function revisionOf(bytes) {
|
|
|
32
32
|
function workerPrecache(input) {
|
|
33
33
|
const all = [
|
|
34
34
|
...input.offline ? [input.offline] : [],
|
|
35
|
-
...precacheList2(parseBrowserManifest2(input.manifestSource)),
|
|
35
|
+
...precacheList2(parseBrowserManifest2(input.manifestSource), input.routes),
|
|
36
36
|
...input.include ? assetPrecache2(input.assetFiles, input.include) : []
|
|
37
37
|
];
|
|
38
38
|
const seen = new Set;
|
|
@@ -77,7 +77,8 @@ async function buildWorker2(options) {
|
|
|
77
77
|
manifestSource: await readFile(join(assets, manifest), "utf8"),
|
|
78
78
|
assetFiles: files,
|
|
79
79
|
offline,
|
|
80
|
-
include: options.precacheAssets
|
|
80
|
+
include: options.precacheAssets,
|
|
81
|
+
routes: options.precacheRoutes
|
|
81
82
|
});
|
|
82
83
|
const out = urlInClient(client, workerUrl);
|
|
83
84
|
const result = await Bun.build({
|
|
@@ -115,5 +116,5 @@ ${result.logs.map(String).join(`
|
|
|
115
116
|
}
|
|
116
117
|
export { buildWorker2 };
|
|
117
118
|
|
|
118
|
-
//# debugId=
|
|
119
|
-
//# sourceMappingURL=index-
|
|
119
|
+
//# debugId=2FAB7BEE1D818DB764756E2164756E21
|
|
120
|
+
//# sourceMappingURL=index-97e6pc48.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/pwa/build/build-worker.ts", "../src/pwa/build/precache.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { existsSync } from 'node:fs';\nimport { readdir, readFile, stat } from 'node:fs/promises';\nimport { basename, dirname, join, resolve, sep } from 'node:path';\nimport type { PrecacheEntry, PrecacheRoutes } from '../model/precache-list';\nimport {\n\tOFFLINE_URL,\n\tSERVICE_WORKER_URL,\n\ttype WorkerContract,\n} from '../model/worker-contract';\nimport { PRECACHE_DEFINE } from '../worker/injected';\nimport { browserManifestFile, revisionOf, workerPrecache } from './precache';\n\nexport interface BuildWorkerOptions {\n\t/**\n\t * The worker's source, relative to `root`: `app/service-worker.ts`. Named\n\t * `file`, not `entry`: `reveal` reads `alxia({ entry })`.\n\t */\n\tfile: string;\n\t/** `process.cwd()` by default. */\n\troot?: string;\n\t/** The client build, relative to `root`: `build/client` by default. */\n\tclient?: string;\n\t/** Where the worker is written and which offline page is precached. */\n\tcontract?: Pick<WorkerContract, 'serviceWorkerUrl' | 'offlineUrl'>;\n\t/** Precache the offline page, which must then exist. `true` by default. */\n\toffline?: boolean;\n\t/** More files of `assets/` to precache, such as fonts: the app's regex. */\n\tprecacheAssets?: RegExp;\n\t/**\n\t * Which routes' code the worker precaches: `\"all\"` (the default), `\"root\"`\n\t * (the client entry and the root route, with their imports and CSS), a\n\t * RegExp or a `(routeId) => boolean` over the route ids, which adds the\n\t * matching routes to those two. The other routes are cached when visited.\n\t */\n\tprecacheRoutes?: PrecacheRoutes;\n\t/** `true` by default. */\n\tminify?: boolean;\n}\n\nexport interface WorkerBuild {\n\t/** The absolute path of the worker written. */\n\tfile: string;\n\tprecache: PrecacheEntry[];\n\t/** The precached files' size, before compression. */\n\tprecacheBytes: number;\n\t/** The worker's own size. */\n\tbytes: number;\n}\n\n/** Not `requireBun` of `vite/`: `/pwa/build` imports Node's built-ins only. */\nexport function assertBun(\n\tonBun = (globalThis as { Bun?: unknown }).Bun !== undefined,\n): void {\n\tif (onBun) return;\n\tthrow new Error(\n\t\t'buildWorker() runs on Bun: it is running on Node. Run it with bun, or run react-router build with bun --bun.',\n\t);\n}\n\n/**\n * The file a root-relative URL names inside `client`. It fails closed: a URL\n * that is absolute, protocol-relative, not rooted at `/`, or that resolves to\n * `client` itself or outside it, is refused.\n */\nfunction urlInClient(client: string, url: string): string {\n\tconst path = join(client, url);\n\tif (\n\t\t!url.startsWith('/') ||\n\t\t/^[a-z][a-z0-9+.-]*:|^\\/\\//i.test(url) ||\n\t\t!path.startsWith(client + sep) ||\n\t\tpath.endsWith(sep)\n\t) {\n\t\tthrow new Error(`buildWorker(): ${url} is outside ${client}.`);\n\t}\n\treturn path;\n}\n\n/**\n * Bundles the worker (Workbox included) into the client build, after\n * `react-router build`, with the precache list written in: the offline page\n * by its content, the routes' code (`precacheRoutes`) and `precacheAssets`. A new build\n * changes the list, so the worker's bytes, so the browser installs it.\n * Runs on Bun; the only imports of this module are Node's built-ins.\n */\nexport async function buildWorker(\n\toptions: BuildWorkerOptions,\n): Promise<WorkerBuild> {\n\tassertBun();\n\tconst root = resolve(options.root ?? process.cwd());\n\tconst client = resolve(root, options.client ?? 'build/client');\n\tconst source = resolve(root, options.file);\n\tconst workerUrl = options.contract?.serviceWorkerUrl ?? SERVICE_WORKER_URL;\n\tconst offlineUrl = options.contract?.offlineUrl ?? OFFLINE_URL;\n\tif (!existsSync(source)) {\n\t\tthrow new Error(`buildWorker(): ${options.file} does not exist.`);\n\t}\n\tconst assets = join(client, 'assets');\n\tconst files = await readdir(assets).catch(() => []);\n\tconst manifest = browserManifestFile(files);\n\tlet offline: PrecacheEntry | undefined;\n\tif (options.offline !== false) {\n\t\tconst page = urlInClient(client, offlineUrl);\n\t\tif (!existsSync(page)) {\n\t\t\tthrow new Error(\n\t\t\t\t`buildWorker(): ${options.client ?? 'build/client'}${offlineUrl} does not exist. Add public${offlineUrl}, or pass offline: false (\\`worker: { offline: false }\\` in alxia()), or pass the app's contract (\\`worker: { contract }\\` in alxia()).`,\n\t\t\t);\n\t\t}\n\t\toffline = { url: offlineUrl, revision: revisionOf(await readFile(page)) };\n\t}\n\tconst precache = workerPrecache({\n\t\tmanifestSource: await readFile(join(assets, manifest), 'utf8'),\n\t\tassetFiles: files,\n\t\toffline,\n\t\tinclude: options.precacheAssets,\n\t\troutes: options.precacheRoutes,\n\t});\n\tconst out = urlInClient(client, workerUrl);\n\tconst result = await Bun.build({\n\t\tentrypoints: [source],\n\t\toutdir: dirname(out),\n\t\tnaming: basename(out),\n\t\ttarget: 'browser',\n\t\tformat: 'iife',\n\t\tminify: options.minify ?? true,\n\t\tdefine: {\n\t\t\t// Workbox's production build: no logging, no dev assertions.\n\t\t\t'process.env.NODE_ENV': '\"production\"',\n\t\t\t[PRECACHE_DEFINE]: JSON.stringify(precache),\n\t\t},\n\t}).catch((error: unknown) => {\n\t\tconst detail =\n\t\t\terror instanceof AggregateError\n\t\t\t\t? error.errors.map(String).join('\\n')\n\t\t\t\t: String(error);\n\t\tthrow new Error(`buildWorker(): Bun.build failed:\\n${detail}`);\n\t});\n\tif (!result.success) {\n\t\tthrow new Error(\n\t\t\t`buildWorker(): Bun.build failed:\\n${result.logs.map(String).join('\\n')}`,\n\t\t);\n\t}\n\tlet precacheBytes = 0;\n\tfor (const { url } of precache) {\n\t\tprecacheBytes += (await stat(join(client, url))).size;\n\t}\n\treturn {\n\t\tfile: out,\n\t\tprecache,\n\t\tprecacheBytes,\n\t\tbytes: (await stat(out)).size,\n\t};\n}\n",
|
|
6
|
+
"import { createHash } from 'node:crypto';\nimport {\n\tassetPrecache,\n\ttype PrecacheEntry,\n\ttype PrecacheRoutes,\n\tparseBrowserManifest,\n\tprecacheList,\n} from '../model/precache-list';\n\n/** The one React Router browser manifest among the names in build/client/assets. */\nexport function browserManifestFile(files: readonly string[]): string {\n\tconst found = files.filter((file) => /^manifest-[\\w-]+\\.js$/.test(file));\n\tconst [only] = found;\n\tif (found.length !== 1 || only === undefined) {\n\t\tthrow new Error(\n\t\t\t`buildWorker(): expected one React Router browser manifest, build/client/assets/manifest-*.js, found ${found.length}. Run react-router build first.`,\n\t\t);\n\t}\n\treturn only;\n}\n\n/** A file's revision: the first 16 hex characters of its sha256. */\nexport function revisionOf(bytes: Uint8Array): string {\n\treturn createHash('sha256').update(bytes).digest('hex').slice(0, 16);\n}\n\n/**\n * The worker's precache list: the offline page (revisioned by its content),\n * the routes' code (`routes`: all by default), then the asset files `include` matches. Each URL once,\n * the first kept.\n */\nexport function workerPrecache(input: {\n\tmanifestSource: string;\n\tassetFiles: readonly string[];\n\toffline?: PrecacheEntry | undefined;\n\tinclude?: RegExp | undefined;\n\troutes?: PrecacheRoutes | undefined;\n}): PrecacheEntry[] {\n\tconst all = [\n\t\t...(input.offline ? [input.offline] : []),\n\t\t...precacheList(parseBrowserManifest(input.manifestSource), input.routes),\n\t\t...(input.include ? assetPrecache(input.assetFiles, input.include) : []),\n\t];\n\tconst seen = new Set<string>();\n\treturn all.filter(({ url }) => !seen.has(url) && seen.add(url));\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AACA;AACA;;;ACFA;AAUO,SAAS,mBAAmB,CAAC,OAAkC;AAAA,EACrE,MAAM,QAAQ,MAAM,OAAO,CAAC,SAAS,wBAAwB,KAAK,IAAI,CAAC;AAAA,EACvE,OAAO,QAAQ;AAAA,EACf,IAAI,MAAM,WAAW,KAAK,SAAS,WAAW;AAAA,IAC7C,MAAM,IAAI,MACT,uGAAuG,MAAM,uCAC9G;AAAA,EACD;AAAA,EACA,OAAO;AAAA;AAID,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AAO,IAAI,MAAM,EAAE,KAAK;AAAA,CAAI,IAClC,OAAO,KAAK;AAAA,IAChB,MAAM,IAAI,MAAM;AAAA,EAAqC,QAAQ;AAAA,GAC7D;AAAA,EACD,IAAI,CAAC,OAAO,SAAS;AAAA,IACpB,MAAM,IAAI,MACT;AAAA,EAAqC,OAAO,KAAK,IAAI,MAAM,EAAE,KAAK;AAAA,CAAI,GACvE;AAAA,EACD;AAAA,EACA,IAAI,gBAAgB;AAAA,EACpB,aAAa,SAAS,UAAU;AAAA,IAC/B,kBAAkB,MAAM,KAAK,KAAK,QAAQ,GAAG,CAAC,GAAG;AAAA,EAClD;AAAA,EACA,OAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ,MAAM,KAAK,GAAG,GAAG;AAAA,EAC1B;AAAA;",
|
|
9
|
+
"debugId": "2FAB7BEE1D818DB764756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -8,9 +8,20 @@ function parseBrowserManifest2(source) {
|
|
|
8
8
|
}
|
|
9
9
|
return JSON.parse(source.slice(start, end + 1));
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function keepsRoute(routes, id) {
|
|
12
|
+
if (id === "root" || routes === "all")
|
|
13
|
+
return true;
|
|
14
|
+
if (routes === "root")
|
|
15
|
+
return false;
|
|
16
|
+
if (typeof routes === "function")
|
|
17
|
+
return routes(id);
|
|
18
|
+
routes.lastIndex = 0;
|
|
19
|
+
return routes.test(id);
|
|
20
|
+
}
|
|
21
|
+
function precacheList2(manifest, routes = "all") {
|
|
12
22
|
const urls = new Set([manifest.url]);
|
|
13
|
-
|
|
23
|
+
const parts = Object.entries(manifest.routes).filter(([id]) => keepsRoute(routes, id)).map(([, part]) => part);
|
|
24
|
+
for (const part of [manifest.entry, ...parts]) {
|
|
14
25
|
for (const url of [
|
|
15
26
|
...part.module ? [part.module] : [],
|
|
16
27
|
...part.imports ?? [],
|
|
@@ -30,5 +41,5 @@ function assetPrecache2(assetFiles, include, base = "/assets/") {
|
|
|
30
41
|
|
|
31
42
|
export { parseBrowserManifest2, precacheList2, assetPrecache2 };
|
|
32
43
|
|
|
33
|
-
//# debugId=
|
|
34
|
-
//# sourceMappingURL=index-
|
|
44
|
+
//# debugId=20F7D7F33351F96864756E2164756E21
|
|
45
|
+
//# sourceMappingURL=index-nc5af0fn.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/pwa/model/precache-list.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * What the service worker precaches, read from a build: every script and\n * stylesheet React Router's manifest names (the client entry and each\n * route's module, imports and CSS), and the manifest itself, so a client\n * navigation offline to a route never visited still finds its code. Only\n * hashed `/assets/` files: a new build names new files, so each precaches\n * under its own URL, revision `null`. Chunks only a component loads on\n * demand stay out: a cache-first route stores them the first time they load.\n *\n * Dependency-free: a build script runs it at build time.\n */\n\n/** A route or the entry, as `window.__reactRouterManifest` lists it. */\ntype ManifestModule = { module?: string; imports?: string[]; css?: string[] };\n\n/** The parts of React Router's browser manifest the list reads. */\nexport type BrowserManifest = {\n\turl: string;\n\tentry: ManifestModule;\n\troutes: Record<string, ManifestModule>;\n};\n\n/** A Workbox precache entry: a hashed URL needs no revision. */\nexport type PrecacheEntry = { url: string; revision: string | null };\n\n/** A Vite-hashed file under `/assets/`: `name-<8 hash chars>.js|css`. */\nconst HASHED_ASSET = /^\\/assets\\/[^/]+-[\\w-]{8}\\.(?:js|css)$/;\n\n/** Reads `window.__reactRouterManifest={…};` (build/client/assets/manifest-*.js). */\nexport function parseBrowserManifest(source: string): BrowserManifest {\n\tconst start = source.indexOf('{');\n\tconst end = source.lastIndexOf('}');\n\tif (start < 0 || end < start) {\n\t\tthrow new Error(\n\t\t\t\"parseBrowserManifest(): not React Router's browser manifest (build/client/assets/manifest-*.js).\",\n\t\t);\n\t}\n\treturn JSON.parse(source.slice(start, end + 1)) as BrowserManifest;\n}\n\n/**\n * Which routes' code the list holds: `\"all\"` (the default), `\"root\"` (the\n * root route alone), a RegExp or a predicate over the route ids of\n * `app/routes.ts` (`root`, `routes/items`, …). The client entry, its imports\n * and the `root` route are always kept, since every page renders inside them.\n */\nexport type PrecacheRoutes =\n\t| 'all'\n\t| 'root'\n\t| RegExp\n\t| ((routeId: string) => boolean);\n\nfunction keepsRoute(routes: PrecacheRoutes, id: string): boolean {\n\tif (id === 'root' || routes === 'all') return true;\n\tif (routes === 'root') return false;\n\tif (typeof routes === 'function') return routes(id);\n\troutes.lastIndex = 0; // a /g or /y regex remembers its last match\n\treturn routes.test(id);\n}\n\n/**\n * The hashed scripts and stylesheets the routes need, the manifest's own file\n * first. `routes` narrows which routes' code is kept (all of them by default).\n */\nexport function precacheList(\n\tmanifest: BrowserManifest,\n\troutes: PrecacheRoutes = 'all',\n): PrecacheEntry[] {\n\tconst urls = new Set<string>([manifest.url]);\n\tconst parts = Object.entries(manifest.routes)\n\t\t.filter(([id]) => keepsRoute(routes, id))\n\t\t.map(([, part]) => part);\n\tfor (const part of [manifest.entry, ...parts]) {\n\t\tfor (const url of [\n\t\t\t...(part.module ? [part.module] : []),\n\t\t\t...(part.imports ?? []),\n\t\t\t...(part.css ?? []),\n\t\t]) {\n\t\t\turls.add(url);\n\t\t}\n\t}\n\treturn [...urls]\n\t\t.filter((url) => HASHED_ASSET.test(url))\n\t\t.map((url) => ({ url, revision: null }));\n}\n\n/**\n * The precache entries of the files among `assetFiles` (the names in\n * build/client/assets) that `include` matches, sorted, under `base`: fonts\n * an app keeps offline, say. The regex is the app's.\n */\nexport function assetPrecache(\n\tassetFiles: readonly string[],\n\tinclude: RegExp,\n\tbase = '/assets/',\n): PrecacheEntry[] {\n\treturn assetFiles\n\t\t.filter((file) => {\n\t\t\tinclude.lastIndex = 0; // a /g or /y regex remembers its last match\n\t\t\treturn include.test(file);\n\t\t})\n\t\t.sort()\n\t\t.map((file) => ({ url: `${base}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tC,IAAI,CAAC,SAAS,EAAE,KAAK,UAAU,KAAK,EAAE;AAAA;AAQlC,SAAS,cAAa,CAC5B,YACA,SACA,OAAO,YACW;AAAA,EAClB,OAAO,WACL,OAAO,CAAC,SAAS;AAAA,IACjB,QAAQ,YAAY;AAAA,IACpB,OAAO,QAAQ,KAAK,IAAI;AAAA,GACxB,EACA,KAAK,EACL,IAAI,CAAC,UAAU,EAAE,KAAK,GAAG,OAAO,QAAQ,UAAU,KAAK,EAAE;AAAA;",
|
|
8
|
+
"debugId": "20F7D7F33351F96864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/pwa/worker/injected.ts
|
|
2
|
+
var PRECACHE_DEFINE = "globalThis.__ALXIA_PRECACHE__";
|
|
3
|
+
function injectedPrecache2() {
|
|
4
|
+
return globalThis.__ALXIA_PRECACHE__;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { PRECACHE_DEFINE, injectedPrecache2 };
|
|
8
|
+
|
|
9
|
+
//# debugId=EC1988A1AB9FF26C64756E2164756E21
|
|
10
|
+
//# sourceMappingURL=index-q0ks955b.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/** The define key the build sets: the worker's precache list, as JSON. */\nexport const PRECACHE_DEFINE = 'globalThis.__ALXIA_PRECACHE__';\n\n/** One file the worker precaches: its URL and a revision (`null` when hashed in the name). */\ntype Entry = { readonly url: string; readonly revision: string | null };\n\n/**\n * The precache list the build wrote into this worker, or `undefined` when the\n * worker did not go through the build. Read through `globalThis`, so a missing\n * define is `undefined`, never a `ReferenceError`.\n */\nexport function injectedPrecache(): readonly Entry[] | undefined {\n\treturn (globalThis as { __ALXIA_PRECACHE__?: readonly Entry[] })\n\t\t.__ALXIA_PRECACHE__;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AACO,IAAM,kBAAkB;AAUxB,SAAS,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AACO,IAAM,kBAAkB;AAUxB,SAAS,iBAAgB,GAAiC;AAAA,EAChE,OAAQ,WACN;AAAA;",
|
|
8
|
+
"debugId": "EC1988A1AB9FF26C64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors/api-error.ts", "../src/errors/route-error.ts", "../src/errors/problem-error.ts", "../src/errors/request-id.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * The shape of an API's refusal, as `@
|
|
5
|
+
"/**\n * The shape of an API's refusal, as `@softistx/graphql-client`'s `ApiError`\n * carries it, declared structurally: `/errors` never imports the client, so\n * an app needs it only if it calls the API through it. `api-error.spec.ts`\n * holds the two in step.\n */\n\n/** One refused input field: `extensions.fields` of a validation refusal. */\nexport interface ApiFieldErrorLike {\n\treadonly path: string;\n\treadonly code: string;\n\treadonly message: string;\n\t/** The values the field's message interpolates. */\n\treadonly params?: Readonly<Record<string, unknown>>;\n}\n\n/** The values a message interpolates; a throttle's wait is `minutes` or `retryAfter`. */\nexport interface ApiErrorParamsLike {\n\treadonly minutes?: unknown;\n\treadonly retryAfter?: unknown;\n\treadonly attemptsLeft?: unknown;\n\treadonly [key: string]: unknown;\n}\n\n/**\n * One GraphQL error's `extensions`. `code` is the API's own\n * `<module>.errors.<slug>`; the rest is what its messages name.\n */\nexport interface ApiErrorExtensionsLike {\n\treadonly code?: string;\n\t/** The values the message interpolates, when the API sends them. */\n\treadonly params?: ApiErrorParamsLike;\n\t/** A validation refusal: every field at fault, by input path. */\n\treadonly fields?: readonly ApiFieldErrorLike[];\n\t/** Any other refusal about one input field, by its path. */\n\treadonly field?: string;\n\t/** A throttle's wait, in minutes (`waitMinutes` coerces a string). */\n\treadonly minutes?: unknown;\n\t/** A throttle's wait, in seconds. */\n\treadonly retryAfter?: unknown;\n\t/** The tries a refused code leaves, as `@softistx/janus` counts them. */\n\treadonly attemptsLeft?: unknown;\n\treadonly [key: string]: unknown;\n}\n\n/** One error of a response's `errors`. */\nexport interface ApiErrorEntryLike {\n\treadonly message: string;\n\treadonly extensions?: ApiErrorExtensionsLike;\n}\n\n/** A refusal read from a GraphQL API: what `ApiError` has, and the request id. */\nexport interface ApiErrorLike extends Error {\n\treadonly errors: readonly ApiErrorEntryLike[];\n\t/** The first error's `extensions.code`. */\n\treadonly code: string | undefined;\n\t/** The HTTP status to answer with. */\n\treadonly status: number;\n\t/** The id the API logged the request under, when the caller kept it. */\n\treadonly requestId?: string;\n}\n\n/** Whether `error` is an `Error` of this `name`: the client's errors are told by it, never `instanceof`. */\nexport const isNamed = (error: unknown, name: string): error is Error =>\n\terror instanceof Error && error.name === name;\n\n/**\n * Whether `error` is an `ApiError` of `@softistx/graphql-client`, by the test\n * that client's `isApiError` makes (an `Error` named `ApiError` with an\n * `errors` array), plus a numeric `status`, which `ApiErrorLike` promises.\n * It holds across two copies of the client.\n */\nexport function isApiErrorLike(error: unknown): error is ApiErrorLike {\n\treturn (\n\t\tisNamed(error, 'ApiError') &&\n\t\tArray.isArray((error as { errors?: unknown }).errors) &&\n\t\ttypeof (error as { status?: unknown }).status === 'number'\n\t);\n}\n\n/**\n * Whether `error` is an API's refusal of an update whose version is out of\n * date: an `ApiError` with status 409 whose `code` ends with\n * `.errors.stale-version`. False for any other value.\n */\nexport function isStaleVersion(error: unknown): error is ApiErrorLike {\n\treturn (\n\t\tisApiErrorLike(error) &&\n\t\terror.status === 409 &&\n\t\ttypeof error.code === 'string' &&\n\t\terror.code.endsWith('.errors.stale-version')\n\t);\n}\n\n/**\n * The minutes a wait lasts, as the API words it: `minutes` (at least one, in\n * `extensions.params` or beside it), else the `retryAfter` seconds rounded\n * up, else one.\n */\nexport function waitMinutes(\n\textensions: ApiErrorExtensionsLike | undefined,\n): number {\n\tconst minutes = extensions?.params?.minutes ?? extensions?.minutes;\n\tif (minutes !== undefined) return Math.max(1, Number(minutes) || 1);\n\tconst seconds = extensions?.params?.retryAfter ?? extensions?.retryAfter;\n\treturn Math.max(1, Math.ceil(Number(seconds) / 60) || 1);\n}\n\nconst MAX_RETRY_AFTER = 86_400;\n\n/** A wait in seconds from one value: a finite number from 0, or a decimal string. */\nfunction secondsOf(value: unknown): number | undefined {\n\tconst seconds =\n\t\ttypeof value === 'string' && /^\\d+(\\.\\d+)?$/.test(value.trim())\n\t\t\t? Number(value.trim())\n\t\t\t: value;\n\treturn typeof seconds === 'number' && Number.isFinite(seconds) && seconds >= 0\n\t\t? Math.min(MAX_RETRY_AFTER, Math.ceil(seconds)) + 0\n\t\t: undefined;\n}\n\n/**\n * The seconds a throttle asks to wait: `retryAfter` of the first error's\n * `extensions.params`, else (when that is unusable) of its `extensions`.\n * Only a finite number from 0, or a decimal string, counts; it is rounded up\n * and held at a day (86 400), and `-0` is 0. `undefined` when the API sent\n * none usable. Exported from `/errors`; `/session` words it as a typed\n * `retryAfter`.\n */\nexport function retryAfterOf(error: ApiErrorLike): number | undefined {\n\tconst extensions = error.errors[0]?.extensions;\n\treturn (\n\t\tsecondsOf(extensions?.params?.retryAfter) ??\n\t\tsecondsOf(extensions?.retryAfter)\n\t);\n}\n\n/** The API's `extensions.reason` of the first error (also in its `params`): `'throttled'` is a timed wait. */\nexport function reasonOf(error: ApiErrorLike): unknown {\n\tconst extensions = error.errors[0]?.extensions;\n\treturn extensions?.['reason'] ?? extensions?.params?.['reason'];\n}\n\n/** Whether the refusal carries `reason: 'throttled'`: a rate limit that asks to wait, whatever its code. */\nexport const isThrottledReason = (error: ApiErrorLike): boolean =>\n\treasonOf(error) === 'throttled';\n\n/**\n * The tries a refused code leaves, as `@softistx/janus` counts them:\n * `extensions.attemptsLeft` of the first error, else the same key in its\n * `params`. A whole number from 0 up; `undefined` when the API sent none or\n * something that is not a count. A throttled refusal (`isThrottledReason`)\n * spends no try: whatever count it carries (`0` included), it answers\n * `undefined`.\n */\nexport function attemptsLeftOf(error: ApiErrorLike): number | undefined {\n\tif (isThrottledReason(error)) return undefined;\n\tconst extensions = error.errors[0]?.extensions;\n\tfor (const value of [\n\t\textensions?.attemptsLeft,\n\t\textensions?.params?.attemptsLeft,\n\t]) {\n\t\tif (typeof value === 'number' && Number.isInteger(value) && value >= 0) {\n\t\t\treturn value;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * The values a message names: `extensions.params` over the extensions\n * themselves, where older errors and the extras of a few sit.\n */\nexport function valuesOf(\n\textensions: ApiErrorExtensionsLike | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return undefined;\n\treturn extensions.params\n\t\t? { ...extensions, ...extensions.params }\n\t\t: extensions;\n}\n\n/** `@softistx/graphql-client`'s `ApiStatusError`, as far as the failure reads it. */\nexport interface StatusErrorLike extends Error {\n\tstatus: number;\n\tstatusText?: string | undefined;\n\tbody?: unknown;\n}\n\n/** `@softistx/graphql-client`'s `ApiUnavailableError`, as far as the failure reads it. */\nexport interface UnavailableErrorLike extends Error {\n\treason: string;\n}\n\nexport const isStatusError = (error: unknown): error is StatusErrorLike =>\n\tisNamed(error, 'ApiStatusError') &&\n\ttypeof (error as { status?: unknown }).status === 'number';\n\nexport const isUnavailableError = (\n\terror: unknown,\n): error is UnavailableErrorLike =>\n\tisNamed(error, 'ApiUnavailableError') &&\n\ttypeof (error as { reason?: unknown }).reason === 'string';\n",
|
|
6
6
|
"import { data } from 'react-router';\nimport { isApiErrorLike } from './api-error';\nimport { isProblemErrorLike } from './problem-error';\nimport { requestIdOf } from './request-id';\n\n/** The statuses an error page words: unauthenticated, forbidden, missing, unavailable. */\nconst ROUTED: ReadonlySet<number> = new Set([401, 403, 404, 503]);\n\n/**\n * What a route error of the API carries to the error page: the API's code\n * and message when it gave a code, and the `X-Request-Id` of the call as the\n * support reference (`errorRequestId`).\n */\nexport type RouteErrorData = {\n\tcode?: string | undefined;\n\tmessage?: string | undefined;\n\trequestId?: string | undefined;\n};\n\nexport interface RouteErrorOptions {\n\t/** The statuses that become a route error of their own; 401, 403, 404 and 503 by default. */\n\tstatuses?: ReadonlySet<number>;\n}\n\n/**\n * What a loader throws for an error from the API: an `ApiError` whose\n * status is routed (401, 403, 404 or 503) becomes a route error response of\n * that status, which the root `ErrorBoundary` renders as its page, with the\n * call's request id when the API gave one. A thrown routed `Response` that\n * carries a request id becomes one too (a bare `Response` hands the browser\n * its body only). Any other `ApiError` that has a request id becomes a 500\n * with just that id, so the generic error page can show it. A `ProblemError`\n * (`problemError`, a REST API's RFC 9457 reply) is treated alike, its message\n * being the problem's detail or title. Anything else\n * is returned as it is.\n */\nexport function routeError(\n\terror: unknown,\n\t{ statuses = ROUTED }: RouteErrorOptions = {},\n): unknown {\n\tif (isApiErrorLike(error)) {\n\t\tconst { requestId } = error;\n\t\tif (statuses.has(error.status)) {\n\t\t\treturn data<RouteErrorData>(\n\t\t\t\t{ code: error.code, message: error.message, requestId },\n\t\t\t\t{ status: error.status },\n\t\t\t);\n\t\t}\n\t\treturn requestId\n\t\t\t? data<RouteErrorData>({ requestId }, { status: 500 })\n\t\t\t: error;\n\t}\n\tif (isProblemErrorLike(error)) {\n\t\tconst { requestId } = error;\n\t\tif (statuses.has(error.status)) {\n\t\t\treturn data<RouteErrorData>(\n\t\t\t\t{ message: error.message, requestId },\n\t\t\t\t{ status: error.status },\n\t\t\t);\n\t\t}\n\t\treturn requestId\n\t\t\t? data<RouteErrorData>({ requestId }, { status: 500 })\n\t\t\t: error;\n\t}\n\tif (error instanceof Response && statuses.has(error.status)) {\n\t\tconst requestId = requestIdOf(error);\n\t\tif (requestId) {\n\t\t\treturn data<RouteErrorData>({ requestId }, { status: error.status });\n\t\t}\n\t}\n\treturn error;\n}\n\n/**\n * The support reference an error page shows: the API's `X-Request-Id` a\n * route error carries (`routeError`), if it carries one.\n */\nexport function errorRequestId(error: unknown): string | undefined {\n\tif (typeof error !== 'object' || error === null) return undefined;\n\tconst { data: body } = error as { data?: unknown };\n\tif (typeof body !== 'object' || body === null) return undefined;\n\tconst { requestId } = body as { requestId?: unknown };\n\treturn typeof requestId === 'string' && requestId ? requestId : undefined;\n}\n",
|
|
7
7
|
"import { isNamed } from './api-error';\n\n/** A reply of a REST/OpenAPI client, as far as `problemError` reads it: `{ status, data }`. */\nexport interface ProblemReply {\n\treadonly status: number;\n\t/** The parsed body; a problem document (RFC 9457) when the API refused. */\n\treadonly data?: unknown;\n}\n\nexport interface ProblemErrorOptions {\n\t/** The `x-request-id` the API answered (`requestIdOf(response)`). */\n\trequestId?: string | undefined;\n}\n\n/** A refusal read from a REST API's RFC 9457 problem reply. */\nexport interface ProblemErrorLike extends Error {\n\t/** The HTTP status of the reply. */\n\treadonly status: number;\n\t/** The problem's `title`, else `Error <status>`. */\n\treadonly title: string;\n\t/** The problem's `detail`, when it has one. */\n\treadonly detail?: string | undefined;\n\t/** The problem's `type` URI, when it has one. */\n\treadonly type?: string | undefined;\n\t/** The problem's `instance` URI, when it has one. */\n\treadonly instance?: string | undefined;\n\t/** The id the API logged the request under, when the caller kept it. */\n\trequestId?: string | undefined;\n}\n\nconst text = (value: unknown): string | undefined =>\n\ttypeof value === 'string' && value ? value : undefined;\n\n/**\n * The error of an RFC 9457 problem reply. Its `message` is the problem's\n * `detail`, else its `title`, else `Error <status>`.\n */\nexport class ProblemError extends Error implements ProblemErrorLike {\n\toverride readonly name = 'ProblemError';\n\treadonly status: number;\n\treadonly title: string;\n\treadonly detail: string | undefined;\n\treadonly type: string | undefined;\n\treadonly instance: string | undefined;\n\trequestId: string | undefined;\n\n\tconstructor(reply: ProblemReply, { requestId }: ProblemErrorOptions = {}) {\n\t\tconst body =\n\t\t\ttypeof reply.data === 'object' && reply.data !== null\n\t\t\t\t? (reply.data as {\n\t\t\t\t\t\ttitle?: unknown;\n\t\t\t\t\t\tdetail?: unknown;\n\t\t\t\t\t\ttype?: unknown;\n\t\t\t\t\t\tinstance?: unknown;\n\t\t\t\t\t})\n\t\t\t\t: {};\n\t\tconst title = text(body.title) ?? `Error ${reply.status}`;\n\t\tconst detail = text(body.detail);\n\t\tsuper(detail ?? title);\n\t\tthis.status = reply.status;\n\t\tthis.title = title;\n\t\tthis.detail = detail;\n\t\tthis.type = text(body.type);\n\t\tthis.instance = text(body.instance);\n\t\tthis.requestId = requestId;\n\t}\n}\n\n/**\n * Turns a REST/OpenAPI client's `{ status, data }` reply into a\n * `ProblemError`; a body that is not a problem document gives `Error <status>`.\n */\nexport function problemError(\n\treply: ProblemReply,\n\toptions?: ProblemErrorOptions,\n): ProblemError {\n\treturn new ProblemError(reply, options);\n}\n\n/**\n * Whether `error` is a `ProblemError`, told by its name and a numeric\n * `status`, never `instanceof`, so it holds across two copies of the package.\n */\nexport function isProblemErrorLike(error: unknown): error is ProblemErrorLike {\n\treturn (\n\t\tisNamed(error, 'ProblemError') &&\n\t\ttypeof (error as { status?: unknown }).status === 'number'\n\t);\n}\n",
|
|
8
8
|
"/** The header an API echoes on every response: the id its logs carry. */\nexport const REQUEST_ID_HEADER = 'x-request-id';\n\n/** The request id a response carries, if the API sent one. */\nexport function requestIdOf(response: Response): string | undefined {\n\treturn response.headers.get(REQUEST_ID_HEADER) || undefined;\n}\n"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The shape of an API's refusal, as `@
|
|
2
|
+
* The shape of an API's refusal, as `@softistx/graphql-client`'s `ApiError`
|
|
3
3
|
* carries it, declared structurally: `/errors` never imports the client, so
|
|
4
4
|
* an app needs it only if it calls the API through it. `api-error.spec.ts`
|
|
5
5
|
* holds the two in step.
|
|
@@ -57,7 +57,7 @@ export interface ApiErrorLike extends Error {
|
|
|
57
57
|
/** Whether `error` is an `Error` of this `name`: the client's errors are told by it, never `instanceof`. */
|
|
58
58
|
export declare const isNamed: (error: unknown, name: string) => error is Error;
|
|
59
59
|
/**
|
|
60
|
-
* Whether `error` is an `ApiError` of `@
|
|
60
|
+
* Whether `error` is an `ApiError` of `@softistx/graphql-client`, by the test
|
|
61
61
|
* that client's `isApiError` makes (an `Error` named `ApiError` with an
|
|
62
62
|
* `errors` array), plus a numeric `status`, which `ApiErrorLike` promises.
|
|
63
63
|
* It holds across two copies of the client.
|
|
@@ -102,13 +102,13 @@ export declare function attemptsLeftOf(error: ApiErrorLike): number | undefined;
|
|
|
102
102
|
* themselves, where older errors and the extras of a few sit.
|
|
103
103
|
*/
|
|
104
104
|
export declare function valuesOf(extensions: ApiErrorExtensionsLike | undefined): Record<string, unknown> | undefined;
|
|
105
|
-
/** `@
|
|
105
|
+
/** `@softistx/graphql-client`'s `ApiStatusError`, as far as the failure reads it. */
|
|
106
106
|
export interface StatusErrorLike extends Error {
|
|
107
107
|
status: number;
|
|
108
108
|
statusText?: string | undefined;
|
|
109
109
|
body?: unknown;
|
|
110
110
|
}
|
|
111
|
-
/** `@
|
|
111
|
+
/** `@softistx/graphql-client`'s `ApiUnavailableError`, as far as the failure reads it. */
|
|
112
112
|
export interface UnavailableErrorLike extends Error {
|
|
113
113
|
reason: string;
|
|
114
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-error.d.ts","sourceRoot":"","sources":["../../src/errors/api-error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,Q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`routeError` reads
|
|
23
23
|
* it.
|
|
24
24
|
*
|
|
25
|
-
* It recognises `@
|
|
25
|
+
* It recognises `@softistx/graphql-client`'s errors by their `name`, never with
|
|
26
26
|
* `instanceof`, so it needs no import of the client and holds across two
|
|
27
27
|
* copies of it.
|
|
28
28
|
*/
|
package/dist/errors/index.js.map
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"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 { formRefusal } from './form-refusal';\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\tformRefusal: (error, language, fieldOf, route) =>\n\t\t\tformRefusal(parts, error, language, fieldOf, 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",
|
|
11
11
|
"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 { FormRefusal } from './form-refusal';\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 * A fetcher form's refusal (`fetcherRefusal`) with its field issues under\n\t * the form field `fieldOf` names for each input path: `{ error,\n\t * fieldErrors, status }`, `error` empty when every issue found its field.\n\t */\n\tformRefusal(\n\t\terror: unknown,\n\t\tlanguage: L,\n\t\tfieldOf: (path: string) => string | undefined,\n\t\troute?: RouteErrorOptions,\n\t): FormRefusal;\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",
|
|
12
12
|
"/** 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",
|
|
13
|
-
"import { isApiErrorLike, isStatusError, isUnavailableError } from './api-error';\nimport { quietLog } from './log';\nimport { isProblemErrorLike } from './problem-error';\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` or `ProblemError` 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 `@
|
|
13
|
+
"import { isApiErrorLike, isStatusError, isUnavailableError } from './api-error';\nimport { quietLog } from './log';\nimport { isProblemErrorLike } from './problem-error';\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` or `ProblemError` 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 `@softistx/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 (isProblemErrorLike(error)) {\n\t\tif (requestId) error.requestId = requestId;\n\t\tconst line = `${call} answered ${error.status}`;\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",
|
|
14
14
|
"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",
|
|
15
15
|
"import type { ApiMessages, CatalogueMessage } from './messages';\n\n/** What the API answers for one language: its version and every message. */\nexport type CatalogueReply = {\n\tversion: string;\n\tmessages: ReadonlyArray<CatalogueMessage & { readonly code: string }>;\n};\n\n/** A language's catalogue as held, and when its version was last confirmed. */\nexport type Held = { version: string; checkedAt: number };\n\nexport interface CatalogueReaderOptions<L extends string> {\n\tmessages: ApiMessages<L>;\n\tread(language: L): Promise<CatalogueReply>;\n\tretryMs: number;\n\tfirstReadWaitMs: number;\n\tlog: Pick<Console, 'error'>;\n}\n\n/**\n * Waits for the read, until `firstReadWaitMs` after it started (not after\n * this request came: a hung API holds a request at most that long in\n * all); the read goes on either way.\n */\nasync function boundedWait(\n\tpending: { read: Promise<void>; started: number },\n\tfirstReadWaitMs: number,\n) {\n\tconst left = firstReadWaitMs - (performance.now() - pending.started);\n\tif (left <= 0) return;\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst limit = new Promise<void>((resolve) => {\n\t\ttimer = setTimeout(resolve, left);\n\t});\n\tawait Promise.race([pending.read, limit]);\n\tclearTimeout(timer);\n}\n\n/**\n * The reading half of the catalogue: the first read of each language (one in\n * flight, a bounded wait, a retry delay after a failure) and the version\n * each one holds. `createErrorCatalogue` adds the TTL check on top.\n */\nexport function createCatalogueReader<L extends string>({\n\tmessages,\n\tread,\n\tretryMs,\n\tfirstReadWaitMs,\n\tlog,\n}: CatalogueReaderOptions<L>) {\n\tconst held = new Map<L, Held>();\n\tconst loading = new Map<L, { read: Promise<void>; started: number }>();\n\tconst failedAt = new Map<L, number>();\n\n\t/** Reads one language's messages and holds them. */\n\tasync function load(language: L, now: number) {\n\t\tconst reply = await read(language);\n\t\tconst entries: Record<string, CatalogueMessage> = Object.create(null);\n\t\tfor (const { code, message, params } of reply.messages) {\n\t\t\tentries[code] = { message, params };\n\t\t}\n\t\tmessages.set(language, entries);\n\t\theld.set(language, { version: reply.version, checkedAt: now });\n\t}\n\n\t/** The first read of a language, once however many pages ask at the same time. */\n\tfunction loadOnce(language: L, now: number) {\n\t\tlet pending = loading.get(language);\n\t\tif (!pending) {\n\t\t\tconst started = performance.now();\n\t\t\tconst reading = load(language, now)\n\t\t\t\t.then(() => {\n\t\t\t\t\tfailedAt.delete(language);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\t// When it failed, not when it started: a read that hung for\n\t\t\t\t\t// the wait is not retried at once by the next request.\n\t\t\t\t\tfailedAt.set(language, now + (performance.now() - started));\n\t\t\t\t\tlog.error(\n\t\t\t\t\t\t`alxia-react-router: the error catalogue (${language}) was not read`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tloading.delete(language);\n\t\t\t\t});\n\t\t\tpending = { read: reading, started };\n\t\t\tloading.set(language, pending);\n\t\t}\n\t\treturn pending;\n\t}\n\n\treturn {\n\t\theld,\n\t\tload,\n\t\t/** Reads a language that is not held yet, unless a failure is still fresh. */\n\t\tasync first(language: L, now: number) {\n\t\t\tconst failed = failedAt.get(language);\n\t\t\tif (failed === undefined || now - failed >= retryMs) {\n\t\t\t\tawait boundedWait(loadOnce(language, now), firstReadWaitMs);\n\t\t\t}\n\t\t},\n\t\treset() {\n\t\t\theld.clear();\n\t\t\tloading.clear();\n\t\t\tfailedAt.clear();\n\t\t},\n\t};\n}\n",
|
|
16
16
|
"import { checkVersions, safeTtl } from './catalogue-check';\nimport { type CatalogueReply, createCatalogueReader } from './catalogue-read';\nimport { quietLog } from './log';\nimport type { ApiMessages, CatalogueMessages } from './messages';\n\nexport type { CatalogueReply } from './catalogue-read';\n\nexport interface ErrorCatalogueOptions<L extends string> {\n\t/** The store the page words refusals from (`createApiMessages`). */\n\tmessages: ApiMessages<L>;\n\t/** The languages to hold, each read once and kept fresh. */\n\tlanguages: readonly L[];\n\t/** Reads one language's catalogue from the API. */\n\tread(language: L): Promise<CatalogueReply>;\n\t/** Asks the API for the version of every language, in one call. */\n\tversions(): Promise<Partial<Record<L, string>>>;\n\t/** How long a held catalogue is served before its version is checked. */\n\tttlMs: number | (() => number);\n\t/** How soon a check or a first read that failed is tried again. Default 5000. */\n\tretryMs?: number;\n\t/**\n\t * How long a request waits for a language's first read; past it the\n\t * request goes on and the read carries on in the background. Default 1500.\n\t */\n\tfirstReadWaitMs?: number;\n\t/** The codes the browser words itself (`clientMessages`). */\n\tclientCodes: readonly string[];\n\t/** Where failures are reported. Default `console`. */\n\tlog?: Pick<Console, 'error'>;\n}\n\n/** The API's error catalogue, kept fresh for the server. */\nexport interface ErrorCatalogue<L extends string> {\n\t/**\n\t * The catalogue of `language`, ready to word a refusal. Only a language\n\t * with no catalogue yet is awaited, for at most `firstReadWaitMs`. A held\n\t * one is served as it is, and once older than the TTL its version is\n\t * checked in the background, one check at a time.\n\t */\n\tfresh(language: L, now?: number): Promise<void>;\n\t/** Every language, fresh: what the root middleware awaits. */\n\tfreshAll(now?: number): Promise<void>;\n\t/** At startup: reads every language without holding the boot back. */\n\twarm(): void;\n\t/** The messages the browser words itself, by language, for the root's loader. */\n\tclientMessages(): Record<L, CatalogueMessages>;\n\t/**\n\t * Forgets everything held and in flight. For use between tests, with\n\t * nothing in flight: a read or check still running when it is called\n\t * finishes and holds its result again.\n\t */\n\treset(): void;\n\t/** The version held for a language, if any. */\n\theldVersion(language: L): string | undefined;\n\t/** Waits for the check in flight, if any (tests). */\n\tsettled(): Promise<void>;\n}\n\n/** The messages the browser words itself, by language. */\nfunction clientMessages<L extends string>(\n\tmessages: ApiMessages<L>,\n\tlanguages: readonly L[],\n\tclientCodes: readonly string[],\n) {\n\tconst byLanguage = {} as Record<L, CatalogueMessages>;\n\tfor (const language of languages) {\n\t\tconst entries: Record<string, CatalogueMessages[string]> =\n\t\t\tObject.create(null);\n\t\tfor (const code of clientCodes) {\n\t\t\tconst entry = messages.messageOf(language, code);\n\t\t\tif (entry) entries[code] = entry;\n\t\t}\n\t\tbyLanguage[language] = entries;\n\t}\n\treturn byLanguage;\n}\n\n/**\n * Keeps the API's error catalogue in `messages`: read on first use, checked\n * against the API's versions once per TTL, and re-read only for the\n * languages whose version moved. It is an instance, not module state.\n */\nexport function createErrorCatalogue<L extends string>({\n\tmessages,\n\tlanguages,\n\tread,\n\tversions,\n\tttlMs,\n\tretryMs = 5_000,\n\tfirstReadWaitMs = 1_500,\n\tclientCodes,\n\tlog: appLog = console,\n}: ErrorCatalogueOptions<L>): ErrorCatalogue<L> {\n\tif (languages.length === 0) {\n\t\tthrow new TypeError('createErrorCatalogue(): needs at least one language.');\n\t}\n\tconst log = quietLog(appLog, ['error']);\n\tconst ttl = safeTtl(ttlMs, retryMs, log);\n\tconst reader = createCatalogueReader({\n\t\tmessages,\n\t\tread,\n\t\tretryMs,\n\t\tfirstReadWaitMs,\n\t\tlog,\n\t});\n\tconst context = { reader, versions, ttl, retryMs, log };\n\tlet checking: Promise<void> | undefined;\n\n\tasync function fresh(language: L, now: number = Date.now()) {\n\t\tconst entry = reader.held.get(language);\n\t\tif (!entry) return reader.first(language, now);\n\t\tif (now - entry.checkedAt >= ttl() && !checking) {\n\t\t\tchecking = checkVersions(context, now)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tchecking = undefined;\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t}\n\t}\n\n\tconst freshAll = async (now: number = Date.now()) => {\n\t\tawait Promise.all(languages.map((language) => fresh(language, now)));\n\t};\n\n\treturn {\n\t\tfresh,\n\t\tfreshAll,\n\t\twarm() {\n\t\t\tfreshAll().catch((error) => {\n\t\t\t\tlog.error(\n\t\t\t\t\t'alxia-react-router: the error catalogue was not warmed',\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t});\n\t\t},\n\t\tclientMessages: () => clientMessages(messages, languages, clientCodes),\n\t\treset() {\n\t\t\treader.reset();\n\t\t\tchecking = undefined;\n\t\t\tmessages.clear();\n\t\t},\n\t\theldVersion: (language) => reader.held.get(language)?.version,\n\t\tsettled: () => checking ?? Promise.resolve(),\n\t};\n}\n",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrecacheEntry } from '../model/precache-list';
|
|
1
|
+
import type { PrecacheEntry, PrecacheRoutes } from '../model/precache-list';
|
|
2
2
|
import { type WorkerContract } from '../model/worker-contract';
|
|
3
3
|
export interface BuildWorkerOptions {
|
|
4
4
|
/**
|
|
@@ -16,6 +16,13 @@ export interface BuildWorkerOptions {
|
|
|
16
16
|
offline?: boolean;
|
|
17
17
|
/** More files of `assets/` to precache, such as fonts: the app's regex. */
|
|
18
18
|
precacheAssets?: RegExp;
|
|
19
|
+
/**
|
|
20
|
+
* Which routes' code the worker precaches: `"all"` (the default), `"root"`
|
|
21
|
+
* (the client entry and the root route, with their imports and CSS), a
|
|
22
|
+
* RegExp or a `(routeId) => boolean` over the route ids, which adds the
|
|
23
|
+
* matching routes to those two. The other routes are cached when visited.
|
|
24
|
+
*/
|
|
25
|
+
precacheRoutes?: PrecacheRoutes;
|
|
19
26
|
/** `true` by default. */
|
|
20
27
|
minify?: boolean;
|
|
21
28
|
}
|
|
@@ -33,7 +40,7 @@ export declare function assertBun(onBun?: boolean): void;
|
|
|
33
40
|
/**
|
|
34
41
|
* Bundles the worker (Workbox included) into the client build, after
|
|
35
42
|
* `react-router build`, with the precache list written in: the offline page
|
|
36
|
-
* by its content,
|
|
43
|
+
* by its content, the routes' code (`precacheRoutes`) and `precacheAssets`. A new build
|
|
37
44
|
* changes the list, so the worker's bytes, so the browser installs it.
|
|
38
45
|
* Runs on Bun; the only imports of this module are Node's built-ins.
|
|
39
46
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-worker.d.ts","sourceRoot":"","sources":["../../../src/pwa/build/build-worker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"build-worker.d.ts","sourceRoot":"","sources":["../../../src/pwa/build/build-worker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,0BAA0B,CAAC;AAIlC,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,kBAAkB,GAAG,YAAY,CAAC,CAAC;IACnE,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,yBAAyB;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC3B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,qDAAqD;IACrD,aAAa,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;CACd;AAED,+EAA+E;AAC/E,wBAAgB,SAAS,CACxB,KAAK,UAAsD,GACzD,IAAI,CAKN;AAoBD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAChC,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,WAAW,CAAC,CAiEtB"}
|
package/dist/pwa/build/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type PrecacheEntry } from '../model/precache-list';
|
|
1
|
+
import { type PrecacheEntry, type PrecacheRoutes } from '../model/precache-list';
|
|
2
2
|
/** The one React Router browser manifest among the names in build/client/assets. */
|
|
3
3
|
export declare function browserManifestFile(files: readonly string[]): string;
|
|
4
4
|
/** A file's revision: the first 16 hex characters of its sha256. */
|
|
5
5
|
export declare function revisionOf(bytes: Uint8Array): string;
|
|
6
6
|
/**
|
|
7
7
|
* The worker's precache list: the offline page (revisioned by its content),
|
|
8
|
-
*
|
|
8
|
+
* the routes' code (`routes`: all by default), then the asset files `include` matches. Each URL once,
|
|
9
9
|
* the first kept.
|
|
10
10
|
*/
|
|
11
11
|
export declare function workerPrecache(input: {
|
|
@@ -13,5 +13,6 @@ export declare function workerPrecache(input: {
|
|
|
13
13
|
assetFiles: readonly string[];
|
|
14
14
|
offline?: PrecacheEntry | undefined;
|
|
15
15
|
include?: RegExp | undefined;
|
|
16
|
+
routes?: PrecacheRoutes | undefined;
|
|
16
17
|
}): PrecacheEntry[];
|
|
17
18
|
//# sourceMappingURL=precache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precache.d.ts","sourceRoot":"","sources":["../../../src/pwa/build/precache.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"precache.d.ts","sourceRoot":"","sources":["../../../src/pwa/build/precache.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,aAAa,EAClB,KAAK,cAAc,EAGnB,MAAM,wBAAwB,CAAC;AAEhC,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CASpE;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;CACpC,GAAG,aAAa,EAAE,CAQlB"}
|
package/dist/pwa/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { type Caching, type CachingOptions, cachingFor, type RequestFacts, } fro
|
|
|
7
7
|
export { clearAppCaches } from './model/clear-app-caches';
|
|
8
8
|
export { fontPrecachePattern } from './model/font-precache';
|
|
9
9
|
export { MANIFEST_HEADERS, MANIFEST_PATH, type ManifestIcon, MINIMAL_2023_ICONS, manifestHref, manifestLanguage, type WebAppManifest, type WebAppManifestOptions, webAppManifest, } from './model/manifest';
|
|
10
|
-
export { assetPrecache, type BrowserManifest, type PrecacheEntry, parseBrowserManifest, precacheList, } from './model/precache-list';
|
|
10
|
+
export { assetPrecache, type BrowserManifest, type PrecacheEntry, type PrecacheRoutes, parseBrowserManifest, precacheList, } from './model/precache-list';
|
|
11
11
|
export { type ApplyUpdate, afterLoad, createUpdater, type RegisterOptions, registerServiceWorker, type ServiceWorkerContainerLike, watchForUpdates, } from './model/registration';
|
|
12
12
|
export { isStorable } from './model/storable';
|
|
13
13
|
export { themeColorHex, themeColors } from './model/theme-color';
|
package/dist/pwa/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pwa/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,YAAY,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACN,gBAAgB,EAChB,aAAa,EACb,KAAK,YAAY,EACjB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,oBAAoB,EACpB,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,WAAW,EAChB,SAAS,EACT,aAAa,EACb,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,0BAA0B,EAC/B,eAAe,GACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EACN,kBAAkB,EAClB,KAAK,aAAa,EAClB,YAAY,EACZ,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,iBAAiB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,UAAU,EACf,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC1B,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pwa/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,YAAY,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACN,gBAAgB,EAChB,aAAa,EACb,KAAK,YAAY,EACjB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,oBAAoB,EACpB,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,WAAW,EAChB,SAAS,EACT,aAAa,EACb,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,0BAA0B,EAC/B,eAAe,GACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EACN,kBAAkB,EAClB,KAAK,aAAa,EAClB,YAAY,EACZ,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,iBAAiB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,UAAU,EACf,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC1B,MAAM,yBAAyB,CAAC"}
|
package/dist/pwa/index.js
CHANGED
|
@@ -28,8 +28,18 @@ export type PrecacheEntry = {
|
|
|
28
28
|
};
|
|
29
29
|
/** Reads `window.__reactRouterManifest={…};` (build/client/assets/manifest-*.js). */
|
|
30
30
|
export declare function parseBrowserManifest(source: string): BrowserManifest;
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Which routes' code the list holds: `"all"` (the default), `"root"` (the
|
|
33
|
+
* root route alone), a RegExp or a predicate over the route ids of
|
|
34
|
+
* `app/routes.ts` (`root`, `routes/items`, …). The client entry, its imports
|
|
35
|
+
* and the `root` route are always kept, since every page renders inside them.
|
|
36
|
+
*/
|
|
37
|
+
export type PrecacheRoutes = 'all' | 'root' | RegExp | ((routeId: string) => boolean);
|
|
38
|
+
/**
|
|
39
|
+
* The hashed scripts and stylesheets the routes need, the manifest's own file
|
|
40
|
+
* first. `routes` narrows which routes' code is kept (all of them by default).
|
|
41
|
+
*/
|
|
42
|
+
export declare function precacheList(manifest: BrowserManifest, routes?: PrecacheRoutes): PrecacheEntry[];
|
|
33
43
|
/**
|
|
34
44
|
* The precache entries of the files among `assetFiles` (the names in
|
|
35
45
|
* build/client/assets) that `include` matches, sorted, under `base`: fonts
|