@orpc/contract 0.0.0-next.eb37cbe → 0.0.0-next.ed15210
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 +405 -36
- package/dist/src/builder.d.ts +28 -10
- package/dist/src/client-utils.d.ts +5 -0
- package/dist/src/client.d.ts +19 -0
- package/dist/src/config.d.ts +11 -0
- package/dist/src/error-map.d.ts +58 -0
- package/dist/src/error-orpc.d.ts +109 -0
- package/dist/src/error.d.ts +13 -0
- package/dist/src/index.d.ts +14 -1
- package/dist/src/procedure-builder-with-input.d.ts +19 -0
- package/dist/src/procedure-builder-with-output.d.ts +19 -0
- package/dist/src/procedure-builder.d.ts +15 -0
- package/dist/src/procedure-client.d.ts +6 -0
- package/dist/src/procedure-decorated.d.ts +9 -9
- package/dist/src/procedure.d.ts +11 -17
- package/dist/src/route.d.ts +88 -0
- package/dist/src/router-builder.d.ts +16 -12
- package/dist/src/router-client.d.ts +7 -0
- package/dist/src/router.d.ts +8 -7
- package/dist/src/schema-utils.d.ts +5 -0
- package/dist/src/types.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var ContractProcedure = class {
|
|
|
6
6
|
if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
|
|
7
7
|
throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
|
|
8
8
|
}
|
|
9
|
+
if (Object.values(def.errorMap).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
|
|
10
|
+
throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
|
|
11
|
+
}
|
|
9
12
|
this["~orpc"] = def;
|
|
10
13
|
}
|
|
11
14
|
};
|
|
@@ -13,7 +16,36 @@ function isContractProcedure(item) {
|
|
|
13
16
|
if (item instanceof ContractProcedure) {
|
|
14
17
|
return true;
|
|
15
18
|
}
|
|
16
|
-
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"];
|
|
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"] && "route" in item["~orpc"];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/route.ts
|
|
23
|
+
function mergeRoute(a, b) {
|
|
24
|
+
return {
|
|
25
|
+
...a,
|
|
26
|
+
...b
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function prefixRoute(route, prefix) {
|
|
30
|
+
if (!route.path) {
|
|
31
|
+
return route;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...route,
|
|
35
|
+
path: `${prefix}${route.path}`
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function unshiftTagRoute(route, tags) {
|
|
39
|
+
return {
|
|
40
|
+
...route,
|
|
41
|
+
tags: [...tags, ...route.tags ?? []]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function mergePrefix(a, b) {
|
|
45
|
+
return a ? `${a}${b}` : b;
|
|
46
|
+
}
|
|
47
|
+
function mergeTags(a, b) {
|
|
48
|
+
return a ? [...a, ...b] : b;
|
|
17
49
|
}
|
|
18
50
|
|
|
19
51
|
// src/procedure-decorated.ts
|
|
@@ -24,44 +56,116 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
|
|
|
24
56
|
}
|
|
25
57
|
return new _DecoratedContractProcedure(procedure["~orpc"]);
|
|
26
58
|
}
|
|
59
|
+
errors(errors) {
|
|
60
|
+
return new _DecoratedContractProcedure({
|
|
61
|
+
...this["~orpc"],
|
|
62
|
+
errorMap: {
|
|
63
|
+
...this["~orpc"].errorMap,
|
|
64
|
+
...errors
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
27
68
|
route(route) {
|
|
28
69
|
return new _DecoratedContractProcedure({
|
|
29
70
|
...this["~orpc"],
|
|
30
|
-
route
|
|
71
|
+
route: mergeRoute(this["~orpc"].route, route)
|
|
31
72
|
});
|
|
32
73
|
}
|
|
33
74
|
prefix(prefix) {
|
|
34
75
|
return new _DecoratedContractProcedure({
|
|
35
76
|
...this["~orpc"],
|
|
36
|
-
|
|
37
|
-
route: {
|
|
38
|
-
...this["~orpc"].route,
|
|
39
|
-
path: `${prefix}${this["~orpc"].route.path}`
|
|
40
|
-
}
|
|
41
|
-
} : void 0
|
|
77
|
+
route: prefixRoute(this["~orpc"].route, prefix)
|
|
42
78
|
});
|
|
43
79
|
}
|
|
44
80
|
unshiftTag(...tags) {
|
|
45
81
|
return new _DecoratedContractProcedure({
|
|
46
82
|
...this["~orpc"],
|
|
47
|
-
route:
|
|
48
|
-
...this["~orpc"].route,
|
|
49
|
-
tags: [
|
|
50
|
-
...tags,
|
|
51
|
-
...this["~orpc"].route?.tags?.filter((tag) => !tags.includes(tag)) ?? []
|
|
52
|
-
]
|
|
53
|
-
}
|
|
83
|
+
route: unshiftTagRoute(this["~orpc"].route, tags)
|
|
54
84
|
});
|
|
55
85
|
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/procedure-builder-with-input.ts
|
|
89
|
+
var ContractProcedureBuilderWithInput = class _ContractProcedureBuilderWithInput extends ContractProcedure {
|
|
90
|
+
errors(errors) {
|
|
91
|
+
const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
|
|
92
|
+
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
93
|
+
}
|
|
94
|
+
route(route) {
|
|
95
|
+
const decorated = DecoratedContractProcedure.decorate(this).route(route);
|
|
96
|
+
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
97
|
+
}
|
|
98
|
+
prefix(prefix) {
|
|
99
|
+
const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
|
|
100
|
+
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
101
|
+
}
|
|
102
|
+
unshiftTag(...tags) {
|
|
103
|
+
const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
|
|
104
|
+
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
105
|
+
}
|
|
106
|
+
output(schema, example) {
|
|
107
|
+
return new DecoratedContractProcedure({
|
|
108
|
+
...this["~orpc"],
|
|
109
|
+
OutputSchema: schema,
|
|
110
|
+
outputExample: example
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/procedure-builder-with-output.ts
|
|
116
|
+
var ContractProcedureBuilderWithOutput = class _ContractProcedureBuilderWithOutput extends ContractProcedure {
|
|
117
|
+
errors(errors) {
|
|
118
|
+
const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
|
|
119
|
+
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
120
|
+
}
|
|
121
|
+
route(route) {
|
|
122
|
+
const decorated = DecoratedContractProcedure.decorate(this).route(route);
|
|
123
|
+
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
124
|
+
}
|
|
125
|
+
prefix(prefix) {
|
|
126
|
+
const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
|
|
127
|
+
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
128
|
+
}
|
|
129
|
+
unshiftTag(...tags) {
|
|
130
|
+
const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
|
|
131
|
+
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
132
|
+
}
|
|
56
133
|
input(schema, example) {
|
|
57
|
-
return new
|
|
134
|
+
return new DecoratedContractProcedure({
|
|
135
|
+
...this["~orpc"],
|
|
136
|
+
InputSchema: schema,
|
|
137
|
+
inputExample: example
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// src/procedure-builder.ts
|
|
143
|
+
var ContractProcedureBuilder = class _ContractProcedureBuilder extends ContractProcedure {
|
|
144
|
+
errors(errors) {
|
|
145
|
+
const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
|
|
146
|
+
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
147
|
+
}
|
|
148
|
+
route(route) {
|
|
149
|
+
const decorated = DecoratedContractProcedure.decorate(this).route(route);
|
|
150
|
+
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
151
|
+
}
|
|
152
|
+
prefix(prefix) {
|
|
153
|
+
const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
|
|
154
|
+
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
155
|
+
}
|
|
156
|
+
unshiftTag(...tags) {
|
|
157
|
+
const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
|
|
158
|
+
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
159
|
+
}
|
|
160
|
+
input(schema, example) {
|
|
161
|
+
return new ContractProcedureBuilderWithInput({
|
|
58
162
|
...this["~orpc"],
|
|
59
163
|
InputSchema: schema,
|
|
60
164
|
inputExample: example
|
|
61
165
|
});
|
|
62
166
|
}
|
|
63
167
|
output(schema, example) {
|
|
64
|
-
return new
|
|
168
|
+
return new ContractProcedureBuilderWithOutput({
|
|
65
169
|
...this["~orpc"],
|
|
66
170
|
OutputSchema: schema,
|
|
67
171
|
outputExample: example
|
|
@@ -79,13 +183,22 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
|
79
183
|
prefix(prefix) {
|
|
80
184
|
return new _ContractRouterBuilder({
|
|
81
185
|
...this["~orpc"],
|
|
82
|
-
prefix:
|
|
186
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
83
187
|
});
|
|
84
188
|
}
|
|
85
189
|
tag(...tags) {
|
|
86
190
|
return new _ContractRouterBuilder({
|
|
87
191
|
...this["~orpc"],
|
|
88
|
-
tags:
|
|
192
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
errors(errors) {
|
|
196
|
+
return new _ContractRouterBuilder({
|
|
197
|
+
...this["~orpc"],
|
|
198
|
+
errorMap: {
|
|
199
|
+
...this["~orpc"].errorMap,
|
|
200
|
+
...errors
|
|
201
|
+
}
|
|
89
202
|
});
|
|
90
203
|
}
|
|
91
204
|
router(router) {
|
|
@@ -97,6 +210,7 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
|
97
210
|
if (this["~orpc"].prefix) {
|
|
98
211
|
decorated = decorated.prefix(this["~orpc"].prefix);
|
|
99
212
|
}
|
|
213
|
+
decorated = decorated.errors(this["~orpc"].errorMap);
|
|
100
214
|
return decorated;
|
|
101
215
|
}
|
|
102
216
|
const adapted = {};
|
|
@@ -108,51 +222,306 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
|
108
222
|
};
|
|
109
223
|
|
|
110
224
|
// src/builder.ts
|
|
111
|
-
var ContractBuilder = class {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
225
|
+
var ContractBuilder = class _ContractBuilder extends ContractProcedure {
|
|
226
|
+
constructor(def) {
|
|
227
|
+
super(def);
|
|
228
|
+
this["~orpc"].config = def.config;
|
|
229
|
+
}
|
|
230
|
+
config(config) {
|
|
231
|
+
return new _ContractBuilder({
|
|
232
|
+
...this["~orpc"],
|
|
233
|
+
config: {
|
|
234
|
+
...this["~orpc"].config,
|
|
235
|
+
...config
|
|
236
|
+
}
|
|
115
237
|
});
|
|
116
238
|
}
|
|
117
|
-
|
|
118
|
-
return new
|
|
119
|
-
|
|
239
|
+
errors(errors) {
|
|
240
|
+
return new _ContractBuilder({
|
|
241
|
+
...this["~orpc"],
|
|
242
|
+
errorMap: {
|
|
243
|
+
...this["~orpc"].errorMap,
|
|
244
|
+
...errors
|
|
245
|
+
}
|
|
120
246
|
});
|
|
121
247
|
}
|
|
122
248
|
route(route) {
|
|
123
|
-
return new
|
|
124
|
-
route,
|
|
249
|
+
return new ContractProcedureBuilder({
|
|
250
|
+
route: mergeRoute(this["~orpc"].route, route),
|
|
125
251
|
InputSchema: void 0,
|
|
126
|
-
OutputSchema: void 0
|
|
252
|
+
OutputSchema: void 0,
|
|
253
|
+
errorMap: this["~orpc"].errorMap
|
|
127
254
|
});
|
|
128
255
|
}
|
|
129
256
|
input(schema, example) {
|
|
130
|
-
return new
|
|
257
|
+
return new ContractProcedureBuilderWithInput({
|
|
258
|
+
route: this["~orpc"].route,
|
|
131
259
|
InputSchema: schema,
|
|
132
260
|
inputExample: example,
|
|
133
|
-
OutputSchema: void 0
|
|
261
|
+
OutputSchema: void 0,
|
|
262
|
+
errorMap: this["~orpc"].errorMap
|
|
134
263
|
});
|
|
135
264
|
}
|
|
136
265
|
output(schema, example) {
|
|
137
|
-
return new
|
|
266
|
+
return new ContractProcedureBuilderWithOutput({
|
|
267
|
+
route: this["~orpc"].route,
|
|
138
268
|
OutputSchema: schema,
|
|
139
269
|
outputExample: example,
|
|
140
|
-
InputSchema: void 0
|
|
270
|
+
InputSchema: void 0,
|
|
271
|
+
errorMap: this["~orpc"].errorMap
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
prefix(prefix) {
|
|
275
|
+
return new ContractRouterBuilder({
|
|
276
|
+
prefix,
|
|
277
|
+
errorMap: this["~orpc"].errorMap,
|
|
278
|
+
tags: void 0
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
tag(...tags) {
|
|
282
|
+
return new ContractRouterBuilder({
|
|
283
|
+
tags,
|
|
284
|
+
errorMap: this["~orpc"].errorMap,
|
|
285
|
+
prefix: void 0
|
|
141
286
|
});
|
|
142
287
|
}
|
|
143
288
|
router(router) {
|
|
144
|
-
return
|
|
289
|
+
return new ContractRouterBuilder({
|
|
290
|
+
errorMap: this["~orpc"].errorMap,
|
|
291
|
+
prefix: void 0,
|
|
292
|
+
tags: void 0
|
|
293
|
+
}).router(router);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// src/error-orpc.ts
|
|
298
|
+
import { isPlainObject } from "@orpc/shared";
|
|
299
|
+
var COMMON_ORPC_ERROR_DEFS = {
|
|
300
|
+
BAD_REQUEST: {
|
|
301
|
+
status: 400,
|
|
302
|
+
message: "Bad Request"
|
|
303
|
+
},
|
|
304
|
+
UNAUTHORIZED: {
|
|
305
|
+
status: 401,
|
|
306
|
+
message: "Unauthorized"
|
|
307
|
+
},
|
|
308
|
+
FORBIDDEN: {
|
|
309
|
+
status: 403,
|
|
310
|
+
message: "Forbidden"
|
|
311
|
+
},
|
|
312
|
+
NOT_FOUND: {
|
|
313
|
+
status: 404,
|
|
314
|
+
message: "Not Found"
|
|
315
|
+
},
|
|
316
|
+
METHOD_NOT_SUPPORTED: {
|
|
317
|
+
status: 405,
|
|
318
|
+
message: "Method Not Supported"
|
|
319
|
+
},
|
|
320
|
+
NOT_ACCEPTABLE: {
|
|
321
|
+
status: 406,
|
|
322
|
+
message: "Not Acceptable"
|
|
323
|
+
},
|
|
324
|
+
TIMEOUT: {
|
|
325
|
+
status: 408,
|
|
326
|
+
message: "Request Timeout"
|
|
327
|
+
},
|
|
328
|
+
CONFLICT: {
|
|
329
|
+
status: 409,
|
|
330
|
+
message: "Conflict"
|
|
331
|
+
},
|
|
332
|
+
PRECONDITION_FAILED: {
|
|
333
|
+
status: 412,
|
|
334
|
+
message: "Precondition Failed"
|
|
335
|
+
},
|
|
336
|
+
PAYLOAD_TOO_LARGE: {
|
|
337
|
+
status: 413,
|
|
338
|
+
message: "Payload Too Large"
|
|
339
|
+
},
|
|
340
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
341
|
+
status: 415,
|
|
342
|
+
message: "Unsupported Media Type"
|
|
343
|
+
},
|
|
344
|
+
UNPROCESSABLE_CONTENT: {
|
|
345
|
+
status: 422,
|
|
346
|
+
message: "Unprocessable Content"
|
|
347
|
+
},
|
|
348
|
+
TOO_MANY_REQUESTS: {
|
|
349
|
+
status: 429,
|
|
350
|
+
message: "Too Many Requests"
|
|
351
|
+
},
|
|
352
|
+
CLIENT_CLOSED_REQUEST: {
|
|
353
|
+
status: 499,
|
|
354
|
+
message: "Client Closed Request"
|
|
355
|
+
},
|
|
356
|
+
INTERNAL_SERVER_ERROR: {
|
|
357
|
+
status: 500,
|
|
358
|
+
message: "Internal Server Error"
|
|
359
|
+
},
|
|
360
|
+
NOT_IMPLEMENTED: {
|
|
361
|
+
status: 501,
|
|
362
|
+
message: "Not Implemented"
|
|
363
|
+
},
|
|
364
|
+
BAD_GATEWAY: {
|
|
365
|
+
status: 502,
|
|
366
|
+
message: "Bad Gateway"
|
|
367
|
+
},
|
|
368
|
+
SERVICE_UNAVAILABLE: {
|
|
369
|
+
status: 503,
|
|
370
|
+
message: "Service Unavailable"
|
|
371
|
+
},
|
|
372
|
+
GATEWAY_TIMEOUT: {
|
|
373
|
+
status: 504,
|
|
374
|
+
message: "Gateway Timeout"
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
378
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
379
|
+
}
|
|
380
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
381
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
382
|
+
}
|
|
383
|
+
var ORPCError = class extends Error {
|
|
384
|
+
defined;
|
|
385
|
+
code;
|
|
386
|
+
status;
|
|
387
|
+
data;
|
|
388
|
+
constructor(options) {
|
|
389
|
+
if (options.status && (options.status < 400 || options.status >= 600)) {
|
|
390
|
+
throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
|
|
391
|
+
}
|
|
392
|
+
const message = fallbackORPCErrorMessage(options.code, options.message);
|
|
393
|
+
super(message, options);
|
|
394
|
+
this.code = options.code;
|
|
395
|
+
this.status = fallbackORPCErrorStatus(options.code, options.status);
|
|
396
|
+
this.defined = options.defined ?? false;
|
|
397
|
+
this.data = options.data;
|
|
398
|
+
}
|
|
399
|
+
toJSON() {
|
|
400
|
+
return {
|
|
401
|
+
defined: this.defined,
|
|
402
|
+
code: this.code,
|
|
403
|
+
status: this.status,
|
|
404
|
+
message: this.message,
|
|
405
|
+
data: this.data
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
static isValidJSON(json) {
|
|
409
|
+
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";
|
|
145
410
|
}
|
|
146
411
|
};
|
|
412
|
+
function isDefinedError(error) {
|
|
413
|
+
return error instanceof ORPCError && error.defined;
|
|
414
|
+
}
|
|
415
|
+
async function validateORPCError(map, error) {
|
|
416
|
+
const { code, status, message, data, cause, defined } = error;
|
|
417
|
+
const config = map?.[error.code];
|
|
418
|
+
if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
|
|
419
|
+
return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
|
|
420
|
+
}
|
|
421
|
+
if (!config.data) {
|
|
422
|
+
return defined ? error : new ORPCError({ defined: true, code, status, message, data, cause });
|
|
423
|
+
}
|
|
424
|
+
const validated = await config.data["~standard"].validate(error.data);
|
|
425
|
+
if (validated.issues) {
|
|
426
|
+
return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
|
|
427
|
+
}
|
|
428
|
+
return new ORPCError({
|
|
429
|
+
defined: true,
|
|
430
|
+
code,
|
|
431
|
+
status,
|
|
432
|
+
message,
|
|
433
|
+
data: validated.value,
|
|
434
|
+
cause
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/client-utils.ts
|
|
439
|
+
async function safe(promise) {
|
|
440
|
+
try {
|
|
441
|
+
const output = await promise;
|
|
442
|
+
return [output, void 0, false];
|
|
443
|
+
} catch (e) {
|
|
444
|
+
const error = e;
|
|
445
|
+
if (isDefinedError(error)) {
|
|
446
|
+
return [void 0, error, true];
|
|
447
|
+
}
|
|
448
|
+
return [void 0, error, false];
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/config.ts
|
|
453
|
+
var DEFAULT_CONFIG = {
|
|
454
|
+
defaultMethod: "POST",
|
|
455
|
+
defaultSuccessStatus: 200,
|
|
456
|
+
defaultSuccessDescription: "OK",
|
|
457
|
+
defaultInputStructure: "compact",
|
|
458
|
+
defaultOutputStructure: "compact",
|
|
459
|
+
defaultInitialRoute: {}
|
|
460
|
+
};
|
|
461
|
+
function fallbackContractConfig(key, value) {
|
|
462
|
+
if (value === void 0) {
|
|
463
|
+
return DEFAULT_CONFIG[key];
|
|
464
|
+
}
|
|
465
|
+
return value;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// src/error.ts
|
|
469
|
+
var ValidationError = class extends Error {
|
|
470
|
+
issues;
|
|
471
|
+
constructor(options) {
|
|
472
|
+
super(options.message, options);
|
|
473
|
+
this.issues = options.issues;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
// src/schema-utils.ts
|
|
478
|
+
function type(...[map]) {
|
|
479
|
+
return {
|
|
480
|
+
"~standard": {
|
|
481
|
+
vendor: "custom",
|
|
482
|
+
version: 1,
|
|
483
|
+
async validate(value) {
|
|
484
|
+
if (map) {
|
|
485
|
+
return { value: await map(value) };
|
|
486
|
+
}
|
|
487
|
+
return { value };
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
147
492
|
|
|
148
493
|
// src/index.ts
|
|
149
|
-
var oc = new ContractBuilder(
|
|
494
|
+
var oc = new ContractBuilder({
|
|
495
|
+
config: {},
|
|
496
|
+
route: {},
|
|
497
|
+
errorMap: {},
|
|
498
|
+
InputSchema: void 0,
|
|
499
|
+
OutputSchema: void 0
|
|
500
|
+
});
|
|
150
501
|
export {
|
|
502
|
+
COMMON_ORPC_ERROR_DEFS,
|
|
151
503
|
ContractBuilder,
|
|
152
504
|
ContractProcedure,
|
|
505
|
+
ContractProcedureBuilder,
|
|
506
|
+
ContractProcedureBuilderWithInput,
|
|
507
|
+
ContractProcedureBuilderWithOutput,
|
|
153
508
|
ContractRouterBuilder,
|
|
154
509
|
DecoratedContractProcedure,
|
|
510
|
+
ORPCError,
|
|
511
|
+
ValidationError,
|
|
512
|
+
fallbackContractConfig,
|
|
513
|
+
fallbackORPCErrorMessage,
|
|
514
|
+
fallbackORPCErrorStatus,
|
|
155
515
|
isContractProcedure,
|
|
156
|
-
|
|
516
|
+
isDefinedError,
|
|
517
|
+
mergePrefix,
|
|
518
|
+
mergeRoute,
|
|
519
|
+
mergeTags,
|
|
520
|
+
oc,
|
|
521
|
+
prefixRoute,
|
|
522
|
+
safe,
|
|
523
|
+
type,
|
|
524
|
+
unshiftTagRoute,
|
|
525
|
+
validateORPCError
|
|
157
526
|
};
|
|
158
527
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
|
+
import type { ContractProcedureDef } from './procedure';
|
|
3
|
+
import type { HTTPPath, MergeRoute, Route, StrictRoute } from './route';
|
|
2
4
|
import type { ContractRouter } from './router';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
+
import type { AdaptedContractRouter } from './router-builder';
|
|
6
|
+
import type { Schema, SchemaInput, SchemaOutput } from './types';
|
|
7
|
+
import { ContractProcedure } from './procedure';
|
|
8
|
+
import { ContractProcedureBuilder } from './procedure-builder';
|
|
9
|
+
import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
|
|
10
|
+
import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
|
5
11
|
import { ContractRouterBuilder } from './router-builder';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
export interface ContractBuilderConfig {
|
|
13
|
+
initialRoute?: Route;
|
|
14
|
+
}
|
|
15
|
+
export type MergeContractBuilderConfig<A extends ContractBuilderConfig, B extends ContractBuilderConfig> = Omit<A, keyof B> & B;
|
|
16
|
+
export type GetInitialRoute<T extends ContractBuilderConfig> = T['initialRoute'] extends Route ? T['initialRoute'] : Record<never, never>;
|
|
17
|
+
export interface ContractBuilderDef<TConfig extends ContractBuilderConfig, TErrorMap extends ErrorMap> extends ContractProcedureDef<undefined, undefined, TErrorMap, StrictRoute<GetInitialRoute<TConfig>>> {
|
|
18
|
+
config: TConfig;
|
|
19
|
+
}
|
|
20
|
+
export declare class ContractBuilder<TConfig extends ContractBuilderConfig, TErrorMap extends ErrorMap> extends ContractProcedure<undefined, undefined, TErrorMap, GetInitialRoute<TConfig>> {
|
|
21
|
+
'~orpc': ContractBuilderDef<TConfig, TErrorMap>;
|
|
22
|
+
constructor(def: ContractBuilderDef<TConfig, TErrorMap>);
|
|
23
|
+
config<const U extends ContractBuilderConfig>(config: U): ContractBuilder<MergeContractBuilderConfig<TConfig, U>, TErrorMap>;
|
|
24
|
+
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractBuilder<TConfig, StrictErrorMap<U> & TErrorMap>;
|
|
25
|
+
route<const U extends Route>(route: U): ContractProcedureBuilder<TErrorMap, MergeRoute<StrictRoute<GetInitialRoute<TConfig>>, U>>;
|
|
26
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap, StrictRoute<GetInitialRoute<TConfig>>>;
|
|
27
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap, StrictRoute<GetInitialRoute<TConfig>>>;
|
|
28
|
+
prefix<U extends HTTPPath>(prefix: U): ContractRouterBuilder<TErrorMap, U, undefined>;
|
|
29
|
+
tag<U extends string[]>(...tags: U): ContractRouterBuilder<TErrorMap, undefined, U>;
|
|
30
|
+
router<T extends ContractRouter<ErrorMap & Partial<TErrorMap>>>(router: T): AdaptedContractRouter<T, TErrorMap, undefined, undefined>;
|
|
13
31
|
}
|
|
14
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,19 @@
|
|
|
1
|
+
import type { AbortSignal } from './types';
|
|
2
|
+
export type ClientOptions<TClientContext> = {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
} & (undefined extends TClientContext ? {
|
|
5
|
+
context?: TClientContext;
|
|
6
|
+
} : {
|
|
7
|
+
context: TClientContext;
|
|
8
|
+
});
|
|
9
|
+
export type ClientRest<TClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never);
|
|
10
|
+
export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
11
|
+
__typeError?: TError;
|
|
12
|
+
};
|
|
13
|
+
export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
|
|
14
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
15
|
+
}
|
|
16
|
+
export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
|
|
17
|
+
[k: string]: NestedClient<TClientContext>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HTTPMethod, InputStructure, Route } from './route';
|
|
2
|
+
export interface ContractConfig {
|
|
3
|
+
defaultMethod: HTTPMethod;
|
|
4
|
+
defaultSuccessStatus: number;
|
|
5
|
+
defaultSuccessDescription: string;
|
|
6
|
+
defaultInputStructure: InputStructure;
|
|
7
|
+
defaultOutputStructure: InputStructure;
|
|
8
|
+
defaultInitialRoute: Route;
|
|
9
|
+
}
|
|
10
|
+
export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
11
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CommonORPCErrorCode } from './error-orpc';
|
|
2
|
+
import type { Schema } from './types';
|
|
3
|
+
export type ErrorMapItem<TDataSchema extends Schema> = {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @default 500
|
|
7
|
+
*/
|
|
8
|
+
status?: number;
|
|
9
|
+
message?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
data?: TDataSchema;
|
|
12
|
+
};
|
|
13
|
+
export interface ErrorMap {
|
|
14
|
+
[k: string]: ErrorMapItem<Schema>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions
|
|
18
|
+
*
|
|
19
|
+
* Purpose:
|
|
20
|
+
* - Helps `U` suggest `CommonORPCErrorCode` to the user when typing.
|
|
21
|
+
*
|
|
22
|
+
* Why not replace `ErrorMap` with `ErrorMapSuggestions`?
|
|
23
|
+
* - `ErrorMapSuggestions` has a drawback: it allows `undefined` values for items.
|
|
24
|
+
* - `ErrorMapGuard<TErrorMap>` uses `Partial`, which can introduce `undefined` values.
|
|
25
|
+
*
|
|
26
|
+
* This could lead to unintended behavior where `undefined` values override `TErrorMap`,
|
|
27
|
+
* potentially resulting in a `never` type after merging.
|
|
28
|
+
*
|
|
29
|
+
* Recommendation:
|
|
30
|
+
* - Use `ErrorMapSuggestions` to assist users in typing correctly but do not replace `ErrorMap`.
|
|
31
|
+
* - Ensure `ErrorMapGuard<TErrorMap>` is adjusted to prevent `undefined` values.
|
|
32
|
+
*/
|
|
33
|
+
export type ErrorMapSuggestions = {
|
|
34
|
+
[key in CommonORPCErrorCode | (string & {})]?: ErrorMapItem<Schema>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* `U` extends `ErrorMap` & `ErrorMapGuard<TErrorMap>`
|
|
38
|
+
*
|
|
39
|
+
* `ErrorMapGuard` is a utility type that ensures `U` cannot redefine the structure of `TErrorMap`.
|
|
40
|
+
* It achieves this by setting each key in `TErrorMap` to `never`, effectively preventing any redefinition.
|
|
41
|
+
*
|
|
42
|
+
* Why not just use `Partial<TErrorMap>`?
|
|
43
|
+
* - Allowing users to redefine existing error map items would require using `StrictErrorMap`.
|
|
44
|
+
* - However, I prefer not to use `StrictErrorMap` frequently, due to perceived performance concerns,
|
|
45
|
+
* though this has not been benchmarked and is based on personal preference.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export type ErrorMapGuard<TErrorMap extends ErrorMap> = {
|
|
49
|
+
[K in keyof TErrorMap]?: never;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Since `undefined` has a specific meaning (it use default value),
|
|
53
|
+
* we ensure all additional properties in each item of the ErrorMap are explicitly set to `undefined`.
|
|
54
|
+
*/
|
|
55
|
+
export type StrictErrorMap<T extends ErrorMap> = {
|
|
56
|
+
[K in keyof T]: T[K] & Partial<Record<Exclude<keyof ErrorMapItem<any>, keyof T[K]>, undefined>>;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=error-map.d.ts.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ErrorMap, ErrorMapItem } from './error-map';
|
|
2
|
+
import type { SchemaOutput } from './types';
|
|
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 ORPCErrorOptions<TCode extends string, TData> = ErrorOptions & {
|
|
86
|
+
defined?: boolean;
|
|
87
|
+
code: TCode;
|
|
88
|
+
status?: number;
|
|
89
|
+
message?: string;
|
|
90
|
+
} & (undefined extends TData ? {
|
|
91
|
+
data?: TData;
|
|
92
|
+
} : {
|
|
93
|
+
data: TData;
|
|
94
|
+
});
|
|
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
|
+
readonly defined: boolean;
|
|
99
|
+
readonly code: TCode;
|
|
100
|
+
readonly status: number;
|
|
101
|
+
readonly data: TData;
|
|
102
|
+
constructor(options: ORPCErrorOptions<TCode, TData>);
|
|
103
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
104
|
+
static isValidJSON(json: unknown): json is ORPCErrorJSON<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
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
|
+
//# sourceMappingURL=error-orpc.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
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
2
|
import { ContractBuilder } from './builder';
|
|
3
3
|
export * from './builder';
|
|
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';
|
|
4
10
|
export * from './procedure';
|
|
11
|
+
export * from './procedure-builder';
|
|
12
|
+
export * from './procedure-builder-with-input';
|
|
13
|
+
export * from './procedure-builder-with-output';
|
|
14
|
+
export * from './procedure-client';
|
|
5
15
|
export * from './procedure-decorated';
|
|
16
|
+
export * from './route';
|
|
6
17
|
export * from './router';
|
|
7
18
|
export * from './router-builder';
|
|
19
|
+
export * from './router-client';
|
|
20
|
+
export * from './schema-utils';
|
|
8
21
|
export * from './types';
|
|
9
|
-
export declare const oc: ContractBuilder
|
|
22
|
+
export declare const oc: ContractBuilder<{}, {}>;
|
|
10
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
|
+
import type { HTTPPath, MergeRoute, PrefixRoute, Route, UnshiftTagRoute } from './route';
|
|
3
|
+
import type { Schema, SchemaOutput } from './types';
|
|
4
|
+
import { ContractProcedure } from './procedure';
|
|
5
|
+
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
6
|
+
/**
|
|
7
|
+
* `ContractProcedureBuilderWithInput` is a branch of `ContractProcedureBuilder` which it has input schema.
|
|
8
|
+
*
|
|
9
|
+
* Why?
|
|
10
|
+
* - prevents override input schema after .input
|
|
11
|
+
*/
|
|
12
|
+
export declare class ContractProcedureBuilderWithInput<TInputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> extends ContractProcedure<TInputSchema, undefined, TErrorMap, TRoute> {
|
|
13
|
+
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, StrictErrorMap<U> & TErrorMap, TRoute>;
|
|
14
|
+
route<const U extends Route>(route: U): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap, MergeRoute<TRoute, U>>;
|
|
15
|
+
prefix<U extends HTTPPath>(prefix: U): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap, PrefixRoute<TRoute, U>>;
|
|
16
|
+
unshiftTag<U extends string[]>(...tags: U): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap, UnshiftTagRoute<TRoute, U>>;
|
|
17
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U, TErrorMap, TRoute>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=procedure-builder-with-input.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
|
+
import type { HTTPPath, MergeRoute, PrefixRoute, Route, UnshiftTagRoute } from './route';
|
|
3
|
+
import type { Schema, SchemaInput } from './types';
|
|
4
|
+
import { ContractProcedure } from './procedure';
|
|
5
|
+
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
6
|
+
/**
|
|
7
|
+
* `ContractProcedureBuilderWithOutput` is a branch of `ContractProcedureBuilder` which it has output schema.
|
|
8
|
+
*
|
|
9
|
+
* Why?
|
|
10
|
+
* - prevents override output schema after .output
|
|
11
|
+
*/
|
|
12
|
+
export declare class ContractProcedureBuilderWithOutput<TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> extends ContractProcedure<undefined, TOutputSchema, TErrorMap, TRoute> {
|
|
13
|
+
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilderWithOutput<TOutputSchema, StrictErrorMap<U> & TErrorMap, TRoute>;
|
|
14
|
+
route<const U extends Route>(route: U): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap, MergeRoute<TRoute, U>>;
|
|
15
|
+
prefix<U extends HTTPPath>(prefix: U): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap, PrefixRoute<TRoute, U>>;
|
|
16
|
+
unshiftTag<U extends string[]>(...tags: U): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap, UnshiftTagRoute<TRoute, U>>;
|
|
17
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema, TErrorMap, TRoute>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=procedure-builder-with-output.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
|
+
import type { HTTPPath, MergeRoute, PrefixRoute, Route, UnshiftTagRoute } from './route';
|
|
3
|
+
import type { Schema, SchemaInput, SchemaOutput } from './types';
|
|
4
|
+
import { ContractProcedure } from './procedure';
|
|
5
|
+
import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
|
|
6
|
+
import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
|
7
|
+
export declare class ContractProcedureBuilder<TErrorMap extends ErrorMap, TRoute extends Route> extends ContractProcedure<undefined, undefined, TErrorMap, TRoute> {
|
|
8
|
+
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilder<StrictErrorMap<U> & TErrorMap, TRoute>;
|
|
9
|
+
route<const U extends Route>(route: U): ContractProcedureBuilder<TErrorMap, MergeRoute<TRoute, U>>;
|
|
10
|
+
prefix<U extends HTTPPath>(prefix: U): ContractProcedureBuilder<TErrorMap, PrefixRoute<TRoute, U>>;
|
|
11
|
+
unshiftTag<U extends string[]>(...tags: U): ContractProcedureBuilder<TErrorMap, UnshiftTagRoute<TRoute, U>>;
|
|
12
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap, TRoute>;
|
|
13
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap, TRoute>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=procedure-builder.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 './types';
|
|
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,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
|
+
import type { Schema } from './types';
|
|
3
3
|
import { ContractProcedure } from './procedure';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
import { type HTTPPath, type MergeRoute, type PrefixRoute, type Route, type UnshiftTagRoute } from './route';
|
|
5
|
+
export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TRoute> {
|
|
6
|
+
static decorate<UInputSchema extends Schema, UOutputSchema extends Schema, UErrorMap extends ErrorMap, URoute extends Route>(procedure: ContractProcedure<UInputSchema, UOutputSchema, UErrorMap, URoute>): DecoratedContractProcedure<UInputSchema, UOutputSchema, UErrorMap, URoute>;
|
|
7
|
+
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, StrictErrorMap<U> & TErrorMap, TRoute>;
|
|
8
|
+
route<const U extends Route>(route: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap, MergeRoute<TRoute, U>>;
|
|
9
|
+
prefix<U extends HTTPPath>(prefix: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap, PrefixRoute<TRoute, U>>;
|
|
10
|
+
unshiftTag<U extends string[]>(...tags: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap, UnshiftTagRoute<TRoute, U>>;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
description?: string;
|
|
7
|
-
deprecated?: boolean;
|
|
8
|
-
tags?: readonly string[];
|
|
9
|
-
successStatus?: number;
|
|
10
|
-
}
|
|
11
|
-
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
12
|
-
route?: RouteOptions;
|
|
1
|
+
import type { ErrorMap } from './error-map';
|
|
2
|
+
import type { Route } from './route';
|
|
3
|
+
import type { Schema, SchemaOutput } from './types';
|
|
4
|
+
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> {
|
|
5
|
+
route: TRoute;
|
|
13
6
|
InputSchema: TInputSchema;
|
|
14
7
|
inputExample?: SchemaOutput<TInputSchema>;
|
|
15
8
|
OutputSchema: TOutputSchema;
|
|
16
9
|
outputExample?: SchemaOutput<TOutputSchema>;
|
|
10
|
+
errorMap: TErrorMap;
|
|
17
11
|
}
|
|
18
|
-
export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
12
|
+
export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> {
|
|
19
13
|
'~type': "ContractProcedure";
|
|
20
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema>;
|
|
21
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema>);
|
|
14
|
+
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TRoute>;
|
|
15
|
+
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TRoute>);
|
|
22
16
|
}
|
|
23
|
-
export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any>;
|
|
24
|
-
export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
|
|
17
|
+
export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any, any, any>;
|
|
18
|
+
export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema, ErrorMap, Route>;
|
|
25
19
|
export declare function isContractProcedure(item: unknown): item is ANY_CONTRACT_PROCEDURE;
|
|
26
20
|
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
/**
|
|
70
|
+
* Since `undefined` has a specific meaning (it use default value),
|
|
71
|
+
* we ensure all additional properties in each item of the ErrorMap are explicitly set to `undefined`.
|
|
72
|
+
*/
|
|
73
|
+
export type StrictRoute<T extends Route> = T & Partial<Record<Exclude<keyof Route, keyof T>, undefined>>;
|
|
74
|
+
export type MergeRoute<A extends Route, B extends Route> = Omit<A, keyof B> & B;
|
|
75
|
+
export declare function mergeRoute<A extends Route, B extends Route>(a: A, b: B): MergeRoute<A, B>;
|
|
76
|
+
export type PrefixRoute<TRoute extends Route, TPrefix extends HTTPPath> = TRoute['path'] extends HTTPPath ? Omit<TRoute, 'path'> & {
|
|
77
|
+
path: TPrefix extends HTTPPath ? `${TPrefix}${TRoute['path']}` : TRoute['path'];
|
|
78
|
+
} : TRoute;
|
|
79
|
+
export declare function prefixRoute<TRoute extends Route, TPrefix extends HTTPPath>(route: TRoute, prefix: TPrefix): PrefixRoute<TRoute, TPrefix>;
|
|
80
|
+
export type UnshiftTagRoute<TRoute extends Route, TTags extends readonly string[]> = Omit<TRoute, 'tags'> & {
|
|
81
|
+
tags: TRoute['tags'] extends string[] ? [...TTags, ...TRoute['tags']] : TTags;
|
|
82
|
+
};
|
|
83
|
+
export declare function unshiftTagRoute<TRoute extends Route, TTags extends readonly string[]>(route: TRoute, tags: TTags): UnshiftTagRoute<TRoute, TTags>;
|
|
84
|
+
export type MergePrefix<A extends HTTPPath | undefined, B extends HTTPPath> = A extends HTTPPath ? `${A}${B}` : B;
|
|
85
|
+
export declare function mergePrefix<A extends HTTPPath | undefined, B extends HTTPPath>(a: A, b: B): MergePrefix<A, B>;
|
|
86
|
+
export type MergeTags<A extends readonly string[] | undefined, B extends readonly string[]> = A extends readonly string[] ? [...A, ...B] : B;
|
|
87
|
+
export declare function mergeTags<A extends readonly string[] | undefined, B extends readonly string[]>(a: A, b: B): MergeTags<A, B>;
|
|
88
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
1
2
|
import type { ContractProcedure } from './procedure';
|
|
2
3
|
import type { ContractRouter } from './router';
|
|
3
|
-
import type { HTTPPath } from './types';
|
|
4
4
|
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { type HTTPPath, type MergePrefix, type MergeTags, type PrefixRoute, type Route, type UnshiftTagRoute } from './route';
|
|
6
|
+
export type AdaptRoute<TRoute extends Route, TPrefix extends HTTPPath | undefined, TTags extends readonly string[] | undefined> = TPrefix extends HTTPPath ? PrefixRoute<TTags extends readonly string[] ? UnshiftTagRoute<TRoute, TTags> : TRoute, TPrefix> : TTags extends readonly string[] ? UnshiftTagRoute<TRoute, TTags> : TRoute;
|
|
7
|
+
export type AdaptedContractRouter<TContract extends ContractRouter<any>, TErrorMapExtra extends ErrorMap, TPrefix extends HTTPPath | undefined, TTags extends readonly string[] | undefined> = {
|
|
8
|
+
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer URoute> ? DecoratedContractProcedure<UInputSchema, UOutputSchema, UErrors & TErrorMapExtra, AdaptRoute<URoute, TPrefix, TTags>> : TContract[K] extends ContractRouter<any> ? AdaptedContractRouter<TContract[K], TErrorMapExtra, TPrefix, TTags> : never;
|
|
7
9
|
};
|
|
8
|
-
export interface ContractRouterBuilderDef {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export interface ContractRouterBuilderDef<TErrorMap extends ErrorMap, TPrefix extends HTTPPath | undefined, TTags extends readonly string[] | undefined> {
|
|
11
|
+
errorMap: TErrorMap;
|
|
12
|
+
prefix: TPrefix;
|
|
13
|
+
tags: TTags;
|
|
11
14
|
}
|
|
12
|
-
export declare class ContractRouterBuilder {
|
|
15
|
+
export declare class ContractRouterBuilder<TErrorMap extends ErrorMap, TPrefix extends HTTPPath | undefined, TTags extends readonly string[] | undefined> {
|
|
13
16
|
'~type': "ContractProcedure";
|
|
14
|
-
'~orpc': ContractRouterBuilderDef
|
|
15
|
-
constructor(def: ContractRouterBuilderDef);
|
|
16
|
-
prefix(prefix:
|
|
17
|
-
tag(...tags:
|
|
18
|
-
|
|
17
|
+
'~orpc': ContractRouterBuilderDef<TErrorMap, TPrefix, TTags>;
|
|
18
|
+
constructor(def: ContractRouterBuilderDef<TErrorMap, TPrefix, TTags>);
|
|
19
|
+
prefix<U extends HTTPPath>(prefix: U): ContractRouterBuilder<TErrorMap, MergePrefix<TPrefix, U>, TTags>;
|
|
20
|
+
tag<U extends string[]>(...tags: U): ContractRouterBuilder<TErrorMap, TPrefix, MergeTags<TTags, U>>;
|
|
21
|
+
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractRouterBuilder<StrictErrorMap<U> & TErrorMap, TPrefix, TTags>;
|
|
22
|
+
router<T extends ContractRouter<ErrorMap & Partial<TErrorMap>>>(router: T): AdaptedContractRouter<T, TErrorMap, TPrefix, TTags>;
|
|
19
23
|
}
|
|
20
24
|
//# sourceMappingURL=router-builder.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContractProcedure } from './procedure';
|
|
2
|
+
import type { ContractProcedureClient } from './procedure-client';
|
|
3
|
+
import type { ContractRouter } from './router';
|
|
4
|
+
export type ContractRouterClient<TRouter extends ContractRouter<any>, TClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
5
|
+
[K in keyof TRouter]: TRouter[K] extends ContractRouter<any> ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ErrorMap } from './error-map';
|
|
2
|
+
import type { ContractProcedure } from './procedure';
|
|
2
3
|
import type { SchemaInput, SchemaOutput } from './types';
|
|
3
|
-
export type ContractRouter =
|
|
4
|
-
[k: string]: ContractRouter
|
|
4
|
+
export type ContractRouter<T extends ErrorMap> = ContractProcedure<any, any, T, any> | {
|
|
5
|
+
[k: string]: ContractRouter<T>;
|
|
5
6
|
};
|
|
6
|
-
export type InferContractRouterInputs<T extends ContractRouter
|
|
7
|
-
[K in keyof T]: T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
7
|
+
export type InferContractRouterInputs<T extends ContractRouter<any>> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
|
|
8
|
+
[K in keyof T]: T[K] extends ContractRouter<any> ? InferContractRouterInputs<T[K]> : never;
|
|
8
9
|
};
|
|
9
|
-
export type InferContractRouterOutputs<T extends ContractRouter
|
|
10
|
-
[K in keyof T]: T[K] extends ContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
10
|
+
export type InferContractRouterOutputs<T extends ContractRouter<any>> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? SchemaOutput<UOutputSchema> : {
|
|
11
|
+
[K in keyof T]: T[K] extends ContractRouter<any> ? InferContractRouterOutputs<T[K]> : never;
|
|
11
12
|
};
|
|
12
13
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IsEqual, Promisable } from '@orpc/shared';
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
export type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
4
|
+
export declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): StandardSchemaV1<TInput, TOutput>;
|
|
5
|
+
//# sourceMappingURL=schema-utils.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { FindGlobalInstanceType } from '@orpc/shared';
|
|
1
2
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
export type HTTPPath = `/${string}`;
|
|
3
|
-
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
3
|
export type Schema = StandardSchemaV1 | undefined;
|
|
5
4
|
export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
|
|
6
5
|
export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
6
|
+
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
|
7
7
|
//# 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.
|
|
4
|
+
"version": "0.0.0-next.ed15210",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@standard-schema/spec": "1.0.0-beta.4",
|
|
33
|
-
"@orpc/shared": "0.0.0-next.
|
|
33
|
+
"@orpc/shared": "0.0.0-next.ed15210"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"arktype": "2.0.0-rc.26",
|