arri 0.1.0-beta.4 → 0.1.0-beta.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/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +21 -11
- package/dist/index.d.mts +21 -11
- package/dist/index.d.ts +21 -11
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.ef78b5e0.cjs → arri.ab9313ca.cjs} +49 -0
- package/dist/shared/{arri.74120afa.mjs → arri.b5addda0.mjs} +50 -1
- package/package.json +5 -5
package/dist/cli.cjs
CHANGED
|
@@ -11,7 +11,7 @@ const consola = require('consola');
|
|
|
11
11
|
const esbuild = require('esbuild');
|
|
12
12
|
const path = require('pathe');
|
|
13
13
|
const prettier = require('prettier');
|
|
14
|
-
const config = require('./shared/arri.
|
|
14
|
+
const config = require('./shared/arri.ab9313ca.cjs');
|
|
15
15
|
const globby = require('globby');
|
|
16
16
|
const scule = require('scule');
|
|
17
17
|
const arriCodegenDart = require('arri-codegen-dart');
|
package/dist/cli.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import * as esbuild from 'esbuild';
|
|
|
10
10
|
import { build as build$1 } from 'esbuild';
|
|
11
11
|
import path from 'pathe';
|
|
12
12
|
import prettier from 'prettier';
|
|
13
|
-
import { m as defaultConfig, l as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.
|
|
13
|
+
import { m as defaultConfig, l as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.b5addda0.mjs';
|
|
14
14
|
import { globby } from 'globby';
|
|
15
15
|
import { camelCase, kebabCase } from 'scule';
|
|
16
16
|
import { dartClientGenerator } from 'arri-codegen-dart';
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
2
|
import * as arri_validate from 'arri-validate';
|
|
3
|
-
import { AObjectSchema, InferType, a, ValidationError } from 'arri-validate';
|
|
3
|
+
import { AObjectSchema, ASchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
4
|
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
5
|
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
@@ -18,17 +18,27 @@ type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? Ext
|
|
|
18
18
|
|
|
19
19
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
20
20
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
21
|
-
interface RouteEventContext<TPath extends string> extends H3EventContext {
|
|
21
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
22
22
|
params: ExtractParams<TPath>;
|
|
23
|
+
query: TQuery;
|
|
24
|
+
body: TBody;
|
|
23
25
|
}
|
|
24
|
-
interface RouteEvent<TPath extends string> extends H3Event {
|
|
25
|
-
context: RouteEventContext<TPath>;
|
|
26
|
+
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
27
|
+
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
26
28
|
}
|
|
27
|
-
interface
|
|
29
|
+
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
30
|
+
response: TResponse;
|
|
31
|
+
}
|
|
32
|
+
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
33
|
+
context: PostRouteEventContext<TPath, TQuery, TBody, TResponse>;
|
|
34
|
+
}
|
|
35
|
+
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
28
36
|
path: TPath;
|
|
29
37
|
method: HttpMethod | HttpMethod[];
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
query?: TQuery;
|
|
39
|
+
body?: TBody;
|
|
40
|
+
handler: (event: RouteEvent<TPath, InferType<TQuery>, InferType<TBody>>) => TResponse;
|
|
41
|
+
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
32
42
|
}
|
|
33
43
|
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
34
44
|
middleware: Middleware[];
|
|
@@ -72,15 +82,15 @@ declare function registerRpc(router: Router, path: string, procedure: ArriNamedP
|
|
|
72
82
|
|
|
73
83
|
interface ArriRouterBase {
|
|
74
84
|
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
75
|
-
route: <TPath extends string>(route: ArriRoute<TPath>) => void;
|
|
85
|
+
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
76
86
|
}
|
|
77
87
|
declare class ArriRouter implements ArriRouterBase {
|
|
78
88
|
private readonly procedures;
|
|
79
89
|
private readonly routes;
|
|
80
90
|
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
81
|
-
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
91
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
82
92
|
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
83
|
-
getRoutes(): ArriRoute<any>[];
|
|
93
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
@@ -102,7 +112,7 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
102
112
|
constructor(opts?: ArriOptions);
|
|
103
113
|
use(input: Middleware | ArriRouter): void;
|
|
104
114
|
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
105
|
-
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
115
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
106
116
|
getAppDefinition(): AppDefinition;
|
|
107
117
|
}
|
|
108
118
|
interface ArriOptions {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
2
|
import * as arri_validate from 'arri-validate';
|
|
3
|
-
import { AObjectSchema, InferType, a, ValidationError } from 'arri-validate';
|
|
3
|
+
import { AObjectSchema, ASchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
4
|
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
5
|
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
@@ -18,17 +18,27 @@ type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? Ext
|
|
|
18
18
|
|
|
19
19
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
20
20
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
21
|
-
interface RouteEventContext<TPath extends string> extends H3EventContext {
|
|
21
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
22
22
|
params: ExtractParams<TPath>;
|
|
23
|
+
query: TQuery;
|
|
24
|
+
body: TBody;
|
|
23
25
|
}
|
|
24
|
-
interface RouteEvent<TPath extends string> extends H3Event {
|
|
25
|
-
context: RouteEventContext<TPath>;
|
|
26
|
+
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
27
|
+
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
26
28
|
}
|
|
27
|
-
interface
|
|
29
|
+
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
30
|
+
response: TResponse;
|
|
31
|
+
}
|
|
32
|
+
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
33
|
+
context: PostRouteEventContext<TPath, TQuery, TBody, TResponse>;
|
|
34
|
+
}
|
|
35
|
+
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
28
36
|
path: TPath;
|
|
29
37
|
method: HttpMethod | HttpMethod[];
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
query?: TQuery;
|
|
39
|
+
body?: TBody;
|
|
40
|
+
handler: (event: RouteEvent<TPath, InferType<TQuery>, InferType<TBody>>) => TResponse;
|
|
41
|
+
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
32
42
|
}
|
|
33
43
|
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
34
44
|
middleware: Middleware[];
|
|
@@ -72,15 +82,15 @@ declare function registerRpc(router: Router, path: string, procedure: ArriNamedP
|
|
|
72
82
|
|
|
73
83
|
interface ArriRouterBase {
|
|
74
84
|
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
75
|
-
route: <TPath extends string>(route: ArriRoute<TPath>) => void;
|
|
85
|
+
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
76
86
|
}
|
|
77
87
|
declare class ArriRouter implements ArriRouterBase {
|
|
78
88
|
private readonly procedures;
|
|
79
89
|
private readonly routes;
|
|
80
90
|
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
81
|
-
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
91
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
82
92
|
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
83
|
-
getRoutes(): ArriRoute<any>[];
|
|
93
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
@@ -102,7 +112,7 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
102
112
|
constructor(opts?: ArriOptions);
|
|
103
113
|
use(input: Middleware | ArriRouter): void;
|
|
104
114
|
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
105
|
-
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
115
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
106
116
|
getAppDefinition(): AppDefinition;
|
|
107
117
|
}
|
|
108
118
|
interface ArriOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
2
|
import * as arri_validate from 'arri-validate';
|
|
3
|
-
import { AObjectSchema, InferType, a, ValidationError } from 'arri-validate';
|
|
3
|
+
import { AObjectSchema, ASchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
4
|
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
5
|
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
@@ -18,17 +18,27 @@ type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? Ext
|
|
|
18
18
|
|
|
19
19
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
20
20
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
21
|
-
interface RouteEventContext<TPath extends string> extends H3EventContext {
|
|
21
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
22
22
|
params: ExtractParams<TPath>;
|
|
23
|
+
query: TQuery;
|
|
24
|
+
body: TBody;
|
|
23
25
|
}
|
|
24
|
-
interface RouteEvent<TPath extends string> extends H3Event {
|
|
25
|
-
context: RouteEventContext<TPath>;
|
|
26
|
+
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
27
|
+
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
26
28
|
}
|
|
27
|
-
interface
|
|
29
|
+
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
30
|
+
response: TResponse;
|
|
31
|
+
}
|
|
32
|
+
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
33
|
+
context: PostRouteEventContext<TPath, TQuery, TBody, TResponse>;
|
|
34
|
+
}
|
|
35
|
+
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
28
36
|
path: TPath;
|
|
29
37
|
method: HttpMethod | HttpMethod[];
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
query?: TQuery;
|
|
39
|
+
body?: TBody;
|
|
40
|
+
handler: (event: RouteEvent<TPath, InferType<TQuery>, InferType<TBody>>) => TResponse;
|
|
41
|
+
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
32
42
|
}
|
|
33
43
|
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
34
44
|
middleware: Middleware[];
|
|
@@ -72,15 +82,15 @@ declare function registerRpc(router: Router, path: string, procedure: ArriNamedP
|
|
|
72
82
|
|
|
73
83
|
interface ArriRouterBase {
|
|
74
84
|
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
75
|
-
route: <TPath extends string>(route: ArriRoute<TPath>) => void;
|
|
85
|
+
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
76
86
|
}
|
|
77
87
|
declare class ArriRouter implements ArriRouterBase {
|
|
78
88
|
private readonly procedures;
|
|
79
89
|
private readonly routes;
|
|
80
90
|
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
81
|
-
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
91
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
82
92
|
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
83
|
-
getRoutes(): ArriRoute<any>[];
|
|
93
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
@@ -102,7 +112,7 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
102
112
|
constructor(opts?: ArriOptions);
|
|
103
113
|
use(input: Middleware | ArriRouter): void;
|
|
104
114
|
rpc<TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>): void;
|
|
105
|
-
route<TPath extends string>(route: ArriRoute<TPath>): void;
|
|
115
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
106
116
|
getAppDefinition(): AppDefinition;
|
|
107
117
|
}
|
|
108
118
|
interface ArriOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as ArriApp, o as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, c as createRpcDefinition, m as defaultConfig, n as defineConfig, f as defineError, d as defineRpc, h as errorResponseFromValidationErrors, b as getRpcParamName, g as getRpcPath, e as getRpcResponseName, j as handleH3Error, k as isArriConfig, l as isResolvedArriConfig, i as isRpc, r as registerRpc } from './shared/arri.
|
|
1
|
+
export { A as ArriApp, o as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, c as createRpcDefinition, m as defaultConfig, n as defineConfig, f as defineError, d as defineRpc, h as errorResponseFromValidationErrors, b as getRpcParamName, g as getRpcPath, e as getRpcResponseName, j as handleH3Error, k as isArriConfig, l as isResolvedArriConfig, i as isRpc, r as registerRpc } from './shared/arri.b5addda0.mjs';
|
|
2
2
|
export * from 'h3';
|
|
3
3
|
import 'arri-validate';
|
|
4
4
|
import 'arri-codegen-utils';
|
|
@@ -455,6 +455,55 @@ function handleRoute(router, method, route, opts) {
|
|
|
455
455
|
await m(event);
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
+
if (route.query) {
|
|
459
|
+
const query = h3.getQuery(event);
|
|
460
|
+
const parsedQuery = arriValidate.a.safeCoerce(route.query, query);
|
|
461
|
+
if (!parsedQuery.success) {
|
|
462
|
+
const errParts = [];
|
|
463
|
+
for (const err of parsedQuery.error.errors) {
|
|
464
|
+
const errPath = err.instancePath.split("/");
|
|
465
|
+
errPath.shift();
|
|
466
|
+
const propName = errPath.join(".");
|
|
467
|
+
if (!errParts.includes(propName)) {
|
|
468
|
+
errParts.push(propName);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const message = `Missing or invalid url query parameters: [${errParts.join(
|
|
472
|
+
", "
|
|
473
|
+
)}]`;
|
|
474
|
+
throw defineError(400, {
|
|
475
|
+
statusMessage: message
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
event.context.query = parsedQuery.value;
|
|
479
|
+
}
|
|
480
|
+
const notAllowedBodyMethods = [
|
|
481
|
+
"GET",
|
|
482
|
+
"HEAD",
|
|
483
|
+
"CONNECT",
|
|
484
|
+
"OPTIONS"
|
|
485
|
+
];
|
|
486
|
+
if (route.body && !notAllowedBodyMethods.includes(event.method)) {
|
|
487
|
+
const body = await h3.readRawBody(event);
|
|
488
|
+
const parsedBody = arriValidate.a.safeParse(route.body, body);
|
|
489
|
+
if (!parsedBody.success) {
|
|
490
|
+
const errorParts = [];
|
|
491
|
+
for (const err of parsedBody.error.errors) {
|
|
492
|
+
const errPath = err.instancePath.split("/");
|
|
493
|
+
errPath.shift();
|
|
494
|
+
if (!errorParts.includes(errPath.join("."))) {
|
|
495
|
+
errorParts.push(errPath.join("."));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
throw defineError(400, {
|
|
499
|
+
statusMessage: `Invalid request body. Affected properties [${errorParts.join(
|
|
500
|
+
", "
|
|
501
|
+
)}]`,
|
|
502
|
+
data: parsedBody.error
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
event.context.body = parsedBody.value;
|
|
506
|
+
}
|
|
458
507
|
const response = await route.handler(event);
|
|
459
508
|
event.context.response = response;
|
|
460
509
|
if (!event.handled) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a, isAObjectSchema } from 'arri-validate';
|
|
2
|
-
import { createError, isError, setResponseStatus, send, eventHandler, isPreflightRequest, readRawBody, getValidatedQuery, setResponseHeader, defineEventHandler, setHeader, createRouter, createApp, sendError } from 'h3';
|
|
2
|
+
import { createError, isError, setResponseStatus, send, eventHandler, isPreflightRequest, readRawBody, getValidatedQuery, setResponseHeader, defineEventHandler, getQuery, setHeader, createRouter, createApp, sendError } from 'h3';
|
|
3
3
|
import { isHttpMethod, removeDisallowedChars } from 'arri-codegen-utils';
|
|
4
4
|
import { kebabCase, pascalCase } from 'scule';
|
|
5
5
|
|
|
@@ -453,6 +453,55 @@ function handleRoute(router, method, route, opts) {
|
|
|
453
453
|
await m(event);
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
|
+
if (route.query) {
|
|
457
|
+
const query = getQuery(event);
|
|
458
|
+
const parsedQuery = a.safeCoerce(route.query, query);
|
|
459
|
+
if (!parsedQuery.success) {
|
|
460
|
+
const errParts = [];
|
|
461
|
+
for (const err of parsedQuery.error.errors) {
|
|
462
|
+
const errPath = err.instancePath.split("/");
|
|
463
|
+
errPath.shift();
|
|
464
|
+
const propName = errPath.join(".");
|
|
465
|
+
if (!errParts.includes(propName)) {
|
|
466
|
+
errParts.push(propName);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const message = `Missing or invalid url query parameters: [${errParts.join(
|
|
470
|
+
", "
|
|
471
|
+
)}]`;
|
|
472
|
+
throw defineError(400, {
|
|
473
|
+
statusMessage: message
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
event.context.query = parsedQuery.value;
|
|
477
|
+
}
|
|
478
|
+
const notAllowedBodyMethods = [
|
|
479
|
+
"GET",
|
|
480
|
+
"HEAD",
|
|
481
|
+
"CONNECT",
|
|
482
|
+
"OPTIONS"
|
|
483
|
+
];
|
|
484
|
+
if (route.body && !notAllowedBodyMethods.includes(event.method)) {
|
|
485
|
+
const body = await readRawBody(event);
|
|
486
|
+
const parsedBody = a.safeParse(route.body, body);
|
|
487
|
+
if (!parsedBody.success) {
|
|
488
|
+
const errorParts = [];
|
|
489
|
+
for (const err of parsedBody.error.errors) {
|
|
490
|
+
const errPath = err.instancePath.split("/");
|
|
491
|
+
errPath.shift();
|
|
492
|
+
if (!errorParts.includes(errPath.join("."))) {
|
|
493
|
+
errorParts.push(errPath.join("."));
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
throw defineError(400, {
|
|
497
|
+
statusMessage: `Invalid request body. Affected properties [${errorParts.join(
|
|
498
|
+
", "
|
|
499
|
+
)}]`,
|
|
500
|
+
data: parsedBody.error
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
event.context.body = parsedBody.value;
|
|
504
|
+
}
|
|
456
505
|
const response = await route.handler(event);
|
|
457
506
|
event.context.response = response;
|
|
458
507
|
if (!event.handled) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arri",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"pathe": "^1.1.1",
|
|
32
32
|
"prettier": "^3.0.3",
|
|
33
33
|
"scule": "^1.0.0",
|
|
34
|
-
"arri-codegen-dart": "0.1.0-beta.
|
|
35
|
-
"arri-codegen-utils": "0.1.0-beta.
|
|
36
|
-
"arri-validate": "0.1.0-beta.
|
|
37
|
-
"arri-codegen-ts": "0.1.0-beta.
|
|
34
|
+
"arri-codegen-dart": "0.1.0-beta.5",
|
|
35
|
+
"arri-codegen-utils": "0.1.0-beta.5",
|
|
36
|
+
"arri-validate": "0.1.0-beta.5",
|
|
37
|
+
"arri-codegen-ts": "0.1.0-beta.5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"bun-types": "^1.0.5"
|