brustjs 0.1.24-alpha → 0.1.25-alpha
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/example/pokedex/actions.ts +10 -2
- package/example/pokedex/app.css +30 -30
- package/example/pokedex/components/AddToTeamButton.tsx +1 -2
- package/example/pokedex/components/AppLayout.tsx +5 -1
- package/example/pokedex/components/ThemeToggle.tsx +51 -0
- package/example/pokedex/lib/loaders.ts +14 -6
- package/example/pokedex/lib/pokeapi.ts +7 -5
- package/example/pokedex/lib/types.ts +1 -0
- package/package.json +9 -8
- package/runtime/cookies.ts +61 -0
- package/runtime/define-actions.ts +34 -7
- package/runtime/index.js +52 -52
- package/runtime/index.ts +9 -0
- package/runtime/loader-cache.ts +42 -0
- package/runtime/request-context.ts +35 -0
- package/runtime/routes.ts +96 -25
- package/runtime/treaty.ts +47 -10
- package/runtime/treaty.type-test.ts +69 -0
- package/runtime/tsconfig.typecheck.json +15 -0
package/runtime/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('brustjs-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('brustjs-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '0.1.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
80
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('brustjs-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('brustjs-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '0.1.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
96
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('brustjs-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('brustjs-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '0.1.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
117
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('brustjs-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('brustjs-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '0.1.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
133
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('brustjs-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('brustjs-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.1.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
150
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('brustjs-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('brustjs-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '0.1.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
166
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('brustjs-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('brustjs-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '0.1.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
185
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('brustjs-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('brustjs-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '0.1.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
201
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('brustjs-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('brustjs-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '0.1.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
217
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('brustjs-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('brustjs-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.1.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
237
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('brustjs-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('brustjs-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '0.1.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
253
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('brustjs-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('brustjs-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '0.1.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
274
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('brustjs-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('brustjs-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '0.1.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
290
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('brustjs-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('brustjs-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '0.1.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
308
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('brustjs-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('brustjs-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '0.1.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
324
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('brustjs-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('brustjs-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '0.1.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
342
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('brustjs-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('brustjs-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '0.1.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
358
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('brustjs-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('brustjs-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '0.1.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
376
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('brustjs-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('brustjs-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '0.1.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
392
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('brustjs-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('brustjs-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.1.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
410
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('brustjs-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('brustjs-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '0.1.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
426
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('brustjs-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('brustjs-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.1.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
443
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('brustjs-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('brustjs-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.1.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
459
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('brustjs-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('brustjs-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.1.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
479
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('brustjs-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('brustjs-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.1.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
495
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('brustjs-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('brustjs-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '0.1.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
511
|
+
if (bindingPackageVersion !== '0.1.25-alpha' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.25-alpha but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
package/runtime/index.ts
CHANGED
|
@@ -781,8 +781,17 @@ export type { BrustPageProps, HeadEntry } from './islands/brust-page.tsx'
|
|
|
781
781
|
export { defineStore, signal, computed, effect, batch } from './store/index.ts'
|
|
782
782
|
export type { StoreHandle, Snapshot, Signal, Computed } from './store/index.ts'
|
|
783
783
|
|
|
784
|
+
// S2 — request-scoped loader cache/dedupe helpers. `runInRequestCache` (the
|
|
785
|
+
// scope opener) is owned by the runtime route handler and intentionally NOT
|
|
786
|
+
// exported.
|
|
787
|
+
export { dedupe, cachedFetch } from './loader-cache.ts'
|
|
788
|
+
|
|
784
789
|
export { buildIslands } from './islands/build.ts'
|
|
785
790
|
export type { IslandsBuildResult, BuildIslandsOptions } from './islands/build.ts'
|
|
786
791
|
|
|
787
792
|
export { cache } from './cache.ts'
|
|
788
793
|
export type { InvalidateArgs } from './cache.ts'
|
|
794
|
+
|
|
795
|
+
export { getRequestContext } from './request-context.ts'
|
|
796
|
+
export { cookies } from './cookies.ts'
|
|
797
|
+
export type { CookieOptions } from './cookies.ts'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
|
+
|
|
3
|
+
const cacheCtx = new AsyncLocalStorage<Map<string, Promise<unknown>>>()
|
|
4
|
+
|
|
5
|
+
export function runInRequestCache<T>(fn: () => T): T {
|
|
6
|
+
return cacheCtx.run(new Map(), fn)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Request-scoped memoize: share the in-flight promise + cache result for the
|
|
10
|
+
* scope's lifetime. Outside a scope → passthrough. Reject → guarded delete
|
|
11
|
+
* (identity-checked) so a stale catch can't evict a newer entry.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: the reject cleanup runs one microtask after rejection, so a caller that
|
|
14
|
+
* dedupes the SAME key within that gap receives the about-to-reject promise (and
|
|
15
|
+
* thus the rejection) — acceptable: the result is one shared failure, not a hang. */
|
|
16
|
+
export function dedupe<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
|
17
|
+
const map = cacheCtx.getStore()
|
|
18
|
+
if (!map) return fn()
|
|
19
|
+
const existing = map.get(key) as Promise<T> | undefined
|
|
20
|
+
if (existing) return existing
|
|
21
|
+
const p = fn()
|
|
22
|
+
map.set(key, p)
|
|
23
|
+
p.catch(() => {
|
|
24
|
+
if (map.get(key) === p) map.delete(key)
|
|
25
|
+
})
|
|
26
|
+
return p
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Idempotent (GET/HEAD) fetch deduped per request; non-idempotent → bypass.
|
|
30
|
+
* Returns a fresh clone every call (the stored Response is never exposed).
|
|
31
|
+
*
|
|
32
|
+
* NOTE: the cache key is `method + url` ONLY — it does NOT include `init`
|
|
33
|
+
* headers/body. Two `cachedFetch(sameUrl, {headers:…})` calls with DIFFERENT
|
|
34
|
+
* headers in one request share the FIRST call's response. Intended for plain
|
|
35
|
+
* idempotent GETs (the common loader case); if a caller varies `init` per call
|
|
36
|
+
* on the same URL, use `fetch` directly. */
|
|
37
|
+
export function cachedFetch(url: string, init?: RequestInit): Promise<Response> {
|
|
38
|
+
const method = (init?.method ?? 'GET').toUpperCase()
|
|
39
|
+
if (method !== 'GET' && method !== 'HEAD') return fetch(url, init)
|
|
40
|
+
// `dedupe` infers T = Response from the fetch thunk, so `r` is already Response.
|
|
41
|
+
return dedupe(`${method} ${url}`, () => fetch(url, init)).then((r) => r.clone())
|
|
42
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// This module imports a Node builtin (node:async_hooks) and therefore must NOT
|
|
2
|
+
// be reachable from browser/island bundles (brustjs/client) or from the
|
|
3
|
+
// isomorphic store entry (brustjs/store). It mirrors store/server-context.ts:
|
|
4
|
+
// the server pulls it in via routes.ts, where each request is wrapped in a
|
|
5
|
+
// per-request scope. cookies.ts reaches the active scope through __scope().
|
|
6
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
7
|
+
|
|
8
|
+
interface RequestScope {
|
|
9
|
+
ctx: Map<string, unknown>
|
|
10
|
+
reqCookies: Record<string, string>
|
|
11
|
+
setCookies: string[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const reqCtx = new AsyncLocalStorage<RequestScope>()
|
|
15
|
+
|
|
16
|
+
/** Open a per-request scope. `reqCookies` is the parsed incoming Cookie header
|
|
17
|
+
* (BrustRequest.cookies). Staged Set-Cookie strings accumulate in `setCookies`
|
|
18
|
+
* and are flushed by routes.ts onto the response headers. */
|
|
19
|
+
export function runInRequestScope<T>(reqCookies: Record<string, string>, fn: () => T): T {
|
|
20
|
+
return reqCtx.run({ ctx: new Map(), reqCookies, setCookies: [] }, fn)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Per-request scratch Map for apps building request-scoped state on top of the
|
|
24
|
+
* module-global store. Throws when called outside a request scope. */
|
|
25
|
+
export function getRequestContext(): Map<string, unknown> {
|
|
26
|
+
const s = reqCtx.getStore()
|
|
27
|
+
if (!s) throw new Error('getRequestContext() called outside a request scope')
|
|
28
|
+
return s.ctx
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Internal — the active scope (or undefined). Used by cookies.ts and the
|
|
32
|
+
* routes.ts flush. Not re-exported from the package entry. */
|
|
33
|
+
export function __scope(): RequestScope | undefined {
|
|
34
|
+
return reqCtx.getStore()
|
|
35
|
+
}
|
package/runtime/routes.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { Buffer } from 'node:buffer'
|
|
|
11
11
|
import * as native from './index.js'
|
|
12
12
|
import { renderBranchStreaming } from './render/stream.ts'
|
|
13
13
|
import { runInStoreContext, collectSnapshot } from './store/server-context.ts'
|
|
14
|
+
import { runInRequestCache } from './loader-cache.ts'
|
|
15
|
+
import { runInRequestScope, __scope } from './request-context.ts'
|
|
14
16
|
import {
|
|
15
17
|
loadIslandManifest,
|
|
16
18
|
resolveIslandContext,
|
|
@@ -23,6 +25,16 @@ import type { EndpointDef } from './define-actions.ts'
|
|
|
23
25
|
import { isRespondSentinel, makeRespond } from './define-actions.ts'
|
|
24
26
|
import { validate } from './standard-schema.ts'
|
|
25
27
|
|
|
28
|
+
// S2 + B3 — unified per-request scope. The request scope (B3 cookies/context) is
|
|
29
|
+
// the OUTERMOST layer, then the request-scoped loader cache/dedupe (S2: one Map
|
|
30
|
+
// per request for `cachedFetch`/`dedupe` across loaders AND render), then the
|
|
31
|
+
// store scope (per-request store instance). `reqCookies` is the parsed incoming
|
|
32
|
+
// Cookie header so a loader's `cookies.get` reads it and `cookies.set` stages
|
|
33
|
+
// onto this scope (flushed onto response headers via flushSetCookie).
|
|
34
|
+
function runInRequestContext<T>(reqCookies: Record<string, string>, fn: () => T): T {
|
|
35
|
+
return runInRequestScope(reqCookies, () => runInRequestCache(() => runInStoreContext(fn)))
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
// Sub-project J — island ISR cache, backed by the Rust-side store (shared across
|
|
27
39
|
// the worker pool) via NAPI. napi-rs maps snake→camel: island_cache_get →
|
|
28
40
|
// islandCacheGet, island_cache_set → islandCacheSet. `as any` avoids depending on
|
|
@@ -725,7 +737,9 @@ export function makeRenderer(
|
|
|
725
737
|
// child loaders (one Map per request — NOT one per loader). No
|
|
726
738
|
// snapshot is collected and no <script> is injected on native paths —
|
|
727
739
|
// Spec B owns native store delivery (hard non-goal here).
|
|
728
|
-
chainResult = await
|
|
740
|
+
chainResult = await runInRequestContext(call.req?.cookies ?? {}, () =>
|
|
741
|
+
runNativeChainLoaders(flat.chain, ctx),
|
|
742
|
+
)
|
|
729
743
|
} catch (err) {
|
|
730
744
|
console.error(`[brust] loader failed for native route ${flat.fullPath}:`, err)
|
|
731
745
|
// FAST LANE: native routes take dispatch_single_chunk (no chunk
|
|
@@ -756,6 +770,13 @@ export function makeRenderer(
|
|
|
756
770
|
data = chainResult.data
|
|
757
771
|
}
|
|
758
772
|
const json = JSON.stringify(data)
|
|
773
|
+
// napiRenderJinja has no headers param — any Set-Cookie staged by a
|
|
774
|
+
// native loader is dropped on this path. Dev-warn so it's not silent.
|
|
775
|
+
if ((__scope()?.setCookies.length ?? 0) > 0 && process.env.BRUST_DEV === '1') {
|
|
776
|
+
console.warn(
|
|
777
|
+
`[brust] cookies.set in a native loader for "${flat.nativeTemplate}" is dropped — native render has no headers; use a React route to write cookies`,
|
|
778
|
+
)
|
|
779
|
+
}
|
|
759
780
|
// Sub-project J — islands + components. If this template has an enriched
|
|
760
781
|
// islands manifest or a components manifest, merge per-island context vars
|
|
761
782
|
// (island_<id>_props, plus island_<id>_html for ssr entries) and per-component
|
|
@@ -842,7 +863,7 @@ export function makeRenderer(
|
|
|
842
863
|
// or render resolves the same per-request instance. Snapshot is collected
|
|
843
864
|
// after loaders (buildRenderElement resolved) — that's where Spec A stores
|
|
844
865
|
// are seeded — and threaded into the render for <script> injection.
|
|
845
|
-
return await
|
|
866
|
+
return await runInRequestContext(call.req?.cookies ?? {}, async () => {
|
|
846
867
|
let element: ReactNode
|
|
847
868
|
let errorBoundary: ComponentType<{ error: Error }>
|
|
848
869
|
try {
|
|
@@ -869,7 +890,7 @@ export function makeRenderer(
|
|
|
869
890
|
napi,
|
|
870
891
|
errorBoundary,
|
|
871
892
|
status: verdict.status,
|
|
872
|
-
headers: verdict.headers,
|
|
893
|
+
headers: flushSetCookie(verdict.headers),
|
|
873
894
|
routePath: flat.fullPath,
|
|
874
895
|
storeSnapshot,
|
|
875
896
|
})
|
|
@@ -1047,12 +1068,19 @@ async function navigationBranch(
|
|
|
1047
1068
|
// nav payload so the client can apply it to its live stores. Native nav
|
|
1048
1069
|
// collects no snapshot (Spec B owns native store delivery).
|
|
1049
1070
|
let store: Record<string, Record<string, unknown>> | null = null
|
|
1071
|
+
// Set-Cookie staged by a React nav loader, flushed onto the nav response
|
|
1072
|
+
// below. The request scope is opened per-path (inside runInRequestContext),
|
|
1073
|
+
// so capture the flushed headers inside that scope — the emit runs after the
|
|
1074
|
+
// scope has closed. Native nav (renderNativeRouteToHtml) opens its own scope
|
|
1075
|
+
// with no headers param, so staged cookies are dropped there (same as the
|
|
1076
|
+
// full-document native render path).
|
|
1077
|
+
let navHeaders: Record<string, string> | undefined
|
|
1050
1078
|
if (flat.nativeTemplate !== undefined) {
|
|
1051
1079
|
fullHtml = await renderNativeRouteToHtml(call, flat, view, encoder, workerId)
|
|
1052
1080
|
} else {
|
|
1053
1081
|
// Wrap loader run (inside buildRenderElement) + render in one store scope so
|
|
1054
1082
|
// store reads resolve the per-request instance; collect after render.
|
|
1055
|
-
fullHtml = await
|
|
1083
|
+
fullHtml = await runInRequestContext(call.req?.cookies ?? {}, async () => {
|
|
1056
1084
|
const element = await buildRenderElement(call as any, flat, getWorkerId)
|
|
1057
1085
|
if (!element) throw new Error('render setup failed')
|
|
1058
1086
|
// Use renderToPipeableStream + onAllReady so pages with <Suspense> emit
|
|
@@ -1061,6 +1089,7 @@ async function navigationBranch(
|
|
|
1061
1089
|
// would otherwise ship "loading…" and never recover.
|
|
1062
1090
|
const html = await renderToAwaitedString(element)
|
|
1063
1091
|
store = collectSnapshot()
|
|
1092
|
+
navHeaders = flushSetCookie(undefined)
|
|
1064
1093
|
return html
|
|
1065
1094
|
})
|
|
1066
1095
|
}
|
|
@@ -1087,6 +1116,7 @@ async function navigationBranch(
|
|
|
1087
1116
|
status: 200,
|
|
1088
1117
|
contentType: 'application/json; charset=utf-8',
|
|
1089
1118
|
body,
|
|
1119
|
+
headers: navHeaders,
|
|
1090
1120
|
})
|
|
1091
1121
|
} catch (err) {
|
|
1092
1122
|
console.error('[brust] navigation render failed:', err)
|
|
@@ -1122,7 +1152,7 @@ async function renderNativeRouteToHtml(
|
|
|
1122
1152
|
// Run the WHOLE route chain's loaders top-down and merge into ONE flat context
|
|
1123
1153
|
// (child keys win), mirroring the full-render branch. One per-request store
|
|
1124
1154
|
// scope wraps the entire loop (isolation only — no snapshot / no <script>).
|
|
1125
|
-
const chainResult = await
|
|
1155
|
+
const chainResult = await runInRequestContext(call.req?.cookies ?? {}, () =>
|
|
1126
1156
|
runNativeChainLoaders(flat.chain, {
|
|
1127
1157
|
params: call.params,
|
|
1128
1158
|
path: call.path,
|
|
@@ -1397,6 +1427,42 @@ function actionErrorResponse(err: ActionError): RouteResponse {
|
|
|
1397
1427
|
}
|
|
1398
1428
|
}
|
|
1399
1429
|
|
|
1430
|
+
/** Flush any cookies staged via `cookies.set`/`cookies.delete` in the active
|
|
1431
|
+
* request scope onto the response headers.
|
|
1432
|
+
*
|
|
1433
|
+
* The Rust response-header writer stores worker-response headers in a
|
|
1434
|
+
* CASE-SENSITIVE map (no lowercase dedup), so a mix of 'Set-Cookie' /
|
|
1435
|
+
* 'set-cookie' would emit two lines. We therefore use the SINGLE canonical key
|
|
1436
|
+
* 'set-cookie' (lowercase) for ALL cookie writes.
|
|
1437
|
+
*
|
|
1438
|
+
* RouteResponse.headers is Record<string,string>, so only ONE Set-Cookie per
|
|
1439
|
+
* response is representable. If multiple were staged, only the LAST is sent
|
|
1440
|
+
* (documented limitation; dev-warn). If the handler already set a 'set-cookie'
|
|
1441
|
+
* header explicitly (respond({ headers })), the explicit value WINS and staged
|
|
1442
|
+
* cookies are dropped (dev-warn on conflict). */
|
|
1443
|
+
function flushSetCookie(
|
|
1444
|
+
headers: Record<string, string> | undefined,
|
|
1445
|
+
): Record<string, string> | undefined {
|
|
1446
|
+
const staged = __scope()?.setCookies ?? []
|
|
1447
|
+
if (staged.length === 0) return headers
|
|
1448
|
+
if (headers && 'set-cookie' in headers) {
|
|
1449
|
+
if (process.env.BRUST_DEV === '1') {
|
|
1450
|
+
console.warn(
|
|
1451
|
+
'[brust] cookies.set conflicts with an explicit set-cookie header — explicit respond() wins',
|
|
1452
|
+
)
|
|
1453
|
+
}
|
|
1454
|
+
return headers
|
|
1455
|
+
}
|
|
1456
|
+
if (staged.length > 1 && process.env.BRUST_DEV === '1') {
|
|
1457
|
+
console.warn(
|
|
1458
|
+
`[brust] ${staged.length} cookies staged but only one Set-Cookie per response is supported — only the last is sent`,
|
|
1459
|
+
)
|
|
1460
|
+
}
|
|
1461
|
+
const out = { ...(headers ?? {}) }
|
|
1462
|
+
out['set-cookie'] = staged[staged.length - 1]
|
|
1463
|
+
return out
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1400
1466
|
export async function dispatchAction(
|
|
1401
1467
|
call: Extract<RouteCall, { kind: 'action' }>,
|
|
1402
1468
|
byId: Map<string, EndpointDef>,
|
|
@@ -1487,28 +1553,33 @@ export async function dispatchAction(
|
|
|
1487
1553
|
}
|
|
1488
1554
|
}
|
|
1489
1555
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1556
|
+
// Open a per-request scope (OUTER) so cookies.set during middleware/handler
|
|
1557
|
+
// stage onto this request, then flush the staged Set-Cookie onto the response
|
|
1558
|
+
// headers. The cache + store scopes wrap INNER — request-scope is outermost.
|
|
1559
|
+
return await runInRequestContext(call.req.cookies ?? {}, async () => {
|
|
1560
|
+
const chain = composeChain(call.req, def.middleware, terminal)
|
|
1561
|
+
let response: RouteResponse
|
|
1562
|
+
try {
|
|
1563
|
+
response = await chain()
|
|
1564
|
+
} catch (err) {
|
|
1565
|
+
if (isActionError(err)) {
|
|
1566
|
+
response = actionErrorResponse(err)
|
|
1567
|
+
} else {
|
|
1568
|
+
console.error('[brust] action middleware uncaught:', err)
|
|
1569
|
+
response = {
|
|
1570
|
+
status: 500,
|
|
1571
|
+
body: '{"error":{"message":"internal error"}}',
|
|
1572
|
+
contentType: 'application/json; charset=utf-8',
|
|
1573
|
+
}
|
|
1503
1574
|
}
|
|
1504
1575
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}
|
|
1576
|
+
return {
|
|
1577
|
+
status: response.status,
|
|
1578
|
+
body: response.body,
|
|
1579
|
+
contentType: response.contentType ?? 'application/json; charset=utf-8',
|
|
1580
|
+
headers: flushSetCookie(response.headers),
|
|
1581
|
+
}
|
|
1582
|
+
})
|
|
1512
1583
|
}
|
|
1513
1584
|
|
|
1514
1585
|
async function mcpBranchToResponse(
|