arri 0.1.0-beta.4 → 0.1.0-beta.6
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 +2 -1
- package/dist/index.d.cts +23 -12
- package/dist/index.d.mts +23 -12
- package/dist/index.d.ts +23 -12
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.74120afa.mjs → arri.18968810.mjs} +78 -26
- package/dist/shared/{arri.ef78b5e0.cjs → arri.45622e4c.cjs} +77 -24
- 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.45622e4c.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.18968810.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const config = require('./shared/arri.
|
|
3
|
+
const config = require('./shared/arri.45622e4c.cjs');
|
|
4
4
|
const h3 = require('h3');
|
|
5
5
|
require('arri-validate');
|
|
6
6
|
require('arri-codegen-utils');
|
|
@@ -17,6 +17,7 @@ exports.createRpcDefinition = config.createRpcDefinition;
|
|
|
17
17
|
exports.defaultConfig = config.defaultConfig;
|
|
18
18
|
exports.defineConfig = config.defineConfig;
|
|
19
19
|
exports.defineError = config.defineError;
|
|
20
|
+
exports.defineRoute = config.defineRoute;
|
|
20
21
|
exports.defineRpc = config.defineRpc;
|
|
21
22
|
exports.errorResponseFromValidationErrors = config.errorResponseFromValidationErrors;
|
|
22
23
|
exports.getRpcParamName = config.getRpcParamName;
|
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,18 +18,29 @@ 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
|
}
|
|
43
|
+
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
33
44
|
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
34
45
|
middleware: Middleware[];
|
|
35
46
|
};
|
|
@@ -72,15 +83,15 @@ declare function registerRpc(router: Router, path: string, procedure: ArriNamedP
|
|
|
72
83
|
|
|
73
84
|
interface ArriRouterBase {
|
|
74
85
|
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;
|
|
86
|
+
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
87
|
}
|
|
77
88
|
declare class ArriRouter implements ArriRouterBase {
|
|
78
89
|
private readonly procedures;
|
|
79
90
|
private readonly routes;
|
|
80
91
|
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;
|
|
92
|
+
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
93
|
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
83
|
-
getRoutes(): ArriRoute<any>[];
|
|
94
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
@@ -102,7 +113,7 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
102
113
|
constructor(opts?: ArriOptions);
|
|
103
114
|
use(input: Middleware | ArriRouter): void;
|
|
104
115
|
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;
|
|
116
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
106
117
|
getAppDefinition(): AppDefinition;
|
|
107
118
|
}
|
|
108
119
|
interface ArriOptions {
|
|
@@ -157,4 +168,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
157
168
|
declare const defaultConfig: Required<ArriConfig>;
|
|
158
169
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
159
170
|
|
|
160
|
-
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ResolvedArriConfig, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
|
171
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ResolvedArriConfig, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
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,18 +18,29 @@ 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
|
}
|
|
43
|
+
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
33
44
|
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
34
45
|
middleware: Middleware[];
|
|
35
46
|
};
|
|
@@ -72,15 +83,15 @@ declare function registerRpc(router: Router, path: string, procedure: ArriNamedP
|
|
|
72
83
|
|
|
73
84
|
interface ArriRouterBase {
|
|
74
85
|
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;
|
|
86
|
+
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
87
|
}
|
|
77
88
|
declare class ArriRouter implements ArriRouterBase {
|
|
78
89
|
private readonly procedures;
|
|
79
90
|
private readonly routes;
|
|
80
91
|
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;
|
|
92
|
+
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
93
|
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
83
|
-
getRoutes(): ArriRoute<any>[];
|
|
94
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
@@ -102,7 +113,7 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
102
113
|
constructor(opts?: ArriOptions);
|
|
103
114
|
use(input: Middleware | ArriRouter): void;
|
|
104
115
|
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;
|
|
116
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
106
117
|
getAppDefinition(): AppDefinition;
|
|
107
118
|
}
|
|
108
119
|
interface ArriOptions {
|
|
@@ -157,4 +168,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
157
168
|
declare const defaultConfig: Required<ArriConfig>;
|
|
158
169
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
159
170
|
|
|
160
|
-
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ResolvedArriConfig, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
|
171
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ResolvedArriConfig, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
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,18 +18,29 @@ 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
|
}
|
|
43
|
+
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
33
44
|
type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
|
|
34
45
|
middleware: Middleware[];
|
|
35
46
|
};
|
|
@@ -72,15 +83,15 @@ declare function registerRpc(router: Router, path: string, procedure: ArriNamedP
|
|
|
72
83
|
|
|
73
84
|
interface ArriRouterBase {
|
|
74
85
|
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;
|
|
86
|
+
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
87
|
}
|
|
77
88
|
declare class ArriRouter implements ArriRouterBase {
|
|
78
89
|
private readonly procedures;
|
|
79
90
|
private readonly routes;
|
|
80
91
|
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;
|
|
92
|
+
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
93
|
getProcedures(): ArriNamedProcedure<any, any>[];
|
|
83
|
-
getRoutes(): ArriRoute<any>[];
|
|
94
|
+
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
|
|
@@ -102,7 +113,7 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
102
113
|
constructor(opts?: ArriOptions);
|
|
103
114
|
use(input: Middleware | ArriRouter): void;
|
|
104
115
|
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;
|
|
116
|
+
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
106
117
|
getAppDefinition(): AppDefinition;
|
|
107
118
|
}
|
|
108
119
|
interface ArriOptions {
|
|
@@ -157,4 +168,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
157
168
|
declare const defaultConfig: Required<ArriConfig>;
|
|
158
169
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
159
170
|
|
|
160
|
-
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ResolvedArriConfig, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
|
171
|
+
export { ArriApp, type ArriConfig, type ArriNamedProcedure, type ArriOptions, type ArriProcedure, type ArriProcedureHandler, type ArriProcedurePostHandler, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, type ExtractParam$1 as ExtractParam, type ExtractParams$1 as ExtractParams, type HandlerContext, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ResolvedArriConfig, type RpcEvent, type RpcHandlerContext, type RpcPostEvent, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
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, p as defineRoute, 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.18968810.mjs';
|
|
2
2
|
export * from 'h3';
|
|
3
3
|
import 'arri-validate';
|
|
4
4
|
import 'arri-codegen-utils';
|
|
@@ -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
|
|
|
@@ -405,31 +405,9 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
var __publicField$1 = (obj, key, value) => {
|
|
411
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
412
|
-
return value;
|
|
413
|
-
};
|
|
414
|
-
class ArriRouter {
|
|
415
|
-
constructor() {
|
|
416
|
-
__publicField$1(this, "procedures", []);
|
|
417
|
-
__publicField$1(this, "routes", []);
|
|
418
|
-
}
|
|
419
|
-
rpc(procedure) {
|
|
420
|
-
this.procedures.push(procedure);
|
|
421
|
-
}
|
|
422
|
-
route(route) {
|
|
423
|
-
this.routes.push(route);
|
|
424
|
-
}
|
|
425
|
-
getProcedures() {
|
|
426
|
-
return this.procedures;
|
|
427
|
-
}
|
|
428
|
-
getRoutes() {
|
|
429
|
-
return this.routes;
|
|
430
|
-
}
|
|
408
|
+
function defineRoute(route) {
|
|
409
|
+
return route;
|
|
431
410
|
}
|
|
432
|
-
|
|
433
411
|
function registerRoute(router, route, opts) {
|
|
434
412
|
if (typeof route.method === "string") {
|
|
435
413
|
handleRoute(router, route.method, route, opts);
|
|
@@ -453,6 +431,55 @@ function handleRoute(router, method, route, opts) {
|
|
|
453
431
|
await m(event);
|
|
454
432
|
}
|
|
455
433
|
}
|
|
434
|
+
if (route.query) {
|
|
435
|
+
const query = getQuery(event);
|
|
436
|
+
const parsedQuery = a.safeCoerce(route.query, query);
|
|
437
|
+
if (!parsedQuery.success) {
|
|
438
|
+
const errParts = [];
|
|
439
|
+
for (const err of parsedQuery.error.errors) {
|
|
440
|
+
const errPath = err.instancePath.split("/");
|
|
441
|
+
errPath.shift();
|
|
442
|
+
const propName = errPath.join(".");
|
|
443
|
+
if (!errParts.includes(propName)) {
|
|
444
|
+
errParts.push(propName);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
const message = `Missing or invalid url query parameters: [${errParts.join(
|
|
448
|
+
", "
|
|
449
|
+
)}]`;
|
|
450
|
+
throw defineError(400, {
|
|
451
|
+
statusMessage: message
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
event.context.query = parsedQuery.value;
|
|
455
|
+
}
|
|
456
|
+
const notAllowedBodyMethods = [
|
|
457
|
+
"GET",
|
|
458
|
+
"HEAD",
|
|
459
|
+
"CONNECT",
|
|
460
|
+
"OPTIONS"
|
|
461
|
+
];
|
|
462
|
+
if (route.body && !notAllowedBodyMethods.includes(event.method)) {
|
|
463
|
+
const body = await readRawBody(event);
|
|
464
|
+
const parsedBody = a.safeParse(route.body, body);
|
|
465
|
+
if (!parsedBody.success) {
|
|
466
|
+
const errorParts = [];
|
|
467
|
+
for (const err of parsedBody.error.errors) {
|
|
468
|
+
const errPath = err.instancePath.split("/");
|
|
469
|
+
errPath.shift();
|
|
470
|
+
if (!errorParts.includes(errPath.join("."))) {
|
|
471
|
+
errorParts.push(errPath.join("."));
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
throw defineError(400, {
|
|
475
|
+
statusMessage: `Invalid request body. Affected properties [${errorParts.join(
|
|
476
|
+
", "
|
|
477
|
+
)}]`,
|
|
478
|
+
data: parsedBody.error
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
event.context.body = parsedBody.value;
|
|
482
|
+
}
|
|
456
483
|
const response = await route.handler(event);
|
|
457
484
|
event.context.response = response;
|
|
458
485
|
if (!event.handled) {
|
|
@@ -499,6 +526,31 @@ function handleRoute(router, method, route, opts) {
|
|
|
499
526
|
}
|
|
500
527
|
}
|
|
501
528
|
|
|
529
|
+
var __defProp$1 = Object.defineProperty;
|
|
530
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
531
|
+
var __publicField$1 = (obj, key, value) => {
|
|
532
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
533
|
+
return value;
|
|
534
|
+
};
|
|
535
|
+
class ArriRouter {
|
|
536
|
+
constructor() {
|
|
537
|
+
__publicField$1(this, "procedures", []);
|
|
538
|
+
__publicField$1(this, "routes", []);
|
|
539
|
+
}
|
|
540
|
+
rpc(procedure) {
|
|
541
|
+
this.procedures.push(procedure);
|
|
542
|
+
}
|
|
543
|
+
route(route) {
|
|
544
|
+
this.routes.push(route);
|
|
545
|
+
}
|
|
546
|
+
getProcedures() {
|
|
547
|
+
return this.procedures;
|
|
548
|
+
}
|
|
549
|
+
getRoutes() {
|
|
550
|
+
return this.routes;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
502
554
|
var __defProp = Object.defineProperty;
|
|
503
555
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
504
556
|
var __publicField = (obj, key, value) => {
|
|
@@ -673,4 +725,4 @@ function defineConfig(config) {
|
|
|
673
725
|
};
|
|
674
726
|
}
|
|
675
727
|
|
|
676
|
-
export { ArriApp as A, DEV_ENDPOINT_ROOT as D, ErrorResponse as E, DEV_DEFINITION_ENDPOINT as a, getRpcParamName as b, createRpcDefinition as c, defineRpc as d, getRpcResponseName as e, defineError as f, getRpcPath as g, errorResponseFromValidationErrors as h, isRpc as i, handleH3Error as j, isArriConfig as k, isResolvedArriConfig as l, defaultConfig as m, defineConfig as n, ArriRouter as o, registerRpc as r };
|
|
728
|
+
export { ArriApp as A, DEV_ENDPOINT_ROOT as D, ErrorResponse as E, DEV_DEFINITION_ENDPOINT as a, getRpcParamName as b, createRpcDefinition as c, defineRpc as d, getRpcResponseName as e, defineError as f, getRpcPath as g, errorResponseFromValidationErrors as h, isRpc as i, handleH3Error as j, isArriConfig as k, isResolvedArriConfig as l, defaultConfig as m, defineConfig as n, ArriRouter as o, defineRoute as p, registerRpc as r };
|
|
@@ -407,31 +407,9 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
var __publicField$1 = (obj, key, value) => {
|
|
413
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
414
|
-
return value;
|
|
415
|
-
};
|
|
416
|
-
class ArriRouter {
|
|
417
|
-
constructor() {
|
|
418
|
-
__publicField$1(this, "procedures", []);
|
|
419
|
-
__publicField$1(this, "routes", []);
|
|
420
|
-
}
|
|
421
|
-
rpc(procedure) {
|
|
422
|
-
this.procedures.push(procedure);
|
|
423
|
-
}
|
|
424
|
-
route(route) {
|
|
425
|
-
this.routes.push(route);
|
|
426
|
-
}
|
|
427
|
-
getProcedures() {
|
|
428
|
-
return this.procedures;
|
|
429
|
-
}
|
|
430
|
-
getRoutes() {
|
|
431
|
-
return this.routes;
|
|
432
|
-
}
|
|
410
|
+
function defineRoute(route) {
|
|
411
|
+
return route;
|
|
433
412
|
}
|
|
434
|
-
|
|
435
413
|
function registerRoute(router, route, opts) {
|
|
436
414
|
if (typeof route.method === "string") {
|
|
437
415
|
handleRoute(router, route.method, route, opts);
|
|
@@ -455,6 +433,55 @@ function handleRoute(router, method, route, opts) {
|
|
|
455
433
|
await m(event);
|
|
456
434
|
}
|
|
457
435
|
}
|
|
436
|
+
if (route.query) {
|
|
437
|
+
const query = h3.getQuery(event);
|
|
438
|
+
const parsedQuery = arriValidate.a.safeCoerce(route.query, query);
|
|
439
|
+
if (!parsedQuery.success) {
|
|
440
|
+
const errParts = [];
|
|
441
|
+
for (const err of parsedQuery.error.errors) {
|
|
442
|
+
const errPath = err.instancePath.split("/");
|
|
443
|
+
errPath.shift();
|
|
444
|
+
const propName = errPath.join(".");
|
|
445
|
+
if (!errParts.includes(propName)) {
|
|
446
|
+
errParts.push(propName);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const message = `Missing or invalid url query parameters: [${errParts.join(
|
|
450
|
+
", "
|
|
451
|
+
)}]`;
|
|
452
|
+
throw defineError(400, {
|
|
453
|
+
statusMessage: message
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
event.context.query = parsedQuery.value;
|
|
457
|
+
}
|
|
458
|
+
const notAllowedBodyMethods = [
|
|
459
|
+
"GET",
|
|
460
|
+
"HEAD",
|
|
461
|
+
"CONNECT",
|
|
462
|
+
"OPTIONS"
|
|
463
|
+
];
|
|
464
|
+
if (route.body && !notAllowedBodyMethods.includes(event.method)) {
|
|
465
|
+
const body = await h3.readRawBody(event);
|
|
466
|
+
const parsedBody = arriValidate.a.safeParse(route.body, body);
|
|
467
|
+
if (!parsedBody.success) {
|
|
468
|
+
const errorParts = [];
|
|
469
|
+
for (const err of parsedBody.error.errors) {
|
|
470
|
+
const errPath = err.instancePath.split("/");
|
|
471
|
+
errPath.shift();
|
|
472
|
+
if (!errorParts.includes(errPath.join("."))) {
|
|
473
|
+
errorParts.push(errPath.join("."));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
throw defineError(400, {
|
|
477
|
+
statusMessage: `Invalid request body. Affected properties [${errorParts.join(
|
|
478
|
+
", "
|
|
479
|
+
)}]`,
|
|
480
|
+
data: parsedBody.error
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
event.context.body = parsedBody.value;
|
|
484
|
+
}
|
|
458
485
|
const response = await route.handler(event);
|
|
459
486
|
event.context.response = response;
|
|
460
487
|
if (!event.handled) {
|
|
@@ -501,6 +528,31 @@ function handleRoute(router, method, route, opts) {
|
|
|
501
528
|
}
|
|
502
529
|
}
|
|
503
530
|
|
|
531
|
+
var __defProp$1 = Object.defineProperty;
|
|
532
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
533
|
+
var __publicField$1 = (obj, key, value) => {
|
|
534
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
535
|
+
return value;
|
|
536
|
+
};
|
|
537
|
+
class ArriRouter {
|
|
538
|
+
constructor() {
|
|
539
|
+
__publicField$1(this, "procedures", []);
|
|
540
|
+
__publicField$1(this, "routes", []);
|
|
541
|
+
}
|
|
542
|
+
rpc(procedure) {
|
|
543
|
+
this.procedures.push(procedure);
|
|
544
|
+
}
|
|
545
|
+
route(route) {
|
|
546
|
+
this.routes.push(route);
|
|
547
|
+
}
|
|
548
|
+
getProcedures() {
|
|
549
|
+
return this.procedures;
|
|
550
|
+
}
|
|
551
|
+
getRoutes() {
|
|
552
|
+
return this.routes;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
504
556
|
var __defProp = Object.defineProperty;
|
|
505
557
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
506
558
|
var __publicField = (obj, key, value) => {
|
|
@@ -684,6 +736,7 @@ exports.createRpcDefinition = createRpcDefinition;
|
|
|
684
736
|
exports.defaultConfig = defaultConfig;
|
|
685
737
|
exports.defineConfig = defineConfig;
|
|
686
738
|
exports.defineError = defineError;
|
|
739
|
+
exports.defineRoute = defineRoute;
|
|
687
740
|
exports.defineRpc = defineRpc;
|
|
688
741
|
exports.errorResponseFromValidationErrors = errorResponseFromValidationErrors;
|
|
689
742
|
exports.getRpcParamName = getRpcParamName;
|
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.6",
|
|
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-
|
|
35
|
-
"arri-codegen-
|
|
36
|
-
"arri-validate": "0.1.0-beta.
|
|
37
|
-
"arri-codegen-ts": "0.1.0-beta.
|
|
34
|
+
"arri-codegen-utils": "0.1.0-beta.6",
|
|
35
|
+
"arri-codegen-dart": "0.1.0-beta.6",
|
|
36
|
+
"arri-validate": "0.1.0-beta.6",
|
|
37
|
+
"arri-codegen-ts": "0.1.0-beta.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"bun-types": "^1.0.5"
|