arri 0.34.0 → 0.36.0
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 +12 -6
- package/dist/cli.mjs +12 -6
- package/dist/index.cjs +3 -2
- package/dist/index.d.cts +38 -29
- package/dist/index.d.mts +38 -29
- package/dist/index.d.ts +38 -29
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.0dce1db1.cjs → arri.087dabd0.cjs} +143 -98
- package/dist/shared/{arri.1b62504f.mjs → arri.b0950dad.mjs} +143 -99
- package/package.json +5 -5
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.
|
|
14
|
+
const config = require('./shared/arri.087dabd0.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
|
|
530
|
-
|
|
531
|
-
|
|
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(
|
|
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 {
|
|
13
|
+
import { q as defaultConfig, o as isArriConfig, p as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.b0950dad.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
|
|
506
|
-
|
|
507
|
-
|
|
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(
|
|
517
|
+
fileWatcher = chokidar.watch(dirsToWatch, {
|
|
512
518
|
ignored: [buildDir, outDir],
|
|
513
519
|
ignoreInitial: true
|
|
514
520
|
});
|
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.087dabd0.cjs');
|
|
4
4
|
const h3 = require('h3');
|
|
5
5
|
require('arri-codegen-utils');
|
|
6
6
|
require('arri-validate');
|
|
@@ -11,9 +11,10 @@ const defineMiddleware = (middleware) => middleware;
|
|
|
11
11
|
|
|
12
12
|
exports.ArriApp = config.ArriApp;
|
|
13
13
|
exports.ArriRouter = config.ArriRouter;
|
|
14
|
+
exports.ArriServerError = config.ArriServerError;
|
|
15
|
+
exports.ArriServerErrorResponse = config.ArriServerErrorResponse;
|
|
14
16
|
exports.DEV_DEFINITION_ENDPOINT = config.DEV_DEFINITION_ENDPOINT;
|
|
15
17
|
exports.DEV_ENDPOINT_ROOT = config.DEV_ENDPOINT_ROOT;
|
|
16
|
-
exports.ErrorResponse = config.ErrorResponse;
|
|
17
18
|
exports.EventStreamConnection = config.EventStreamConnection;
|
|
18
19
|
exports.createAppDefinition = config.createAppDefinition;
|
|
19
20
|
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,
|
|
3
|
-
import {
|
|
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:
|
|
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,17 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
176
184
|
__isArri__: boolean;
|
|
177
185
|
readonly h3App: App;
|
|
178
186
|
readonly h3Router: Router;
|
|
179
|
-
private readonly
|
|
180
|
-
private readonly
|
|
187
|
+
private readonly _rpcDefinitionPath;
|
|
188
|
+
private readonly _rpcRoutePrefix;
|
|
181
189
|
appInfo: AppDefinition["info"];
|
|
182
|
-
private
|
|
183
|
-
private
|
|
184
|
-
private readonly
|
|
185
|
-
private readonly
|
|
186
|
-
private readonly
|
|
187
|
-
private readonly
|
|
188
|
-
private readonly
|
|
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;
|
|
189
198
|
constructor(opts?: ArriOptions);
|
|
190
199
|
use(input: Middleware | ArriRouter): void;
|
|
191
200
|
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 +217,7 @@ interface ArriOptions {
|
|
|
208
217
|
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
209
218
|
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
210
219
|
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
211
|
-
onError?: (error:
|
|
220
|
+
onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
interface ArriConfig {
|
|
@@ -238,4 +247,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
238
247
|
declare const defaultConfig: Required<ArriConfig>;
|
|
239
248
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
240
249
|
|
|
241
|
-
export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT,
|
|
250
|
+
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,
|
|
3
|
-
import {
|
|
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:
|
|
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,17 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
176
184
|
__isArri__: boolean;
|
|
177
185
|
readonly h3App: App;
|
|
178
186
|
readonly h3Router: Router;
|
|
179
|
-
private readonly
|
|
180
|
-
private readonly
|
|
187
|
+
private readonly _rpcDefinitionPath;
|
|
188
|
+
private readonly _rpcRoutePrefix;
|
|
181
189
|
appInfo: AppDefinition["info"];
|
|
182
|
-
private
|
|
183
|
-
private
|
|
184
|
-
private readonly
|
|
185
|
-
private readonly
|
|
186
|
-
private readonly
|
|
187
|
-
private readonly
|
|
188
|
-
private readonly
|
|
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;
|
|
189
198
|
constructor(opts?: ArriOptions);
|
|
190
199
|
use(input: Middleware | ArriRouter): void;
|
|
191
200
|
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 +217,7 @@ interface ArriOptions {
|
|
|
208
217
|
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
209
218
|
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
210
219
|
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
211
|
-
onError?: (error:
|
|
220
|
+
onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
interface ArriConfig {
|
|
@@ -238,4 +247,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
238
247
|
declare const defaultConfig: Required<ArriConfig>;
|
|
239
248
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
240
249
|
|
|
241
|
-
export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT,
|
|
250
|
+
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,
|
|
3
|
-
import {
|
|
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:
|
|
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,17 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
176
184
|
__isArri__: boolean;
|
|
177
185
|
readonly h3App: App;
|
|
178
186
|
readonly h3Router: Router;
|
|
179
|
-
private readonly
|
|
180
|
-
private readonly
|
|
187
|
+
private readonly _rpcDefinitionPath;
|
|
188
|
+
private readonly _rpcRoutePrefix;
|
|
181
189
|
appInfo: AppDefinition["info"];
|
|
182
|
-
private
|
|
183
|
-
private
|
|
184
|
-
private readonly
|
|
185
|
-
private readonly
|
|
186
|
-
private readonly
|
|
187
|
-
private readonly
|
|
188
|
-
private readonly
|
|
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;
|
|
189
198
|
constructor(opts?: ArriOptions);
|
|
190
199
|
use(input: Middleware | ArriRouter): void;
|
|
191
200
|
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 +217,7 @@ interface ArriOptions {
|
|
|
208
217
|
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
209
218
|
onAfterResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
210
219
|
onBeforeResponse?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
211
|
-
onError?: (error:
|
|
220
|
+
onError?: (error: ArriServerError, event: MiddlewareEvent) => void | Promise<void>;
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
interface ArriConfig {
|
|
@@ -238,4 +247,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
238
247
|
declare const defaultConfig: Required<ArriConfig>;
|
|
239
248
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
240
249
|
|
|
241
|
-
export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT,
|
|
250
|
+
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,4 +1,4 @@
|
|
|
1
|
-
export { A as ArriApp,
|
|
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.b0950dad.mjs';
|
|
2
2
|
export * from 'h3';
|
|
3
3
|
import 'arri-codegen-utils';
|
|
4
4
|
import 'arri-validate';
|