arri 0.41.0 → 0.42.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 +70 -1
- package/dist/cli.cjs +8 -8
- package/dist/cli.mjs +8 -8
- package/dist/codegen.cjs +2 -0
- package/dist/codegen.d.cts +1 -0
- package/dist/codegen.d.mts +1 -0
- package/dist/codegen.d.ts +1 -0
- package/dist/codegen.mjs +1 -0
- package/dist/index.d.cts +26 -25
- package/dist/index.d.mts +26 -25
- package/dist/index.d.ts +26 -25
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Typescript implementation of Arri RPC. It's built on top of [H3](https://github.
|
|
|
13
13
|
- [File-Based Routing](#file-based-routing)
|
|
14
14
|
- [Manual Routing](#manual-routing)
|
|
15
15
|
- [Creating Event Stream Procedures](#creating-event-stream-procedures)
|
|
16
|
+
- [Creating Websocket Procedures](#creating-websocket-procedures)
|
|
16
17
|
- [Adding Non-RPC Routes](#adding-non-rpc-routes)
|
|
17
18
|
- [Adding Middleware](#adding-middleware)
|
|
18
19
|
- [Key Concepts](#key-concepts)
|
|
@@ -277,6 +278,68 @@ stream.end()
|
|
|
277
278
|
stream.on(e: 'request:close' | 'close', callback: () => any)
|
|
278
279
|
```
|
|
279
280
|
|
|
281
|
+
### Creating Websocket Procedures
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
// Websocket procedures work really well with discriminated unions
|
|
285
|
+
const IncomingMsg = a.discriminator('type', {
|
|
286
|
+
FOO: a.object({
|
|
287
|
+
message: a.string(),
|
|
288
|
+
}),
|
|
289
|
+
PING: a.object({
|
|
290
|
+
message: a.string(),
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const OutgoingMsg = a.discriminator('type', {
|
|
295
|
+
BAR: a.object({
|
|
296
|
+
message: a.string(),
|
|
297
|
+
}),
|
|
298
|
+
PONG: a.object({
|
|
299
|
+
message: a.string()
|
|
300
|
+
})
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
export default defineWebsocketRpc(
|
|
304
|
+
params: IncomingMsg,
|
|
305
|
+
response: OutgoingMsg,
|
|
306
|
+
handler: {
|
|
307
|
+
onOpen: (peer) => {},
|
|
308
|
+
onMessage: (peer, message) => {
|
|
309
|
+
switch(message.type) {
|
|
310
|
+
case "FOO":
|
|
311
|
+
peer.send({
|
|
312
|
+
type: "BAR",
|
|
313
|
+
message: "You sent a FOO message"
|
|
314
|
+
});
|
|
315
|
+
break;
|
|
316
|
+
case "PING":
|
|
317
|
+
peer.send({
|
|
318
|
+
type: "PONG",
|
|
319
|
+
message: "You sent a PING message"
|
|
320
|
+
});
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
onError: (peer, error) => {}
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Under the hook Websocket RPCs use [crossws](https://crossws.unjs.io/).
|
|
330
|
+
|
|
331
|
+
The possible payloads sent by the server will look like the following:
|
|
332
|
+
|
|
333
|
+
```
|
|
334
|
+
event: message
|
|
335
|
+
data: <response serialized to json>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
event: error
|
|
340
|
+
data: {"code": <some-err-code>, "message": <some-error-msg>}
|
|
341
|
+
```
|
|
342
|
+
|
|
280
343
|
### Adding Non-RPC Routes
|
|
281
344
|
|
|
282
345
|
You can also add generic endpoints for instances when a message-based RPC endpoint doesn't fit.
|
|
@@ -467,16 +530,19 @@ The supported HTTP methods are as follows:
|
|
|
467
530
|
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.
|
|
468
531
|
|
|
469
532
|
### H3 Support
|
|
533
|
+
|
|
470
534
|
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.
|
|
471
535
|
|
|
472
536
|
#### Accessing Utilities
|
|
537
|
+
|
|
473
538
|
Arri re-eports all of the H3 utilities.
|
|
474
539
|
|
|
475
540
|
```ts
|
|
476
|
-
import { getRequestIP, setResponseHeader } from
|
|
541
|
+
import { getRequestIP, setResponseHeader } from "arri";
|
|
477
542
|
```
|
|
478
543
|
|
|
479
544
|
#### Accessing H3 Events
|
|
545
|
+
|
|
480
546
|
You can access H3 events from inside procedures handlers.
|
|
481
547
|
|
|
482
548
|
```ts
|
|
@@ -508,6 +574,9 @@ arri build [flags]
|
|
|
508
574
|
|
|
509
575
|
# create a new project
|
|
510
576
|
arri init [dir]
|
|
577
|
+
|
|
578
|
+
# run codegen
|
|
579
|
+
arri codegen [path-to-definition-file]
|
|
511
580
|
```
|
|
512
581
|
|
|
513
582
|
## Development
|
package/dist/cli.cjs
CHANGED
|
@@ -273,8 +273,8 @@ async function bundleAppEntry(config, allowCodegen = true) {
|
|
|
273
273
|
bundle: true,
|
|
274
274
|
packages: "external",
|
|
275
275
|
format: "esm",
|
|
276
|
-
sourcemap: true,
|
|
277
|
-
|
|
276
|
+
sourcemap: config.esbuild.sourcemap ?? true,
|
|
277
|
+
minify: config.esbuild.minify ?? true,
|
|
278
278
|
banner: {
|
|
279
279
|
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
280
280
|
const require = topLevelCreateRequire(import.meta.url);`
|
|
@@ -503,10 +503,10 @@ export default app.h3App;`;
|
|
|
503
503
|
outfile: path__default.resolve(config.rootDir, ".output", OUT_APP_FILE),
|
|
504
504
|
format: "esm",
|
|
505
505
|
bundle: true,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
506
|
+
packages: "external",
|
|
507
|
+
sourcemap: config.esbuild.sourcemap ?? true,
|
|
508
|
+
target: config.esbuild.target ?? "node20",
|
|
509
|
+
platform: config.esbuild.platform ?? "node"
|
|
510
510
|
});
|
|
511
511
|
}
|
|
512
512
|
async function startDevServer(config) {
|
|
@@ -609,7 +609,7 @@ async function generateClients(config$1) {
|
|
|
609
609
|
}
|
|
610
610
|
logger.log(`Generating client code...`);
|
|
611
611
|
const clientCount = config$1.generators.length;
|
|
612
|
-
await Promise.
|
|
612
|
+
await Promise.allSettled(
|
|
613
613
|
config$1.generators.map(
|
|
614
614
|
(generator) => generator.generator(result, true)
|
|
615
615
|
)
|
|
@@ -618,7 +618,7 @@ async function generateClients(config$1) {
|
|
|
618
618
|
`Generated ${clientCount} client${clientCount === 1 ? "" : "s"}`
|
|
619
619
|
);
|
|
620
620
|
} catch (err) {
|
|
621
|
-
|
|
621
|
+
logger.error(err);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
async function createEntryModule(config) {
|
package/dist/cli.mjs
CHANGED
|
@@ -250,8 +250,8 @@ async function bundleAppEntry(config, allowCodegen = true) {
|
|
|
250
250
|
bundle: true,
|
|
251
251
|
packages: "external",
|
|
252
252
|
format: "esm",
|
|
253
|
-
sourcemap: true,
|
|
254
|
-
|
|
253
|
+
sourcemap: config.esbuild.sourcemap ?? true,
|
|
254
|
+
minify: config.esbuild.minify ?? true,
|
|
255
255
|
banner: {
|
|
256
256
|
js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
257
257
|
const require = topLevelCreateRequire(import.meta.url);`
|
|
@@ -480,10 +480,10 @@ export default app.h3App;`;
|
|
|
480
480
|
outfile: path.resolve(config.rootDir, ".output", OUT_APP_FILE),
|
|
481
481
|
format: "esm",
|
|
482
482
|
bundle: true,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
packages: "external",
|
|
484
|
+
sourcemap: config.esbuild.sourcemap ?? true,
|
|
485
|
+
target: config.esbuild.target ?? "node20",
|
|
486
|
+
platform: config.esbuild.platform ?? "node"
|
|
487
487
|
});
|
|
488
488
|
}
|
|
489
489
|
async function startDevServer(config) {
|
|
@@ -586,7 +586,7 @@ async function generateClients(config) {
|
|
|
586
586
|
}
|
|
587
587
|
logger.log(`Generating client code...`);
|
|
588
588
|
const clientCount = config.generators.length;
|
|
589
|
-
await Promise.
|
|
589
|
+
await Promise.allSettled(
|
|
590
590
|
config.generators.map(
|
|
591
591
|
(generator) => generator.generator(result, true)
|
|
592
592
|
)
|
|
@@ -595,7 +595,7 @@ async function generateClients(config) {
|
|
|
595
595
|
`Generated ${clientCount} client${clientCount === 1 ? "" : "s"}`
|
|
596
596
|
);
|
|
597
597
|
} catch (err) {
|
|
598
|
-
|
|
598
|
+
logger.error(err);
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
601
|
async function createEntryModule(config) {
|
package/dist/codegen.cjs
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const arriCodegenDart = require('arri-codegen-dart');
|
|
4
4
|
const arriCodegenTs = require('arri-codegen-ts');
|
|
5
|
+
const arriCodegenUtils = require('arri-codegen-utils');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
exports.dartClientGenerator = arriCodegenDart.dartClientGenerator;
|
|
9
10
|
exports.typescriptClientGenerator = arriCodegenTs.typescriptClientGenerator;
|
|
11
|
+
exports.createAppDefinition = arriCodegenUtils.createAppDefinition;
|
package/dist/codegen.d.cts
CHANGED
package/dist/codegen.d.mts
CHANGED
package/dist/codegen.d.ts
CHANGED
package/dist/codegen.mjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -28,9 +28,26 @@ declare function errorResponseFromValidationErrors(errors: ValidationError["erro
|
|
|
28
28
|
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;
|
|
29
29
|
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
type ArriEventContext = Record<string, any>;
|
|
32
|
+
interface RpcEventContext<TParams = undefined> extends ArriEventContext, Omit<H3EventContext, "params"> {
|
|
33
|
+
rpcName: string;
|
|
34
|
+
params: TParams;
|
|
35
|
+
}
|
|
36
|
+
interface RpcPostEventContext<TParams = undefined, TResponse = undefined> extends RpcEventContext<TParams> {
|
|
37
|
+
response: TResponse;
|
|
38
|
+
}
|
|
39
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends ArriEventContext, H3EventContext {
|
|
40
|
+
params: ExtractParams<TPath>;
|
|
41
|
+
query: TQuery;
|
|
42
|
+
body: TBody;
|
|
43
|
+
}
|
|
44
|
+
interface RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
45
|
+
response: TResponse;
|
|
46
|
+
}
|
|
47
|
+
interface MiddlewareEventContext extends ArriEventContext, H3EventContext {
|
|
32
48
|
rpcName?: string;
|
|
33
49
|
}
|
|
50
|
+
|
|
34
51
|
interface MiddlewareEvent extends H3Event {
|
|
35
52
|
context: MiddlewareEventContext;
|
|
36
53
|
}
|
|
@@ -39,19 +56,11 @@ declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
|
39
56
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
40
57
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
41
58
|
|
|
42
|
-
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
43
|
-
params: ExtractParams<TPath>;
|
|
44
|
-
query: TQuery;
|
|
45
|
-
body: TBody;
|
|
46
|
-
}
|
|
47
59
|
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
48
60
|
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
49
61
|
}
|
|
50
|
-
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
51
|
-
response: TResponse;
|
|
52
|
-
}
|
|
53
62
|
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
54
|
-
context:
|
|
63
|
+
context: RoutePostEventContext<TPath, TQuery, TBody, TResponse>;
|
|
55
64
|
}
|
|
56
65
|
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
57
66
|
path: TPath;
|
|
@@ -75,7 +84,7 @@ interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined,
|
|
|
75
84
|
handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
76
85
|
}
|
|
77
86
|
type EventStreamRpcHandler<TParams, TResponse> = (context: EventStreamRpcHandlerContext<TParams, TResponse>, event: RpcEvent<TResponse>) => void | Promise<void>;
|
|
78
|
-
interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends
|
|
87
|
+
interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends RpcEventContext<TParams> {
|
|
79
88
|
stream: EventStreamConnection<TResponse>;
|
|
80
89
|
}
|
|
81
90
|
interface EventStreamConnectionOptions<TData> {
|
|
@@ -185,22 +194,14 @@ interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSc
|
|
|
185
194
|
postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
186
195
|
}
|
|
187
196
|
type HttpRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined> = Omit<Rpc<false, TParams, TResponse>, "isEventStream">;
|
|
188
|
-
type HandlerContext = Record<string, any>;
|
|
189
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
190
|
-
rpcName: string;
|
|
191
|
-
params: TParams;
|
|
192
|
-
}
|
|
193
|
-
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
194
|
-
response: TResponse;
|
|
195
|
-
}
|
|
196
197
|
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
197
|
-
context:
|
|
198
|
+
context: RpcEventContext<TParams>;
|
|
198
199
|
}
|
|
199
200
|
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
200
|
-
context:
|
|
201
|
+
context: RpcPostEventContext<TParams, TResponse>;
|
|
201
202
|
}
|
|
202
|
-
type RpcHandler<TParams, TResponse> = (context:
|
|
203
|
-
type RpcPostHandler<TParams, TResponse> = (context:
|
|
203
|
+
type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
204
|
+
type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
204
205
|
declare function isRpc(input: unknown): input is Rpc<any, any>;
|
|
205
206
|
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
|
|
206
207
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
|
|
@@ -289,7 +290,7 @@ interface ArriConfig {
|
|
|
289
290
|
procedureGlobPatterns?: string[];
|
|
290
291
|
generators?: Array<ClientGenerator<any>>;
|
|
291
292
|
buildDir?: string;
|
|
292
|
-
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
293
|
+
esbuild?: Omit<BuildOptions, "bundle" | "format" | "outfile" | "outdir" | "entryNames" | "entryPoints" | "packages">;
|
|
293
294
|
https?: {
|
|
294
295
|
cert: string;
|
|
295
296
|
key: string;
|
|
@@ -309,4 +310,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
309
310
|
declare const defaultConfig: Required<ArriConfig>;
|
|
310
311
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
311
312
|
|
|
312
|
-
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
|
|
313
|
+
export { ArriApp, type ArriConfig, type ArriEventContext, 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 HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type NamedWebsocketRpc, type PostRouteEvent, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type StatusCode, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };
|
package/dist/index.d.mts
CHANGED
|
@@ -28,9 +28,26 @@ declare function errorResponseFromValidationErrors(errors: ValidationError["erro
|
|
|
28
28
|
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;
|
|
29
29
|
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
type ArriEventContext = Record<string, any>;
|
|
32
|
+
interface RpcEventContext<TParams = undefined> extends ArriEventContext, Omit<H3EventContext, "params"> {
|
|
33
|
+
rpcName: string;
|
|
34
|
+
params: TParams;
|
|
35
|
+
}
|
|
36
|
+
interface RpcPostEventContext<TParams = undefined, TResponse = undefined> extends RpcEventContext<TParams> {
|
|
37
|
+
response: TResponse;
|
|
38
|
+
}
|
|
39
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends ArriEventContext, H3EventContext {
|
|
40
|
+
params: ExtractParams<TPath>;
|
|
41
|
+
query: TQuery;
|
|
42
|
+
body: TBody;
|
|
43
|
+
}
|
|
44
|
+
interface RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
45
|
+
response: TResponse;
|
|
46
|
+
}
|
|
47
|
+
interface MiddlewareEventContext extends ArriEventContext, H3EventContext {
|
|
32
48
|
rpcName?: string;
|
|
33
49
|
}
|
|
50
|
+
|
|
34
51
|
interface MiddlewareEvent extends H3Event {
|
|
35
52
|
context: MiddlewareEventContext;
|
|
36
53
|
}
|
|
@@ -39,19 +56,11 @@ declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
|
39
56
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
40
57
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
41
58
|
|
|
42
|
-
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
43
|
-
params: ExtractParams<TPath>;
|
|
44
|
-
query: TQuery;
|
|
45
|
-
body: TBody;
|
|
46
|
-
}
|
|
47
59
|
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
48
60
|
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
49
61
|
}
|
|
50
|
-
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
51
|
-
response: TResponse;
|
|
52
|
-
}
|
|
53
62
|
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
54
|
-
context:
|
|
63
|
+
context: RoutePostEventContext<TPath, TQuery, TBody, TResponse>;
|
|
55
64
|
}
|
|
56
65
|
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
57
66
|
path: TPath;
|
|
@@ -75,7 +84,7 @@ interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined,
|
|
|
75
84
|
handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
76
85
|
}
|
|
77
86
|
type EventStreamRpcHandler<TParams, TResponse> = (context: EventStreamRpcHandlerContext<TParams, TResponse>, event: RpcEvent<TResponse>) => void | Promise<void>;
|
|
78
|
-
interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends
|
|
87
|
+
interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends RpcEventContext<TParams> {
|
|
79
88
|
stream: EventStreamConnection<TResponse>;
|
|
80
89
|
}
|
|
81
90
|
interface EventStreamConnectionOptions<TData> {
|
|
@@ -185,22 +194,14 @@ interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSc
|
|
|
185
194
|
postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
186
195
|
}
|
|
187
196
|
type HttpRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined> = Omit<Rpc<false, TParams, TResponse>, "isEventStream">;
|
|
188
|
-
type HandlerContext = Record<string, any>;
|
|
189
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
190
|
-
rpcName: string;
|
|
191
|
-
params: TParams;
|
|
192
|
-
}
|
|
193
|
-
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
194
|
-
response: TResponse;
|
|
195
|
-
}
|
|
196
197
|
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
197
|
-
context:
|
|
198
|
+
context: RpcEventContext<TParams>;
|
|
198
199
|
}
|
|
199
200
|
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
200
|
-
context:
|
|
201
|
+
context: RpcPostEventContext<TParams, TResponse>;
|
|
201
202
|
}
|
|
202
|
-
type RpcHandler<TParams, TResponse> = (context:
|
|
203
|
-
type RpcPostHandler<TParams, TResponse> = (context:
|
|
203
|
+
type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
204
|
+
type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
204
205
|
declare function isRpc(input: unknown): input is Rpc<any, any>;
|
|
205
206
|
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
|
|
206
207
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
|
|
@@ -289,7 +290,7 @@ interface ArriConfig {
|
|
|
289
290
|
procedureGlobPatterns?: string[];
|
|
290
291
|
generators?: Array<ClientGenerator<any>>;
|
|
291
292
|
buildDir?: string;
|
|
292
|
-
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
293
|
+
esbuild?: Omit<BuildOptions, "bundle" | "format" | "outfile" | "outdir" | "entryNames" | "entryPoints" | "packages">;
|
|
293
294
|
https?: {
|
|
294
295
|
cert: string;
|
|
295
296
|
key: string;
|
|
@@ -309,4 +310,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
309
310
|
declare const defaultConfig: Required<ArriConfig>;
|
|
310
311
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
311
312
|
|
|
312
|
-
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
|
|
313
|
+
export { ArriApp, type ArriConfig, type ArriEventContext, 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 HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type NamedWebsocketRpc, type PostRouteEvent, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type StatusCode, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -28,9 +28,26 @@ declare function errorResponseFromValidationErrors(errors: ValidationError["erro
|
|
|
28
28
|
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;
|
|
29
29
|
declare function handleH3Error(err: unknown, event: H3Event, onError: ArriOptions["onError"], debug: boolean): Promise<void>;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
type ArriEventContext = Record<string, any>;
|
|
32
|
+
interface RpcEventContext<TParams = undefined> extends ArriEventContext, Omit<H3EventContext, "params"> {
|
|
33
|
+
rpcName: string;
|
|
34
|
+
params: TParams;
|
|
35
|
+
}
|
|
36
|
+
interface RpcPostEventContext<TParams = undefined, TResponse = undefined> extends RpcEventContext<TParams> {
|
|
37
|
+
response: TResponse;
|
|
38
|
+
}
|
|
39
|
+
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends ArriEventContext, H3EventContext {
|
|
40
|
+
params: ExtractParams<TPath>;
|
|
41
|
+
query: TQuery;
|
|
42
|
+
body: TBody;
|
|
43
|
+
}
|
|
44
|
+
interface RoutePostEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
45
|
+
response: TResponse;
|
|
46
|
+
}
|
|
47
|
+
interface MiddlewareEventContext extends ArriEventContext, H3EventContext {
|
|
32
48
|
rpcName?: string;
|
|
33
49
|
}
|
|
50
|
+
|
|
34
51
|
interface MiddlewareEvent extends H3Event {
|
|
35
52
|
context: MiddlewareEventContext;
|
|
36
53
|
}
|
|
@@ -39,19 +56,11 @@ declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
|
39
56
|
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
40
57
|
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
41
58
|
|
|
42
|
-
interface RouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3EventContext {
|
|
43
|
-
params: ExtractParams<TPath>;
|
|
44
|
-
query: TQuery;
|
|
45
|
-
body: TBody;
|
|
46
|
-
}
|
|
47
59
|
interface RouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any> extends H3Event {
|
|
48
60
|
context: RouteEventContext<TPath, TQuery, TBody>;
|
|
49
61
|
}
|
|
50
|
-
interface PostRouteEventContext<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends RouteEventContext<TPath, TQuery, TBody> {
|
|
51
|
-
response: TResponse;
|
|
52
|
-
}
|
|
53
62
|
interface PostRouteEvent<TPath extends string, TQuery extends Record<any, any> = any, TBody = any, TResponse = any> extends H3Event {
|
|
54
|
-
context:
|
|
63
|
+
context: RoutePostEventContext<TPath, TQuery, TBody, TResponse>;
|
|
55
64
|
}
|
|
56
65
|
interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any> {
|
|
57
66
|
path: TPath;
|
|
@@ -75,7 +84,7 @@ interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined,
|
|
|
75
84
|
handler: EventStreamRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
76
85
|
}
|
|
77
86
|
type EventStreamRpcHandler<TParams, TResponse> = (context: EventStreamRpcHandlerContext<TParams, TResponse>, event: RpcEvent<TResponse>) => void | Promise<void>;
|
|
78
|
-
interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends
|
|
87
|
+
interface EventStreamRpcHandlerContext<TParams = any, TResponse = any> extends RpcEventContext<TParams> {
|
|
79
88
|
stream: EventStreamConnection<TResponse>;
|
|
80
89
|
}
|
|
81
90
|
interface EventStreamConnectionOptions<TData> {
|
|
@@ -185,22 +194,14 @@ interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSc
|
|
|
185
194
|
postHandler?: TIsEventStream extends true ? undefined : RpcPostHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
186
195
|
}
|
|
187
196
|
type HttpRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined> = Omit<Rpc<false, TParams, TResponse>, "isEventStream">;
|
|
188
|
-
type HandlerContext = Record<string, any>;
|
|
189
|
-
interface RpcHandlerContext<TParams = undefined> extends HandlerContext, Omit<H3EventContext, "params"> {
|
|
190
|
-
rpcName: string;
|
|
191
|
-
params: TParams;
|
|
192
|
-
}
|
|
193
|
-
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
194
|
-
response: TResponse;
|
|
195
|
-
}
|
|
196
197
|
interface RpcEvent<TParams = undefined> extends Omit<H3Event, "context"> {
|
|
197
|
-
context:
|
|
198
|
+
context: RpcEventContext<TParams>;
|
|
198
199
|
}
|
|
199
200
|
interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<H3Event, "context"> {
|
|
200
|
-
context:
|
|
201
|
+
context: RpcPostEventContext<TParams, TResponse>;
|
|
201
202
|
}
|
|
202
|
-
type RpcHandler<TParams, TResponse> = (context:
|
|
203
|
-
type RpcPostHandler<TParams, TResponse> = (context:
|
|
203
|
+
type RpcHandler<TParams, TResponse> = (context: RpcEventContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
204
|
+
type RpcPostHandler<TParams, TResponse> = (context: RpcPostEventContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
204
205
|
declare function isRpc(input: unknown): input is Rpc<any, any>;
|
|
205
206
|
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
|
|
206
207
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
|
|
@@ -289,7 +290,7 @@ interface ArriConfig {
|
|
|
289
290
|
procedureGlobPatterns?: string[];
|
|
290
291
|
generators?: Array<ClientGenerator<any>>;
|
|
291
292
|
buildDir?: string;
|
|
292
|
-
esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
|
|
293
|
+
esbuild?: Omit<BuildOptions, "bundle" | "format" | "outfile" | "outdir" | "entryNames" | "entryPoints" | "packages">;
|
|
293
294
|
https?: {
|
|
294
295
|
cert: string;
|
|
295
296
|
key: string;
|
|
@@ -309,4 +310,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
309
310
|
declare const defaultConfig: Required<ArriConfig>;
|
|
310
311
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
311
312
|
|
|
312
|
-
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
|
|
313
|
+
export { ArriApp, type ArriConfig, type ArriEventContext, 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 HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type NamedWebsocketRpc, type PostRouteEvent, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type RoutePostEventContext, type Rpc, type RpcEvent, type RpcEventContext, type RpcHandler, type RpcParamSchema, type RpcPostEvent, type RpcPostEventContext, type RpcPostHandler, type StatusCode, type WebSocketRpcHandler, type WebsocketRpc, WsPeer, type WsPeerContext, createAppDefinition, createHttpRpcDefinition, createWsRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, defineWebsocketRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, registerWebsocketRpc, validateRpcRequestInput };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arri",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"scule": "^1.3.0",
|
|
48
48
|
"source-map-support": "^0.5.21",
|
|
49
49
|
"uncrypto": "^0.1.3",
|
|
50
|
-
"arri-codegen-
|
|
51
|
-
"arri-codegen-
|
|
52
|
-
"arri-
|
|
53
|
-
"arri-
|
|
50
|
+
"arri-codegen-dart": "0.42.1",
|
|
51
|
+
"arri-codegen-utils": "0.42.1",
|
|
52
|
+
"arri-validate": "0.42.1",
|
|
53
|
+
"arri-codegen-ts": "0.42.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/degit": "^2.8.6",
|
|
57
|
-
"bun-types": "^1.1.
|
|
57
|
+
"bun-types": "^1.1.7"
|
|
58
58
|
}
|
|
59
59
|
}
|