@orpc/contract 0.0.0-next.f22c7ec → 0.0.0-next.f4d410a

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,23 +0,0 @@
1
- import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
2
- import type { RouteOptions } from './procedure';
3
- import type { ContractRouter } from './router';
4
- import type { AdaptedContractRouter } from './router-builder';
5
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
6
- import { DecoratedContractProcedure } from './procedure-decorated';
7
- import { ContractRouterBuilder } from './router-builder';
8
- export type ContractBuilderDef<TErrorMap extends ErrorMap> = {
9
- errorMap: TErrorMap;
10
- };
11
- export declare class ContractBuilder<TErrorMap extends ErrorMap> {
12
- '~type': "ContractBuilder";
13
- '~orpc': ContractBuilderDef<TErrorMap>;
14
- constructor(def: ContractBuilderDef<TErrorMap>);
15
- errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractBuilder<U & TErrorMap>;
16
- prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap>;
17
- tag(...tags: string[]): ContractRouterBuilder<TErrorMap>;
18
- route(route: RouteOptions): DecoratedContractProcedure<undefined, undefined, TErrorMap>;
19
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, undefined, TErrorMap>;
20
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<undefined, U, TErrorMap>;
21
- router<T extends ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>(router: T): AdaptedContractRouter<T, TErrorMap>;
22
- }
23
- //# sourceMappingURL=builder.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { ClientPromiseResult } from './client';
2
- import { type ORPCError } from './error-orpc';
3
- export type SafeResult<TOutput, TError extends Error> = [output: TOutput, error: undefined, isDefinedError: false] | [output: undefined, error: TError, isDefinedError: false] | [output: undefined, error: Extract<TError, ORPCError<any, any>>, isDefinedError: true];
4
- export declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
5
- //# sourceMappingURL=client-utils.d.ts.map
@@ -1,19 +0,0 @@
1
- import type { AbortSignal } from './types';
2
- export type ClientOptions<TClientContext> = {
3
- signal?: AbortSignal;
4
- } & (undefined extends TClientContext ? {
5
- context?: TClientContext;
6
- } : {
7
- context: TClientContext;
8
- });
9
- export type ClientRest<TClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never);
10
- export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
11
- __typeError?: TError;
12
- };
13
- export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
14
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
15
- }
16
- export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
17
- [k: string]: NestedClient<TClientContext>;
18
- };
19
- //# sourceMappingURL=client.d.ts.map
@@ -1,36 +0,0 @@
1
- import type { HTTPMethod, InputStructure } from './types';
2
- export interface ORPCConfig {
3
- /**
4
- * @default 'POST'
5
- */
6
- defaultMethod?: HTTPMethod;
7
- /**
8
- *
9
- * @default 200
10
- */
11
- defaultSuccessStatus?: number;
12
- /**
13
- *
14
- * @default 'OK'
15
- */
16
- defaultSuccessDescription?: string;
17
- /**
18
- *
19
- * @default 'compact'
20
- */
21
- defaultInputStructure?: InputStructure;
22
- /**
23
- *
24
- * @default 'compact'
25
- */
26
- defaultOutputStructure?: InputStructure;
27
- }
28
- /**
29
- * Set the global configuration, this configuration can effect entire project
30
- */
31
- export declare function configGlobal(config: ORPCConfig): void;
32
- /**
33
- * Fallback the value to the global config if it is undefined
34
- */
35
- export declare function fallbackToGlobalConfig<T extends keyof ORPCConfig>(key: T, value: ORPCConfig[T]): Exclude<ORPCConfig[T], undefined>;
36
- //# sourceMappingURL=config.d.ts.map
@@ -1,58 +0,0 @@
1
- import type { CommonORPCErrorCode } from './error-orpc';
2
- import type { Schema } from './types';
3
- export type ErrorMapItem<TDataSchema extends Schema> = {
4
- /**
5
- *
6
- * @default 500
7
- */
8
- status?: number;
9
- message?: string;
10
- description?: string;
11
- data?: TDataSchema;
12
- };
13
- export interface ErrorMap {
14
- [k: string]: ErrorMapItem<Schema>;
15
- }
16
- /**
17
- * const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions
18
- *
19
- * Purpose:
20
- * - Helps `U` suggest `CommonORPCErrorCode` to the user when typing.
21
- *
22
- * Why not replace `ErrorMap` with `ErrorMapSuggestions`?
23
- * - `ErrorMapSuggestions` has a drawback: it allows `undefined` values for items.
24
- * - `ErrorMapGuard<TErrorMap>` uses `Partial`, which can introduce `undefined` values.
25
- *
26
- * This could lead to unintended behavior where `undefined` values override `TErrorMap`,
27
- * potentially resulting in a `never` type after merging.
28
- *
29
- * Recommendation:
30
- * - Use `ErrorMapSuggestions` to assist users in typing correctly but do not replace `ErrorMap`.
31
- * - Ensure `ErrorMapGuard<TErrorMap>` is adjusted to prevent `undefined` values.
32
- */
33
- export type ErrorMapSuggestions = {
34
- [key in CommonORPCErrorCode | (string & {})]?: ErrorMapItem<Schema>;
35
- };
36
- /**
37
- * `U` extends `ErrorMap` & `ErrorMapGuard<TErrorMap>`
38
- *
39
- * `ErrorMapGuard` is a utility type that ensures `U` cannot redefine the structure of `TErrorMap`.
40
- * It achieves this by setting each key in `TErrorMap` to `never`, effectively preventing any redefinition.
41
- *
42
- * Why not just use `Partial<TErrorMap>`?
43
- * - Allowing users to redefine existing error map items would require using `StrictErrorMap`.
44
- * - However, I prefer not to use `StrictErrorMap` frequently, due to perceived performance concerns,
45
- * though this has not been benchmarked and is based on personal preference.
46
- *
47
- */
48
- export type ErrorMapGuard<TErrorMap extends ErrorMap> = {
49
- [K in keyof TErrorMap]?: never;
50
- };
51
- /**
52
- * Since `undefined` has a specific meaning (it use default value),
53
- * we ensure all additional properties in each item of the ErrorMap are explicitly set to `undefined`.
54
- */
55
- export type StrictErrorMap<T extends ErrorMap> = {
56
- [K in keyof T]: T[K] & Partial<Record<Exclude<keyof ErrorMapItem<any>, keyof T[K]>, undefined>>;
57
- };
58
- //# sourceMappingURL=error-map.d.ts.map
@@ -1,109 +0,0 @@
1
- import type { ErrorMap, ErrorMapItem } from './error-map';
2
- import type { SchemaOutput } from './types';
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 ORPCErrorOptions<TCode extends string, TData> = ErrorOptions & {
86
- defined?: boolean;
87
- code: TCode;
88
- status?: number;
89
- message?: string;
90
- } & (undefined extends TData ? {
91
- data?: TData;
92
- } : {
93
- data: TData;
94
- });
95
- export declare function fallbackORPCErrorStatus(code: CommonORPCErrorCode | (string & {}), status: number | undefined): number;
96
- export declare function fallbackORPCErrorMessage(code: CommonORPCErrorCode | (string & {}), message: string | undefined): string;
97
- export declare class ORPCError<TCode extends CommonORPCErrorCode | (string & {}), TData> extends Error {
98
- readonly defined: boolean;
99
- readonly code: TCode;
100
- readonly status: number;
101
- readonly data: TData;
102
- constructor(options: ORPCErrorOptions<TCode, TData>);
103
- toJSON(): ORPCErrorJSON<TCode, TData>;
104
- static isValidJSON(json: unknown): json is ORPCErrorJSON<string, unknown>;
105
- }
106
- export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
107
- export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
108
- export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
109
- //# sourceMappingURL=error-orpc.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,18 +0,0 @@
1
- /** unnoq */
2
- import { ContractBuilder } from './builder';
3
- export * from './builder';
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 './procedure';
11
- export * from './procedure-client';
12
- export * from './procedure-decorated';
13
- export * from './router';
14
- export * from './router-builder';
15
- export * from './router-client';
16
- export * from './types';
17
- export declare const oc: ContractBuilder<Record<never, never>>;
18
- //# sourceMappingURL=index.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 './types';
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,14 +0,0 @@
1
- import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
2
- import type { RouteOptions } from './procedure';
3
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
4
- import { ContractProcedure } from './procedure';
5
- export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap> {
6
- static decorate<UInputSchema extends Schema, UOutputSchema extends Schema, TErrorMap extends ErrorMap>(procedure: ContractProcedure<UInputSchema, UOutputSchema, TErrorMap>): DecoratedContractProcedure<UInputSchema, UOutputSchema, TErrorMap>;
7
- route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
8
- prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
9
- unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
10
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema, TErrorMap>;
11
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U, TErrorMap>;
12
- errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap & U>;
13
- }
14
- //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -1,83 +0,0 @@
1
- import type { ErrorMap } from './error-map';
2
- import type { HTTPMethod, HTTPPath, InputStructure, OutputStructure, Schema, SchemaOutput } from './types';
3
- export interface RouteOptions {
4
- method?: HTTPMethod;
5
- path?: HTTPPath;
6
- summary?: string;
7
- description?: string;
8
- deprecated?: boolean;
9
- tags?: readonly string[];
10
- /**
11
- * The status code of the response when the procedure is successful.
12
- *
13
- * @default 200
14
- */
15
- successStatus?: number;
16
- /**
17
- * The description of the response when the procedure is successful.
18
- *
19
- * @default 'OK'
20
- */
21
- successDescription?: string;
22
- /**
23
- * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
24
- *
25
- * @option 'compact'
26
- * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
27
- *
28
- * @option 'detailed'
29
- * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
30
- *
31
- * Example:
32
- * ```ts
33
- * const input = {
34
- * params: { id: 1 },
35
- * query: { search: 'hello' },
36
- * headers: { 'Content-Type': 'application/json' },
37
- * body: { name: 'John' },
38
- * }
39
- * ```
40
- *
41
- * @default 'compact'
42
- */
43
- inputStructure?: InputStructure;
44
- /**
45
- * Determines how the response should be structured based on the output.
46
- *
47
- * @option 'compact'
48
- * Includes only the body data, encoded directly in the response.
49
- *
50
- * @option 'detailed'
51
- * Separates the output into `headers` and `body` fields.
52
- * - `headers`: Custom headers to merge with the response headers.
53
- * - `body`: The response data.
54
- *
55
- * Example:
56
- * ```ts
57
- * const output = {
58
- * headers: { 'x-custom-header': 'value' },
59
- * body: { message: 'Hello, world!' },
60
- * };
61
- * ```
62
- *
63
- * @default 'compact'
64
- */
65
- outputStructure?: OutputStructure;
66
- }
67
- export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
68
- route?: RouteOptions;
69
- InputSchema: TInputSchema;
70
- inputExample?: SchemaOutput<TInputSchema>;
71
- OutputSchema: TOutputSchema;
72
- outputExample?: SchemaOutput<TOutputSchema>;
73
- errorMap: TErrorMap;
74
- }
75
- export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
76
- '~type': "ContractProcedure";
77
- '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap>;
78
- constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap>);
79
- }
80
- export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any, any>;
81
- export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema, ErrorMap>;
82
- export declare function isContractProcedure(item: unknown): item is ANY_CONTRACT_PROCEDURE;
83
- //# sourceMappingURL=procedure.d.ts.map
@@ -1,23 +0,0 @@
1
- import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
2
- import type { ContractProcedure } from './procedure';
3
- import type { ContractRouter } from './router';
4
- import type { HTTPPath } from './types';
5
- import { DecoratedContractProcedure } from './procedure-decorated';
6
- export type AdaptedContractRouter<TContract extends ContractRouter<any>, TErrorMapExtra extends ErrorMap> = {
7
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors> ? DecoratedContractProcedure<UInputSchema, UOutputSchema, UErrors & TErrorMapExtra> : TContract[K] extends ContractRouter<any> ? AdaptedContractRouter<TContract[K], TErrorMapExtra> : never;
8
- };
9
- export interface ContractRouterBuilderDef<TErrorMap extends ErrorMap> {
10
- prefix?: HTTPPath;
11
- tags?: string[];
12
- errorMap: TErrorMap;
13
- }
14
- export declare class ContractRouterBuilder<TErrorMap extends ErrorMap> {
15
- '~type': "ContractProcedure";
16
- '~orpc': ContractRouterBuilderDef<TErrorMap>;
17
- constructor(def: ContractRouterBuilderDef<TErrorMap>);
18
- prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap>;
19
- tag(...tags: string[]): ContractRouterBuilder<TErrorMap>;
20
- errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractRouterBuilder<U & TErrorMap>;
21
- router<T extends ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>(router: T): AdaptedContractRouter<T, TErrorMap>;
22
- }
23
- //# sourceMappingURL=router-builder.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { ContractProcedure } from './procedure';
2
- import type { ContractProcedureClient } from './procedure-client';
3
- import type { ContractRouter } from './router';
4
- export type ContractRouterClient<TRouter extends ContractRouter<any>, TClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
5
- [K in keyof TRouter]: TRouter[K] extends ContractRouter<any> ? ContractRouterClient<TRouter[K], TClientContext> : never;
6
- };
7
- //# sourceMappingURL=router-client.d.ts.map
@@ -1,13 +0,0 @@
1
- import type { ErrorMap } from './error-map';
2
- import type { ContractProcedure } from './procedure';
3
- import type { SchemaInput, SchemaOutput } from './types';
4
- export type ContractRouter<T extends ErrorMap> = ContractProcedure<any, any, T> | {
5
- [k: string]: ContractRouter<T>;
6
- };
7
- export type InferContractRouterInputs<T extends ContractRouter<any>> = T extends ContractProcedure<infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : {
8
- [K in keyof T]: T[K] extends ContractRouter<any> ? InferContractRouterInputs<T[K]> : never;
9
- };
10
- export type InferContractRouterOutputs<T extends ContractRouter<any>> = T extends ContractProcedure<any, infer UOutputSchema, any> ? SchemaOutput<UOutputSchema> : {
11
- [K in keyof T]: T[K] extends ContractRouter<any> ? InferContractRouterOutputs<T[K]> : never;
12
- };
13
- //# sourceMappingURL=router.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { FindGlobalInstanceType } from '@orpc/shared';
2
- import type { StandardSchemaV1 } from '@standard-schema/spec';
3
- export type HTTPPath = `/${string}`;
4
- export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
- export type InputStructure = 'compact' | 'detailed';
6
- export type OutputStructure = 'compact' | 'detailed';
7
- export type Schema = StandardSchemaV1 | undefined;
8
- export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
9
- export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
10
- export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
11
- //# sourceMappingURL=types.d.ts.map