@orpc/contract 0.0.0-next.caefe3a → 0.0.0-next.cc4cb21
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 +101 -0
- package/dist/index.js +59 -198
- package/dist/src/builder-variants.d.ts +1 -1
- package/dist/src/builder.d.ts +1 -1
- package/dist/src/error.d.ts +17 -3
- package/dist/src/event-iterator.d.ts +8 -0
- package/dist/src/index.d.ts +2 -6
- package/dist/src/procedure-client.d.ts +3 -4
- package/dist/src/procedure.d.ts +1 -1
- package/dist/src/router-client.d.ts +2 -1
- package/dist/src/router.d.ts +1 -1
- package/package.json +6 -4
- package/dist/src/client-utils.d.ts +0 -5
- package/dist/src/client.d.ts +0 -21
- 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 -15
- package/dist/src/types.d.ts +0 -3
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/contract">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fcontract?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
|
+
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
29
|
+
|
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
|
34
|
+
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
|
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
|
42
|
+
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
+
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
+
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
+
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
|
+
|
|
51
|
+
## Packages
|
|
52
|
+
|
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
|
|
62
|
+
## `@orpc/contract`
|
|
63
|
+
|
|
64
|
+
Build your API contract. Read the [documentation](https://orpc.unnoq.com/docs/contract-first/define-contract) for more information.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
export const PlanetSchema = z.object({
|
|
68
|
+
id: z.number().int().min(1),
|
|
69
|
+
name: z.string(),
|
|
70
|
+
description: z.string().optional(),
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export const listPlanetContract = oc
|
|
74
|
+
.input(
|
|
75
|
+
z.object({
|
|
76
|
+
limit: z.number().int().min(1).max(100).optional(),
|
|
77
|
+
cursor: z.number().int().min(0).default(0),
|
|
78
|
+
}),
|
|
79
|
+
)
|
|
80
|
+
.output(z.array(PlanetSchema))
|
|
81
|
+
|
|
82
|
+
export const findPlanetContract = oc
|
|
83
|
+
.input(PlanetSchema.pick({ id: true }))
|
|
84
|
+
.output(PlanetSchema)
|
|
85
|
+
|
|
86
|
+
export const createPlanetContract = oc
|
|
87
|
+
.input(PlanetSchema.omit({ id: true }))
|
|
88
|
+
.output(PlanetSchema)
|
|
89
|
+
|
|
90
|
+
export const contract = {
|
|
91
|
+
planet: {
|
|
92
|
+
list: listPlanetContract,
|
|
93
|
+
find: findPlanetContract,
|
|
94
|
+
create: createPlanetContract,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
// src/error
|
|
1
|
+
// src/error.ts
|
|
2
|
+
var ValidationError = class extends Error {
|
|
3
|
+
issues;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super(options.message, options);
|
|
6
|
+
this.issues = options.issues;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
2
9
|
function mergeErrorMap(errorMap1, errorMap2) {
|
|
3
10
|
return { ...errorMap1, ...errorMap2 };
|
|
4
11
|
}
|
|
@@ -160,186 +167,6 @@ var oc = new ContractBuilder({
|
|
|
160
167
|
meta: {}
|
|
161
168
|
});
|
|
162
169
|
|
|
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
|
-
function toORPCError(error) {
|
|
323
|
-
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
324
|
-
message: "Internal server error",
|
|
325
|
-
cause: error
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// src/client-utils.ts
|
|
330
|
-
async function safe(promise) {
|
|
331
|
-
try {
|
|
332
|
-
const output = await promise;
|
|
333
|
-
return [output, void 0, false];
|
|
334
|
-
} catch (e) {
|
|
335
|
-
const error = e;
|
|
336
|
-
if (isDefinedError(error)) {
|
|
337
|
-
return [void 0, error, true];
|
|
338
|
-
}
|
|
339
|
-
return [void 0, error, false];
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
170
|
// src/config.ts
|
|
344
171
|
var DEFAULT_CONFIG = {
|
|
345
172
|
defaultMethod: "POST",
|
|
@@ -355,14 +182,51 @@ function fallbackContractConfig(key, value) {
|
|
|
355
182
|
return value;
|
|
356
183
|
}
|
|
357
184
|
|
|
358
|
-
// src/
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
185
|
+
// src/event-iterator.ts
|
|
186
|
+
import { mapEventIterator, ORPCError } from "@orpc/client";
|
|
187
|
+
import { isAsyncIteratorObject } from "@orpc/shared";
|
|
188
|
+
var EVENT_ITERATOR_SCHEMA_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_SCHEMA");
|
|
189
|
+
function eventIterator(yields, returns) {
|
|
190
|
+
return {
|
|
191
|
+
"~standard": {
|
|
192
|
+
[EVENT_ITERATOR_SCHEMA_SYMBOL]: { yields, returns },
|
|
193
|
+
vendor: "orpc",
|
|
194
|
+
version: 1,
|
|
195
|
+
validate(iterator) {
|
|
196
|
+
if (!isAsyncIteratorObject(iterator)) {
|
|
197
|
+
return { issues: [{ message: "Expect event source iterator", path: [] }] };
|
|
198
|
+
}
|
|
199
|
+
const mapped = mapEventIterator(iterator, {
|
|
200
|
+
async value(value, done) {
|
|
201
|
+
const schema = done ? returns : yields;
|
|
202
|
+
if (!schema) {
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
const result = await schema["~standard"].validate(value);
|
|
206
|
+
if (result.issues) {
|
|
207
|
+
throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
|
|
208
|
+
message: "Event source iterator validation failed",
|
|
209
|
+
cause: new ValidationError({
|
|
210
|
+
issues: result.issues,
|
|
211
|
+
message: "Event source iterator validation failed"
|
|
212
|
+
})
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return result.value;
|
|
216
|
+
},
|
|
217
|
+
error: async (error) => error
|
|
218
|
+
});
|
|
219
|
+
return { value: mapped };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function getEventIteratorSchemaDetails(schema) {
|
|
225
|
+
if (schema === void 0) {
|
|
226
|
+
return void 0;
|
|
364
227
|
}
|
|
365
|
-
|
|
228
|
+
return schema["~standard"][EVENT_ITERATOR_SCHEMA_SYMBOL];
|
|
229
|
+
}
|
|
366
230
|
|
|
367
231
|
// src/schema.ts
|
|
368
232
|
function type(...[map]) {
|
|
@@ -379,20 +243,20 @@ function type(...[map]) {
|
|
|
379
243
|
}
|
|
380
244
|
};
|
|
381
245
|
}
|
|
246
|
+
|
|
247
|
+
// src/index.ts
|
|
248
|
+
import { ORPCError as ORPCError2 } from "@orpc/client";
|
|
382
249
|
export {
|
|
383
|
-
COMMON_ORPC_ERROR_DEFS,
|
|
384
250
|
ContractBuilder,
|
|
385
251
|
ContractProcedure,
|
|
386
|
-
ORPCError,
|
|
252
|
+
ORPCError2 as ORPCError,
|
|
387
253
|
ValidationError,
|
|
388
254
|
adaptContractRouter,
|
|
389
255
|
adaptRoute,
|
|
390
|
-
|
|
256
|
+
eventIterator,
|
|
391
257
|
fallbackContractConfig,
|
|
392
|
-
|
|
393
|
-
fallbackORPCErrorStatus,
|
|
258
|
+
getEventIteratorSchemaDetails,
|
|
394
259
|
isContractProcedure,
|
|
395
|
-
isDefinedError,
|
|
396
260
|
mergeErrorMap,
|
|
397
261
|
mergeMeta,
|
|
398
262
|
mergePrefix,
|
|
@@ -400,10 +264,7 @@ export {
|
|
|
400
264
|
mergeTags,
|
|
401
265
|
oc,
|
|
402
266
|
prefixRoute,
|
|
403
|
-
safe,
|
|
404
|
-
toORPCError,
|
|
405
267
|
type,
|
|
406
|
-
unshiftTagRoute
|
|
407
|
-
validateORPCError
|
|
268
|
+
unshiftTagRoute
|
|
408
269
|
};
|
|
409
270
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ContractProcedureBuilder, ContractProcedureBuilderWithInput, Contr
|
|
|
2
2
|
import type { ContractProcedureDef } from './procedure';
|
|
3
3
|
import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
|
|
4
4
|
import type { Schema } from './schema';
|
|
5
|
-
import { type ErrorMap, type MergedErrorMap } from './error
|
|
5
|
+
import { type ErrorMap, type MergedErrorMap } from './error';
|
|
6
6
|
import { type Meta } from './meta';
|
|
7
7
|
import { ContractProcedure } from './procedure';
|
|
8
8
|
import { type HTTPPath, type Route } from './route';
|
package/dist/src/error.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { ORPCError, ORPCErrorCode } from '@orpc/client';
|
|
1
2
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ORPCErrorFromErrorMap } from './error-orpc';
|
|
4
|
-
export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
|
|
3
|
+
import type { Schema, SchemaOutput } from './schema';
|
|
5
4
|
export interface ValidationErrorOptions extends ErrorOptions {
|
|
6
5
|
message: string;
|
|
7
6
|
issues: readonly StandardSchemaV1.Issue[];
|
|
@@ -10,4 +9,19 @@ export declare class ValidationError extends Error {
|
|
|
10
9
|
readonly issues: readonly StandardSchemaV1.Issue[];
|
|
11
10
|
constructor(options: ValidationErrorOptions);
|
|
12
11
|
}
|
|
12
|
+
export type ErrorMapItem<TDataSchema extends Schema> = {
|
|
13
|
+
status?: number;
|
|
14
|
+
message?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
data?: TDataSchema;
|
|
17
|
+
};
|
|
18
|
+
export type ErrorMap = {
|
|
19
|
+
[key in ORPCErrorCode]?: ErrorMapItem<Schema>;
|
|
20
|
+
};
|
|
21
|
+
export type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
22
|
+
export declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
23
|
+
export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
24
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
|
|
25
|
+
}[keyof TErrorMap];
|
|
26
|
+
export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
|
|
13
27
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: StandardSchemaV1<TYieldIn, TYieldOut>, returns?: StandardSchemaV1<TReturnIn, TReturnOut>): StandardSchemaV1<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
|
|
4
|
+
export declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
|
|
5
|
+
yields: Schema;
|
|
6
|
+
returns: Schema;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=event-iterator.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
2
|
export * from './builder';
|
|
3
3
|
export * from './builder-variants';
|
|
4
|
-
export * from './client';
|
|
5
|
-
export * from './client-utils';
|
|
6
4
|
export * from './config';
|
|
7
5
|
export * from './error';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './error-orpc';
|
|
10
|
-
export * from './error-utils';
|
|
6
|
+
export * from './event-iterator';
|
|
11
7
|
export * from './meta';
|
|
12
8
|
export * from './procedure';
|
|
13
9
|
export * from './procedure-client';
|
|
@@ -15,5 +11,5 @@ export * from './route';
|
|
|
15
11
|
export * from './router';
|
|
16
12
|
export * from './router-client';
|
|
17
13
|
export * from './schema';
|
|
18
|
-
export
|
|
14
|
+
export { ORPCError } from '@orpc/client';
|
|
19
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Client } from '
|
|
2
|
-
import type { ErrorFromErrorMap } from './error';
|
|
3
|
-
import type { ErrorMap } from './error-map';
|
|
1
|
+
import type { Client, ClientContext } from '@orpc/client';
|
|
2
|
+
import type { ErrorFromErrorMap, ErrorMap } from './error';
|
|
4
3
|
import type { Schema, SchemaInput, SchemaOutput } from './schema';
|
|
5
|
-
export type ContractProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
4
|
+
export type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
6
5
|
//# sourceMappingURL=procedure-client.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { ClientContext } from '@orpc/client';
|
|
1
2
|
import type { ContractProcedure } from './procedure';
|
|
2
3
|
import type { ContractProcedureClient } from './procedure-client';
|
|
3
4
|
import type { AnyContractRouter } from './router';
|
|
4
|
-
export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext
|
|
5
|
+
export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
5
6
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
6
7
|
};
|
|
7
8
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Meta } from './meta';
|
|
2
2
|
import type { SchemaInput, SchemaOutput } from './schema';
|
|
3
|
-
import { type ErrorMap, type MergedErrorMap } from './error
|
|
3
|
+
import { type ErrorMap, type MergedErrorMap } from './error';
|
|
4
4
|
import { ContractProcedure } from './procedure';
|
|
5
5
|
import { type HTTPPath } from './route';
|
|
6
6
|
export type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
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.cc4cb21",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,13 +29,15 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@standard-schema/spec": "1.0.0
|
|
33
|
-
"@orpc/
|
|
32
|
+
"@standard-schema/spec": "^1.0.0",
|
|
33
|
+
"@orpc/client": "0.0.0-next.cc4cb21",
|
|
34
|
+
"@orpc/shared": "0.0.0-next.cc4cb21",
|
|
35
|
+
"@orpc/standard-server": "0.0.0-next.cc4cb21"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"arktype": "2.0.0-rc.26",
|
|
37
39
|
"valibot": "1.0.0-beta.9",
|
|
38
|
-
"zod": "3.24.1"
|
|
40
|
+
"zod": "^3.24.1"
|
|
39
41
|
},
|
|
40
42
|
"scripts": {
|
|
41
43
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
@@ -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/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
|
package/dist/src/error-orpc.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, ErrorMapItem } from './error-map';
|
|
2
|
-
import type { SchemaOutput } from './schema';
|
|
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 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 & {
|
|
89
|
-
defined?: boolean;
|
|
90
|
-
status?: number;
|
|
91
|
-
message?: string;
|
|
92
|
-
} & (undefined extends TData ? {
|
|
93
|
-
data?: TData;
|
|
94
|
-
} : {
|
|
95
|
-
data: TData;
|
|
96
|
-
});
|
|
97
|
-
export type ORPCErrorOptionsRest<TData> = [options: ORPCErrorOptions<TData>] | (undefined extends TData ? [] : never);
|
|
98
|
-
export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
99
|
-
readonly defined: boolean;
|
|
100
|
-
readonly code: TCode;
|
|
101
|
-
readonly status: number;
|
|
102
|
-
readonly data: TData;
|
|
103
|
-
constructor(code: TCode, ...[options]: ORPCErrorOptionsRest<TData>);
|
|
104
|
-
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
105
|
-
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>): ORPCError<TCode, TData>;
|
|
106
|
-
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
107
|
-
}
|
|
108
|
-
export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
|
109
|
-
//# sourceMappingURL=error-orpc.d.ts.map
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
export declare function toORPCError(error: unknown): ORPCError<any, any>;
|
|
15
|
-
//# sourceMappingURL=error-utils.d.ts.map
|
package/dist/src/types.d.ts
DELETED