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