@orpc/contract 0.0.0-next.da84cda → 0.0.0-next.da8ae32

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,12 +1,21 @@
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
- "~type" = "ContractProcedure";
4
13
  "~orpc";
5
14
  constructor(def) {
6
15
  if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
7
16
  throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
8
17
  }
9
- if (Object.values(def.errorMap ?? {}).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
18
+ if (Object.values(def.errorMap).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
10
19
  throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
11
20
  }
12
21
  this["~orpc"] = def;
@@ -16,159 +25,143 @@ function isContractProcedure(item) {
16
25
  if (item instanceof ContractProcedure) {
17
26
  return true;
18
27
  }
19
- return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "ContractProcedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "InputSchema" in item["~orpc"] && "OutputSchema" in item["~orpc"] && "errorMap" in item["~orpc"];
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"];
20
29
  }
21
30
 
22
- // src/procedure-decorated.ts
23
- var DecoratedContractProcedure = class _DecoratedContractProcedure extends ContractProcedure {
24
- static decorate(procedure) {
25
- if (procedure instanceof _DecoratedContractProcedure) {
26
- return procedure;
27
- }
28
- return new _DecoratedContractProcedure(procedure["~orpc"]);
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;
29
38
  }
30
- route(route) {
31
- return new _DecoratedContractProcedure({
32
- ...this["~orpc"],
33
- route: {
34
- ...this["~orpc"].route,
35
- ...route
36
- }
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);
60
+ }
61
+ if (options.tags) {
62
+ router = unshiftTagRoute(router, options.tags);
63
+ }
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)
37
74
  });
75
+ return adapted2;
38
76
  }
39
- prefix(prefix) {
40
- return new _DecoratedContractProcedure({
77
+ const adapted = {};
78
+ for (const key in contract) {
79
+ adapted[key] = adaptContractRouter(contract[key], options);
80
+ }
81
+ return adapted;
82
+ }
83
+
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;
90
+ }
91
+ /**
92
+ * Reset initial meta
93
+ */
94
+ $meta(initialMeta) {
95
+ return new _ContractBuilder({
41
96
  ...this["~orpc"],
42
- ...this["~orpc"].route?.path ? {
43
- route: {
44
- ...this["~orpc"].route,
45
- path: `${prefix}${this["~orpc"].route.path}`
46
- }
47
- } : void 0
97
+ meta: initialMeta
48
98
  });
49
99
  }
50
- unshiftTag(...tags) {
51
- return new _DecoratedContractProcedure({
100
+ /**
101
+ * Reset initial route
102
+ */
103
+ $route(initialRoute) {
104
+ return new _ContractBuilder({
52
105
  ...this["~orpc"],
53
- route: {
54
- ...this["~orpc"].route,
55
- tags: [
56
- ...tags,
57
- ...this["~orpc"].route?.tags?.filter((tag) => !tags.includes(tag)) ?? []
58
- ]
59
- }
106
+ route: initialRoute
60
107
  });
61
108
  }
62
- input(schema, example) {
63
- return new _DecoratedContractProcedure({
109
+ errors(errors) {
110
+ return new _ContractBuilder({
64
111
  ...this["~orpc"],
65
- InputSchema: schema,
66
- inputExample: example
112
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
67
113
  });
68
114
  }
69
- output(schema, example) {
70
- return new _DecoratedContractProcedure({
115
+ meta(meta) {
116
+ return new _ContractBuilder({
71
117
  ...this["~orpc"],
72
- OutputSchema: schema,
73
- outputExample: example
118
+ meta: mergeMeta(this["~orpc"].meta, meta)
74
119
  });
75
120
  }
76
- errors(errorMap) {
77
- return new _DecoratedContractProcedure({
121
+ route(route) {
122
+ return new _ContractBuilder({
78
123
  ...this["~orpc"],
79
- errorMap
124
+ route: mergeRoute(this["~orpc"].route, route)
80
125
  });
81
126
  }
82
- };
83
-
84
- // src/router-builder.ts
85
- var ContractRouterBuilder = class _ContractRouterBuilder {
86
- "~type" = "ContractProcedure";
87
- "~orpc";
88
- constructor(def) {
89
- this["~orpc"] = def;
90
- }
91
- prefix(prefix) {
92
- return new _ContractRouterBuilder({
127
+ input(schema) {
128
+ return new _ContractBuilder({
93
129
  ...this["~orpc"],
94
- prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
130
+ inputSchema: schema
95
131
  });
96
132
  }
97
- tag(...tags) {
98
- return new _ContractRouterBuilder({
133
+ output(schema) {
134
+ return new _ContractBuilder({
99
135
  ...this["~orpc"],
100
- tags: [...this["~orpc"].tags ?? [], ...tags]
136
+ outputSchema: schema
101
137
  });
102
138
  }
103
- router(router) {
104
- if (isContractProcedure(router)) {
105
- let decorated = DecoratedContractProcedure.decorate(router);
106
- if (this["~orpc"].tags) {
107
- decorated = decorated.unshiftTag(...this["~orpc"].tags);
108
- }
109
- if (this["~orpc"].prefix) {
110
- decorated = decorated.prefix(this["~orpc"].prefix);
111
- }
112
- return decorated;
113
- }
114
- const adapted = {};
115
- for (const key in router) {
116
- adapted[key] = this.router(router[key]);
117
- }
118
- return adapted;
119
- }
120
- };
121
-
122
- // src/builder.ts
123
- var ContractBuilder = class {
124
139
  prefix(prefix) {
125
- return new ContractRouterBuilder({
126
- prefix
140
+ return new _ContractBuilder({
141
+ ...this["~orpc"],
142
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
127
143
  });
128
144
  }
129
145
  tag(...tags) {
130
- return new ContractRouterBuilder({
131
- tags
132
- });
133
- }
134
- route(route) {
135
- return new DecoratedContractProcedure({
136
- route,
137
- InputSchema: void 0,
138
- OutputSchema: void 0,
139
- errorMap: void 0
140
- });
141
- }
142
- input(schema, example) {
143
- return new DecoratedContractProcedure({
144
- InputSchema: schema,
145
- inputExample: example,
146
- OutputSchema: void 0,
147
- errorMap: void 0
148
- });
149
- }
150
- output(schema, example) {
151
- return new DecoratedContractProcedure({
152
- OutputSchema: schema,
153
- outputExample: example,
154
- InputSchema: void 0,
155
- errorMap: void 0
156
- });
157
- }
158
- errors(errorMap) {
159
- return new DecoratedContractProcedure({
160
- InputSchema: void 0,
161
- OutputSchema: void 0,
162
- errorMap
146
+ return new _ContractBuilder({
147
+ ...this["~orpc"],
148
+ tags: mergeTags(this["~orpc"].tags, tags)
163
149
  });
164
150
  }
165
151
  router(router) {
166
- return router;
152
+ return adaptContractRouter(router, this["~orpc"]);
167
153
  }
168
154
  };
155
+ var oc = new ContractBuilder({
156
+ errorMap: {},
157
+ inputSchema: void 0,
158
+ outputSchema: void 0,
159
+ route: {},
160
+ meta: {}
161
+ });
169
162
 
170
163
  // src/error-orpc.ts
171
- import { isPlainObject } from "@orpc/shared";
164
+ import { isObject } from "@orpc/shared";
172
165
  var COMMON_ORPC_ERROR_DEFS = {
173
166
  BAD_REQUEST: {
174
167
  status: 400,
@@ -253,21 +246,21 @@ function fallbackORPCErrorStatus(code, status) {
253
246
  function fallbackORPCErrorMessage(code, message) {
254
247
  return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
255
248
  }
256
- var ORPCError = class extends Error {
249
+ var ORPCError = class _ORPCError extends Error {
257
250
  defined;
258
251
  code;
259
252
  status;
260
253
  data;
261
- constructor(options) {
262
- if (options.status && (options.status < 400 || options.status >= 600)) {
254
+ constructor(code, ...[options]) {
255
+ if (options?.status && (options.status < 400 || options.status >= 600)) {
263
256
  throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
264
257
  }
265
- const message = fallbackORPCErrorMessage(options.code, options.message);
258
+ const message = fallbackORPCErrorMessage(code, options?.message);
266
259
  super(message, options);
267
- this.code = options.code;
268
- this.status = fallbackORPCErrorStatus(options.code, options.status);
269
- this.defined = options.defined ?? false;
270
- this.data = options.data;
260
+ this.code = code;
261
+ this.status = fallbackORPCErrorStatus(code, options?.status);
262
+ this.defined = options?.defined ?? false;
263
+ this.data = options?.data;
271
264
  }
272
265
  toJSON() {
273
266
  return {
@@ -278,33 +271,58 @@ var ORPCError = class extends Error {
278
271
  data: this.data
279
272
  };
280
273
  }
274
+ static fromJSON(json) {
275
+ return new _ORPCError(json.code, json);
276
+ }
281
277
  static isValidJSON(json) {
282
- 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";
278
+ return isObject(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";
283
279
  }
284
280
  };
281
+
282
+ // src/error-utils.ts
285
283
  function isDefinedError(error) {
286
284
  return error instanceof ORPCError && error.defined;
287
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;
303
+ }
304
+ });
305
+ return proxy;
306
+ }
288
307
  async function validateORPCError(map, error) {
289
308
  const { code, status, message, data, cause, defined } = error;
290
309
  const config = map?.[error.code];
291
310
  if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
292
- return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
311
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
293
312
  }
294
313
  if (!config.data) {
295
- return defined ? error : new ORPCError({ defined: true, code, status, message, data, cause });
314
+ return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
296
315
  }
297
316
  const validated = await config.data["~standard"].validate(error.data);
298
317
  if (validated.issues) {
299
- return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
318
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
300
319
  }
301
- return new ORPCError({
302
- defined: true,
303
- code,
304
- status,
305
- message,
306
- data: validated.value,
307
- cause
320
+ return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
321
+ }
322
+ function toORPCError(error) {
323
+ return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
324
+ message: "Internal server error",
325
+ cause: error
308
326
  });
309
327
  }
310
328
 
@@ -330,20 +348,9 @@ var DEFAULT_CONFIG = {
330
348
  defaultInputStructure: "compact",
331
349
  defaultOutputStructure: "compact"
332
350
  };
333
- var GLOBAL_CONFIG_REF = { value: DEFAULT_CONFIG };
334
- function configGlobal(config) {
335
- if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
336
- throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
337
- }
338
- GLOBAL_CONFIG_REF.value = config;
339
- }
340
- function fallbackToGlobalConfig(key, value) {
351
+ function fallbackContractConfig(key, value) {
341
352
  if (value === void 0) {
342
- const fallback = GLOBAL_CONFIG_REF.value[key];
343
- if (fallback === void 0) {
344
- return DEFAULT_CONFIG[key];
345
- }
346
- return fallback;
353
+ return DEFAULT_CONFIG[key];
347
354
  }
348
355
  return value;
349
356
  }
@@ -357,24 +364,46 @@ var ValidationError = class extends Error {
357
364
  }
358
365
  };
359
366
 
360
- // src/index.ts
361
- var oc = new ContractBuilder();
367
+ // src/schema.ts
368
+ function type(...[map]) {
369
+ return {
370
+ "~standard": {
371
+ vendor: "custom",
372
+ version: 1,
373
+ async validate(value) {
374
+ if (map) {
375
+ return { value: await map(value) };
376
+ }
377
+ return { value };
378
+ }
379
+ }
380
+ };
381
+ }
362
382
  export {
363
383
  COMMON_ORPC_ERROR_DEFS,
364
384
  ContractBuilder,
365
385
  ContractProcedure,
366
- ContractRouterBuilder,
367
- DecoratedContractProcedure,
368
386
  ORPCError,
369
387
  ValidationError,
370
- configGlobal,
388
+ adaptContractRouter,
389
+ adaptRoute,
390
+ createORPCErrorConstructorMap,
391
+ fallbackContractConfig,
371
392
  fallbackORPCErrorMessage,
372
393
  fallbackORPCErrorStatus,
373
- fallbackToGlobalConfig,
374
394
  isContractProcedure,
375
395
  isDefinedError,
396
+ mergeErrorMap,
397
+ mergeMeta,
398
+ mergePrefix,
399
+ mergeRoute,
400
+ mergeTags,
376
401
  oc,
402
+ prefixRoute,
377
403
  safe,
404
+ toORPCError,
405
+ type,
406
+ unshiftTagRoute,
378
407
  validateORPCError
379
408
  };
380
409
  //# 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,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-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> {
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,5 +1,5 @@
1
1
  import type { ClientPromiseResult } from './client';
2
- import { type ORPCError } from './error-orpc';
2
+ import type { ORPCError } from './error-orpc';
3
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
4
  export declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
5
5
  //# sourceMappingURL=client-utils.d.ts.map
@@ -1,19 +1,21 @@
1
- import type { AbortSignal } from './types';
2
- export type ClientOptions<TClientContext> = {
1
+ export type ClientContext = Record<string, any>;
2
+ export type ClientOptions<TClientContext extends ClientContext> = {
3
3
  signal?: AbortSignal;
4
- } & (undefined extends TClientContext ? {
4
+ } & (Record<never, never> extends TClientContext ? {
5
5
  context?: TClientContext;
6
6
  } : {
7
7
  context: TClientContext;
8
8
  });
9
- export type ClientRest<TClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never);
9
+ export type ClientRest<TClientContext extends ClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (Record<never, never> extends TClientContext ? (undefined extends TInput ? [input?: TInput] : [input: TInput]) : never);
10
10
  export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
11
- __typeError?: TError;
11
+ __error?: {
12
+ type: TError;
13
+ };
12
14
  };
13
- export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
15
+ export interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
14
16
  (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
15
17
  }
16
- export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
18
+ export type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
17
19
  [k: string]: NestedClient<TClientContext>;
18
20
  };
19
21
  //# sourceMappingURL=client.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,16 +1,14 @@
1
- import type { CommonORPCErrorCode } from './error-orpc';
2
- import type { Schema } from './types';
1
+ import type { ORPCErrorCode } from './error-orpc';
2
+ import type { Schema } from './schema';
3
3
  export type ErrorMapItem<TDataSchema extends Schema> = {
4
- /**
5
- *
6
- * @default 200
7
- */
8
4
  status?: number;
9
5
  message?: string;
10
6
  description?: string;
11
7
  data?: TDataSchema;
12
8
  };
13
- export type ErrorMap = undefined | {
14
- [key in CommonORPCErrorCode | (string & {})]?: ErrorMapItem<Schema>;
9
+ export type ErrorMap = {
10
+ [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
15
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>;
16
14
  //# sourceMappingURL=error-map.d.ts.map
@@ -1,5 +1,6 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
1
2
  import type { ErrorMap, ErrorMapItem } from './error-map';
2
- import type { SchemaOutput } from './types';
3
+ import type { SchemaOutput } from './schema';
3
4
  export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
4
5
  [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
5
6
  }[keyof TErrorMap];
@@ -82,9 +83,11 @@ export declare const COMMON_ORPC_ERROR_DEFS: {
82
83
  };
83
84
  };
84
85
  export type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
85
- export type ORPCErrorOptions<TCode extends string, TData> = ErrorOptions & {
86
+ export type ORPCErrorCode = CommonORPCErrorCode | (string & {});
87
+ export declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
88
+ export declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
89
+ export type ORPCErrorOptions<TData> = ErrorOptions & {
86
90
  defined?: boolean;
87
- code: TCode;
88
91
  status?: number;
89
92
  message?: string;
90
93
  } & (undefined extends TData ? {
@@ -92,18 +95,15 @@ export type ORPCErrorOptions<TCode extends string, TData> = ErrorOptions & {
92
95
  } : {
93
96
  data: TData;
94
97
  });
95
- export declare function fallbackORPCErrorStatus(code: CommonORPCErrorCode | (string & {}), status: number | undefined): number;
96
- export declare function fallbackORPCErrorMessage(code: CommonORPCErrorCode | (string & {}), message: string | undefined): string;
97
- export declare class ORPCError<TCode extends CommonORPCErrorCode | (string & {}), TData> extends Error {
98
+ export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
98
99
  readonly defined: boolean;
99
100
  readonly code: TCode;
100
101
  readonly status: number;
101
102
  readonly data: TData;
102
- constructor(options: ORPCErrorOptions<TCode, TData>);
103
+ constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
103
104
  toJSON(): ORPCErrorJSON<TCode, TData>;
104
- static isValidJSON(json: unknown): json is ORPCErrorJSON<string, unknown>;
105
+ static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>): ORPCError<TCode, TData>;
106
+ static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
105
107
  }
106
108
  export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
107
- export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
108
- export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
109
109
  //# sourceMappingURL=error-orpc.d.ts.map
@@ -0,0 +1,15 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { ErrorMap, ErrorMapItem } from './error-map';
3
+ import type { ORPCErrorCode, ORPCErrorOptions } from './error-orpc';
4
+ import type { SchemaInput } from './schema';
5
+ import { ORPCError } from './error-orpc';
6
+ export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
7
+ export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
8
+ export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<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
+ export declare function toORPCError(error: unknown): ORPCError<any, any>;
15
+ //# sourceMappingURL=error-utils.d.ts.map
@@ -1,18 +1,18 @@
1
1
  /** unnoq */
2
- import { ContractBuilder } from './builder';
3
2
  export * from './builder';
3
+ export * from './builder-variants';
4
4
  export * from './client';
5
5
  export * from './client-utils';
6
6
  export * from './config';
7
7
  export * from './error';
8
8
  export * from './error-map';
9
9
  export * from './error-orpc';
10
+ export * from './error-utils';
11
+ export * from './meta';
10
12
  export * from './procedure';
11
13
  export * from './procedure-client';
12
- export * from './procedure-decorated';
14
+ export * from './route';
13
15
  export * from './router';
14
- export * from './router-builder';
15
16
  export * from './router-client';
16
- export * from './types';
17
- export declare const oc: ContractBuilder;
17
+ export * from './schema';
18
18
  //# 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,6 @@
1
- import type { Client } from './client';
1
+ import type { Client, ClientContext } from './client';
2
2
  import type { ErrorFromErrorMap } from './error';
3
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>>;
4
+ import type { Schema, SchemaInput, SchemaOutput } from './schema';
5
+ export type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
6
6
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,83 +1,18 @@
1
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>;
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 './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> = 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-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>;
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.da84cda",
4
+ "version": "0.0.0-next.da8ae32",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,13 +29,13 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@standard-schema/spec": "1.0.0-beta.4",
33
- "@orpc/shared": "0.0.0-next.da84cda"
32
+ "@standard-schema/spec": "1.0.0",
33
+ "@orpc/shared": "0.0.0-next.da8ae32"
34
34
  },
35
35
  "devDependencies": {
36
36
  "arktype": "2.0.0-rc.26",
37
37
  "valibot": "1.0.0-beta.9",
38
- "zod": "3.24.1"
38
+ "zod": "^3.24.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
@@ -1,14 +0,0 @@
1
- import type { ErrorMap } from './error-map';
2
- import type { RouteOptions } from './procedure';
3
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
4
- import { ContractProcedure } from './procedure';
5
- export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap> {
6
- static decorate<UInputSchema extends Schema, UOutputSchema extends Schema, TErrorMap extends ErrorMap>(procedure: ContractProcedure<UInputSchema, UOutputSchema, TErrorMap>): DecoratedContractProcedure<UInputSchema, UOutputSchema, TErrorMap>;
7
- route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
8
- prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
9
- unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
10
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema, TErrorMap>;
11
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U, TErrorMap>;
12
- errors<const U extends ErrorMap>(errorMap: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, U>;
13
- }
14
- //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -1,20 +0,0 @@
1
- import type { ContractProcedure } from './procedure';
2
- import type { ContractRouter } from './router';
3
- import type { HTTPPath } from './types';
4
- import { DecoratedContractProcedure } from './procedure-decorated';
5
- export type AdaptedContractRouter<TContract extends ContractRouter> = {
6
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors> ? DecoratedContractProcedure<UInputSchema, UOutputSchema, UErrors> : TContract[K] extends ContractRouter ? AdaptedContractRouter<TContract[K]> : never;
7
- };
8
- export interface ContractRouterBuilderDef {
9
- prefix?: HTTPPath;
10
- tags?: string[];
11
- }
12
- export declare class ContractRouterBuilder {
13
- '~type': "ContractProcedure";
14
- '~orpc': ContractRouterBuilderDef;
15
- constructor(def: ContractRouterBuilderDef);
16
- prefix(prefix: HTTPPath): ContractRouterBuilder;
17
- tag(...tags: string[]): ContractRouterBuilder;
18
- router<T extends ContractRouter>(router: T): AdaptedContractRouter<T>;
19
- }
20
- //# sourceMappingURL=router-builder.d.ts.map