@orpc/contract 0.0.0-next.f56d2b3 → 0.0.0-next.f677f1d
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/README.md +114 -0
- package/dist/index.d.mts +307 -0
- package/dist/index.d.ts +307 -0
- package/dist/index.mjs +326 -0
- package/dist/plugins/index.d.mts +43 -0
- package/dist/plugins/index.d.ts +43 -0
- package/dist/plugins/index.mjs +81 -0
- package/dist/shared/contract.CvRxURhn.d.mts +254 -0
- package/dist/shared/contract.CvRxURhn.d.ts +254 -0
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/package.json +16 -14
- package/dist/index.js +0 -402
- package/dist/src/builder-variants.d.ts +0 -38
- package/dist/src/builder.d.ts +0 -32
- package/dist/src/client-utils.d.ts +0 -5
- package/dist/src/client.d.ts +0 -21
- package/dist/src/config.d.ts +0 -10
- package/dist/src/error-map.d.ts +0 -14
- package/dist/src/error-orpc.d.ts +0 -109
- package/dist/src/error-utils.d.ts +0 -14
- package/dist/src/error.d.ts +0 -13
- package/dist/src/index.d.ts +0 -19
- package/dist/src/meta.d.ts +0 -3
- package/dist/src/procedure-client.d.ts +0 -6
- package/dist/src/procedure.d.ts +0 -18
- package/dist/src/route.d.ts +0 -79
- package/dist/src/router-client.d.ts +0 -7
- package/dist/src/router.d.ts +0 -29
- package/dist/src/schema.d.ts +0 -8
- package/dist/src/types.d.ts +0 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { fallbackORPCErrorStatus, ORPCError, isORPCErrorStatus } from '@orpc/client';
|
|
2
|
+
|
|
3
|
+
class ValidationError extends Error {
|
|
4
|
+
issues;
|
|
5
|
+
data;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options.message, options);
|
|
8
|
+
this.issues = options.issues;
|
|
9
|
+
this.data = options.data;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function mergeErrorMap(errorMap1, errorMap2) {
|
|
13
|
+
return { ...errorMap1, ...errorMap2 };
|
|
14
|
+
}
|
|
15
|
+
async function validateORPCError(map, error) {
|
|
16
|
+
const { code, status, message, data, cause, defined } = error;
|
|
17
|
+
const config = map?.[error.code];
|
|
18
|
+
if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
|
|
19
|
+
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
20
|
+
}
|
|
21
|
+
if (!config.data) {
|
|
22
|
+
return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
|
|
23
|
+
}
|
|
24
|
+
const validated = await config.data["~standard"].validate(error.data);
|
|
25
|
+
if (validated.issues) {
|
|
26
|
+
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
27
|
+
}
|
|
28
|
+
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class ContractProcedure {
|
|
32
|
+
/**
|
|
33
|
+
* This property holds the defined options for the contract procedure.
|
|
34
|
+
*/
|
|
35
|
+
"~orpc";
|
|
36
|
+
constructor(def) {
|
|
37
|
+
if (def.route?.successStatus && isORPCErrorStatus(def.route.successStatus)) {
|
|
38
|
+
throw new Error("[ContractProcedure] Invalid successStatus.");
|
|
39
|
+
}
|
|
40
|
+
if (Object.values(def.errorMap).some((val) => val && val.status && !isORPCErrorStatus(val.status))) {
|
|
41
|
+
throw new Error("[ContractProcedure] Invalid error status code.");
|
|
42
|
+
}
|
|
43
|
+
this["~orpc"] = def;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function isContractProcedure(item) {
|
|
47
|
+
if (item instanceof ContractProcedure) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "errorMap" in item["~orpc"] && "route" in item["~orpc"] && "meta" in item["~orpc"];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { ContractProcedure as C, ValidationError as V, isContractProcedure as i, mergeErrorMap as m, validateORPCError as v };
|
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.f677f1d",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,30 +15,32 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
-
"
|
|
23
|
-
"types": "./dist/
|
|
22
|
+
"./plugins": {
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
24
26
|
}
|
|
25
27
|
},
|
|
26
28
|
"files": [
|
|
27
|
-
"!**/*.map",
|
|
28
|
-
"!**/*.tsbuildinfo",
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@standard-schema/spec": "1.0.0
|
|
33
|
-
"
|
|
32
|
+
"@standard-schema/spec": "^1.0.0",
|
|
33
|
+
"openapi-types": "^12.1.3",
|
|
34
|
+
"@orpc/shared": "0.0.0-next.f677f1d",
|
|
35
|
+
"@orpc/client": "0.0.0-next.f677f1d"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"arktype": "2.
|
|
37
|
-
"valibot": "1.
|
|
38
|
-
"zod": "
|
|
38
|
+
"arktype": "2.1.22",
|
|
39
|
+
"valibot": "^1.1.0",
|
|
40
|
+
"zod": "^4.1.11"
|
|
39
41
|
},
|
|
40
42
|
"scripts": {
|
|
41
|
-
"build": "
|
|
43
|
+
"build": "unbuild",
|
|
42
44
|
"build:watch": "pnpm run build --watch",
|
|
43
45
|
"type:check": "tsc -b"
|
|
44
46
|
}
|
package/dist/index.js
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
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
|
-
|
|
11
|
-
// src/procedure.ts
|
|
12
|
-
var ContractProcedure = class {
|
|
13
|
-
"~orpc";
|
|
14
|
-
constructor(def) {
|
|
15
|
-
if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
|
|
16
|
-
throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
|
|
17
|
-
}
|
|
18
|
-
if (Object.values(def.errorMap).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
|
|
19
|
-
throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
|
|
20
|
-
}
|
|
21
|
-
this["~orpc"] = def;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
function isContractProcedure(item) {
|
|
25
|
-
if (item instanceof ContractProcedure) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
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"];
|
|
29
|
-
}
|
|
30
|
-
|
|
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;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...route,
|
|
41
|
-
path: `${prefix}${route.path}`
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function unshiftTagRoute(route, tags) {
|
|
45
|
-
return {
|
|
46
|
-
...route,
|
|
47
|
-
tags: [...tags, ...route.tags ?? []]
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function mergePrefix(a, b) {
|
|
51
|
-
return a ? `${a}${b}` : b;
|
|
52
|
-
}
|
|
53
|
-
function mergeTags(a, b) {
|
|
54
|
-
return a ? [...a, ...b] : b;
|
|
55
|
-
}
|
|
56
|
-
function adaptRoute(route, options) {
|
|
57
|
-
let router = route;
|
|
58
|
-
if (options.prefix) {
|
|
59
|
-
router = prefixRoute(router, options.prefix);
|
|
60
|
-
}
|
|
61
|
-
if (options.tags) {
|
|
62
|
-
router = unshiftTagRoute(router, options.tags);
|
|
63
|
-
}
|
|
64
|
-
return router;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/router.ts
|
|
68
|
-
function adaptContractRouter(contract, options) {
|
|
69
|
-
if (isContractProcedure(contract)) {
|
|
70
|
-
const adapted2 = new ContractProcedure({
|
|
71
|
-
...contract["~orpc"],
|
|
72
|
-
errorMap: mergeErrorMap(options.errorMap, contract["~orpc"].errorMap),
|
|
73
|
-
route: adaptRoute(contract["~orpc"].route, options)
|
|
74
|
-
});
|
|
75
|
-
return adapted2;
|
|
76
|
-
}
|
|
77
|
-
const adapted = {};
|
|
78
|
-
for (const key in contract) {
|
|
79
|
-
adapted[key] = adaptContractRouter(contract[key], options);
|
|
80
|
-
}
|
|
81
|
-
return adapted;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/builder.ts
|
|
85
|
-
var ContractBuilder = class _ContractBuilder extends ContractProcedure {
|
|
86
|
-
constructor(def) {
|
|
87
|
-
super(def);
|
|
88
|
-
this["~orpc"].prefix = def.prefix;
|
|
89
|
-
this["~orpc"].tags = def.tags;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Reset initial meta
|
|
93
|
-
*/
|
|
94
|
-
$meta(initialMeta) {
|
|
95
|
-
return new _ContractBuilder({
|
|
96
|
-
...this["~orpc"],
|
|
97
|
-
meta: initialMeta
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Reset initial route
|
|
102
|
-
*/
|
|
103
|
-
$route(initialRoute) {
|
|
104
|
-
return new _ContractBuilder({
|
|
105
|
-
...this["~orpc"],
|
|
106
|
-
route: initialRoute
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
errors(errors) {
|
|
110
|
-
return new _ContractBuilder({
|
|
111
|
-
...this["~orpc"],
|
|
112
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
meta(meta) {
|
|
116
|
-
return new _ContractBuilder({
|
|
117
|
-
...this["~orpc"],
|
|
118
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
route(route) {
|
|
122
|
-
return new _ContractBuilder({
|
|
123
|
-
...this["~orpc"],
|
|
124
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
input(schema) {
|
|
128
|
-
return new _ContractBuilder({
|
|
129
|
-
...this["~orpc"],
|
|
130
|
-
inputSchema: schema
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
output(schema) {
|
|
134
|
-
return new _ContractBuilder({
|
|
135
|
-
...this["~orpc"],
|
|
136
|
-
outputSchema: schema
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
prefix(prefix) {
|
|
140
|
-
return new _ContractBuilder({
|
|
141
|
-
...this["~orpc"],
|
|
142
|
-
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
tag(...tags) {
|
|
146
|
-
return new _ContractBuilder({
|
|
147
|
-
...this["~orpc"],
|
|
148
|
-
tags: mergeTags(this["~orpc"].tags, tags)
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
router(router) {
|
|
152
|
-
return adaptContractRouter(router, this["~orpc"]);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
var oc = new ContractBuilder({
|
|
156
|
-
errorMap: {},
|
|
157
|
-
inputSchema: void 0,
|
|
158
|
-
outputSchema: void 0,
|
|
159
|
-
route: {},
|
|
160
|
-
meta: {}
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// src/error-orpc.ts
|
|
164
|
-
import { isPlainObject } from "@orpc/shared";
|
|
165
|
-
var COMMON_ORPC_ERROR_DEFS = {
|
|
166
|
-
BAD_REQUEST: {
|
|
167
|
-
status: 400,
|
|
168
|
-
message: "Bad Request"
|
|
169
|
-
},
|
|
170
|
-
UNAUTHORIZED: {
|
|
171
|
-
status: 401,
|
|
172
|
-
message: "Unauthorized"
|
|
173
|
-
},
|
|
174
|
-
FORBIDDEN: {
|
|
175
|
-
status: 403,
|
|
176
|
-
message: "Forbidden"
|
|
177
|
-
},
|
|
178
|
-
NOT_FOUND: {
|
|
179
|
-
status: 404,
|
|
180
|
-
message: "Not Found"
|
|
181
|
-
},
|
|
182
|
-
METHOD_NOT_SUPPORTED: {
|
|
183
|
-
status: 405,
|
|
184
|
-
message: "Method Not Supported"
|
|
185
|
-
},
|
|
186
|
-
NOT_ACCEPTABLE: {
|
|
187
|
-
status: 406,
|
|
188
|
-
message: "Not Acceptable"
|
|
189
|
-
},
|
|
190
|
-
TIMEOUT: {
|
|
191
|
-
status: 408,
|
|
192
|
-
message: "Request Timeout"
|
|
193
|
-
},
|
|
194
|
-
CONFLICT: {
|
|
195
|
-
status: 409,
|
|
196
|
-
message: "Conflict"
|
|
197
|
-
},
|
|
198
|
-
PRECONDITION_FAILED: {
|
|
199
|
-
status: 412,
|
|
200
|
-
message: "Precondition Failed"
|
|
201
|
-
},
|
|
202
|
-
PAYLOAD_TOO_LARGE: {
|
|
203
|
-
status: 413,
|
|
204
|
-
message: "Payload Too Large"
|
|
205
|
-
},
|
|
206
|
-
UNSUPPORTED_MEDIA_TYPE: {
|
|
207
|
-
status: 415,
|
|
208
|
-
message: "Unsupported Media Type"
|
|
209
|
-
},
|
|
210
|
-
UNPROCESSABLE_CONTENT: {
|
|
211
|
-
status: 422,
|
|
212
|
-
message: "Unprocessable Content"
|
|
213
|
-
},
|
|
214
|
-
TOO_MANY_REQUESTS: {
|
|
215
|
-
status: 429,
|
|
216
|
-
message: "Too Many Requests"
|
|
217
|
-
},
|
|
218
|
-
CLIENT_CLOSED_REQUEST: {
|
|
219
|
-
status: 499,
|
|
220
|
-
message: "Client Closed Request"
|
|
221
|
-
},
|
|
222
|
-
INTERNAL_SERVER_ERROR: {
|
|
223
|
-
status: 500,
|
|
224
|
-
message: "Internal Server Error"
|
|
225
|
-
},
|
|
226
|
-
NOT_IMPLEMENTED: {
|
|
227
|
-
status: 501,
|
|
228
|
-
message: "Not Implemented"
|
|
229
|
-
},
|
|
230
|
-
BAD_GATEWAY: {
|
|
231
|
-
status: 502,
|
|
232
|
-
message: "Bad Gateway"
|
|
233
|
-
},
|
|
234
|
-
SERVICE_UNAVAILABLE: {
|
|
235
|
-
status: 503,
|
|
236
|
-
message: "Service Unavailable"
|
|
237
|
-
},
|
|
238
|
-
GATEWAY_TIMEOUT: {
|
|
239
|
-
status: 504,
|
|
240
|
-
message: "Gateway Timeout"
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
function fallbackORPCErrorStatus(code, status) {
|
|
244
|
-
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
245
|
-
}
|
|
246
|
-
function fallbackORPCErrorMessage(code, message) {
|
|
247
|
-
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
248
|
-
}
|
|
249
|
-
var ORPCError = class _ORPCError extends Error {
|
|
250
|
-
defined;
|
|
251
|
-
code;
|
|
252
|
-
status;
|
|
253
|
-
data;
|
|
254
|
-
constructor(code, ...[options]) {
|
|
255
|
-
if (options?.status && (options.status < 400 || options.status >= 600)) {
|
|
256
|
-
throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
|
|
257
|
-
}
|
|
258
|
-
const message = fallbackORPCErrorMessage(code, options?.message);
|
|
259
|
-
super(message, options);
|
|
260
|
-
this.code = code;
|
|
261
|
-
this.status = fallbackORPCErrorStatus(code, options?.status);
|
|
262
|
-
this.defined = options?.defined ?? false;
|
|
263
|
-
this.data = options?.data;
|
|
264
|
-
}
|
|
265
|
-
toJSON() {
|
|
266
|
-
return {
|
|
267
|
-
defined: this.defined,
|
|
268
|
-
code: this.code,
|
|
269
|
-
status: this.status,
|
|
270
|
-
message: this.message,
|
|
271
|
-
data: this.data
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
static fromJSON(json) {
|
|
275
|
-
return new _ORPCError(json.code, json);
|
|
276
|
-
}
|
|
277
|
-
static isValidJSON(json) {
|
|
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";
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
// src/error-utils.ts
|
|
283
|
-
function isDefinedError(error) {
|
|
284
|
-
return error instanceof ORPCError && error.defined;
|
|
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
|
-
}
|
|
307
|
-
async function validateORPCError(map, error) {
|
|
308
|
-
const { code, status, message, data, cause, defined } = error;
|
|
309
|
-
const config = map?.[error.code];
|
|
310
|
-
if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
|
|
311
|
-
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
312
|
-
}
|
|
313
|
-
if (!config.data) {
|
|
314
|
-
return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
|
|
315
|
-
}
|
|
316
|
-
const validated = await config.data["~standard"].validate(error.data);
|
|
317
|
-
if (validated.issues) {
|
|
318
|
-
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
319
|
-
}
|
|
320
|
-
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// src/client-utils.ts
|
|
324
|
-
async function safe(promise) {
|
|
325
|
-
try {
|
|
326
|
-
const output = await promise;
|
|
327
|
-
return [output, void 0, false];
|
|
328
|
-
} catch (e) {
|
|
329
|
-
const error = e;
|
|
330
|
-
if (isDefinedError(error)) {
|
|
331
|
-
return [void 0, error, true];
|
|
332
|
-
}
|
|
333
|
-
return [void 0, error, false];
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// src/config.ts
|
|
338
|
-
var DEFAULT_CONFIG = {
|
|
339
|
-
defaultMethod: "POST",
|
|
340
|
-
defaultSuccessStatus: 200,
|
|
341
|
-
defaultSuccessDescription: "OK",
|
|
342
|
-
defaultInputStructure: "compact",
|
|
343
|
-
defaultOutputStructure: "compact"
|
|
344
|
-
};
|
|
345
|
-
function fallbackContractConfig(key, value) {
|
|
346
|
-
if (value === void 0) {
|
|
347
|
-
return DEFAULT_CONFIG[key];
|
|
348
|
-
}
|
|
349
|
-
return value;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// src/error.ts
|
|
353
|
-
var ValidationError = class extends Error {
|
|
354
|
-
issues;
|
|
355
|
-
constructor(options) {
|
|
356
|
-
super(options.message, options);
|
|
357
|
-
this.issues = options.issues;
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
// src/schema.ts
|
|
362
|
-
function type(...[map]) {
|
|
363
|
-
return {
|
|
364
|
-
"~standard": {
|
|
365
|
-
vendor: "custom",
|
|
366
|
-
version: 1,
|
|
367
|
-
async validate(value) {
|
|
368
|
-
if (map) {
|
|
369
|
-
return { value: await map(value) };
|
|
370
|
-
}
|
|
371
|
-
return { value };
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
export {
|
|
377
|
-
COMMON_ORPC_ERROR_DEFS,
|
|
378
|
-
ContractBuilder,
|
|
379
|
-
ContractProcedure,
|
|
380
|
-
ORPCError,
|
|
381
|
-
ValidationError,
|
|
382
|
-
adaptContractRouter,
|
|
383
|
-
adaptRoute,
|
|
384
|
-
createORPCErrorConstructorMap,
|
|
385
|
-
fallbackContractConfig,
|
|
386
|
-
fallbackORPCErrorMessage,
|
|
387
|
-
fallbackORPCErrorStatus,
|
|
388
|
-
isContractProcedure,
|
|
389
|
-
isDefinedError,
|
|
390
|
-
mergeErrorMap,
|
|
391
|
-
mergeMeta,
|
|
392
|
-
mergePrefix,
|
|
393
|
-
mergeRoute,
|
|
394
|
-
mergeTags,
|
|
395
|
-
oc,
|
|
396
|
-
prefixRoute,
|
|
397
|
-
safe,
|
|
398
|
-
type,
|
|
399
|
-
unshiftTagRoute,
|
|
400
|
-
validateORPCError
|
|
401
|
-
};
|
|
402
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,38 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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> {
|
|
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, {}, {}>;
|
|
32
|
-
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
__error?: {
|
|
12
|
-
type: TError;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
|
|
16
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
17
|
-
}
|
|
18
|
-
export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
|
|
19
|
-
[k: string]: NestedClient<TClientContext>;
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/config.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
8
|
-
}
|
|
9
|
-
export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
10
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/error-map.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ORPCErrorCode } from './error-orpc';
|
|
2
|
-
import type { Schema } from './schema';
|
|
3
|
-
export type ErrorMapItem<TDataSchema extends Schema> = {
|
|
4
|
-
status?: number;
|
|
5
|
-
message?: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
data?: TDataSchema;
|
|
8
|
-
};
|
|
9
|
-
export type ErrorMap = {
|
|
10
|
-
[key in ORPCErrorCode]?: ErrorMapItem<Schema>;
|
|
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>;
|
|
14
|
-
//# sourceMappingURL=error-map.d.ts.map
|