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

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.
package/dist/index.js CHANGED
@@ -1,175 +1,402 @@
1
+ // src/error-map.ts
2
+ function mergeErrorMap(errorMap1, errorMap2) {
3
+ return { ...errorMap1, ...errorMap2 };
4
+ }
5
+
6
+ // src/meta.ts
7
+ function mergeMeta(meta1, meta2) {
8
+ return { ...meta1, ...meta2 };
9
+ }
10
+
1
11
  // src/procedure.ts
2
12
  var ContractProcedure = class {
3
- constructor(zz$cp) {
4
- this.zz$cp = zz$cp;
13
+ "~orpc";
14
+ constructor(def) {
15
+ if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
16
+ throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
17
+ }
18
+ if (Object.values(def.errorMap).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
19
+ throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
20
+ }
21
+ this["~orpc"] = def;
5
22
  }
6
23
  };
7
- var DecoratedContractProcedure = class _DecoratedContractProcedure extends ContractProcedure {
8
- static decorate(cp) {
9
- if (cp instanceof _DecoratedContractProcedure)
10
- return cp;
11
- return new _DecoratedContractProcedure(cp.zz$cp);
12
- }
13
- route(opts) {
14
- return new _DecoratedContractProcedure({
15
- ...this.zz$cp,
16
- ...opts,
17
- method: opts.method,
18
- path: opts.path
19
- });
24
+ function isContractProcedure(item) {
25
+ if (item instanceof ContractProcedure) {
26
+ return true;
20
27
  }
21
- prefix(prefix) {
22
- if (!this.zz$cp.path)
23
- return this;
24
- return new _DecoratedContractProcedure({
25
- ...this.zz$cp,
26
- path: `${prefix}${this.zz$cp.path}`
27
- });
28
+ 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"];
29
+ }
30
+
31
+ // src/route.ts
32
+ function mergeRoute(a, b) {
33
+ return { ...a, ...b };
34
+ }
35
+ function prefixRoute(route, prefix) {
36
+ if (!route.path) {
37
+ return route;
28
38
  }
29
- addTags(...tags) {
30
- if (!tags.length)
31
- return this;
32
- return new _DecoratedContractProcedure({
33
- ...this.zz$cp,
34
- tags: [...this.zz$cp.tags ?? [], ...tags]
35
- });
39
+ return {
40
+ ...route,
41
+ path: `${prefix}${route.path}`
42
+ };
43
+ }
44
+ function unshiftTagRoute(route, tags) {
45
+ return {
46
+ ...route,
47
+ tags: [...tags, ...route.tags ?? []]
48
+ };
49
+ }
50
+ function mergePrefix(a, b) {
51
+ return a ? `${a}${b}` : b;
52
+ }
53
+ function mergeTags(a, b) {
54
+ return a ? [...a, ...b] : b;
55
+ }
56
+ function adaptRoute(route, options) {
57
+ let router = route;
58
+ if (options.prefix) {
59
+ router = prefixRoute(router, options.prefix);
36
60
  }
37
- input(schema, example) {
38
- return new _DecoratedContractProcedure({
39
- ...this.zz$cp,
40
- InputSchema: schema,
41
- inputExample: example
42
- });
61
+ if (options.tags) {
62
+ router = unshiftTagRoute(router, options.tags);
43
63
  }
44
- output(schema, example) {
45
- return new _DecoratedContractProcedure({
46
- ...this.zz$cp,
47
- OutputSchema: schema,
48
- outputExample: example
64
+ return router;
65
+ }
66
+
67
+ // src/router.ts
68
+ function adaptContractRouter(contract, options) {
69
+ if (isContractProcedure(contract)) {
70
+ const adapted2 = new ContractProcedure({
71
+ ...contract["~orpc"],
72
+ errorMap: mergeErrorMap(options.errorMap, contract["~orpc"].errorMap),
73
+ route: adaptRoute(contract["~orpc"].route, options)
49
74
  });
75
+ return adapted2;
50
76
  }
51
- };
52
- function isContractProcedure(item) {
53
- if (item instanceof ContractProcedure)
54
- return true;
55
- return (typeof item === "object" || typeof item === "function") && item !== null && "zz$cp" in item && typeof item.zz$cp === "object" && item.zz$cp !== null && "InputSchema" in item.zz$cp && "OutputSchema" in item.zz$cp;
77
+ const adapted = {};
78
+ for (const key in contract) {
79
+ adapted[key] = adaptContractRouter(contract[key], options);
80
+ }
81
+ return adapted;
56
82
  }
57
83
 
58
- // src/router-builder.ts
59
- var ContractRouterBuilder = class _ContractRouterBuilder {
60
- constructor(zz$crb) {
61
- this.zz$crb = zz$crb;
84
+ // src/builder.ts
85
+ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
86
+ constructor(def) {
87
+ super(def);
88
+ this["~orpc"].prefix = def.prefix;
89
+ this["~orpc"].tags = def.tags;
62
90
  }
63
- prefix(prefix) {
64
- return new _ContractRouterBuilder({
65
- ...this.zz$crb,
66
- prefix: `${this.zz$crb.prefix ?? ""}${prefix}`
91
+ /**
92
+ * Reset initial meta
93
+ */
94
+ $meta(initialMeta) {
95
+ return new _ContractBuilder({
96
+ ...this["~orpc"],
97
+ meta: initialMeta
67
98
  });
68
99
  }
69
- tags(...tags) {
70
- if (!tags.length)
71
- return this;
72
- return new _ContractRouterBuilder({
73
- ...this.zz$crb,
74
- tags: [...this.zz$crb.tags ?? [], ...tags]
100
+ /**
101
+ * Reset initial route
102
+ */
103
+ $route(initialRoute) {
104
+ return new _ContractBuilder({
105
+ ...this["~orpc"],
106
+ route: initialRoute
75
107
  });
76
108
  }
77
- router(router) {
78
- const handled = {};
79
- for (const key in router) {
80
- const item = router[key];
81
- if (isContractProcedure(item)) {
82
- const decorated = DecoratedContractProcedure.decorate(item).addTags(
83
- ...this.zz$crb.tags ?? []
84
- );
85
- handled[key] = this.zz$crb.prefix ? decorated.prefix(this.zz$crb.prefix) : decorated;
86
- } else {
87
- handled[key] = this.router(item);
88
- }
89
- }
90
- return handled;
109
+ errors(errors) {
110
+ return new _ContractBuilder({
111
+ ...this["~orpc"],
112
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
113
+ });
91
114
  }
92
- };
93
-
94
- // src/builder.ts
95
- var ContractBuilder = class {
96
- prefix(prefix) {
97
- return new ContractRouterBuilder({
98
- prefix
115
+ meta(meta) {
116
+ return new _ContractBuilder({
117
+ ...this["~orpc"],
118
+ meta: mergeMeta(this["~orpc"].meta, meta)
99
119
  });
100
120
  }
101
- tags(...tags) {
102
- return new ContractRouterBuilder({
103
- tags
121
+ route(route) {
122
+ return new _ContractBuilder({
123
+ ...this["~orpc"],
124
+ route: mergeRoute(this["~orpc"].route, route)
104
125
  });
105
126
  }
106
- route(opts) {
107
- return new DecoratedContractProcedure({
108
- InputSchema: void 0,
109
- OutputSchema: void 0,
110
- ...opts
127
+ input(schema) {
128
+ return new _ContractBuilder({
129
+ ...this["~orpc"],
130
+ inputSchema: schema
111
131
  });
112
132
  }
113
- input(schema, example) {
114
- return new DecoratedContractProcedure({
115
- InputSchema: schema,
116
- inputExample: example,
117
- OutputSchema: void 0
133
+ output(schema) {
134
+ return new _ContractBuilder({
135
+ ...this["~orpc"],
136
+ outputSchema: schema
118
137
  });
119
138
  }
120
- output(schema, example) {
121
- return new DecoratedContractProcedure({
122
- InputSchema: void 0,
123
- OutputSchema: schema,
124
- outputExample: example
139
+ prefix(prefix) {
140
+ return new _ContractBuilder({
141
+ ...this["~orpc"],
142
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
143
+ });
144
+ }
145
+ tag(...tags) {
146
+ return new _ContractBuilder({
147
+ ...this["~orpc"],
148
+ tags: mergeTags(this["~orpc"].tags, tags)
125
149
  });
126
150
  }
127
151
  router(router) {
128
- return router;
152
+ return adaptContractRouter(router, this["~orpc"]);
129
153
  }
130
154
  };
155
+ var oc = new ContractBuilder({
156
+ errorMap: {},
157
+ inputSchema: void 0,
158
+ outputSchema: void 0,
159
+ route: {},
160
+ meta: {}
161
+ });
131
162
 
132
- // src/constants.ts
133
- var ORPC_HEADER = "x-orpc-transformer";
134
- var ORPC_HEADER_VALUE = "t";
163
+ // src/error-orpc.ts
164
+ import { isPlainObject } from "@orpc/shared";
165
+ var COMMON_ORPC_ERROR_DEFS = {
166
+ BAD_REQUEST: {
167
+ status: 400,
168
+ message: "Bad Request"
169
+ },
170
+ UNAUTHORIZED: {
171
+ status: 401,
172
+ message: "Unauthorized"
173
+ },
174
+ FORBIDDEN: {
175
+ status: 403,
176
+ message: "Forbidden"
177
+ },
178
+ NOT_FOUND: {
179
+ status: 404,
180
+ message: "Not Found"
181
+ },
182
+ METHOD_NOT_SUPPORTED: {
183
+ status: 405,
184
+ message: "Method Not Supported"
185
+ },
186
+ NOT_ACCEPTABLE: {
187
+ status: 406,
188
+ message: "Not Acceptable"
189
+ },
190
+ TIMEOUT: {
191
+ status: 408,
192
+ message: "Request Timeout"
193
+ },
194
+ CONFLICT: {
195
+ status: 409,
196
+ message: "Conflict"
197
+ },
198
+ PRECONDITION_FAILED: {
199
+ status: 412,
200
+ message: "Precondition Failed"
201
+ },
202
+ PAYLOAD_TOO_LARGE: {
203
+ status: 413,
204
+ message: "Payload Too Large"
205
+ },
206
+ UNSUPPORTED_MEDIA_TYPE: {
207
+ status: 415,
208
+ message: "Unsupported Media Type"
209
+ },
210
+ UNPROCESSABLE_CONTENT: {
211
+ status: 422,
212
+ message: "Unprocessable Content"
213
+ },
214
+ TOO_MANY_REQUESTS: {
215
+ status: 429,
216
+ message: "Too Many Requests"
217
+ },
218
+ CLIENT_CLOSED_REQUEST: {
219
+ status: 499,
220
+ message: "Client Closed Request"
221
+ },
222
+ INTERNAL_SERVER_ERROR: {
223
+ status: 500,
224
+ message: "Internal Server Error"
225
+ },
226
+ NOT_IMPLEMENTED: {
227
+ status: 501,
228
+ message: "Not Implemented"
229
+ },
230
+ BAD_GATEWAY: {
231
+ status: 502,
232
+ message: "Bad Gateway"
233
+ },
234
+ SERVICE_UNAVAILABLE: {
235
+ status: 503,
236
+ message: "Service Unavailable"
237
+ },
238
+ GATEWAY_TIMEOUT: {
239
+ status: 504,
240
+ message: "Gateway Timeout"
241
+ }
242
+ };
243
+ function fallbackORPCErrorStatus(code, status) {
244
+ return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
245
+ }
246
+ function fallbackORPCErrorMessage(code, message) {
247
+ return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
248
+ }
249
+ var ORPCError = class _ORPCError extends Error {
250
+ defined;
251
+ code;
252
+ status;
253
+ data;
254
+ constructor(code, ...[options]) {
255
+ if (options?.status && (options.status < 400 || options.status >= 600)) {
256
+ throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
257
+ }
258
+ const message = fallbackORPCErrorMessage(code, options?.message);
259
+ super(message, options);
260
+ this.code = code;
261
+ this.status = fallbackORPCErrorStatus(code, options?.status);
262
+ this.defined = options?.defined ?? false;
263
+ this.data = options?.data;
264
+ }
265
+ toJSON() {
266
+ return {
267
+ defined: this.defined,
268
+ code: this.code,
269
+ status: this.status,
270
+ message: this.message,
271
+ data: this.data
272
+ };
273
+ }
274
+ static fromJSON(json) {
275
+ return new _ORPCError(json.code, json);
276
+ }
277
+ static isValidJSON(json) {
278
+ return isPlainObject(json) && "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
279
+ }
280
+ };
135
281
 
136
- // src/router.ts
137
- function eachContractRouterLeaf(router, callback, prefix = []) {
138
- for (const key in router) {
139
- const item = router[key];
140
- if (isContractProcedure(item)) {
141
- callback(item, [...prefix, key]);
142
- } else {
143
- eachContractRouterLeaf(item, callback, [...prefix, key]);
282
+ // src/error-utils.ts
283
+ function isDefinedError(error) {
284
+ return error instanceof ORPCError && error.defined;
285
+ }
286
+ function createORPCErrorConstructorMap(errors) {
287
+ const proxy = new Proxy(errors, {
288
+ get(target, code) {
289
+ if (typeof code !== "string") {
290
+ return Reflect.get(target, code);
291
+ }
292
+ const item = (...[options]) => {
293
+ const config = errors[code];
294
+ return new ORPCError(code, {
295
+ defined: Boolean(config),
296
+ status: config?.status,
297
+ message: options?.message ?? config?.message,
298
+ data: options?.data,
299
+ cause: options?.cause
300
+ });
301
+ };
302
+ return item;
144
303
  }
304
+ });
305
+ return proxy;
306
+ }
307
+ async function validateORPCError(map, error) {
308
+ const { code, status, message, data, cause, defined } = error;
309
+ const config = map?.[error.code];
310
+ if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
311
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
312
+ }
313
+ if (!config.data) {
314
+ return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
315
+ }
316
+ const validated = await config.data["~standard"].validate(error.data);
317
+ if (validated.issues) {
318
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
145
319
  }
320
+ return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
146
321
  }
147
322
 
148
- // src/utils.ts
149
- function standardizeHTTPPath(path) {
150
- return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
151
- }
152
- function prefixHTTPPath(prefix, path) {
153
- const prefix_ = standardizeHTTPPath(prefix);
154
- const path_ = standardizeHTTPPath(path);
155
- if (prefix_ === "/")
156
- return path_;
157
- if (path_ === "/")
158
- return prefix_;
159
- return `${prefix_}${path_}`;
323
+ // src/client-utils.ts
324
+ async function safe(promise) {
325
+ try {
326
+ const output = await promise;
327
+ return [output, void 0, false];
328
+ } catch (e) {
329
+ const error = e;
330
+ if (isDefinedError(error)) {
331
+ return [void 0, error, true];
332
+ }
333
+ return [void 0, error, false];
334
+ }
160
335
  }
161
336
 
162
- // src/index.ts
163
- var oc = new ContractBuilder();
337
+ // src/config.ts
338
+ var DEFAULT_CONFIG = {
339
+ defaultMethod: "POST",
340
+ defaultSuccessStatus: 200,
341
+ defaultSuccessDescription: "OK",
342
+ defaultInputStructure: "compact",
343
+ defaultOutputStructure: "compact"
344
+ };
345
+ function fallbackContractConfig(key, value) {
346
+ if (value === void 0) {
347
+ return DEFAULT_CONFIG[key];
348
+ }
349
+ return value;
350
+ }
351
+
352
+ // src/error.ts
353
+ var ValidationError = class extends Error {
354
+ issues;
355
+ constructor(options) {
356
+ super(options.message, options);
357
+ this.issues = options.issues;
358
+ }
359
+ };
360
+
361
+ // src/schema.ts
362
+ function type(...[map]) {
363
+ return {
364
+ "~standard": {
365
+ vendor: "custom",
366
+ version: 1,
367
+ async validate(value) {
368
+ if (map) {
369
+ return { value: await map(value) };
370
+ }
371
+ return { value };
372
+ }
373
+ }
374
+ };
375
+ }
164
376
  export {
377
+ COMMON_ORPC_ERROR_DEFS,
165
378
  ContractBuilder,
166
379
  ContractProcedure,
167
- DecoratedContractProcedure,
168
- ORPC_HEADER,
169
- ORPC_HEADER_VALUE,
170
- eachContractRouterLeaf,
380
+ ORPCError,
381
+ ValidationError,
382
+ adaptContractRouter,
383
+ adaptRoute,
384
+ createORPCErrorConstructorMap,
385
+ fallbackContractConfig,
386
+ fallbackORPCErrorMessage,
387
+ fallbackORPCErrorStatus,
171
388
  isContractProcedure,
389
+ isDefinedError,
390
+ mergeErrorMap,
391
+ mergeMeta,
392
+ mergePrefix,
393
+ mergeRoute,
394
+ mergeTags,
172
395
  oc,
173
- prefixHTTPPath,
174
- standardizeHTTPPath
396
+ prefixRoute,
397
+ safe,
398
+ type,
399
+ unshiftTagRoute,
400
+ validateORPCError
175
401
  };
402
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,38 @@
1
+ import type { ErrorMap, MergedErrorMap } from './error-map';
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,12 +1,32 @@
1
- import type { ContractRouter } from './router';
2
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
3
- import { DecoratedContractProcedure, type RouteOptions } from './procedure';
4
- import { ContractRouterBuilder } from './router-builder';
5
- export declare class ContractBuilder {
6
- prefix(prefix: HTTPPath): ContractRouterBuilder;
7
- tags(...tags: string[]): ContractRouterBuilder;
8
- route(opts: RouteOptions): DecoratedContractProcedure<undefined, undefined>;
9
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): DecoratedContractProcedure<USchema, undefined>;
10
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): DecoratedContractProcedure<undefined, USchema>;
11
- 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-map';
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> {
12
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
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,21 @@
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
+ __error?: {
12
+ type: TError;
13
+ };
14
+ };
15
+ export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
16
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
17
+ }
18
+ export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
19
+ [k: string]: NestedClient<TClientContext>;
20
+ };
21
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,14 @@
1
+ import type { ORPCErrorCode } from './error-orpc';
2
+ import type { Schema } from './schema';
3
+ export type ErrorMapItem<TDataSchema extends Schema> = {
4
+ status?: number;
5
+ message?: string;
6
+ description?: string;
7
+ data?: TDataSchema;
8
+ };
9
+ export type ErrorMap = {
10
+ [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
11
+ };
12
+ export type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
13
+ export declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
14
+ //# sourceMappingURL=error-map.d.ts.map
@@ -0,0 +1,109 @@
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
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,13 @@
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,9 +1,19 @@
1
1
  /** unnoq */
2
- import { ContractBuilder } from './builder';
3
2
  export * from './builder';
4
- export * from './constants';
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';
5
12
  export * from './procedure';
13
+ export * from './procedure-client';
14
+ export * from './route';
6
15
  export * from './router';
16
+ export * from './router-client';
17
+ export * from './schema';
7
18
  export * from './types';
8
- export * from './utils';
9
- export declare const oc: ContractBuilder;
19
+ //# 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
@@ -0,0 +1,6 @@
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,45 +1,18 @@
1
- import type { HTTPMethod, HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
2
- export interface RouteOptions {
3
- method?: HTTPMethod;
4
- path?: HTTPPath;
5
- summary?: string;
6
- description?: string;
7
- deprecated?: boolean;
8
- tags?: string[];
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;
9
11
  }
10
- export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> {
11
- zz$cp: {
12
- path?: HTTPPath;
13
- method?: HTTPMethod;
14
- summary?: string;
15
- description?: string;
16
- deprecated?: boolean;
17
- tags?: string[];
18
- InputSchema: TInputSchema;
19
- inputExample?: SchemaOutput<TInputSchema>;
20
- OutputSchema: TOutputSchema;
21
- outputExample?: SchemaOutput<TOutputSchema>;
22
- };
23
- constructor(zz$cp: {
24
- path?: HTTPPath;
25
- method?: HTTPMethod;
26
- summary?: string;
27
- description?: string;
28
- deprecated?: boolean;
29
- tags?: string[];
30
- InputSchema: TInputSchema;
31
- inputExample?: SchemaOutput<TInputSchema>;
32
- OutputSchema: TOutputSchema;
33
- outputExample?: SchemaOutput<TOutputSchema>;
34
- });
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>);
35
15
  }
36
- export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> extends ContractProcedure<TInputSchema, TOutputSchema> {
37
- static decorate<TInputSchema extends Schema, TOutputSchema extends Schema>(cp: ContractProcedure<TInputSchema, TOutputSchema>): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
38
- route(opts: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
39
- prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
40
- addTags(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
41
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): DecoratedContractProcedure<USchema, TOutputSchema>;
42
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): DecoratedContractProcedure<TInputSchema, USchema>;
43
- }
44
- export type WELL_DEFINED_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
45
- export declare function isContractProcedure(item: unknown): item is WELL_DEFINED_CONTRACT_PROCEDURE;
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
@@ -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
@@ -0,0 +1,7 @@
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,15 +1,29 @@
1
- import type { SchemaInput, SchemaOutput } from './types';
2
- import { type ContractProcedure, type DecoratedContractProcedure, type WELL_DEFINED_CONTRACT_PROCEDURE } from './procedure';
3
- export interface ContractRouter {
4
- [k: string]: ContractProcedure<any, any> | ContractRouter;
5
- }
6
- export type HandledContractRouter<TContract extends ContractRouter> = {
7
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? DecoratedContractProcedure<UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? HandledContractRouter<TContract[K]> : never;
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;
8
12
  };
9
- export declare function eachContractRouterLeaf(router: ContractRouter, callback: (item: WELL_DEFINED_CONTRACT_PROCEDURE, path: string[]) => void, prefix?: string[]): void;
10
- export type InferContractRouterInputs<T extends ContractRouter> = {
11
- [K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, any> ? SchemaInput<UInputSchema> : T[K] extends ContractRouter ? InferContractRouterInputs<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;
12
21
  };
13
- export type InferContractRouterOutputs<T extends ContractRouter> = {
14
- [K in keyof T]: T[K] extends ContractProcedure<any, infer UOutputSchema> ? SchemaOutput<UOutputSchema> : T[K] extends ContractRouter ? InferContractRouterOutputs<T[K]> : never;
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;
15
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
@@ -0,0 +1,8 @@
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,7 +1,3 @@
1
- import type { input, output, ZodType } from 'zod';
2
- export type HTTPPath = `/${string}`;
3
- export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
- export type HTTPStatus = number;
5
- export type Schema = ZodType<any, any, any> | undefined;
6
- export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends ZodType<any, any, any> ? input<TSchema> : TFallback;
7
- export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends ZodType<any, any, any> ? output<TSchema> : TFallback;
1
+ import type { FindGlobalInstanceType } from '@orpc/shared';
2
+ export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
3
+ //# sourceMappingURL=types.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.ef3ba82",
4
+ "version": "0.0.0-next.f56d2b3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -24,17 +24,21 @@
24
24
  }
25
25
  },
26
26
  "files": [
27
- "!dist/*.tsbuildinfo",
27
+ "!**/*.map",
28
+ "!**/*.tsbuildinfo",
28
29
  "dist"
29
30
  ],
30
- "peerDependencies": {
31
- "zod": ">=3.23.0"
32
- },
33
31
  "dependencies": {
34
- "@orpc/shared": "0.0.0-next.ef3ba82"
32
+ "@standard-schema/spec": "1.0.0-rc.0",
33
+ "@orpc/shared": "0.0.0-next.f56d2b3"
34
+ },
35
+ "devDependencies": {
36
+ "arktype": "2.0.0-rc.26",
37
+ "valibot": "1.0.0-beta.9",
38
+ "zod": "3.24.1"
35
39
  },
36
40
  "scripts": {
37
- "build": "tsup --clean --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
41
+ "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
38
42
  "build:watch": "pnpm run build --watch",
39
43
  "type:check": "tsc -b"
40
44
  }
@@ -1,2 +0,0 @@
1
- export declare const ORPC_HEADER = "x-orpc-transformer";
2
- export declare const ORPC_HEADER_VALUE = "t";
@@ -1,15 +0,0 @@
1
- import type { ContractRouter, HandledContractRouter } from './router';
2
- import type { HTTPPath } from './types';
3
- export declare class ContractRouterBuilder {
4
- zz$crb: {
5
- prefix?: HTTPPath;
6
- tags?: string[];
7
- };
8
- constructor(zz$crb: {
9
- prefix?: HTTPPath;
10
- tags?: string[];
11
- });
12
- prefix(prefix: HTTPPath): ContractRouterBuilder;
13
- tags(...tags: string[]): ContractRouterBuilder;
14
- router<T extends ContractRouter>(router: T): HandledContractRouter<T>;
15
- }
@@ -1,3 +0,0 @@
1
- import type { HTTPPath } from './types';
2
- export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
3
- export declare function prefixHTTPPath(prefix: HTTPPath, path: HTTPPath): HTTPPath;