@orpc/contract 0.0.0-next.f56d2b3 → 0.0.0-next.f677f1d

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.
@@ -1,109 +0,0 @@
1
- import type { ErrorMap, ErrorMapItem } from './error-map';
2
- import type { SchemaOutput } from './schema';
3
- export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
4
- [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
5
- }[keyof TErrorMap];
6
- export declare const COMMON_ORPC_ERROR_DEFS: {
7
- readonly BAD_REQUEST: {
8
- readonly status: 400;
9
- readonly message: "Bad Request";
10
- };
11
- readonly UNAUTHORIZED: {
12
- readonly status: 401;
13
- readonly message: "Unauthorized";
14
- };
15
- readonly FORBIDDEN: {
16
- readonly status: 403;
17
- readonly message: "Forbidden";
18
- };
19
- readonly NOT_FOUND: {
20
- readonly status: 404;
21
- readonly message: "Not Found";
22
- };
23
- readonly METHOD_NOT_SUPPORTED: {
24
- readonly status: 405;
25
- readonly message: "Method Not Supported";
26
- };
27
- readonly NOT_ACCEPTABLE: {
28
- readonly status: 406;
29
- readonly message: "Not Acceptable";
30
- };
31
- readonly TIMEOUT: {
32
- readonly status: 408;
33
- readonly message: "Request Timeout";
34
- };
35
- readonly CONFLICT: {
36
- readonly status: 409;
37
- readonly message: "Conflict";
38
- };
39
- readonly PRECONDITION_FAILED: {
40
- readonly status: 412;
41
- readonly message: "Precondition Failed";
42
- };
43
- readonly PAYLOAD_TOO_LARGE: {
44
- readonly status: 413;
45
- readonly message: "Payload Too Large";
46
- };
47
- readonly UNSUPPORTED_MEDIA_TYPE: {
48
- readonly status: 415;
49
- readonly message: "Unsupported Media Type";
50
- };
51
- readonly UNPROCESSABLE_CONTENT: {
52
- readonly status: 422;
53
- readonly message: "Unprocessable Content";
54
- };
55
- readonly TOO_MANY_REQUESTS: {
56
- readonly status: 429;
57
- readonly message: "Too Many Requests";
58
- };
59
- readonly CLIENT_CLOSED_REQUEST: {
60
- readonly status: 499;
61
- readonly message: "Client Closed Request";
62
- };
63
- readonly INTERNAL_SERVER_ERROR: {
64
- readonly status: 500;
65
- readonly message: "Internal Server Error";
66
- };
67
- readonly NOT_IMPLEMENTED: {
68
- readonly status: 501;
69
- readonly message: "Not Implemented";
70
- };
71
- readonly BAD_GATEWAY: {
72
- readonly status: 502;
73
- readonly message: "Bad Gateway";
74
- };
75
- readonly SERVICE_UNAVAILABLE: {
76
- readonly status: 503;
77
- readonly message: "Service Unavailable";
78
- };
79
- readonly GATEWAY_TIMEOUT: {
80
- readonly status: 504;
81
- readonly message: "Gateway Timeout";
82
- };
83
- };
84
- export type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
85
- export type ORPCErrorCode = CommonORPCErrorCode | (string & {});
86
- export declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
87
- export declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
88
- export type ORPCErrorOptions<TData> = ErrorOptions & {
89
- defined?: boolean;
90
- status?: number;
91
- message?: string;
92
- } & (undefined extends TData ? {
93
- data?: TData;
94
- } : {
95
- data: TData;
96
- });
97
- export type ORPCErrorOptionsRest<TData> = [options: ORPCErrorOptions<TData>] | (undefined extends TData ? [] : never);
98
- export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
99
- readonly defined: boolean;
100
- readonly code: TCode;
101
- readonly status: number;
102
- readonly data: TData;
103
- constructor(code: TCode, ...[options]: ORPCErrorOptionsRest<TData>);
104
- toJSON(): ORPCErrorJSON<TCode, TData>;
105
- static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>): ORPCError<TCode, TData>;
106
- static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
107
- }
108
- export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
109
- //# sourceMappingURL=error-orpc.d.ts.map
@@ -1,14 +0,0 @@
1
- import type { ErrorMap, ErrorMapItem } from './error-map';
2
- import type { ORPCErrorCode, ORPCErrorOptions } from './error-orpc';
3
- import type { SchemaInput } from './schema';
4
- import { ORPCError } from './error-orpc';
5
- export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
6
- export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
7
- export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
8
- export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: ORPCErrorConstructorMapItemRest<TInData>) => ORPCError<TCode, TInData>;
9
- export type ORPCErrorConstructorMap<T extends ErrorMap> = {
10
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
11
- };
12
- export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
13
- export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
14
- //# sourceMappingURL=error-utils.d.ts.map
@@ -1,13 +0,0 @@
1
- import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import type { ErrorMap } from './error-map';
3
- import type { ORPCErrorFromErrorMap } from './error-orpc';
4
- export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
5
- export interface ValidationErrorOptions extends ErrorOptions {
6
- message: string;
7
- issues: readonly StandardSchemaV1.Issue[];
8
- }
9
- export declare class ValidationError extends Error {
10
- readonly issues: readonly StandardSchemaV1.Issue[];
11
- constructor(options: ValidationErrorOptions);
12
- }
13
- //# sourceMappingURL=error.d.ts.map
@@ -1,19 +0,0 @@
1
- /** unnoq */
2
- export * from './builder';
3
- export * from './builder-variants';
4
- export * from './client';
5
- export * from './client-utils';
6
- export * from './config';
7
- export * from './error';
8
- export * from './error-map';
9
- export * from './error-orpc';
10
- export * from './error-utils';
11
- export * from './meta';
12
- export * from './procedure';
13
- export * from './procedure-client';
14
- export * from './route';
15
- export * from './router';
16
- export * from './router-client';
17
- export * from './schema';
18
- export * from './types';
19
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export type Meta = Record<string, any>;
2
- export declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
3
- //# sourceMappingURL=meta.d.ts.map
@@ -1,6 +0,0 @@
1
- import type { Client } from './client';
2
- import type { ErrorFromErrorMap } from './error';
3
- import type { ErrorMap } from './error-map';
4
- import type { Schema, SchemaInput, SchemaOutput } from './schema';
5
- export type ContractProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
6
- //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,18 +0,0 @@
1
- import type { ErrorMap } from './error-map';
2
- import type { Meta } from './meta';
3
- import type { Route } from './route';
4
- import type { Schema } from './schema';
5
- export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
6
- meta: TMeta;
7
- route: Route;
8
- inputSchema: TInputSchema;
9
- outputSchema: TOutputSchema;
10
- errorMap: TErrorMap;
11
- }
12
- export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
13
- '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
14
- constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
15
- }
16
- export type AnyContractProcedure = ContractProcedure<any, any, any, any>;
17
- export declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
18
- //# sourceMappingURL=procedure.d.ts.map
@@ -1,79 +0,0 @@
1
- export type HTTPPath = `/${string}`;
2
- export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3
- export type InputStructure = 'compact' | 'detailed';
4
- export type OutputStructure = 'compact' | 'detailed';
5
- export interface Route {
6
- method?: HTTPMethod;
7
- path?: HTTPPath;
8
- summary?: string;
9
- description?: string;
10
- deprecated?: boolean;
11
- tags?: readonly string[];
12
- /**
13
- * The status code of the response when the procedure is successful.
14
- *
15
- * @default 200
16
- */
17
- successStatus?: number;
18
- /**
19
- * The description of the response when the procedure is successful.
20
- *
21
- * @default 'OK'
22
- */
23
- successDescription?: string;
24
- /**
25
- * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
26
- *
27
- * @option 'compact'
28
- * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
29
- *
30
- * @option 'detailed'
31
- * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
32
- *
33
- * Example:
34
- * ```ts
35
- * const input = {
36
- * params: { id: 1 },
37
- * query: { search: 'hello' },
38
- * headers: { 'Content-Type': 'application/json' },
39
- * body: { name: 'John' },
40
- * }
41
- * ```
42
- *
43
- * @default 'compact'
44
- */
45
- inputStructure?: InputStructure;
46
- /**
47
- * Determines how the response should be structured based on the output.
48
- *
49
- * @option 'compact'
50
- * Includes only the body data, encoded directly in the response.
51
- *
52
- * @option 'detailed'
53
- * Separates the output into `headers` and `body` fields.
54
- * - `headers`: Custom headers to merge with the response headers.
55
- * - `body`: The response data.
56
- *
57
- * Example:
58
- * ```ts
59
- * const output = {
60
- * headers: { 'x-custom-header': 'value' },
61
- * body: { message: 'Hello, world!' },
62
- * };
63
- * ```
64
- *
65
- * @default 'compact'
66
- */
67
- outputStructure?: OutputStructure;
68
- }
69
- export declare function mergeRoute(a: Route, b: Route): Route;
70
- export declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
71
- export declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
72
- export declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
73
- export declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
74
- export interface AdaptRouteOptions {
75
- prefix?: HTTPPath;
76
- tags?: readonly string[];
77
- }
78
- export declare function adaptRoute(route: Route, options: AdaptRouteOptions): Route;
79
- //# sourceMappingURL=route.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { ContractProcedure } from './procedure';
2
- import type { ContractProcedureClient } from './procedure-client';
3
- import type { AnyContractRouter } from './router';
4
- export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
5
- [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
6
- };
7
- //# sourceMappingURL=router-client.d.ts.map
@@ -1,29 +0,0 @@
1
- import type { Meta } from './meta';
2
- import type { SchemaInput, SchemaOutput } from './schema';
3
- import { type ErrorMap, type MergedErrorMap } from './error-map';
4
- import { ContractProcedure } from './procedure';
5
- import { type HTTPPath } from './route';
6
- export type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
7
- [k: string]: ContractRouter<TMeta>;
8
- };
9
- export type AnyContractRouter = ContractRouter<any>;
10
- export type AdaptedContractRouter<TContract extends AnyContractRouter, TErrorMap extends ErrorMap> = {
11
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : TContract[K] extends AnyContractRouter ? AdaptedContractRouter<TContract[K], TErrorMap> : never;
12
- };
13
- export interface AdaptContractRouterOptions<TErrorMap extends ErrorMap> {
14
- errorMap: TErrorMap;
15
- prefix?: HTTPPath;
16
- tags?: readonly string[];
17
- }
18
- export declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
19
- export type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
20
- [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
21
- };
22
- export type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? SchemaOutput<UOutputSchema> : {
23
- [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
24
- };
25
- export type ContractRouterToErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
26
- [K in keyof T]: T[K] extends AnyContractRouter ? ContractRouterToErrorMap<T[K]> : never;
27
- }[keyof T];
28
- export type ContractRouterToMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
29
- //# sourceMappingURL=router.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { IsEqual, Promisable } from '@orpc/shared';
2
- import type { StandardSchemaV1 } from '@standard-schema/spec';
3
- export type Schema = StandardSchemaV1 | undefined;
4
- export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
5
- export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
6
- export type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
7
- export declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): StandardSchemaV1<TInput, TOutput>;
8
- //# sourceMappingURL=schema.d.ts.map
@@ -1,3 +0,0 @@
1
- import type { FindGlobalInstanceType } from '@orpc/shared';
2
- export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
3
- //# sourceMappingURL=types.d.ts.map