@orpc/contract 0.0.0-next.cba521d → 0.0.0-next.cc4cb21

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.
@@ -0,0 +1,38 @@
1
+ import type { ErrorMap, MergedErrorMap } from './error';
2
+ import type { Meta } from './meta';
3
+ import type { ContractProcedure } from './procedure';
4
+ import type { HTTPPath, Route } from './route';
5
+ import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
6
+ import type { Schema } from './schema';
7
+ export interface ContractProcedureBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
8
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
9
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
10
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
11
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
12
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
13
+ }
14
+ export interface ContractProcedureBuilderWithInput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
15
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
16
+ meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
17
+ route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
18
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
19
+ }
20
+ export interface ContractProcedureBuilderWithOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
21
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
22
+ meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
23
+ route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
24
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
25
+ }
26
+ export interface ContractProcedureBuilderWithInputOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
27
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
28
+ meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
29
+ route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
30
+ }
31
+ export interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
32
+ '~orpc': AdaptContractRouterOptions<TErrorMap>;
33
+ 'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
34
+ 'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
35
+ 'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
36
+ 'router'<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
37
+ }
38
+ //# sourceMappingURL=builder-variants.d.ts.map
@@ -1,16 +1,32 @@
1
- import type { ErrorMap } from './error-map';
2
- import type { RouteOptions } from './procedure';
3
- import type { ContractRouter } from './router';
4
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
5
- import { DecoratedContractProcedure } from './procedure-decorated';
6
- import { ContractRouterBuilder } from './router-builder';
7
- export declare class ContractBuilder {
8
- prefix(prefix: HTTPPath): ContractRouterBuilder;
9
- tag(...tags: string[]): ContractRouterBuilder;
10
- route(route: RouteOptions): DecoratedContractProcedure<undefined, undefined, undefined>;
11
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, undefined, undefined>;
12
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<undefined, U, undefined>;
13
- errors<const U extends ErrorMap>(errorMap: U): DecoratedContractProcedure<undefined, undefined, U>;
14
- router<T extends ContractRouter>(router: T): T;
1
+ import type { ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithOutput, ContractRouterBuilder } from './builder-variants';
2
+ import type { ContractProcedureDef } from './procedure';
3
+ import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
4
+ import type { Schema } from './schema';
5
+ import { type ErrorMap, type MergedErrorMap } from './error';
6
+ import { type Meta } from './meta';
7
+ import { ContractProcedure } from './procedure';
8
+ import { type HTTPPath, type Route } from './route';
9
+ export interface ContractBuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptContractRouterOptions<TErrorMap> {
15
10
  }
11
+ export declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
12
+ '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
13
+ constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
14
+ /**
15
+ * Reset initial meta
16
+ */
17
+ $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U>;
18
+ /**
19
+ * Reset initial route
20
+ */
21
+ $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
22
+ errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
23
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
24
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
25
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
26
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
27
+ prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
28
+ tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
29
+ router<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
30
+ }
31
+ export declare const oc: ContractBuilder<undefined, undefined, {}, {}>;
16
32
  //# sourceMappingURL=builder.d.ts.map
@@ -1,36 +1,10 @@
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;
1
+ import type { HTTPMethod, InputStructure } from './route';
2
+ export interface ContractConfig {
3
+ defaultMethod: HTTPMethod;
4
+ defaultSuccessStatus: number;
5
+ defaultSuccessDescription: string;
6
+ defaultInputStructure: InputStructure;
7
+ defaultOutputStructure: InputStructure;
27
8
  }
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>;
9
+ export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
36
10
  //# sourceMappingURL=config.d.ts.map
@@ -1,7 +1,6 @@
1
+ import type { ORPCError, ORPCErrorCode } from '@orpc/client';
1
2
  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>;
3
+ import type { Schema, SchemaOutput } from './schema';
5
4
  export interface ValidationErrorOptions extends ErrorOptions {
6
5
  message: string;
7
6
  issues: readonly StandardSchemaV1.Issue[];
@@ -10,4 +9,19 @@ export declare class ValidationError extends Error {
10
9
  readonly issues: readonly StandardSchemaV1.Issue[];
11
10
  constructor(options: ValidationErrorOptions);
12
11
  }
12
+ export type ErrorMapItem<TDataSchema extends Schema> = {
13
+ status?: number;
14
+ message?: string;
15
+ description?: string;
16
+ data?: TDataSchema;
17
+ };
18
+ export type ErrorMap = {
19
+ [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
20
+ };
21
+ export type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
22
+ export declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
23
+ export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
24
+ [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
25
+ }[keyof TErrorMap];
26
+ export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
13
27
  //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { Schema } from './schema';
3
+ export declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: StandardSchemaV1<TYieldIn, TYieldOut>, returns?: StandardSchemaV1<TReturnIn, TReturnOut>): StandardSchemaV1<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
4
+ export declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
5
+ yields: Schema;
6
+ returns: Schema;
7
+ };
8
+ //# sourceMappingURL=event-iterator.d.ts.map
@@ -1,18 +1,15 @@
1
1
  /** unnoq */
2
- import { ContractBuilder } from './builder';
3
2
  export * from './builder';
4
- export * from './client';
5
- export * from './client-utils';
3
+ export * from './builder-variants';
6
4
  export * from './config';
7
5
  export * from './error';
8
- export * from './error-map';
9
- export * from './error-orpc';
6
+ export * from './event-iterator';
7
+ export * from './meta';
10
8
  export * from './procedure';
11
9
  export * from './procedure-client';
12
- export * from './procedure-decorated';
10
+ export * from './route';
13
11
  export * from './router';
14
- export * from './router-builder';
15
12
  export * from './router-client';
16
- export * from './types';
17
- export declare const oc: ContractBuilder;
13
+ export * from './schema';
14
+ export { ORPCError } from '@orpc/client';
18
15
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
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 +1,5 @@
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>>;
1
+ import type { Client, ClientContext } from '@orpc/client';
2
+ import type { ErrorFromErrorMap, ErrorMap } from './error';
3
+ import type { Schema, SchemaInput, SchemaOutput } from './schema';
4
+ export type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
6
5
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,83 +1,18 @@
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>;
1
+ import type { ErrorMap } from './error';
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;
73
10
  errorMap: TErrorMap;
74
11
  }
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>);
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>);
79
15
  }
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;
16
+ export type AnyContractProcedure = ContractProcedure<any, any, any, any>;
17
+ export declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
83
18
  //# sourceMappingURL=procedure.d.ts.map
@@ -0,0 +1,79 @@
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 +1,8 @@
1
+ import type { ClientContext } from '@orpc/client';
1
2
  import type { ContractProcedure } from './procedure';
2
3
  import type { ContractProcedureClient } from './procedure-client';
3
- import type { ContractRouter } from './router';
4
- export type ContractRouterClient<TRouter extends ContractRouter, TClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
5
- [K in keyof TRouter]: TRouter[K] extends ContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
4
+ import type { AnyContractRouter } from './router';
5
+ export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
6
+ [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
6
7
  };
7
8
  //# sourceMappingURL=router-client.d.ts.map
@@ -1,12 +1,29 @@
1
- import type { ANY_CONTRACT_PROCEDURE, ContractProcedure } from './procedure';
2
- import type { SchemaInput, SchemaOutput } from './types';
3
- export type ContractRouter = ANY_CONTRACT_PROCEDURE | {
4
- [k: string]: ContractRouter;
1
+ import type { Meta } from './meta';
2
+ import type { SchemaInput, SchemaOutput } from './schema';
3
+ import { type ErrorMap, type MergedErrorMap } from './error';
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>;
5
8
  };
6
- export type InferContractRouterInputs<T extends ContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : {
7
- [K in keyof T]: T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
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;
8
12
  };
9
- export type InferContractRouterOutputs<T extends ContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any> ? SchemaOutput<UOutputSchema> : {
10
- [K in keyof T]: T[K] extends ContractRouter ? InferContractRouterOutputs<T[K]> : never;
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;
11
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;
12
29
  //# sourceMappingURL=router.d.ts.map
@@ -1,11 +1,8 @@
1
- import type { FindGlobalInstanceType } from '@orpc/shared';
1
+ import type { IsEqual, Promisable } from '@orpc/shared';
2
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
3
  export type Schema = StandardSchemaV1 | undefined;
8
4
  export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
9
5
  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
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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/contract",
3
3
  "type": "module",
4
- "version": "0.0.0-next.cba521d",
4
+ "version": "0.0.0-next.cc4cb21",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,13 +29,15 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@standard-schema/spec": "1.0.0-beta.4",
33
- "@orpc/shared": "0.0.0-next.cba521d"
32
+ "@standard-schema/spec": "^1.0.0",
33
+ "@orpc/client": "0.0.0-next.cc4cb21",
34
+ "@orpc/shared": "0.0.0-next.cc4cb21",
35
+ "@orpc/standard-server": "0.0.0-next.cc4cb21"
34
36
  },
35
37
  "devDependencies": {
36
38
  "arktype": "2.0.0-rc.26",
37
39
  "valibot": "1.0.0-beta.9",
38
- "zod": "3.24.1"
40
+ "zod": "^3.24.1"
39
41
  },
40
42
  "scripts": {
41
43
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
@@ -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,16 +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 200
7
- */
8
- status?: number;
9
- message?: string;
10
- description?: string;
11
- data?: TDataSchema;
12
- };
13
- export type ErrorMap = undefined | {
14
- [key in CommonORPCErrorCode | (string & {})]?: ErrorMapItem<Schema>;
15
- };
16
- //# sourceMappingURL=error-map.d.ts.map