@bakery-framework/plugin-vue 2.0.0-rc.5 → 2.0.1
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/package.json +2 -2
- package/src/utils.ts +37 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakery-framework/plugin-vue",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Bakery vue plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bakery",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"vue": "^3.5.38"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@bakery-framework/core": "^2.0.
|
|
46
|
+
"@bakery-framework/core": "^2.0.1"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"bun": ">=1.4.0"
|
package/src/utils.ts
CHANGED
|
@@ -512,6 +512,39 @@ function writeServerModule(
|
|
|
512
512
|
return task
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
+
/**
|
|
516
|
+
* What a server block answers when it could not run: it failed to load, or
|
|
517
|
+
* it threw while running.
|
|
518
|
+
*
|
|
519
|
+
* **A block that declares a guard fails closed.** The generated wrapper runs
|
|
520
|
+
* the block's top-level statements and *then* calls `middleware`, so a throw
|
|
521
|
+
* anywhere above skips the guard completely, and a module that never loads
|
|
522
|
+
* has no wrapper to run at all. Returning `{}` then served the route: a
|
|
523
|
+
* `/admin/*` page answering 200 to an anonymous caller because a query threw.
|
|
524
|
+
* Not hypothetical, and not only the obvious causes: a database being down, a
|
|
525
|
+
* null deref, a typo, an import that does not resolve, or a top-level
|
|
526
|
+
* `const req` (the wrapper's own parameter) all reach it.
|
|
527
|
+
*
|
|
528
|
+
* Convention 2 names this shape exactly: a guard "returns the rejection, not
|
|
529
|
+
* `null`, on any indeterminate state". A guard that ceased to exist is the
|
|
530
|
+
* most indeterminate state there is.
|
|
531
|
+
*
|
|
532
|
+
* Only when a guard is declared. A data-only block renders the page with no
|
|
533
|
+
* data, which is the documented behavior and is a visible failure rather than
|
|
534
|
+
* a silent one: the page is obviously broken, and nothing was protecting it.
|
|
535
|
+
*
|
|
536
|
+
* The declaration is read from the source, not from the result, because there
|
|
537
|
+
* is no result: the module failed before its exports existed. That is the
|
|
538
|
+
* same static list `compileServerBlock` already builds to decide which
|
|
539
|
+
* exports are callable as actions.
|
|
540
|
+
*/
|
|
541
|
+
function failedBlockResponse(script: string): Response | Record<string, never> {
|
|
542
|
+
if (collectExportedFunctionNames(script).includes('middleware')) {
|
|
543
|
+
return new Response('Internal Server Error', { status: 500 })
|
|
544
|
+
}
|
|
545
|
+
return {}
|
|
546
|
+
}
|
|
547
|
+
|
|
515
548
|
export async function getServerResponse(options: ServerResponseOptions) {
|
|
516
549
|
const { script, id, lastMod, req, body, filePath, actionName, actionArgs } =
|
|
517
550
|
options
|
|
@@ -536,7 +569,9 @@ export async function getServerResponse(options: ServerResponseOptions) {
|
|
|
536
569
|
}`,
|
|
537
570
|
'error',
|
|
538
571
|
)
|
|
539
|
-
|
|
572
|
+
// The load path answered `{}` on its own for as long as the throw path
|
|
573
|
+
// below failed closed, so a guarded block that failed to load was served.
|
|
574
|
+
return failedBlockResponse(script)
|
|
540
575
|
}
|
|
541
576
|
|
|
542
577
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
@@ -594,33 +629,7 @@ export async function getServerResponse(options: ServerResponseOptions) {
|
|
|
594
629
|
'error',
|
|
595
630
|
)
|
|
596
631
|
|
|
597
|
-
|
|
598
|
-
//
|
|
599
|
-
// The generated wrapper runs the block's top-level statements and *then*
|
|
600
|
-
// calls `middleware`, so a throw anywhere above skips the guard
|
|
601
|
-
// completely. Returning `{}` here then served the route: a `/admin/*`
|
|
602
|
-
// page answering 200 to an anonymous caller because a query threw. Not
|
|
603
|
-
// hypothetical, and not only the obvious causes: the block only has to
|
|
604
|
-
// throw, so a database being down, a null deref or a typo all reach it.
|
|
605
|
-
//
|
|
606
|
-
// Convention 2 names this shape exactly: a guard "returns the rejection,
|
|
607
|
-
// not `null`, on any indeterminate state". A guard that ceased to exist
|
|
608
|
-
// is the most indeterminate state there is.
|
|
609
|
-
//
|
|
610
|
-
// Only when a guard is declared. A data-only block that throws still
|
|
611
|
-
// renders the page with no data, which is the documented behavior and is
|
|
612
|
-
// a visible failure rather than a silent one: the page is obviously
|
|
613
|
-
// broken, and nothing was protecting it.
|
|
614
|
-
//
|
|
615
|
-
// The declaration is read from the source, not from the result, because
|
|
616
|
-
// there is no result: the module threw before its exports existed. That
|
|
617
|
-
// is the same static list `compileServerBlock` already builds to decide
|
|
618
|
-
// which exports are callable as actions.
|
|
619
|
-
if (collectExportedFunctionNames(script).includes('middleware')) {
|
|
620
|
-
return new Response('Internal Server Error', { status: 500 })
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
return {}
|
|
632
|
+
return failedBlockResponse(script)
|
|
624
633
|
} finally {
|
|
625
634
|
clearTimeout(timer)
|
|
626
635
|
}
|