@orpc/contract 0.0.0-next.3f6c426 → 0.0.0-next.43c0c87
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 +317 -22
- package/dist/src/builder.d.ts +17 -9
- package/dist/src/client-utils.d.ts +5 -0
- package/dist/src/client.d.ts +19 -0
- package/dist/src/config.d.ts +5 -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 +11 -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 +8 -8
- package/dist/src/procedure.d.ts +14 -6
- package/dist/src/router-builder.d.ts +12 -9
- package/dist/src/router-client.d.ts +7 -0
- package/dist/src/router.d.ts +8 -7
- package/dist/src/types.d.ts +2 -0
- 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,7 @@ 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"];
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
// src/procedure-decorated.ts
|
|
@@ -24,10 +27,22 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
|
|
|
24
27
|
}
|
|
25
28
|
return new _DecoratedContractProcedure(procedure["~orpc"]);
|
|
26
29
|
}
|
|
30
|
+
errors(errors) {
|
|
31
|
+
return new _DecoratedContractProcedure({
|
|
32
|
+
...this["~orpc"],
|
|
33
|
+
errorMap: {
|
|
34
|
+
...this["~orpc"].errorMap,
|
|
35
|
+
...errors
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
27
39
|
route(route) {
|
|
28
40
|
return new _DecoratedContractProcedure({
|
|
29
41
|
...this["~orpc"],
|
|
30
|
-
route
|
|
42
|
+
route: {
|
|
43
|
+
...this["~orpc"].route,
|
|
44
|
+
...route
|
|
45
|
+
}
|
|
31
46
|
});
|
|
32
47
|
}
|
|
33
48
|
prefix(prefix) {
|
|
@@ -53,15 +68,89 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
|
|
|
53
68
|
}
|
|
54
69
|
});
|
|
55
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"]);
|
|
113
|
+
}
|
|
114
|
+
unshiftTag(...tags) {
|
|
115
|
+
const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
|
|
116
|
+
return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
|
|
117
|
+
}
|
|
56
118
|
input(schema, example) {
|
|
57
|
-
return new
|
|
119
|
+
return new DecoratedContractProcedure({
|
|
120
|
+
...this["~orpc"],
|
|
121
|
+
InputSchema: schema,
|
|
122
|
+
inputExample: example
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/procedure-builder.ts
|
|
128
|
+
var ContractProcedureBuilder = class _ContractProcedureBuilder extends ContractProcedure {
|
|
129
|
+
errors(errors) {
|
|
130
|
+
const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
|
|
131
|
+
return new _ContractProcedureBuilder(decorated["~orpc"]);
|
|
132
|
+
}
|
|
133
|
+
route(route) {
|
|
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({
|
|
58
147
|
...this["~orpc"],
|
|
59
148
|
InputSchema: schema,
|
|
60
149
|
inputExample: example
|
|
61
150
|
});
|
|
62
151
|
}
|
|
63
152
|
output(schema, example) {
|
|
64
|
-
return new
|
|
153
|
+
return new ContractProcedureBuilderWithOutput({
|
|
65
154
|
...this["~orpc"],
|
|
66
155
|
OutputSchema: schema,
|
|
67
156
|
outputExample: example
|
|
@@ -88,6 +177,15 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
|
88
177
|
tags: [...this["~orpc"].tags ?? [], ...tags]
|
|
89
178
|
});
|
|
90
179
|
}
|
|
180
|
+
errors(errors) {
|
|
181
|
+
return new _ContractRouterBuilder({
|
|
182
|
+
...this["~orpc"],
|
|
183
|
+
errorMap: {
|
|
184
|
+
...this["~orpc"].errorMap,
|
|
185
|
+
...errors
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
91
189
|
router(router) {
|
|
92
190
|
if (isContractProcedure(router)) {
|
|
93
191
|
let decorated = DecoratedContractProcedure.decorate(router);
|
|
@@ -97,6 +195,7 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
|
97
195
|
if (this["~orpc"].prefix) {
|
|
98
196
|
decorated = decorated.prefix(this["~orpc"].prefix);
|
|
99
197
|
}
|
|
198
|
+
decorated = decorated.errors(this["~orpc"].errorMap);
|
|
100
199
|
return decorated;
|
|
101
200
|
}
|
|
102
201
|
const adapted = {};
|
|
@@ -108,47 +207,219 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
|
108
207
|
};
|
|
109
208
|
|
|
110
209
|
// src/builder.ts
|
|
111
|
-
var ContractBuilder = class {
|
|
112
|
-
|
|
113
|
-
return new
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
tags
|
|
210
|
+
var ContractBuilder = class _ContractBuilder extends ContractProcedure {
|
|
211
|
+
errors(errors) {
|
|
212
|
+
return new _ContractBuilder({
|
|
213
|
+
...this["~orpc"],
|
|
214
|
+
errorMap: {
|
|
215
|
+
...this["~orpc"].errorMap,
|
|
216
|
+
...errors
|
|
217
|
+
}
|
|
120
218
|
});
|
|
121
219
|
}
|
|
122
220
|
route(route) {
|
|
123
|
-
return new
|
|
221
|
+
return new ContractProcedureBuilder({
|
|
124
222
|
route,
|
|
125
223
|
InputSchema: void 0,
|
|
126
|
-
OutputSchema: void 0
|
|
224
|
+
OutputSchema: void 0,
|
|
225
|
+
errorMap: this["~orpc"].errorMap
|
|
127
226
|
});
|
|
128
227
|
}
|
|
129
228
|
input(schema, example) {
|
|
130
|
-
return new
|
|
229
|
+
return new ContractProcedureBuilderWithInput({
|
|
131
230
|
InputSchema: schema,
|
|
132
231
|
inputExample: example,
|
|
133
|
-
OutputSchema: void 0
|
|
232
|
+
OutputSchema: void 0,
|
|
233
|
+
errorMap: this["~orpc"].errorMap
|
|
134
234
|
});
|
|
135
235
|
}
|
|
136
236
|
output(schema, example) {
|
|
137
|
-
return new
|
|
237
|
+
return new ContractProcedureBuilderWithOutput({
|
|
138
238
|
OutputSchema: schema,
|
|
139
239
|
outputExample: example,
|
|
140
|
-
InputSchema: void 0
|
|
240
|
+
InputSchema: void 0,
|
|
241
|
+
errorMap: this["~orpc"].errorMap
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
prefix(prefix) {
|
|
245
|
+
return new ContractRouterBuilder({
|
|
246
|
+
prefix,
|
|
247
|
+
errorMap: this["~orpc"].errorMap
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
tag(...tags) {
|
|
251
|
+
return new ContractRouterBuilder({
|
|
252
|
+
tags,
|
|
253
|
+
errorMap: this["~orpc"].errorMap
|
|
141
254
|
});
|
|
142
255
|
}
|
|
143
256
|
router(router) {
|
|
144
|
-
return
|
|
257
|
+
return new ContractRouterBuilder({
|
|
258
|
+
errorMap: this["~orpc"].errorMap
|
|
259
|
+
}).router(router);
|
|
145
260
|
}
|
|
146
261
|
};
|
|
147
262
|
|
|
263
|
+
// src/error-orpc.ts
|
|
264
|
+
import { isPlainObject } from "@orpc/shared";
|
|
265
|
+
var COMMON_ORPC_ERROR_DEFS = {
|
|
266
|
+
BAD_REQUEST: {
|
|
267
|
+
status: 400,
|
|
268
|
+
message: "Bad Request"
|
|
269
|
+
},
|
|
270
|
+
UNAUTHORIZED: {
|
|
271
|
+
status: 401,
|
|
272
|
+
message: "Unauthorized"
|
|
273
|
+
},
|
|
274
|
+
FORBIDDEN: {
|
|
275
|
+
status: 403,
|
|
276
|
+
message: "Forbidden"
|
|
277
|
+
},
|
|
278
|
+
NOT_FOUND: {
|
|
279
|
+
status: 404,
|
|
280
|
+
message: "Not Found"
|
|
281
|
+
},
|
|
282
|
+
METHOD_NOT_SUPPORTED: {
|
|
283
|
+
status: 405,
|
|
284
|
+
message: "Method Not Supported"
|
|
285
|
+
},
|
|
286
|
+
NOT_ACCEPTABLE: {
|
|
287
|
+
status: 406,
|
|
288
|
+
message: "Not Acceptable"
|
|
289
|
+
},
|
|
290
|
+
TIMEOUT: {
|
|
291
|
+
status: 408,
|
|
292
|
+
message: "Request Timeout"
|
|
293
|
+
},
|
|
294
|
+
CONFLICT: {
|
|
295
|
+
status: 409,
|
|
296
|
+
message: "Conflict"
|
|
297
|
+
},
|
|
298
|
+
PRECONDITION_FAILED: {
|
|
299
|
+
status: 412,
|
|
300
|
+
message: "Precondition Failed"
|
|
301
|
+
},
|
|
302
|
+
PAYLOAD_TOO_LARGE: {
|
|
303
|
+
status: 413,
|
|
304
|
+
message: "Payload Too Large"
|
|
305
|
+
},
|
|
306
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
307
|
+
status: 415,
|
|
308
|
+
message: "Unsupported Media Type"
|
|
309
|
+
},
|
|
310
|
+
UNPROCESSABLE_CONTENT: {
|
|
311
|
+
status: 422,
|
|
312
|
+
message: "Unprocessable Content"
|
|
313
|
+
},
|
|
314
|
+
TOO_MANY_REQUESTS: {
|
|
315
|
+
status: 429,
|
|
316
|
+
message: "Too Many Requests"
|
|
317
|
+
},
|
|
318
|
+
CLIENT_CLOSED_REQUEST: {
|
|
319
|
+
status: 499,
|
|
320
|
+
message: "Client Closed Request"
|
|
321
|
+
},
|
|
322
|
+
INTERNAL_SERVER_ERROR: {
|
|
323
|
+
status: 500,
|
|
324
|
+
message: "Internal Server Error"
|
|
325
|
+
},
|
|
326
|
+
NOT_IMPLEMENTED: {
|
|
327
|
+
status: 501,
|
|
328
|
+
message: "Not Implemented"
|
|
329
|
+
},
|
|
330
|
+
BAD_GATEWAY: {
|
|
331
|
+
status: 502,
|
|
332
|
+
message: "Bad Gateway"
|
|
333
|
+
},
|
|
334
|
+
SERVICE_UNAVAILABLE: {
|
|
335
|
+
status: 503,
|
|
336
|
+
message: "Service Unavailable"
|
|
337
|
+
},
|
|
338
|
+
GATEWAY_TIMEOUT: {
|
|
339
|
+
status: 504,
|
|
340
|
+
message: "Gateway Timeout"
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
344
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
345
|
+
}
|
|
346
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
347
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
348
|
+
}
|
|
349
|
+
var ORPCError = class extends Error {
|
|
350
|
+
defined;
|
|
351
|
+
code;
|
|
352
|
+
status;
|
|
353
|
+
data;
|
|
354
|
+
constructor(options) {
|
|
355
|
+
if (options.status && (options.status < 400 || options.status >= 600)) {
|
|
356
|
+
throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
|
|
357
|
+
}
|
|
358
|
+
const message = fallbackORPCErrorMessage(options.code, options.message);
|
|
359
|
+
super(message, options);
|
|
360
|
+
this.code = options.code;
|
|
361
|
+
this.status = fallbackORPCErrorStatus(options.code, options.status);
|
|
362
|
+
this.defined = options.defined ?? false;
|
|
363
|
+
this.data = options.data;
|
|
364
|
+
}
|
|
365
|
+
toJSON() {
|
|
366
|
+
return {
|
|
367
|
+
defined: this.defined,
|
|
368
|
+
code: this.code,
|
|
369
|
+
status: this.status,
|
|
370
|
+
message: this.message,
|
|
371
|
+
data: this.data
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
static isValidJSON(json) {
|
|
375
|
+
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
|
+
}
|
|
377
|
+
};
|
|
378
|
+
function isDefinedError(error) {
|
|
379
|
+
return error instanceof ORPCError && error.defined;
|
|
380
|
+
}
|
|
381
|
+
async function validateORPCError(map, error) {
|
|
382
|
+
const { code, status, message, data, cause, defined } = error;
|
|
383
|
+
const config = map?.[error.code];
|
|
384
|
+
if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
|
|
385
|
+
return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
|
|
386
|
+
}
|
|
387
|
+
if (!config.data) {
|
|
388
|
+
return defined ? error : new ORPCError({ defined: true, code, status, message, data, cause });
|
|
389
|
+
}
|
|
390
|
+
const validated = await config.data["~standard"].validate(error.data);
|
|
391
|
+
if (validated.issues) {
|
|
392
|
+
return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
|
|
393
|
+
}
|
|
394
|
+
return new ORPCError({
|
|
395
|
+
defined: true,
|
|
396
|
+
code,
|
|
397
|
+
status,
|
|
398
|
+
message,
|
|
399
|
+
data: validated.value,
|
|
400
|
+
cause
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/client-utils.ts
|
|
405
|
+
async function safe(promise) {
|
|
406
|
+
try {
|
|
407
|
+
const output = await promise;
|
|
408
|
+
return [output, void 0, false];
|
|
409
|
+
} catch (e) {
|
|
410
|
+
const error = e;
|
|
411
|
+
if (isDefinedError(error)) {
|
|
412
|
+
return [void 0, error, true];
|
|
413
|
+
}
|
|
414
|
+
return [void 0, error, false];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
148
418
|
// src/config.ts
|
|
149
419
|
var DEFAULT_CONFIG = {
|
|
150
420
|
defaultMethod: "POST",
|
|
151
421
|
defaultSuccessStatus: 200,
|
|
422
|
+
defaultSuccessDescription: "OK",
|
|
152
423
|
defaultInputStructure: "compact",
|
|
153
424
|
defaultOutputStructure: "compact"
|
|
154
425
|
};
|
|
@@ -170,16 +441,40 @@ function fallbackToGlobalConfig(key, value) {
|
|
|
170
441
|
return value;
|
|
171
442
|
}
|
|
172
443
|
|
|
444
|
+
// src/error.ts
|
|
445
|
+
var ValidationError = class extends Error {
|
|
446
|
+
issues;
|
|
447
|
+
constructor(options) {
|
|
448
|
+
super(options.message, options);
|
|
449
|
+
this.issues = options.issues;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
173
453
|
// src/index.ts
|
|
174
|
-
var oc = new ContractBuilder(
|
|
454
|
+
var oc = new ContractBuilder({
|
|
455
|
+
errorMap: {},
|
|
456
|
+
InputSchema: void 0,
|
|
457
|
+
OutputSchema: void 0
|
|
458
|
+
});
|
|
175
459
|
export {
|
|
460
|
+
COMMON_ORPC_ERROR_DEFS,
|
|
176
461
|
ContractBuilder,
|
|
177
462
|
ContractProcedure,
|
|
463
|
+
ContractProcedureBuilder,
|
|
464
|
+
ContractProcedureBuilderWithInput,
|
|
465
|
+
ContractProcedureBuilderWithOutput,
|
|
178
466
|
ContractRouterBuilder,
|
|
179
467
|
DecoratedContractProcedure,
|
|
468
|
+
ORPCError,
|
|
469
|
+
ValidationError,
|
|
180
470
|
configGlobal,
|
|
471
|
+
fallbackORPCErrorMessage,
|
|
472
|
+
fallbackORPCErrorStatus,
|
|
181
473
|
fallbackToGlobalConfig,
|
|
182
474
|
isContractProcedure,
|
|
183
|
-
|
|
475
|
+
isDefinedError,
|
|
476
|
+
oc,
|
|
477
|
+
safe,
|
|
478
|
+
validateORPCError
|
|
184
479
|
};
|
|
185
480
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
|
|
2
2
|
import type { ContractRouter } from './router';
|
|
3
|
+
import type { AdaptedContractRouter } from './router-builder';
|
|
3
4
|
import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
|
|
4
|
-
import {
|
|
5
|
+
import { ContractProcedure, type RouteOptions } from './procedure';
|
|
6
|
+
import { ContractProcedureBuilder } from './procedure-builder';
|
|
7
|
+
import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
|
|
8
|
+
import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
|
5
9
|
import { ContractRouterBuilder } from './router-builder';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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>;
|
|
13
21
|
}
|
|
14
22
|
//# 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
|
package/dist/src/config.d.ts
CHANGED
|
@@ -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,11 +1,21 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
2
|
import { ContractBuilder } from './builder';
|
|
3
3
|
export * from './builder';
|
|
4
|
+
export * from './client';
|
|
5
|
+
export * from './client-utils';
|
|
4
6
|
export * from './config';
|
|
7
|
+
export * from './error';
|
|
8
|
+
export * from './error-map';
|
|
9
|
+
export * from './error-orpc';
|
|
5
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';
|
|
6
15
|
export * from './procedure-decorated';
|
|
7
16
|
export * from './router';
|
|
8
17
|
export * from './router-builder';
|
|
18
|
+
export * from './router-client';
|
|
9
19
|
export * from './types';
|
|
10
|
-
export declare const oc: ContractBuilder
|
|
20
|
+
export declare const oc: ContractBuilder<Record<never, never>>;
|
|
11
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -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 { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
|
|
1
2
|
import type { RouteOptions } from './procedure';
|
|
2
|
-
import type { HTTPPath, Schema
|
|
3
|
+
import type { HTTPPath, Schema } from './types';
|
|
3
4
|
import { ContractProcedure } from './procedure';
|
|
4
|
-
export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> extends ContractProcedure<TInputSchema, TOutputSchema> {
|
|
5
|
-
static decorate<UInputSchema extends Schema
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U>;
|
|
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
11
|
}
|
|
12
12
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ErrorMap } from './error-map';
|
|
1
2
|
import type { HTTPMethod, HTTPPath, InputStructure, OutputStructure, Schema, SchemaOutput } from './types';
|
|
2
3
|
export interface RouteOptions {
|
|
3
4
|
method?: HTTPMethod;
|
|
@@ -12,6 +13,12 @@ export interface RouteOptions {
|
|
|
12
13
|
* @default 200
|
|
13
14
|
*/
|
|
14
15
|
successStatus?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The description of the response when the procedure is successful.
|
|
18
|
+
*
|
|
19
|
+
* @default 'OK'
|
|
20
|
+
*/
|
|
21
|
+
successDescription?: string;
|
|
15
22
|
/**
|
|
16
23
|
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
17
24
|
*
|
|
@@ -57,19 +64,20 @@ export interface RouteOptions {
|
|
|
57
64
|
*/
|
|
58
65
|
outputStructure?: OutputStructure;
|
|
59
66
|
}
|
|
60
|
-
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
67
|
+
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
|
61
68
|
route?: RouteOptions;
|
|
62
69
|
InputSchema: TInputSchema;
|
|
63
70
|
inputExample?: SchemaOutput<TInputSchema>;
|
|
64
71
|
OutputSchema: TOutputSchema;
|
|
65
72
|
outputExample?: SchemaOutput<TOutputSchema>;
|
|
73
|
+
errorMap: TErrorMap;
|
|
66
74
|
}
|
|
67
|
-
export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
75
|
+
export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
|
68
76
|
'~type': "ContractProcedure";
|
|
69
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema>;
|
|
70
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema>);
|
|
77
|
+
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap>;
|
|
78
|
+
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap>);
|
|
71
79
|
}
|
|
72
|
-
export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any>;
|
|
73
|
-
export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
|
|
80
|
+
export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any, any>;
|
|
81
|
+
export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema, ErrorMap>;
|
|
74
82
|
export declare function isContractProcedure(item: unknown): item is ANY_CONTRACT_PROCEDURE;
|
|
75
83
|
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -1,20 +1,23 @@
|
|
|
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
4
|
import type { HTTPPath } from './types';
|
|
4
5
|
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
5
|
-
export type AdaptedContractRouter<TContract extends ContractRouter> = {
|
|
6
|
-
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? DecoratedContractProcedure<UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? AdaptedContractRouter<TContract[K]> : never;
|
|
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;
|
|
7
8
|
};
|
|
8
|
-
export interface ContractRouterBuilderDef {
|
|
9
|
+
export interface ContractRouterBuilderDef<TErrorMap extends ErrorMap> {
|
|
9
10
|
prefix?: HTTPPath;
|
|
10
11
|
tags?: string[];
|
|
12
|
+
errorMap: TErrorMap;
|
|
11
13
|
}
|
|
12
|
-
export declare class ContractRouterBuilder {
|
|
14
|
+
export declare class ContractRouterBuilder<TErrorMap extends ErrorMap> {
|
|
13
15
|
'~type': "ContractProcedure";
|
|
14
|
-
'~orpc': ContractRouterBuilderDef
|
|
15
|
-
constructor(def: ContractRouterBuilderDef);
|
|
16
|
-
prefix(prefix: HTTPPath): ContractRouterBuilder
|
|
17
|
-
tag(...tags: string[]): ContractRouterBuilder
|
|
18
|
-
|
|
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>;
|
|
19
22
|
}
|
|
20
23
|
//# 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> ? 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> | {
|
|
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> ? 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> ? 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
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FindGlobalInstanceType } from '@orpc/shared';
|
|
1
2
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
3
|
export type HTTPPath = `/${string}`;
|
|
3
4
|
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
@@ -6,4 +7,5 @@ export type OutputStructure = 'compact' | 'detailed';
|
|
|
6
7
|
export type Schema = StandardSchemaV1 | undefined;
|
|
7
8
|
export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
|
|
8
9
|
export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
10
|
+
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
|
9
11
|
//# 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.43c0c87",
|
|
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.43c0c87"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"arktype": "2.0.0-rc.26",
|