@avelonjs/core 0.8.4 → 0.8.5
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/README.md +4 -0
- package/package.json +1 -1
- package/src/runtime/kernel.ts +9 -16
- package/src/runtime/requests.ts +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,10 @@ export const updatePost: QueryIR = {
|
|
|
64
64
|
|
|
65
65
|
Adapters translate native requests and responses at three seams: mount, request conversion, and response conversion. Every mounted route delegates middleware, binding, validation mapping, controller dispatch, and exception mapping to `Kernel`. `HttpRequest.rawBody()` preserves signature-verification bytes, and streaming adapters accept `StreamResult`. A POST route exists whether the adapter uses a server action or an ordinary HTTP POST, and the adapter alone interprets an opaque view reference.
|
|
66
66
|
|
|
67
|
+
`createKernel({ resolveActor })` resolves the actor once per dispatch. The built-in `auth` middleware
|
|
68
|
+
requires that actor, and `can:*` uses the same actor as the controller. Register other middleware
|
|
69
|
+
aliases through `middleware`; an unknown alias returns a validation failure.
|
|
70
|
+
|
|
67
71
|
```ts
|
|
68
72
|
import type { Adapter, Kernel, RouteManifest } from '@avelonjs/core'
|
|
69
73
|
|
package/package.json
CHANGED
package/src/runtime/kernel.ts
CHANGED
|
@@ -47,13 +47,6 @@ export interface CreateKernelOptions {
|
|
|
47
47
|
mapException?: (error: unknown) => KernelResult | undefined
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function hasHeader(headers: Readonly<Record<string, string>>, name: string): boolean {
|
|
51
|
-
const target = name.toLowerCase()
|
|
52
|
-
return Object.entries(headers).some(
|
|
53
|
-
([key, value]) => key.toLowerCase() === target && value.length > 0,
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
50
|
/**
|
|
58
51
|
* Maps framework errors onto transport-neutral kernel results.
|
|
59
52
|
*
|
|
@@ -161,28 +154,28 @@ async function runMiddleware(
|
|
|
161
154
|
options: CreateKernelOptions,
|
|
162
155
|
): Promise<void> {
|
|
163
156
|
for (const name of route.middleware) {
|
|
164
|
-
const custom =
|
|
157
|
+
const custom =
|
|
158
|
+
options.middleware !== undefined && Object.hasOwn(options.middleware, name)
|
|
159
|
+
? options.middleware[name]
|
|
160
|
+
: undefined
|
|
165
161
|
if (custom !== undefined) {
|
|
166
162
|
await custom(request, route)
|
|
167
163
|
continue
|
|
168
164
|
}
|
|
169
165
|
if (name === 'auth') {
|
|
170
|
-
|
|
171
|
-
const signedIn =
|
|
172
|
-
actor !== null ||
|
|
173
|
-
hasHeader(request.headers, 'authorization') ||
|
|
174
|
-
hasHeader(request.headers, 'cookie')
|
|
175
|
-
if (!signedIn) {
|
|
166
|
+
if (Gate.actor() === null) {
|
|
176
167
|
throw new Unauthenticated('Authentication is required.', { metadata: { guard: 'auth' } })
|
|
177
168
|
}
|
|
178
169
|
continue
|
|
179
170
|
}
|
|
180
171
|
if (name.startsWith('can:')) {
|
|
181
172
|
const ability = name.slice(4)
|
|
182
|
-
|
|
183
|
-
await Gate.authorize(ability, 'Gate', actor)
|
|
173
|
+
await Gate.authorize(ability, 'Gate')
|
|
184
174
|
continue
|
|
185
175
|
}
|
|
176
|
+
throw new Invalid(`Unknown middleware '${name}'.`, {
|
|
177
|
+
metadata: { fields: { middleware: [`${name} is not registered.`] } },
|
|
178
|
+
})
|
|
186
179
|
}
|
|
187
180
|
}
|
|
188
181
|
|
package/src/runtime/requests.ts
CHANGED
|
@@ -24,7 +24,7 @@ function extractFields(error: unknown): Record<string, readonly string[]> {
|
|
|
24
24
|
'issues' in error &&
|
|
25
25
|
Array.isArray((error as { issues: unknown }).issues)
|
|
26
26
|
) {
|
|
27
|
-
const fields: Record<string, string[]> =
|
|
27
|
+
const fields: Record<string, string[]> = Object.create(null)
|
|
28
28
|
for (const issue of (error as { issues: Array<{ path?: unknown[]; message?: string }> })
|
|
29
29
|
.issues) {
|
|
30
30
|
const key = Array.isArray(issue.path) ? issue.path.map(String).join('.') || '_form' : '_form'
|