@belte/belte 0.19.2 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @belte/belte
2
2
 
3
+ ## 0.19.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ae17e17`](https://github.com/briancray/belte/commit/ae17e17cac4a52a7506e411a572857cdf6f2d5d1) - type the warm sync return as Promise<Return> | Return ([`a00afa7`](https://github.com/briancray/belte/commit/a00afa7955fef3755f91b8a4da935916701c070a))
8
+
3
9
  ## 0.19.2
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@belte/belte",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "type": "module",
5
5
  "description": "Isomorphic multimodal HTTP framework built for humans and machines in a single Bun runtime",
6
6
  "license": "MIT",
@@ -72,7 +72,7 @@ the child.
72
72
  export function cache<Args, Return>(
73
73
  fn: RemoteFunction<Args, Return>,
74
74
  options?: CacheOptions,
75
- ): (args?: Args) => Promise<Return>
75
+ ): (args?: Args) => Promise<Return> | Return
76
76
  export function cache<Args>(
77
77
  fn: RawRemoteFunction<Args>,
78
78
  options?: CacheOptions,
@@ -118,13 +118,14 @@ export function cache<Args, Return>(
118
118
  invalidate the replacement entry carries no value and falls through
119
119
  to the async fetch as before.
120
120
 
121
- The public overload stays typed Promise<Return> on purpose: a
122
- non-thenable is the only thing {#await} can render synchronously, so
123
- the sync return is left as an internal optimization rather than
124
- widened to `Return | Promise<Return>` (which would leak it into every
125
- caller's types). The one cost is that `.then`/`.catch`/`.finally`
126
- directly on a warm result throws consume cache via `await`/`{#await}`,
127
- never `.then`. Don't "fix" the type; see memory cache-warm-sync-tradeoff.
121
+ The decoded overload is typed `Promise<Return> | Return` so the warm
122
+ sync return is honest at the type level: a non-thenable is the only
123
+ thing {#await} can render synchronously, and surfacing the union turns
124
+ chaining `.then`/`.catch`/`.finally` on a read into a compile error
125
+ rather than a runtime throw on warm hits. Consume cache via
126
+ `await`/`{#await}` (both accept the union); in the await form handle
127
+ errors with `try/catch`, never `.catch`. Raw and producer callers stay
128
+ `Promise<…>` — they never take this sync path.
128
129
 
129
130
  Each warm read returns its own clone of the stored value: the entry's
130
131
  value is decoded once at hydration and would otherwise be handed by