arri 0.1.0-beta.2 → 0.1.0-beta.4
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 +4 -1
- package/dist/cli.mjs +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +24 -10
- package/dist/index.d.mts +24 -10
- package/dist/index.d.ts +24 -10
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.8539c7bd.mjs → arri.74120afa.mjs} +20 -21
- package/dist/shared/{arri.406d936a.cjs → arri.ef78b5e0.cjs} +20 -21
- package/package.json +7 -7
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.ef78b5e0.cjs');
|
|
15
15
|
const globby = require('globby');
|
|
16
16
|
const scule = require('scule');
|
|
17
17
|
const arriCodegenDart = require('arri-codegen-dart');
|
|
@@ -263,6 +263,7 @@ async function bundleFiles(config, allowCodegen = true) {
|
|
|
263
263
|
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
264
264
|
const require = topLevelCreateRequire(import.meta.url);`
|
|
265
265
|
},
|
|
266
|
+
allowOverwrite: true,
|
|
266
267
|
outdir: path__default.resolve(config.rootDir, ".output")
|
|
267
268
|
});
|
|
268
269
|
}
|
|
@@ -309,6 +310,7 @@ async function createBuildCodegenModule(config) {
|
|
|
309
310
|
app.rpc({
|
|
310
311
|
name: route.id,
|
|
311
312
|
method: route.route.method,
|
|
313
|
+
path: route.route.path,
|
|
312
314
|
params: route.route.params,
|
|
313
315
|
response: route.route.response,
|
|
314
316
|
handler: route.route.handler,
|
|
@@ -549,6 +551,7 @@ for (const route of routes) {
|
|
|
549
551
|
app.rpc({
|
|
550
552
|
name: route.id,
|
|
551
553
|
method: route.route.method,
|
|
554
|
+
path: route.route.path,
|
|
552
555
|
params: route.route.params,
|
|
553
556
|
response: route.route.response,
|
|
554
557
|
handler: route.route.handler,
|
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.74120afa.mjs';
|
|
14
14
|
import { globby } from 'globby';
|
|
15
15
|
import { camelCase, kebabCase } from 'scule';
|
|
16
16
|
import { dartClientGenerator } from 'arri-codegen-dart';
|
|
@@ -242,6 +242,7 @@ async function bundleFiles(config, allowCodegen = true) {
|
|
|
242
242
|
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
243
243
|
const require = topLevelCreateRequire(import.meta.url);`
|
|
244
244
|
},
|
|
245
|
+
allowOverwrite: true,
|
|
245
246
|
outdir: path.resolve(config.rootDir, ".output")
|
|
246
247
|
});
|
|
247
248
|
}
|
|
@@ -288,6 +289,7 @@ async function createBuildCodegenModule(config) {
|
|
|
288
289
|
app.rpc({
|
|
289
290
|
name: route.id,
|
|
290
291
|
method: route.route.method,
|
|
292
|
+
path: route.route.path,
|
|
291
293
|
params: route.route.params,
|
|
292
294
|
response: route.route.response,
|
|
293
295
|
handler: route.route.handler,
|
|
@@ -528,6 +530,7 @@ for (const route of routes) {
|
|
|
528
530
|
app.rpc({
|
|
529
531
|
name: route.id,
|
|
530
532
|
method: route.route.method,
|
|
533
|
+
path: route.route.path,
|
|
531
534
|
params: route.route.params,
|
|
532
535
|
response: route.route.response,
|
|
533
536
|
handler: route.route.handler,
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
2
|
import * as arri_validate from 'arri-validate';
|
|
3
3
|
import { AObjectSchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
-
import {
|
|
4
|
+
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
5
|
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface MiddlewareEventContext extends H3EventContext {
|
|
9
|
+
rpcName?: string;
|
|
10
|
+
}
|
|
11
|
+
interface MiddlewareEvent extends H3Event {
|
|
12
|
+
context: MiddlewareEventContext;
|
|
13
|
+
}
|
|
14
|
+
type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
|
|
9
15
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
10
16
|
type ExtractParam$1<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
11
17
|
type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam$1<Segment, ExtractParams$1<Rest>> : ExtractParam$1<Path, {}>;
|
|
@@ -31,6 +37,7 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
|
|
|
31
37
|
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
32
38
|
description?: string;
|
|
33
39
|
method?: HttpMethod;
|
|
40
|
+
path?: string;
|
|
34
41
|
params: TParams;
|
|
35
42
|
response: TResponse;
|
|
36
43
|
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
@@ -41,20 +48,27 @@ interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TRespons
|
|
|
41
48
|
}
|
|
42
49
|
type HandlerContext = Record<string, any>;
|
|
43
50
|
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
51
|
+
rpcName: string;
|
|
44
52
|
params: TParams;
|
|
45
53
|
}
|
|
46
54
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
47
55
|
response: TResponse;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
58
|
+
context: RpcHandlerContext<TParams>;
|
|
59
|
+
}
|
|
60
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
61
|
+
context: RpcPostHandlerContext<TParams, TResponse>;
|
|
62
|
+
}
|
|
63
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
64
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
51
65
|
declare function isRpc(input: any): input is ArriProcedure<any, any>;
|
|
52
66
|
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
53
67
|
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
54
68
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
55
69
|
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
56
70
|
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
57
|
-
declare function registerRpc(router: Router, path: string, procedure:
|
|
71
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriNamedProcedure<any, any>, opts: RouteOptions): void;
|
|
58
72
|
|
|
59
73
|
interface ArriRouterBase {
|
|
60
74
|
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
@@ -103,10 +117,10 @@ interface ArriOptions {
|
|
|
103
117
|
* This parameters also takes the rpcRoutePrefix option into account
|
|
104
118
|
*/
|
|
105
119
|
rpcDefinitionPath?: string;
|
|
106
|
-
onRequest?: (event:
|
|
107
|
-
onAfterResponse?: (event:
|
|
108
|
-
onBeforeResponse?: (event:
|
|
109
|
-
onError?: (error: H3Error, event:
|
|
120
|
+
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
121
|
+
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
122
|
+
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
123
|
+
onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
@@ -143,4 +157,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
143
157
|
declare const defaultConfig: Required<ArriConfig>;
|
|
144
158
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
145
159
|
|
|
146
|
-
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 ResolvedArriConfig, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
2
|
import * as arri_validate from 'arri-validate';
|
|
3
3
|
import { AObjectSchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
-
import {
|
|
4
|
+
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
5
|
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface MiddlewareEventContext extends H3EventContext {
|
|
9
|
+
rpcName?: string;
|
|
10
|
+
}
|
|
11
|
+
interface MiddlewareEvent extends H3Event {
|
|
12
|
+
context: MiddlewareEventContext;
|
|
13
|
+
}
|
|
14
|
+
type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
|
|
9
15
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
10
16
|
type ExtractParam$1<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
11
17
|
type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam$1<Segment, ExtractParams$1<Rest>> : ExtractParam$1<Path, {}>;
|
|
@@ -31,6 +37,7 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
|
|
|
31
37
|
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
32
38
|
description?: string;
|
|
33
39
|
method?: HttpMethod;
|
|
40
|
+
path?: string;
|
|
34
41
|
params: TParams;
|
|
35
42
|
response: TResponse;
|
|
36
43
|
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
@@ -41,20 +48,27 @@ interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TRespons
|
|
|
41
48
|
}
|
|
42
49
|
type HandlerContext = Record<string, any>;
|
|
43
50
|
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
51
|
+
rpcName: string;
|
|
44
52
|
params: TParams;
|
|
45
53
|
}
|
|
46
54
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
47
55
|
response: TResponse;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
58
|
+
context: RpcHandlerContext<TParams>;
|
|
59
|
+
}
|
|
60
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
61
|
+
context: RpcPostHandlerContext<TParams, TResponse>;
|
|
62
|
+
}
|
|
63
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
64
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
51
65
|
declare function isRpc(input: any): input is ArriProcedure<any, any>;
|
|
52
66
|
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
53
67
|
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
54
68
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
55
69
|
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
56
70
|
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
57
|
-
declare function registerRpc(router: Router, path: string, procedure:
|
|
71
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriNamedProcedure<any, any>, opts: RouteOptions): void;
|
|
58
72
|
|
|
59
73
|
interface ArriRouterBase {
|
|
60
74
|
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
@@ -103,10 +117,10 @@ interface ArriOptions {
|
|
|
103
117
|
* This parameters also takes the rpcRoutePrefix option into account
|
|
104
118
|
*/
|
|
105
119
|
rpcDefinitionPath?: string;
|
|
106
|
-
onRequest?: (event:
|
|
107
|
-
onAfterResponse?: (event:
|
|
108
|
-
onBeforeResponse?: (event:
|
|
109
|
-
onError?: (error: H3Error, event:
|
|
120
|
+
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
121
|
+
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
122
|
+
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
123
|
+
onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
@@ -143,4 +157,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
143
157
|
declare const defaultConfig: Required<ArriConfig>;
|
|
144
158
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
145
159
|
|
|
146
|
-
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 ResolvedArriConfig, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { HttpMethod, RpcDefinition, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
2
|
import * as arri_validate from 'arri-validate';
|
|
3
3
|
import { AObjectSchema, InferType, a, ValidationError } from 'arri-validate';
|
|
4
|
-
import {
|
|
4
|
+
import { H3EventContext, H3Event, Router, App, H3Error } from 'h3';
|
|
5
5
|
export * from 'h3';
|
|
6
6
|
import { BuildOptions } from 'esbuild';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface MiddlewareEventContext extends H3EventContext {
|
|
9
|
+
rpcName?: string;
|
|
10
|
+
}
|
|
11
|
+
interface MiddlewareEvent extends H3Event {
|
|
12
|
+
context: MiddlewareEventContext;
|
|
13
|
+
}
|
|
14
|
+
type Middleware = (event: MiddlewareEvent) => void | Promise<void>;
|
|
9
15
|
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
10
16
|
type ExtractParam$1<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
11
17
|
type ExtractParams$1<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam$1<Segment, ExtractParams$1<Rest>> : ExtractParam$1<Path, {}>;
|
|
@@ -31,6 +37,7 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
|
|
|
31
37
|
interface ArriProcedure<TParams extends AObjectSchema | undefined, TResponse extends AObjectSchema | undefined> {
|
|
32
38
|
description?: string;
|
|
33
39
|
method?: HttpMethod;
|
|
40
|
+
path?: string;
|
|
34
41
|
params: TParams;
|
|
35
42
|
response: TResponse;
|
|
36
43
|
handler: ArriProcedureHandler<TParams extends AObjectSchema ? InferType<TParams> : undefined, TResponse extends AObjectSchema ? InferType<TResponse> : void>;
|
|
@@ -41,20 +48,27 @@ interface ArriNamedProcedure<TParams extends AObjectSchema | undefined, TRespons
|
|
|
41
48
|
}
|
|
42
49
|
type HandlerContext = Record<string, any>;
|
|
43
50
|
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
51
|
+
rpcName: string;
|
|
44
52
|
params: TParams;
|
|
45
53
|
}
|
|
46
54
|
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
47
55
|
response: TResponse;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
58
|
+
context: RpcHandlerContext<TParams>;
|
|
59
|
+
}
|
|
60
|
+
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
61
|
+
context: RpcPostHandlerContext<TParams, TResponse>;
|
|
62
|
+
}
|
|
63
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
64
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
51
65
|
declare function isRpc(input: any): input is ArriProcedure<any, any>;
|
|
52
66
|
declare function defineRpc<TParams extends AObjectSchema | undefined = undefined, TResponse extends AObjectSchema | undefined | never = undefined>(config: ArriProcedure<TParams, TResponse>): ArriProcedure<TParams, TResponse>;
|
|
53
67
|
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any>): RpcDefinition;
|
|
54
68
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
55
69
|
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
56
70
|
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any>): string | undefined;
|
|
57
|
-
declare function registerRpc(router: Router, path: string, procedure:
|
|
71
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriNamedProcedure<any, any>, opts: RouteOptions): void;
|
|
58
72
|
|
|
59
73
|
interface ArriRouterBase {
|
|
60
74
|
rpc: <TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: ArriNamedProcedure<TParams, TResponse>) => void;
|
|
@@ -103,10 +117,10 @@ interface ArriOptions {
|
|
|
103
117
|
* This parameters also takes the rpcRoutePrefix option into account
|
|
104
118
|
*/
|
|
105
119
|
rpcDefinitionPath?: string;
|
|
106
|
-
onRequest?: (event:
|
|
107
|
-
onAfterResponse?: (event:
|
|
108
|
-
onBeforeResponse?: (event:
|
|
109
|
-
onError?: (error: H3Error, event:
|
|
120
|
+
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
121
|
+
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
122
|
+
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
123
|
+
onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
declare const ErrorResponse: arri_validate.AObjectSchema<{
|
|
@@ -143,4 +157,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
143
157
|
declare const defaultConfig: Required<ArriConfig>;
|
|
144
158
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
145
159
|
|
|
146
|
-
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 ResolvedArriConfig, type RpcHandlerContext, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineMiddleware, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, isArriConfig, isResolvedArriConfig, isRpc, registerRpc };
|
|
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 };
|
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.74120afa.mjs';
|
|
2
2
|
export * from 'h3';
|
|
3
3
|
import 'arri-validate';
|
|
4
4
|
import 'arri-codegen-utils';
|
|
@@ -270,10 +270,10 @@ function getRpcResponseDefinition(rpcName, procedure) {
|
|
|
270
270
|
return name;
|
|
271
271
|
}
|
|
272
272
|
function registerRpc(router, path, procedure, opts) {
|
|
273
|
-
const paramValidator = procedure.params ? a.compile(procedure.params) : void 0;
|
|
274
273
|
const responseValidator = procedure.response ? a.compile(procedure.response) : void 0;
|
|
275
274
|
const httpMethod = procedure.method ?? "post";
|
|
276
275
|
const handler = eventHandler(async (event) => {
|
|
276
|
+
event.context.rpcName = procedure.name;
|
|
277
277
|
if (isPreflightRequest(event)) {
|
|
278
278
|
return "ok";
|
|
279
279
|
}
|
|
@@ -286,7 +286,7 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
286
286
|
await m(event);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
if (isAObjectSchema(procedure.params)
|
|
289
|
+
if (isAObjectSchema(procedure.params)) {
|
|
290
290
|
switch (httpMethod) {
|
|
291
291
|
case "get":
|
|
292
292
|
case "head": {
|
|
@@ -326,7 +326,10 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
326
326
|
statusMessage: `Invalid request body. Expected object. Got undefined.`
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
|
-
const parsedParams =
|
|
329
|
+
const parsedParams = a.safeParse(
|
|
330
|
+
procedure.params,
|
|
331
|
+
body
|
|
332
|
+
);
|
|
330
333
|
if (!parsedParams.success) {
|
|
331
334
|
const errorParts = [];
|
|
332
335
|
for (const err of parsedParams.error.errors) {
|
|
@@ -365,21 +368,8 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
365
368
|
responseValidator?.serialize(response) ?? JSON.stringify(response)
|
|
366
369
|
);
|
|
367
370
|
} else {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
response ?? `<!doctype html>
|
|
371
|
-
<html lang="en">
|
|
372
|
-
<head>
|
|
373
|
-
<meta charset="UTF-8" />
|
|
374
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
375
|
-
<title>Empty Response</title>
|
|
376
|
-
</head>
|
|
377
|
-
<body>
|
|
378
|
-
nothing to see here
|
|
379
|
-
</body>
|
|
380
|
-
</html>
|
|
381
|
-
`
|
|
382
|
-
);
|
|
371
|
+
setResponseHeader(event, "Content-Type", "application/json");
|
|
372
|
+
await send(event, `{}`);
|
|
383
373
|
}
|
|
384
374
|
if (opts.onAfterResponse) {
|
|
385
375
|
await opts.onAfterResponse(event);
|
|
@@ -451,6 +441,9 @@ function registerRoute(router, route, opts) {
|
|
|
451
441
|
}
|
|
452
442
|
function handleRoute(router, method, route, opts) {
|
|
453
443
|
const handler = defineEventHandler(async (event) => {
|
|
444
|
+
if (isPreflightRequest(event)) {
|
|
445
|
+
return "ok";
|
|
446
|
+
}
|
|
454
447
|
try {
|
|
455
448
|
if (opts.onRequest) {
|
|
456
449
|
await opts.onRequest(event);
|
|
@@ -482,6 +475,7 @@ function handleRoute(router, method, route, opts) {
|
|
|
482
475
|
} catch (err) {
|
|
483
476
|
await handleH3Error(err, event, opts.onError);
|
|
484
477
|
}
|
|
478
|
+
return "";
|
|
485
479
|
});
|
|
486
480
|
switch (method) {
|
|
487
481
|
case "get":
|
|
@@ -532,6 +526,7 @@ class ArriApp {
|
|
|
532
526
|
this.h3App = createApp({
|
|
533
527
|
debug: opts?.debug
|
|
534
528
|
});
|
|
529
|
+
this.onRequest = opts.onRequest;
|
|
535
530
|
this.onError = opts.onError;
|
|
536
531
|
this.onAfterResponse = opts.onAfterResponse;
|
|
537
532
|
this.onBeforeResponse = opts.onBeforeResponse;
|
|
@@ -554,6 +549,9 @@ class ArriApp {
|
|
|
554
549
|
setResponseStatus(event, 404);
|
|
555
550
|
const error = defineError(404);
|
|
556
551
|
try {
|
|
552
|
+
if (this.onRequest) {
|
|
553
|
+
await this.onRequest(event);
|
|
554
|
+
}
|
|
557
555
|
if (this.middlewares.length) {
|
|
558
556
|
for (const m of this.middlewares) {
|
|
559
557
|
await m(event);
|
|
@@ -588,7 +586,7 @@ class ArriApp {
|
|
|
588
586
|
this.middlewares.push(input);
|
|
589
587
|
}
|
|
590
588
|
rpc(procedure) {
|
|
591
|
-
const path = getRpcPath(procedure.name, this.rpcRoutePrefix);
|
|
589
|
+
const path = procedure.path ?? getRpcPath(procedure.name, this.rpcRoutePrefix);
|
|
592
590
|
this.procedures[procedure.name] = createRpcDefinition(
|
|
593
591
|
procedure.name,
|
|
594
592
|
path,
|
|
@@ -608,6 +606,7 @@ class ArriApp {
|
|
|
608
606
|
}
|
|
609
607
|
registerRpc(this.h3Router, path, procedure, {
|
|
610
608
|
middleware: this.middlewares,
|
|
609
|
+
onRequest: this.onRequest,
|
|
611
610
|
onError: this.onError,
|
|
612
611
|
onAfterResponse: this.onAfterResponse,
|
|
613
612
|
onBeforeResponse: this.onBeforeResponse
|
|
@@ -616,6 +615,7 @@ class ArriApp {
|
|
|
616
615
|
route(route) {
|
|
617
616
|
registerRoute(this.h3Router, route, {
|
|
618
617
|
middleware: this.middlewares,
|
|
618
|
+
onRequest: this.onRequest,
|
|
619
619
|
onError: this.onError,
|
|
620
620
|
onAfterResponse: this.onAfterResponse,
|
|
621
621
|
onBeforeResponse: this.onBeforeResponse
|
|
@@ -626,8 +626,7 @@ class ArriApp {
|
|
|
626
626
|
arriSchemaVersion: "0.0.2",
|
|
627
627
|
info: this.appInfo,
|
|
628
628
|
procedures: {},
|
|
629
|
-
models: this.models
|
|
630
|
-
errors: ErrorResponse
|
|
629
|
+
models: this.models
|
|
631
630
|
};
|
|
632
631
|
for (const key of Object.keys(this.procedures)) {
|
|
633
632
|
const rpc = this.procedures[key];
|
|
@@ -272,10 +272,10 @@ function getRpcResponseDefinition(rpcName, procedure) {
|
|
|
272
272
|
return name;
|
|
273
273
|
}
|
|
274
274
|
function registerRpc(router, path, procedure, opts) {
|
|
275
|
-
const paramValidator = procedure.params ? arriValidate.a.compile(procedure.params) : void 0;
|
|
276
275
|
const responseValidator = procedure.response ? arriValidate.a.compile(procedure.response) : void 0;
|
|
277
276
|
const httpMethod = procedure.method ?? "post";
|
|
278
277
|
const handler = h3.eventHandler(async (event) => {
|
|
278
|
+
event.context.rpcName = procedure.name;
|
|
279
279
|
if (h3.isPreflightRequest(event)) {
|
|
280
280
|
return "ok";
|
|
281
281
|
}
|
|
@@ -288,7 +288,7 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
288
288
|
await m(event);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
if (arriValidate.isAObjectSchema(procedure.params)
|
|
291
|
+
if (arriValidate.isAObjectSchema(procedure.params)) {
|
|
292
292
|
switch (httpMethod) {
|
|
293
293
|
case "get":
|
|
294
294
|
case "head": {
|
|
@@ -328,7 +328,10 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
328
328
|
statusMessage: `Invalid request body. Expected object. Got undefined.`
|
|
329
329
|
});
|
|
330
330
|
}
|
|
331
|
-
const parsedParams =
|
|
331
|
+
const parsedParams = arriValidate.a.safeParse(
|
|
332
|
+
procedure.params,
|
|
333
|
+
body
|
|
334
|
+
);
|
|
332
335
|
if (!parsedParams.success) {
|
|
333
336
|
const errorParts = [];
|
|
334
337
|
for (const err of parsedParams.error.errors) {
|
|
@@ -367,21 +370,8 @@ function registerRpc(router, path, procedure, opts) {
|
|
|
367
370
|
responseValidator?.serialize(response) ?? JSON.stringify(response)
|
|
368
371
|
);
|
|
369
372
|
} else {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
response ?? `<!doctype html>
|
|
373
|
-
<html lang="en">
|
|
374
|
-
<head>
|
|
375
|
-
<meta charset="UTF-8" />
|
|
376
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
377
|
-
<title>Empty Response</title>
|
|
378
|
-
</head>
|
|
379
|
-
<body>
|
|
380
|
-
nothing to see here
|
|
381
|
-
</body>
|
|
382
|
-
</html>
|
|
383
|
-
`
|
|
384
|
-
);
|
|
373
|
+
h3.setResponseHeader(event, "Content-Type", "application/json");
|
|
374
|
+
await h3.send(event, `{}`);
|
|
385
375
|
}
|
|
386
376
|
if (opts.onAfterResponse) {
|
|
387
377
|
await opts.onAfterResponse(event);
|
|
@@ -453,6 +443,9 @@ function registerRoute(router, route, opts) {
|
|
|
453
443
|
}
|
|
454
444
|
function handleRoute(router, method, route, opts) {
|
|
455
445
|
const handler = h3.defineEventHandler(async (event) => {
|
|
446
|
+
if (h3.isPreflightRequest(event)) {
|
|
447
|
+
return "ok";
|
|
448
|
+
}
|
|
456
449
|
try {
|
|
457
450
|
if (opts.onRequest) {
|
|
458
451
|
await opts.onRequest(event);
|
|
@@ -484,6 +477,7 @@ function handleRoute(router, method, route, opts) {
|
|
|
484
477
|
} catch (err) {
|
|
485
478
|
await handleH3Error(err, event, opts.onError);
|
|
486
479
|
}
|
|
480
|
+
return "";
|
|
487
481
|
});
|
|
488
482
|
switch (method) {
|
|
489
483
|
case "get":
|
|
@@ -534,6 +528,7 @@ class ArriApp {
|
|
|
534
528
|
this.h3App = h3.createApp({
|
|
535
529
|
debug: opts?.debug
|
|
536
530
|
});
|
|
531
|
+
this.onRequest = opts.onRequest;
|
|
537
532
|
this.onError = opts.onError;
|
|
538
533
|
this.onAfterResponse = opts.onAfterResponse;
|
|
539
534
|
this.onBeforeResponse = opts.onBeforeResponse;
|
|
@@ -556,6 +551,9 @@ class ArriApp {
|
|
|
556
551
|
h3.setResponseStatus(event, 404);
|
|
557
552
|
const error = defineError(404);
|
|
558
553
|
try {
|
|
554
|
+
if (this.onRequest) {
|
|
555
|
+
await this.onRequest(event);
|
|
556
|
+
}
|
|
559
557
|
if (this.middlewares.length) {
|
|
560
558
|
for (const m of this.middlewares) {
|
|
561
559
|
await m(event);
|
|
@@ -590,7 +588,7 @@ class ArriApp {
|
|
|
590
588
|
this.middlewares.push(input);
|
|
591
589
|
}
|
|
592
590
|
rpc(procedure) {
|
|
593
|
-
const path = getRpcPath(procedure.name, this.rpcRoutePrefix);
|
|
591
|
+
const path = procedure.path ?? getRpcPath(procedure.name, this.rpcRoutePrefix);
|
|
594
592
|
this.procedures[procedure.name] = createRpcDefinition(
|
|
595
593
|
procedure.name,
|
|
596
594
|
path,
|
|
@@ -610,6 +608,7 @@ class ArriApp {
|
|
|
610
608
|
}
|
|
611
609
|
registerRpc(this.h3Router, path, procedure, {
|
|
612
610
|
middleware: this.middlewares,
|
|
611
|
+
onRequest: this.onRequest,
|
|
613
612
|
onError: this.onError,
|
|
614
613
|
onAfterResponse: this.onAfterResponse,
|
|
615
614
|
onBeforeResponse: this.onBeforeResponse
|
|
@@ -618,6 +617,7 @@ class ArriApp {
|
|
|
618
617
|
route(route) {
|
|
619
618
|
registerRoute(this.h3Router, route, {
|
|
620
619
|
middleware: this.middlewares,
|
|
620
|
+
onRequest: this.onRequest,
|
|
621
621
|
onError: this.onError,
|
|
622
622
|
onAfterResponse: this.onAfterResponse,
|
|
623
623
|
onBeforeResponse: this.onBeforeResponse
|
|
@@ -628,8 +628,7 @@ class ArriApp {
|
|
|
628
628
|
arriSchemaVersion: "0.0.2",
|
|
629
629
|
info: this.appInfo,
|
|
630
630
|
procedures: {},
|
|
631
|
-
models: this.models
|
|
632
|
-
errors: ErrorResponse
|
|
631
|
+
models: this.models
|
|
633
632
|
};
|
|
634
633
|
for (const key of Object.keys(this.procedures)) {
|
|
635
634
|
const rpc = this.procedures[key];
|
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.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"chokidar": "^3.5.3",
|
|
23
23
|
"citty": "^0.1.4",
|
|
24
24
|
"consola": "^3.2.3",
|
|
25
|
-
"esbuild": "^0.19.
|
|
25
|
+
"esbuild": "^0.19.4",
|
|
26
26
|
"globby": "^13.2.2",
|
|
27
27
|
"h3": "^1.8.2",
|
|
28
28
|
"jiti": "^1.20.0",
|
|
@@ -31,12 +31,12 @@
|
|
|
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-
|
|
36
|
-
"arri-
|
|
37
|
-
"arri-codegen-
|
|
34
|
+
"arri-codegen-dart": "0.1.0-beta.4",
|
|
35
|
+
"arri-codegen-utils": "0.1.0-beta.4",
|
|
36
|
+
"arri-validate": "0.1.0-beta.4",
|
|
37
|
+
"arri-codegen-ts": "0.1.0-beta.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"bun-types": "^1.0.
|
|
40
|
+
"bun-types": "^1.0.5"
|
|
41
41
|
}
|
|
42
42
|
}
|