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

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.mjs ADDED
@@ -0,0 +1,355 @@
1
+ import { isORPCErrorStatus, mapEventIterator, ORPCError } from '@orpc/client';
2
+ export { ORPCError } from '@orpc/client';
3
+ import { isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
4
+
5
+ class ValidationError extends Error {
6
+ issues;
7
+ constructor(options) {
8
+ super(options.message, options);
9
+ this.issues = options.issues;
10
+ }
11
+ }
12
+ function mergeErrorMap(errorMap1, errorMap2) {
13
+ return { ...errorMap1, ...errorMap2 };
14
+ }
15
+
16
+ function mergeMeta(meta1, meta2) {
17
+ return { ...meta1, ...meta2 };
18
+ }
19
+
20
+ class ContractProcedure {
21
+ /**
22
+ * This property holds the defined options for the contract procedure.
23
+ */
24
+ "~orpc";
25
+ constructor(def) {
26
+ if (def.route?.successStatus && isORPCErrorStatus(def.route.successStatus)) {
27
+ throw new Error("[ContractProcedure] Invalid successStatus.");
28
+ }
29
+ if (Object.values(def.errorMap).some((val) => val && val.status && !isORPCErrorStatus(val.status))) {
30
+ throw new Error("[ContractProcedure] Invalid error status code.");
31
+ }
32
+ this["~orpc"] = def;
33
+ }
34
+ }
35
+ function isContractProcedure(item) {
36
+ if (item instanceof ContractProcedure) {
37
+ return true;
38
+ }
39
+ return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "errorMap" in item["~orpc"] && "route" in item["~orpc"] && "meta" in item["~orpc"];
40
+ }
41
+
42
+ function mergeRoute(a, b) {
43
+ return { ...a, ...b };
44
+ }
45
+ function prefixRoute(route, prefix) {
46
+ if (!route.path) {
47
+ return route;
48
+ }
49
+ return {
50
+ ...route,
51
+ path: `${prefix}${route.path}`
52
+ };
53
+ }
54
+ function unshiftTagRoute(route, tags) {
55
+ return {
56
+ ...route,
57
+ tags: [...tags, ...route.tags ?? []]
58
+ };
59
+ }
60
+ function mergePrefix(a, b) {
61
+ return a ? `${a}${b}` : b;
62
+ }
63
+ function mergeTags(a, b) {
64
+ return a ? [...a, ...b] : b;
65
+ }
66
+ function enhanceRoute(route, options) {
67
+ let router = route;
68
+ if (options.prefix) {
69
+ router = prefixRoute(router, options.prefix);
70
+ }
71
+ if (options.tags?.length) {
72
+ router = unshiftTagRoute(router, options.tags);
73
+ }
74
+ return router;
75
+ }
76
+
77
+ function getContractRouter(router, path) {
78
+ let current = router;
79
+ for (let i = 0; i < path.length; i++) {
80
+ const segment = path[i];
81
+ if (!current) {
82
+ return void 0;
83
+ }
84
+ if (isContractProcedure(current)) {
85
+ return void 0;
86
+ }
87
+ current = current[segment];
88
+ }
89
+ return current;
90
+ }
91
+ function enhanceContractRouter(router, options) {
92
+ if (isContractProcedure(router)) {
93
+ const enhanced2 = new ContractProcedure({
94
+ ...router["~orpc"],
95
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
96
+ route: enhanceRoute(router["~orpc"].route, options)
97
+ });
98
+ return enhanced2;
99
+ }
100
+ const enhanced = {};
101
+ for (const key in router) {
102
+ enhanced[key] = enhanceContractRouter(router[key], options);
103
+ }
104
+ return enhanced;
105
+ }
106
+ function minifyContractRouter(router) {
107
+ if (isContractProcedure(router)) {
108
+ const procedure = {
109
+ "~orpc": {
110
+ errorMap: {},
111
+ meta: router["~orpc"].meta,
112
+ route: router["~orpc"].route
113
+ }
114
+ };
115
+ return procedure;
116
+ }
117
+ const json = {};
118
+ for (const key in router) {
119
+ json[key] = minifyContractRouter(router[key]);
120
+ }
121
+ return json;
122
+ }
123
+
124
+ class ContractBuilder extends ContractProcedure {
125
+ constructor(def) {
126
+ super(def);
127
+ this["~orpc"].prefix = def.prefix;
128
+ this["~orpc"].tags = def.tags;
129
+ }
130
+ /**
131
+ * Sets or overrides the initial meta.
132
+ *
133
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
134
+ */
135
+ $meta(initialMeta) {
136
+ return new ContractBuilder({
137
+ ...this["~orpc"],
138
+ meta: initialMeta
139
+ });
140
+ }
141
+ /**
142
+ * Sets or overrides the initial route.
143
+ * This option is typically relevant when integrating with OpenAPI.
144
+ *
145
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
146
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
147
+ */
148
+ $route(initialRoute) {
149
+ return new ContractBuilder({
150
+ ...this["~orpc"],
151
+ route: initialRoute
152
+ });
153
+ }
154
+ /**
155
+ * Adds type-safe custom errors to the contract.
156
+ * The provided errors are spared-merged with any existing errors in the contract.
157
+ *
158
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
159
+ */
160
+ errors(errors) {
161
+ return new ContractBuilder({
162
+ ...this["~orpc"],
163
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
164
+ });
165
+ }
166
+ /**
167
+ * Sets or updates the metadata for the contract.
168
+ * The provided metadata is spared-merged with any existing metadata in the contract.
169
+ *
170
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
171
+ */
172
+ meta(meta) {
173
+ return new ContractBuilder({
174
+ ...this["~orpc"],
175
+ meta: mergeMeta(this["~orpc"].meta, meta)
176
+ });
177
+ }
178
+ /**
179
+ * Sets or updates the route definition for the contract.
180
+ * The provided route is spared-merged with any existing route in the contract.
181
+ * This option is typically relevant when integrating with OpenAPI.
182
+ *
183
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
184
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
185
+ */
186
+ route(route) {
187
+ return new ContractBuilder({
188
+ ...this["~orpc"],
189
+ route: mergeRoute(this["~orpc"].route, route)
190
+ });
191
+ }
192
+ /**
193
+ * Defines the input validation schema for the contract.
194
+ *
195
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
196
+ */
197
+ input(schema) {
198
+ return new ContractBuilder({
199
+ ...this["~orpc"],
200
+ inputSchema: schema
201
+ });
202
+ }
203
+ /**
204
+ * Defines the output validation schema for the contract.
205
+ *
206
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
207
+ */
208
+ output(schema) {
209
+ return new ContractBuilder({
210
+ ...this["~orpc"],
211
+ outputSchema: schema
212
+ });
213
+ }
214
+ /**
215
+ * Prefixes all procedures in the contract router.
216
+ * The provided prefix is post-appended to any existing router prefix.
217
+ *
218
+ * @note This option does not affect procedures that do not define a path in their route definition.
219
+ *
220
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
221
+ */
222
+ prefix(prefix) {
223
+ return new ContractBuilder({
224
+ ...this["~orpc"],
225
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
226
+ });
227
+ }
228
+ /**
229
+ * Adds tags to all procedures in the contract router.
230
+ * This helpful when you want to group procedures together in the OpenAPI specification.
231
+ *
232
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
233
+ */
234
+ tag(...tags) {
235
+ return new ContractBuilder({
236
+ ...this["~orpc"],
237
+ tags: mergeTags(this["~orpc"].tags, tags)
238
+ });
239
+ }
240
+ /**
241
+ * Applies all of the previously defined options to the specified contract router.
242
+ *
243
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
244
+ */
245
+ router(router) {
246
+ return enhanceContractRouter(router, this["~orpc"]);
247
+ }
248
+ }
249
+ const oc = new ContractBuilder({
250
+ errorMap: {},
251
+ route: {},
252
+ meta: {}
253
+ });
254
+
255
+ const DEFAULT_CONFIG = {
256
+ defaultMethod: "POST",
257
+ defaultSuccessStatus: 200,
258
+ defaultSuccessDescription: "OK",
259
+ defaultInputStructure: "compact",
260
+ defaultOutputStructure: "compact"
261
+ };
262
+ function fallbackContractConfig(key, value) {
263
+ if (value === void 0) {
264
+ return DEFAULT_CONFIG[key];
265
+ }
266
+ return value;
267
+ }
268
+
269
+ const EVENT_ITERATOR_DETAILS_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_DETAILS");
270
+ function eventIterator(yields, returns) {
271
+ return {
272
+ "~standard": {
273
+ [EVENT_ITERATOR_DETAILS_SYMBOL]: { yields, returns },
274
+ vendor: "orpc",
275
+ version: 1,
276
+ validate(iterator) {
277
+ if (!isAsyncIteratorObject(iterator)) {
278
+ return { issues: [{ message: "Expect event iterator", path: [] }] };
279
+ }
280
+ const mapped = mapEventIterator(iterator, {
281
+ async value(value, done) {
282
+ const schema = done ? returns : yields;
283
+ if (!schema) {
284
+ return value;
285
+ }
286
+ const result = await schema["~standard"].validate(value);
287
+ if (result.issues) {
288
+ throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
289
+ message: "Event iterator validation failed",
290
+ cause: new ValidationError({
291
+ issues: result.issues,
292
+ message: "Event iterator validation failed"
293
+ })
294
+ });
295
+ }
296
+ return result.value;
297
+ },
298
+ error: async (error) => error
299
+ });
300
+ return { value: mapped };
301
+ }
302
+ }
303
+ };
304
+ }
305
+ function getEventIteratorSchemaDetails(schema) {
306
+ if (schema === void 0) {
307
+ return void 0;
308
+ }
309
+ return schema["~standard"][EVENT_ITERATOR_DETAILS_SYMBOL];
310
+ }
311
+
312
+ function inferRPCMethodFromContractRouter(contract) {
313
+ return (_, path) => {
314
+ const procedure = get(contract, path);
315
+ if (!isContractProcedure(procedure)) {
316
+ throw new Error(
317
+ `[inferRPCMethodFromContractRouter] No valid procedure found at path "${path.join(".")}". This may happen when the contract router is not properly configured.`
318
+ );
319
+ }
320
+ const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
321
+ return method === "HEAD" ? "GET" : method;
322
+ };
323
+ }
324
+
325
+ function type(...[map]) {
326
+ return {
327
+ "~standard": {
328
+ vendor: "custom",
329
+ version: 1,
330
+ async validate(value) {
331
+ if (map) {
332
+ return { value: await map(value) };
333
+ }
334
+ return { value };
335
+ }
336
+ }
337
+ };
338
+ }
339
+
340
+ function isSchemaIssue(issue) {
341
+ if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
342
+ return false;
343
+ }
344
+ if (issue.path !== void 0) {
345
+ if (!Array.isArray(issue.path)) {
346
+ return false;
347
+ }
348
+ if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
349
+ return false;
350
+ }
351
+ }
352
+ return true;
353
+ }
354
+
355
+ export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
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.f16d90e",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,26 +15,27 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
21
- },
22
- "./🔒/*": {
23
- "types": "./dist/src/*.d.ts"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
24
21
  }
25
22
  },
26
23
  "files": [
27
- "!dist/*.tsbuildinfo",
28
24
  "dist"
29
25
  ],
30
- "peerDependencies": {
31
- "zod": ">=3.23.0"
32
- },
33
26
  "dependencies": {
34
- "@orpc/shared": "0.0.0-next.ef3ba82"
27
+ "@standard-schema/spec": "^1.0.0",
28
+ "openapi-types": "^12.1.3",
29
+ "@orpc/client": "0.0.0-next.f16d90e",
30
+ "@orpc/shared": "0.0.0-next.f16d90e"
31
+ },
32
+ "devDependencies": {
33
+ "arktype": "2.1.20",
34
+ "valibot": "^1.1.0",
35
+ "zod": "^3.25.11"
35
36
  },
36
37
  "scripts": {
37
- "build": "tsup --clean --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
38
+ "build": "unbuild",
38
39
  "build:watch": "pnpm run build --watch",
39
40
  "type:check": "tsc -b"
40
41
  }
package/dist/index.js DELETED
@@ -1,175 +0,0 @@
1
- // src/procedure.ts
2
- var ContractProcedure = class {
3
- constructor(zz$cp) {
4
- this.zz$cp = zz$cp;
5
- }
6
- };
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
- });
20
- }
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
- }
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
- });
36
- }
37
- input(schema, example) {
38
- return new _DecoratedContractProcedure({
39
- ...this.zz$cp,
40
- InputSchema: schema,
41
- inputExample: example
42
- });
43
- }
44
- output(schema, example) {
45
- return new _DecoratedContractProcedure({
46
- ...this.zz$cp,
47
- OutputSchema: schema,
48
- outputExample: example
49
- });
50
- }
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;
56
- }
57
-
58
- // src/router-builder.ts
59
- var ContractRouterBuilder = class _ContractRouterBuilder {
60
- constructor(zz$crb) {
61
- this.zz$crb = zz$crb;
62
- }
63
- prefix(prefix) {
64
- return new _ContractRouterBuilder({
65
- ...this.zz$crb,
66
- prefix: `${this.zz$crb.prefix ?? ""}${prefix}`
67
- });
68
- }
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]
75
- });
76
- }
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;
91
- }
92
- };
93
-
94
- // src/builder.ts
95
- var ContractBuilder = class {
96
- prefix(prefix) {
97
- return new ContractRouterBuilder({
98
- prefix
99
- });
100
- }
101
- tags(...tags) {
102
- return new ContractRouterBuilder({
103
- tags
104
- });
105
- }
106
- route(opts) {
107
- return new DecoratedContractProcedure({
108
- InputSchema: void 0,
109
- OutputSchema: void 0,
110
- ...opts
111
- });
112
- }
113
- input(schema, example) {
114
- return new DecoratedContractProcedure({
115
- InputSchema: schema,
116
- inputExample: example,
117
- OutputSchema: void 0
118
- });
119
- }
120
- output(schema, example) {
121
- return new DecoratedContractProcedure({
122
- InputSchema: void 0,
123
- OutputSchema: schema,
124
- outputExample: example
125
- });
126
- }
127
- router(router) {
128
- return router;
129
- }
130
- };
131
-
132
- // src/constants.ts
133
- var ORPC_HEADER = "x-orpc-transformer";
134
- var ORPC_HEADER_VALUE = "t";
135
-
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]);
144
- }
145
- }
146
- }
147
-
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_}`;
160
- }
161
-
162
- // src/index.ts
163
- var oc = new ContractBuilder();
164
- export {
165
- ContractBuilder,
166
- ContractProcedure,
167
- DecoratedContractProcedure,
168
- ORPC_HEADER,
169
- ORPC_HEADER_VALUE,
170
- eachContractRouterLeaf,
171
- isContractProcedure,
172
- oc,
173
- prefixHTTPPath,
174
- standardizeHTTPPath
175
- };
@@ -1,12 +0,0 @@
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;
12
- }
@@ -1,2 +0,0 @@
1
- export declare const ORPC_HEADER = "x-orpc-transformer";
2
- export declare const ORPC_HEADER_VALUE = "t";
@@ -1,9 +0,0 @@
1
- /** unnoq */
2
- import { ContractBuilder } from './builder';
3
- export * from './builder';
4
- export * from './constants';
5
- export * from './procedure';
6
- export * from './router';
7
- export * from './types';
8
- export * from './utils';
9
- export declare const oc: ContractBuilder;
@@ -1,45 +0,0 @@
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[];
9
- }
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
- });
35
- }
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;
@@ -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,15 +0,0 @@
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;
8
- };
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;
12
- };
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;
15
- };
@@ -1,7 +0,0 @@
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,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;