@brust/core 2.0.0-alpha.1 → 2.0.0-alpha.2
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 +19 -1
- package/native/index.js +56 -54
- package/package.json +8 -8
- package/src/actions/prefix.ts +3 -1
- package/src/actions-bridge.ts +49 -10
- package/src/build/config.ts +21 -7
- package/src/build/index.ts +1 -1
- package/src/build/manifest.ts +3 -1
- package/src/native.ts +11 -1
- package/src/run.ts +2 -2
- package/src/worker.ts +4 -2
package/native/index.d.ts
CHANGED
|
@@ -43,10 +43,14 @@ export declare function compileTree(path: string, root: string, runtimeImport: s
|
|
|
43
43
|
/** The bound address as `host:port` (port 0 resolves here). */
|
|
44
44
|
export declare function localAddr(): string
|
|
45
45
|
|
|
46
|
-
/** M3-F A3 consumer `{ prefix?, maxBodyBytes? }` (defaults `/_brust/action`,
|
|
46
|
+
/** M3-F A3 consumer `{ prefix?, maxBodyBytes?, maxResponseBytes? }` (defaults `/_brust/action`, 1 MiB, 8 MiB). Present = actions on. */
|
|
47
47
|
export interface NapiActionsOptions {
|
|
48
48
|
prefix?: string
|
|
49
49
|
maxBodyBytes?: number
|
|
50
|
+
/** F82: cap on an action response body (default 8388608). */
|
|
51
|
+
maxResponseBytes?: number
|
|
52
|
+
/** `"reject"` (default) or `"allow"` (F87): cross-site mutating action requests. */
|
|
53
|
+
crossSite?: string
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/**
|
|
@@ -91,6 +95,13 @@ export interface NapiInvalidateResult {
|
|
|
91
95
|
*/
|
|
92
96
|
export declare function planJobs(slot: number, len: number): string
|
|
93
97
|
|
|
98
|
+
/**
|
|
99
|
+
* F82: hand Rust the response body of the calling worker's in-flight `fetch` call for `slot`
|
|
100
|
+
* (too large for the SAB slot). `false` = declined (over `max_response_bytes`, not in a `fetch`
|
|
101
|
+
* call, already put, nothing bound). Sync, on the worker's JS thread; never throws.
|
|
102
|
+
*/
|
|
103
|
+
export declare function putFetchReply(slot: number, body: Uint8Array): boolean
|
|
104
|
+
|
|
94
105
|
/**
|
|
95
106
|
* Register the calling worker with the current server. `buf` is a view of
|
|
96
107
|
* the worker's SharedArrayBuffer, which must outlive the process's use of
|
|
@@ -137,6 +148,13 @@ export interface StartOptions {
|
|
|
137
148
|
*/
|
|
138
149
|
export declare function startServer(opts: StartOptions): void
|
|
139
150
|
|
|
151
|
+
/**
|
|
152
|
+
* F82: the heap request body of the calling worker's in-flight `fetch` call for `slot`, once.
|
|
153
|
+
* `None` when there is none, nothing is bound, or the binding is ambiguous. Sync, on the
|
|
154
|
+
* worker's JS thread; never throws.
|
|
155
|
+
*/
|
|
156
|
+
export declare function takeFetchBody(slot: number): Uint8Array | null
|
|
157
|
+
|
|
140
158
|
/**
|
|
141
159
|
* Resolves once `workers` workers registered with the current server;
|
|
142
160
|
* 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.
|
|
93
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
92
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
109
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
108
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
130
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
129
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
146
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
145
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
163
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
162
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
179
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
178
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
198
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
197
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
214
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
213
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
230
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
229
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
250
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
249
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
266
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
265
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
287
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
286
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
303
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
302
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
321
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
320
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
337
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
336
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
355
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
354
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
371
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
370
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
389
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
388
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
405
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
404
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
423
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
422
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
439
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
438
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
456
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
455
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
472
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
471
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
492
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
491
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
508
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
507
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
524
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
523
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2' && 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.2 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.
|
|
665
|
-
throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.
|
|
664
|
+
if (bindingPackageVersion !== '2.0.0-alpha.2') {
|
|
665
|
+
throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
wasiBinding = require('@brust/native-wasm32-wasi')
|
|
@@ -784,6 +784,8 @@ module.exports.cacheStats = nativeBinding.cacheStats
|
|
|
784
784
|
module.exports.compileTree = nativeBinding.compileTree
|
|
785
785
|
module.exports.localAddr = nativeBinding.localAddr
|
|
786
786
|
module.exports.planJobs = nativeBinding.planJobs
|
|
787
|
+
module.exports.putFetchReply = nativeBinding.putFetchReply
|
|
787
788
|
module.exports.registerWorker = nativeBinding.registerWorker
|
|
788
789
|
module.exports.startServer = nativeBinding.startServer
|
|
790
|
+
module.exports.takeFetchBody = nativeBinding.takeFetchBody
|
|
789
791
|
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.
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
4
4
|
"description": "brust v2 — React components compiled to Rust-rendered templates",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@brust/runtime-dom": "2.0.0-alpha.
|
|
47
|
+
"@brust/runtime-dom": "2.0.0-alpha.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^19.0.0",
|
|
@@ -81,11 +81,11 @@
|
|
|
81
81
|
"access": "public"
|
|
82
82
|
},
|
|
83
83
|
"optionalDependencies": {
|
|
84
|
-
"@brust/native-darwin-x64": "2.0.0-alpha.
|
|
85
|
-
"@brust/native-darwin-arm64": "2.0.0-alpha.
|
|
86
|
-
"@brust/native-linux-x64-gnu": "2.0.0-alpha.
|
|
87
|
-
"@brust/native-linux-arm64-gnu": "2.0.0-alpha.
|
|
88
|
-
"@brust/native-linux-x64-musl": "2.0.0-alpha.
|
|
89
|
-
"@brust/native-linux-arm64-musl": "2.0.0-alpha.
|
|
84
|
+
"@brust/native-darwin-x64": "2.0.0-alpha.2",
|
|
85
|
+
"@brust/native-darwin-arm64": "2.0.0-alpha.2",
|
|
86
|
+
"@brust/native-linux-x64-gnu": "2.0.0-alpha.2",
|
|
87
|
+
"@brust/native-linux-arm64-gnu": "2.0.0-alpha.2",
|
|
88
|
+
"@brust/native-linux-x64-musl": "2.0.0-alpha.2",
|
|
89
|
+
"@brust/native-linux-arm64-musl": "2.0.0-alpha.2"
|
|
90
90
|
}
|
|
91
91
|
}
|
package/src/actions/prefix.ts
CHANGED
|
@@ -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 =
|
|
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. */
|
package/src/actions-bridge.ts
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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
|
|
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,12 +112,21 @@ 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
|
-
|
|
115
|
+
/** The `fetch` call (makeDispatch). Never rejects, never writes JSON: every outcome is a frame. A body of
|
|
116
|
+
* more than 262144 bytes arrives by `io.takeBody` (A1 `{heap}`); a response that does not fit the slot leaves
|
|
117
|
+
* by `io.putReply` with only status/headers/`heap` in the slot (F82), unless it exceeds `max_response_bytes`. */
|
|
118
|
+
export async function runFetch(requestJson: string, view: Uint8Array, slot: number, slots: number, io: HeapIo = nativeHeapIo): Promise<number> {
|
|
97
119
|
const a = app
|
|
98
120
|
if (!a) return fail(view, slot, slots, 'brust: actions are not configured in this worker')
|
|
99
121
|
try {
|
|
100
|
-
const
|
|
122
|
+
const fr = JSON.parse(requestJson) as FetchRequest
|
|
123
|
+
let heapBody: Uint8Array | undefined
|
|
124
|
+
if (fr.body && 'heap' in fr.body) {
|
|
125
|
+
const got = io.takeBody(slot)
|
|
126
|
+
if (!got || got.length !== fr.body.heap) throw new Error(`heap request body ${got ? `${got.length} != ${fr.body.heap}` : 'missing'} bytes (F82)`)
|
|
127
|
+
heapBody = got
|
|
128
|
+
}
|
|
129
|
+
const req = toRequest(fr, heapBody)
|
|
101
130
|
// R1/E5: one store scope around the handler AND the body read (a lazy body may still touch stores).
|
|
102
131
|
const out = await runInStoreContext(async () => {
|
|
103
132
|
const res = await a.fetch(req)
|
|
@@ -108,7 +137,17 @@ export async function runFetch(requestJson: string, view: Uint8Array, slot: numb
|
|
|
108
137
|
for (const c of res.headers.getSetCookie()) pairs.push(['set-cookie', c])
|
|
109
138
|
return { status: res.status, pairs, body: new Uint8Array(await res.arrayBuffer()) }
|
|
110
139
|
})
|
|
111
|
-
|
|
140
|
+
const sub = Math.floor(view.byteLength / Math.max(1, slots))
|
|
141
|
+
const metaLen = (m: FetchMeta) => enc.encode(JSON.stringify(m)).length
|
|
142
|
+
if (4 + metaLen({ status: out.status, headers: out.pairs }) + out.body.length <= sub) return writeFramed(view, slot, slots, out.status, out.pairs, out.body)
|
|
143
|
+
if (out.body.length > maxResponseBytes) {
|
|
144
|
+
console.error(`[brust] action response body ${out.body.length} bytes exceeds max_response_bytes ${maxResponseBytes} — answered 500`)
|
|
145
|
+
return writeFramed(view, slot, slots, 500, TEXT_PLAIN, enc.encode(`brust: action response exceeds ${maxResponseBytes} bytes`))
|
|
146
|
+
}
|
|
147
|
+
// The meta alone must fit; otherwise writeFramed's own 500 (R10) answers.
|
|
148
|
+
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)
|
|
149
|
+
if (!io.putReply(slot, out.body)) throw new Error('heap reply declined by the server (F82)')
|
|
150
|
+
return writeFramed(view, slot, slots, out.status, out.pairs, new Uint8Array(0), out.body.length)
|
|
112
151
|
} catch (e) {
|
|
113
152
|
console.error(`[brust] action failed: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}`)
|
|
114
153
|
return fail(view, slot, slots, 'brust: action failed')
|
package/src/build/config.ts
CHANGED
|
@@ -4,18 +4,20 @@
|
|
|
4
4
|
// `server_only` is the app config `serverOnly` of the compiler spec (§8.2): the compiler refuses
|
|
5
5
|
// such an import in client code, and every browser bundle refuses to include it.
|
|
6
6
|
import { join } from 'node:path'
|
|
7
|
-
import { DEFAULT_ACTION_PREFIX, DEFAULT_MAX_BODY_BYTES, prefixError } from '../actions/prefix'
|
|
7
|
+
import { DEFAULT_ACTION_PREFIX, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_RESPONSE_BYTES, MAX_ACTION_BYTES, prefixError } from '../actions/prefix'
|
|
8
8
|
import { BuildError } from './errors'
|
|
9
9
|
|
|
10
|
-
// [actions] (opt-in, ruling R6): present table => actions on.
|
|
10
|
+
// [actions] (opt-in, ruling R6): present table => actions on. Both byte caps cross napi as u32 (F82: 1..64 MiB / 256 KiB..64 MiB).
|
|
11
11
|
// [actions]
|
|
12
|
-
// entry = "actions.ts" prefix = "/_brust/action" max_body_bytes =
|
|
13
|
-
const
|
|
12
|
+
// entry = "actions.ts" prefix = "/_brust/action" max_body_bytes = 1048576 max_response_bytes = 8388608 cross_site = "reject" | "allow" (F87)
|
|
13
|
+
const MIN_RESPONSE_BYTES = 262_144
|
|
14
14
|
|
|
15
15
|
export interface ActionsBuildConfig {
|
|
16
16
|
entry: string
|
|
17
17
|
prefix: string
|
|
18
18
|
maxBodyBytes: number
|
|
19
|
+
maxResponseBytes: number
|
|
20
|
+
crossSite: 'reject' | 'allow'
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export interface BuildConfig {
|
|
@@ -41,11 +43,23 @@ function parseActions(file: string, raw: unknown): ActionsBuildConfig | null {
|
|
|
41
43
|
let maxBodyBytes = DEFAULT_MAX_BODY_BYTES
|
|
42
44
|
if (t.max_body_bytes !== undefined) {
|
|
43
45
|
const n = t.max_body_bytes
|
|
44
|
-
if (typeof n !== 'number' || !Number.isInteger(n) || n < 1 || n >
|
|
45
|
-
throw new BuildError('config', `${file}: actions.max_body_bytes must be an integer in 1..${
|
|
46
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n < 1 || n > MAX_ACTION_BYTES)
|
|
47
|
+
throw new BuildError('config', `${file}: actions.max_body_bytes must be an integer in 1..${MAX_ACTION_BYTES} (got ${String(n)})`)
|
|
46
48
|
maxBodyBytes = n
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
let maxResponseBytes = DEFAULT_MAX_RESPONSE_BYTES
|
|
51
|
+
if (t.max_response_bytes !== undefined) {
|
|
52
|
+
const n = t.max_response_bytes
|
|
53
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n < MIN_RESPONSE_BYTES || n > MAX_ACTION_BYTES)
|
|
54
|
+
throw new BuildError('config', `${file}: actions.max_response_bytes must be an integer in ${MIN_RESPONSE_BYTES}..${MAX_ACTION_BYTES} (got ${String(n)})`)
|
|
55
|
+
maxResponseBytes = n
|
|
56
|
+
}
|
|
57
|
+
let crossSite: 'reject' | 'allow' = 'reject'
|
|
58
|
+
if (t.cross_site !== undefined) {
|
|
59
|
+
if (t.cross_site !== 'reject' && t.cross_site !== 'allow') throw new BuildError('config', `${file}: actions.cross_site must be "reject" or "allow"`)
|
|
60
|
+
crossSite = t.cross_site
|
|
61
|
+
}
|
|
62
|
+
return { entry, prefix, maxBodyBytes, maxResponseBytes, crossSite }
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
const DEFAULT_ENTRY = 'actions.ts'
|
package/src/build/index.ts
CHANGED
|
@@ -175,7 +175,7 @@ async function buildInto(
|
|
|
175
175
|
await buildJobs(out, compiled, ctx.sourceOf, appRoot, storeModules(manifest))
|
|
176
176
|
manifest.actions =
|
|
177
177
|
o.actions && o.actionsEntry
|
|
178
|
-
? { entry: await buildActions(out, o.actionsEntry), prefix: o.actions.prefix, maxBodyBytes: o.actions.maxBodyBytes }
|
|
178
|
+
? { entry: await buildActions(out, o.actionsEntry), prefix: o.actions.prefix, maxBodyBytes: o.actions.maxBodyBytes, maxResponseBytes: o.actions.maxResponseBytes, crossSite: o.actions.crossSite }
|
|
179
179
|
: null
|
|
180
180
|
writeFileSync(join(out, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`)
|
|
181
181
|
writeFileSync(join(out, MARKER), 'generated by `brust build`: this directory is replaced on every build\n')
|
package/src/build/manifest.ts
CHANGED
|
@@ -51,11 +51,13 @@ export interface RouteRecord {
|
|
|
51
51
|
catch_all: boolean
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/** `manifest.actions` (A3): `entry` is relative to dist; `maxBodyBytes`
|
|
54
|
+
/** `manifest.actions` (A3): `entry` is relative to dist; `maxBodyBytes`/`maxResponseBytes` are camelCase by contract. */
|
|
55
55
|
export interface ActionsRecord {
|
|
56
56
|
entry: string
|
|
57
57
|
prefix: string
|
|
58
58
|
maxBodyBytes: number
|
|
59
|
+
maxResponseBytes: number
|
|
60
|
+
crossSite: 'reject' | 'allow'
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export interface ManifestJson {
|
package/src/native.ts
CHANGED
|
@@ -41,10 +41,14 @@ export interface CorsOptions {
|
|
|
41
41
|
credentials?: boolean
|
|
42
42
|
maxAgeSeconds?: number
|
|
43
43
|
}
|
|
44
|
-
/** napi `NapiActionsOptions`; defaults `/_brust/action`,
|
|
44
|
+
/** napi `NapiActionsOptions`; defaults `/_brust/action`, 1048576, 8388608. */
|
|
45
45
|
export interface ActionsOptions {
|
|
46
46
|
prefix?: string
|
|
47
47
|
maxBodyBytes?: number
|
|
48
|
+
/** F82: response body cap (bytes). Default 8388608. */
|
|
49
|
+
maxResponseBytes?: number
|
|
50
|
+
/** F87: cross-site mutating requests. Default `reject`. */
|
|
51
|
+
crossSite?: 'reject' | 'allow'
|
|
48
52
|
}
|
|
49
53
|
export type WorkerFn = (kind: 'loader' | 'jobs' | 'fetch', requestJson: string, slot: number) => Promise<number>
|
|
50
54
|
export interface NativeBinding {
|
|
@@ -57,6 +61,10 @@ export interface NativeBinding {
|
|
|
57
61
|
localAddr(): string
|
|
58
62
|
/** M3-P P6 — see crates/brust-napi/src/server.rs `plan_jobs`. Never throws. */
|
|
59
63
|
planJobs(slot: number, len: number): string
|
|
64
|
+
/** F82 — the heap request body of the in-flight `fetch` call, once; null if none. Never throws. */
|
|
65
|
+
takeFetchBody(slot: number): Uint8Array | null
|
|
66
|
+
/** F82 — hand Rust a response body too large for the slot; false = declined. Never throws. */
|
|
67
|
+
putFetchReply(slot: number, body: Uint8Array): boolean
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
let binding: NativeBinding | null = null
|
|
@@ -83,3 +91,5 @@ export const cacheInvalidate = (args: InvalidateArgs): InvalidateResult => nativ
|
|
|
83
91
|
export const cacheStats = (): string => native().cacheStats()
|
|
84
92
|
export const localAddr = (): string => native().localAddr()
|
|
85
93
|
export const planJobs = (slot: number, len: number): string => native().planJobs(slot, len)
|
|
94
|
+
export const takeFetchBody = (slot: number): Uint8Array | null => native().takeFetchBody(slot)
|
|
95
|
+
export const putFetchReply = (slot: number, body: Uint8Array): boolean => native().putFetchReply(slot, body)
|
package/src/run.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface RunOptions {
|
|
|
22
22
|
|
|
23
23
|
/** The manifest fields `run` needs (build/manifest.ts owns the full shape). */
|
|
24
24
|
export interface RunManifest {
|
|
25
|
-
actions?: { entry: string; prefix: string; maxBodyBytes: number } | null
|
|
25
|
+
actions?: { entry: string; prefix: string; maxBodyBytes: number; maxResponseBytes?: number; crossSite?: 'reject' | 'allow' } | null
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/** Pure: the napi `StartOptions`. No actions/cors → exactly the pre-actions keys. */
|
|
@@ -35,7 +35,7 @@ export function startOptions(cfg: BrustConfig, distDir: string, m: RunManifest,
|
|
|
35
35
|
callTimeoutMs: cfg.callTimeoutMs,
|
|
36
36
|
workerThreads: cfg.ioThreads,
|
|
37
37
|
generator: `brust/${version}`,
|
|
38
|
-
...(m.actions ? { actions: { prefix: m.actions.prefix, maxBodyBytes: m.actions.maxBodyBytes } } : {}),
|
|
38
|
+
...(m.actions ? { actions: { prefix: m.actions.prefix, maxBodyBytes: m.actions.maxBodyBytes, ...(m.actions.maxResponseBytes !== undefined ? { maxResponseBytes: m.actions.maxResponseBytes } : {}), ...(m.actions.crossSite ? { crossSite: m.actions.crossSite } : {}) } } : {}),
|
|
39
39
|
...(cfg.cors ? { cors: cfg.cors } : {}),
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/worker.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// handler NEVER rejects across the tsfn: every failure becomes `{error}` / `{id, error}`.
|
|
4
4
|
import { join, resolve } from 'node:path'
|
|
5
5
|
import { workerData } from 'node:worker_threads'
|
|
6
|
-
import { runFetch, setActionsApp } from './actions-bridge'
|
|
6
|
+
import { runFetch, setActionsApp, setActionsLimits } from './actions-bridge'
|
|
7
|
+
import { DEFAULT_MAX_RESPONSE_BYTES } from './actions/prefix'
|
|
7
8
|
import { planJobs, registerWorker } from './native'
|
|
8
9
|
import { installServerResolver, type StoreSnapshot } from './store/core-adapter'
|
|
9
10
|
import { collectSnapshot, getServerInstance, runInStoreContext, touchStores } from './store/server-context'
|
|
@@ -71,7 +72,7 @@ export interface ManifestLike {
|
|
|
71
72
|
>
|
|
72
73
|
jobs_module?: string
|
|
73
74
|
/** `brust build` (M3-F A3): the actions entry, relative to dist. Absent/null = no actions. */
|
|
74
|
-
actions?: { entry: string; prefix: string; maxBodyBytes: number } | null
|
|
75
|
+
actions?: { entry: string; prefix: string; maxBodyBytes: number; maxResponseBytes?: number } | null
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
// ---- SAB slot writer ----
|
|
@@ -327,6 +328,7 @@ export async function startWorker(opts: StartWorkerOptions = {}): Promise<number
|
|
|
327
328
|
// Lazy: elysia is an optional peer, so an app without [actions] must boot without it installed (R7).
|
|
328
329
|
const { loadActionsApp } = await import('./actions/load')
|
|
329
330
|
setActionsApp(await loadActionsApp(join(dist, manifest.actions.entry), manifest.actions.prefix))
|
|
331
|
+
setActionsLimits({ maxResponseBytes: manifest.actions.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES })
|
|
330
332
|
}
|
|
331
333
|
sab = opts.sab ?? new SharedArrayBuffer(SLOT_BYTES * slots)
|
|
332
334
|
view = new Uint8Array(sab)
|