@brust/core 2.0.0-alpha.1 → 2.0.0-alpha.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/native/index.d.ts CHANGED
@@ -15,9 +15,24 @@ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-was
15
15
  */
16
16
  export declare function beginDrain(timeoutMs: number): Promise<void>
17
17
 
18
+ /** Drop both tier-1 caches (a broadcast gap, R10); `stats.l2.resets`++. The L1 entries removed. */
19
+ export declare function cacheClear(): number
20
+
18
21
  /** `cache.invalidate({ key?, tags?, path?, method? })` (spec §5). */
19
22
  export declare function cacheInvalidate(args: NapiInvalidateArgs): NapiInvalidateResult
20
23
 
24
+ /**
25
+ * Bump the `stats.l2` counter `name` (the JS side's counts, R9). `false` = unknown name, no
26
+ * adapter, or no server. Never throws.
27
+ */
28
+ export declare function cacheL2Count(name: string): boolean
29
+
30
+ /**
31
+ * A broadcast invalidation another process published (worker 0's subscriber, cache-adapter R10):
32
+ * tier 1 + the floor at `seq`. Never re-published (L3). Same args/result as `cache_invalidate`.
33
+ */
34
+ export declare function cacheReplay(args: NapiInvalidateArgs, seq?: number | undefined | null): NapiInvalidateResult
35
+
21
36
  /** `/_brust/cache/stats` JSON (snake_case keys, as the server serialises it). */
22
37
  export declare function cacheStats(): string
23
38
 
@@ -43,10 +58,14 @@ export declare function compileTree(path: string, root: string, runtimeImport: s
43
58
  /** The bound address as `host:port` (port 0 resolves here). */
44
59
  export declare function localAddr(): string
45
60
 
46
- /** M3-F A3 consumer `{ prefix?, maxBodyBytes? }` (defaults `/_brust/action`, 262144). Present = actions on. */
61
+ /** M3-F A3 consumer `{ prefix?, maxBodyBytes?, maxResponseBytes? }` (defaults `/_brust/action`, 1 MiB, 8 MiB). Present = actions on. */
47
62
  export interface NapiActionsOptions {
48
63
  prefix?: string
49
64
  maxBodyBytes?: number
65
+ /** F82: cap on an action response body (default 8388608). */
66
+ maxResponseBytes?: number
67
+ /** `"reject"` (default) or `"allow"` (F87): cross-site mutating action requests. */
68
+ crossSite?: string
50
69
  }
51
70
 
52
71
  /**
@@ -83,6 +102,17 @@ export interface NapiInvalidateResult {
83
102
  jobRemoved: number
84
103
  }
85
104
 
105
+ /** The cache adapter (`[cache]`, cache-adapter lane A); built by `brust start` from `manifest.cache`. */
106
+ export interface NapiL2Options {
107
+ adapter: string
108
+ /** The `store.get` budget; absent = 50. */
109
+ getTimeoutMs?: number
110
+ /** A bigger rendered body is not written; absent = 1 048 576. */
111
+ maxBodyBytes?: number
112
+ namespace: string
113
+ buildId: string
114
+ }
115
+
86
116
  /**
87
117
  * M3-P P6: plan the calling worker's in-flight loader call for `slot` from the `len` bytes it
88
118
  * just wrote there. Returns the misses' `JobsRequest` JSON, `""` when every job hit, or `"!"`
@@ -91,6 +121,13 @@ export interface NapiInvalidateResult {
91
121
  */
92
122
  export declare function planJobs(slot: number, len: number): string
93
123
 
124
+ /**
125
+ * F82: hand Rust the response body of the calling worker's in-flight `fetch` call for `slot`
126
+ * (too large for the SAB slot). `false` = declined (over `max_response_bytes`, not in a `fetch`
127
+ * call, already put, nothing bound). Sync, on the worker's JS thread; never throws.
128
+ */
129
+ export declare function putFetchReply(slot: number, body: Uint8Array): boolean
130
+
94
131
  /**
95
132
  * Register the calling worker with the current server. `buf` is a view of
96
133
  * the worker's SharedArrayBuffer, which must outlive the process's use of
@@ -128,6 +165,8 @@ export interface StartOptions {
128
165
  cors?: NapiCorsOptions
129
166
  /** The actions subtree (M3-F); absent = no actions (byte-identical server). */
130
167
  actions?: NapiActionsOptions
168
+ /** The cache adapter; absent = none (byte-identical server). */
169
+ l2?: NapiL2Options
131
170
  }
132
171
 
133
172
  /**
@@ -137,6 +176,13 @@ export interface StartOptions {
137
176
  */
138
177
  export declare function startServer(opts: StartOptions): void
139
178
 
179
+ /**
180
+ * F82: the heap request body of the calling worker's in-flight `fetch` call for `slot`, once.
181
+ * `None` when there is none, nothing is bound, or the binding is ambiguous. Sync, on the
182
+ * worker's JS thread; never throws.
183
+ */
184
+ export declare function takeFetchBody(slot: number): Uint8Array | null
185
+
140
186
  /**
141
187
  * Resolves once `workers` workers registered with the current server;
142
188
  * rejects after `timeout_ms` (the caller decides the exit policy).
package/native/index.js CHANGED
@@ -89,8 +89,8 @@ function requireNative() {
89
89
  try {
90
90
  const binding = require('@brust/native-android-arm64')
91
91
  const bindingPackageVersion = require('@brust/native-android-arm64/package.json').version
92
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
93
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
92
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
93
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
94
94
  }
95
95
  return binding
96
96
  } catch (e) {
@@ -105,8 +105,8 @@ function requireNative() {
105
105
  try {
106
106
  const binding = require('@brust/native-android-arm-eabi')
107
107
  const bindingPackageVersion = require('@brust/native-android-arm-eabi/package.json').version
108
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
109
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
108
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
109
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
110
110
  }
111
111
  return binding
112
112
  } catch (e) {
@@ -126,8 +126,8 @@ function requireNative() {
126
126
  try {
127
127
  const binding = require('@brust/native-win32-x64-gnu')
128
128
  const bindingPackageVersion = require('@brust/native-win32-x64-gnu/package.json').version
129
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
130
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
129
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
130
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
131
131
  }
132
132
  return binding
133
133
  } catch (e) {
@@ -142,8 +142,8 @@ function requireNative() {
142
142
  try {
143
143
  const binding = require('@brust/native-win32-x64-msvc')
144
144
  const bindingPackageVersion = require('@brust/native-win32-x64-msvc/package.json').version
145
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
146
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
145
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
146
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
147
147
  }
148
148
  return binding
149
149
  } catch (e) {
@@ -159,8 +159,8 @@ function requireNative() {
159
159
  try {
160
160
  const binding = require('@brust/native-win32-ia32-msvc')
161
161
  const bindingPackageVersion = require('@brust/native-win32-ia32-msvc/package.json').version
162
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
163
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
162
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
163
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
164
164
  }
165
165
  return binding
166
166
  } catch (e) {
@@ -175,8 +175,8 @@ function requireNative() {
175
175
  try {
176
176
  const binding = require('@brust/native-win32-arm64-msvc')
177
177
  const bindingPackageVersion = require('@brust/native-win32-arm64-msvc/package.json').version
178
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
179
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
178
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
179
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
180
180
  }
181
181
  return binding
182
182
  } catch (e) {
@@ -194,8 +194,8 @@ function requireNative() {
194
194
  try {
195
195
  const binding = require('@brust/native-darwin-universal')
196
196
  const bindingPackageVersion = require('@brust/native-darwin-universal/package.json').version
197
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
198
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
197
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
198
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
199
199
  }
200
200
  return binding
201
201
  } catch (e) {
@@ -210,8 +210,8 @@ function requireNative() {
210
210
  try {
211
211
  const binding = require('@brust/native-darwin-x64')
212
212
  const bindingPackageVersion = require('@brust/native-darwin-x64/package.json').version
213
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
214
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
213
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
214
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
215
215
  }
216
216
  return binding
217
217
  } catch (e) {
@@ -226,8 +226,8 @@ function requireNative() {
226
226
  try {
227
227
  const binding = require('@brust/native-darwin-arm64')
228
228
  const bindingPackageVersion = require('@brust/native-darwin-arm64/package.json').version
229
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
230
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
229
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
230
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
231
231
  }
232
232
  return binding
233
233
  } catch (e) {
@@ -246,8 +246,8 @@ function requireNative() {
246
246
  try {
247
247
  const binding = require('@brust/native-freebsd-x64')
248
248
  const bindingPackageVersion = require('@brust/native-freebsd-x64/package.json').version
249
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
250
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
249
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
250
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
251
251
  }
252
252
  return binding
253
253
  } catch (e) {
@@ -262,8 +262,8 @@ function requireNative() {
262
262
  try {
263
263
  const binding = require('@brust/native-freebsd-arm64')
264
264
  const bindingPackageVersion = require('@brust/native-freebsd-arm64/package.json').version
265
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
266
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
265
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
266
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
267
267
  }
268
268
  return binding
269
269
  } catch (e) {
@@ -283,8 +283,8 @@ function requireNative() {
283
283
  try {
284
284
  const binding = require('@brust/native-linux-x64-musl')
285
285
  const bindingPackageVersion = require('@brust/native-linux-x64-musl/package.json').version
286
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
287
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
286
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
287
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
288
288
  }
289
289
  return binding
290
290
  } catch (e) {
@@ -299,8 +299,8 @@ function requireNative() {
299
299
  try {
300
300
  const binding = require('@brust/native-linux-x64-gnu')
301
301
  const bindingPackageVersion = require('@brust/native-linux-x64-gnu/package.json').version
302
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
303
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
302
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
303
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
304
304
  }
305
305
  return binding
306
306
  } catch (e) {
@@ -317,8 +317,8 @@ function requireNative() {
317
317
  try {
318
318
  const binding = require('@brust/native-linux-arm64-musl')
319
319
  const bindingPackageVersion = require('@brust/native-linux-arm64-musl/package.json').version
320
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
321
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
320
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
321
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
322
322
  }
323
323
  return binding
324
324
  } catch (e) {
@@ -333,8 +333,8 @@ function requireNative() {
333
333
  try {
334
334
  const binding = require('@brust/native-linux-arm64-gnu')
335
335
  const bindingPackageVersion = require('@brust/native-linux-arm64-gnu/package.json').version
336
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
337
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
336
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
337
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
338
338
  }
339
339
  return binding
340
340
  } catch (e) {
@@ -351,8 +351,8 @@ function requireNative() {
351
351
  try {
352
352
  const binding = require('@brust/native-linux-arm-musleabihf')
353
353
  const bindingPackageVersion = require('@brust/native-linux-arm-musleabihf/package.json').version
354
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
355
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
354
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
355
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
356
356
  }
357
357
  return binding
358
358
  } catch (e) {
@@ -367,8 +367,8 @@ function requireNative() {
367
367
  try {
368
368
  const binding = require('@brust/native-linux-arm-gnueabihf')
369
369
  const bindingPackageVersion = require('@brust/native-linux-arm-gnueabihf/package.json').version
370
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
371
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
370
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
371
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
372
372
  }
373
373
  return binding
374
374
  } catch (e) {
@@ -385,8 +385,8 @@ function requireNative() {
385
385
  try {
386
386
  const binding = require('@brust/native-linux-loong64-musl')
387
387
  const bindingPackageVersion = require('@brust/native-linux-loong64-musl/package.json').version
388
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
389
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
388
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
389
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
390
390
  }
391
391
  return binding
392
392
  } catch (e) {
@@ -401,8 +401,8 @@ function requireNative() {
401
401
  try {
402
402
  const binding = require('@brust/native-linux-loong64-gnu')
403
403
  const bindingPackageVersion = require('@brust/native-linux-loong64-gnu/package.json').version
404
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
405
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
404
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
405
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
406
406
  }
407
407
  return binding
408
408
  } catch (e) {
@@ -419,8 +419,8 @@ function requireNative() {
419
419
  try {
420
420
  const binding = require('@brust/native-linux-riscv64-musl')
421
421
  const bindingPackageVersion = require('@brust/native-linux-riscv64-musl/package.json').version
422
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
423
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
422
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
423
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
424
424
  }
425
425
  return binding
426
426
  } catch (e) {
@@ -435,8 +435,8 @@ function requireNative() {
435
435
  try {
436
436
  const binding = require('@brust/native-linux-riscv64-gnu')
437
437
  const bindingPackageVersion = require('@brust/native-linux-riscv64-gnu/package.json').version
438
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
439
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
438
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
439
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
440
440
  }
441
441
  return binding
442
442
  } catch (e) {
@@ -452,8 +452,8 @@ function requireNative() {
452
452
  try {
453
453
  const binding = require('@brust/native-linux-ppc64-gnu')
454
454
  const bindingPackageVersion = require('@brust/native-linux-ppc64-gnu/package.json').version
455
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
456
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
455
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
456
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
457
457
  }
458
458
  return binding
459
459
  } catch (e) {
@@ -468,8 +468,8 @@ function requireNative() {
468
468
  try {
469
469
  const binding = require('@brust/native-linux-s390x-gnu')
470
470
  const bindingPackageVersion = require('@brust/native-linux-s390x-gnu/package.json').version
471
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
472
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
471
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
472
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
473
473
  }
474
474
  return binding
475
475
  } catch (e) {
@@ -488,8 +488,8 @@ function requireNative() {
488
488
  try {
489
489
  const binding = require('@brust/native-openharmony-arm64')
490
490
  const bindingPackageVersion = require('@brust/native-openharmony-arm64/package.json').version
491
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
492
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
491
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
492
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
493
493
  }
494
494
  return binding
495
495
  } catch (e) {
@@ -504,8 +504,8 @@ function requireNative() {
504
504
  try {
505
505
  const binding = require('@brust/native-openharmony-x64')
506
506
  const bindingPackageVersion = require('@brust/native-openharmony-x64/package.json').version
507
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
508
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
507
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
508
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
509
509
  }
510
510
  return binding
511
511
  } catch (e) {
@@ -520,8 +520,8 @@ function requireNative() {
520
520
  try {
521
521
  const binding = require('@brust/native-openharmony-arm')
522
522
  const bindingPackageVersion = require('@brust/native-openharmony-arm/package.json').version
523
- if (bindingPackageVersion !== '2.0.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
524
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
523
+ if (bindingPackageVersion !== '2.0.0-alpha.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
524
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
525
525
  }
526
526
  return binding
527
527
  } catch (e) {
@@ -661,8 +661,8 @@ if (!nativeBinding || forceWasi) {
661
661
  if (!candidateFailed) {
662
662
  if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
663
663
  const bindingPackageVersion = require('@brust/native-wasm32-wasi/package.json').version
664
- if (bindingPackageVersion !== '2.0.0-alpha.1') {
665
- throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
664
+ if (bindingPackageVersion !== '2.0.0-alpha.3') {
665
+ throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
666
666
  }
667
667
  }
668
668
  wasiBinding = require('@brust/native-wasm32-wasi')
@@ -779,11 +779,16 @@ function __napiStampBindingTarget(exportsObject, target) {
779
779
  module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
780
780
  module.exports = nativeBinding
781
781
  module.exports.beginDrain = nativeBinding.beginDrain
782
+ module.exports.cacheClear = nativeBinding.cacheClear
782
783
  module.exports.cacheInvalidate = nativeBinding.cacheInvalidate
784
+ module.exports.cacheL2Count = nativeBinding.cacheL2Count
785
+ module.exports.cacheReplay = nativeBinding.cacheReplay
783
786
  module.exports.cacheStats = nativeBinding.cacheStats
784
787
  module.exports.compileTree = nativeBinding.compileTree
785
788
  module.exports.localAddr = nativeBinding.localAddr
786
789
  module.exports.planJobs = nativeBinding.planJobs
790
+ module.exports.putFetchReply = nativeBinding.putFetchReply
787
791
  module.exports.registerWorker = nativeBinding.registerWorker
788
792
  module.exports.startServer = nativeBinding.startServer
793
+ module.exports.takeFetchBody = nativeBinding.takeFetchBody
789
794
  module.exports.untilReady = nativeBinding.untilReady
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brust/core",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "brust v2 — React components compiled to Rust-rendered templates",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -13,11 +13,16 @@
13
13
  },
14
14
  "exports": {
15
15
  ".": {
16
+ "workerd": "./src/cf.ts",
16
17
  "browser": "./src/browser.ts",
17
18
  "default": "./src/index.ts"
18
19
  },
19
20
  "./routes": "./src/routes.ts",
20
21
  "./server": "./src/server.ts",
22
+ "./server-handlers": "./src/server-handlers.ts",
23
+ "./server-handlers/actions": "./src/actions/load.ts",
24
+ "./cache-adapter": "./src/cache-adapter/index.ts",
25
+ "./cache-adapter/conformance": "./src/cache-adapter/conformance.ts",
21
26
  "./store": "./src/store/index.ts",
22
27
  "./store/react": "./src/store/react.ts",
23
28
  "./elysia": "./src/actions/elysia.ts",
@@ -44,7 +49,7 @@
44
49
  ]
45
50
  },
46
51
  "dependencies": {
47
- "@brust/runtime-dom": "2.0.0-alpha.1"
52
+ "@brust/runtime-dom": "2.0.0-alpha.3"
48
53
  },
49
54
  "peerDependencies": {
50
55
  "react": "^19.0.0",
@@ -81,11 +86,12 @@
81
86
  "access": "public"
82
87
  },
83
88
  "optionalDependencies": {
84
- "@brust/native-darwin-x64": "2.0.0-alpha.1",
85
- "@brust/native-darwin-arm64": "2.0.0-alpha.1",
86
- "@brust/native-linux-x64-gnu": "2.0.0-alpha.1",
87
- "@brust/native-linux-arm64-gnu": "2.0.0-alpha.1",
88
- "@brust/native-linux-x64-musl": "2.0.0-alpha.1",
89
- "@brust/native-linux-arm64-musl": "2.0.0-alpha.1"
89
+ "@brust/native-darwin-x64": "2.0.0-alpha.3",
90
+ "@brust/native-darwin-arm64": "2.0.0-alpha.3",
91
+ "@brust/native-linux-x64-gnu": "2.0.0-alpha.3",
92
+ "@brust/native-linux-arm64-gnu": "2.0.0-alpha.3",
93
+ "@brust/native-linux-x64-musl": "2.0.0-alpha.3",
94
+ "@brust/native-linux-arm64-musl": "2.0.0-alpha.3",
95
+ "@brust/core-cf": "2.0.0-alpha.3"
90
96
  }
91
97
  }
@@ -1,6 +1,8 @@
1
1
  // Browser-safe (the client imports it): no elysia import.
2
2
  export const DEFAULT_ACTION_PREFIX = '/_brust/action'
3
- export const DEFAULT_MAX_BODY_BYTES = 262_144
3
+ export const DEFAULT_MAX_BODY_BYTES = 1_048_576
4
+ export const DEFAULT_MAX_RESPONSE_BYTES = 8_388_608
5
+ export const MAX_ACTION_BYTES = 67_108_864
4
6
  const SEG = /^[A-Za-z0-9._~-]+$/
5
7
 
6
8
  /** Why `p` cannot be the actions prefix, or null. Segment-safe like the server's match. */
@@ -1,6 +1,7 @@
1
1
  // The worker side of the `fetch` call kind (design E4/E5, contracts A1/A2). Rust forwards the actions prefix subtree
2
2
  // here; the app registered with `setActionsApp` (Elysia 2 via brust() — m3f-actions-elysia) answers a web Request
3
3
  // with a web Response, framed into this worker's SAB slot. No Elysia import: the app is anything with `fetch`.
4
+ import { putFetchReply, takeFetchBody } from './native'
4
5
  import type { LoaderReq } from './routes'
5
6
  import { runInStoreContext } from './store/server-context'
6
7
 
@@ -9,6 +10,7 @@ export interface ActionsManifest {
9
10
  entry: string
10
11
  prefix: string
11
12
  maxBodyBytes: number
13
+ maxResponseBytes?: number
12
14
  }
13
15
  /** What the worker drives: an Elysia 2 app (`app.fetch`, web-standard), or anything with that shape. */
14
16
  export interface ActionsApp {
@@ -20,13 +22,30 @@ export interface FetchRequest {
20
22
  method: string
21
23
  url: string
22
24
  headers: [string, string][]
23
- body: { text: string } | { b64: string } | null
25
+ /** `{heap: n}` (F82): more than 262144 bytes, fetched with `takeFetchBody(slot)`. */
26
+ body: { text: string } | { b64: string } | { heap: number } | null
24
27
  req: LoaderReq
25
28
  }
26
- /** A2 meta: exactly these two keys (never a store). */
29
+ /** A2 meta: `status`, `headers`, and (F82) `heap` — the byte length of a response body that crossed by
30
+ * `putFetchReply` instead of the slot (the slot body is then empty). Never a store. */
27
31
  export interface FetchMeta {
28
32
  status: number
29
33
  headers: [string, string][]
34
+ heap?: number
35
+ }
36
+
37
+ /** F82: the worker→Rust heap channel for the in-flight `fetch` call of a slot. The default is the napi addon,
38
+ * loaded lazily (so a fetch that never needs it never touches the binding). */
39
+ export interface HeapIo {
40
+ takeBody(slot: number): Uint8Array | null
41
+ putReply(slot: number, body: Uint8Array): boolean
42
+ }
43
+ const nativeHeapIo: HeapIo = { takeBody: (slot) => takeFetchBody(slot), putReply: (slot, body) => putFetchReply(slot, body) }
44
+
45
+ let maxResponseBytes = 8_388_608
46
+ /** `startWorker` sets the manifest's `actions.maxResponseBytes` (R5). Default 8388608. */
47
+ export function setActionsLimits(l: { maxResponseBytes: number }): void {
48
+ maxResponseBytes = l.maxResponseBytes
30
49
  }
31
50
 
32
51
  let app: ActionsApp | null = null
@@ -49,21 +68,22 @@ const TEXT_PLAIN: [string, string][] = [['content-type', 'text/plain; charset=ut
49
68
 
50
69
  /** A1 → web Request (R8 origin: `http://<host>` when the host pair is sane, else `localhost`). Bytes, never a
51
70
  * string body, so no content-type is invented. GET/HEAD never carry a body (R4; `new Request` forbids one). */
52
- export function toRequest(r: FetchRequest): Request {
71
+ export function toRequest(r: FetchRequest, heapBody?: Uint8Array): Request {
53
72
  const host = r.headers.find(([k]) => k === 'host')?.[1]
54
73
  const origin = `http://${host && HOST.test(host) ? host : 'localhost'}`
55
74
  const bodyless = r.method === 'GET' || r.method === 'HEAD'
56
- const body = bodyless || !r.body ? undefined : 'text' in r.body ? enc.encode(r.body.text) : Buffer.from(r.body.b64, 'base64')
75
+ const b = r.body
76
+ const body = bodyless || !b ? undefined : 'heap' in b ? (heapBody as BodyInit | undefined) : 'text' in b ? enc.encode(b.text) : Buffer.from(b.b64, 'base64')
57
77
  return new Request(origin + r.url, { method: r.method, headers: r.headers, body })
58
78
  }
59
79
 
60
80
  /** A2 writer at `slot`'s sub-region `[slot*sub, slot*sub+sub)`, `sub = floor(view.byteLength / slots)`:
61
81
  * `[u32 LE meta_len][meta JSON][body]`; returns the byte length. A frame that does not fit becomes R10's 500
62
82
  * (always fits a real slot); 0 when not even that fits (Rust: BadResponse → 500). */
63
- export function writeFramed(view: Uint8Array, slot: number, slots: number, status: number, headers: [string, string][], body: Uint8Array): number {
83
+ export function writeFramed(view: Uint8Array, slot: number, slots: number, status: number, headers: [string, string][], body: Uint8Array, heap?: number): number {
64
84
  const sub = Math.floor(view.byteLength / Math.max(1, slots))
65
85
  const dst = view.subarray(slot * sub, slot * sub + sub)
66
- const meta = enc.encode(JSON.stringify({ status, headers } satisfies FetchMeta))
86
+ const meta = enc.encode(JSON.stringify((heap === undefined ? { status, headers } : { status, headers, heap }) satisfies FetchMeta))
67
87
  const total = 4 + meta.length + body.length
68
88
  if (total <= sub) return put(dst, meta, body)
69
89
  console.error(`[brust] action response ${total} bytes exceeds the ${sub}-byte slot (F82) — answered 500`)
@@ -92,23 +112,60 @@ export function readFramed(view: Uint8Array, slot: number, slots: number, len: n
92
112
 
93
113
  const fail = (view: Uint8Array, slot: number, slots: number, msg: string) => writeFramed(view, slot, slots, 500, TEXT_PLAIN, enc.encode(msg))
94
114
 
95
- /** The `fetch` call (makeDispatch). Never rejects, never writes JSON: every outcome is a frame. */
96
- export async function runFetch(requestJson: string, view: Uint8Array, slot: number, slots: number): Promise<number> {
115
+ /** The store-scoped core shared by `runFetch` and `fetchInScope`: R1/E5 — one store scope around the handler AND the
116
+ * body read (a lazy body may still touch stores); set-cookie values kept apart. */
117
+ export async function fetchParts(a: ActionsApp, req: Request): Promise<{ status: number; pairs: [string, string][]; body: Uint8Array }> {
118
+ return runInStoreContext(async () => {
119
+ const res = await a.fetch(req)
120
+ const pairs: [string, string][] = []
121
+ res.headers.forEach((v, k) => {
122
+ if (k !== 'set-cookie') pairs.push([k, v])
123
+ })
124
+ for (const c of res.headers.getSetCookie()) pairs.push(['set-cookie', c])
125
+ return { status: res.status, pairs, body: new Uint8Array(await res.arrayBuffer()) }
126
+ })
127
+ }
128
+
129
+ /** Host-agnostic entry (Cloudflare `action(req)`): the same scope and framing-free parts as `runFetch`, as a Response. */
130
+ export async function fetchInScope(a: ActionsApp, req: Request): Promise<Response> {
131
+ const { status, pairs, body } = await fetchParts(a, req)
132
+ const headers = new Headers()
133
+ for (const [k, v] of pairs) headers.append(k, v)
134
+ return new Response([101, 204, 205, 304].includes(status) ? null : (body as BodyInit), { status, headers })
135
+ }
136
+
137
+ /** The `action` export of a worker whose app has no `[actions]`. */
138
+ export const noActions = async (_: Request): Promise<Response> =>
139
+ new Response('brust: actions are not configured in this worker', { status: 500, headers: { 'content-type': 'text/plain; charset=utf-8' } })
140
+
141
+ /** The `fetch` call (makeDispatch). Never rejects, never writes JSON: every outcome is a frame. A body of
142
+ * more than 262144 bytes arrives by `io.takeBody` (A1 `{heap}`); a response that does not fit the slot leaves
143
+ * by `io.putReply` with only status/headers/`heap` in the slot (F82), unless it exceeds `max_response_bytes`. */
144
+ export async function runFetch(requestJson: string, view: Uint8Array, slot: number, slots: number, io: HeapIo = nativeHeapIo): Promise<number> {
97
145
  const a = app
98
146
  if (!a) return fail(view, slot, slots, 'brust: actions are not configured in this worker')
99
147
  try {
100
- const req = toRequest(JSON.parse(requestJson) as FetchRequest)
148
+ const fr = JSON.parse(requestJson) as FetchRequest
149
+ let heapBody: Uint8Array | undefined
150
+ if (fr.body && 'heap' in fr.body) {
151
+ const got = io.takeBody(slot)
152
+ if (!got || got.length !== fr.body.heap) throw new Error(`heap request body ${got ? `${got.length} != ${fr.body.heap}` : 'missing'} bytes (F82)`)
153
+ heapBody = got
154
+ }
155
+ const req = toRequest(fr, heapBody)
101
156
  // R1/E5: one store scope around the handler AND the body read (a lazy body may still touch stores).
102
- const out = await runInStoreContext(async () => {
103
- const res = await a.fetch(req)
104
- const pairs: [string, string][] = []
105
- res.headers.forEach((v, k) => {
106
- if (k !== 'set-cookie') pairs.push([k, v])
107
- })
108
- for (const c of res.headers.getSetCookie()) pairs.push(['set-cookie', c])
109
- return { status: res.status, pairs, body: new Uint8Array(await res.arrayBuffer()) }
110
- })
111
- return writeFramed(view, slot, slots, out.status, out.pairs, out.body)
157
+ const out = await fetchParts(a, req)
158
+ const sub = Math.floor(view.byteLength / Math.max(1, slots))
159
+ const metaLen = (m: FetchMeta) => enc.encode(JSON.stringify(m)).length
160
+ if (4 + metaLen({ status: out.status, headers: out.pairs }) + out.body.length <= sub) return writeFramed(view, slot, slots, out.status, out.pairs, out.body)
161
+ if (out.body.length > maxResponseBytes) {
162
+ console.error(`[brust] action response body ${out.body.length} bytes exceeds max_response_bytes ${maxResponseBytes} — answered 500`)
163
+ return writeFramed(view, slot, slots, 500, TEXT_PLAIN, enc.encode(`brust: action response exceeds ${maxResponseBytes} bytes`))
164
+ }
165
+ // The meta alone must fit; otherwise writeFramed's own 500 (R10) answers.
166
+ if (4 + metaLen({ status: out.status, headers: out.pairs, heap: out.body.length }) > sub) return writeFramed(view, slot, slots, out.status, out.pairs, out.body)
167
+ if (!io.putReply(slot, out.body)) throw new Error('heap reply declined by the server (F82)')
168
+ return writeFramed(view, slot, slots, out.status, out.pairs, new Uint8Array(0), out.body.length)
112
169
  } catch (e) {
113
170
  console.error(`[brust] action failed: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}`)
114
171
  return fail(view, slot, slots, 'brust: action failed')