@websolutespa/bom-next 4.0.0-next.15 → 4.0.0-next.17

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.
Files changed (258) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +12 -1
  3. package/dist/cache-handler/redis.js.map +1 -1
  4. package/dist/cache-handlers/default.js.map +1 -1
  5. package/dist/client/client.js +5 -5
  6. package/dist/client/client.js.map +1 -1
  7. package/dist/client/extra.js.map +1 -1
  8. package/dist/client/label.js.map +1 -1
  9. package/dist/client/layout.js.map +1 -1
  10. package/dist/client/live-preview.d.ts +14 -0
  11. package/dist/client/live-preview.d.ts.map +1 -0
  12. package/dist/client/live-preview.js +55 -0
  13. package/dist/client/live-preview.js.map +1 -0
  14. package/dist/client/local.collection.js.map +1 -1
  15. package/dist/client/metadata.js.map +1 -1
  16. package/dist/client/page.d.ts.map +1 -1
  17. package/dist/client/page.js +5 -1
  18. package/dist/client/page.js.map +1 -1
  19. package/dist/client/useApi.js.map +1 -1
  20. package/dist/client/useCollectionApi.js.map +1 -1
  21. package/dist/client/useExtra.js.map +1 -1
  22. package/dist/client/useHttp.js.map +1 -1
  23. package/dist/client/useLabel.js.map +1 -1
  24. package/dist/client/useLayout.js.map +1 -1
  25. package/dist/client/useLink.js.map +1 -1
  26. package/dist/client/useMetaData.js.map +1 -1
  27. package/dist/client/usePage.d.ts.map +1 -1
  28. package/dist/client/usePage.js.map +1 -1
  29. package/dist/client/useUser.js.map +1 -1
  30. package/dist/client/user.js.map +1 -1
  31. package/dist/config/with-bom.js.map +1 -1
  32. package/dist/exports/client.d.ts +2 -1
  33. package/dist/exports/client.js +2 -1
  34. package/dist/exports/server.d.ts +4 -3
  35. package/dist/exports/server.js +3 -2
  36. package/dist/instrumentation/client.js.map +1 -1
  37. package/dist/instrumentation/sentry/capture.requestError.js.map +1 -1
  38. package/dist/instrumentation/sentry/capture.routerTransitionStart.js.map +1 -1
  39. package/dist/instrumentation/sentry/config.client.js.map +1 -1
  40. package/dist/instrumentation/sentry/config.edge.js.map +1 -1
  41. package/dist/instrumentation/sentry/config.server.js.map +1 -1
  42. package/dist/instrumentation/server.js.map +1 -1
  43. package/dist/lib/breadcrumb.js.map +1 -1
  44. package/dist/lib/const.js.map +1 -1
  45. package/dist/lib/debug.js.map +1 -1
  46. package/dist/lib/http.js.map +1 -1
  47. package/dist/lib/label.js.map +1 -1
  48. package/dist/lib/layout.defaults.js.map +1 -1
  49. package/dist/lib/link.js.map +1 -1
  50. package/dist/lib/live-preview.js +21 -0
  51. package/dist/lib/live-preview.js.map +1 -0
  52. package/dist/lib/page-metadata.js.map +1 -1
  53. package/dist/lib/pagination.js.map +1 -1
  54. package/dist/lib/route.js.map +1 -1
  55. package/dist/lib/store.js.map +1 -1
  56. package/dist/lib/utils.js.map +1 -1
  57. package/dist/mock.d.ts +5 -1
  58. package/dist/mock.d.ts.map +1 -1
  59. package/dist/proxy/protected-route.js.map +1 -1
  60. package/dist/proxy/proxy.js.map +1 -1
  61. package/dist/server/cache/cached-types.js.map +1 -1
  62. package/dist/server/cache/cached.js.map +1 -1
  63. package/dist/server/cache/defaults.js.map +1 -1
  64. package/dist/server/cache/executor.js +1 -1
  65. package/dist/server/cache/executor.js.map +1 -1
  66. package/dist/server/cache/handler.js.map +1 -1
  67. package/dist/server/cache/inspector/filesystem.js.map +1 -1
  68. package/dist/server/cache/inspector/index.js.map +1 -1
  69. package/dist/server/cache/inspector/redis.js.map +1 -1
  70. package/dist/server/cache/inspector/route-cache-key.js.map +1 -1
  71. package/dist/server/cache/inspector/types.js.map +1 -1
  72. package/dist/server/cache/local-executor.js.map +1 -1
  73. package/dist/server/cache/mode/classic.js +1 -1
  74. package/dist/server/cache/mode/classic.js.map +1 -1
  75. package/dist/server/cache/mode/components.js +1 -1
  76. package/dist/server/cache/mode/components.js.map +1 -1
  77. package/dist/server/cache/profiles.js.map +1 -1
  78. package/dist/server/cache/registry.js.map +1 -1
  79. package/dist/server/cache/tag-page.js.map +1 -1
  80. package/dist/server/context.d.ts +38 -2
  81. package/dist/server/context.d.ts.map +1 -1
  82. package/dist/server/context.js +58 -2
  83. package/dist/server/context.js.map +1 -1
  84. package/dist/server/handlers/captions.handler.js.map +1 -1
  85. package/dist/server/handlers/collection.handler.js.map +1 -1
  86. package/dist/server/handlers/error-response.js.map +1 -1
  87. package/dist/server/handlers/index.handler.js.map +1 -1
  88. package/dist/server/handlers/preview.handler.d.ts.map +1 -1
  89. package/dist/server/handlers/preview.handler.js +34 -4
  90. package/dist/server/handlers/preview.handler.js.map +1 -1
  91. package/dist/server/handlers/registry.handler.js.map +1 -1
  92. package/dist/server/handlers/revalidate.handler.js.map +1 -1
  93. package/dist/server/handlers/route.handler.js.map +1 -1
  94. package/dist/server/handlers/sitemap.handler.js.map +1 -1
  95. package/dist/server/handlers/static-params.handler.js.map +1 -1
  96. package/dist/server/handlers/vars.handler.js.map +1 -1
  97. package/dist/server/helpers.js.map +1 -1
  98. package/dist/server/json-ld.js.map +1 -1
  99. package/dist/server/layout.js.map +1 -1
  100. package/dist/server/lazy.d.ts +24 -2
  101. package/dist/server/lazy.d.ts.map +1 -1
  102. package/dist/server/lazy.js +80 -7
  103. package/dist/server/lazy.js.map +1 -1
  104. package/dist/server/live-preview-store.js +59 -0
  105. package/dist/server/live-preview-store.js.map +1 -0
  106. package/dist/server/live-preview.actions.js +38 -0
  107. package/dist/server/live-preview.actions.js.map +1 -0
  108. package/dist/server/live-preview.d.ts +11 -0
  109. package/dist/server/live-preview.d.ts.map +1 -0
  110. package/dist/server/live-preview.js +39 -0
  111. package/dist/server/live-preview.js.map +1 -0
  112. package/dist/server/local-api.js.map +1 -1
  113. package/dist/server/metadata.js.map +1 -1
  114. package/dist/server/mixer.d.ts +6 -1
  115. package/dist/server/mixer.d.ts.map +1 -1
  116. package/dist/server/mixer.js +7 -3
  117. package/dist/server/mixer.js.map +1 -1
  118. package/dist/server/page.js.map +1 -1
  119. package/dist/server/utils.js.map +1 -1
  120. package/dist/server/utmz.js.map +1 -1
  121. package/dist/types.d.ts +5 -0
  122. package/dist/types.d.ts.map +1 -1
  123. package/package.json +4 -3
  124. package/src/cache-handler/redis.test.ts +230 -230
  125. package/src/cache-handler/redis.ts +344 -344
  126. package/src/cache-handlers/default.test.ts +125 -125
  127. package/src/cache-handlers/default.ts +246 -246
  128. package/src/client/client.tsx +20 -20
  129. package/src/client/extra.tsx +17 -17
  130. package/src/client/label.tsx +20 -20
  131. package/src/client/layout.tsx +18 -18
  132. package/src/client/live-preview.test.tsx +110 -0
  133. package/src/client/live-preview.tsx +64 -0
  134. package/src/client/local.collection.ts +72 -72
  135. package/src/client/metadata.tsx +187 -187
  136. package/src/client/page.tsx +24 -18
  137. package/src/client/useApi.test.tsx +212 -212
  138. package/src/client/useApi.ts +115 -115
  139. package/src/client/useCollectionApi.test.tsx +213 -213
  140. package/src/client/useCollectionApi.ts +135 -135
  141. package/src/client/useExtra.tsx +12 -12
  142. package/src/client/useHttp.ts +78 -78
  143. package/src/client/useLabel.test.tsx +82 -82
  144. package/src/client/useLabel.tsx +12 -12
  145. package/src/client/useLayout.tsx +13 -13
  146. package/src/client/useLink.tsx +16 -16
  147. package/src/client/useMetaData.tsx +12 -12
  148. package/src/client/usePage.tsx +12 -12
  149. package/src/client/useUser.tsx +12 -12
  150. package/src/client/user.test.tsx +63 -63
  151. package/src/client/user.tsx +73 -73
  152. package/src/config/with-bom.test.ts +61 -61
  153. package/src/config/with-bom.ts +68 -68
  154. package/src/exports/cache-handlers-default.ts +3 -3
  155. package/src/exports/cache-handlers-isr.ts +9 -9
  156. package/src/exports/client.ts +20 -19
  157. package/src/exports/config.ts +3 -3
  158. package/src/exports/instrumentation.ts +1 -1
  159. package/src/exports/server.ts +1 -0
  160. package/src/global.d.ts +6 -6
  161. package/src/instrumentation/client.ts +18 -18
  162. package/src/instrumentation/sentry/capture.requestError.ts +9 -9
  163. package/src/instrumentation/sentry/capture.routerTransitionStart.ts +7 -7
  164. package/src/instrumentation/sentry/config.client.ts +9 -9
  165. package/src/instrumentation/sentry/config.edge.ts +9 -9
  166. package/src/instrumentation/sentry/config.server.ts +9 -9
  167. package/src/instrumentation/server.ts +39 -39
  168. package/src/instrumentation/types.ts +11 -11
  169. package/src/lib/breadcrumb.ts +25 -25
  170. package/src/lib/const.ts +28 -28
  171. package/src/lib/debug.ts +11 -11
  172. package/src/lib/http.test.ts +25 -25
  173. package/src/lib/http.ts +127 -127
  174. package/src/lib/label.ts +47 -47
  175. package/src/lib/layout.defaults.ts +167 -167
  176. package/src/lib/link.ts +19 -19
  177. package/src/lib/live-preview.ts +35 -0
  178. package/src/lib/meta-data.ts +60 -60
  179. package/src/lib/open-graph.ts +165 -165
  180. package/src/lib/page-metadata.test.ts +192 -192
  181. package/src/lib/page-metadata.ts +296 -296
  182. package/src/lib/pagination.ts +80 -80
  183. package/src/lib/route.test.ts +62 -62
  184. package/src/lib/route.ts +117 -117
  185. package/src/lib/store.ts +63 -63
  186. package/src/lib/structured-data.ts +24 -24
  187. package/src/lib/twitter-card.ts +49 -49
  188. package/src/lib/utils.ts +44 -44
  189. package/src/mock.ts +5 -1
  190. package/src/proxy/protected-route.test.ts +75 -75
  191. package/src/proxy/protected-route.ts +68 -68
  192. package/src/proxy/proxy.test.ts +51 -51
  193. package/src/proxy/proxy.ts +81 -81
  194. package/src/server/cache/cached-types.ts +73 -73
  195. package/src/server/cache/cached.test.ts +115 -115
  196. package/src/server/cache/cached.ts +22 -22
  197. package/src/server/cache/defaults.ts +46 -46
  198. package/src/server/cache/executor.test.ts +134 -134
  199. package/src/server/cache/executor.ts +141 -141
  200. package/src/server/cache/handler.test.ts +122 -122
  201. package/src/server/cache/handler.ts +126 -126
  202. package/src/server/cache/index.ts +39 -39
  203. package/src/server/cache/inspector/filesystem.test.ts +142 -142
  204. package/src/server/cache/inspector/filesystem.ts +214 -214
  205. package/src/server/cache/inspector/index.ts +19 -19
  206. package/src/server/cache/inspector/redis.test.ts +97 -97
  207. package/src/server/cache/inspector/redis.ts +183 -183
  208. package/src/server/cache/inspector/route-cache-key.test.ts +31 -31
  209. package/src/server/cache/inspector/route-cache-key.ts +40 -40
  210. package/src/server/cache/inspector/types.ts +49 -49
  211. package/src/server/cache/local-executor.ts +39 -39
  212. package/src/server/cache/mode/classic.ts +59 -59
  213. package/src/server/cache/mode/components.test.ts +53 -53
  214. package/src/server/cache/mode/components.ts +64 -64
  215. package/src/server/cache/profiles.ts +41 -41
  216. package/src/server/cache/registry.test.ts +66 -66
  217. package/src/server/cache/registry.ts +82 -82
  218. package/src/server/cache/route-parity.test.ts +33 -33
  219. package/src/server/cache/tag-page.ts +23 -23
  220. package/src/server/context.cache.test.ts +79 -79
  221. package/src/server/context.test.ts +810 -645
  222. package/src/server/context.ts +580 -488
  223. package/src/server/context.type-test.ts +112 -112
  224. package/src/server/handlers/captions.handler.ts +36 -36
  225. package/src/server/handlers/collection.handler.test.ts +63 -63
  226. package/src/server/handlers/collection.handler.ts +221 -221
  227. package/src/server/handlers/error-response.ts +50 -50
  228. package/src/server/handlers/index.handler.ts +153 -153
  229. package/src/server/handlers/preview.handler.test.ts +124 -92
  230. package/src/server/handlers/preview.handler.ts +134 -95
  231. package/src/server/handlers/registry.handler.test.ts +171 -171
  232. package/src/server/handlers/registry.handler.ts +514 -514
  233. package/src/server/handlers/revalidate.handler.ts +148 -148
  234. package/src/server/handlers/route.handler.test.ts +50 -50
  235. package/src/server/handlers/route.handler.ts +188 -188
  236. package/src/server/handlers/sitemap.handler.ts +432 -432
  237. package/src/server/handlers/static-params.cache.test.ts +81 -81
  238. package/src/server/handlers/static-params.handler.ts +123 -123
  239. package/src/server/handlers/vars.handler.ts +174 -174
  240. package/src/server/helpers.ts +97 -97
  241. package/src/server/json-ld.tsx +65 -65
  242. package/src/server/layout.ts +148 -148
  243. package/src/server/lazy.cache.test.ts +168 -0
  244. package/src/server/lazy.ts +155 -41
  245. package/src/server/live-preview-store.ts +104 -0
  246. package/src/server/live-preview.actions.test.ts +113 -0
  247. package/src/server/live-preview.actions.ts +61 -0
  248. package/src/server/live-preview.ts +50 -0
  249. package/src/server/local-api.ts +67 -67
  250. package/src/server/metadata.ts +79 -79
  251. package/src/server/mixer-payload.ts +115 -115
  252. package/src/server/mixer-payload.type-test.ts +27 -27
  253. package/src/server/mixer.ts +516 -513
  254. package/src/server/page.ts +148 -148
  255. package/src/server/request-data.test.ts +39 -34
  256. package/src/server/utils.ts +23 -23
  257. package/src/server/utmz.ts +11 -11
  258. package/src/types.ts +368 -363
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @websolutespa/bom-next
2
2
 
3
+ ## 4.0.0-next.17
4
+
5
+ ### Patch Changes
6
+
7
+ - `IMockLocale` accepts `isActive`, so a seed can keep a Payload locale for content and give it no routes (`{ id: 'en', title: 'English', isActive: false }`).
8
+
9
+ ## 4.0.0-next.16
10
+
11
+ ### Minor Changes
12
+
13
+ - 13f1d9c: With Cache Components, the server decorators registered with `withLazyProps` run in their own `'use cache'` scope (`bom:fn:lazy-props`) on public renders, keyed by the page read and the block. A decorator that reads Payload (a listing) no longer fails the prerender with "unstable value `Date.now()`", and the tags it attaches with `tagPage` invalidate its entry and the page. It receives the guest Payload instance and the mixer context of the page's market and locale, and its result must be serializable. Drafts, authenticated pages, live preview and the classic model call decorators directly, as before. `withLazyProps(key, fn, { life, cache })` sets the lifetime (default `bom-page`) or opts a decorator out with `cache: false`. No change is needed in apps.
14
+ - 75c14fa: **Live preview.** Payload's live preview now works on the page collections, with no code in the app: while the editor types, the preview shows the unsaved values.
15
+ - **bom-next.** For a live preview URL (`_live`) the preview handler sets the `bom-live` cookie next to Draft Mode. `PageProvider` listens to the admin and sends each edit to a Server Action, which keeps the unsaved values for the session and renders the route again; `createPageContext` reads the page with those values in place of the stored ones (Bowl's hooks and population still run, nothing is written). `decorateLazyComponents` does not run the `withLazyProps` loaders again while the editor types: a block keeps what its loader returned and its unsaved values override it; a new block is loaded once. On save everything is read and loaded again. New exports: `isLivePreview()` (server), `LivePreviewListener` (client), `ReadOptions.data`. See "Live preview" in the README for the limits (in-memory per instance, Server Action body size).
16
+ - **payload-plugin-bowl.** `admin.livePreview.collections` is the page collections again (it was emptied waiting for this). The app's `admin.livePreview` now adds to Bowl's defaults instead of replacing them. `getLivePreviewURL` accepts populated `markets` and `template`, and adds the editor's `_token` when the site is not on the admin's origin. The page detail endpoint accepts the unsaved document of a live preview request (`data` in the body of a POST with a GET method override), as Payload's own does.
17
+ - **payload-bowl-live-preview.** New `subscribeLive` (debounced edits and save events, no merge: for a frontend that renders on the server). `mergeData` calls `serverURL` + `apiRoute` (it called the page's own origin), takes the `market` instead of a fixed `ww`, and keeps the current data on an error response. `useLivePreview` no longer breaks the rules of hooks or resubscribes on every render, and keeps the page fields Bowl does not send back; the mixer apps pass the live page to `PageProvider`. `payload` is now a peer dependency. `formatAdminURL` is removed.
18
+
19
+ ### Patch Changes
20
+
21
+ - bd87aa7: `decorateLazyComponents` decorates every copy of the page that `createPageContext` returned in the request. When `generateMetadata` read the same page after the template, the stored context page was the metadata's copy, so the template rendered its blocks without the decorators' data (seen with Cache Components, where render timing varies). Cached decorators also receive a deep copy of their block.
22
+ - Updated dependencies [75c14fa]
23
+ - @websolutespa/payload-bowl-live-preview@4.0.0-next.11
24
+
3
25
  ## 4.0.0-next.15
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -75,6 +75,17 @@ The server context (`getContext`) reads routes from the Bowl route store and cac
75
75
 
76
76
  `getPreviewHandler(config)` is the `/api/-preview` route (`export const GET = getPreviewHandler(config)`). It turns Next.js Draft Mode on and redirects to the page, only for an editor (`PREVIEW_ROLES`: admin, contributor, editor; the admin session cookie, or the `_token` Bowl adds to the admin's preview URL) or with `secret` equal to `MIXER_SECRET`; anyone else gets 401 and no cookie. Templates pass `draft: (await draftMode()).isEnabled` to `createPageContext`; draft renders without an editor session read as `previewer` (an editing role), and only while Draft Mode is on, because Bowl serves drafts to the editing roles only. The old `previewHandler(request)` is deprecated and accepts only the secret.
77
77
 
78
+ ## Live preview
79
+
80
+ Payload's live preview works with no code in the app: Bowl enables it on the page collections and points the preview window to `/api/-preview?...&_live=true`, and `PageProvider` listens to the admin.
81
+
82
+ - **Session.** For a live preview URL the preview handler also sets the `bom-live` cookie (a session id and the origin of the admin: `PAYLOAD_PUBLIC_SERVER_URL`, else `NEXT_PUBLIC_URL`). A request is a live preview only with Draft Mode on and that cookie (`isLivePreview()`).
83
+ - **Each edit.** The preview window receives the unsaved form values from the admin, waits for a pause in typing and sends them to the `setLivePreviewData` Server Action, which keeps them for the session and renders the route again. `createPageContext` then reads the page with those values in place of the stored ones (the `data` option of the Payload local API): Bowl's hooks, rich text and populated relations run as for a saved document. Nothing is written to the database.
84
+ - **Blocks.** While the editor types, `decorateLazyComponents` does not run the `withLazyProps` loaders again: each block keeps what its loader returned on the last full render, and the block's unsaved values override it (`{ ...loaded, ...block }`, matched by block `id`). So a property the loader adds (`items`) stays, and a property the block has in the CMS wins. A block added in the admin, or one without an `id`, is loaded once.
85
+ - **Save.** On a save (or autosave) the unsaved values and the loader results are dropped and the route renders again from the saved draft, loaders included.
86
+
87
+ Limits: the unsaved values live in the memory of the server instance that received them (a later request served by another instance shows the saved draft until the next edit), for 30 minutes; an edit is a Server Action call, so the document must fit Next's `serverActions.bodySizeLimit` (1 MB by default); globals and the layout update on save only. A page that does not use `PageProvider` mounts `<LivePreviewListener />` from `@websolutespa/bom-next/client` instead.
88
+
78
89
  ## Cache
79
90
 
80
91
  Pages are tagged from their route by `createPageContext` and `createLayoutContext`, and invalidated by the Bowl change hooks and the Bowl cache panel (`/admin/cache`). The site exposes its side of the panel with one route:
@@ -91,7 +102,7 @@ export const dynamic = 'force-dynamic';
91
102
  - `bomCached(name, fn, { life, tags, resultTags })` caches a data function by name. `life` is a BOM profile (`bom-layout`, `bom-page`, `bom-listing`, `bom-static`, see `bomProfiles`) or an inline profile. `documentTags(collection, result)` tags a result by its documents. Every entry carries `bom:fn:<name>`, so the panel lists and revalidates it.
92
103
  - `withBom(nextConfig)` (`@websolutespa/bom-next/config`) wires the caching model:
93
104
  - **Classic ISR** (default): `bomCached` uses `unstable_cache`, templates keep `generateStaticParams` and `export const revalidate`.
94
- - **`cacheComponents: true`**: `bomCached` and `tagPage` use `'use cache'`, `cacheLife` and `cacheTag`; the BOM profiles are registered as `cacheLife` profiles, `cacheHandlers.default` is the BOM `'use cache'` handler, and `createPageContext` reads public pages and layouts through cached functions. Templates must drop `export const revalidate`. `getStaticParams` returns at least one route per template (Cache Components refuses an empty list), so every template needs one published page at build time.
105
+ - **`cacheComponents: true`**: `bomCached` and `tagPage` use `'use cache'`, `cacheLife` and `cacheTag`; the BOM profiles are registered as `cacheLife` profiles, `cacheHandlers.default` is the BOM `'use cache'` handler, and `createPageContext` reads public pages and layouts through cached functions. Server decorators (`withLazyProps`) run in their own cached scope on public renders (`bom:fn:lazy-props`, keyed by the page read and the block): their Payload reads are cached, the tags they attach with `tagPage` invalidate them and the page, and their result must be serializable. `withLazyProps(key, fn, { life })` changes the lifetime (default `bom-page`); `{ cache: false }` runs a decorator that reads no data directly. Drafts, authenticated pages and live preview call decorators directly. Templates must drop `export const revalidate`. `getStaticParams` returns at least one route per template (Cache Components refuses an empty list), so every template needs one published page at build time.
95
106
  - **`REDIS_URL` at build time**: `cacheHandler` is the shared Redis handler (`@websolutespa/bom-next/cache-handlers/isr`), which applies `revalidateTag(tag, 'max')` as stale-while-revalidate across instances; `'use cache'` entries share its tag keys.
96
107
  - `registerIntrumentation()` registers the in-process cache executor; Bowl uses `/api/-cache` (Bearer `MIXER_SECRET`) when it runs in another process.
97
108
 
@@ -1 +1 @@
1
- {"version":3,"file":"redis.js","names":[],"sources":["../../src/cache-handler/redis.ts"],"sourcesContent":["/**\n * Next.js incremental cache handler (ISR pages, route handlers, `fetch` and `unstable_cache` entries) backed by\n * Redis, shared by every instance of a site. Set it in `next.config` with `withBom()`, or directly:\n * `cacheHandler: require.resolve('@websolutespa/bom-next/cache-handlers/isr')`, `cacheMaxMemorySize: 0`.\n *\n * - Entries: `${REDIS_PREFIX}:next:<key>`, written as `{ lastModified, tags, revalidate, cacheControl, value }` (in\n * this order: the cache panel reads the head of the value without parsing the page). `get` returns the stored\n * `cacheControl`: Next.js (16.4+) otherwise knows the lifetime only of paths this instance rendered or\n * prerendered, and treats an entry written by another instance as revalidate 1 s (served stale, re-rendered).\n * - Client: one connection per process (`globalThis`), shared by this handler, which Next.js loads from\n * node_modules, and the bundled server code (cache panel inspector, `registerIntrumentation` warm-up).\n * - Meta: `${REDIS_PREFIX}:next-meta:<key>`, a small JSON per entry that the cache panel lists with SCAN.\n * - Tags: `${REDIS_PREFIX}:next-tag:<tag>` is when the tag expired (the next request waits for a fresh render),\n * `${REDIS_PREFIX}:next-tag-stale:<tag>` when it went stale (served once more, regenerated in the background).\n * `revalidateTag(tag, 'max')` sets the stale time; `revalidateTag(tag, { expire: 0 })`, `updateTag` and\n * `revalidatePath` set the expiry. Next.js only applies stale tags of its own file-system cache, so this handler\n * reports a stale entry by moving its `lastModified` back past its revalidate time.\n * - Redis down: reads miss and writes are dropped, so pages still render (uncached) instead of failing.\n */\n\n/** The subset of a `redis` client this handler uses (injectable for tests). */\nexport type RedisLike = {\n isReady: boolean;\n get(key: string): Promise<string | null>;\n mGet(keys: string[]): Promise<(string | null)[]>;\n set(key: string, value: string, options?: { EX?: number }): Promise<unknown>;\n mSet(entries: [string, string][]): Promise<unknown>;\n del(key: string | string[]): Promise<unknown>;\n};\n\nexport type CacheHandlerContext = {\n tags?: string[];\n softTags?: string[];\n revalidate?: number | false;\n cacheControl?: { revalidate?: number | false; expire?: number };\n};\n\nexport const tagsHeader = 'x-next-cache-tags';\n\nexport function redisPrefix(env: NodeJS.ProcessEnv = process.env): string {\n return env.REDIS_PREFIX ? `${env.REDIS_PREFIX}:` : '';\n}\n\nexport const keys = (prefix: string) => ({\n entry: `${prefix}next:`,\n meta: `${prefix}next-meta:`,\n expired: `${prefix}next-tag:`,\n stale: `${prefix}next-tag-stale:`,\n});\n\nfunction replacer(_key: string, value: unknown) {\n if (value instanceof Map) {\n return { __t: 'map', d: Array.from(value.entries()) };\n }\n if (\n value &&\n typeof value === 'object' &&\n (value as { type?: string }).type === 'Buffer' &&\n Array.isArray((value as { data?: unknown }).data)\n ) {\n return { __t: 'buf', d: Buffer.from((value as { data: number[] }).data).toString('base64') };\n }\n return value;\n}\n\nfunction reviver(_key: string, value: unknown) {\n if (value && typeof value === 'object' && (value as { __t?: string }).__t === 'map') {\n return new Map((value as { d: [unknown, unknown][] }).d);\n }\n if (value && typeof value === 'object' && (value as { __t?: string }).__t === 'buf') {\n return Buffer.from((value as { d: string }).d, 'base64');\n }\n return value;\n}\n\n/** Serializes a cache entry, keeping Buffers and Maps (RSC payloads, segment data). */\nexport function encode(entry: unknown): string {\n return JSON.stringify(entry, replacer);\n}\n\n/** Restores a cache entry written by {@link encode}. */\nexport function decode<T = unknown>(raw: string): T {\n return JSON.parse(raw, reviver) as T;\n}\n\n/** The fields of a Next.js cache value this handler reads; the rest is stored as it is. */\ntype CacheValue = {\n kind?: string;\n status?: number;\n revalidate?: number | false;\n headers?: Record<string, string | string[] | undefined>;\n};\n\n/** The lifetime Next.js keeps per route (`CacheControl`); `expire` in seconds. */\ntype StoredCacheControl = { revalidate: number | false; expire: number | undefined };\n\ntype StoredEntry = {\n lastModified: number;\n tags: string[];\n revalidate: number | false | null;\n /** Absent on entries written before 4.0.0-next.12. */\n cacheControl?: StoredCacheControl;\n value: CacheValue;\n};\n\n/** The lifetime returned with an entry, so every instance applies the one it was written with. */\nfunction cacheControlOf(entry: StoredEntry): StoredCacheControl | undefined {\n if (entry.cacheControl) {\n return entry.cacheControl;\n }\n return typeof entry.revalidate === 'number' || entry.revalidate === false\n ? { revalidate: entry.revalidate, expire: undefined }\n : undefined;\n}\n\n/** Explicit tags of a value: the context tags plus the `x-next-cache-tags` header of pages and route handlers. */\nexport function entryTags(\n value: CacheValue | null | undefined,\n ctx: CacheHandlerContext | undefined\n): string[] {\n const tags = new Set(ctx?.tags ?? []);\n const header = value?.headers?.[tagsHeader];\n if (typeof header === 'string') {\n header\n .split(',')\n .filter(Boolean)\n .forEach((tag) => tags.add(tag));\n }\n return Array.from(tags);\n}\n\nfunction revalidateOf(\n value: CacheValue,\n ctx: CacheHandlerContext | undefined\n): number | false | null {\n const revalidate = ctx?.cacheControl?.revalidate ?? ctx?.revalidate ?? value?.revalidate;\n return typeof revalidate === 'number' || revalidate === false ? revalidate : null;\n}\n\ntype ConnectingClient = RedisLike & {\n on(event: 'error' | 'ready', listener: (error: Error) => void): unknown;\n once(event: 'ready', listener: () => void): unknown;\n off(event: 'ready', listener: () => void): unknown;\n connect(): Promise<unknown>;\n};\n\n/**\n * The client lives on `globalThis`: Next.js loads this handler from node_modules while the inspector and the\n * instrumentation are bundled into the app, and module state would give each its own connection.\n */\nconst shared = globalThis as typeof globalThis & { __bomRedisClient?: ConnectingClient };\n\n/** A connecting client used only while ready: awaiting `connect()` would hang every request while Redis is down. */\nexport async function getRedisClient(): Promise<RedisLike | undefined> {\n if (!process.env.REDIS_URL) {\n return undefined;\n }\n if (!shared.__bomRedisClient) {\n const { createClient } = await import('redis');\n // another caller may have created it while the module loaded\n if (shared.__bomRedisClient) {\n return getRedisClient();\n }\n const client = createClient({\n url: process.env.REDIS_URL,\n // fail fast while disconnected instead of queueing commands behind a dead socket\n disableOfflineQueue: true,\n socket: {\n connectTimeout: 2000,\n reconnectStrategy: (retries: number) => Math.min(retries * 200, 5000),\n },\n }) as unknown as ConnectingClient;\n shared.__bomRedisClient = client;\n let logged = false;\n client.on('error', (error: Error) => {\n if (!logged) {\n console.warn('[cache-handler] redis unavailable, serving uncached:', error.message);\n logged = true;\n }\n });\n client.on('ready', () => {\n logged = false;\n });\n client.connect().catch(() => {\n /* reported by the error listener, retried by reconnectStrategy */\n });\n }\n const sharedClient = shared.__bomRedisClient;\n return sharedClient.isReady ? sharedClient : undefined;\n}\n\n/**\n * Starts the shared client and waits until it is ready, up to `timeout` ms (the connect timeout). For callers that\n * may wait, unlike a page lookup: the cache panel, and the startup warm-up, so the first request of a cold instance\n * already reads Redis.\n */\nexport async function connectRedisClient(timeout = 2000): Promise<RedisLike | undefined> {\n const ready = await getRedisClient();\n const client = shared.__bomRedisClient;\n if (ready || !client) {\n return ready;\n }\n await new Promise<void>((resolve) => {\n const done = { timer: undefined as ReturnType<typeof setTimeout> | undefined };\n const onReady = () => {\n clearTimeout(done.timer);\n resolve();\n };\n // no listener left behind while Redis stays down and the panel keeps asking\n done.timer = setTimeout(() => {\n client.off('ready', onReady);\n resolve();\n }, timeout);\n client.once('ready', onReady);\n });\n return client.isReady ? client : undefined;\n}\n\n/** Builds the handler class around a client getter, so tests can inject one. */\nexport function createRedisCacheHandler(\n getClient: () => Promise<RedisLike | undefined> = getRedisClient,\n prefix = redisPrefix()\n) {\n const k = keys(prefix);\n return class RedisCacheHandler {\n constructor(_ctx?: unknown) {}\n\n async get(key: string, ctx?: CacheHandlerContext) {\n const client = await getClient();\n if (!client?.isReady) {\n return null;\n }\n try {\n const raw = await client.get(k.entry + key);\n if (!raw) {\n return null;\n }\n const entry = decode<StoredEntry>(raw);\n const tags = [\n ...new Set([...(entry.tags ?? []), ...(ctx?.tags ?? []), ...(ctx?.softTags ?? [])]),\n ];\n const cacheControl = cacheControlOf(entry);\n if (!tags.length) {\n return { lastModified: entry.lastModified, value: entry.value, cacheControl };\n }\n const [expired, stale] = await Promise.all([\n client.mGet(tags.map((tag) => k.expired + tag)),\n client.mGet(tags.map((tag) => k.stale + tag)),\n ]);\n const now = Date.now();\n // an expiry set after this entry was written, and already reached, is a miss: blocking regeneration\n if (expired.some((at) => at && Number(at) > entry.lastModified && Number(at) <= now)) {\n return null;\n }\n if (stale.some((at) => at && Number(at) > entry.lastModified)) {\n if (typeof entry.revalidate !== 'number') {\n // never revalidated by time: a stale entry can only be regenerated by a miss\n return null;\n }\n // serve once more and regenerate in the background: Next.js sees an entry past its revalidate time\n return {\n lastModified: Math.min(entry.lastModified, now - entry.revalidate * 1000 - 1),\n value: entry.value,\n cacheControl,\n };\n }\n return { lastModified: entry.lastModified, value: entry.value, cacheControl };\n } catch {\n return null;\n }\n }\n\n async set(key: string, data: CacheValue | null, ctx?: CacheHandlerContext) {\n const client = await getClient();\n if (!client?.isReady) {\n return;\n }\n try {\n if (data == null) {\n await client.del([k.entry + key, k.meta + key]);\n return;\n }\n const revalidate = revalidateOf(data, ctx);\n const entry: StoredEntry = {\n lastModified: Date.now(),\n tags: entryTags(data, ctx),\n revalidate,\n cacheControl:\n revalidate === null ? undefined : { revalidate, expire: ctx?.cacheControl?.expire },\n value: data,\n };\n const raw = encode(entry);\n const expire = ctx?.cacheControl?.expire;\n const ttl =\n typeof expire === 'number' && Number.isFinite(expire) && expire > 0\n ? { EX: Math.ceil(expire) }\n : undefined;\n const meta = {\n lastModified: entry.lastModified,\n tags: entry.tags,\n revalidate: entry.revalidate,\n kind: data.kind ?? null,\n status: typeof data.status === 'number' ? data.status : null,\n size: Buffer.byteLength(raw),\n };\n await Promise.all([\n client.set(k.entry + key, raw, ttl),\n client.set(k.meta + key, JSON.stringify(meta), ttl),\n ]);\n } catch {\n // a failed write only costs a regeneration on the next request\n }\n }\n\n async revalidateTag(tags: string | string[], durations?: { expire?: number }) {\n const list = (Array.isArray(tags) ? tags : [tags]).filter(Boolean);\n const client = await getClient();\n if (!client?.isReady || !list.length) {\n return;\n }\n const now = Date.now();\n const writes: [string, string][] = [];\n for (const tag of list) {\n if (durations) {\n writes.push([k.stale + tag, String(now)]);\n if (durations.expire !== undefined) {\n writes.push([k.expired + tag, String(now + durations.expire * 1000)]);\n }\n } else {\n writes.push([k.expired + tag, String(now)]);\n }\n }\n try {\n await client.mSet(writes);\n } catch {\n // the entries expire on their own\n }\n }\n\n resetRequestCache() {}\n };\n}\n\nexport default createRedisCacheHandler();\n"],"mappings":";AAqCA,MAAa,aAAa;AAE1B,SAAgB,YAAY,MAAyB,QAAQ,KAAa;AAC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AE;AACrC,QAAK,MAAM,OAAO,KAChB,KAAI,WAAW;AACb,WAAO,KAAK,CAAC,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC;AACzC,QAAI,UAAU,WAAW,KAAA,EACvB,QAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,MAAM,UAAU,SAAS,IAAK,CAAC,CAAC;SAGvE,QAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,IAAI,CAAC,CAAC;AAG/C,OAAI;AACF,UAAM,OAAO,KAAK,OAAO;WACnB;;EAKV,oBAAoB;;;AAIxB,IAAA,gBAAe,yBAAyB"}
1
+ {"version":3,"file":"redis.js","names":[],"sources":["../../src/cache-handler/redis.ts"],"sourcesContent":["/**\r\n * Next.js incremental cache handler (ISR pages, route handlers, `fetch` and `unstable_cache` entries) backed by\r\n * Redis, shared by every instance of a site. Set it in `next.config` with `withBom()`, or directly:\r\n * `cacheHandler: require.resolve('@websolutespa/bom-next/cache-handlers/isr')`, `cacheMaxMemorySize: 0`.\r\n *\r\n * - Entries: `${REDIS_PREFIX}:next:<key>`, written as `{ lastModified, tags, revalidate, cacheControl, value }` (in\r\n * this order: the cache panel reads the head of the value without parsing the page). `get` returns the stored\r\n * `cacheControl`: Next.js (16.4+) otherwise knows the lifetime only of paths this instance rendered or\r\n * prerendered, and treats an entry written by another instance as revalidate 1 s (served stale, re-rendered).\r\n * - Client: one connection per process (`globalThis`), shared by this handler, which Next.js loads from\r\n * node_modules, and the bundled server code (cache panel inspector, `registerIntrumentation` warm-up).\r\n * - Meta: `${REDIS_PREFIX}:next-meta:<key>`, a small JSON per entry that the cache panel lists with SCAN.\r\n * - Tags: `${REDIS_PREFIX}:next-tag:<tag>` is when the tag expired (the next request waits for a fresh render),\r\n * `${REDIS_PREFIX}:next-tag-stale:<tag>` when it went stale (served once more, regenerated in the background).\r\n * `revalidateTag(tag, 'max')` sets the stale time; `revalidateTag(tag, { expire: 0 })`, `updateTag` and\r\n * `revalidatePath` set the expiry. Next.js only applies stale tags of its own file-system cache, so this handler\r\n * reports a stale entry by moving its `lastModified` back past its revalidate time.\r\n * - Redis down: reads miss and writes are dropped, so pages still render (uncached) instead of failing.\r\n */\r\n\r\n/** The subset of a `redis` client this handler uses (injectable for tests). */\r\nexport type RedisLike = {\r\n isReady: boolean;\r\n get(key: string): Promise<string | null>;\r\n mGet(keys: string[]): Promise<(string | null)[]>;\r\n set(key: string, value: string, options?: { EX?: number }): Promise<unknown>;\r\n mSet(entries: [string, string][]): Promise<unknown>;\r\n del(key: string | string[]): Promise<unknown>;\r\n};\r\n\r\nexport type CacheHandlerContext = {\r\n tags?: string[];\r\n softTags?: string[];\r\n revalidate?: number | false;\r\n cacheControl?: { revalidate?: number | false; expire?: number };\r\n};\r\n\r\nexport const tagsHeader = 'x-next-cache-tags';\r\n\r\nexport function redisPrefix(env: NodeJS.ProcessEnv = process.env): string {\r\n return env.REDIS_PREFIX ? `${env.REDIS_PREFIX}:` : '';\r\n}\r\n\r\nexport const keys = (prefix: string) => ({\r\n entry: `${prefix}next:`,\r\n meta: `${prefix}next-meta:`,\r\n expired: `${prefix}next-tag:`,\r\n stale: `${prefix}next-tag-stale:`,\r\n});\r\n\r\nfunction replacer(_key: string, value: unknown) {\r\n if (value instanceof Map) {\r\n return { __t: 'map', d: Array.from(value.entries()) };\r\n }\r\n if (\r\n value &&\r\n typeof value === 'object' &&\r\n (value as { type?: string }).type === 'Buffer' &&\r\n Array.isArray((value as { data?: unknown }).data)\r\n ) {\r\n return { __t: 'buf', d: Buffer.from((value as { data: number[] }).data).toString('base64') };\r\n }\r\n return value;\r\n}\r\n\r\nfunction reviver(_key: string, value: unknown) {\r\n if (value && typeof value === 'object' && (value as { __t?: string }).__t === 'map') {\r\n return new Map((value as { d: [unknown, unknown][] }).d);\r\n }\r\n if (value && typeof value === 'object' && (value as { __t?: string }).__t === 'buf') {\r\n return Buffer.from((value as { d: string }).d, 'base64');\r\n }\r\n return value;\r\n}\r\n\r\n/** Serializes a cache entry, keeping Buffers and Maps (RSC payloads, segment data). */\r\nexport function encode(entry: unknown): string {\r\n return JSON.stringify(entry, replacer);\r\n}\r\n\r\n/** Restores a cache entry written by {@link encode}. */\r\nexport function decode<T = unknown>(raw: string): T {\r\n return JSON.parse(raw, reviver) as T;\r\n}\r\n\r\n/** The fields of a Next.js cache value this handler reads; the rest is stored as it is. */\r\ntype CacheValue = {\r\n kind?: string;\r\n status?: number;\r\n revalidate?: number | false;\r\n headers?: Record<string, string | string[] | undefined>;\r\n};\r\n\r\n/** The lifetime Next.js keeps per route (`CacheControl`); `expire` in seconds. */\r\ntype StoredCacheControl = { revalidate: number | false; expire: number | undefined };\r\n\r\ntype StoredEntry = {\r\n lastModified: number;\r\n tags: string[];\r\n revalidate: number | false | null;\r\n /** Absent on entries written before 4.0.0-next.12. */\r\n cacheControl?: StoredCacheControl;\r\n value: CacheValue;\r\n};\r\n\r\n/** The lifetime returned with an entry, so every instance applies the one it was written with. */\r\nfunction cacheControlOf(entry: StoredEntry): StoredCacheControl | undefined {\r\n if (entry.cacheControl) {\r\n return entry.cacheControl;\r\n }\r\n return typeof entry.revalidate === 'number' || entry.revalidate === false\r\n ? { revalidate: entry.revalidate, expire: undefined }\r\n : undefined;\r\n}\r\n\r\n/** Explicit tags of a value: the context tags plus the `x-next-cache-tags` header of pages and route handlers. */\r\nexport function entryTags(\r\n value: CacheValue | null | undefined,\r\n ctx: CacheHandlerContext | undefined\r\n): string[] {\r\n const tags = new Set(ctx?.tags ?? []);\r\n const header = value?.headers?.[tagsHeader];\r\n if (typeof header === 'string') {\r\n header\r\n .split(',')\r\n .filter(Boolean)\r\n .forEach((tag) => tags.add(tag));\r\n }\r\n return Array.from(tags);\r\n}\r\n\r\nfunction revalidateOf(\r\n value: CacheValue,\r\n ctx: CacheHandlerContext | undefined\r\n): number | false | null {\r\n const revalidate = ctx?.cacheControl?.revalidate ?? ctx?.revalidate ?? value?.revalidate;\r\n return typeof revalidate === 'number' || revalidate === false ? revalidate : null;\r\n}\r\n\r\ntype ConnectingClient = RedisLike & {\r\n on(event: 'error' | 'ready', listener: (error: Error) => void): unknown;\r\n once(event: 'ready', listener: () => void): unknown;\r\n off(event: 'ready', listener: () => void): unknown;\r\n connect(): Promise<unknown>;\r\n};\r\n\r\n/**\r\n * The client lives on `globalThis`: Next.js loads this handler from node_modules while the inspector and the\r\n * instrumentation are bundled into the app, and module state would give each its own connection.\r\n */\r\nconst shared = globalThis as typeof globalThis & { __bomRedisClient?: ConnectingClient };\r\n\r\n/** A connecting client used only while ready: awaiting `connect()` would hang every request while Redis is down. */\r\nexport async function getRedisClient(): Promise<RedisLike | undefined> {\r\n if (!process.env.REDIS_URL) {\r\n return undefined;\r\n }\r\n if (!shared.__bomRedisClient) {\r\n const { createClient } = await import('redis');\r\n // another caller may have created it while the module loaded\r\n if (shared.__bomRedisClient) {\r\n return getRedisClient();\r\n }\r\n const client = createClient({\r\n url: process.env.REDIS_URL,\r\n // fail fast while disconnected instead of queueing commands behind a dead socket\r\n disableOfflineQueue: true,\r\n socket: {\r\n connectTimeout: 2000,\r\n reconnectStrategy: (retries: number) => Math.min(retries * 200, 5000),\r\n },\r\n }) as unknown as ConnectingClient;\r\n shared.__bomRedisClient = client;\r\n let logged = false;\r\n client.on('error', (error: Error) => {\r\n if (!logged) {\r\n console.warn('[cache-handler] redis unavailable, serving uncached:', error.message);\r\n logged = true;\r\n }\r\n });\r\n client.on('ready', () => {\r\n logged = false;\r\n });\r\n client.connect().catch(() => {\r\n /* reported by the error listener, retried by reconnectStrategy */\r\n });\r\n }\r\n const sharedClient = shared.__bomRedisClient;\r\n return sharedClient.isReady ? sharedClient : undefined;\r\n}\r\n\r\n/**\r\n * Starts the shared client and waits until it is ready, up to `timeout` ms (the connect timeout). For callers that\r\n * may wait, unlike a page lookup: the cache panel, and the startup warm-up, so the first request of a cold instance\r\n * already reads Redis.\r\n */\r\nexport async function connectRedisClient(timeout = 2000): Promise<RedisLike | undefined> {\r\n const ready = await getRedisClient();\r\n const client = shared.__bomRedisClient;\r\n if (ready || !client) {\r\n return ready;\r\n }\r\n await new Promise<void>((resolve) => {\r\n const done = { timer: undefined as ReturnType<typeof setTimeout> | undefined };\r\n const onReady = () => {\r\n clearTimeout(done.timer);\r\n resolve();\r\n };\r\n // no listener left behind while Redis stays down and the panel keeps asking\r\n done.timer = setTimeout(() => {\r\n client.off('ready', onReady);\r\n resolve();\r\n }, timeout);\r\n client.once('ready', onReady);\r\n });\r\n return client.isReady ? client : undefined;\r\n}\r\n\r\n/** Builds the handler class around a client getter, so tests can inject one. */\r\nexport function createRedisCacheHandler(\r\n getClient: () => Promise<RedisLike | undefined> = getRedisClient,\r\n prefix = redisPrefix()\r\n) {\r\n const k = keys(prefix);\r\n return class RedisCacheHandler {\r\n constructor(_ctx?: unknown) {}\r\n\r\n async get(key: string, ctx?: CacheHandlerContext) {\r\n const client = await getClient();\r\n if (!client?.isReady) {\r\n return null;\r\n }\r\n try {\r\n const raw = await client.get(k.entry + key);\r\n if (!raw) {\r\n return null;\r\n }\r\n const entry = decode<StoredEntry>(raw);\r\n const tags = [\r\n ...new Set([...(entry.tags ?? []), ...(ctx?.tags ?? []), ...(ctx?.softTags ?? [])]),\r\n ];\r\n const cacheControl = cacheControlOf(entry);\r\n if (!tags.length) {\r\n return { lastModified: entry.lastModified, value: entry.value, cacheControl };\r\n }\r\n const [expired, stale] = await Promise.all([\r\n client.mGet(tags.map((tag) => k.expired + tag)),\r\n client.mGet(tags.map((tag) => k.stale + tag)),\r\n ]);\r\n const now = Date.now();\r\n // an expiry set after this entry was written, and already reached, is a miss: blocking regeneration\r\n if (expired.some((at) => at && Number(at) > entry.lastModified && Number(at) <= now)) {\r\n return null;\r\n }\r\n if (stale.some((at) => at && Number(at) > entry.lastModified)) {\r\n if (typeof entry.revalidate !== 'number') {\r\n // never revalidated by time: a stale entry can only be regenerated by a miss\r\n return null;\r\n }\r\n // serve once more and regenerate in the background: Next.js sees an entry past its revalidate time\r\n return {\r\n lastModified: Math.min(entry.lastModified, now - entry.revalidate * 1000 - 1),\r\n value: entry.value,\r\n cacheControl,\r\n };\r\n }\r\n return { lastModified: entry.lastModified, value: entry.value, cacheControl };\r\n } catch {\r\n return null;\r\n }\r\n }\r\n\r\n async set(key: string, data: CacheValue | null, ctx?: CacheHandlerContext) {\r\n const client = await getClient();\r\n if (!client?.isReady) {\r\n return;\r\n }\r\n try {\r\n if (data == null) {\r\n await client.del([k.entry + key, k.meta + key]);\r\n return;\r\n }\r\n const revalidate = revalidateOf(data, ctx);\r\n const entry: StoredEntry = {\r\n lastModified: Date.now(),\r\n tags: entryTags(data, ctx),\r\n revalidate,\r\n cacheControl:\r\n revalidate === null ? undefined : { revalidate, expire: ctx?.cacheControl?.expire },\r\n value: data,\r\n };\r\n const raw = encode(entry);\r\n const expire = ctx?.cacheControl?.expire;\r\n const ttl =\r\n typeof expire === 'number' && Number.isFinite(expire) && expire > 0\r\n ? { EX: Math.ceil(expire) }\r\n : undefined;\r\n const meta = {\r\n lastModified: entry.lastModified,\r\n tags: entry.tags,\r\n revalidate: entry.revalidate,\r\n kind: data.kind ?? null,\r\n status: typeof data.status === 'number' ? data.status : null,\r\n size: Buffer.byteLength(raw),\r\n };\r\n await Promise.all([\r\n client.set(k.entry + key, raw, ttl),\r\n client.set(k.meta + key, JSON.stringify(meta), ttl),\r\n ]);\r\n } catch {\r\n // a failed write only costs a regeneration on the next request\r\n }\r\n }\r\n\r\n async revalidateTag(tags: string | string[], durations?: { expire?: number }) {\r\n const list = (Array.isArray(tags) ? tags : [tags]).filter(Boolean);\r\n const client = await getClient();\r\n if (!client?.isReady || !list.length) {\r\n return;\r\n }\r\n const now = Date.now();\r\n const writes: [string, string][] = [];\r\n for (const tag of list) {\r\n if (durations) {\r\n writes.push([k.stale + tag, String(now)]);\r\n if (durations.expire !== undefined) {\r\n writes.push([k.expired + tag, String(now + durations.expire * 1000)]);\r\n }\r\n } else {\r\n writes.push([k.expired + tag, String(now)]);\r\n }\r\n }\r\n try {\r\n await client.mSet(writes);\r\n } catch {\r\n // the entries expire on their own\r\n }\r\n }\r\n\r\n resetRequestCache() {}\r\n };\r\n}\r\n\r\nexport default createRedisCacheHandler();\r\n"],"mappings":";AAqCA,MAAa,aAAa;AAE1B,SAAgB,YAAY,MAAyB,QAAQ,KAAa;AACxE,QAAO,IAAI,eAAe,GAAG,IAAI,aAAa,KAAK;;AAGrD,MAAa,QAAQ,YAAoB;CACvC,OAAO,GAAG,OAAO;CACjB,MAAM,GAAG,OAAO;CAChB,SAAS,GAAG,OAAO;CACnB,OAAO,GAAG,OAAO;CAClB;AAED,SAAS,SAAS,MAAc,OAAgB;AAC9C,KAAI,iBAAiB,IACnB,QAAO;EAAE,KAAK;EAAO,GAAG,MAAM,KAAK,MAAM,SAAS,CAAC;EAAE;AAEvD,KACE,SACA,OAAO,UAAU,YAChB,MAA4B,SAAS,YACtC,MAAM,QAAS,MAA6B,KAAK,CAEjD,QAAO;EAAE,KAAK;EAAO,GAAG,OAAO,KAAM,MAA6B,KAAK,CAAC,SAAS,SAAS;EAAE;AAE9F,QAAO;;AAGT,SAAS,QAAQ,MAAc,OAAgB;AAC7C,KAAI,SAAS,OAAO,UAAU,YAAa,MAA2B,QAAQ,MAC5E,QAAO,IAAI,IAAK,MAAsC,EAAE;AAE1D,KAAI,SAAS,OAAO,UAAU,YAAa,MAA2B,QAAQ,MAC5E,QAAO,OAAO,KAAM,MAAwB,GAAG,SAAS;AAE1D,QAAO;;;AAIT,SAAgB,OAAO,OAAwB;AAC7C,QAAO,KAAK,UAAU,OAAO,SAAS;;;AAIxC,SAAgB,OAAoB,KAAgB;AAClD,QAAO,KAAK,MAAM,KAAK,QAAQ;;;AAwBjC,SAAS,eAAe,OAAoD;AAC1E,KAAI,MAAM,aACR,QAAO,MAAM;AAEf,QAAO,OAAO,MAAM,eAAe,YAAY,MAAM,eAAe,QAChE;EAAE,YAAY,MAAM;EAAY,QAAQ,KAAA;EAAW,GACnD,KAAA;;;AAIN,SAAgB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AAM,QAAQ,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,OAAO,QAAQ;GAClE,MAAM,SAAS,MAAM,WAAW;AAChC,OAAI,CAAC,QAAQ,WAAW,CAAC,KAAK,OAC5B;GAEF,MAAM,MAAM,KAAK,KAAK;GACtB,MAAM,SAA6B,EAAE;AACrC,QAAK,MAAM,OAAO,KAChB,KAAI,WAAW;AACb,WAAO,KAAK,CAAC,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC;AACzC,QAAI,UAAU,WAAW,KAAA,EACvB,QAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,MAAM,UAAU,SAAS,IAAK,CAAC,CAAC;SAGvE,QAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,IAAI,CAAC,CAAC;AAG/C,OAAI;AACF,UAAM,OAAO,KAAK,OAAO;WACnB;;EAKV,oBAAoB;;;AAIxB,IAAA,gBAAe,yBAAyB"}
@@ -1 +1 @@
1
- {"version":3,"file":"default.js","names":[],"sources":["../../src/cache-handlers/default.ts"],"sourcesContent":["import type { CacheEntry, CacheHandler } from 'next/cache';\nimport { getRedisClient, keys, redisPrefix, type RedisLike } from '../cache-handler/redis';\n\n/**\n * `cacheHandlers.default` for `'use cache'` (Cache Components), set by `withBom()`. In memory per process by\n * default (bounded, least recently used out first); shared in Redis when `REDIS_URL` is set. Tag state uses the\n * same keys as the ISR handler (`next-tag:` expired, `next-tag-stale:` stale), so one `revalidateTag` reaches\n * pages and cached functions on every instance. It also keeps a small index of what it stores, which the cache\n * panel lists (`listUseCacheEntries`).\n */\nexport type UseCacheMeta = {\n key: string;\n tags: string[];\n timestamp: number;\n revalidate: number;\n expire: number;\n size: number;\n};\n\ntype Stored = Omit<CacheEntry, 'value'> & { value: Uint8Array };\ntype TagState = { stale?: number; expired?: number };\n\nconst maxBytes = Number(process.env.BOM_USE_CACHE_MAX_BYTES) || 64 * 1024 * 1024;\n\n/** Shared through `globalThis`: Next.js loads the handler outside the bundles the cache panel runs in. */\nconst shared = globalThis as {\n __bomUseCache?: {\n entries: Map<string, Stored>;\n meta: Map<string, UseCacheMeta>;\n tags: Map<string, TagState>;\n bytes: number;\n };\n};\nconst memory = (shared.__bomUseCache ??= {\n entries: new Map(),\n meta: new Map(),\n tags: new Map(),\n bytes: 0,\n});\n\nfunction stream(bytes: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream({\n start(controller) {\n controller.enqueue(bytes);\n controller.close();\n },\n });\n}\n\nfunction evict() {\n // Map iteration order is insertion order; `get` re-inserts, so the first entries are the least recently used\n for (const [key, entry] of memory.entries) {\n if (memory.bytes <= maxBytes) break;\n memory.entries.delete(key);\n memory.meta.delete(key);\n memory.bytes -= entry.value.byteLength;\n }\n}\n\n/** Entries of this process (memory mode) for the cache panel. */\nexport function listUseCacheEntries(): UseCacheMeta[] {\n return [...memory.meta.values()];\n}\n\n/** Reported state of an entry from the tag timestamps: an expiry reached after it was written, or a stale mark. */\nexport function tagState(\n entry: { tags: string[]; timestamp: number },\n read: (tag: string) => TagState,\n now = Date.now()\n) {\n let stale = false;\n for (const tag of entry.tags) {\n const { stale: staleAt = 0, expired = 0 } = read(tag);\n if (expired > entry.timestamp && expired <= now) {\n return 'expired' as const;\n }\n if (staleAt > entry.timestamp) {\n stale = true;\n }\n }\n return stale ? ('stale' as const) : ('fresh' as const);\n}\n\nexport function createUseCacheHandler(\n getClient: () => Promise<RedisLike | undefined> = getRedisClient,\n prefix = redisPrefix(),\n useRedis = Boolean(process.env.REDIS_URL)\n): CacheHandler {\n const k = keys(prefix);\n const entryKey = `${prefix}use-cache:`;\n const metaKey = `${prefix}use-cache-meta:`;\n const pending = new Map<string, Promise<void>>();\n\n async function readTags(tags: string[]): Promise<Map<string, TagState>> {\n const states = new Map<string, TagState>(tags.map((tag) => [tag, memory.tags.get(tag) ?? {}]));\n const client = useRedis ? await getClient() : undefined;\n if (client?.isReady && tags.length) {\n try {\n const [expired, stale] = await Promise.all([\n client.mGet(tags.map((tag) => k.expired + tag)),\n client.mGet(tags.map((tag) => k.stale + tag)),\n ]);\n tags.forEach((tag, index) => {\n states.set(tag, {\n expired: Number(expired[index] ?? 0) || undefined,\n stale: Number(stale[index] ?? 0) || undefined,\n });\n });\n } catch {\n // tag state unknown: serve what is stored\n }\n }\n return states;\n }\n\n async function load(cacheKey: string): Promise<Stored | undefined> {\n if (!useRedis) {\n const entry = memory.entries.get(cacheKey);\n if (entry) {\n // most recently used goes last\n memory.entries.delete(cacheKey);\n memory.entries.set(cacheKey, entry);\n }\n return entry;\n }\n const client = await getClient();\n if (!client?.isReady) return undefined;\n const raw = await client.get(entryKey + cacheKey);\n if (!raw) return undefined;\n const data = JSON.parse(raw) as Omit<Stored, 'value'> & { value: string };\n return { ...data, value: Buffer.from(data.value, 'base64') };\n }\n\n return {\n async get(cacheKey) {\n await pending.get(cacheKey);\n try {\n const entry = await load(cacheKey);\n if (!entry) return undefined;\n const states = await readTags(entry.tags);\n const state = tagState(entry, (tag) => states.get(tag) ?? {});\n if (state === 'expired') return undefined;\n // a stale tag: served once more, regenerated in the background\n return {\n ...entry,\n revalidate: state === 'stale' ? -1 : entry.revalidate,\n value: stream(entry.value),\n };\n } catch {\n return undefined;\n }\n },\n\n async set(cacheKey, pendingEntry) {\n let done!: () => void;\n pending.set(\n cacheKey,\n new Promise<void>((resolve) => {\n done = resolve;\n })\n );\n try {\n const entry = await pendingEntry;\n const value = new Uint8Array(await new Response(entry.value).arrayBuffer());\n const stored: Stored = { ...entry, value };\n const meta: UseCacheMeta = {\n key: cacheKey,\n tags: entry.tags,\n timestamp: entry.timestamp,\n revalidate: entry.revalidate,\n expire: entry.expire,\n size: value.byteLength,\n };\n if (useRedis) {\n const client = await getClient();\n if (client?.isReady) {\n const ttl = Number.isFinite(entry.expire)\n ? { EX: Math.max(1, Math.ceil(entry.expire)) }\n : undefined;\n const { value: _bytes, ...rest } = stored;\n await Promise.all([\n client.set(\n entryKey + cacheKey,\n JSON.stringify({ ...rest, value: Buffer.from(value).toString('base64') }),\n ttl\n ),\n client.set(metaKey + cacheKey, JSON.stringify(meta), ttl),\n ]);\n }\n } else {\n const previous = memory.entries.get(cacheKey);\n if (previous) memory.bytes -= previous.value.byteLength;\n memory.entries.delete(cacheKey);\n memory.entries.set(cacheKey, stored);\n memory.meta.set(cacheKey, meta);\n memory.bytes += value.byteLength;\n evict();\n }\n } catch {\n // an interrupted value is discarded: the next read regenerates it\n } finally {\n pending.delete(cacheKey);\n done();\n }\n },\n\n async refreshTags() {\n // tag state is read from Redis on every lookup; in memory it is already local\n },\n\n async getExpiration(tags) {\n const states = await readTags(tags);\n const now = Date.now();\n return Math.max(\n 0,\n ...[...states.values()].map(({ expired = 0 }) => (expired <= now ? expired : 0))\n );\n },\n\n async updateTags(tags, durations) {\n const now = Date.now();\n const writes: [string, string][] = [];\n for (const tag of tags) {\n const state = memory.tags.get(tag) ?? {};\n if (durations) {\n state.stale = now;\n writes.push([k.stale + tag, String(now)]);\n if (durations.expire !== undefined) {\n state.expired = now + durations.expire * 1000;\n writes.push([k.expired + tag, String(state.expired)]);\n }\n } else {\n state.expired = now;\n writes.push([k.expired + tag, String(now)]);\n }\n memory.tags.set(tag, state);\n }\n if (useRedis && writes.length) {\n const client = await getClient();\n await client?.mSet(writes).catch(() => {});\n }\n },\n };\n}\n\nexport default createUseCacheHandler();\n"],"mappings":";;AAsBA,MAAM,WAAW,OAAO,QAAQ,IAAI,wBAAwB,IAAI,KAAK,OAAO;;AAG5E,MAAM,SAAS;AAQf,MAAM,SAAU,OAAO,kBAAkB;CACvC,yBAAS,IAAI,KAAK;CAClB,sBAAM,IAAI,KAAK;CACf,sBAAM,IAAI,KAAK;CACf,OAAO;CACR;AAED,SAAS,OAAO,OAA+C;AAC7D,QAAO,IAAI,eAAe,EACxB,MAAM,YAAY;AAChB,aAAW,QAAQ,MAAM;AACzB,aAAW,OAAO;IAErB,CAAC;;AAGJ,SAAS,QAAQ;AAEf,MAAK,MAAM,CAAC,KAAK,UAAU,OA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;IACtB,MAAM,QAAQ,OAAO,KAAK,IAAI,IAAI,IAAI,EAAE;AACxC,QAAI,WAAW;AACb,WAAM,QAAQ;AACd,YAAO,KAAK,CAAC,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC;AACzC,SAAI,UAAU,WAAW,KAAA,GAAW;AAClC,YAAM,UAAU,MAAM,UAAU,SAAS;AACzC,aAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,MAAM,QAAQ,CAAC,CAAC;;WAElD;AACL,WAAM,UAAU;AAChB,YAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,IAAI,CAAC,CAAC;;AAE7C,WAAO,KAAK,IAAI,KAAK,MAAM;;AAE7B,OAAI,YAAY,OAAO,OAErB,QADe,MAAM,WAAW,GAClB,KAAK,OAAO,CAAC,YAAY,GAAG;;EAG/C;;AAGH,IAAA,kBAAe,uBAAuB"}
1
+ {"version":3,"file":"default.js","names":[],"sources":["../../src/cache-handlers/default.ts"],"sourcesContent":["import type { CacheEntry, CacheHandler } from 'next/cache';\r\nimport { getRedisClient, keys, redisPrefix, type RedisLike } from '../cache-handler/redis';\r\n\r\n/**\r\n * `cacheHandlers.default` for `'use cache'` (Cache Components), set by `withBom()`. In memory per process by\r\n * default (bounded, least recently used out first); shared in Redis when `REDIS_URL` is set. Tag state uses the\r\n * same keys as the ISR handler (`next-tag:` expired, `next-tag-stale:` stale), so one `revalidateTag` reaches\r\n * pages and cached functions on every instance. It also keeps a small index of what it stores, which the cache\r\n * panel lists (`listUseCacheEntries`).\r\n */\r\nexport type UseCacheMeta = {\r\n key: string;\r\n tags: string[];\r\n timestamp: number;\r\n revalidate: number;\r\n expire: number;\r\n size: number;\r\n};\r\n\r\ntype Stored = Omit<CacheEntry, 'value'> & { value: Uint8Array };\r\ntype TagState = { stale?: number; expired?: number };\r\n\r\nconst maxBytes = Number(process.env.BOM_USE_CACHE_MAX_BYTES) || 64 * 1024 * 1024;\r\n\r\n/** Shared through `globalThis`: Next.js loads the handler outside the bundles the cache panel runs in. */\r\nconst shared = globalThis as {\r\n __bomUseCache?: {\r\n entries: Map<string, Stored>;\r\n meta: Map<string, UseCacheMeta>;\r\n tags: Map<string, TagState>;\r\n bytes: number;\r\n };\r\n};\r\nconst memory = (shared.__bomUseCache ??= {\r\n entries: new Map(),\r\n meta: new Map(),\r\n tags: new Map(),\r\n bytes: 0,\r\n});\r\n\r\nfunction stream(bytes: Uint8Array): ReadableStream<Uint8Array> {\r\n return new ReadableStream({\r\n start(controller) {\r\n controller.enqueue(bytes);\r\n controller.close();\r\n },\r\n });\r\n}\r\n\r\nfunction evict() {\r\n // Map iteration order is insertion order; `get` re-inserts, so the first entries are the least recently used\r\n for (const [key, entry] of memory.entries) {\r\n if (memory.bytes <= maxBytes) break;\r\n memory.entries.delete(key);\r\n memory.meta.delete(key);\r\n memory.bytes -= entry.value.byteLength;\r\n }\r\n}\r\n\r\n/** Entries of this process (memory mode) for the cache panel. */\r\nexport function listUseCacheEntries(): UseCacheMeta[] {\r\n return [...memory.meta.values()];\r\n}\r\n\r\n/** Reported state of an entry from the tag timestamps: an expiry reached after it was written, or a stale mark. */\r\nexport function tagState(\r\n entry: { tags: string[]; timestamp: number },\r\n read: (tag: string) => TagState,\r\n now = Date.now()\r\n) {\r\n let stale = false;\r\n for (const tag of entry.tags) {\r\n const { stale: staleAt = 0, expired = 0 } = read(tag);\r\n if (expired > entry.timestamp && expired <= now) {\r\n return 'expired' as const;\r\n }\r\n if (staleAt > entry.timestamp) {\r\n stale = true;\r\n }\r\n }\r\n return stale ? ('stale' as const) : ('fresh' as const);\r\n}\r\n\r\nexport function createUseCacheHandler(\r\n getClient: () => Promise<RedisLike | undefined> = getRedisClient,\r\n prefix = redisPrefix(),\r\n useRedis = Boolean(process.env.REDIS_URL)\r\n): CacheHandler {\r\n const k = keys(prefix);\r\n const entryKey = `${prefix}use-cache:`;\r\n const metaKey = `${prefix}use-cache-meta:`;\r\n const pending = new Map<string, Promise<void>>();\r\n\r\n async function readTags(tags: string[]): Promise<Map<string, TagState>> {\r\n const states = new Map<string, TagState>(tags.map((tag) => [tag, memory.tags.get(tag) ?? {}]));\r\n const client = useRedis ? await getClient() : undefined;\r\n if (client?.isReady && tags.length) {\r\n try {\r\n const [expired, stale] = await Promise.all([\r\n client.mGet(tags.map((tag) => k.expired + tag)),\r\n client.mGet(tags.map((tag) => k.stale + tag)),\r\n ]);\r\n tags.forEach((tag, index) => {\r\n states.set(tag, {\r\n expired: Number(expired[index] ?? 0) || undefined,\r\n stale: Number(stale[index] ?? 0) || undefined,\r\n });\r\n });\r\n } catch {\r\n // tag state unknown: serve what is stored\r\n }\r\n }\r\n return states;\r\n }\r\n\r\n async function load(cacheKey: string): Promise<Stored | undefined> {\r\n if (!useRedis) {\r\n const entry = memory.entries.get(cacheKey);\r\n if (entry) {\r\n // most recently used goes last\r\n memory.entries.delete(cacheKey);\r\n memory.entries.set(cacheKey, entry);\r\n }\r\n return entry;\r\n }\r\n const client = await getClient();\r\n if (!client?.isReady) return undefined;\r\n const raw = await client.get(entryKey + cacheKey);\r\n if (!raw) return undefined;\r\n const data = JSON.parse(raw) as Omit<Stored, 'value'> & { value: string };\r\n return { ...data, value: Buffer.from(data.value, 'base64') };\r\n }\r\n\r\n return {\r\n async get(cacheKey) {\r\n await pending.get(cacheKey);\r\n try {\r\n const entry = await load(cacheKey);\r\n if (!entry) return undefined;\r\n const states = await readTags(entry.tags);\r\n const state = tagState(entry, (tag) => states.get(tag) ?? {});\r\n if (state === 'expired') return undefined;\r\n // a stale tag: served once more, regenerated in the background\r\n return {\r\n ...entry,\r\n revalidate: state === 'stale' ? -1 : entry.revalidate,\r\n value: stream(entry.value),\r\n };\r\n } catch {\r\n return undefined;\r\n }\r\n },\r\n\r\n async set(cacheKey, pendingEntry) {\r\n let done!: () => void;\r\n pending.set(\r\n cacheKey,\r\n new Promise<void>((resolve) => {\r\n done = resolve;\r\n })\r\n );\r\n try {\r\n const entry = await pendingEntry;\r\n const value = new Uint8Array(await new Response(entry.value).arrayBuffer());\r\n const stored: Stored = { ...entry, value };\r\n const meta: UseCacheMeta = {\r\n key: cacheKey,\r\n tags: entry.tags,\r\n timestamp: entry.timestamp,\r\n revalidate: entry.revalidate,\r\n expire: entry.expire,\r\n size: value.byteLength,\r\n };\r\n if (useRedis) {\r\n const client = await getClient();\r\n if (client?.isReady) {\r\n const ttl = Number.isFinite(entry.expire)\r\n ? { EX: Math.max(1, Math.ceil(entry.expire)) }\r\n : undefined;\r\n const { value: _bytes, ...rest } = stored;\r\n await Promise.all([\r\n client.set(\r\n entryKey + cacheKey,\r\n JSON.stringify({ ...rest, value: Buffer.from(value).toString('base64') }),\r\n ttl\r\n ),\r\n client.set(metaKey + cacheKey, JSON.stringify(meta), ttl),\r\n ]);\r\n }\r\n } else {\r\n const previous = memory.entries.get(cacheKey);\r\n if (previous) memory.bytes -= previous.value.byteLength;\r\n memory.entries.delete(cacheKey);\r\n memory.entries.set(cacheKey, stored);\r\n memory.meta.set(cacheKey, meta);\r\n memory.bytes += value.byteLength;\r\n evict();\r\n }\r\n } catch {\r\n // an interrupted value is discarded: the next read regenerates it\r\n } finally {\r\n pending.delete(cacheKey);\r\n done();\r\n }\r\n },\r\n\r\n async refreshTags() {\r\n // tag state is read from Redis on every lookup; in memory it is already local\r\n },\r\n\r\n async getExpiration(tags) {\r\n const states = await readTags(tags);\r\n const now = Date.now();\r\n return Math.max(\r\n 0,\r\n ...[...states.values()].map(({ expired = 0 }) => (expired <= now ? expired : 0))\r\n );\r\n },\r\n\r\n async updateTags(tags, durations) {\r\n const now = Date.now();\r\n const writes: [string, string][] = [];\r\n for (const tag of tags) {\r\n const state = memory.tags.get(tag) ?? {};\r\n if (durations) {\r\n state.stale = now;\r\n writes.push([k.stale + tag, String(now)]);\r\n if (durations.expire !== undefined) {\r\n state.expired = now + durations.expire * 1000;\r\n writes.push([k.expired + tag, String(state.expired)]);\r\n }\r\n } else {\r\n state.expired = now;\r\n writes.push([k.expired + tag, String(now)]);\r\n }\r\n memory.tags.set(tag, state);\r\n }\r\n if (useRedis && writes.length) {\r\n const client = await getClient();\r\n await client?.mSet(writes).catch(() => {});\r\n }\r\n },\r\n };\r\n}\r\n\r\nexport default createUseCacheHandler();\r\n"],"mappings":";;AAsBA,MAAM,WAAW,OAAO,QAAQ,IAAI,wBAAwB,IAAI,KAAK,OAAO;;AAG5E,MAAM,SAAS;AAQf,MAAM,SAAU,OAAO,kBAAkB;CACvC,yBAAS,IAAI,KAAK;CAClB,sBAAM,IAAI,KAAK;CACf,sBAAM,IAAI,KAAK;CACf,OAAO;CACR;AAED,SAAS,OAAO,OAA+C;AAC7D,QAAO,IAAI,eAAe,EACxB,MAAM,YAAY;AAChB,aAAW,QAAQ,MAAM;AACzB,aAAW,OAAO;IAErB,CAAC;;AAGJ,SAAS,QAAQ;AAEf,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,SAAS;AACzC,MAAI,OAAO,SAAS,SAAU;AAC9B,SAAO,QAAQ,OAAO,IAAI;AAC1B,SAAO,KAAK,OAAO,IAAI;AACvB,SAAO,SAAS,MAAM,MAAM;;;;AAKhC,SAAgB,sBAAsC;AACpD,QAAO,CAAC,GAAG,OAAO,KAAK,QAAQ,CAAC;;;AAIlC,SAAgB,SACd,OACA,MACA,MAAM,KAAK,KAAK,EAChB;CACA,IAAI,QAAQ;AACZ,MAAK,MAAM,OAAO,MAAM,MAAM;EAC5B,MAAM,EAAE,OAAO,UAAU,GAAG,UAAU,MAAM,KAAK,IAAI;AACrD,MAAI,UAAU,MAAM,aAAa,WAAW,IAC1C,QAAO;AAET,MAAI,UAAU,MAAM,UAClB,SAAQ;;AAGZ,QAAO,QAAS,UAAqB;;AAGvC,SAAgB,sBACd,YAAkD,gBAClD,SAAS,aAAa,EACtB,WAAW,QAAQ,QAAQ,IAAI,UAAU,EAC3B;CACd,MAAM,IAAI,KAAK,OAAO;CACtB,MAAM,WAAW,GAAG,OAAO;CAC3B,MAAM,UAAU,GAAG,OAAO;CA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MAAM;AAC7C,YAAO,QAAQ,OAAO,SAAS;AAC/B,YAAO,QAAQ,IAAI,UAAU,OAAO;AACpC,YAAO,KAAK,IAAI,UAAU,KAAK;AAC/B,YAAO,SAAS,MAAM;AACtB,YAAO;;WAEH,WAEE;AACR,YAAQ,OAAO,SAAS;AACxB,UAAM;;;EAIV,MAAM,cAAc;EAIpB,MAAM,cAAc,MAAM;GACxB,MAAM,SAAS,MAAM,SAAS,KAAK;GACnC,MAAM,MAAM,KAAK,KAAK;AACtB,UAAO,KAAK,IACV,GACA,GAAG,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,KAAK,EAAE,UAAU,QAAS,WAAW,MAAM,UAAU,EAAG,CACjF;;EAGH,MAAM,WAAW,MAAM,WAAW;GAChC,MAAM,MAAM,KAAK,KAAK;GACtB,MAAM,SAA6B,EAAE;AACrC,QAAK,MAAM,OAAO,MAAM;IACtB,MAAM,QAAQ,OAAO,KAAK,IAAI,IAAI,IAAI,EAAE;AACxC,QAAI,WAAW;AACb,WAAM,QAAQ;AACd,YAAO,KAAK,CAAC,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC;AACzC,SAAI,UAAU,WAAW,KAAA,GAAW;AAClC,YAAM,UAAU,MAAM,UAAU,SAAS;AACzC,aAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,MAAM,QAAQ,CAAC,CAAC;;WAElD;AACL,WAAM,UAAU;AAChB,YAAO,KAAK,CAAC,EAAE,UAAU,KAAK,OAAO,IAAI,CAAC,CAAC;;AAE7C,WAAO,KAAK,IAAI,KAAK,MAAM;;AAE7B,OAAI,YAAY,OAAO,OAErB,QADe,MAAM,WAAW,GAClB,KAAK,OAAO,CAAC,YAAY,GAAG;;EAG/C;;AAGH,IAAA,kBAAe,uBAAuB"}
@@ -7,11 +7,11 @@ function Client() {
7
7
  const label = useLabel();
8
8
  const page = usePage();
9
9
  const classNames = getClassNames("client");
10
- return <div className={classNames}>
11
- <h2 className="display-2">
12
- {page.title} <sup>{page.id}</sup>
13
- </h2>
14
- <h2>{label("label")}</h2>
10
+ return <div className={classNames}>
11
+ <h2 className="display-2">
12
+ {page.title} <sup>{page.id}</sup>
13
+ </h2>
14
+ <h2>{label("label")}</h2>
15
15
  </div>;
16
16
  }
17
17
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/client/client.tsx"],"sourcesContent":["'use client';\n\nimport { getClassNames } from '@websolutespa/bom-core';\nimport { useLabel } from './useLabel';\nimport { usePage } from './usePage';\n\nexport function Client() {\n const label = useLabel();\n const page = usePage();\n // console.log('Client', layout, page, label('label'));\n const classNames = getClassNames('client');\n return (\n <div className={classNames}>\n <h2 className=\"display-2\">\n {page.title} <sup>{page.id}</sup>\n </h2>\n <h2>{label('label')}</h2>\n </div>\n );\n}\n"],"mappings":";;;;;AAMA,SAAgB,SAAS;CACvB,MAAM,QAAQ,UAAU;CACxB,MAAM,OAAO,SAAS;CAEtB,MAAM,aAAa,cAAc,SAAS;AAC1C,QACE,CAAC,IAAI,WAAW,YAAY;MAC1B,CAAC,GAAG,sBAAsB;SACvB,KAAK,MAAM,CAAC,CAAC,KAAK,KAAK,GAAG,EAAE,IAAI;MACnC,EAAE,GAAG;MACL,CAAC,IAAI,MAAM,QAAQ,CAAC,EAAE,GAAG;IAC3B,EAAE"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/client/client.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { getClassNames } from '@websolutespa/bom-core';\r\nimport { useLabel } from './useLabel';\r\nimport { usePage } from './usePage';\r\n\r\nexport function Client() {\r\n const label = useLabel();\r\n const page = usePage();\r\n // console.log('Client', layout, page, label('label'));\r\n const classNames = getClassNames('client');\r\n return (\r\n <div className={classNames}>\r\n <h2 className=\"display-2\">\r\n {page.title} <sup>{page.id}</sup>\r\n </h2>\r\n <h2>{label('label')}</h2>\r\n </div>\r\n );\r\n}\r\n"],"mappings":";;;;;AAMA,SAAgB,SAAS;CACvB,MAAM,QAAQ,UAAU;CACxB,MAAM,OAAO,SAAS;CAEtB,MAAM,aAAa,cAAc,SAAS;AAC1C,QACE,CAAC,IAAI,WAAW,YAAY;MAC1B,CAAC,GAAG,sBAAsB;SACvB,KAAK,MAAM,CAAC,CAAC,KAAK,KAAK,GAAG,EAAE,IAAI;MACnC,EAAE,GAAG;MACL,CAAC,IAAI,MAAM,QAAQ,CAAC,EAAE,GAAG;IAC3B,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"extra.js","names":[],"sources":["../../src/client/extra.tsx"],"sourcesContent":["'use client';\n\nimport { createContext } from 'react';\n\nexport type IExtraContext = Record<string, any>;\n\nexport const ExtraContext = createContext<IExtraContext | undefined>(undefined);\n\nexport function ExtraProvider({\n extra = {},\n children,\n}: {\n extra?: Record<string, any>;\n children?: React.ReactNode;\n}) {\n return <ExtraContext.Provider value={extra}>{children}</ExtraContext.Provider>;\n}\n"],"mappings":";;;AAMA,MAAa,eAAe,cAAyC,KAAA,EAAU;AAE/E,SAAgB,cAAc,EAC5B,QAAQ,EAAE,EACV,YAIC;AACD,QAAO,CAAC,aAAa,SAAS,OAAO,QAAQ,SAAS,EAAE,aAAa"}
1
+ {"version":3,"file":"extra.js","names":[],"sources":["../../src/client/extra.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { createContext } from 'react';\r\n\r\nexport type IExtraContext = Record<string, any>;\r\n\r\nexport const ExtraContext = createContext<IExtraContext | undefined>(undefined);\r\n\r\nexport function ExtraProvider({\r\n extra = {},\r\n children,\r\n}: {\r\n extra?: Record<string, any>;\r\n children?: React.ReactNode;\r\n}) {\r\n return <ExtraContext.Provider value={extra}>{children}</ExtraContext.Provider>;\r\n}\r\n"],"mappings":";;;AAMA,MAAa,eAAe,cAAyC,KAAA,EAAU;AAE/E,SAAgB,cAAc,EAC5B,QAAQ,EAAE,EACV,YAIC;AACD,QAAO,CAAC,aAAa,SAAS,OAAO,QAAQ,SAAS,EAAE,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"label.js","names":[],"sources":["../../src/client/label.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useMemo } from 'react';\nimport { LabelService } from '../lib/label';\nimport { useLayout } from './useLayout';\n\nexport type ILabelContext = (key: string, params?: Record<string, any>) => string;\n\nexport const LabelContext = createContext<ILabelContext | undefined>(undefined);\n\nexport function LabelProvider({ children }: { children?: React.ReactNode }) {\n const { labels } = useLayout();\n // one function per labels: consumers list `label` in effect dependencies, a new function on every\n // render would run their effects again (e.g. a toast shown twice)\n const getLabel = useMemo<ILabelContext>(() => {\n const labelService = new LabelService(labels);\n return (key, params) => labelService.getLabel(key, params);\n }, [labels]);\n return <LabelContext.Provider value={getLabel}>{children}</LabelContext.Provider>;\n}\n"],"mappings":";;;;;AAQA,MAAa,eAAe,cAAyC,KAAA,EAAU;AAE/E,SAAgB,cAAc,EAAE,YAA4C;CAC1E,MAAM,EAAE,WAAW,WAAW;CAG9B,MAAM,WAAW,cAA6B;EAC5C,MAAM,eAAe,IAAI,aAAa,OAAO;AAC7C,UAAQ,KAAK,WAAW,aAAa,SAAS,KAAK,OAAO;IACzD,CAAC,OAAO,CAAC;AACZ,QAAO,CAAC,aAAa,SAAS,OAAO,WAAW,SAAS,EAAE,aAAa"}
1
+ {"version":3,"file":"label.js","names":[],"sources":["../../src/client/label.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { createContext, useMemo } from 'react';\r\nimport { LabelService } from '../lib/label';\r\nimport { useLayout } from './useLayout';\r\n\r\nexport type ILabelContext = (key: string, params?: Record<string, any>) => string;\r\n\r\nexport const LabelContext = createContext<ILabelContext | undefined>(undefined);\r\n\r\nexport function LabelProvider({ children }: { children?: React.ReactNode }) {\r\n const { labels } = useLayout();\r\n // one function per labels: consumers list `label` in effect dependencies, a new function on every\r\n // render would run their effects again (e.g. a toast shown twice)\r\n const getLabel = useMemo<ILabelContext>(() => {\r\n const labelService = new LabelService(labels);\r\n return (key, params) => labelService.getLabel(key, params);\r\n }, [labels]);\r\n return <LabelContext.Provider value={getLabel}>{children}</LabelContext.Provider>;\r\n}\r\n"],"mappings":";;;;;AAQA,MAAa,eAAe,cAAyC,KAAA,EAAU;AAE/E,SAAgB,cAAc,EAAE,YAA4C;CAC1E,MAAM,EAAE,WAAW,WAAW;CAG9B,MAAM,WAAW,cAA6B;EAC5C,MAAM,eAAe,IAAI,aAAa,OAAO;AAC7C,UAAQ,KAAK,WAAW,aAAa,SAAS,KAAK,OAAO;IACzD,CAAC,OAAO,CAAC;AACZ,QAAO,CAAC,aAAa,SAAS,OAAO,WAAW,SAAS,EAAE,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"layout.js","names":[],"sources":["../../src/client/layout.tsx"],"sourcesContent":["'use client';\n\nimport { ILayout } from '@websolutespa/bom-core';\nimport { createContext } from 'react';\n\nexport type ILayoutContext = ILayout;\n\nexport const LayoutContext = createContext<ILayoutContext | undefined>(undefined);\n\nexport function LayoutProvider({\n layout,\n children,\n}: {\n layout: ILayout;\n children?: React.ReactNode;\n}) {\n return <LayoutContext.Provider value={layout}>{children}</LayoutContext.Provider>;\n}\n"],"mappings":";;;AAOA,MAAa,gBAAgB,cAA0C,KAAA,EAAU;AAEjF,SAAgB,eAAe,EAC7B,QACA,YAIC;AACD,QAAO,CAAC,cAAc,SAAS,OAAO,SAAS,SAAS,EAAE,cAAc"}
1
+ {"version":3,"file":"layout.js","names":[],"sources":["../../src/client/layout.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { ILayout } from '@websolutespa/bom-core';\r\nimport { createContext } from 'react';\r\n\r\nexport type ILayoutContext = ILayout;\r\n\r\nexport const LayoutContext = createContext<ILayoutContext | undefined>(undefined);\r\n\r\nexport function LayoutProvider({\r\n layout,\r\n children,\r\n}: {\r\n layout: ILayout;\r\n children?: React.ReactNode;\r\n}) {\r\n return <LayoutContext.Provider value={layout}>{children}</LayoutContext.Provider>;\r\n}\r\n"],"mappings":";;;AAOA,MAAa,gBAAgB,cAA0C,KAAA,EAAU;AAEjF,SAAgB,eAAe,EAC7B,QACA,YAIC;AACD,QAAO,CAAC,cAAc,SAAS,OAAO,SAAS,SAAS,EAAE,cAAc"}
@@ -0,0 +1,14 @@
1
+ //#region src/client/live-preview.d.ts
2
+ /**
3
+ * Connects the page to the admin's live preview: each edit is sent to the server, which renders the route
4
+ * again with the unsaved values, and a save renders it from the saved draft. Does nothing outside a live
5
+ * preview window. `PageProvider` mounts it, so a page using that provider needs nothing else.
6
+ */
7
+ declare function LivePreviewListener({
8
+ debounce
9
+ }: {
10
+ debounce?: number;
11
+ }): null;
12
+ //#endregion
13
+ export { LivePreviewListener };
14
+ //# sourceMappingURL=live-preview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-preview.d.ts","names":[],"sources":["../../src/client/live-preview.tsx"],"mappings":";;AAwBA;;;;iBAAgB,mBAAA,CAAA;EAAsB;AAAA;EAAc,QAAA;AAAA"}
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ import { LIVE_COOKIE, parseLiveCookie } from "../lib/live-preview.js";
3
+ import { clearLivePreviewData, setLivePreviewData } from "../server/live-preview.actions.js";
4
+ import { startTransition, useEffect } from "react";
5
+ import { ready, subscribeLive } from "@websolutespa/payload-bowl-live-preview";
6
+ //#region src/client/live-preview.tsx
7
+ function readLiveCookie() {
8
+ const pair = document.cookie.split("; ").find((item) => item.startsWith(`${LIVE_COOKIE}=`));
9
+ if (!pair) return;
10
+ try {
11
+ return parseLiveCookie(decodeURIComponent(pair.slice(LIVE_COOKIE.length + 1)));
12
+ } catch {
13
+ return;
14
+ }
15
+ }
16
+ /**
17
+ * Connects the page to the admin's live preview: each edit is sent to the server, which renders the route
18
+ * again with the unsaved values, and a save renders it from the saved draft. Does nothing outside a live
19
+ * preview window. `PageProvider` mounts it, so a page using that provider needs nothing else.
20
+ */
21
+ function LivePreviewListener({ debounce }) {
22
+ useEffect(() => {
23
+ if (window.parent === window && !window.opener) return;
24
+ const live = readLiveCookie();
25
+ if (!live) return;
26
+ const { serverURL } = live;
27
+ const unsubscribe = subscribeLive({
28
+ debounce,
29
+ serverURL,
30
+ onData: ({ collectionSlug, data, locale }) => {
31
+ if (!collectionSlug || data.id === void 0 || data.id === null) return;
32
+ startTransition(async () => {
33
+ await setLivePreviewData({
34
+ collection: collectionSlug,
35
+ id: String(data.id),
36
+ locale,
37
+ data
38
+ });
39
+ });
40
+ },
41
+ onDocumentEvent: () => {
42
+ startTransition(async () => {
43
+ await clearLivePreviewData();
44
+ });
45
+ }
46
+ });
47
+ ready({ serverURL });
48
+ return unsubscribe;
49
+ }, [debounce]);
50
+ return null;
51
+ }
52
+ //#endregion
53
+ export { LivePreviewListener };
54
+
55
+ //# sourceMappingURL=live-preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-preview.js","names":[],"sources":["../../src/client/live-preview.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { ready, subscribeLive } from '@websolutespa/payload-bowl-live-preview';\r\nimport { startTransition, useEffect } from 'react';\r\nimport { LIVE_COOKIE, parseLiveCookie, type LiveCookie } from '../lib/live-preview';\r\nimport { clearLivePreviewData, setLivePreviewData } from '../server/live-preview.actions';\r\n\r\nfunction readLiveCookie(): LiveCookie | undefined {\r\n const pair = document.cookie.split('; ').find((item) => item.startsWith(`${LIVE_COOKIE}=`));\r\n if (!pair) {\r\n return undefined;\r\n }\r\n try {\r\n return parseLiveCookie(decodeURIComponent(pair.slice(LIVE_COOKIE.length + 1)));\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Connects the page to the admin's live preview: each edit is sent to the server, which renders the route\r\n * again with the unsaved values, and a save renders it from the saved draft. Does nothing outside a live\r\n * preview window. `PageProvider` mounts it, so a page using that provider needs nothing else.\r\n */\r\nexport function LivePreviewListener({ debounce }: { debounce?: number }) {\r\n useEffect(() => {\r\n // the admin's iframe or popup, opened through the preview handler\r\n if (window.parent === window && !window.opener) {\r\n return;\r\n }\r\n const live = readLiveCookie();\r\n if (!live) {\r\n return;\r\n }\r\n const { serverURL } = live;\r\n const unsubscribe = subscribeLive({\r\n debounce,\r\n serverURL,\r\n onData: ({ collectionSlug, data, locale }) => {\r\n if (!collectionSlug || data.id === undefined || data.id === null) {\r\n return;\r\n }\r\n startTransition(async () => {\r\n await setLivePreviewData({\r\n collection: collectionSlug,\r\n id: String(data.id),\r\n locale,\r\n data,\r\n });\r\n });\r\n },\r\n onDocumentEvent: () => {\r\n startTransition(async () => {\r\n await clearLivePreviewData();\r\n });\r\n },\r\n });\r\n // the admin sends nothing until the preview window says it is listening\r\n ready({ serverURL });\r\n return unsubscribe;\r\n }, [debounce]);\r\n\r\n return null;\r\n}\r\n"],"mappings":";;;;;;AAOA,SAAS,iBAAyC;CAChD,MAAM,OAAO,SAAS,OAAO,MAAM,KAAK,CAAC,MAAM,SAAS,KAAK,WAAW,GAAG,YAAY,GAAG,CAAC;AAC3F,KAAI,CAAC,KACH;AAEF,KAAI;AACF,SAAO,gBAAgB,mBAAmB,KAAK,MAAM,YAAY,SAAS,EAAE,CAAC,CAAC;SACxE;AACN;;;;;;;;AASJ,SAAgB,oBAAoB,EAAE,YAAmC;AACvE,iBAAgB;AAEd,MAAI,OAAO,WAAW,UAAU,CAAC,OAAO,OACtC;EAEF,MAAM,OAAO,gBAAgB;AAC7B,MAAI,CAAC,KACH;EAEF,MAAM,EAAE,cAAc;EACtB,MAAM,cAAc,cAAc;GAChC;GACA;GACA,SAAS,EAAE,gBAAgB,MAAM,aAAa;AAC5C,QAAI,CAAC,kBAAkB,KAAK,OAAO,KAAA,KAAa,KAAK,OAAO,KAC1D;AAEF,oBAAgB,YAAY;AAC1B,WAAM,mBAAmB;MACvB,YAAY;MACZ,IAAI,OAAO,KAAK,GAAG;MACnB;MACA;MACD,CAAC;MACF;;GAEJ,uBAAuB;AACrB,oBAAgB,YAAY;AAC1B,WAAM,sBAAsB;MAC5B;;GAEL,CAAC;AAEF,QAAM,EAAE,WAAW,CAAC;AACpB,SAAO;IACN,CAAC,SAAS,CAAC;AAEd,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"local.collection.js","names":[],"sources":["../../src/client/local.collection.ts"],"sourcesContent":["import { httpFetch, merge } from '@websolutespa/bom-core';\nimport { ApiRequestOptions, getLocalApiRequestOptions, getLocalApiUrl } from '../lib/http';\n\nexport async function localCollectionFetch<T = unknown>(\n pathname: string,\n options: ApiRequestOptions = {},\n serviceOptions?: { locale: string; market: string }\n): Promise<T> {\n const url = new URL(getLocalApiUrl(pathname));\n if (serviceOptions) {\n url.searchParams.append('locale', serviceOptions.locale);\n url.searchParams.append('market', serviceOptions.market);\n }\n const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);\n const apiResponse = await httpFetch(url.href, apiOptions);\n return apiResponse;\n}\n\nexport async function localCollectionGet<T = unknown>(\n url: string,\n options: ApiRequestOptions = {},\n serviceOptions?: { locale: string; market: string }\n): Promise<T> {\n return await localCollectionFetch<T>(url, { ...options, method: 'GET' }, serviceOptions);\n}\n\nexport async function localCollectionPost<T = unknown>(\n url: string,\n payload?: unknown,\n options: ApiRequestOptions = {},\n serviceOptions?: { locale: string; market: string }\n): Promise<T> {\n return await localCollectionFetch<T>(\n url,\n { ...options, method: 'POST', body: payload ? JSON.stringify(payload) : undefined },\n serviceOptions\n );\n}\n\nexport async function localCollectionPut<T = unknown>(\n url: string,\n payload?: unknown,\n options: ApiRequestOptions = {},\n serviceOptions?: { locale: string; market: string }\n): Promise<T> {\n return await localCollectionFetch<T>(\n url,\n { ...options, method: 'PUT', body: payload ? JSON.stringify(payload) : undefined },\n serviceOptions\n );\n}\n\nexport async function localCollectionPatch<T = unknown>(\n url: string,\n payload?: unknown,\n options: ApiRequestOptions = {},\n serviceOptions?: { locale: string; market: string }\n): Promise<T> {\n return await localCollectionFetch<T>(\n url,\n { ...options, method: 'PATCH', body: payload ? JSON.stringify(payload) : undefined },\n serviceOptions\n );\n}\n\nexport async function localCollectionDelete<T = unknown>(\n url: string,\n options: ApiRequestOptions = {},\n serviceOptions?: { locale: string; market: string }\n): Promise<T> {\n return await localCollectionFetch<T>(url, { ...options, method: 'DELETE' }, serviceOptions);\n}\n"],"mappings":";;;AAGA,eAAsB,qBACpB,UACA,UAA6B,EAAE,EAC/B,gBACY;CACZ,MAAM,MAAM,IAAI,IAAI,eAAe,SAAS,CAAC;AAC7C,KAAI,gBAAgB;AAClB,MAAI,aAAa,OAAO,UAAU,eAAe,OAAO;AACxD,MAAI,aAAa,OAAO,UAAU,eAAe,OAAO;;CAE1D,MAAM,aAAa,MAAM,EAAE,GAAG,2BAA2B,EAAE,EAAE,QAAQ;AAErE,QADoB,MAAM,UAAU,IAAI,MAAM,WAAW;;AAI3D,eAAsB,mBACpB,KACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBAAwB,KAAK;EAAE,GAAG;EAAS,QAAQ;EAAO,EAAE,eAAe;;AAG1F,eAAsB,oBACpB,KACA,SACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBACX,KACA;EAAE,GAAG;EAAS,QAAQ;EAAQ,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAAW,EACnF,eACD;;AAGH,eAAsB,mBACpB,KACA,SACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBACX,KACA;EAAE,GAAG;EAAS,QAAQ;EAAO,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAAW,EAClF,eACD;;AAGH,eAAsB,qBACpB,KACA,SACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBACX,KACA;EAAE,GAAG;EAAS,QAAQ;EAAS,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAAW,EACpF,eACD;;AAGH,eAAsB,sBACpB,KACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBAAwB,KAAK;EAAE,GAAG;EAAS,QAAQ;EAAU,EAAE,eAAe"}
1
+ {"version":3,"file":"local.collection.js","names":[],"sources":["../../src/client/local.collection.ts"],"sourcesContent":["import { httpFetch, merge } from '@websolutespa/bom-core';\r\nimport { ApiRequestOptions, getLocalApiRequestOptions, getLocalApiUrl } from '../lib/http';\r\n\r\nexport async function localCollectionFetch<T = unknown>(\r\n pathname: string,\r\n options: ApiRequestOptions = {},\r\n serviceOptions?: { locale: string; market: string }\r\n): Promise<T> {\r\n const url = new URL(getLocalApiUrl(pathname));\r\n if (serviceOptions) {\r\n url.searchParams.append('locale', serviceOptions.locale);\r\n url.searchParams.append('market', serviceOptions.market);\r\n }\r\n const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);\r\n const apiResponse = await httpFetch(url.href, apiOptions);\r\n return apiResponse;\r\n}\r\n\r\nexport async function localCollectionGet<T = unknown>(\r\n url: string,\r\n options: ApiRequestOptions = {},\r\n serviceOptions?: { locale: string; market: string }\r\n): Promise<T> {\r\n return await localCollectionFetch<T>(url, { ...options, method: 'GET' }, serviceOptions);\r\n}\r\n\r\nexport async function localCollectionPost<T = unknown>(\r\n url: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {},\r\n serviceOptions?: { locale: string; market: string }\r\n): Promise<T> {\r\n return await localCollectionFetch<T>(\r\n url,\r\n { ...options, method: 'POST', body: payload ? JSON.stringify(payload) : undefined },\r\n serviceOptions\r\n );\r\n}\r\n\r\nexport async function localCollectionPut<T = unknown>(\r\n url: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {},\r\n serviceOptions?: { locale: string; market: string }\r\n): Promise<T> {\r\n return await localCollectionFetch<T>(\r\n url,\r\n { ...options, method: 'PUT', body: payload ? JSON.stringify(payload) : undefined },\r\n serviceOptions\r\n );\r\n}\r\n\r\nexport async function localCollectionPatch<T = unknown>(\r\n url: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {},\r\n serviceOptions?: { locale: string; market: string }\r\n): Promise<T> {\r\n return await localCollectionFetch<T>(\r\n url,\r\n { ...options, method: 'PATCH', body: payload ? JSON.stringify(payload) : undefined },\r\n serviceOptions\r\n );\r\n}\r\n\r\nexport async function localCollectionDelete<T = unknown>(\r\n url: string,\r\n options: ApiRequestOptions = {},\r\n serviceOptions?: { locale: string; market: string }\r\n): Promise<T> {\r\n return await localCollectionFetch<T>(url, { ...options, method: 'DELETE' }, serviceOptions);\r\n}\r\n"],"mappings":";;;AAGA,eAAsB,qBACpB,UACA,UAA6B,EAAE,EAC/B,gBACY;CACZ,MAAM,MAAM,IAAI,IAAI,eAAe,SAAS,CAAC;AAC7C,KAAI,gBAAgB;AAClB,MAAI,aAAa,OAAO,UAAU,eAAe,OAAO;AACxD,MAAI,aAAa,OAAO,UAAU,eAAe,OAAO;;CAE1D,MAAM,aAAa,MAAM,EAAE,GAAG,2BAA2B,EAAE,EAAE,QAAQ;AAErE,QADoB,MAAM,UAAU,IAAI,MAAM,WAAW;;AAI3D,eAAsB,mBACpB,KACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBAAwB,KAAK;EAAE,GAAG;EAAS,QAAQ;EAAO,EAAE,eAAe;;AAG1F,eAAsB,oBACpB,KACA,SACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBACX,KACA;EAAE,GAAG;EAAS,QAAQ;EAAQ,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAAW,EACnF,eACD;;AAGH,eAAsB,mBACpB,KACA,SACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBACX,KACA;EAAE,GAAG;EAAS,QAAQ;EAAO,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAAW,EAClF,eACD;;AAGH,eAAsB,qBACpB,KACA,SACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBACX,KACA;EAAE,GAAG;EAAS,QAAQ;EAAS,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAAW,EACpF,eACD;;AAGH,eAAsB,sBACpB,KACA,UAA6B,EAAE,EAC/B,gBACY;AACZ,QAAO,MAAM,qBAAwB,KAAK;EAAE,GAAG;EAAS,QAAQ;EAAU,EAAE,eAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.js","names":[],"sources":["../../src/client/metadata.tsx"],"sourcesContent":["'use client';\n\nimport { getMetaRobots, IMedia } from '@websolutespa/bom-core';\nimport { createContext, ReactNode, useMemo } from 'react';\nimport { ContactPoint, Organization, PostalAddress } from 'schema-dts';\nimport { IBrand, IMeta, IMetaData } from '../lib/meta-data';\nimport { OpenGraphType } from '../lib/open-graph';\nimport { StructuredDataType } from '../lib/structured-data';\nimport { TwitterCardType } from '../lib/twitter-card';\nimport {\n getPageAlternates,\n getPageXDefault,\n getPaginationQuery,\n toPlainText,\n} from '../lib/page-metadata';\nimport { getPublicUrl, resolveHref } from '../lib/utils';\nimport { useLayout } from './useLayout';\nimport { usePage } from './usePage';\n\nexport type IMetaDataOptions = {\n brand: {\n name: string;\n logo: string;\n businessName?: string;\n appName?: string;\n url?: string;\n email?: string;\n telephone?: string;\n zipCode?: string;\n address?: string;\n city?: string;\n provinceCode?: string;\n countryName?: string;\n countryCode?: string;\n twitterName?: string;\n social?: Record<string, string>;\n };\n structuredData?: StructuredDataType;\n openGraph?: OpenGraphType;\n twitterCard?: TwitterCardType;\n};\n\nexport type IMetaDataContext = IMetaData;\n\nexport const MetaDataContext = createContext<IMetaDataContext | undefined>(undefined);\n\n/**\n * Computes page metadata for client components (`useMetaData`). It renders\n * nothing into `<head>`: in the App Router, export `generateMetadata` built\n * with `getPageMetadata` from `@websolutespa/bom-next/server` instead.\n *\n * `search` is the current query string (e.g. `?pagination[page]=2`); pages\n * after the first keep their pagination in the canonical URL.\n */\nexport function MetaDataProvider({\n metaData,\n search,\n children,\n}: {\n metaData: IMetaDataOptions;\n search?: string;\n children?: ReactNode;\n}) {\n const layout = useLayout();\n const page = usePage();\n const homeHref = layout.homeHref ?? layout.tree?.href;\n const brand: IBrand = {\n ...metaData.brand,\n logo: resolveHref(metaData.brand.logo),\n url: metaData.brand.url || (homeHref ? resolveHref(homeHref) : getPublicUrl()),\n businessName: metaData.brand.businessName || metaData.brand.name,\n appName: metaData.brand.appName || metaData.brand.name,\n };\n const title = toPlainText(page.meta?.title || page.title || '');\n const description = toPlainText(page.meta?.description || page.abstract || '');\n const media = (page.meta as { image: IMedia } | undefined)?.image || page.media;\n const image = media ? resolveHref(media.src || media.url) : brand.logo;\n const canonical = `${resolveHref(page.href)}${getPaginationQuery(new URLSearchParams(search || ''))}`;\n const url = canonical;\n const alternates = useMemo(() => getPageAlternates(page, layout, getPublicUrl()), [layout, page]);\n const xDefault = useMemo(() => getPageXDefault(page, layout, getPublicUrl()), [layout, page]);\n const meta: IMeta = {\n title: title,\n description: description,\n image: image,\n keywords: page.meta?.keywords,\n robots: getMetaRobots(page.meta),\n slug: page.href,\n url,\n canonical,\n alternates,\n xDefault,\n };\n const contactPoint: ContactPoint = {\n '@type': 'ContactPoint',\n telephone: brand.telephone,\n email: brand.email,\n contactType: 'customer service',\n areaServed: layout.locales.map((x) => x.id),\n availableLanguage: layout.locales.map((x) => x.id),\n };\n const postalAddress: PostalAddress = {\n '@type': 'PostalAddress',\n streetAddress: brand.address,\n addressLocality: brand.city,\n postalCode: brand.zipCode,\n addressRegion: brand.provinceCode,\n addressCountry: brand.countryCode,\n };\n const organization: Organization = {\n '@type': 'Organization',\n name: brand.businessName,\n logo: {\n '@type': 'ImageObject',\n url: brand.logo,\n },\n url: brand.url,\n /*\n description,\n founder,\n foundingDate,\n numberOfEmployees,\n */\n /*\n foundingDate: '2020-01-01',\n numberOfEmployees: {\n '@type': 'QuantitativeValue',\n value: 150,\n },\n */\n };\n const hasContact = Boolean(brand.email || brand.telephone);\n if (hasContact) {\n organization.contactPoint = contactPoint;\n }\n const hasAddress = Boolean(\n brand.address || brand.city || brand.zipCode || brand.provinceCode || brand.countryCode\n );\n if (hasAddress) {\n organization.address = postalAddress;\n }\n if (brand.social) {\n organization.sameAs = Object.values(brand.social);\n }\n const structuredData: StructuredDataType = metaData.structuredData || {\n '@type': 'WebPage',\n name: title,\n url: url,\n description: description,\n publisher: organization,\n };\n const openGraph: OpenGraphType = metaData.openGraph || {\n type: 'website',\n title: title,\n description: description,\n url: url,\n siteName: brand.name,\n image: image,\n locale: layout.locale,\n };\n const twitterCard: TwitterCardType | undefined =\n metaData.twitterCard ||\n (brand.twitterName\n ? {\n card: 'summary_large_image',\n title: title,\n description: description,\n image: image,\n imageAlt: brand.businessName,\n site: brand.twitterName,\n creator: brand.twitterName,\n }\n : undefined);\n const value: IMetaData = {\n layout,\n page,\n brand,\n contactPoint,\n meta,\n openGraph,\n organization,\n postalAddress,\n structuredData,\n twitterCard,\n };\n return <MetaDataContext.Provider value={value}>{children}</MetaDataContext.Provider>;\n}\n"],"mappings":";;;;;;;;AA4CA,MAAa,kBAAkB,cAA4C,KAAA,EAAU;;;;;;;;;AAUrF,SAAgB,iBAAiB,EAC/B,UACA,QACA,YAKC;CACD,MAAM,SAAS,WAAW;CAC1B,MAAM,OAAO,SAAS;CACtB,MAAM,WAAW,OAAO,YAAY,OAAO,MAAM;CACjD,MAAM,QAAgB;EACpB,GAAG,SAAS;EACZ,MAAM,YAAY,SAAS,MAAM,KAAK;EACtC,KAAK,SAAS,MAAM,QAAQ,WAAW,YAAY,SAAS,GAAG,cAAc;EAC7E,cAAc,SAAS,MAAM,gBAAgB,SAAS,MAAM;EAC5D,SAAS,SAAS,MAAM,WAAW,SAAS,MAAM;EACnD;CACD,MAAM,QAAQ,YAAY,KAAK,MAAM,SAAS,KAAK,SAAS,GAAG;CAC/D,MAAM,cAAc,YAAY,KAAK,MAAM,eAAe,KAAK,YAAY,GAAG;CAC9E,MAAM,QAAS,KAAK,MAAwC,SAAS,KAAK;CAC1E,MAAM,QAAQ,QAAQ,YAAY,MAAM,OAAO,MAAM,IAAI,GAAG,MAAM;CAClE,MAAM,YAAY,GAAG,YAAY,KAAK,KAAK,GAAG,mBAAmB,IAAI,gBAAgB,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qBC;EACA;EACA;EACA,aAtBA,SAAS,gBACR,MAAM,cACH;GACE,MAAM;GACC;GACM;GACN;GACP,UAAU,MAAM;GAChB,MAAM,MAAM;GACZ,SAAS,MAAM;GAChB,GACD,KAAA;EAYL;AACD,QAAO,CAAC,gBAAgB,SAAS,OAAO,QAAQ,SAAS,EAAE,gBAAgB"}
1
+ {"version":3,"file":"metadata.js","names":[],"sources":["../../src/client/metadata.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { getMetaRobots, IMedia } from '@websolutespa/bom-core';\r\nimport { createContext, ReactNode, useMemo } from 'react';\r\nimport { ContactPoint, Organization, PostalAddress } from 'schema-dts';\r\nimport { IBrand, IMeta, IMetaData } from '../lib/meta-data';\r\nimport { OpenGraphType } from '../lib/open-graph';\r\nimport { StructuredDataType } from '../lib/structured-data';\r\nimport { TwitterCardType } from '../lib/twitter-card';\r\nimport {\r\n getPageAlternates,\r\n getPageXDefault,\r\n getPaginationQuery,\r\n toPlainText,\r\n} from '../lib/page-metadata';\r\nimport { getPublicUrl, resolveHref } from '../lib/utils';\r\nimport { useLayout } from './useLayout';\r\nimport { usePage } from './usePage';\r\n\r\nexport type IMetaDataOptions = {\r\n brand: {\r\n name: string;\r\n logo: string;\r\n businessName?: string;\r\n appName?: string;\r\n url?: string;\r\n email?: string;\r\n telephone?: string;\r\n zipCode?: string;\r\n address?: string;\r\n city?: string;\r\n provinceCode?: string;\r\n countryName?: string;\r\n countryCode?: string;\r\n twitterName?: string;\r\n social?: Record<string, string>;\r\n };\r\n structuredData?: StructuredDataType;\r\n openGraph?: OpenGraphType;\r\n twitterCard?: TwitterCardType;\r\n};\r\n\r\nexport type IMetaDataContext = IMetaData;\r\n\r\nexport const MetaDataContext = createContext<IMetaDataContext | undefined>(undefined);\r\n\r\n/**\r\n * Computes page metadata for client components (`useMetaData`). It renders\r\n * nothing into `<head>`: in the App Router, export `generateMetadata` built\r\n * with `getPageMetadata` from `@websolutespa/bom-next/server` instead.\r\n *\r\n * `search` is the current query string (e.g. `?pagination[page]=2`); pages\r\n * after the first keep their pagination in the canonical URL.\r\n */\r\nexport function MetaDataProvider({\r\n metaData,\r\n search,\r\n children,\r\n}: {\r\n metaData: IMetaDataOptions;\r\n search?: string;\r\n children?: ReactNode;\r\n}) {\r\n const layout = useLayout();\r\n const page = usePage();\r\n const homeHref = layout.homeHref ?? layout.tree?.href;\r\n const brand: IBrand = {\r\n ...metaData.brand,\r\n logo: resolveHref(metaData.brand.logo),\r\n url: metaData.brand.url || (homeHref ? resolveHref(homeHref) : getPublicUrl()),\r\n businessName: metaData.brand.businessName || metaData.brand.name,\r\n appName: metaData.brand.appName || metaData.brand.name,\r\n };\r\n const title = toPlainText(page.meta?.title || page.title || '');\r\n const description = toPlainText(page.meta?.description || page.abstract || '');\r\n const media = (page.meta as { image: IMedia } | undefined)?.image || page.media;\r\n const image = media ? resolveHref(media.src || media.url) : brand.logo;\r\n const canonical = `${resolveHref(page.href)}${getPaginationQuery(new URLSearchParams(search || ''))}`;\r\n const url = canonical;\r\n const alternates = useMemo(() => getPageAlternates(page, layout, getPublicUrl()), [layout, page]);\r\n const xDefault = useMemo(() => getPageXDefault(page, layout, getPublicUrl()), [layout, page]);\r\n const meta: IMeta = {\r\n title: title,\r\n description: description,\r\n image: image,\r\n keywords: page.meta?.keywords,\r\n robots: getMetaRobots(page.meta),\r\n slug: page.href,\r\n url,\r\n canonical,\r\n alternates,\r\n xDefault,\r\n };\r\n const contactPoint: ContactPoint = {\r\n '@type': 'ContactPoint',\r\n telephone: brand.telephone,\r\n email: brand.email,\r\n contactType: 'customer service',\r\n areaServed: layout.locales.map((x) => x.id),\r\n availableLanguage: layout.locales.map((x) => x.id),\r\n };\r\n const postalAddress: PostalAddress = {\r\n '@type': 'PostalAddress',\r\n streetAddress: brand.address,\r\n addressLocality: brand.city,\r\n postalCode: brand.zipCode,\r\n addressRegion: brand.provinceCode,\r\n addressCountry: brand.countryCode,\r\n };\r\n const organization: Organization = {\r\n '@type': 'Organization',\r\n name: brand.businessName,\r\n logo: {\r\n '@type': 'ImageObject',\r\n url: brand.logo,\r\n },\r\n url: brand.url,\r\n /*\r\n description,\r\n founder,\r\n foundingDate,\r\n numberOfEmployees,\r\n */\r\n /*\r\n foundingDate: '2020-01-01',\r\n numberOfEmployees: {\r\n '@type': 'QuantitativeValue',\r\n value: 150,\r\n },\r\n */\r\n };\r\n const hasContact = Boolean(brand.email || brand.telephone);\r\n if (hasContact) {\r\n organization.contactPoint = contactPoint;\r\n }\r\n const hasAddress = Boolean(\r\n brand.address || brand.city || brand.zipCode || brand.provinceCode || brand.countryCode\r\n );\r\n if (hasAddress) {\r\n organization.address = postalAddress;\r\n }\r\n if (brand.social) {\r\n organization.sameAs = Object.values(brand.social);\r\n }\r\n const structuredData: StructuredDataType = metaData.structuredData || {\r\n '@type': 'WebPage',\r\n name: title,\r\n url: url,\r\n description: description,\r\n publisher: organization,\r\n };\r\n const openGraph: OpenGraphType = metaData.openGraph || {\r\n type: 'website',\r\n title: title,\r\n description: description,\r\n url: url,\r\n siteName: brand.name,\r\n image: image,\r\n locale: layout.locale,\r\n };\r\n const twitterCard: TwitterCardType | undefined =\r\n metaData.twitterCard ||\r\n (brand.twitterName\r\n ? {\r\n card: 'summary_large_image',\r\n title: title,\r\n description: description,\r\n image: image,\r\n imageAlt: brand.businessName,\r\n site: brand.twitterName,\r\n creator: brand.twitterName,\r\n }\r\n : undefined);\r\n const value: IMetaData = {\r\n layout,\r\n page,\r\n brand,\r\n contactPoint,\r\n meta,\r\n openGraph,\r\n organization,\r\n postalAddress,\r\n structuredData,\r\n twitterCard,\r\n };\r\n return <MetaDataContext.Provider value={value}>{children}</MetaDataContext.Provider>;\r\n}\r\n"],"mappings":";;;;;;;;AA4CA,MAAa,kBAAkB,cAA4C,KAAA,EAAU;;;;;;;;;AAUrF,SAAgB,iBAAiB,EAC/B,UACA,QACA,YAKC;CACD,MAAM,SAAS,WAAW;CAC1B,MAAM,OAAO,SAAS;CACtB,MAAM,WAA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A,CAAM,SAAA;AAAA,IAClB,KAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -1,9 +1,13 @@
1
1
  "use client";
2
+ import { LivePreviewListener } from "./live-preview.js";
2
3
  import { createContext } from "react";
3
4
  //#region src/client/page.tsx
4
5
  const PageContext = createContext(void 0);
5
6
  function PageProvider({ page, children }) {
6
- return <PageContext.Provider value={page}>{children}</PageContext.Provider>;
7
+ return <PageContext.Provider value={page}>
8
+ <LivePreviewListener />
9
+ {children}
10
+ </PageContext.Provider>;
7
11
  }
8
12
  //#endregion
9
13
  export { PageContext, PageProvider };
@@ -1 +1 @@
1
- {"version":3,"file":"page.js","names":[],"sources":["../../src/client/page.tsx"],"sourcesContent":["'use client';\n\nimport { ILocalized, IPage } from '@websolutespa/bom-core';\nimport { createContext } from 'react';\n\nexport type IPageContext = ILocalized<IPage>;\n\nexport const PageContext = createContext<IPageContext | undefined>(undefined);\n\nexport function PageProvider({\n page,\n children,\n}: {\n page: ILocalized<IPage>;\n children?: React.ReactNode;\n}) {\n return <PageContext.Provider value={page}>{children}</PageContext.Provider>;\n}\n"],"mappings":";;;AAOA,MAAa,cAAc,cAAwC,KAAA,EAAU;AAE7E,SAAgB,aAAa,EAC3B,MACA,YAIC;AACD,QAAO,CAAC,YAAY,SAAS,OAAO,OAAO,SAAS,EAAE,YAAY"}
1
+ {"version":3,"file":"page.js","names":[],"sources":["../../src/client/page.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { ILocalized, IPage } from '@websolutespa/bom-core';\r\nimport { createContext } from 'react';\r\nimport { LivePreviewListener } from './live-preview';\r\n\r\nexport type IPageContext = ILocalized<IPage>;\r\n\r\nexport const PageContext = createContext<IPageContext | undefined>(undefined);\r\n\r\nexport function PageProvider({\r\n page,\r\n children,\r\n}: {\r\n page: ILocalized<IPage>;\r\n children?: React.ReactNode;\r\n}) {\r\n return (\r\n <PageContext.Provider value={page}>\r\n <LivePreviewListener />\r\n {children}\r\n </PageContext.Provider>\r\n );\r\n}\r\n"],"mappings":";;;;AAQA,MAAa,cAAc,cAAwC,KAAA,EAAU;AAE7E,SAAgB,aAAa,EAC3B,MACA,YAIC;AACD,QACE,CAAC,YAAY,SAAS,OAAO,MAAM;MACjC,CAAC,sBAAsB;OACtB,SAAS;IACZ,EAAE,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"useApi.js","names":[],"sources":["../../src/client/useApi.ts"],"sourcesContent":["import {\n ApiRequestOptions,\n localApiDelete,\n localApiFetch,\n localApiGet,\n localApiPatch,\n localApiPost,\n localApiPut,\n} from '../lib/http';\nimport { useHttpFetch } from './useHttp';\nimport { useLayout } from './useLayout';\n\nexport function useApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\n const layout = useLayout();\n // const layout = { locale: '', market: '' };\n return useHttpFetch<T>(pathname, options, localApiFetch, layout);\n}\n\nexport function useApiGet<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\n return useApiFetch<T>(pathname, { ...options, method: 'GET' });\n}\n\nexport function useApiPost<T = unknown>(\n pathname: string,\n payload: unknown,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, {\n ...options,\n method: 'POST',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useApiPut<T = unknown>(\n pathname: string,\n payload: unknown,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, {\n ...options,\n method: 'PUT',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useApiPatch<T = unknown>(\n pathname: string,\n payload: unknown,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, {\n ...options,\n method: 'PATCH',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useApiDelete<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\n return useApiFetch<T>(pathname, { ...options, method: 'DELETE' });\n}\n\ntype Api = {\n get: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;\n post: <T = unknown>(\n pathname: string,\n payload?: unknown,\n options?: ApiRequestOptions\n ) => Promise<T>;\n put: <T = unknown>(\n pathname: string,\n payload?: unknown,\n options?: ApiRequestOptions\n ) => Promise<T>;\n patch: <T = unknown>(\n pathname: string,\n payload?: unknown,\n options?: ApiRequestOptions\n ) => Promise<T>;\n delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;\n};\n\nexport function useApi(): Api {\n const layout = useLayout();\n // const layout = { locale: '', market: '' };\n return {\n get: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {\n return localApiGet<T>(pathname, options, layout);\n },\n post: async <T = unknown>(\n pathname: string,\n payload?: unknown,\n options: ApiRequestOptions = {}\n ) => {\n return localApiPost<T>(pathname, payload, options, layout);\n },\n put: async <T = unknown>(\n pathname: string,\n payload?: unknown,\n options: ApiRequestOptions = {}\n ) => {\n return localApiPut<T>(pathname, payload, options, layout);\n },\n patch: async <T = unknown>(\n pathname: string,\n payload?: unknown,\n options: ApiRequestOptions = {}\n ) => {\n return localApiPatch<T>(pathname, payload, options, layout);\n },\n delete: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {\n return localApiDelete<T>(pathname, options, layout);\n },\n };\n}\n"],"mappings":";;;;AAYA,SAAgB,YAAyB,UAAkB,UAA6B,EAAE,EAAE;AAG1F,QAAO,aAAgB,UAAU,SAAS,eAF3B,WAAW,CAEsC;;AAGlE,SAAgB,UAAuB,UAAkB,UAA6B,EAAE,EAAE;AACxF,QAAO,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAO,CAAC;;AAGhE,SAAgB,WACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,UACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,YACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,aAA0B,UAAkB,UAA6B,EAAE,EAAE;AAC3F,QAAO,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAU,CAAC;;AAuBnE,SAAgB,SAAc;CAC5B,MAAM,SAAS,WAAW;AAE1B,QAAO;EACL,KAAK,OAAoB,UAAkB,UAA6B,EAAE,KAAK;AAC7E,UAAO,YAAe,UAAU,SAAS,OAAO;;EAElD,MAAM,OACJ,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,aAAgB,UAAU,SAAS,SAAS,OAAO;;EAE5D,KAAK,OACH,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,YAAe,UAAU,SAAS,SAAS,OAAO;;EAE3D,OAAO,OACL,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,cAAiB,UAAU,SAAS,SAAS,OAAO;;EAE7D,QAAQ,OAAoB,UAAkB,UAA6B,EAAE,KAAK;AAChF,UAAO,eAAkB,UAAU,SAAS,OAAO;;EAEtD"}
1
+ {"version":3,"file":"useApi.js","names":[],"sources":["../../src/client/useApi.ts"],"sourcesContent":["import {\r\n ApiRequestOptions,\r\n localApiDelete,\r\n localApiFetch,\r\n localApiGet,\r\n localApiPatch,\r\n localApiPost,\r\n localApiPut,\r\n} from '../lib/http';\r\nimport { useHttpFetch } from './useHttp';\r\nimport { useLayout } from './useLayout';\r\n\r\nexport function useApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\r\n const layout = useLayout();\r\n // const layout = { locale: '', market: '' };\r\n return useHttpFetch<T>(pathname, options, localApiFetch, layout);\r\n}\r\n\r\nexport function useApiGet<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\r\n return useApiFetch<T>(pathname, { ...options, method: 'GET' });\r\n}\r\n\r\nexport function useApiPost<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, {\r\n ...options,\r\n method: 'POST',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useApiPut<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, {\r\n ...options,\r\n method: 'PUT',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useApiPatch<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, {\r\n ...options,\r\n method: 'PATCH',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useApiDelete<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\r\n return useApiFetch<T>(pathname, { ...options, method: 'DELETE' });\r\n}\r\n\r\ntype Api = {\r\n get: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;\r\n post: <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n put: <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n patch: <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;\r\n};\r\n\r\nexport function useApi(): Api {\r\n const layout = useLayout();\r\n // const layout = { locale: '', market: '' };\r\n return {\r\n get: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {\r\n return localApiGet<T>(pathname, options, layout);\r\n },\r\n post: async <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n return localApiPost<T>(pathname, payload, options, layout);\r\n },\r\n put: async <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n return localApiPut<T>(pathname, payload, options, layout);\r\n },\r\n patch: async <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n return localApiPatch<T>(pathname, payload, options, layout);\r\n },\r\n delete: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {\r\n return localApiDelete<T>(pathname, options, layout);\r\n },\r\n };\r\n}\r\n"],"mappings":";;;;AAYA,SAAgB,YAAyB,UAAkB,UAA6B,EAAE,EAAE;AAG1F,QAAO,aAAgB,UAAU,SAAS,eAF3B,WAAW,CAEsC;;AAGlE,SAAgB,UAAuB,UAAkB,UAA6B,EAAE,EAAE;AACxF,QAAO,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAO,CAAC;;AAGhE,SAAgB,WACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,UACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,YACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,aAA0B,UAAkB,UAA6B,EAAE,EAAE;AAC3F,QAAO,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAU,CAAC;;AAuBnE,SAAgB,SAAc;CAC5B,MAAM,SAAS,WAAW;AAE1B,QAAO;EACL,KAAK,OAAoB,UAAkB,UAA6B,EAAE,KAAK;AAC7E,UAAO,YAAe,UAAU,SAAS,OAAO;;EAElD,MAAM,OACJ,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,aAAgB,UAAU,SAAS,SAAS,OAAO;;EAE5D,KAAK,OACH,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,YAAe,UAAU,SAAS,SAAS,OAAO;;EAE3D,OAAO,OACL,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,cAAiB,UAAU,SAAS,SAAS,OAAO;;EAE7D,QAAQ,OAAoB,UAAkB,UAA6B,EAAE,KAAK;AAChF,UAAO,eAAkB,UAAU,SAAS,OAAO;;EAEtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCollectionApi.js","names":[],"sources":["../../src/client/useCollectionApi.ts"],"sourcesContent":["import { QueryParams, qsSerialize } from '@websolutespa/bom-core';\nimport { ApiRequestOptions } from '../lib/http';\nimport {\n localCollectionDelete,\n localCollectionGet,\n localCollectionPatch,\n localCollectionPost,\n localCollectionPut,\n} from './local.collection';\nimport { useApiFetch } from './useApi';\nimport { useLayout } from './useLayout';\n\ntype CollectionApi = {\n get: <T = unknown>(\n pathname: string,\n params?: QueryParams,\n options?: ApiRequestOptions\n ) => Promise<T>;\n post: <T = unknown>(\n pathname: string,\n payload?: unknown,\n options?: ApiRequestOptions\n ) => Promise<T>;\n put: <T = unknown>(\n pathname: string,\n payload?: unknown,\n options?: ApiRequestOptions\n ) => Promise<T>;\n patch: <T = unknown>(\n pathname: string,\n payload?: unknown,\n options?: ApiRequestOptions\n ) => Promise<T>;\n delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;\n};\n\nexport function useCollectionApi(): CollectionApi {\n const layout = useLayout();\n return {\n get: async <T = unknown>(\n pathname: string,\n params: QueryParams = {},\n options: ApiRequestOptions = {}\n ) => {\n params.locale = params.locale || layout.locale;\n params.market = params.market || layout.market;\n const qs = qsSerialize(params);\n return localCollectionGet<T>(pathname + (qs ? '?' + qs : ''), options);\n },\n post: async <T = unknown>(\n pathname: string,\n payload?: unknown,\n options: ApiRequestOptions = {}\n ) => {\n return localCollectionPost<T>(pathname, payload, options, layout);\n },\n put: async <T = unknown>(\n pathname: string,\n payload?: unknown,\n options: ApiRequestOptions = {}\n ) => {\n return localCollectionPut<T>(pathname, payload, options, layout);\n },\n patch: async <T = unknown>(\n pathname: string,\n payload?: unknown,\n options: ApiRequestOptions = {}\n ) => {\n return localCollectionPatch<T>(pathname, payload, options, layout);\n },\n delete: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {\n return localCollectionDelete<T>(pathname, options, layout);\n },\n };\n}\n\n/*\nexport function useCollectionApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\n const layout = useLayout();\n // const layout = { locale: '', market: '' };\n return useHttpFetch<T>(pathname, options, localApiFetch, layout);\n}\n*/\n\nexport function useCollectionApiGet<T = unknown>(\n pathname: string,\n params?: QueryParams,\n options: ApiRequestOptions = {}\n) {\n const api = useApiFetch<T>(pathname, { ...options, method: 'GET' });\n return api;\n}\n\nexport function useCollectionApiPost<T = unknown>(\n pathname: string,\n payload: unknown,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, {\n ...options,\n method: 'POST',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useCollectionApiPut<T = unknown>(\n pathname: string,\n payload: unknown,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, {\n ...options,\n method: 'PUT',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useCollectionApiPatch<T = unknown>(\n pathname: string,\n payload: unknown,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, {\n ...options,\n method: 'PATCH',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useCollectionApiDelete<T = unknown>(\n pathname: string,\n options: ApiRequestOptions = {}\n) {\n return useApiFetch<T>(pathname, { ...options, method: 'DELETE' });\n}\n"],"mappings":";;;;;AAoCA,SAAgB,mBAAkC;CAChD,MAAM,SAAS,WAAW;AAC1B,QAAO;EACL,KAAK,OACH,UACA,SAAsB,EAAE,EACxB,UAA6B,EAAE,KAC5B;AACH,UAAO,SAAS,OAAO,UAAU,OAAO;AACxC,UAAO,SAAS,OAAO,UAAU,OAAO;GACxC,MAAM,KAAK,YAAY,OAAO;AAC9B,UAAO,mBAAsB,YAAY,KAAK,MAAM,KAAK,KAAK,QAAQ;;EAExE,MAAM,OACJ,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,oBAAuB,UAAU,SAAS,SAAS,OAAO;;EAEnE,KAAK,OACH,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,mBAAsB,UAAU,SAAS,SAAS,OAAO;;EAElE,OAAO,OACL,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,qBAAwB,UAAU,SAAS,SAAS,OAAO;;EAEpE,QAAQ,OAAoB,UAAkB,UAA6B,EAAE,KAAK;AAChF,UAAO,sBAAyB,UAAU,SAAS,OAAO;;EAE7D;;AAWH,SAAgB,oBACd,UACA,QACA,UAA6B,EAAE,EAC/B;AAEA,QADY,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAO,CAAC;;AAIrE,SAAgB,qBACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,oBACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,sBACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,uBACd,UACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAU,CAAC"}
1
+ {"version":3,"file":"useCollectionApi.js","names":[],"sources":["../../src/client/useCollectionApi.ts"],"sourcesContent":["import { QueryParams, qsSerialize } from '@websolutespa/bom-core';\r\nimport { ApiRequestOptions } from '../lib/http';\r\nimport {\r\n localCollectionDelete,\r\n localCollectionGet,\r\n localCollectionPatch,\r\n localCollectionPost,\r\n localCollectionPut,\r\n} from './local.collection';\r\nimport { useApiFetch } from './useApi';\r\nimport { useLayout } from './useLayout';\r\n\r\ntype CollectionApi = {\r\n get: <T = unknown>(\r\n pathname: string,\r\n params?: QueryParams,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n post: <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n put: <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n patch: <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options?: ApiRequestOptions\r\n ) => Promise<T>;\r\n delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;\r\n};\r\n\r\nexport function useCollectionApi(): CollectionApi {\r\n const layout = useLayout();\r\n return {\r\n get: async <T = unknown>(\r\n pathname: string,\r\n params: QueryParams = {},\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n params.locale = params.locale || layout.locale;\r\n params.market = params.market || layout.market;\r\n const qs = qsSerialize(params);\r\n return localCollectionGet<T>(pathname + (qs ? '?' + qs : ''), options);\r\n },\r\n post: async <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n return localCollectionPost<T>(pathname, payload, options, layout);\r\n },\r\n put: async <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n return localCollectionPut<T>(pathname, payload, options, layout);\r\n },\r\n patch: async <T = unknown>(\r\n pathname: string,\r\n payload?: unknown,\r\n options: ApiRequestOptions = {}\r\n ) => {\r\n return localCollectionPatch<T>(pathname, payload, options, layout);\r\n },\r\n delete: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {\r\n return localCollectionDelete<T>(pathname, options, layout);\r\n },\r\n };\r\n}\r\n\r\n/*\r\nexport function useCollectionApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {\r\n const layout = useLayout();\r\n // const layout = { locale: '', market: '' };\r\n return useHttpFetch<T>(pathname, options, localApiFetch, layout);\r\n}\r\n*/\r\n\r\nexport function useCollectionApiGet<T = unknown>(\r\n pathname: string,\r\n params?: QueryParams,\r\n options: ApiRequestOptions = {}\r\n) {\r\n const api = useApiFetch<T>(pathname, { ...options, method: 'GET' });\r\n return api;\r\n}\r\n\r\nexport function useCollectionApiPost<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, {\r\n ...options,\r\n method: 'POST',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useCollectionApiPut<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, {\r\n ...options,\r\n method: 'PUT',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useCollectionApiPatch<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, {\r\n ...options,\r\n method: 'PATCH',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useCollectionApiDelete<T = unknown>(\r\n pathname: string,\r\n options: ApiRequestOptions = {}\r\n) {\r\n return useApiFetch<T>(pathname, { ...options, method: 'DELETE' });\r\n}\r\n"],"mappings":";;;;;AAoCA,SAAgB,mBAAkC;CAChD,MAAM,SAAS,WAAW;AAC1B,QAAO;EACL,KAAK,OACH,UACA,SAAsB,EAAE,EACxB,UAA6B,EAAE,KAC5B;AACH,UAAO,SAAS,OAAO,UAAU,OAAO;AACxC,UAAO,SAAS,OAAO,UAAU,OAAO;GACxC,MAAM,KAAK,YAAY,OAAO;AAC9B,UAAO,mBAAsB,YAAY,KAAK,MAAM,KAAK,KAAK,QAAQ;;EAExE,MAAM,OACJ,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,oBAAuB,UAAU,SAAS,SAAS,OAAO;;EAEnE,KAAK,OACH,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,mBAAsB,UAAU,SAAS,SAAS,OAAO;;EAElE,OAAO,OACL,UACA,SACA,UAA6B,EAAE,KAC5B;AACH,UAAO,qBAAwB,UAAU,SAAS,SAAS,OAAO;;EAEpE,QAAQ,OAAoB,UAAkB,UAA6B,EAAE,KAAK;AAChF,UAAO,sBAAyB,UAAU,SAAS,OAAO;;EAE7D;;AAWH,SAAgB,oBACd,UACA,QACA,UAA6B,EAAE,EAC/B;AAEA,QADY,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAO,CAAC;;AAIrE,SAAgB,qBACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,oBACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,sBACd,UACA,SACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAC9B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,uBACd,UACA,UAA6B,EAAE,EAC/B;AACA,QAAO,YAAe,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useExtra.js","names":[],"sources":["../../src/client/useExtra.tsx"],"sourcesContent":["'use client';\n\nimport { useContext } from 'react';\nimport { ExtraContext } from './extra';\n\nexport const useExtra = () => {\n const context = useContext(ExtraContext);\n if (!context) {\n throw new Error('useExtra must be used within ExtraProvider');\n }\n return context;\n};\n"],"mappings":";;;;AAKA,MAAa,iBAAiB;CAC5B,MAAM,UAAU,WAAW,aAAa;AACxC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,6CAA6C;AAE/D,QAAO"}
1
+ {"version":3,"file":"useExtra.js","names":[],"sources":["../../src/client/useExtra.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useContext } from 'react';\r\nimport { ExtraContext } from './extra';\r\n\r\nexport const useExtra = () => {\r\n const context = useContext(ExtraContext);\r\n if (!context) {\r\n throw new Error('useExtra must be used within ExtraProvider');\r\n }\r\n return context;\r\n};\r\n"],"mappings":";;;;AAKA,MAAa,iBAAiB;CAC5B,MAAM,UAAU,WAAW,aAAa;AACxC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,6CAA6C;AAE/D,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"useHttp.js","names":[],"sources":["../../src/client/useHttp.ts"],"sourcesContent":["'use client';\n\nimport { FetchError, FetchRequestOptions, FetchService, httpFetch } from '@websolutespa/bom-core';\nimport { Dispatch, useEffect, useState } from 'react';\n\nexport function useHttpFetch<T = unknown>(\n pathname: string,\n options: FetchRequestOptions = { method: 'GET' },\n service: FetchService<T> = httpFetch,\n serviceOptions?: unknown\n): [T | undefined, boolean, FetchError, Dispatch<FetchError>] {\n const [response, setResponse] = useState<T>();\n const [loading, setLoading] = useState<boolean>(false);\n const [error, setError] = useState<FetchError>(null);\n useEffect(() => {\n // const source = axios.CancelToken.source();\n const fetchData = async () => {\n loading ? null : setLoading(true);\n error ? setError(null) : null;\n try {\n const response = await service(pathname, options, serviceOptions);\n // console.log('useHttp.response', response);\n setResponse(response);\n } catch (error: FetchError) {\n // console.error(error)\n setError(error);\n }\n setLoading(false);\n };\n fetchData();\n // return () => source.cancel();\n }, [pathname, options.method, options.body]);\n return [response, loading, error, setError];\n}\n\nexport function useHttpGet<T = unknown>(pathname: string, options: FetchRequestOptions = {}) {\n return useHttpFetch<T>(pathname, { ...options, method: 'GET' });\n}\n\nexport function useHttpPost<T = unknown>(\n pathname: string,\n payload: unknown,\n options: FetchRequestOptions = {}\n) {\n return useHttpFetch<T>(pathname, {\n ...options,\n method: 'POST',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useHttpPut<T = unknown>(\n pathname: string,\n payload: unknown,\n options: FetchRequestOptions = {}\n) {\n return useHttpFetch<T>(pathname, {\n ...options,\n method: 'PUT',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useHttpPatch<T = unknown>(\n pathname: string,\n payload: unknown,\n options: FetchRequestOptions = {}\n) {\n return useHttpFetch<T>(pathname, {\n ...options,\n method: 'PATCH',\n body: payload ? JSON.stringify(payload) : undefined,\n });\n}\n\nexport function useHttpDelete<T = unknown>(pathname: string, options: FetchRequestOptions = {}) {\n return useHttpFetch<T>(pathname, { ...options, method: 'DELETE' });\n}\n"],"mappings":";;;;AAKA,SAAgB,aACd,UACA,UAA+B,EAAE,QAAQ,OAAO,EAChD,UAA2B,WAC3B,gBAC4D;CAC5D,MAAM,CAAC,UAAU,eAAe,UAAa;CAC7C,MAAM,CAAC,SAAS,cAAc,SAAkB,MAAM;CACtD,MAAM,CAAC,OAAO,YAAY,SAAqB,KAAK;AACpD,iBAAgB;EAEd,MAAM,YAAY,YAAY;AAC5B,cAAiB,WAAW,KAAK;AACjC,YAAQ,SAAS,KAAK;AACtB,OAAI;AAGF,gBAFiB,MAAM,QAAQ,UAAU,SAAS,eAAe,CAE5C;YACd,OAAmB;AAE1B,aAAS,MAAM;;AAEjB,cAAW,MAAM;;AAEnB,aAAW;IAEV;EAAC;EAAU,QAAQ;EAAQ,QAAQ;EAAK,CAAC;AAC5C,QAAO;EAAC;EAAU;EAAS;EAAO;EAAS;;AAG7C,SAAgB,WAAwB,UAAkB,UAA+B,EAAE,EAAE;AAC3F,QAAO,aAAgB,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAO,CAAC;;AAGjE,SAAgB,YACd,UACA,SACA,UAA+B,EAAE,EACjC;AACA,QAAO,aAAgB,UAAU;EAC/B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,WACd,UACA,SACA,UAA+B,EAAE,EACjC;AACA,QAAO,aAAgB,UAAU;EAC/B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,aACd,UACA,SACA,UAA+B,EAAE,EACjC;AACA,QAAO,aAAgB,UAAU;EAC/B,GAAG;EACH,QAAQ;EACR,MAAM,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAA;EAC3C,CAAC;;AAGJ,SAAgB,cAA2B,UAAkB,UAA+B,EAAE,EAAE;AAC9F,QAAO,aAAgB,UAAU;EAAE,GAAG;EAAS,QAAQ;EAAU,CAAC"}
1
+ {"version":3,"file":"useHttp.js","names":[],"sources":["../../src/client/useHttp.ts"],"sourcesContent":["'use client';\r\n\r\nimport { FetchError, FetchRequestOptions, FetchService, httpFetch } from '@websolutespa/bom-core';\r\nimport { Dispatch, useEffect, useState } from 'react';\r\n\r\nexport function useHttpFetch<T = unknown>(\r\n pathname: string,\r\n options: FetchRequestOptions = { method: 'GET' },\r\n service: FetchService<T> = httpFetch,\r\n serviceOptions?: unknown\r\n): [T | undefined, boolean, FetchError, Dispatch<FetchError>] {\r\n const [response, setResponse] = useState<T>();\r\n const [loading, setLoading] = useState<boolean>(false);\r\n const [error, setError] = useState<FetchError>(null);\r\n useEffect(() => {\r\n // const source = axios.CancelToken.source();\r\n const fetchData = async () => {\r\n loading ? null : setLoading(true);\r\n error ? setError(null) : null;\r\n try {\r\n const response = await service(pathname, options, serviceOptions);\r\n // console.log('useHttp.response', response);\r\n setResponse(response);\r\n } catch (error: FetchError) {\r\n // console.error(error)\r\n setError(error);\r\n }\r\n setLoading(false);\r\n };\r\n fetchData();\r\n // return () => source.cancel();\r\n }, [pathname, options.method, options.body]);\r\n return [response, loading, error, setError];\r\n}\r\n\r\nexport function useHttpGet<T = unknown>(pathname: string, options: FetchRequestOptions = {}) {\r\n return useHttpFetch<T>(pathname, { ...options, method: 'GET' });\r\n}\r\n\r\nexport function useHttpPost<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: FetchRequestOptions = {}\r\n) {\r\n return useHttpFetch<T>(pathname, {\r\n ...options,\r\n method: 'POST',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useHttpPut<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: FetchRequestOptions = {}\r\n) {\r\n return useHttpFetch<T>(pathname, {\r\n ...options,\r\n method: 'PUT',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useHttpPatch<T = unknown>(\r\n pathname: string,\r\n payload: unknown,\r\n options: FetchRequestOptions = {}\r\n) {\r\n return useHttpFetch<T>(pathname, {\r\n ...options,\r\n method: 'PATCH',\r\n body: payload ? JSON.stringify(payload) : undefined,\r\n });\r\n}\r\n\r\nexport function useHttpDelete<T = unknown>(pathname: string, options: FetchRequestOptions = {}) {\r\n return useHttpFetch<T>(pathname, { ...options, method: 'DELETE' });\r\n}\r\n"],"mappings":";;;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 -1 +1 @@
1
- {"version":3,"file":"useLabel.js","names":[],"sources":["../../src/client/useLabel.tsx"],"sourcesContent":["'use client';\n\nimport { useContext } from 'react';\nimport { LabelContext } from './label';\n\nexport const useLabel = () => {\n const context = useContext(LabelContext);\n if (!context) {\n throw new Error('useLabel must be used within LabelProvider');\n }\n return context;\n};\n"],"mappings":";;;;AAKA,MAAa,iBAAiB;CAC5B,MAAM,UAAU,WAAW,aAAa;AACxC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,6CAA6C;AAE/D,QAAO"}
1
+ {"version":3,"file":"useLabel.js","names":[],"sources":["../../src/client/useLabel.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useContext } from 'react';\r\nimport { LabelContext } from './label';\r\n\r\nexport const useLabel = () => {\r\n const context = useContext(LabelContext);\r\n if (!context) {\r\n throw new Error('useLabel must be used within LabelProvider');\r\n }\r\n return context;\r\n};\r\n"],"mappings":";;;;AAKA,MAAa,iBAAiB;CAC5B,MAAM,UAAU,WAAW,aAAa;AACxC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,6CAA6C;AAE/D,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLayout.js","names":[],"sources":["../../src/client/useLayout.tsx"],"sourcesContent":["'use client';\n\nimport { IAppExtended, ILayout } from '@websolutespa/bom-core';\nimport { useContext } from 'react';\nimport { LayoutContext } from './layout';\n\nexport const useLayout = <T extends IAppExtended = IAppExtended>() => {\n const context = useContext(LayoutContext);\n if (!context) {\n throw new Error('useLayout must be used within LayoutProvider');\n }\n return context as ILayout<T>;\n};\n"],"mappings":";;;;AAMA,MAAa,kBAAyD;CACpE,MAAM,UAAU,WAAW,cAAc;AACzC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,+CAA+C;AAEjE,QAAO"}
1
+ {"version":3,"file":"useLayout.js","names":[],"sources":["../../src/client/useLayout.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { IAppExtended, ILayout } from '@websolutespa/bom-core';\r\nimport { useContext } from 'react';\r\nimport { LayoutContext } from './layout';\r\n\r\nexport const useLayout = <T extends IAppExtended = IAppExtended>() => {\r\n const context = useContext(LayoutContext);\r\n if (!context) {\r\n throw new Error('useLayout must be used within LayoutProvider');\r\n }\r\n return context as ILayout<T>;\r\n};\r\n"],"mappings":";;;;AAMA,MAAa,kBAAyD;CACpE,MAAM,UAAU,WAAW,cAAc;AACzC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,+CAA+C;AAEjE,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLink.js","names":[],"sources":["../../src/client/useLink.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback } from 'react';\nimport { getLink } from '../lib/link';\nimport { useLayout } from './useLayout';\n\nexport const useLink = () => {\n const layout = useLayout();\n const link = useCallback(\n (category: string) => {\n return getLink(category, layout);\n },\n [layout]\n );\n return link;\n};\n"],"mappings":";;;;;AAMA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,WAAW;AAO1B,QANa,aACV,aAAqB;AACpB,SAAO,QAAQ,UAAU,OAAO;IAElC,CAAC,OAAO,CACT"}
1
+ {"version":3,"file":"useLink.js","names":[],"sources":["../../src/client/useLink.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useCallback } from 'react';\r\nimport { getLink } from '../lib/link';\r\nimport { useLayout } from './useLayout';\r\n\r\nexport const useLink = () => {\r\n const layout = useLayout();\r\n const link = useCallback(\r\n (category: string) => {\r\n return getLink(category, layout);\r\n },\r\n [layout]\r\n );\r\n return link;\r\n};\r\n"],"mappings":";;;;;AAMA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,WAAW;AAO1B,QANa,aACV,aAAqB;AACpB,SAAO,QAAQ,UAAU,OAAO;IAElC,CAAC,OAAO,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMetaData.js","names":[],"sources":["../../src/client/useMetaData.tsx"],"sourcesContent":["'use client';\n\nimport { useContext } from 'react';\nimport { MetaDataContext } from './metadata';\n\nexport const useMetaData = () => {\n const context = useContext(MetaDataContext);\n if (!context) {\n throw new Error('useMetaData must be used within MetaDataProvider');\n }\n return context;\n};\n"],"mappings":";;;;AAKA,MAAa,oBAAoB;CAC/B,MAAM,UAAU,WAAW,gBAAgB;AAC3C,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,mDAAmD;AAErE,QAAO"}
1
+ {"version":3,"file":"useMetaData.js","names":[],"sources":["../../src/client/useMetaData.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useContext } from 'react';\r\nimport { MetaDataContext } from './metadata';\r\n\r\nexport const useMetaData = () => {\r\n const context = useContext(MetaDataContext);\r\n if (!context) {\r\n throw new Error('useMetaData must be used within MetaDataProvider');\r\n }\r\n return context;\r\n};\r\n"],"mappings":";;;;AAKA,MAAa,oBAAoB;CAC/B,MAAM,UAAU,WAAW,gBAAgB;AAC3C,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,mDAAmD;AAErE,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePage.d.ts","names":[],"sources":["../../src/client/usePage.tsx"],"mappings":";;;cAKa,OAAA;EAAA;MAMZ,uBAAA,CAAA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;sEACoikB,IAAA;MAAA;;;;0EAAjzT,IAAA;MAAA,oCAAqE,IAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sEAA3lO,IAAA;IAAA"}
1
+ {"version":3,"file":"usePage.d.ts","names":[],"sources":["../../src/client/usePage.tsx"],"mappings":";;;cAKa,OAAA;EAAA;MAMZ,uBAAA,CAAA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;sEACwhkB,IAAA;MAAA;;;;0EAAjzT,IAAA;MAAA,oCAAqE,IAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sEAA3lO,IAAA;IAAA"}