arri 0.34.0 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,6 +18,7 @@ Typescript implementation of Arri RPC. It's built on top of [H3](https://github.
18
18
  - [Key Concepts](#key-concepts)
19
19
  - [Arri Definition File](#arri-definition-file)
20
20
  - [How Procedures Map To Endpoints](#how-procedures-map-to-endpoints)
21
+ - [H3 Support](#h3-support)
21
22
  - [Arri CLI](#arri-cli)
22
23
 
23
24
  ## Quickstart
@@ -480,6 +481,37 @@ The supported HTTP methods are as follows:
480
481
 
481
482
  When using a get method the RPC params will be mapped as query parameters which will be coerced into their type using the `a.coerce` method from `arri-validate`. Get methods support all basic scalar types however arrays and nested objects are not supported.
482
483
 
484
+ ### H3 Support
485
+ Arri is built on top of [H3](https://h3.unjs.io/utils/request#getrequestipevent) so many of the concepts that apply to H3 also apply to Arri.
486
+
487
+ #### Accessing Utilities
488
+ Arri re-eports all of the H3 utilities.
489
+
490
+ ```ts
491
+ import { getRequestIP, setResponseHeader } from 'arri';
492
+ ```
493
+
494
+ #### Accessing H3 Events
495
+ You can access H3 events from inside procedures handlers.
496
+
497
+ ```ts
498
+ defineRpc({
499
+ params: undefined,
500
+ response: undefined,
501
+ handler(_, event) {
502
+ getRequestIP(event);
503
+ }
504
+ )
505
+
506
+ defineEventStreamRpc({
507
+ params: undefined,
508
+ response: undefined,
509
+ handler(_, event) {
510
+ getRequestIP(event);
511
+ }
512
+ )
513
+ ```
514
+
483
515
  ## Arri CLI
484
516
 
485
517
  ```bash
package/dist/cli.cjs CHANGED
@@ -11,7 +11,7 @@ const esbuild = require('esbuild');
11
11
  const esbuildPluginReplace = require('esbuild-plugin-replace');
12
12
  const path = require('pathe');
13
13
  const prettier = require('prettier');
14
- const config = require('./shared/arri.0dce1db1.cjs');
14
+ const config = require('./shared/arri.8e96548e.cjs');
15
15
  const consola = require('consola');
16
16
  const globby = require('globby');
17
17
  const scule = require('scule');
@@ -526,13 +526,19 @@ async function startDevServer(config) {
526
526
  if (fileWatcher) {
527
527
  await fileWatcher.close();
528
528
  }
529
- const dirToWatch = path__default.resolve(
530
- config.rootDir ?? "",
531
- config.srcDir
532
- );
529
+ const srcDir = path__default.resolve(config.rootDir ?? "", config.srcDir);
530
+ const dirsToWatch = [srcDir];
531
+ if (config.esbuild.alias) {
532
+ for (const key of Object.keys(config.esbuild.alias)) {
533
+ const alias = config.esbuild.alias[key];
534
+ if (alias) {
535
+ dirsToWatch.push(alias);
536
+ }
537
+ }
538
+ }
533
539
  const buildDir = path__default.resolve(config.rootDir, config.buildDir);
534
540
  const outDir = path__default.resolve(config.rootDir, ".output");
535
- fileWatcher = chokidar__default.watch([path__default.resolve(dirToWatch)], {
541
+ fileWatcher = chokidar__default.watch(dirsToWatch, {
536
542
  ignored: [buildDir, outDir],
537
543
  ignoreInitial: true
538
544
  });
package/dist/cli.mjs CHANGED
@@ -10,7 +10,7 @@ import { build as build$1 } from 'esbuild';
10
10
  import { replace } from 'esbuild-plugin-replace';
11
11
  import path from 'pathe';
12
12
  import prettier from 'prettier';
13
- import { o as defaultConfig, m as isArriConfig, n as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.1b62504f.mjs';
13
+ import { q as defaultConfig, o as isArriConfig, p as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.b1ff441a.mjs';
14
14
  import { createConsola } from 'consola';
15
15
  import { globby } from 'globby';
16
16
  import { camelCase, kebabCase } from 'scule';
@@ -502,13 +502,19 @@ async function startDevServer(config) {
502
502
  if (fileWatcher) {
503
503
  await fileWatcher.close();
504
504
  }
505
- const dirToWatch = path.resolve(
506
- config.rootDir ?? "",
507
- config.srcDir
508
- );
505
+ const srcDir = path.resolve(config.rootDir ?? "", config.srcDir);
506
+ const dirsToWatch = [srcDir];
507
+ if (config.esbuild.alias) {
508
+ for (const key of Object.keys(config.esbuild.alias)) {
509
+ const alias = config.esbuild.alias[key];
510
+ if (alias) {
511
+ dirsToWatch.push(alias);
512
+ }
513
+ }
514
+ }
509
515
  const buildDir = path.resolve(config.rootDir, config.buildDir);
510
516
  const outDir = path.resolve(config.rootDir, ".output");
511
- fileWatcher = chokidar.watch([path.resolve(dirToWatch)], {
517
+ fileWatcher = chokidar.watch(dirsToWatch, {
512
518
  ignored: [buildDir, outDir],
513
519
  ignoreInitial: true
514
520
  });
package/dist/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const config = require('./shared/arri.0dce1db1.cjs');
3
+ const config = require('./shared/arri.8e96548e.cjs');
4
4
  const h3 = require('h3');
5
5
  require('arri-codegen-utils');
6
+ require('consola');
6
7
  require('arri-validate');
7
8
  require('h3-sse');
8
9
  require('scule');
@@ -11,9 +12,10 @@ const defineMiddleware = (middleware) => middleware;
11
12
 
12
13
  exports.ArriApp = config.ArriApp;
13
14
  exports.ArriRouter = config.ArriRouter;
15
+ exports.ArriServerError = config.ArriServerError;
16
+ exports.ArriServerErrorResponse = config.ArriServerErrorResponse;
14
17
  exports.DEV_DEFINITION_ENDPOINT = config.DEV_DEFINITION_ENDPOINT;
15
18
  exports.DEV_ENDPOINT_ROOT = config.DEV_ENDPOINT_ROOT;
16
- exports.ErrorResponse = config.ErrorResponse;
17
19
  exports.EventStreamConnection = config.EventStreamConnection;
18
20
  exports.createAppDefinition = config.createAppDefinition;
19
21
  exports.createHttpRpcDefinition = config.createHttpRpcDefinition;
package/dist/index.d.cts CHANGED
@@ -1,10 +1,32 @@
1
1
  import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
- import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
2
+ import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
+ import { H3Error, H3Event, H3EventContext, Router, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { EventStream } from 'h3-sse';
6
6
  import { BuildOptions } from 'esbuild';
7
7
 
8
+ declare class ArriServerError extends Error {
9
+ code: number;
10
+ data?: any;
11
+ constructor(err: {
12
+ code: number;
13
+ message: string;
14
+ data?: any;
15
+ stack?: string;
16
+ });
17
+ }
18
+ declare const ArriServerErrorResponse: AObjectSchema<{
19
+ code: number;
20
+ message: string;
21
+ stack?: string[] | undefined;
22
+ data?: any;
23
+ }, false>;
24
+ type ArriServerErrorResponse = a.infer<typeof ArriServerErrorResponse>;
25
+ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ArriServerErrorResponse, "code" | "stack">>): ArriServerError;
26
+ declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
27
+ type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
28
+ declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
29
+
8
30
  interface MiddlewareEventContext extends H3EventContext {
9
31
  rpcName?: string;
10
32
  }
@@ -39,26 +61,12 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
39
61
  postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
40
62
  }
41
63
  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>;
42
- type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
64
+ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest" | "debug"> & {
43
65
  middleware: Middleware[];
44
66
  };
45
67
  declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
46
68
  declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
47
69
 
48
- declare const ErrorResponse: AObjectSchema<{
49
- statusCode: number;
50
- statusMessage: string;
51
- stack?: string | undefined;
52
- data?: any;
53
- }, false>;
54
- type ErrorResponse = a.infer<typeof ErrorResponse>;
55
- declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
56
- stack?: string;
57
- }): H3Error;
58
- declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
59
- type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
60
- declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
61
-
62
70
  declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream">): EventStreamRpc<TParams, TResponse>;
63
71
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
64
72
  interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
@@ -96,7 +104,7 @@ declare class EventStreamConnection<TData> {
96
104
  /**
97
105
  * Publish an error event. This will trigger the `onError` hooks of any connected clients.
98
106
  */
99
- pushError(error: ErrorResponse, eventId?: string): Promise<void>;
107
+ pushError(error: ArriServerErrorResponse, eventId?: string): Promise<void>;
100
108
  private cleanup;
101
109
  /**
102
110
  * Tell clients that the stream has ended and close the connection.
@@ -176,16 +184,18 @@ declare class ArriApp implements ArriRouterBase {
176
184
  __isArri__: boolean;
177
185
  readonly h3App: App;
178
186
  readonly h3Router: Router;
179
- private readonly rpcDefinitionPath;
180
- private readonly rpcRoutePrefix;
187
+ private readonly _rpcDefinitionPath;
188
+ private readonly _rpcRoutePrefix;
181
189
  appInfo: AppDefinition["info"];
182
- private procedures;
183
- private models;
184
- private readonly middlewares;
185
- private readonly onRequest;
186
- private readonly onAfterResponse;
187
- private readonly onBeforeResponse;
188
- private readonly onError;
190
+ private _procedures;
191
+ private _models;
192
+ private readonly _middlewares;
193
+ private readonly _onRequest;
194
+ private readonly _onAfterResponse;
195
+ private readonly _onBeforeResponse;
196
+ private readonly _onError;
197
+ private readonly _debug;
198
+ readonly definitionPath: string;
189
199
  constructor(opts?: ArriOptions);
190
200
  use(input: Middleware | ArriRouter): void;
191
201
  rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: NamedRpc<TIsEventStream, TParams, TResponse>): void;
@@ -208,7 +218,7 @@ interface ArriOptions {
208
218
  onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
209
219
  onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
210
220
  onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
211
- onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
221
+ onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
212
222
  }
213
223
 
214
224
  interface ArriConfig {
@@ -238,4 +248,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
238
248
  declare const defaultConfig: Required<ArriConfig>;
239
249
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
240
250
 
241
- export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
251
+ export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, ArriServerError, ArriServerErrorResponse, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,32 @@
1
1
  import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
- import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
2
+ import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
+ import { H3Error, H3Event, H3EventContext, Router, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { EventStream } from 'h3-sse';
6
6
  import { BuildOptions } from 'esbuild';
7
7
 
8
+ declare class ArriServerError extends Error {
9
+ code: number;
10
+ data?: any;
11
+ constructor(err: {
12
+ code: number;
13
+ message: string;
14
+ data?: any;
15
+ stack?: string;
16
+ });
17
+ }
18
+ declare const ArriServerErrorResponse: AObjectSchema<{
19
+ code: number;
20
+ message: string;
21
+ stack?: string[] | undefined;
22
+ data?: any;
23
+ }, false>;
24
+ type ArriServerErrorResponse = a.infer<typeof ArriServerErrorResponse>;
25
+ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ArriServerErrorResponse, "code" | "stack">>): ArriServerError;
26
+ declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
27
+ type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
28
+ declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
29
+
8
30
  interface MiddlewareEventContext extends H3EventContext {
9
31
  rpcName?: string;
10
32
  }
@@ -39,26 +61,12 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
39
61
  postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
40
62
  }
41
63
  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>;
42
- type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
64
+ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest" | "debug"> & {
43
65
  middleware: Middleware[];
44
66
  };
45
67
  declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
46
68
  declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
47
69
 
48
- declare const ErrorResponse: AObjectSchema<{
49
- statusCode: number;
50
- statusMessage: string;
51
- stack?: string | undefined;
52
- data?: any;
53
- }, false>;
54
- type ErrorResponse = a.infer<typeof ErrorResponse>;
55
- declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
56
- stack?: string;
57
- }): H3Error;
58
- declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
59
- type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
60
- declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
61
-
62
70
  declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream">): EventStreamRpc<TParams, TResponse>;
63
71
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
64
72
  interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
@@ -96,7 +104,7 @@ declare class EventStreamConnection<TData> {
96
104
  /**
97
105
  * Publish an error event. This will trigger the `onError` hooks of any connected clients.
98
106
  */
99
- pushError(error: ErrorResponse, eventId?: string): Promise<void>;
107
+ pushError(error: ArriServerErrorResponse, eventId?: string): Promise<void>;
100
108
  private cleanup;
101
109
  /**
102
110
  * Tell clients that the stream has ended and close the connection.
@@ -176,16 +184,18 @@ declare class ArriApp implements ArriRouterBase {
176
184
  __isArri__: boolean;
177
185
  readonly h3App: App;
178
186
  readonly h3Router: Router;
179
- private readonly rpcDefinitionPath;
180
- private readonly rpcRoutePrefix;
187
+ private readonly _rpcDefinitionPath;
188
+ private readonly _rpcRoutePrefix;
181
189
  appInfo: AppDefinition["info"];
182
- private procedures;
183
- private models;
184
- private readonly middlewares;
185
- private readonly onRequest;
186
- private readonly onAfterResponse;
187
- private readonly onBeforeResponse;
188
- private readonly onError;
190
+ private _procedures;
191
+ private _models;
192
+ private readonly _middlewares;
193
+ private readonly _onRequest;
194
+ private readonly _onAfterResponse;
195
+ private readonly _onBeforeResponse;
196
+ private readonly _onError;
197
+ private readonly _debug;
198
+ readonly definitionPath: string;
189
199
  constructor(opts?: ArriOptions);
190
200
  use(input: Middleware | ArriRouter): void;
191
201
  rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: NamedRpc<TIsEventStream, TParams, TResponse>): void;
@@ -208,7 +218,7 @@ interface ArriOptions {
208
218
  onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
209
219
  onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
210
220
  onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
211
- onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
221
+ onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
212
222
  }
213
223
 
214
224
  interface ArriConfig {
@@ -238,4 +248,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
238
248
  declare const defaultConfig: Required<ArriConfig>;
239
249
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
240
250
 
241
- export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
251
+ export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, ArriServerError, ArriServerErrorResponse, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,32 @@
1
1
  import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
- import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
2
+ import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
+ import { H3Error, H3Event, H3EventContext, Router, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { EventStream } from 'h3-sse';
6
6
  import { BuildOptions } from 'esbuild';
7
7
 
8
+ declare class ArriServerError extends Error {
9
+ code: number;
10
+ data?: any;
11
+ constructor(err: {
12
+ code: number;
13
+ message: string;
14
+ data?: any;
15
+ stack?: string;
16
+ });
17
+ }
18
+ declare const ArriServerErrorResponse: AObjectSchema<{
19
+ code: number;
20
+ message: string;
21
+ stack?: string[] | undefined;
22
+ data?: any;
23
+ }, false>;
24
+ type ArriServerErrorResponse = a.infer<typeof ArriServerErrorResponse>;
25
+ declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ArriServerErrorResponse, "code" | "stack">>): ArriServerError;
26
+ declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
27
+ type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
28
+ declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
29
+
8
30
  interface MiddlewareEventContext extends H3EventContext {
9
31
  rpcName?: string;
10
32
  }
@@ -39,26 +61,12 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
39
61
  postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
40
62
  }
41
63
  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>;
42
- type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest"> & {
64
+ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "onError" | "onRequest" | "debug"> & {
43
65
  middleware: Middleware[];
44
66
  };
45
67
  declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
46
68
  declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
47
69
 
48
- declare const ErrorResponse: AObjectSchema<{
49
- statusCode: number;
50
- statusMessage: string;
51
- stack?: string | undefined;
52
- data?: any;
53
- }, false>;
54
- type ErrorResponse = a.infer<typeof ErrorResponse>;
55
- declare function defineError(statusCode: StatusCode, input?: Partial<Omit<ErrorResponse, "statusCode" | "stack">> & {
56
- stack?: string;
57
- }): H3Error;
58
- declare function errorResponseFromValidationErrors(errors: ValidationError["errors"], prefixText?: string): H3Error;
59
- type StatusCode = number | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
60
- declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"]): Promise<void>;
61
-
62
70
  declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream">): EventStreamRpc<TParams, TResponse>;
63
71
  declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
64
72
  interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
@@ -96,7 +104,7 @@ declare class EventStreamConnection<TData> {
96
104
  /**
97
105
  * Publish an error event. This will trigger the `onError` hooks of any connected clients.
98
106
  */
99
- pushError(error: ErrorResponse, eventId?: string): Promise<void>;
107
+ pushError(error: ArriServerErrorResponse, eventId?: string): Promise<void>;
100
108
  private cleanup;
101
109
  /**
102
110
  * Tell clients that the stream has ended and close the connection.
@@ -176,16 +184,18 @@ declare class ArriApp implements ArriRouterBase {
176
184
  __isArri__: boolean;
177
185
  readonly h3App: App;
178
186
  readonly h3Router: Router;
179
- private readonly rpcDefinitionPath;
180
- private readonly rpcRoutePrefix;
187
+ private readonly _rpcDefinitionPath;
188
+ private readonly _rpcRoutePrefix;
181
189
  appInfo: AppDefinition["info"];
182
- private procedures;
183
- private models;
184
- private readonly middlewares;
185
- private readonly onRequest;
186
- private readonly onAfterResponse;
187
- private readonly onBeforeResponse;
188
- private readonly onError;
190
+ private _procedures;
191
+ private _models;
192
+ private readonly _middlewares;
193
+ private readonly _onRequest;
194
+ private readonly _onAfterResponse;
195
+ private readonly _onBeforeResponse;
196
+ private readonly _onError;
197
+ private readonly _debug;
198
+ readonly definitionPath: string;
189
199
  constructor(opts?: ArriOptions);
190
200
  use(input: Middleware | ArriRouter): void;
191
201
  rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: NamedRpc<TIsEventStream, TParams, TResponse>): void;
@@ -208,7 +218,7 @@ interface ArriOptions {
208
218
  onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
209
219
  onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
210
220
  onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
211
- onError?: (error: H3Error, event: MiddlewareEvent) => void | Promise<void>;
221
+ onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
212
222
  }
213
223
 
214
224
  interface ArriConfig {
@@ -238,4 +248,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
238
248
  declare const defaultConfig: Required<ArriConfig>;
239
249
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
240
250
 
241
- export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
251
+ export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, ArriServerError, ArriServerErrorResponse, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- export { A as ArriApp, q as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, y as EventStreamConnection, c as createAppDefinition, e as createHttpRpcDefinition, o as defaultConfig, p as defineConfig, j as defineError, w as defineEventStreamRpc, s as defineRoute, d as defineRpc, k as errorResponseFromValidationErrors, f as getRpcParamName, g as getRpcPath, h as getRpcResponseName, l as handleH3Error, u as handleRoute, m as isArriConfig, x as isEventStreamRpc, n as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, z as registerEventStreamRpc, t as registerRoute, r as registerRpc, v as validateRpcRequestInput } from './shared/arri.1b62504f.mjs';
1
+ export { A as ArriApp, t as ArriRouter, j as ArriServerError, k as ArriServerErrorResponse, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as EventStreamConnection, c as createAppDefinition, e as createHttpRpcDefinition, q as defaultConfig, s as defineConfig, l as defineError, y as defineEventStreamRpc, u as defineRoute, d as defineRpc, m as errorResponseFromValidationErrors, f as getRpcParamName, g as getRpcPath, h as getRpcResponseName, n as handleH3Error, x as handleRoute, o as isArriConfig, z as isEventStreamRpc, p as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, B as registerEventStreamRpc, w as registerRoute, r as registerRpc, v as validateRpcRequestInput } from './shared/arri.b1ff441a.mjs';
2
2
  export * from 'h3';
3
3
  import 'arri-codegen-utils';
4
+ import 'consola';
4
5
  import 'arri-validate';
5
6
  import 'h3-sse';
6
7
  import 'scule';