@mantiq/core 0.5.16 → 0.5.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantiq/core",
3
- "version": "0.5.16",
3
+ "version": "0.5.17",
4
4
  "description": "Service container, router, middleware, HTTP kernel, config, and exception handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -5,6 +5,7 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
5
5
 
6
6
  export type RouteAction =
7
7
  | [Constructor<any>, string]
8
+ | [Constructor<any>, string, Constructor<any>] // [Controller, method, FormRequest]
8
9
  | ((request: MantiqRequest) => any)
9
10
  | string
10
11
 
@@ -181,9 +181,17 @@ export class HttpKernel {
181
181
  if (typeof action === 'function') {
182
182
  result = await action(request)
183
183
  } else if (Array.isArray(action)) {
184
- const [ControllerClass, method] = action
184
+ const [ControllerClass, method, FormRequestClass] = action
185
185
  const controller = this.container.make(ControllerClass)
186
- result = await (controller as any)[method](request)
186
+
187
+ // If a FormRequest class is specified, auto-validate before calling the action
188
+ if (FormRequestClass) {
189
+ const formRequest = new FormRequestClass(request)
190
+ const validated = await formRequest.validate()
191
+ result = await (controller as any)[method](request, validated)
192
+ } else {
193
+ result = await (controller as any)[method](request)
194
+ }
187
195
  } else {
188
196
  throw new Error(`Unresolved string action '${action}'. Controllers must be registered with router.controllers().`)
189
197
  }