@orpc/contract 0.31.0 → 0.33.0
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 +156 -251
- package/dist/src/builder-variants.d.ts +38 -0
- package/dist/src/builder.d.ts +30 -20
- package/dist/src/client-utils.d.ts +1 -1
- package/dist/src/client.d.ts +3 -1
- package/dist/src/config.d.ts +8 -34
- package/dist/src/error-map.d.ts +6 -50
- package/dist/src/error-orpc.d.ts +10 -10
- package/dist/src/error-utils.d.ts +14 -0
- package/dist/src/index.d.ts +5 -8
- package/dist/src/meta.d.ts +3 -0
- package/dist/src/procedure-client.d.ts +1 -1
- package/dist/src/procedure.d.ts +13 -78
- package/dist/src/route.d.ts +79 -0
- package/dist/src/router-client.d.ts +3 -3
- package/dist/src/router.d.ts +25 -9
- package/dist/src/schema.d.ts +8 -0
- package/dist/src/types.d.ts +0 -8
- package/package.json +3 -3
- package/dist/src/procedure-builder-with-input.d.ts +0 -19
- package/dist/src/procedure-builder-with-output.d.ts +0 -19
- package/dist/src/procedure-builder.d.ts +0 -15
- package/dist/src/procedure-decorated.d.ts +0 -12
- package/dist/src/router-builder.d.ts +0 -23
- package/dist/src/schema-utils.d.ts +0 -5
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
|
|
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,249 +25,140 @@ 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 && "~
|
|
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/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
errors(errors) {
|
|
31
|
-
return new _DecoratedContractProcedure({
|
|
32
|
-
...this["~orpc"],
|
|
33
|
-
errorMap: {
|
|
34
|
-
...this["~orpc"].errorMap,
|
|
35
|
-
...errors
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
route(route) {
|
|
40
|
-
return new _DecoratedContractProcedure({
|
|
41
|
-
...this["~orpc"],
|
|
42
|
-
route: {
|
|
43
|
-
...this["~orpc"].route,
|
|
44
|
-
...route
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
prefix(prefix) {
|
|
49
|
-
return new _DecoratedContractProcedure({
|
|
50
|
-
...this["~orpc"],
|
|
51
|
-
...this["~orpc"].route?.path ? {
|
|
52
|
-
route: {
|
|
53
|
-
...this["~orpc"].route,
|
|
54
|
-
path: `${prefix}${this["~orpc"].route.path}`
|
|
55
|
-
}
|
|
56
|
-
} : void 0
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
unshiftTag(...tags) {
|
|
60
|
-
return new _DecoratedContractProcedure({
|
|
61
|
-
...this["~orpc"],
|
|
62
|
-
route: {
|
|
63
|
-
...this["~orpc"].route,
|
|
64
|
-
tags: [
|
|
65
|
-
...tags,
|
|
66
|
-
...this["~orpc"].route?.tags?.filter((tag) => !tags.includes(tag)) ?? []
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// src/procedure-builder-with-input.ts
|
|
74
|
-
var ContractProcedureBuilderWithInput = class _ContractProcedureBuilderWithInput extends ContractProcedure {
|
|
75
|
-
errors(errors) {
|
|
76
|
-
const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
|
|
77
|
-
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
78
|
-
}
|
|
79
|
-
route(route) {
|
|
80
|
-
const decorated = DecoratedContractProcedure.decorate(this).route(route);
|
|
81
|
-
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
82
|
-
}
|
|
83
|
-
prefix(prefix) {
|
|
84
|
-
const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
|
|
85
|
-
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
86
|
-
}
|
|
87
|
-
unshiftTag(...tags) {
|
|
88
|
-
const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
|
|
89
|
-
return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
|
|
90
|
-
}
|
|
91
|
-
output(schema, example) {
|
|
92
|
-
return new DecoratedContractProcedure({
|
|
93
|
-
...this["~orpc"],
|
|
94
|
-
OutputSchema: schema,
|
|
95
|
-
outputExample: example
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// src/procedure-builder-with-output.ts
|
|
101
|
-
var ContractProcedureBuilderWithOutput = class _ContractProcedureBuilderWithOutput extends ContractProcedure {
|
|
102
|
-
errors(errors) {
|
|
103
|
-
const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
|
|
104
|
-
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
105
|
-
}
|
|
106
|
-
route(route) {
|
|
107
|
-
const decorated = DecoratedContractProcedure.decorate(this).route(route);
|
|
108
|
-
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
109
|
-
}
|
|
110
|
-
prefix(prefix) {
|
|
111
|
-
const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
|
|
112
|
-
return new _ContractProcedureBuilderWithOutput(decorated["~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;
|
|
113
38
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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);
|
|
117
60
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
...this["~orpc"],
|
|
121
|
-
InputSchema: schema,
|
|
122
|
-
inputExample: example
|
|
123
|
-
});
|
|
61
|
+
if (options.tags) {
|
|
62
|
+
router = unshiftTagRoute(router, options.tags);
|
|
124
63
|
}
|
|
125
|
-
|
|
64
|
+
return router;
|
|
65
|
+
}
|
|
126
66
|
|
|
127
|
-
// src/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const decorated = DecoratedContractProcedure.decorate(this).route(route);
|
|
135
|
-
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
136
|
-
}
|
|
137
|
-
prefix(prefix) {
|
|
138
|
-
const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
|
|
139
|
-
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
140
|
-
}
|
|
141
|
-
unshiftTag(...tags) {
|
|
142
|
-
const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
|
|
143
|
-
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
144
|
-
}
|
|
145
|
-
input(schema, example) {
|
|
146
|
-
return new ContractProcedureBuilderWithInput({
|
|
147
|
-
...this["~orpc"],
|
|
148
|
-
InputSchema: schema,
|
|
149
|
-
inputExample: example
|
|
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)
|
|
150
74
|
});
|
|
75
|
+
return adapted2;
|
|
151
76
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
OutputSchema: schema,
|
|
156
|
-
outputExample: example
|
|
157
|
-
});
|
|
77
|
+
const adapted = {};
|
|
78
|
+
for (const key in contract) {
|
|
79
|
+
adapted[key] = adaptContractRouter(contract[key], options);
|
|
158
80
|
}
|
|
159
|
-
|
|
81
|
+
return adapted;
|
|
82
|
+
}
|
|
160
83
|
|
|
161
|
-
// src/
|
|
162
|
-
var
|
|
163
|
-
"~type" = "ContractProcedure";
|
|
164
|
-
"~orpc";
|
|
84
|
+
// src/builder.ts
|
|
85
|
+
var ContractBuilder = class _ContractBuilder extends ContractProcedure {
|
|
165
86
|
constructor(def) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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({
|
|
170
96
|
...this["~orpc"],
|
|
171
|
-
|
|
97
|
+
meta: initialMeta
|
|
172
98
|
});
|
|
173
99
|
}
|
|
174
|
-
|
|
175
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Reset initial route
|
|
102
|
+
*/
|
|
103
|
+
$route(initialRoute) {
|
|
104
|
+
return new _ContractBuilder({
|
|
176
105
|
...this["~orpc"],
|
|
177
|
-
|
|
106
|
+
route: initialRoute
|
|
178
107
|
});
|
|
179
108
|
}
|
|
180
109
|
errors(errors) {
|
|
181
|
-
return new
|
|
110
|
+
return new _ContractBuilder({
|
|
182
111
|
...this["~orpc"],
|
|
183
|
-
errorMap:
|
|
184
|
-
...this["~orpc"].errorMap,
|
|
185
|
-
...errors
|
|
186
|
-
}
|
|
112
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
187
113
|
});
|
|
188
114
|
}
|
|
189
|
-
|
|
190
|
-
if (isContractProcedure(router)) {
|
|
191
|
-
let decorated = DecoratedContractProcedure.decorate(router);
|
|
192
|
-
if (this["~orpc"].tags) {
|
|
193
|
-
decorated = decorated.unshiftTag(...this["~orpc"].tags);
|
|
194
|
-
}
|
|
195
|
-
if (this["~orpc"].prefix) {
|
|
196
|
-
decorated = decorated.prefix(this["~orpc"].prefix);
|
|
197
|
-
}
|
|
198
|
-
decorated = decorated.errors(this["~orpc"].errorMap);
|
|
199
|
-
return decorated;
|
|
200
|
-
}
|
|
201
|
-
const adapted = {};
|
|
202
|
-
for (const key in router) {
|
|
203
|
-
adapted[key] = this.router(router[key]);
|
|
204
|
-
}
|
|
205
|
-
return adapted;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// src/builder.ts
|
|
210
|
-
var ContractBuilder = class _ContractBuilder extends ContractProcedure {
|
|
211
|
-
errors(errors) {
|
|
115
|
+
meta(meta) {
|
|
212
116
|
return new _ContractBuilder({
|
|
213
117
|
...this["~orpc"],
|
|
214
|
-
|
|
215
|
-
...this["~orpc"].errorMap,
|
|
216
|
-
...errors
|
|
217
|
-
}
|
|
118
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
218
119
|
});
|
|
219
120
|
}
|
|
220
121
|
route(route) {
|
|
221
|
-
return new
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
OutputSchema: void 0,
|
|
225
|
-
errorMap: this["~orpc"].errorMap
|
|
122
|
+
return new _ContractBuilder({
|
|
123
|
+
...this["~orpc"],
|
|
124
|
+
route: mergeRoute(this["~orpc"].route, route)
|
|
226
125
|
});
|
|
227
126
|
}
|
|
228
|
-
input(schema
|
|
229
|
-
return new
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
OutputSchema: void 0,
|
|
233
|
-
errorMap: this["~orpc"].errorMap
|
|
127
|
+
input(schema) {
|
|
128
|
+
return new _ContractBuilder({
|
|
129
|
+
...this["~orpc"],
|
|
130
|
+
inputSchema: schema
|
|
234
131
|
});
|
|
235
132
|
}
|
|
236
|
-
output(schema
|
|
237
|
-
return new
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
InputSchema: void 0,
|
|
241
|
-
errorMap: this["~orpc"].errorMap
|
|
133
|
+
output(schema) {
|
|
134
|
+
return new _ContractBuilder({
|
|
135
|
+
...this["~orpc"],
|
|
136
|
+
outputSchema: schema
|
|
242
137
|
});
|
|
243
138
|
}
|
|
244
139
|
prefix(prefix) {
|
|
245
|
-
return new
|
|
246
|
-
|
|
247
|
-
|
|
140
|
+
return new _ContractBuilder({
|
|
141
|
+
...this["~orpc"],
|
|
142
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
248
143
|
});
|
|
249
144
|
}
|
|
250
145
|
tag(...tags) {
|
|
251
|
-
return new
|
|
252
|
-
|
|
253
|
-
|
|
146
|
+
return new _ContractBuilder({
|
|
147
|
+
...this["~orpc"],
|
|
148
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
|
254
149
|
});
|
|
255
150
|
}
|
|
256
151
|
router(router) {
|
|
257
|
-
return
|
|
258
|
-
errorMap: this["~orpc"].errorMap
|
|
259
|
-
}).router(router);
|
|
152
|
+
return adaptContractRouter(router, this["~orpc"]);
|
|
260
153
|
}
|
|
261
154
|
};
|
|
155
|
+
var oc = new ContractBuilder({
|
|
156
|
+
errorMap: {},
|
|
157
|
+
inputSchema: void 0,
|
|
158
|
+
outputSchema: void 0,
|
|
159
|
+
route: {},
|
|
160
|
+
meta: {}
|
|
161
|
+
});
|
|
262
162
|
|
|
263
163
|
// src/error-orpc.ts
|
|
264
164
|
import { isPlainObject } from "@orpc/shared";
|
|
@@ -346,21 +246,21 @@ function fallbackORPCErrorStatus(code, status) {
|
|
|
346
246
|
function fallbackORPCErrorMessage(code, message) {
|
|
347
247
|
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
348
248
|
}
|
|
349
|
-
var ORPCError = class extends Error {
|
|
249
|
+
var ORPCError = class _ORPCError extends Error {
|
|
350
250
|
defined;
|
|
351
251
|
code;
|
|
352
252
|
status;
|
|
353
253
|
data;
|
|
354
|
-
constructor(options) {
|
|
355
|
-
if (options
|
|
254
|
+
constructor(code, ...[options]) {
|
|
255
|
+
if (options?.status && (options.status < 400 || options.status >= 600)) {
|
|
356
256
|
throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
|
|
357
257
|
}
|
|
358
|
-
const message = fallbackORPCErrorMessage(
|
|
258
|
+
const message = fallbackORPCErrorMessage(code, options?.message);
|
|
359
259
|
super(message, options);
|
|
360
|
-
this.code =
|
|
361
|
-
this.status = fallbackORPCErrorStatus(
|
|
362
|
-
this.defined = options
|
|
363
|
-
this.data = options
|
|
260
|
+
this.code = code;
|
|
261
|
+
this.status = fallbackORPCErrorStatus(code, options?.status);
|
|
262
|
+
this.defined = options?.defined ?? false;
|
|
263
|
+
this.data = options?.data;
|
|
364
264
|
}
|
|
365
265
|
toJSON() {
|
|
366
266
|
return {
|
|
@@ -371,34 +271,53 @@ var ORPCError = class extends Error {
|
|
|
371
271
|
data: this.data
|
|
372
272
|
};
|
|
373
273
|
}
|
|
274
|
+
static fromJSON(json) {
|
|
275
|
+
return new _ORPCError(json.code, json);
|
|
276
|
+
}
|
|
374
277
|
static isValidJSON(json) {
|
|
375
278
|
return isPlainObject(json) && "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
|
|
376
279
|
}
|
|
377
280
|
};
|
|
281
|
+
|
|
282
|
+
// src/error-utils.ts
|
|
378
283
|
function isDefinedError(error) {
|
|
379
284
|
return error instanceof ORPCError && error.defined;
|
|
380
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
|
+
}
|
|
381
307
|
async function validateORPCError(map, error) {
|
|
382
308
|
const { code, status, message, data, cause, defined } = error;
|
|
383
309
|
const config = map?.[error.code];
|
|
384
310
|
if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
|
|
385
|
-
return defined ? new ORPCError({ defined: false,
|
|
311
|
+
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
386
312
|
}
|
|
387
313
|
if (!config.data) {
|
|
388
|
-
return defined ? error : new ORPCError({ defined: true,
|
|
314
|
+
return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
|
|
389
315
|
}
|
|
390
316
|
const validated = await config.data["~standard"].validate(error.data);
|
|
391
317
|
if (validated.issues) {
|
|
392
|
-
return defined ? new ORPCError({ defined: false,
|
|
318
|
+
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
393
319
|
}
|
|
394
|
-
return new ORPCError({
|
|
395
|
-
defined: true,
|
|
396
|
-
code,
|
|
397
|
-
status,
|
|
398
|
-
message,
|
|
399
|
-
data: validated.value,
|
|
400
|
-
cause
|
|
401
|
-
});
|
|
320
|
+
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
|
402
321
|
}
|
|
403
322
|
|
|
404
323
|
// src/client-utils.ts
|
|
@@ -423,20 +342,9 @@ var DEFAULT_CONFIG = {
|
|
|
423
342
|
defaultInputStructure: "compact",
|
|
424
343
|
defaultOutputStructure: "compact"
|
|
425
344
|
};
|
|
426
|
-
|
|
427
|
-
function configGlobal(config) {
|
|
428
|
-
if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
|
|
429
|
-
throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
|
|
430
|
-
}
|
|
431
|
-
GLOBAL_CONFIG_REF.value = config;
|
|
432
|
-
}
|
|
433
|
-
function fallbackToGlobalConfig(key, value) {
|
|
345
|
+
function fallbackContractConfig(key, value) {
|
|
434
346
|
if (value === void 0) {
|
|
435
|
-
|
|
436
|
-
if (fallback === void 0) {
|
|
437
|
-
return DEFAULT_CONFIG[key];
|
|
438
|
-
}
|
|
439
|
-
return fallback;
|
|
347
|
+
return DEFAULT_CONFIG[key];
|
|
440
348
|
}
|
|
441
349
|
return value;
|
|
442
350
|
}
|
|
@@ -450,7 +358,7 @@ var ValidationError = class extends Error {
|
|
|
450
358
|
}
|
|
451
359
|
};
|
|
452
360
|
|
|
453
|
-
// src/schema
|
|
361
|
+
// src/schema.ts
|
|
454
362
|
function type(...[map]) {
|
|
455
363
|
return {
|
|
456
364
|
"~standard": {
|
|
@@ -465,33 +373,30 @@ function type(...[map]) {
|
|
|
465
373
|
}
|
|
466
374
|
};
|
|
467
375
|
}
|
|
468
|
-
|
|
469
|
-
// src/index.ts
|
|
470
|
-
var oc = new ContractBuilder({
|
|
471
|
-
errorMap: {},
|
|
472
|
-
InputSchema: void 0,
|
|
473
|
-
OutputSchema: void 0
|
|
474
|
-
});
|
|
475
376
|
export {
|
|
476
377
|
COMMON_ORPC_ERROR_DEFS,
|
|
477
378
|
ContractBuilder,
|
|
478
379
|
ContractProcedure,
|
|
479
|
-
ContractProcedureBuilder,
|
|
480
|
-
ContractProcedureBuilderWithInput,
|
|
481
|
-
ContractProcedureBuilderWithOutput,
|
|
482
|
-
ContractRouterBuilder,
|
|
483
|
-
DecoratedContractProcedure,
|
|
484
380
|
ORPCError,
|
|
485
381
|
ValidationError,
|
|
486
|
-
|
|
382
|
+
adaptContractRouter,
|
|
383
|
+
adaptRoute,
|
|
384
|
+
createORPCErrorConstructorMap,
|
|
385
|
+
fallbackContractConfig,
|
|
487
386
|
fallbackORPCErrorMessage,
|
|
488
387
|
fallbackORPCErrorStatus,
|
|
489
|
-
fallbackToGlobalConfig,
|
|
490
388
|
isContractProcedure,
|
|
491
389
|
isDefinedError,
|
|
390
|
+
mergeErrorMap,
|
|
391
|
+
mergeMeta,
|
|
392
|
+
mergePrefix,
|
|
393
|
+
mergeRoute,
|
|
394
|
+
mergeTags,
|
|
492
395
|
oc,
|
|
396
|
+
prefixRoute,
|
|
493
397
|
safe,
|
|
494
398
|
type,
|
|
399
|
+
unshiftTagRoute,
|
|
495
400
|
validateORPCError
|
|
496
401
|
};
|
|
497
402
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ErrorMap, MergedErrorMap } from './error-map';
|
|
2
|
+
import type { Meta } from './meta';
|
|
3
|
+
import type { ContractProcedure } from './procedure';
|
|
4
|
+
import type { HTTPPath, Route } from './route';
|
|
5
|
+
import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
|
|
6
|
+
import type { Schema } from './schema';
|
|
7
|
+
export interface ContractProcedureBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
8
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
9
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
10
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
11
|
+
input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
12
|
+
output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
13
|
+
}
|
|
14
|
+
export interface ContractProcedureBuilderWithInput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
15
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
16
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
17
|
+
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
18
|
+
output<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
19
|
+
}
|
|
20
|
+
export interface ContractProcedureBuilderWithOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
21
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
22
|
+
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
23
|
+
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
24
|
+
input<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
25
|
+
}
|
|
26
|
+
export interface ContractProcedureBuilderWithInputOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
27
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
28
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
29
|
+
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
30
|
+
}
|
|
31
|
+
export interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
32
|
+
'~orpc': AdaptContractRouterOptions<TErrorMap>;
|
|
33
|
+
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
34
|
+
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
35
|
+
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
36
|
+
'router'<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=builder-variants.d.ts.map
|
package/dist/src/builder.d.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { AdaptedContractRouter } from './router
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
export type ContractBuilderDef<TErrorMap extends ErrorMap> = {
|
|
11
|
-
errorMap: TErrorMap;
|
|
12
|
-
};
|
|
13
|
-
export declare class ContractBuilder<TErrorMap extends ErrorMap> extends ContractProcedure<undefined, undefined, TErrorMap> {
|
|
14
|
-
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractBuilder<U & TErrorMap>;
|
|
15
|
-
route(route: RouteOptions): ContractProcedureBuilder<TErrorMap>;
|
|
16
|
-
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap>;
|
|
17
|
-
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap>;
|
|
18
|
-
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap>;
|
|
19
|
-
tag(...tags: string[]): ContractRouterBuilder<TErrorMap>;
|
|
20
|
-
router<T extends ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>(router: T): AdaptedContractRouter<T, TErrorMap>;
|
|
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> {
|
|
21
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, {}, {}>;
|
|
22
32
|
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientPromiseResult } from './client';
|
|
2
|
-
import {
|
|
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
|
package/dist/src/client.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export type ClientOptions<TClientContext> = {
|
|
|
8
8
|
});
|
|
9
9
|
export type ClientRest<TClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never);
|
|
10
10
|
export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
11
|
-
|
|
11
|
+
__error?: {
|
|
12
|
+
type: TError;
|
|
13
|
+
};
|
|
12
14
|
};
|
|
13
15
|
export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
|
|
14
16
|
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
import type { HTTPMethod, InputStructure } from './
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
package/dist/src/error-map.d.ts
CHANGED
|
@@ -1,58 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Schema } from './
|
|
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 500
|
|
7
|
-
*/
|
|
8
4
|
status?: number;
|
|
9
5
|
message?: string;
|
|
10
6
|
description?: string;
|
|
11
7
|
data?: TDataSchema;
|
|
12
8
|
};
|
|
13
|
-
export
|
|
14
|
-
[
|
|
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>>;
|
|
9
|
+
export type ErrorMap = {
|
|
10
|
+
[key in ORPCErrorCode]?: ErrorMapItem<Schema>;
|
|
57
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>;
|
|
58
14
|
//# sourceMappingURL=error-map.d.ts.map
|
package/dist/src/error-orpc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ErrorMap, ErrorMapItem } from './error-map';
|
|
2
|
-
import type { SchemaOutput } from './
|
|
2
|
+
import type { SchemaOutput } from './schema';
|
|
3
3
|
export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
4
4
|
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
|
|
5
5
|
}[keyof TErrorMap];
|
|
@@ -82,9 +82,11 @@ export declare const COMMON_ORPC_ERROR_DEFS: {
|
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
84
|
export type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
|
85
|
-
export type
|
|
85
|
+
export type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
|
86
|
+
export declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
|
87
|
+
export declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
|
88
|
+
export type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
86
89
|
defined?: boolean;
|
|
87
|
-
code: TCode;
|
|
88
90
|
status?: number;
|
|
89
91
|
message?: string;
|
|
90
92
|
} & (undefined extends TData ? {
|
|
@@ -92,18 +94,16 @@ export type ORPCErrorOptions<TCode extends string, TData> = ErrorOptions & {
|
|
|
92
94
|
} : {
|
|
93
95
|
data: TData;
|
|
94
96
|
});
|
|
95
|
-
export
|
|
96
|
-
export declare
|
|
97
|
-
export declare class ORPCError<TCode extends CommonORPCErrorCode | (string & {}), TData> extends Error {
|
|
97
|
+
export type ORPCErrorOptionsRest<TData> = [options: ORPCErrorOptions<TData>] | (undefined extends TData ? [] : never);
|
|
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(
|
|
103
|
+
constructor(code: TCode, ...[options]: ORPCErrorOptionsRest<TData>);
|
|
103
104
|
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
104
|
-
static
|
|
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,14 @@
|
|
|
1
|
+
import type { ErrorMap, ErrorMapItem } from './error-map';
|
|
2
|
+
import type { ORPCErrorCode, ORPCErrorOptions } from './error-orpc';
|
|
3
|
+
import type { SchemaInput } from './schema';
|
|
4
|
+
import { ORPCError } from './error-orpc';
|
|
5
|
+
export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
|
6
|
+
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
|
7
|
+
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
|
8
|
+
export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: ORPCErrorConstructorMapItemRest<TInData>) => ORPCError<TCode, TInData>;
|
|
9
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
10
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
|
11
|
+
};
|
|
12
|
+
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
13
|
+
export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
|
14
|
+
//# sourceMappingURL=error-utils.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
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
|
-
export * from './procedure-builder';
|
|
12
|
-
export * from './procedure-builder-with-input';
|
|
13
|
-
export * from './procedure-builder-with-output';
|
|
14
13
|
export * from './procedure-client';
|
|
15
|
-
export * from './
|
|
14
|
+
export * from './route';
|
|
16
15
|
export * from './router';
|
|
17
|
-
export * from './router-builder';
|
|
18
16
|
export * from './router-client';
|
|
19
|
-
export * from './schema
|
|
17
|
+
export * from './schema';
|
|
20
18
|
export * from './types';
|
|
21
|
-
export declare const oc: ContractBuilder<Record<never, never>>;
|
|
22
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Client } from './client';
|
|
2
2
|
import type { ErrorFromErrorMap } from './error';
|
|
3
3
|
import type { ErrorMap } from './error-map';
|
|
4
|
-
import type { Schema, SchemaInput, SchemaOutput } from './
|
|
4
|
+
import type { Schema, SchemaInput, SchemaOutput } from './schema';
|
|
5
5
|
export type ContractProcedureClient<TClientContext, 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
|
package/dist/src/procedure.d.ts
CHANGED
|
@@ -1,83 +1,18 @@
|
|
|
1
1
|
import type { ErrorMap } from './error-map';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
'~
|
|
77
|
-
|
|
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
|
|
81
|
-
export
|
|
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,7 @@
|
|
|
1
1
|
import type { ContractProcedure } from './procedure';
|
|
2
2
|
import type { ContractProcedureClient } from './procedure-client';
|
|
3
|
-
import type {
|
|
4
|
-
export type ContractRouterClient<TRouter extends
|
|
5
|
-
[K in keyof TRouter]: TRouter[K] extends
|
|
3
|
+
import type { AnyContractRouter } from './router';
|
|
4
|
+
export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
5
|
+
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
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>;
|
|
6
8
|
};
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
+
export type AnyContractRouter = ContractRouter<any>;
|
|
10
|
+
export type AdaptedContractRouter<TContract extends AnyContractRouter, TErrorMap extends ErrorMap> = {
|
|
11
|
+
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : TContract[K] extends AnyContractRouter ? AdaptedContractRouter<TContract[K], TErrorMap> : never;
|
|
9
12
|
};
|
|
10
|
-
export
|
|
11
|
-
|
|
13
|
+
export interface AdaptContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
14
|
+
errorMap: TErrorMap;
|
|
15
|
+
prefix?: HTTPPath;
|
|
16
|
+
tags?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
|
|
19
|
+
export type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
|
|
20
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
12
21
|
};
|
|
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;
|
|
13
29
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IsEqual, Promisable } from '@orpc/shared';
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
export type Schema = StandardSchemaV1 | undefined;
|
|
4
|
+
export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
|
|
5
|
+
export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
6
|
+
export type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
7
|
+
export declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): StandardSchemaV1<TInput, TOutput>;
|
|
8
|
+
//# sourceMappingURL=schema.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import type { FindGlobalInstanceType } from '@orpc/shared';
|
|
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
|
-
export type Schema = StandardSchemaV1 | undefined;
|
|
8
|
-
export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
|
|
9
|
-
export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
10
2
|
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
|
11
3
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@standard-schema/spec": "1.0.0-
|
|
33
|
-
"@orpc/shared": "0.
|
|
32
|
+
"@standard-schema/spec": "1.0.0-rc.0",
|
|
33
|
+
"@orpc/shared": "0.33.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"arktype": "2.0.0-rc.26",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
|
|
2
|
-
import type { RouteOptions } from './procedure';
|
|
3
|
-
import type { HTTPPath, 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> extends ContractProcedure<TInputSchema, undefined, TErrorMap> {
|
|
13
|
-
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap & U>;
|
|
14
|
-
route(route: RouteOptions): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap>;
|
|
15
|
-
prefix(prefix: HTTPPath): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap>;
|
|
16
|
-
unshiftTag(...tags: string[]): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap>;
|
|
17
|
-
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U, TErrorMap>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=procedure-builder-with-input.d.ts.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
|
|
2
|
-
import type { RouteOptions } from './procedure';
|
|
3
|
-
import type { HTTPPath, 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> extends ContractProcedure<undefined, TOutputSchema, TErrorMap> {
|
|
13
|
-
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap & U>;
|
|
14
|
-
route(route: RouteOptions): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
15
|
-
prefix(prefix: HTTPPath): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
16
|
-
unshiftTag(...tags: string[]): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
17
|
-
input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema, TErrorMap>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=procedure-builder-with-output.d.ts.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
|
|
2
|
-
import type { RouteOptions } from './procedure';
|
|
3
|
-
import type { HTTPPath, 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> extends ContractProcedure<undefined, undefined, TErrorMap> {
|
|
8
|
-
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilder<TErrorMap & U>;
|
|
9
|
-
route(route: RouteOptions): ContractProcedureBuilder<TErrorMap>;
|
|
10
|
-
prefix(prefix: HTTPPath): ContractProcedureBuilder<TErrorMap>;
|
|
11
|
-
unshiftTag(...tags: string[]): ContractProcedureBuilder<TErrorMap>;
|
|
12
|
-
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap>;
|
|
13
|
-
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=procedure-builder.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
|
|
2
|
-
import type { RouteOptions } from './procedure';
|
|
3
|
-
import type { HTTPPath, Schema } 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
|
-
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap & U>;
|
|
8
|
-
route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
|
9
|
-
prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
|
10
|
-
unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=procedure-decorated.d.ts.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
|
-
import type { ContractProcedure } from './procedure';
|
|
3
|
-
import type { ContractRouter } from './router';
|
|
4
|
-
import type { HTTPPath } from './types';
|
|
5
|
-
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
6
|
-
export type AdaptedContractRouter<TContract extends ContractRouter<any>, TErrorMapExtra extends ErrorMap> = {
|
|
7
|
-
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors> ? DecoratedContractProcedure<UInputSchema, UOutputSchema, UErrors & TErrorMapExtra> : TContract[K] extends ContractRouter<any> ? AdaptedContractRouter<TContract[K], TErrorMapExtra> : never;
|
|
8
|
-
};
|
|
9
|
-
export interface ContractRouterBuilderDef<TErrorMap extends ErrorMap> {
|
|
10
|
-
prefix?: HTTPPath;
|
|
11
|
-
tags?: string[];
|
|
12
|
-
errorMap: TErrorMap;
|
|
13
|
-
}
|
|
14
|
-
export declare class ContractRouterBuilder<TErrorMap extends ErrorMap> {
|
|
15
|
-
'~type': "ContractProcedure";
|
|
16
|
-
'~orpc': ContractRouterBuilderDef<TErrorMap>;
|
|
17
|
-
constructor(def: ContractRouterBuilderDef<TErrorMap>);
|
|
18
|
-
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap>;
|
|
19
|
-
tag(...tags: string[]): ContractRouterBuilder<TErrorMap>;
|
|
20
|
-
errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractRouterBuilder<U & TErrorMap>;
|
|
21
|
-
router<T extends ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>(router: T): AdaptedContractRouter<T, TErrorMap>;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=router-builder.d.ts.map
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|