arri 0.0.2 → 0.0.5
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/chunks/acorn.cjs +18 -0
- package/dist/chunks/acorn.mjs +15 -0
- package/dist/chunks/angular.cjs +7 -0
- package/dist/chunks/angular.mjs +4 -0
- package/dist/chunks/babel.cjs +21 -0
- package/dist/chunks/babel.mjs +18 -0
- package/dist/chunks/estree.cjs +42 -0
- package/dist/chunks/estree.mjs +37 -0
- package/dist/chunks/flow.cjs +26 -0
- package/dist/chunks/flow.mjs +23 -0
- package/dist/chunks/glimmer.cjs +37 -0
- package/dist/chunks/glimmer.mjs +32 -0
- package/dist/chunks/graphql.cjs +37 -0
- package/dist/chunks/graphql.mjs +31 -0
- package/dist/chunks/html.cjs +27 -0
- package/dist/chunks/html.mjs +21 -0
- package/dist/chunks/markdown.cjs +67 -0
- package/dist/chunks/markdown.mjs +61 -0
- package/dist/chunks/meriyah.cjs +10 -0
- package/dist/chunks/meriyah.mjs +7 -0
- package/dist/chunks/postcss.cjs +60 -0
- package/dist/chunks/postcss.mjs +54 -0
- package/dist/chunks/typescript.cjs +30 -0
- package/dist/chunks/typescript.mjs +27 -0
- package/dist/chunks/yaml.cjs +169 -0
- package/dist/chunks/yaml.mjs +163 -0
- package/dist/codegen/index.cjs +29866 -0
- package/dist/codegen/index.d.cts +60 -0
- package/dist/codegen/index.d.mts +60 -0
- package/dist/codegen/index.d.ts +60 -0
- package/dist/codegen/index.mjs +29837 -0
- package/dist/index.cjs +21 -4424
- package/dist/index.d.cts +20 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +18 -39
- package/dist/index.mjs +1 -4417
- package/dist/shared/arri.215ad025.mjs +8482 -0
- package/dist/shared/arri.c20aaf19.d.cts +148 -0
- package/dist/shared/arri.c20aaf19.d.mts +148 -0
- package/dist/shared/arri.c20aaf19.d.ts +148 -0
- package/dist/shared/arri.e2731572.cjs +8509 -0
- package/package.json +27 -19
- package/dist/chunks/index.cjs +0 -9499
- package/dist/chunks/index.mjs +0 -9477
- package/dist/cli.cjs +0 -29556
- package/dist/cli.d.ts +0 -2
- package/dist/cli.mjs +0 -29514
- package/dist/shared/arri.6ae90bdf.mjs +0 -181
- package/dist/shared/arri.8d738145.cjs +0 -185
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
|
|
2
|
+
import { H3Event, Router, App, AppOptions } from 'h3';
|
|
3
|
+
|
|
4
|
+
interface ProcedureDefinition {
|
|
5
|
+
path: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
params: string | undefined;
|
|
9
|
+
response: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
interface ServiceDefinition {
|
|
12
|
+
[key: string]: ProcedureDefinition | ServiceDefinition;
|
|
13
|
+
}
|
|
14
|
+
interface ApplicationDefinition {
|
|
15
|
+
schemaVersion: "0.0.1";
|
|
16
|
+
description: string;
|
|
17
|
+
procedures: Record<string, ProcedureDefinition>;
|
|
18
|
+
models: Record<string, JsonSchemaObject>;
|
|
19
|
+
errors: Omit<TObject, symbol>;
|
|
20
|
+
}
|
|
21
|
+
declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
|
|
22
|
+
declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
|
|
23
|
+
type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
|
|
24
|
+
interface JsonSchemaScalarType {
|
|
25
|
+
title?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
type: (typeof JsonSchemaScalarTypeValues)[number];
|
|
28
|
+
}
|
|
29
|
+
interface JsonSchemaNullType {
|
|
30
|
+
type: (typeof JsonSchemaNullTypeValues)[number];
|
|
31
|
+
}
|
|
32
|
+
type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray;
|
|
33
|
+
interface JsonSchemaObject {
|
|
34
|
+
$id?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
type: "object";
|
|
38
|
+
properties: Record<string, JsonSchemaType>;
|
|
39
|
+
required?: string[];
|
|
40
|
+
}
|
|
41
|
+
interface JsonSchemaArray {
|
|
42
|
+
$id?: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
type: "array";
|
|
46
|
+
items: JsonSchemaType;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface ArriProcedureBase {
|
|
50
|
+
method: HttpMethod;
|
|
51
|
+
params?: any;
|
|
52
|
+
response?: any;
|
|
53
|
+
handler: (context: any) => any;
|
|
54
|
+
postHandler?: (context: any) => any;
|
|
55
|
+
}
|
|
56
|
+
interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>> {
|
|
57
|
+
description?: string;
|
|
58
|
+
method?: HttpMethod;
|
|
59
|
+
params: TParams;
|
|
60
|
+
response: TResponse;
|
|
61
|
+
handler: ArriProcedureHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
|
|
62
|
+
postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
|
|
63
|
+
}
|
|
64
|
+
interface HandlerContext {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
event: H3Event;
|
|
67
|
+
}
|
|
68
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
69
|
+
params: TParams;
|
|
70
|
+
}
|
|
71
|
+
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
72
|
+
response: TResponse;
|
|
73
|
+
}
|
|
74
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>) => TResponse | Promise<TResponse>;
|
|
75
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (event: RpcPostHandlerContext<TParams, TResponse>) => any;
|
|
76
|
+
declare function isRpc(input: any): input is ArriProcedure<any, any, any>;
|
|
77
|
+
declare function defineRpc<TParams extends TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined, TFinalResponse extends TResponse extends TObject ? Static<TObject> : Static<TVoid> = any>(config: ArriProcedure<TParams, TResponse, TFinalResponse>): ArriProcedure<TParams, TResponse, TFinalResponse>;
|
|
78
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition;
|
|
79
|
+
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
80
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
|
|
81
|
+
declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition["params"];
|
|
82
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
|
|
83
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any, any>, middleware: Middleware[]): void;
|
|
84
|
+
|
|
85
|
+
interface ArriRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any> {
|
|
86
|
+
path: TPath;
|
|
87
|
+
method: TMethod;
|
|
88
|
+
query?: TQuery;
|
|
89
|
+
body?: TBody;
|
|
90
|
+
response?: TResponse;
|
|
91
|
+
handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
92
|
+
postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
93
|
+
}
|
|
94
|
+
declare function defineRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = any, TBody extends TSchema | undefined = any, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(config: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>;
|
|
95
|
+
type Middleware = (context: HandlerContext) => void | Promise<void>;
|
|
96
|
+
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
97
|
+
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
98
|
+
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
99
|
+
type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
|
|
100
|
+
interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
|
|
101
|
+
params: TParams;
|
|
102
|
+
query: TQuery;
|
|
103
|
+
body: TBody;
|
|
104
|
+
}
|
|
105
|
+
interface RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
|
|
106
|
+
response: TResponse;
|
|
107
|
+
}
|
|
108
|
+
type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>) => any;
|
|
109
|
+
declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string): void;
|
|
110
|
+
|
|
111
|
+
interface ArriServerOptions extends AppOptions {
|
|
112
|
+
rpcRoutePrefix?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Defaults to /__definitions
|
|
115
|
+
* This parameters also takes the rpcRoutePrefix option into account
|
|
116
|
+
*/
|
|
117
|
+
rpcDefinitionPath?: string;
|
|
118
|
+
appDescription?: string;
|
|
119
|
+
}
|
|
120
|
+
declare class ArriServer {
|
|
121
|
+
app: App;
|
|
122
|
+
router: Router;
|
|
123
|
+
rpcRoutePrefix: string;
|
|
124
|
+
rpcDefinitionPath: string;
|
|
125
|
+
procedures: Record<string, ProcedureDefinition>;
|
|
126
|
+
models: Record<string, TObject>;
|
|
127
|
+
middlewares: Middleware[];
|
|
128
|
+
appDescription: string;
|
|
129
|
+
constructor(opts?: ArriServerOptions);
|
|
130
|
+
registerMiddleware(middleware: Middleware): void;
|
|
131
|
+
/**
|
|
132
|
+
* Statically register routes to the server router
|
|
133
|
+
* Routes will not be served until this is done
|
|
134
|
+
*/
|
|
135
|
+
initializeRoutes(): void;
|
|
136
|
+
registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>>(name: string, procedure: ArriProcedure<TParams, TResponse, TFinalResponse>): void;
|
|
137
|
+
registerRoute<TPath extends string, TMethod extends HttpMethod = HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(route: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): void;
|
|
138
|
+
getAppDefinition(): ApplicationDefinition;
|
|
139
|
+
}
|
|
140
|
+
interface ArriService {
|
|
141
|
+
id: string;
|
|
142
|
+
procedures: Record<string, any>;
|
|
143
|
+
}
|
|
144
|
+
declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
|
|
145
|
+
type HttpMethod = (typeof HttpMethodValues)[number];
|
|
146
|
+
declare const isHttpMethod: (input: any) => input is "get" | "post" | "put" | "patch" | "delete" | "head";
|
|
147
|
+
|
|
148
|
+
export { ArriServer as A, type ApplicationDefinition as B, type ExtractParam as E, HttpMethodValues as H, type JsonSchemaObject as J, type Middleware as M, type ProcedureDefinition as P, type RpcHandlerContext as R, type ServiceDefinition as S, type ArriService as a, type HttpMethod as b, type ArriProcedureBase as c, type ArriProcedure as d, type HandlerContext as e, type RpcPostHandlerContext as f, type ArriProcedureHandler as g, type ArriProcedurePostHandler as h, isHttpMethod as i, isRpc as j, defineRpc as k, createRpcDefinition as l, getRpcPath as m, getRpcParamName as n, getRpcParamDefinition as o, getRpcResponseName as p, type ArriRoute as q, registerRpc as r, defineRoute as s, defineMiddleware as t, type ExtractParams as u, type ArriRouteHandler as v, type RouteHandlerContext as w, type RoutePostHandlerContext as x, type ArriRoutePostHandler as y, registerRoute as z };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
|
|
2
|
+
import { H3Event, Router, App, AppOptions } from 'h3';
|
|
3
|
+
|
|
4
|
+
interface ProcedureDefinition {
|
|
5
|
+
path: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
params: string | undefined;
|
|
9
|
+
response: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
interface ServiceDefinition {
|
|
12
|
+
[key: string]: ProcedureDefinition | ServiceDefinition;
|
|
13
|
+
}
|
|
14
|
+
interface ApplicationDefinition {
|
|
15
|
+
schemaVersion: "0.0.1";
|
|
16
|
+
description: string;
|
|
17
|
+
procedures: Record<string, ProcedureDefinition>;
|
|
18
|
+
models: Record<string, JsonSchemaObject>;
|
|
19
|
+
errors: Omit<TObject, symbol>;
|
|
20
|
+
}
|
|
21
|
+
declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
|
|
22
|
+
declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
|
|
23
|
+
type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
|
|
24
|
+
interface JsonSchemaScalarType {
|
|
25
|
+
title?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
type: (typeof JsonSchemaScalarTypeValues)[number];
|
|
28
|
+
}
|
|
29
|
+
interface JsonSchemaNullType {
|
|
30
|
+
type: (typeof JsonSchemaNullTypeValues)[number];
|
|
31
|
+
}
|
|
32
|
+
type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray;
|
|
33
|
+
interface JsonSchemaObject {
|
|
34
|
+
$id?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
type: "object";
|
|
38
|
+
properties: Record<string, JsonSchemaType>;
|
|
39
|
+
required?: string[];
|
|
40
|
+
}
|
|
41
|
+
interface JsonSchemaArray {
|
|
42
|
+
$id?: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
type: "array";
|
|
46
|
+
items: JsonSchemaType;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface ArriProcedureBase {
|
|
50
|
+
method: HttpMethod;
|
|
51
|
+
params?: any;
|
|
52
|
+
response?: any;
|
|
53
|
+
handler: (context: any) => any;
|
|
54
|
+
postHandler?: (context: any) => any;
|
|
55
|
+
}
|
|
56
|
+
interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>> {
|
|
57
|
+
description?: string;
|
|
58
|
+
method?: HttpMethod;
|
|
59
|
+
params: TParams;
|
|
60
|
+
response: TResponse;
|
|
61
|
+
handler: ArriProcedureHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
|
|
62
|
+
postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
|
|
63
|
+
}
|
|
64
|
+
interface HandlerContext {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
event: H3Event;
|
|
67
|
+
}
|
|
68
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
69
|
+
params: TParams;
|
|
70
|
+
}
|
|
71
|
+
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
72
|
+
response: TResponse;
|
|
73
|
+
}
|
|
74
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>) => TResponse | Promise<TResponse>;
|
|
75
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (event: RpcPostHandlerContext<TParams, TResponse>) => any;
|
|
76
|
+
declare function isRpc(input: any): input is ArriProcedure<any, any, any>;
|
|
77
|
+
declare function defineRpc<TParams extends TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined, TFinalResponse extends TResponse extends TObject ? Static<TObject> : Static<TVoid> = any>(config: ArriProcedure<TParams, TResponse, TFinalResponse>): ArriProcedure<TParams, TResponse, TFinalResponse>;
|
|
78
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition;
|
|
79
|
+
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
80
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
|
|
81
|
+
declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition["params"];
|
|
82
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
|
|
83
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any, any>, middleware: Middleware[]): void;
|
|
84
|
+
|
|
85
|
+
interface ArriRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any> {
|
|
86
|
+
path: TPath;
|
|
87
|
+
method: TMethod;
|
|
88
|
+
query?: TQuery;
|
|
89
|
+
body?: TBody;
|
|
90
|
+
response?: TResponse;
|
|
91
|
+
handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
92
|
+
postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
93
|
+
}
|
|
94
|
+
declare function defineRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = any, TBody extends TSchema | undefined = any, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(config: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>;
|
|
95
|
+
type Middleware = (context: HandlerContext) => void | Promise<void>;
|
|
96
|
+
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
97
|
+
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
98
|
+
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
99
|
+
type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
|
|
100
|
+
interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
|
|
101
|
+
params: TParams;
|
|
102
|
+
query: TQuery;
|
|
103
|
+
body: TBody;
|
|
104
|
+
}
|
|
105
|
+
interface RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
|
|
106
|
+
response: TResponse;
|
|
107
|
+
}
|
|
108
|
+
type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>) => any;
|
|
109
|
+
declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string): void;
|
|
110
|
+
|
|
111
|
+
interface ArriServerOptions extends AppOptions {
|
|
112
|
+
rpcRoutePrefix?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Defaults to /__definitions
|
|
115
|
+
* This parameters also takes the rpcRoutePrefix option into account
|
|
116
|
+
*/
|
|
117
|
+
rpcDefinitionPath?: string;
|
|
118
|
+
appDescription?: string;
|
|
119
|
+
}
|
|
120
|
+
declare class ArriServer {
|
|
121
|
+
app: App;
|
|
122
|
+
router: Router;
|
|
123
|
+
rpcRoutePrefix: string;
|
|
124
|
+
rpcDefinitionPath: string;
|
|
125
|
+
procedures: Record<string, ProcedureDefinition>;
|
|
126
|
+
models: Record<string, TObject>;
|
|
127
|
+
middlewares: Middleware[];
|
|
128
|
+
appDescription: string;
|
|
129
|
+
constructor(opts?: ArriServerOptions);
|
|
130
|
+
registerMiddleware(middleware: Middleware): void;
|
|
131
|
+
/**
|
|
132
|
+
* Statically register routes to the server router
|
|
133
|
+
* Routes will not be served until this is done
|
|
134
|
+
*/
|
|
135
|
+
initializeRoutes(): void;
|
|
136
|
+
registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>>(name: string, procedure: ArriProcedure<TParams, TResponse, TFinalResponse>): void;
|
|
137
|
+
registerRoute<TPath extends string, TMethod extends HttpMethod = HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(route: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): void;
|
|
138
|
+
getAppDefinition(): ApplicationDefinition;
|
|
139
|
+
}
|
|
140
|
+
interface ArriService {
|
|
141
|
+
id: string;
|
|
142
|
+
procedures: Record<string, any>;
|
|
143
|
+
}
|
|
144
|
+
declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
|
|
145
|
+
type HttpMethod = (typeof HttpMethodValues)[number];
|
|
146
|
+
declare const isHttpMethod: (input: any) => input is "get" | "post" | "put" | "patch" | "delete" | "head";
|
|
147
|
+
|
|
148
|
+
export { ArriServer as A, type ApplicationDefinition as B, type ExtractParam as E, HttpMethodValues as H, type JsonSchemaObject as J, type Middleware as M, type ProcedureDefinition as P, type RpcHandlerContext as R, type ServiceDefinition as S, type ArriService as a, type HttpMethod as b, type ArriProcedureBase as c, type ArriProcedure as d, type HandlerContext as e, type RpcPostHandlerContext as f, type ArriProcedureHandler as g, type ArriProcedurePostHandler as h, isHttpMethod as i, isRpc as j, defineRpc as k, createRpcDefinition as l, getRpcPath as m, getRpcParamName as n, getRpcParamDefinition as o, getRpcResponseName as p, type ArriRoute as q, registerRpc as r, defineRoute as s, defineMiddleware as t, type ExtractParams as u, type ArriRouteHandler as v, type RouteHandlerContext as w, type RoutePostHandlerContext as x, type ArriRoutePostHandler as y, registerRoute as z };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
|
|
2
|
+
import { H3Event, Router, App, AppOptions } from 'h3';
|
|
3
|
+
|
|
4
|
+
interface ProcedureDefinition {
|
|
5
|
+
path: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
params: string | undefined;
|
|
9
|
+
response: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
interface ServiceDefinition {
|
|
12
|
+
[key: string]: ProcedureDefinition | ServiceDefinition;
|
|
13
|
+
}
|
|
14
|
+
interface ApplicationDefinition {
|
|
15
|
+
schemaVersion: "0.0.1";
|
|
16
|
+
description: string;
|
|
17
|
+
procedures: Record<string, ProcedureDefinition>;
|
|
18
|
+
models: Record<string, JsonSchemaObject>;
|
|
19
|
+
errors: Omit<TObject, symbol>;
|
|
20
|
+
}
|
|
21
|
+
declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
|
|
22
|
+
declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
|
|
23
|
+
type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
|
|
24
|
+
interface JsonSchemaScalarType {
|
|
25
|
+
title?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
type: (typeof JsonSchemaScalarTypeValues)[number];
|
|
28
|
+
}
|
|
29
|
+
interface JsonSchemaNullType {
|
|
30
|
+
type: (typeof JsonSchemaNullTypeValues)[number];
|
|
31
|
+
}
|
|
32
|
+
type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray;
|
|
33
|
+
interface JsonSchemaObject {
|
|
34
|
+
$id?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
type: "object";
|
|
38
|
+
properties: Record<string, JsonSchemaType>;
|
|
39
|
+
required?: string[];
|
|
40
|
+
}
|
|
41
|
+
interface JsonSchemaArray {
|
|
42
|
+
$id?: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
type: "array";
|
|
46
|
+
items: JsonSchemaType;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface ArriProcedureBase {
|
|
50
|
+
method: HttpMethod;
|
|
51
|
+
params?: any;
|
|
52
|
+
response?: any;
|
|
53
|
+
handler: (context: any) => any;
|
|
54
|
+
postHandler?: (context: any) => any;
|
|
55
|
+
}
|
|
56
|
+
interface ArriProcedure<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>> {
|
|
57
|
+
description?: string;
|
|
58
|
+
method?: HttpMethod;
|
|
59
|
+
params: TParams;
|
|
60
|
+
response: TResponse;
|
|
61
|
+
handler: ArriProcedureHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
|
|
62
|
+
postHandler?: ArriProcedurePostHandler<TParams extends TObject ? Static<TParams> : undefined, TFinalResponse>;
|
|
63
|
+
}
|
|
64
|
+
interface HandlerContext {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
event: H3Event;
|
|
67
|
+
}
|
|
68
|
+
interface RpcHandlerContext<TParams = undefined> extends HandlerContext {
|
|
69
|
+
params: TParams;
|
|
70
|
+
}
|
|
71
|
+
interface RpcPostHandlerContext<TParams = undefined, TResponse = undefined> extends RpcHandlerContext<TParams> {
|
|
72
|
+
response: TResponse;
|
|
73
|
+
}
|
|
74
|
+
type ArriProcedureHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>) => TResponse | Promise<TResponse>;
|
|
75
|
+
type ArriProcedurePostHandler<TParams, TResponse> = (event: RpcPostHandlerContext<TParams, TResponse>) => any;
|
|
76
|
+
declare function isRpc(input: any): input is ArriProcedure<any, any, any>;
|
|
77
|
+
declare function defineRpc<TParams extends TObject | undefined = undefined, TResponse extends TObject | undefined | never = undefined, TFinalResponse extends TResponse extends TObject ? Static<TObject> : Static<TVoid> = any>(config: ArriProcedure<TParams, TResponse, TFinalResponse>): ArriProcedure<TParams, TResponse, TFinalResponse>;
|
|
78
|
+
declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition;
|
|
79
|
+
declare function getRpcPath(rpcName: string, prefix?: string): string;
|
|
80
|
+
declare function getRpcParamName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
|
|
81
|
+
declare function getRpcParamDefinition(rpcName: string, procedure: ArriProcedure<any, any, any>): ProcedureDefinition["params"];
|
|
82
|
+
declare function getRpcResponseName(rpcName: string, procedure: ArriProcedure<any, any, any>): string | null;
|
|
83
|
+
declare function registerRpc(router: Router, path: string, procedure: ArriProcedure<any, any, any>, middleware: Middleware[]): void;
|
|
84
|
+
|
|
85
|
+
interface ArriRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any> {
|
|
86
|
+
path: TPath;
|
|
87
|
+
method: TMethod;
|
|
88
|
+
query?: TQuery;
|
|
89
|
+
body?: TBody;
|
|
90
|
+
response?: TResponse;
|
|
91
|
+
handler: ArriRouteHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
92
|
+
postHandler?: ArriRoutePostHandler<TPath, TQuery extends TObject ? Static<TQuery> : undefined, TBody extends TObject ? Static<TObject> : undefined, TResponse extends TSchema ? Static<TResponse> : TFallbackResponse>;
|
|
93
|
+
}
|
|
94
|
+
declare function defineRoute<TPath extends string, TMethod extends HttpMethod, TQuery extends TObject | undefined = any, TBody extends TSchema | undefined = any, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(config: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>;
|
|
95
|
+
type Middleware = (context: HandlerContext) => void | Promise<void>;
|
|
96
|
+
declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
97
|
+
type ExtractParam<Path, NextPart> = Path extends `:${infer Param}` ? Record<Param, string> & NextPart : NextPart;
|
|
98
|
+
type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}` ? ExtractParam<Segment, ExtractParams<Rest>> : ExtractParam<Path, {}>;
|
|
99
|
+
type ArriRouteHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = any> = (context: RouteHandlerContext<ExtractParams<TPath>, TQuery, TBody>) => TResponse extends undefined ? void | Promise<void> : TResponse | Promise<TResponse>;
|
|
100
|
+
interface RouteHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined> extends HandlerContext {
|
|
101
|
+
params: TParams;
|
|
102
|
+
query: TQuery;
|
|
103
|
+
body: TBody;
|
|
104
|
+
}
|
|
105
|
+
interface RoutePostHandlerContext<TParams extends Record<string, string>, TQuery = undefined, TBody = undefined, TResponse = undefined> extends RouteHandlerContext<TParams, TQuery, TBody> {
|
|
106
|
+
response: TResponse;
|
|
107
|
+
}
|
|
108
|
+
type ArriRoutePostHandler<TPath extends string, TQuery = undefined, TBody = undefined, TResponse = undefined> = (context: RoutePostHandlerContext<ExtractParams<TPath>, TQuery, TBody, TResponse>) => any;
|
|
109
|
+
declare function registerRoute<TPath extends string>(router: Router, route: ArriRoute<TPath, HttpMethod, any, any, any>, middleware: Middleware[], prefix?: string): void;
|
|
110
|
+
|
|
111
|
+
interface ArriServerOptions extends AppOptions {
|
|
112
|
+
rpcRoutePrefix?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Defaults to /__definitions
|
|
115
|
+
* This parameters also takes the rpcRoutePrefix option into account
|
|
116
|
+
*/
|
|
117
|
+
rpcDefinitionPath?: string;
|
|
118
|
+
appDescription?: string;
|
|
119
|
+
}
|
|
120
|
+
declare class ArriServer {
|
|
121
|
+
app: App;
|
|
122
|
+
router: Router;
|
|
123
|
+
rpcRoutePrefix: string;
|
|
124
|
+
rpcDefinitionPath: string;
|
|
125
|
+
procedures: Record<string, ProcedureDefinition>;
|
|
126
|
+
models: Record<string, TObject>;
|
|
127
|
+
middlewares: Middleware[];
|
|
128
|
+
appDescription: string;
|
|
129
|
+
constructor(opts?: ArriServerOptions);
|
|
130
|
+
registerMiddleware(middleware: Middleware): void;
|
|
131
|
+
/**
|
|
132
|
+
* Statically register routes to the server router
|
|
133
|
+
* Routes will not be served until this is done
|
|
134
|
+
*/
|
|
135
|
+
initializeRoutes(): void;
|
|
136
|
+
registerRpc<TParams extends TObject | undefined, TResponse extends TObject | undefined, TFinalResponse extends TResponse extends TObject ? Static<TResponse> : Static<TVoid>>(name: string, procedure: ArriProcedure<TParams, TResponse, TFinalResponse>): void;
|
|
137
|
+
registerRoute<TPath extends string, TMethod extends HttpMethod = HttpMethod, TQuery extends TObject | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined, TFallbackResponse = any>(route: ArriRoute<TPath, TMethod, TQuery, TBody, TResponse, TFallbackResponse>): void;
|
|
138
|
+
getAppDefinition(): ApplicationDefinition;
|
|
139
|
+
}
|
|
140
|
+
interface ArriService {
|
|
141
|
+
id: string;
|
|
142
|
+
procedures: Record<string, any>;
|
|
143
|
+
}
|
|
144
|
+
declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
|
|
145
|
+
type HttpMethod = (typeof HttpMethodValues)[number];
|
|
146
|
+
declare const isHttpMethod: (input: any) => input is "get" | "post" | "put" | "patch" | "delete" | "head";
|
|
147
|
+
|
|
148
|
+
export { ArriServer as A, type ApplicationDefinition as B, type ExtractParam as E, HttpMethodValues as H, type JsonSchemaObject as J, type Middleware as M, type ProcedureDefinition as P, type RpcHandlerContext as R, type ServiceDefinition as S, type ArriService as a, type HttpMethod as b, type ArriProcedureBase as c, type ArriProcedure as d, type HandlerContext as e, type RpcPostHandlerContext as f, type ArriProcedureHandler as g, type ArriProcedurePostHandler as h, isHttpMethod as i, isRpc as j, defineRpc as k, createRpcDefinition as l, getRpcPath as m, getRpcParamName as n, getRpcParamDefinition as o, getRpcResponseName as p, type ArriRoute as q, registerRpc as r, defineRoute as s, defineMiddleware as t, type ExtractParams as u, type ArriRouteHandler as v, type RouteHandlerContext as w, type RoutePostHandlerContext as x, type ArriRoutePostHandler as y, registerRoute as z };
|