@krate/runtime 0.5.0-alpha.2 → 0.5.0-alpha.4

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 (105) hide show
  1. package/dist/action-context.d.ts +56 -0
  2. package/dist/action-context.js +73 -0
  3. package/dist/action-context.test.d.ts +1 -0
  4. package/dist/action-context.test.js +47 -0
  5. package/dist/actions.d.ts +120 -0
  6. package/dist/actions.js +550 -0
  7. package/dist/actions.test.d.ts +1 -0
  8. package/dist/actions.test.js +417 -0
  9. package/dist/boundary.d.ts +121 -0
  10. package/dist/boundary.js +429 -0
  11. package/dist/cache-scope.d.ts +118 -0
  12. package/dist/cache-scope.js +311 -0
  13. package/dist/cache.d.ts +55 -0
  14. package/dist/cache.js +155 -0
  15. package/dist/cache.test.d.ts +1 -0
  16. package/dist/cache.test.js +217 -0
  17. package/dist/class-component.d.ts +66 -0
  18. package/dist/class-component.js +633 -0
  19. package/dist/class-component.test.d.ts +1 -0
  20. package/dist/class-component.test.js +411 -0
  21. package/dist/context.d.ts +13 -0
  22. package/dist/context.js +58 -32
  23. package/dist/context.test.d.ts +1 -0
  24. package/dist/context.test.js +57 -0
  25. package/dist/derived.test.d.ts +1 -0
  26. package/dist/derived.test.js +140 -0
  27. package/dist/discrete.test.d.ts +1 -0
  28. package/dist/discrete.test.js +100 -0
  29. package/dist/dom.d.ts +55 -0
  30. package/dist/dom.js +414 -63
  31. package/dist/effects.d.ts +88 -0
  32. package/dist/effects.js +790 -0
  33. package/dist/effects.test.d.ts +1 -0
  34. package/dist/effects.test.js +485 -0
  35. package/dist/events.d.ts +58 -0
  36. package/dist/events.js +503 -0
  37. package/dist/events.test.d.ts +1 -0
  38. package/dist/events.test.js +447 -0
  39. package/dist/index.d.ts +14 -4
  40. package/dist/index.js +9 -3
  41. package/dist/jsx-types.d.ts +2 -0
  42. package/dist/krate-hydrate-lite.js +7 -1
  43. package/dist/krate-hydrate.js +7 -1
  44. package/dist/krate-runtime.js +7 -1
  45. package/dist/krate-suspense.js +2 -0
  46. package/dist/lanes.test.d.ts +1 -0
  47. package/dist/lanes.test.js +59 -0
  48. package/dist/list.d.ts +20 -0
  49. package/dist/list.js +466 -0
  50. package/dist/list.test.d.ts +1 -0
  51. package/dist/list.test.js +344 -0
  52. package/dist/optimistic-lanes.test.d.ts +1 -0
  53. package/dist/optimistic-lanes.test.js +45 -0
  54. package/dist/portal.d.ts +47 -0
  55. package/dist/portal.js +189 -0
  56. package/dist/portal.test.d.ts +1 -0
  57. package/dist/portal.test.js +99 -0
  58. package/dist/react-effects.test.d.ts +1 -0
  59. package/dist/react-effects.test.js +96 -0
  60. package/dist/react-suspense.test.d.ts +1 -0
  61. package/dist/react-suspense.test.js +194 -0
  62. package/dist/react.d.ts +132 -32
  63. package/dist/react.js +335 -81
  64. package/dist/react.test.js +12 -2
  65. package/dist/reconcile.js +13 -0
  66. package/dist/refs.d.ts +33 -0
  67. package/dist/refs.js +142 -0
  68. package/dist/refs.test.d.ts +1 -0
  69. package/dist/refs.test.js +257 -0
  70. package/dist/request-context.d.ts +62 -0
  71. package/dist/request-context.js +107 -0
  72. package/dist/resource.js +20 -1
  73. package/dist/router-layout.test.d.ts +1 -0
  74. package/dist/router-layout.test.js +179 -0
  75. package/dist/router-lite.d.ts +25 -0
  76. package/dist/router-lite.js +73 -0
  77. package/dist/router-nav.test.d.ts +1 -0
  78. package/dist/router-nav.test.js +399 -0
  79. package/dist/router-slots.test.d.ts +1 -0
  80. package/dist/router-slots.test.js +144 -0
  81. package/dist/router.d.ts +66 -2
  82. package/dist/router.js +1535 -650
  83. package/dist/server-async.test.d.ts +1 -0
  84. package/dist/server-async.test.js +174 -0
  85. package/dist/server-renderer.js +494 -119
  86. package/dist/server.d.ts +27 -1
  87. package/dist/server.js +187 -1
  88. package/dist/server.test.js +20 -0
  89. package/dist/signal-lanes.test.d.ts +1 -0
  90. package/dist/signal-lanes.test.js +32 -0
  91. package/dist/signal.d.ts +186 -1
  92. package/dist/signal.js +896 -66
  93. package/dist/slots.d.ts +22 -0
  94. package/dist/slots.js +134 -0
  95. package/dist/slots.test.d.ts +1 -0
  96. package/dist/slots.test.js +169 -0
  97. package/dist/snapshots.test.d.ts +1 -0
  98. package/dist/snapshots.test.js +208 -0
  99. package/dist/suspense-actions.test.d.ts +1 -0
  100. package/dist/suspense-actions.test.js +72 -0
  101. package/dist/suspense.d.ts +220 -0
  102. package/dist/suspense.js +901 -0
  103. package/dist/suspense.test.d.ts +1 -0
  104. package/dist/suspense.test.js +518 -0
  105. package/package.json +5 -1
@@ -0,0 +1,429 @@
1
+ // Owner tree and error boundaries.
2
+ //
3
+ // Krate components run once, so there is no reconciler to unwind when code
4
+ // throws. This module gives each hydrated component instance an Owner: a node
5
+ // in a tree that mirrors React's fiber parent chain. Effects, cleanups and
6
+ // mount callbacks created while an owner is current belong to it (see
7
+ // OwnerHooks in signal.ts), so unmounting an owner disposes its whole subtree,
8
+ // and values thrown by its code are routed up the tree to the nearest owner
9
+ // with a boundary handler. Error boundaries install a handler; Suspense can
10
+ // install one that intercepts thrown promises the same way.
11
+ //
12
+ // Owners also follow conditional branches: an owner registered inside a
13
+ // branch of a compiled conditional is mounted while that branch is shown and
14
+ // unmounted (its cleanups run) when it is swapped out, so componentDidMount /
15
+ // componentWillUnmount and state resets match React. A dormant owner keeps its
16
+ // setup function and is remounted by running it again.
17
+ import { setOwnerHooks, untrack, onCleanup, krateGetOwner, krateSetOwner } from './signal.js';
18
+ import { krateForgetOwner, krateOnHookError } from './effects.js';
19
+ let current = null;
20
+ let nextOrder = 0;
21
+ const byId = new Map();
22
+ const condState = new Map();
23
+ const condOwners = new Map();
24
+ let resetRegistered = false;
25
+ let mountDepth = 0;
26
+ const deferredMounts = [];
27
+ function makeOwner(id, name, parent, creator, cond, branch, setup) {
28
+ const o = {
29
+ id,
30
+ name,
31
+ parent,
32
+ creator,
33
+ children: [],
34
+ order: nextOrder++,
35
+ state: 'dormant',
36
+ boundary: null,
37
+ blocked: false,
38
+ inError: false,
39
+ cond,
40
+ branch,
41
+ setup,
42
+ data: {},
43
+ cleanups: [],
44
+ };
45
+ if (parent)
46
+ parent.children.push(o);
47
+ return o;
48
+ }
49
+ /** The owner whose code is running, or null. */
50
+ export function getOwner() {
51
+ return current;
52
+ }
53
+ /**
54
+ * Creates a mounted owner under parent (default: the current owner). Use it for
55
+ * regions created at runtime; run code in it with runWithOwner.
56
+ */
57
+ export function createOwner(name, parent = current) {
58
+ const o = makeOwner('', name, parent || null, parent || null, '', '', null);
59
+ o.state = parent && parent.state !== 'mounted' ? 'dormant' : 'mounted';
60
+ if (!parent)
61
+ registerReset();
62
+ return o;
63
+ }
64
+ /**
65
+ * Runs fn with owner current: effects and cleanups it creates belong to the
66
+ * owner and errors it throws are routed to the owner's boundaries. Returns
67
+ * fn's value, or undefined when it threw or the owner is not mounted.
68
+ */
69
+ export function runWithOwner(owner, fn) {
70
+ if (!owner)
71
+ return fn();
72
+ const o = owner;
73
+ if (o.state !== 'mounted')
74
+ return undefined;
75
+ const prev = current;
76
+ current = o;
77
+ try {
78
+ return untrack(fn);
79
+ }
80
+ catch (err) {
81
+ handleError(err, o);
82
+ return undefined;
83
+ }
84
+ finally {
85
+ current = prev;
86
+ }
87
+ }
88
+ /** Registers fn to run when owner unmounts (immediately if it already has). */
89
+ export function onOwnerCleanup(owner, fn) {
90
+ const o = owner;
91
+ if (o.state !== 'mounted') {
92
+ safely(fn, o);
93
+ return;
94
+ }
95
+ o.cleanups.push(fn);
96
+ }
97
+ /** Installs a boundary handler on owner (null removes it). */
98
+ export function setBoundary(owner, handler) {
99
+ owner.boundary = handler;
100
+ }
101
+ /** React-style component stack from source up to the root. */
102
+ export function componentStack(source) {
103
+ let out = '';
104
+ for (let o = source; o; o = o.parent) {
105
+ out += '\n at ' + o.name;
106
+ }
107
+ return out;
108
+ }
109
+ /**
110
+ * Routes a thrown value from source to the nearest mounted ancestor boundary
111
+ * that handles it. An owner never catches its own errors: a boundary's own
112
+ * render or lifecycle failure goes to the boundary above it, as in React.
113
+ * Unhandled errors are reported and the failing subtree is unmounted.
114
+ */
115
+ export function handleError(thrown, source = current) {
116
+ if (!source)
117
+ throw thrown;
118
+ const info = { componentStack: componentStack(source) };
119
+ for (let b = source.parent; b; b = b.parent) {
120
+ if (b.state !== 'mounted' || !b.boundary)
121
+ continue;
122
+ let handled = false;
123
+ try {
124
+ handled = b.boundary(thrown, info, source);
125
+ }
126
+ catch (next) {
127
+ // The boundary itself failed (getDerivedStateFromError threw): the new
128
+ // error propagates from the boundary.
129
+ handleError(next, b);
130
+ return;
131
+ }
132
+ if (handled)
133
+ return;
134
+ }
135
+ reportUncaught(thrown, info, source);
136
+ }
137
+ // Uncaught errors. React 18 unmounts the whole root; Krate keeps the page's
138
+ // server-rendered HTML and unmounts only the component that threw (and its
139
+ // descendants), logging the error like React does.
140
+ function reportUncaught(thrown, info, source) {
141
+ const g = globalThis;
142
+ try {
143
+ const msg = String(thrown?.stack || thrown?.message || thrown);
144
+ if (Array.isArray(g.__krateErrs))
145
+ g.__krateErrs.push(msg);
146
+ }
147
+ catch {
148
+ // Reporting must never throw.
149
+ }
150
+ if (typeof console !== 'undefined') {
151
+ console.error(thrown);
152
+ console.error('The above error occurred in the <' + source.name + '> component:' + info.componentStack +
153
+ '\n\nAdd an error boundary (a class component with static getDerivedStateFromError) to recover from it.');
154
+ }
155
+ source.blocked = true;
156
+ unmountOwner(source);
157
+ }
158
+ function safely(fn, owner) {
159
+ try {
160
+ fn();
161
+ }
162
+ catch (err) {
163
+ if (owner && owner.parent)
164
+ handleError(err, owner);
165
+ else
166
+ reportUncaughtLoose(err);
167
+ }
168
+ }
169
+ function reportUncaughtLoose(err) {
170
+ if (typeof console !== 'undefined')
171
+ console.error(err);
172
+ }
173
+ /**
174
+ * Unmounts owner and its subtree: cleanups run parent-first (React calls
175
+ * componentWillUnmount top-down) and the owners become dormant, so they can
176
+ * be mounted again by running their setup.
177
+ */
178
+ export function unmountOwner(owner) {
179
+ disposeTree(owner, 'dormant');
180
+ }
181
+ /** Mounts a dormant owner (and its mountable descendants). */
182
+ export function mountOwner(owner) {
183
+ const o = owner;
184
+ if (o.state !== 'dormant')
185
+ return;
186
+ o.blocked = false;
187
+ if (canMount(o))
188
+ mount(o);
189
+ }
190
+ /** Unmounts every child of owner (an error boundary dropping its subtree). */
191
+ export function unmountChildren(owner) {
192
+ for (const c of owner.children)
193
+ disposeTree(c, 'dormant');
194
+ }
195
+ /**
196
+ * Mounts owner's dormant children that their conditional branch allows,
197
+ * clearing the block a caught error put on them.
198
+ */
199
+ export function remountChildren(owner) {
200
+ if (owner.state !== 'mounted')
201
+ return;
202
+ for (const c of owner.children.slice()) {
203
+ c.blocked = false;
204
+ if (c.state === 'dormant' && canMount(c))
205
+ mount(c);
206
+ }
207
+ }
208
+ function disposeTree(o, to) {
209
+ if (o.state === 'mounted') {
210
+ o.state = to;
211
+ const errors = [];
212
+ for (const fn of o.cleanups.splice(0)) {
213
+ try {
214
+ fn();
215
+ }
216
+ catch (err) {
217
+ errors.push(err);
218
+ }
219
+ }
220
+ // React hook effects (effects.ts) of this component clean up too, and a
221
+ // remount starts them fresh.
222
+ if (o.id) {
223
+ try {
224
+ krateForgetOwner(o.id);
225
+ }
226
+ catch (err) {
227
+ errors.push(err);
228
+ }
229
+ }
230
+ for (const c of o.children)
231
+ disposeTree(c, to);
232
+ // Errors thrown while unmounting go to the boundary above the owner.
233
+ for (const err of errors) {
234
+ if (o.parent)
235
+ handleError(err, o);
236
+ else
237
+ reportUncaughtLoose(err);
238
+ }
239
+ return;
240
+ }
241
+ if (to === 'disposed' && o.state !== 'disposed') {
242
+ o.state = 'disposed';
243
+ for (const c of o.children)
244
+ disposeTree(c, to);
245
+ }
246
+ }
247
+ function condShows(o) {
248
+ if (!o.cond)
249
+ return true;
250
+ const shown = condState.get(o.cond);
251
+ return shown === undefined || shown === o.branch;
252
+ }
253
+ function canMount(o) {
254
+ if (o.blocked || !condShows(o))
255
+ return false;
256
+ return !o.parent || o.parent.state === 'mounted';
257
+ }
258
+ function mount(o) {
259
+ if (o.state !== 'dormant')
260
+ return;
261
+ o.state = 'mounted';
262
+ mountDepth++;
263
+ // The scope declares its effects.ts owner itself; restore the caller's.
264
+ const prevEffectsOwner = krateGetOwner();
265
+ try {
266
+ if (o.setup)
267
+ runWithOwner(o, o.setup);
268
+ }
269
+ finally {
270
+ krateSetOwner(prevEffectsOwner);
271
+ mountDepth--;
272
+ }
273
+ if (o.state === 'mounted') {
274
+ for (const c of o.children.slice()) {
275
+ if (c.state === 'dormant' && canMount(c))
276
+ mount(c);
277
+ }
278
+ }
279
+ if (mountDepth === 0 && deferredMounts.length > 0) {
280
+ const list = deferredMounts.splice(0).sort((a, b) => a.order - b.order);
281
+ for (const d of list) {
282
+ if (d.state === 'dormant' && canMount(d))
283
+ mount(d);
284
+ }
285
+ }
286
+ }
287
+ function registerReset() {
288
+ if (resetRegistered)
289
+ return;
290
+ resetRegistered = true;
291
+ // Top-level registration: runs on disposeAll() (SPA navigation).
292
+ onCleanup(resetOwners);
293
+ }
294
+ function resetOwners() {
295
+ const roots = [];
296
+ for (const o of byId.values())
297
+ if (!o.parent)
298
+ roots.push(o);
299
+ for (const o of roots)
300
+ disposeTree(o, 'disposed');
301
+ byId.clear();
302
+ condState.clear();
303
+ condOwners.clear();
304
+ deferredMounts.length = 0;
305
+ resetRegistered = false;
306
+ }
307
+ /**
308
+ * Hydration entry point: the compiler wraps each component's hydration scope
309
+ * in `__krateOwn(id, meta, setup)` on pages that use the owner tree. The setup
310
+ * runs now when the component is visible, or later when its branch is shown.
311
+ */
312
+ export function __krateOwn(id, meta, setup) {
313
+ const m = meta || {};
314
+ const prior = byId.get(id);
315
+ if (prior)
316
+ disposeTree(prior, 'disposed');
317
+ const parent = (m.p && byId.get(m.p)) || null;
318
+ const creator = (m.k && byId.get(m.k)) || null;
319
+ const o = makeOwner(id, m.n || id, parent, creator, m.c || '', m.b || '', setup);
320
+ byId.set(id, o);
321
+ registerReset();
322
+ if (o.cond) {
323
+ let list = condOwners.get(o.cond);
324
+ if (!list) {
325
+ list = [];
326
+ condOwners.set(o.cond, list);
327
+ }
328
+ list.push(o);
329
+ }
330
+ // An owner rendered as part of a boundary's failed render stays down until
331
+ // the boundary renders again.
332
+ if (parent && parent.inError && condShows(o))
333
+ o.blocked = true;
334
+ if (canMount(o))
335
+ mount(o);
336
+ }
337
+ /** Owner registered under id, if any (tests, devtools). */
338
+ export function __krateOwner(id) {
339
+ return byId.get(id) || null;
340
+ }
341
+ /**
342
+ * Called by the hydration bootstrap before a conditional swaps branches: the
343
+ * outgoing branch's owners unmount while their DOM is still attached.
344
+ */
345
+ export function __krateCondPre(id, show) {
346
+ const prev = condState.get(id);
347
+ const want = show ? 'c' : 'a';
348
+ if (prev === undefined || prev === want)
349
+ return;
350
+ const list = condOwners.get(id);
351
+ if (!list)
352
+ return;
353
+ for (const o of list) {
354
+ if (o.branch === prev && o.state === 'mounted')
355
+ disposeTree(o, 'dormant');
356
+ }
357
+ }
358
+ /** Called after a conditional swapped: the incoming branch's owners mount. */
359
+ export function __krateCondPost(id, show) {
360
+ const want = show ? 'c' : 'a';
361
+ const prev = condState.get(id);
362
+ condState.set(id, want);
363
+ if (prev === want)
364
+ return;
365
+ const list = condOwners.get(id);
366
+ if (!list)
367
+ return;
368
+ for (const o of list) {
369
+ if (o.branch !== want || o.state !== 'dormant' || !canMount(o))
370
+ continue;
371
+ if (mountDepth > 0)
372
+ deferredMounts.push(o);
373
+ else
374
+ mount(o);
375
+ }
376
+ }
377
+ /**
378
+ * Called by the hydration bootstrap's __safe wrapper. Routes an error thrown
379
+ * while a component's hydration scope runs; nodes outside the document (a
380
+ * hidden conditional branch React would not have rendered) are ignored.
381
+ */
382
+ export function __krateOnError(err, node) {
383
+ if (!current)
384
+ return false;
385
+ if (node && node.isConnected === false)
386
+ return false;
387
+ handleError(err, current);
388
+ return true;
389
+ }
390
+ // React hook effects (effects.ts) report errors to the component's owner.
391
+ krateOnHookError((err, id) => {
392
+ const o = id ? byId.get(id) : undefined;
393
+ if (!o)
394
+ return false;
395
+ if (o.state === 'mounted') {
396
+ commitPhaseDepth++;
397
+ try {
398
+ handleError(err, o);
399
+ }
400
+ finally {
401
+ commitPhaseDepth--;
402
+ }
403
+ }
404
+ return true;
405
+ });
406
+ let commitPhaseDepth = 0;
407
+ /**
408
+ * Reports whether the error being handled was thrown in the commit phase
409
+ * (effects, lifecycles). React retries a failed render once, but not a
410
+ * failed commit.
411
+ */
412
+ export function inCommitPhaseError() {
413
+ return commitPhaseDepth > 0;
414
+ }
415
+ setOwnerHooks({
416
+ current: () => current,
417
+ run: (owner, fn) => {
418
+ runWithOwner(owner, fn);
419
+ },
420
+ cleanup: (owner, fn) => onOwnerCleanup(owner, fn),
421
+ error: (owner, err) => {
422
+ const o = owner;
423
+ // Late errors from an unmounted subtree are dropped like React drops
424
+ // updates to unmounted components.
425
+ if (o.state === 'mounted')
426
+ handleError(err, o);
427
+ return true;
428
+ },
429
+ });
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Server data cache and render cache scopes.
3
+ *
4
+ * This module holds the process-wide state behind `@krate/runtime/cache`:
5
+ *
6
+ * - The render scope: the SSR renderer runs every page and region render
7
+ * inside `withCacheScope`, which records the cache tags, the smallest
8
+ * revalidate window and any no-store read the render made. The renderer
9
+ * stores the tags on its ISR/region cache entry so `revalidateTag` can find
10
+ * the entries a tag fed.
11
+ * - The data cache: `unstable_cache` results and `fetch` responses cached via
12
+ * `{ next: { revalidate, tags } }` or `cache: "force-cache"`, keyed by the
13
+ * call, expired by revalidate seconds and indexed by tag.
14
+ * - The `fetch` wrapper that applies those options.
15
+ *
16
+ * State lives on `globalThis` under `Symbol.for` keys, so the copy bundled
17
+ * into the renderer and the copy a page bundle imports share it. The module
18
+ * has no Node imports: the embedded QuickJS API runtime bundles it too, and
19
+ * there the data cache is backed by the Go host (`_go_cache_get/_go_cache_set`).
20
+ */
21
+ /** What one render read through the cache. */
22
+ export interface CacheScope {
23
+ /** Route being rendered (diagnostics only). */
24
+ route: string;
25
+ /** Cache tags the render read. */
26
+ tags: Set<string>;
27
+ /** Smallest positive revalidate window (seconds) a read declared; 0 = none. */
28
+ revalidate: number;
29
+ /** True when a read opted out of caching (no-store, revalidate 0, unstable_noStore). */
30
+ noStore: boolean;
31
+ }
32
+ /** Minimal AsyncLocalStorage shape (the Node class satisfies it). */
33
+ export interface AsyncStore<T> {
34
+ getStore(): T | undefined;
35
+ run<R>(store: T, fn: () => R): R;
36
+ }
37
+ /** Pending revalidations of one server action or API request. */
38
+ export interface RevalidateScope {
39
+ kind: string;
40
+ paths: Array<{
41
+ path: string;
42
+ type: 'page' | 'layout';
43
+ }>;
44
+ tags: string[];
45
+ }
46
+ /** In-process data cache with tag index and FIFO bound. */
47
+ export declare class DataCache {
48
+ private max;
49
+ private map;
50
+ private byTag;
51
+ constructor(max?: number);
52
+ get size(): number;
53
+ get(key: string): unknown | undefined;
54
+ set(key: string, value: unknown, ttlSeconds: number, tags: string[]): void;
55
+ delete(key: string): void;
56
+ /** Removes every entry carrying one of tags; returns how many. */
57
+ invalidateTags(tags: string[]): number;
58
+ clear(): void;
59
+ }
60
+ /** Process-wide cache runtime shared by every bundled copy of this module. */
61
+ export interface CacheRuntime {
62
+ dataCache: DataCache;
63
+ /** Render scope storage; installed by the SSR renderer. */
64
+ renderStore?: AsyncStore<CacheScope>;
65
+ /** Bumped on every invalidation so in-flight renders/reads do not store stale results. */
66
+ epoch: number;
67
+ /** Applies a tag invalidation to the local data cache. */
68
+ invalidate(payload: {
69
+ tags?: string[];
70
+ }): {
71
+ dataEntries: number;
72
+ };
73
+ fetchPatched?: boolean;
74
+ }
75
+ /** The shared cache runtime, created on first use. */
76
+ export declare function cacheRuntime(): CacheRuntime;
77
+ /** Installs the render scope storage (an AsyncLocalStorage). Renderer only. */
78
+ export declare function installRenderStore(store: AsyncStore<CacheScope>): void;
79
+ /** The scope of the render currently running, if any. */
80
+ export declare function currentRenderScope(): CacheScope | undefined;
81
+ /** The pending-revalidation scope of the current server action / API request. */
82
+ export declare function currentRevalidateScope(): RevalidateScope | undefined;
83
+ /**
84
+ * Runs fn inside a fresh render scope and returns its result together with
85
+ * the scope (tags, revalidate window, noStore) and whether an invalidation
86
+ * happened while it ran (then the result must not be cached).
87
+ */
88
+ export declare function withCacheScope<T>(route: string, fn: () => T | Promise<T>): Promise<{
89
+ result: T;
90
+ scope: CacheScope;
91
+ invalidated: boolean;
92
+ }>;
93
+ /**
94
+ * Implicit tag carried by data-cache entries first stored while rendering
95
+ * route, so revalidatePath(route) also drops the data that render cached.
96
+ */
97
+ export declare function routeDataTag(route: string): string;
98
+ /** Records tags and a revalidate window on the current render scope. */
99
+ export declare function recordCacheRead(tags: readonly string[] | undefined, revalidate: number | false | undefined): void;
100
+ /** Marks the current render as uncacheable. Outside a render it has no effect. */
101
+ export declare function markNoStore(): void;
102
+ /** Reads a JSON value from the data cache; undefined on a miss. */
103
+ export declare function dataCacheGetJSON(key: string): string | undefined;
104
+ /**
105
+ * Stores a JSON value unless an invalidation happened since epoch. Inside a
106
+ * render the entry also gets the route's implicit tag (see routeDataTag).
107
+ */
108
+ export declare function dataCacheSetJSON(key: string, json: string, ttlSeconds: number, tags: string[], epoch: number): void;
109
+ /**
110
+ * Wraps globalThis.fetch once so Next-style cache options work in server
111
+ * code: `next.tags` are recorded on the current render, `next.revalidate: N`
112
+ * or `cache: "force-cache"` cache successful GET/HEAD responses (by method,
113
+ * URL and headers) for N seconds (indefinitely for force-cache or
114
+ * `revalidate: false`) under the given tags, and `cache: "no-store"` /
115
+ * `next.revalidate: 0` bypass the cache and make the render uncacheable.
116
+ * Requests without these options are passed through untouched.
117
+ */
118
+ export declare function patchFetch(): void;