@orpc/contract 0.0.0-next.d0e429d → 0.0.0-next.d12598b

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,254 @@
1
+ import { ORPCErrorCode, ORPCError, HTTPMethod, HTTPPath } from '@orpc/client';
2
+ import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
3
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import { OpenAPIV3_1 } from 'openapi-types';
5
+
6
+ type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
7
+ type AnySchema = Schema<any, any>;
8
+ type SchemaIssue = StandardSchemaV1.Issue;
9
+ type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
10
+ type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
11
+ type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
12
+ /**
13
+ * The schema for things can be trust without validation.
14
+ * If the TInput and TOutput are different, you need pass a map function.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/procedure#type-utility Type Utility Docs}
17
+ */
18
+ declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
19
+
20
+ interface ValidationErrorOptions extends ErrorOptions {
21
+ message: string;
22
+ issues: readonly SchemaIssue[];
23
+ /**
24
+ * @todo require this field in v2
25
+ */
26
+ data?: unknown;
27
+ }
28
+ /**
29
+ * This errors usually used for ORPCError.cause when the error is a validation error.
30
+ *
31
+ * @see {@link https://orpc.dev/docs/advanced/validation-errors Validation Errors Docs}
32
+ */
33
+ declare class ValidationError extends Error {
34
+ readonly issues: readonly SchemaIssue[];
35
+ readonly data: unknown;
36
+ constructor(options: ValidationErrorOptions);
37
+ }
38
+ interface ErrorMapItem<TDataSchema extends AnySchema> {
39
+ status?: number;
40
+ message?: string;
41
+ data?: TDataSchema;
42
+ }
43
+ type ErrorMap = {
44
+ [key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
45
+ };
46
+ type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
47
+ declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
48
+ type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
49
+ [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
50
+ }[keyof TErrorMap];
51
+ type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
52
+ declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
53
+
54
+ type Meta = Record<string, any>;
55
+ declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
56
+
57
+ type InputStructure = 'compact' | 'detailed';
58
+ type OutputStructure = 'compact' | 'detailed';
59
+ interface Route {
60
+ /**
61
+ * The HTTP method of the procedure.
62
+ * This option is typically relevant when integrating with OpenAPI.
63
+ *
64
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
65
+ */
66
+ method?: HTTPMethod;
67
+ /**
68
+ * The HTTP path of the procedure.
69
+ * This option is typically relevant when integrating with OpenAPI.
70
+ *
71
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
72
+ */
73
+ path?: HTTPPath;
74
+ /**
75
+ * The operation ID of the endpoint.
76
+ * This option is typically relevant when integrating with OpenAPI.
77
+ *
78
+ * @default Concatenation of router segments
79
+ */
80
+ operationId?: string;
81
+ /**
82
+ * The summary of the procedure.
83
+ * This option is typically relevant when integrating with OpenAPI.
84
+ *
85
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
86
+ */
87
+ summary?: string;
88
+ /**
89
+ * The description of the procedure.
90
+ * This option is typically relevant when integrating with OpenAPI.
91
+ *
92
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
93
+ */
94
+ description?: string;
95
+ /**
96
+ * Marks the procedure as deprecated.
97
+ * This option is typically relevant when integrating with OpenAPI.
98
+ *
99
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
100
+ */
101
+ deprecated?: boolean;
102
+ /**
103
+ * The tags of the procedure.
104
+ * This option is typically relevant when integrating with OpenAPI.
105
+ *
106
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
107
+ */
108
+ tags?: readonly string[];
109
+ /**
110
+ * The status code of the response when the procedure is successful.
111
+ * The status code must be in the 200-399 range.
112
+ * This option is typically relevant when integrating with OpenAPI.
113
+ *
114
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
115
+ * @default 200
116
+ */
117
+ successStatus?: number;
118
+ /**
119
+ * The description of the response when the procedure is successful.
120
+ * This option is typically relevant when integrating with OpenAPI.
121
+ *
122
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
123
+ * @default 'OK'
124
+ */
125
+ successDescription?: string;
126
+ /**
127
+ * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
128
+ *
129
+ * @option 'compact'
130
+ * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
131
+ *
132
+ * @option 'detailed'
133
+ * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
134
+ *
135
+ * Example:
136
+ * ```ts
137
+ * const input = {
138
+ * params: { id: 1 },
139
+ * query: { search: 'hello' },
140
+ * headers: { 'Content-Type': 'application/json' },
141
+ * body: { name: 'John' },
142
+ * }
143
+ * ```
144
+ *
145
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
146
+ * @default 'compact'
147
+ */
148
+ inputStructure?: InputStructure;
149
+ /**
150
+ * Determines how the response should be structured based on the output.
151
+ *
152
+ * @option 'compact'
153
+ * The output data is directly returned as the response body.
154
+ *
155
+ * @option 'detailed'
156
+ * Return an object with optional properties:
157
+ * - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
158
+ * - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
159
+ * - `body`: The response body.
160
+ *
161
+ * Example:
162
+ * ```ts
163
+ * const output = {
164
+ * status: 201,
165
+ * headers: { 'x-custom-header': 'value' },
166
+ * body: { message: 'Hello, world!' },
167
+ * };
168
+ * ```
169
+ *
170
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
171
+ * @default 'compact'
172
+ */
173
+ outputStructure?: OutputStructure;
174
+ /**
175
+ * Override entire auto-generated OpenAPI Operation Object Specification.
176
+ *
177
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
178
+ */
179
+ spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
180
+ }
181
+ declare function mergeRoute(a: Route, b: Route): Route;
182
+ declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
183
+ declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
184
+ declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
185
+ declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
186
+ interface EnhanceRouteOptions {
187
+ prefix?: HTTPPath;
188
+ tags?: readonly string[];
189
+ }
190
+ declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
191
+
192
+ interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
193
+ meta: TMeta;
194
+ route: Route;
195
+ inputSchema?: TInputSchema;
196
+ outputSchema?: TOutputSchema;
197
+ errorMap: TErrorMap;
198
+ }
199
+ /**
200
+ * This class represents a contract procedure.
201
+ *
202
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#procedure-contract Contract Procedure Docs}
203
+ */
204
+ declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
205
+ /**
206
+ * This property holds the defined options for the contract procedure.
207
+ */
208
+ '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
209
+ constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
210
+ }
211
+ type AnyContractProcedure = ContractProcedure<any, any, any, any>;
212
+ declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
213
+
214
+ /**
215
+ * Represents a contract router, which defines a hierarchical structure of contract procedures.
216
+ *
217
+ * @info A contract procedure is a contract router too.
218
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs}
219
+ */
220
+ type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
221
+ [k: string]: ContractRouter<TMeta>;
222
+ };
223
+ type AnyContractRouter = ContractRouter<any>;
224
+ /**
225
+ * Infer all inputs of the contract router.
226
+ *
227
+ * @info A contract procedure is a contract router too.
228
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#utilities Contract Utilities Docs}
229
+ */
230
+ type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
231
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
232
+ };
233
+ /**
234
+ * Infer all outputs of the contract router.
235
+ *
236
+ * @info A contract procedure is a contract router too.
237
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#utilities Contract Utilities Docs}
238
+ */
239
+ type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
240
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
241
+ };
242
+ /**
243
+ * Infer all errors of the contract router.
244
+ *
245
+ * @info A contract procedure is a contract router too.
246
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#utilities Contract Utilities Docs}
247
+ */
248
+ type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
249
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
250
+ }[keyof T];
251
+ type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
252
+
253
+ export { ContractProcedure as C, type as D, ValidationError as j, mergeErrorMap as m, mergeMeta as n, isContractProcedure as p, mergeRoute as q, prefixRoute as r, mergePrefix as s, mergeTags as t, unshiftTagRoute as u, validateORPCError as v, enhanceRoute as w };
254
+ export type { AnyContractRouter as A, InferContractRouterMeta as B, ErrorMap as E, InputStructure as I, MergedErrorMap as M, OutputStructure as O, Route as R, Schema as S, TypeRest as T, ValidationErrorOptions as V, EnhanceRouteOptions as a, AnySchema as b, Meta as c, ContractRouter as d, ContractProcedureDef as e, InferSchemaInput as f, InferSchemaOutput as g, ErrorFromErrorMap as h, SchemaIssue as i, ErrorMapItem as k, ORPCErrorFromErrorMap as l, AnyContractProcedure as o, InferContractRouterInputs as x, InferContractRouterOutputs as y, InferContractRouterErrorMap as z };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@orpc/contract",
3
3
  "type": "module",
4
- "version": "0.0.0-next.d0e429d",
4
+ "version": "0.0.0-next.d12598b",
5
5
  "license": "MIT",
6
- "homepage": "https://orpc.unnoq.com",
6
+ "homepage": "https://orpc.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/unnoq/orpc.git",
@@ -15,32 +15,32 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
21
  },
22
- "./🔒/*": {
23
- "types": "./dist/src/*.d.ts"
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
24
26
  }
25
27
  },
26
28
  "files": [
27
- "!**/*.map",
28
- "!**/*.tsbuildinfo",
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
32
  "@standard-schema/spec": "^1.0.0",
33
- "@orpc/standard-server": "0.0.0-next.d0e429d",
34
- "@orpc/shared": "0.0.0-next.d0e429d",
35
- "@orpc/client": "0.0.0-next.d0e429d"
33
+ "openapi-types": "^12.1.3",
34
+ "@orpc/client": "0.0.0-next.d12598b",
35
+ "@orpc/shared": "0.0.0-next.d12598b"
36
36
  },
37
37
  "devDependencies": {
38
- "arktype": "2.0.0-rc.26",
39
- "valibot": "1.0.0-beta.9",
40
- "zod": "^3.24.1"
38
+ "arktype": "2.1.27",
39
+ "valibot": "^1.2.0",
40
+ "zod": "^4.1.12"
41
41
  },
42
42
  "scripts": {
43
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
43
+ "build": "unbuild",
44
44
  "build:watch": "pnpm run build --watch",
45
45
  "type:check": "tsc -b"
46
46
  }
package/dist/index.js DELETED
@@ -1,270 +0,0 @@
1
- // src/error.ts
2
- var ValidationError = class extends Error {
3
- issues;
4
- constructor(options) {
5
- super(options.message, options);
6
- this.issues = options.issues;
7
- }
8
- };
9
- function mergeErrorMap(errorMap1, errorMap2) {
10
- return { ...errorMap1, ...errorMap2 };
11
- }
12
-
13
- // src/meta.ts
14
- function mergeMeta(meta1, meta2) {
15
- return { ...meta1, ...meta2 };
16
- }
17
-
18
- // src/procedure.ts
19
- var ContractProcedure = class {
20
- "~orpc";
21
- constructor(def) {
22
- if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
23
- throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
24
- }
25
- if (Object.values(def.errorMap).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
26
- throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
27
- }
28
- this["~orpc"] = def;
29
- }
30
- };
31
- function isContractProcedure(item) {
32
- if (item instanceof ContractProcedure) {
33
- return true;
34
- }
35
- return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "inputSchema" in item["~orpc"] && "outputSchema" in item["~orpc"] && "errorMap" in item["~orpc"] && "route" in item["~orpc"] && "meta" in item["~orpc"];
36
- }
37
-
38
- // src/route.ts
39
- function mergeRoute(a, b) {
40
- return { ...a, ...b };
41
- }
42
- function prefixRoute(route, prefix) {
43
- if (!route.path) {
44
- return route;
45
- }
46
- return {
47
- ...route,
48
- path: `${prefix}${route.path}`
49
- };
50
- }
51
- function unshiftTagRoute(route, tags) {
52
- return {
53
- ...route,
54
- tags: [...tags, ...route.tags ?? []]
55
- };
56
- }
57
- function mergePrefix(a, b) {
58
- return a ? `${a}${b}` : b;
59
- }
60
- function mergeTags(a, b) {
61
- return a ? [...a, ...b] : b;
62
- }
63
- function adaptRoute(route, options) {
64
- let router = route;
65
- if (options.prefix) {
66
- router = prefixRoute(router, options.prefix);
67
- }
68
- if (options.tags) {
69
- router = unshiftTagRoute(router, options.tags);
70
- }
71
- return router;
72
- }
73
-
74
- // src/router.ts
75
- function adaptContractRouter(contract, options) {
76
- if (isContractProcedure(contract)) {
77
- const adapted2 = new ContractProcedure({
78
- ...contract["~orpc"],
79
- errorMap: mergeErrorMap(options.errorMap, contract["~orpc"].errorMap),
80
- route: adaptRoute(contract["~orpc"].route, options)
81
- });
82
- return adapted2;
83
- }
84
- const adapted = {};
85
- for (const key in contract) {
86
- adapted[key] = adaptContractRouter(contract[key], options);
87
- }
88
- return adapted;
89
- }
90
-
91
- // src/builder.ts
92
- var ContractBuilder = class _ContractBuilder extends ContractProcedure {
93
- constructor(def) {
94
- super(def);
95
- this["~orpc"].prefix = def.prefix;
96
- this["~orpc"].tags = def.tags;
97
- }
98
- /**
99
- * Reset initial meta
100
- */
101
- $meta(initialMeta) {
102
- return new _ContractBuilder({
103
- ...this["~orpc"],
104
- meta: initialMeta
105
- });
106
- }
107
- /**
108
- * Reset initial route
109
- */
110
- $route(initialRoute) {
111
- return new _ContractBuilder({
112
- ...this["~orpc"],
113
- route: initialRoute
114
- });
115
- }
116
- errors(errors) {
117
- return new _ContractBuilder({
118
- ...this["~orpc"],
119
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
120
- });
121
- }
122
- meta(meta) {
123
- return new _ContractBuilder({
124
- ...this["~orpc"],
125
- meta: mergeMeta(this["~orpc"].meta, meta)
126
- });
127
- }
128
- route(route) {
129
- return new _ContractBuilder({
130
- ...this["~orpc"],
131
- route: mergeRoute(this["~orpc"].route, route)
132
- });
133
- }
134
- input(schema) {
135
- return new _ContractBuilder({
136
- ...this["~orpc"],
137
- inputSchema: schema
138
- });
139
- }
140
- output(schema) {
141
- return new _ContractBuilder({
142
- ...this["~orpc"],
143
- outputSchema: schema
144
- });
145
- }
146
- prefix(prefix) {
147
- return new _ContractBuilder({
148
- ...this["~orpc"],
149
- prefix: mergePrefix(this["~orpc"].prefix, prefix)
150
- });
151
- }
152
- tag(...tags) {
153
- return new _ContractBuilder({
154
- ...this["~orpc"],
155
- tags: mergeTags(this["~orpc"].tags, tags)
156
- });
157
- }
158
- router(router) {
159
- return adaptContractRouter(router, this["~orpc"]);
160
- }
161
- };
162
- var oc = new ContractBuilder({
163
- errorMap: {},
164
- inputSchema: void 0,
165
- outputSchema: void 0,
166
- route: {},
167
- meta: {}
168
- });
169
-
170
- // src/config.ts
171
- var DEFAULT_CONFIG = {
172
- defaultMethod: "POST",
173
- defaultSuccessStatus: 200,
174
- defaultSuccessDescription: "OK",
175
- defaultInputStructure: "compact",
176
- defaultOutputStructure: "compact"
177
- };
178
- function fallbackContractConfig(key, value) {
179
- if (value === void 0) {
180
- return DEFAULT_CONFIG[key];
181
- }
182
- return value;
183
- }
184
-
185
- // src/event-iterator.ts
186
- import { mapEventIterator, ORPCError } from "@orpc/client";
187
- import { isAsyncIteratorObject } from "@orpc/shared";
188
- var EVENT_ITERATOR_SCHEMA_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_SCHEMA");
189
- function eventIterator(yields, returns) {
190
- return {
191
- "~standard": {
192
- [EVENT_ITERATOR_SCHEMA_SYMBOL]: { yields, returns },
193
- vendor: "orpc",
194
- version: 1,
195
- validate(iterator) {
196
- if (!isAsyncIteratorObject(iterator)) {
197
- return { issues: [{ message: "Expect event source iterator", path: [] }] };
198
- }
199
- const mapped = mapEventIterator(iterator, {
200
- async value(value, done) {
201
- const schema = done ? returns : yields;
202
- if (!schema) {
203
- return value;
204
- }
205
- const result = await schema["~standard"].validate(value);
206
- if (result.issues) {
207
- throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
208
- message: "Event source iterator validation failed",
209
- cause: new ValidationError({
210
- issues: result.issues,
211
- message: "Event source iterator validation failed"
212
- })
213
- });
214
- }
215
- return result.value;
216
- },
217
- error: async (error) => error
218
- });
219
- return { value: mapped };
220
- }
221
- }
222
- };
223
- }
224
- function getEventIteratorSchemaDetails(schema) {
225
- if (schema === void 0) {
226
- return void 0;
227
- }
228
- return schema["~standard"][EVENT_ITERATOR_SCHEMA_SYMBOL];
229
- }
230
-
231
- // src/schema.ts
232
- function type(...[map]) {
233
- return {
234
- "~standard": {
235
- vendor: "custom",
236
- version: 1,
237
- async validate(value) {
238
- if (map) {
239
- return { value: await map(value) };
240
- }
241
- return { value };
242
- }
243
- }
244
- };
245
- }
246
-
247
- // src/index.ts
248
- import { ORPCError as ORPCError2 } from "@orpc/client";
249
- export {
250
- ContractBuilder,
251
- ContractProcedure,
252
- ORPCError2 as ORPCError,
253
- ValidationError,
254
- adaptContractRouter,
255
- adaptRoute,
256
- eventIterator,
257
- fallbackContractConfig,
258
- getEventIteratorSchemaDetails,
259
- isContractProcedure,
260
- mergeErrorMap,
261
- mergeMeta,
262
- mergePrefix,
263
- mergeRoute,
264
- mergeTags,
265
- oc,
266
- prefixRoute,
267
- type,
268
- unshiftTagRoute
269
- };
270
- //# sourceMappingURL=index.js.map
@@ -1,38 +0,0 @@
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,32 +0,0 @@
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> {
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, {}, {}>;
32
- //# sourceMappingURL=builder.d.ts.map
@@ -1,10 +0,0 @@
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;
8
- }
9
- export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
10
- //# sourceMappingURL=config.d.ts.map