arri 0.36.1 → 0.37.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/README.md +0 -15
- package/dist/cli.cjs +22 -6
- package/dist/cli.mjs +22 -6
- package/dist/index.cjs +5 -1
- package/dist/index.d.cts +65 -11
- package/dist/index.d.mts +65 -11
- package/dist/index.d.ts +65 -11
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.8e96548e.cjs → arri.1ce0fa20.cjs} +216 -41
- package/dist/shared/{arri.b1ff441a.mjs → arri.90dd1716.mjs} +214 -43
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -108,24 +108,9 @@ Create an app entry file in your src directory. The name of the file must match
|
|
|
108
108
|
```ts
|
|
109
109
|
// ./src/app.ts
|
|
110
110
|
import { ArriApp } from "arri";
|
|
111
|
-
import { a } from "arri-validate";
|
|
112
111
|
|
|
113
112
|
const app = new ArriApp();
|
|
114
113
|
|
|
115
|
-
app.rpc("sayHello", {
|
|
116
|
-
params: a.object({
|
|
117
|
-
name: a.string(),
|
|
118
|
-
}),
|
|
119
|
-
response: a.object({
|
|
120
|
-
message: a.string(),
|
|
121
|
-
}),
|
|
122
|
-
handler({ params }) {
|
|
123
|
-
return {
|
|
124
|
-
message: `Hello ${params.name}`,
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
|
|
129
114
|
export default app;
|
|
130
115
|
```
|
|
131
116
|
|
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.1ce0fa20.cjs');
|
|
15
15
|
const consola = require('consola');
|
|
16
16
|
const globby = require('globby');
|
|
17
17
|
const scule = require('scule');
|
|
@@ -93,10 +93,17 @@ async function createAppWithRoutesModule(config) {
|
|
|
93
93
|
).join(",\n")}
|
|
94
94
|
];
|
|
95
95
|
for(const route of routes) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
if(route.route.transport === 'http') {
|
|
97
|
+
app.rpc({
|
|
98
|
+
name: route.id,
|
|
99
|
+
...route.route,
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
app.wsRpc({
|
|
103
|
+
name: route.id,
|
|
104
|
+
...route.route,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
export default app`,
|
|
102
109
|
{ parser: "typescript", tabWidth: 4 }
|
|
@@ -321,6 +328,14 @@ import app from './${OUT_APP_FILE}';
|
|
|
321
328
|
void listen(toNodeListener(app.h3App), {
|
|
322
329
|
port: process.env.PORT ?? ${config.port},
|
|
323
330
|
public: true,
|
|
331
|
+
ws: {
|
|
332
|
+
resolve(info) {
|
|
333
|
+
if (app.h3App.websocket?.resolve) {
|
|
334
|
+
return app.h3App.websocket.resolve(info);
|
|
335
|
+
}
|
|
336
|
+
return app.h3App.websocket?.hooks ?? app.h3App.handler?.__websocket__ ?? {};
|
|
337
|
+
}
|
|
338
|
+
},
|
|
324
339
|
http2: ${config.http2 ?? false},
|
|
325
340
|
${httpsString}
|
|
326
341
|
});`;
|
|
@@ -471,7 +486,8 @@ const startListener = (config, showQr = false) => listhen.listenAndWatch(path__d
|
|
|
471
486
|
logger,
|
|
472
487
|
qr: showQr,
|
|
473
488
|
https: config.https,
|
|
474
|
-
http2: config.http2
|
|
489
|
+
http2: config.http2,
|
|
490
|
+
ws: true
|
|
475
491
|
});
|
|
476
492
|
async function bundleFilesContext(config) {
|
|
477
493
|
const serverContent = `import app from './${OUT_APP_FILE}';
|
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 { q as defaultConfig, o as isArriConfig, p as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.
|
|
13
|
+
import { q as defaultConfig, o as isArriConfig, p as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.90dd1716.mjs';
|
|
14
14
|
import { createConsola } from 'consola';
|
|
15
15
|
import { globby } from 'globby';
|
|
16
16
|
import { camelCase, kebabCase } from 'scule';
|
|
@@ -69,10 +69,17 @@ async function createAppWithRoutesModule(config) {
|
|
|
69
69
|
).join(",\n")}
|
|
70
70
|
];
|
|
71
71
|
for(const route of routes) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
if(route.route.transport === 'http') {
|
|
73
|
+
app.rpc({
|
|
74
|
+
name: route.id,
|
|
75
|
+
...route.route,
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
app.wsRpc({
|
|
79
|
+
name: route.id,
|
|
80
|
+
...route.route,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
84
|
export default app`,
|
|
78
85
|
{ parser: "typescript", tabWidth: 4 }
|
|
@@ -297,6 +304,14 @@ import app from './${OUT_APP_FILE}';
|
|
|
297
304
|
void listen(toNodeListener(app.h3App), {
|
|
298
305
|
port: process.env.PORT ?? ${config.port},
|
|
299
306
|
public: true,
|
|
307
|
+
ws: {
|
|
308
|
+
resolve(info) {
|
|
309
|
+
if (app.h3App.websocket?.resolve) {
|
|
310
|
+
return app.h3App.websocket.resolve(info);
|
|
311
|
+
}
|
|
312
|
+
return app.h3App.websocket?.hooks ?? app.h3App.handler?.__websocket__ ?? {};
|
|
313
|
+
}
|
|
314
|
+
},
|
|
300
315
|
http2: ${config.http2 ?? false},
|
|
301
316
|
${httpsString}
|
|
302
317
|
});`;
|
|
@@ -447,7 +462,8 @@ const startListener = (config, showQr = false) => listenAndWatch(path.resolve(co
|
|
|
447
462
|
logger,
|
|
448
463
|
qr: showQr,
|
|
449
464
|
https: config.https,
|
|
450
|
-
http2: config.http2
|
|
465
|
+
http2: config.http2,
|
|
466
|
+
ws: true
|
|
451
467
|
});
|
|
452
468
|
async function bundleFilesContext(config) {
|
|
453
469
|
const serverContent = `import app from './${OUT_APP_FILE}';
|
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.1ce0fa20.cjs');
|
|
4
4
|
const h3 = require('h3');
|
|
5
5
|
require('arri-codegen-utils');
|
|
6
6
|
require('consola');
|
|
@@ -17,14 +17,17 @@ exports.ArriServerErrorResponse = config.ArriServerErrorResponse;
|
|
|
17
17
|
exports.DEV_DEFINITION_ENDPOINT = config.DEV_DEFINITION_ENDPOINT;
|
|
18
18
|
exports.DEV_ENDPOINT_ROOT = config.DEV_ENDPOINT_ROOT;
|
|
19
19
|
exports.EventStreamConnection = config.EventStreamConnection;
|
|
20
|
+
exports.WsPeer = config.WsPeer;
|
|
20
21
|
exports.createAppDefinition = config.createAppDefinition;
|
|
21
22
|
exports.createHttpRpcDefinition = config.createHttpRpcDefinition;
|
|
23
|
+
exports.createWsRpcDefinition = config.createWsRpcDefinition;
|
|
22
24
|
exports.defaultConfig = config.defaultConfig;
|
|
23
25
|
exports.defineConfig = config.defineConfig;
|
|
24
26
|
exports.defineError = config.defineError;
|
|
25
27
|
exports.defineEventStreamRpc = config.defineEventStreamRpc;
|
|
26
28
|
exports.defineRoute = config.defineRoute;
|
|
27
29
|
exports.defineRpc = config.defineRpc;
|
|
30
|
+
exports.defineWebsocketRpc = config.defineWebsocketRpc;
|
|
28
31
|
exports.errorResponseFromValidationErrors = config.errorResponseFromValidationErrors;
|
|
29
32
|
exports.getRpcParamName = config.getRpcParamName;
|
|
30
33
|
exports.getRpcPath = config.getRpcPath;
|
|
@@ -39,6 +42,7 @@ exports.isRpcParamSchema = config.isRpcParamSchema;
|
|
|
39
42
|
exports.registerEventStreamRpc = config.registerEventStreamRpc;
|
|
40
43
|
exports.registerRoute = config.registerRoute;
|
|
41
44
|
exports.registerRpc = config.registerRpc;
|
|
45
|
+
exports.registerWebsocketRpc = config.registerWebsocketRpc;
|
|
42
46
|
exports.validateRpcRequestInput = config.validateRpcRequestInput;
|
|
43
47
|
exports.defineMiddleware = defineMiddleware;
|
|
44
48
|
Object.keys(h3).forEach(function (k) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
-
import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, ADiscriminatorSchema } from 'arri-validate';
|
|
1
|
+
import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
+
import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from 'arri-validate';
|
|
3
3
|
import { H3Error, H3Event, H3EventContext, Router, App } from 'h3';
|
|
4
4
|
export * from 'h3';
|
|
5
5
|
import { EventStream } from 'h3-sse';
|
|
6
|
+
import { Peer, WSError } from 'crossws';
|
|
6
7
|
import { BuildOptions } from 'esbuild';
|
|
7
8
|
|
|
8
9
|
declare class ArriServerError extends Error {
|
|
@@ -67,7 +68,7 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
|
|
|
67
68
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
68
69
|
declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
69
70
|
|
|
70
|
-
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream">): EventStreamRpc<TParams, TResponse>;
|
|
71
|
+
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream" | "transport">): EventStreamRpc<TParams, TResponse>;
|
|
71
72
|
declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
|
|
72
73
|
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
|
|
73
74
|
isEventStream: true;
|
|
@@ -116,12 +117,62 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
|
|
|
116
117
|
name: string;
|
|
117
118
|
}, opts: RouteOptions): void;
|
|
118
119
|
|
|
120
|
+
interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends WebsocketRpc<TParams, TResponse> {
|
|
121
|
+
name: string;
|
|
122
|
+
}
|
|
123
|
+
interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
124
|
+
transport: "ws";
|
|
125
|
+
description?: string;
|
|
126
|
+
path?: string;
|
|
127
|
+
isDeprecated?: boolean;
|
|
128
|
+
params: TParams;
|
|
129
|
+
response: TResponse;
|
|
130
|
+
pingInterval?: boolean;
|
|
131
|
+
handler: WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
132
|
+
}
|
|
133
|
+
interface WsPeerOpts<TResponse> {
|
|
134
|
+
validator?: CompiledValidator<ASchema<TResponse>>;
|
|
135
|
+
context: WsPeerContext;
|
|
136
|
+
}
|
|
137
|
+
interface WsPeerContext extends Record<string, any> {
|
|
138
|
+
rpcName: string;
|
|
139
|
+
queryParams?: Record<string, string>;
|
|
140
|
+
clientAddress?: string;
|
|
141
|
+
}
|
|
142
|
+
declare class WsPeer<TResponse> {
|
|
143
|
+
private readonly _peer;
|
|
144
|
+
private readonly _validator?;
|
|
145
|
+
context: WsPeerContext;
|
|
146
|
+
url: string;
|
|
147
|
+
constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
|
|
148
|
+
send(data: TResponse): number | undefined;
|
|
149
|
+
sendError(err: ArriServerErrorResponse): number;
|
|
150
|
+
close(): void;
|
|
151
|
+
subscribe(channel: string): void;
|
|
152
|
+
unsubscribe(channel: string): void;
|
|
153
|
+
publish(channel: string, message: TResponse): void;
|
|
154
|
+
readyState(): (0 | 1 | 2 | 3) | -1;
|
|
155
|
+
}
|
|
156
|
+
interface WebSocketRpcHandler<TParams, TResponse> {
|
|
157
|
+
onOpen: (peer: WsPeer<TResponse>) => void;
|
|
158
|
+
onMessage: (peer: WsPeer<TResponse>, message: TParams) => void;
|
|
159
|
+
onClose: (peer: WsPeer<TResponse>, details: {
|
|
160
|
+
code?: number;
|
|
161
|
+
reason?: string;
|
|
162
|
+
}) => void;
|
|
163
|
+
onError: (peer: WsPeer<TResponse>, error: WSError) => void;
|
|
164
|
+
}
|
|
165
|
+
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, "transport">): WebsocketRpc<TParams, TResponse>;
|
|
166
|
+
declare function registerWebsocketRpc(router: Router, path: string, rpc: NamedWebsocketRpc<any, any>): void;
|
|
167
|
+
declare function createWsRpcDefinition(rpcName: string, path: string, rpc: NamedWebsocketRpc<any, any>): WsRpcDefinition;
|
|
168
|
+
|
|
119
169
|
type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
|
|
120
170
|
declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
|
|
121
171
|
interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
|
|
122
172
|
name: string;
|
|
123
173
|
}
|
|
124
174
|
interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
175
|
+
transport: "http";
|
|
125
176
|
method?: RpcHttpMethod;
|
|
126
177
|
path?: string;
|
|
127
178
|
description?: string;
|
|
@@ -151,16 +202,17 @@ interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<
|
|
|
151
202
|
type RpcHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
152
203
|
type RpcPostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
153
204
|
declare function isRpc(input: unknown): input is Rpc<any, any>;
|
|
154
|
-
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: HttpRpc<TParams, TResponse>): Rpc<false, TParams, TResponse>;
|
|
205
|
+
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
|
|
155
206
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
|
|
156
207
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
157
|
-
declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
|
|
158
|
-
declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
|
|
208
|
+
declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
209
|
+
declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
159
210
|
declare function registerRpc(router: Router, path: string, procedure: NamedRpc<any, any, any>, opts: RouteOptions): void;
|
|
160
211
|
declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema): Promise<void>;
|
|
161
212
|
|
|
162
213
|
interface ArriRouterBase {
|
|
163
|
-
rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: NamedRpc<TIsEventStream, TParams, TResponse>) => void;
|
|
214
|
+
rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">) => void;
|
|
215
|
+
wsRpc: <TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">) => void;
|
|
164
216
|
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
165
217
|
registerModels: (models: ModelMap) => void;
|
|
166
218
|
}
|
|
@@ -168,10 +220,11 @@ declare class ArriRouter implements ArriRouterBase {
|
|
|
168
220
|
private readonly procedures;
|
|
169
221
|
private readonly routes;
|
|
170
222
|
private readonly models;
|
|
171
|
-
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;
|
|
223
|
+
rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
|
|
224
|
+
wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
|
|
172
225
|
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
173
226
|
registerModels(models: ModelMap): void;
|
|
174
|
-
getProcedures(): NamedRpc<any, any, any>[];
|
|
227
|
+
getProcedures(): (NamedWebsocketRpc<any, any> | NamedRpc<any, any, any>)[];
|
|
175
228
|
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
176
229
|
getModels(): ModelMap;
|
|
177
230
|
}
|
|
@@ -198,7 +251,8 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
198
251
|
readonly definitionPath: string;
|
|
199
252
|
constructor(opts?: ArriOptions);
|
|
200
253
|
use(input: Middleware | ArriRouter): void;
|
|
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;
|
|
254
|
+
rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
|
|
255
|
+
wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
|
|
202
256
|
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
203
257
|
registerModels(models: ModelMap): void;
|
|
204
258
|
getAppDefinition(): AppDefinition;
|
|
@@ -248,4 +302,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
248
302
|
declare const defaultConfig: Required<ArriConfig>;
|
|
249
303
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
250
304
|
|
|
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 };
|
|
305
|
+
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 NamedWebsocketRpc, 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, 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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
-
import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, ADiscriminatorSchema } from 'arri-validate';
|
|
1
|
+
import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
+
import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from 'arri-validate';
|
|
3
3
|
import { H3Error, H3Event, H3EventContext, Router, App } from 'h3';
|
|
4
4
|
export * from 'h3';
|
|
5
5
|
import { EventStream } from 'h3-sse';
|
|
6
|
+
import { Peer, WSError } from 'crossws';
|
|
6
7
|
import { BuildOptions } from 'esbuild';
|
|
7
8
|
|
|
8
9
|
declare class ArriServerError extends Error {
|
|
@@ -67,7 +68,7 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
|
|
|
67
68
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
68
69
|
declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
69
70
|
|
|
70
|
-
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream">): EventStreamRpc<TParams, TResponse>;
|
|
71
|
+
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream" | "transport">): EventStreamRpc<TParams, TResponse>;
|
|
71
72
|
declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
|
|
72
73
|
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
|
|
73
74
|
isEventStream: true;
|
|
@@ -116,12 +117,62 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
|
|
|
116
117
|
name: string;
|
|
117
118
|
}, opts: RouteOptions): void;
|
|
118
119
|
|
|
120
|
+
interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends WebsocketRpc<TParams, TResponse> {
|
|
121
|
+
name: string;
|
|
122
|
+
}
|
|
123
|
+
interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
124
|
+
transport: "ws";
|
|
125
|
+
description?: string;
|
|
126
|
+
path?: string;
|
|
127
|
+
isDeprecated?: boolean;
|
|
128
|
+
params: TParams;
|
|
129
|
+
response: TResponse;
|
|
130
|
+
pingInterval?: boolean;
|
|
131
|
+
handler: WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
132
|
+
}
|
|
133
|
+
interface WsPeerOpts<TResponse> {
|
|
134
|
+
validator?: CompiledValidator<ASchema<TResponse>>;
|
|
135
|
+
context: WsPeerContext;
|
|
136
|
+
}
|
|
137
|
+
interface WsPeerContext extends Record<string, any> {
|
|
138
|
+
rpcName: string;
|
|
139
|
+
queryParams?: Record<string, string>;
|
|
140
|
+
clientAddress?: string;
|
|
141
|
+
}
|
|
142
|
+
declare class WsPeer<TResponse> {
|
|
143
|
+
private readonly _peer;
|
|
144
|
+
private readonly _validator?;
|
|
145
|
+
context: WsPeerContext;
|
|
146
|
+
url: string;
|
|
147
|
+
constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
|
|
148
|
+
send(data: TResponse): number | undefined;
|
|
149
|
+
sendError(err: ArriServerErrorResponse): number;
|
|
150
|
+
close(): void;
|
|
151
|
+
subscribe(channel: string): void;
|
|
152
|
+
unsubscribe(channel: string): void;
|
|
153
|
+
publish(channel: string, message: TResponse): void;
|
|
154
|
+
readyState(): (0 | 1 | 2 | 3) | -1;
|
|
155
|
+
}
|
|
156
|
+
interface WebSocketRpcHandler<TParams, TResponse> {
|
|
157
|
+
onOpen: (peer: WsPeer<TResponse>) => void;
|
|
158
|
+
onMessage: (peer: WsPeer<TResponse>, message: TParams) => void;
|
|
159
|
+
onClose: (peer: WsPeer<TResponse>, details: {
|
|
160
|
+
code?: number;
|
|
161
|
+
reason?: string;
|
|
162
|
+
}) => void;
|
|
163
|
+
onError: (peer: WsPeer<TResponse>, error: WSError) => void;
|
|
164
|
+
}
|
|
165
|
+
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, "transport">): WebsocketRpc<TParams, TResponse>;
|
|
166
|
+
declare function registerWebsocketRpc(router: Router, path: string, rpc: NamedWebsocketRpc<any, any>): void;
|
|
167
|
+
declare function createWsRpcDefinition(rpcName: string, path: string, rpc: NamedWebsocketRpc<any, any>): WsRpcDefinition;
|
|
168
|
+
|
|
119
169
|
type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
|
|
120
170
|
declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
|
|
121
171
|
interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
|
|
122
172
|
name: string;
|
|
123
173
|
}
|
|
124
174
|
interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
175
|
+
transport: "http";
|
|
125
176
|
method?: RpcHttpMethod;
|
|
126
177
|
path?: string;
|
|
127
178
|
description?: string;
|
|
@@ -151,16 +202,17 @@ interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<
|
|
|
151
202
|
type RpcHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
152
203
|
type RpcPostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
153
204
|
declare function isRpc(input: unknown): input is Rpc<any, any>;
|
|
154
|
-
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: HttpRpc<TParams, TResponse>): Rpc<false, TParams, TResponse>;
|
|
205
|
+
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
|
|
155
206
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
|
|
156
207
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
157
|
-
declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
|
|
158
|
-
declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
|
|
208
|
+
declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
209
|
+
declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
159
210
|
declare function registerRpc(router: Router, path: string, procedure: NamedRpc<any, any, any>, opts: RouteOptions): void;
|
|
160
211
|
declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema): Promise<void>;
|
|
161
212
|
|
|
162
213
|
interface ArriRouterBase {
|
|
163
|
-
rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: NamedRpc<TIsEventStream, TParams, TResponse>) => void;
|
|
214
|
+
rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">) => void;
|
|
215
|
+
wsRpc: <TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">) => void;
|
|
164
216
|
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
165
217
|
registerModels: (models: ModelMap) => void;
|
|
166
218
|
}
|
|
@@ -168,10 +220,11 @@ declare class ArriRouter implements ArriRouterBase {
|
|
|
168
220
|
private readonly procedures;
|
|
169
221
|
private readonly routes;
|
|
170
222
|
private readonly models;
|
|
171
|
-
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;
|
|
223
|
+
rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
|
|
224
|
+
wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
|
|
172
225
|
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
173
226
|
registerModels(models: ModelMap): void;
|
|
174
|
-
getProcedures(): NamedRpc<any, any, any>[];
|
|
227
|
+
getProcedures(): (NamedWebsocketRpc<any, any> | NamedRpc<any, any, any>)[];
|
|
175
228
|
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
176
229
|
getModels(): ModelMap;
|
|
177
230
|
}
|
|
@@ -198,7 +251,8 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
198
251
|
readonly definitionPath: string;
|
|
199
252
|
constructor(opts?: ArriOptions);
|
|
200
253
|
use(input: Middleware | ArriRouter): void;
|
|
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;
|
|
254
|
+
rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
|
|
255
|
+
wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
|
|
202
256
|
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
203
257
|
registerModels(models: ModelMap): void;
|
|
204
258
|
getAppDefinition(): AppDefinition;
|
|
@@ -248,4 +302,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
248
302
|
declare const defaultConfig: Required<ArriConfig>;
|
|
249
303
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
250
304
|
|
|
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 };
|
|
305
|
+
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 NamedWebsocketRpc, 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, 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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
-
import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, ADiscriminatorSchema } from 'arri-validate';
|
|
1
|
+
import { HttpMethod, WsRpcDefinition, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
|
|
2
|
+
import { AObjectSchema, a, ValidationError, ASchema, InferType, ValueError, CompiledValidator, ADiscriminatorSchema } from 'arri-validate';
|
|
3
3
|
import { H3Error, H3Event, H3EventContext, Router, App } from 'h3';
|
|
4
4
|
export * from 'h3';
|
|
5
5
|
import { EventStream } from 'h3-sse';
|
|
6
|
+
import { Peer, WSError } from 'crossws';
|
|
6
7
|
import { BuildOptions } from 'esbuild';
|
|
7
8
|
|
|
8
9
|
declare class ArriServerError extends Error {
|
|
@@ -67,7 +68,7 @@ type RouteOptions = Pick<ArriOptions, "onAfterResponse" | "onBeforeResponse" | "
|
|
|
67
68
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
68
69
|
declare function handleRoute(router: Router, method: HttpMethod, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
69
70
|
|
|
70
|
-
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream">): EventStreamRpc<TParams, TResponse>;
|
|
71
|
+
declare function defineEventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<EventStreamRpc<TParams, TResponse>, "isEventStream" | "transport">): EventStreamRpc<TParams, TResponse>;
|
|
71
72
|
declare function isEventStreamRpc(input: unknown): input is EventStreamRpc<any, any>;
|
|
72
73
|
interface EventStreamRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Omit<Rpc<true, TParams, TResponse>, "handler" | "postHandler"> {
|
|
73
74
|
isEventStream: true;
|
|
@@ -116,12 +117,62 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
|
|
|
116
117
|
name: string;
|
|
117
118
|
}, opts: RouteOptions): void;
|
|
118
119
|
|
|
120
|
+
interface NamedWebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends WebsocketRpc<TParams, TResponse> {
|
|
121
|
+
name: string;
|
|
122
|
+
}
|
|
123
|
+
interface WebsocketRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
124
|
+
transport: "ws";
|
|
125
|
+
description?: string;
|
|
126
|
+
path?: string;
|
|
127
|
+
isDeprecated?: boolean;
|
|
128
|
+
params: TParams;
|
|
129
|
+
response: TResponse;
|
|
130
|
+
pingInterval?: boolean;
|
|
131
|
+
handler: WebSocketRpcHandler<TParams extends RpcParamSchema ? InferType<TParams> : undefined, TResponse extends RpcParamSchema ? InferType<TResponse> : undefined>;
|
|
132
|
+
}
|
|
133
|
+
interface WsPeerOpts<TResponse> {
|
|
134
|
+
validator?: CompiledValidator<ASchema<TResponse>>;
|
|
135
|
+
context: WsPeerContext;
|
|
136
|
+
}
|
|
137
|
+
interface WsPeerContext extends Record<string, any> {
|
|
138
|
+
rpcName: string;
|
|
139
|
+
queryParams?: Record<string, string>;
|
|
140
|
+
clientAddress?: string;
|
|
141
|
+
}
|
|
142
|
+
declare class WsPeer<TResponse> {
|
|
143
|
+
private readonly _peer;
|
|
144
|
+
private readonly _validator?;
|
|
145
|
+
context: WsPeerContext;
|
|
146
|
+
url: string;
|
|
147
|
+
constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
|
|
148
|
+
send(data: TResponse): number | undefined;
|
|
149
|
+
sendError(err: ArriServerErrorResponse): number;
|
|
150
|
+
close(): void;
|
|
151
|
+
subscribe(channel: string): void;
|
|
152
|
+
unsubscribe(channel: string): void;
|
|
153
|
+
publish(channel: string, message: TResponse): void;
|
|
154
|
+
readyState(): (0 | 1 | 2 | 3) | -1;
|
|
155
|
+
}
|
|
156
|
+
interface WebSocketRpcHandler<TParams, TResponse> {
|
|
157
|
+
onOpen: (peer: WsPeer<TResponse>) => void;
|
|
158
|
+
onMessage: (peer: WsPeer<TResponse>, message: TParams) => void;
|
|
159
|
+
onClose: (peer: WsPeer<TResponse>, details: {
|
|
160
|
+
code?: number;
|
|
161
|
+
reason?: string;
|
|
162
|
+
}) => void;
|
|
163
|
+
onError: (peer: WsPeer<TResponse>, error: WSError) => void;
|
|
164
|
+
}
|
|
165
|
+
declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(def: Omit<WebsocketRpc<TParams, TResponse>, "transport">): WebsocketRpc<TParams, TResponse>;
|
|
166
|
+
declare function registerWebsocketRpc(router: Router, path: string, rpc: NamedWebsocketRpc<any, any>): void;
|
|
167
|
+
declare function createWsRpcDefinition(rpcName: string, path: string, rpc: NamedWebsocketRpc<any, any>): WsRpcDefinition;
|
|
168
|
+
|
|
119
169
|
type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
|
|
120
170
|
declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
|
|
121
171
|
interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
|
|
122
172
|
name: string;
|
|
123
173
|
}
|
|
124
174
|
interface Rpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> {
|
|
175
|
+
transport: "http";
|
|
125
176
|
method?: RpcHttpMethod;
|
|
126
177
|
path?: string;
|
|
127
178
|
description?: string;
|
|
@@ -151,16 +202,17 @@ interface RpcPostEvent<TParams = undefined, TResponse = undefined> extends Omit<
|
|
|
151
202
|
type RpcHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, event: RpcEvent<TParams>) => TResponse | Promise<TResponse>;
|
|
152
203
|
type RpcPostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
|
|
153
204
|
declare function isRpc(input: unknown): input is Rpc<any, any>;
|
|
154
|
-
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: HttpRpc<TParams, TResponse>): Rpc<false, TParams, TResponse>;
|
|
205
|
+
declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: Omit<HttpRpc<TParams, TResponse>, "transport">): Rpc<false, TParams, TResponse>;
|
|
155
206
|
declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
|
|
156
207
|
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
157
|
-
declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
|
|
158
|
-
declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
|
|
208
|
+
declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
209
|
+
declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any> | WebsocketRpc<any, any>): string | undefined;
|
|
159
210
|
declare function registerRpc(router: Router, path: string, procedure: NamedRpc<any, any, any>, opts: RouteOptions): void;
|
|
160
211
|
declare function validateRpcRequestInput(event: H3Event, httpMethod: RpcHttpMethod, schema: ASchema): Promise<void>;
|
|
161
212
|
|
|
162
213
|
interface ArriRouterBase {
|
|
163
|
-
rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: NamedRpc<TIsEventStream, TParams, TResponse>) => void;
|
|
214
|
+
rpc: <TIsEventStream extends boolean, TParams extends AObjectSchema<any, any> | undefined, TResponse extends AObjectSchema<any, any> | undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">) => void;
|
|
215
|
+
wsRpc: <TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">) => void;
|
|
164
216
|
route: <TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>) => void;
|
|
165
217
|
registerModels: (models: ModelMap) => void;
|
|
166
218
|
}
|
|
@@ -168,10 +220,11 @@ declare class ArriRouter implements ArriRouterBase {
|
|
|
168
220
|
private readonly procedures;
|
|
169
221
|
private readonly routes;
|
|
170
222
|
private readonly models;
|
|
171
|
-
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;
|
|
223
|
+
rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
|
|
224
|
+
wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
|
|
172
225
|
route<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends ASchema<any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
173
226
|
registerModels(models: ModelMap): void;
|
|
174
|
-
getProcedures(): NamedRpc<any, any, any>[];
|
|
227
|
+
getProcedures(): (NamedWebsocketRpc<any, any> | NamedRpc<any, any, any>)[];
|
|
175
228
|
getRoutes(): ArriRoute<any, any, any, any>[];
|
|
176
229
|
getModels(): ModelMap;
|
|
177
230
|
}
|
|
@@ -198,7 +251,8 @@ declare class ArriApp implements ArriRouterBase {
|
|
|
198
251
|
readonly definitionPath: string;
|
|
199
252
|
constructor(opts?: ArriOptions);
|
|
200
253
|
use(input: Middleware | ArriRouter): void;
|
|
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;
|
|
254
|
+
rpc<TIsEventStream extends boolean = false, TParams extends AObjectSchema<any, any> | undefined = undefined, TResponse extends AObjectSchema<any, any> | undefined = undefined>(procedure: Omit<NamedRpc<TIsEventStream, TParams, TResponse>, "transport">): void;
|
|
255
|
+
wsRpc<TParams extends RpcParamSchema | undefined, TResponse extends RpcParamSchema | undefined>(procedure: Omit<NamedWebsocketRpc<TParams, TResponse>, "transport">): void;
|
|
202
256
|
route<TPath extends string, TQuery extends AObjectSchema<any, any>, TBody extends ASchema<any>, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): void;
|
|
203
257
|
registerModels(models: ModelMap): void;
|
|
204
258
|
getAppDefinition(): AppDefinition;
|
|
@@ -248,4 +302,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
|
|
|
248
302
|
declare const defaultConfig: Required<ArriConfig>;
|
|
249
303
|
declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
|
|
250
304
|
|
|
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 };
|
|
305
|
+
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 NamedWebsocketRpc, 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, 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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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.
|
|
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, W as WsPeer, c as createAppDefinition, e as createHttpRpcDefinition, G as createWsRpcDefinition, q as defaultConfig, s as defineConfig, l as defineError, y as defineEventStreamRpc, u as defineRoute, d as defineRpc, C as defineWebsocketRpc, 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, F as registerWebsocketRpc, v as validateRpcRequestInput } from './shared/arri.90dd1716.mjs';
|
|
2
2
|
export * from 'h3';
|
|
3
3
|
import 'arri-codegen-utils';
|
|
4
4
|
import 'consola';
|