@orpc/json-schema 2.0.0-beta.17 → 2.0.0-beta.19
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 +8 -2
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +12 -11
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
<a href="https://www.npmjs.com/package/@orpc/json-schema">
|
|
8
8
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fjson-schema?logo=npm" />
|
|
9
9
|
</a>
|
|
10
|
+
<a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
|
|
11
|
+
<img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
|
|
12
|
+
</a>
|
|
10
13
|
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
11
14
|
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
12
15
|
</a>
|
|
@@ -46,11 +49,14 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
46
49
|
**Framework & ecosystem integrations**
|
|
47
50
|
|
|
48
51
|
- [@orpc/next](https://www.npmjs.com/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
52
|
+
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
49
53
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
54
|
+
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
50
55
|
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
51
56
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
52
57
|
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
|
53
58
|
- [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
|
|
59
|
+
- [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
54
60
|
|
|
55
61
|
**Observability**
|
|
56
62
|
|
|
@@ -102,11 +108,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
102
108
|
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
|
|
103
109
|
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
|
|
104
110
|
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
|
|
105
|
-
<td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td>
|
|
106
111
|
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
|
|
112
|
+
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
107
113
|
</tr>
|
|
108
114
|
<tr>
|
|
109
|
-
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
110
115
|
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
111
116
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
112
117
|
</tr>
|
|
@@ -166,6 +171,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
166
171
|
<a href="https://github.com/nelsonlaidev?ref=orpc" target="_blank" rel="noopener" title="Nelson Lai"><img src="https://avatars.githubusercontent.com/u/75498339?u=2fc0e0b95dd184c5ffb744df977cb15a18b60672&v=4" width="32" height="32" alt="Nelson Lai" /></a>
|
|
167
172
|
<a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
|
|
168
173
|
<a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a>
|
|
174
|
+
<a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
|
|
169
175
|
<a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
|
|
170
176
|
<a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="32" height="32" alt="Peter Adam" /></a>
|
|
171
177
|
<a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
|
package/dist/index.d.mts
CHANGED
|
@@ -2,14 +2,13 @@ import * as Draft2020 from 'json-schema-typed/draft-2020-12';
|
|
|
2
2
|
export { Format as JsonSchemaFormat, TypeName as JsonSchemaType } from 'json-schema-typed/draft-2020-12';
|
|
3
3
|
import { AnySchema, RouterContract } from '@orpc/contract';
|
|
4
4
|
export { AnySchema, Schema } from '@orpc/contract';
|
|
5
|
-
import { Promisable } from '@orpc/shared';
|
|
6
5
|
import { Context } from '@orpc/server';
|
|
7
6
|
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
8
7
|
import { ClientContext } from '@orpc/client';
|
|
9
8
|
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
10
9
|
import { StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
11
10
|
|
|
12
|
-
type JsonSchema = Draft2020.JSONSchema
|
|
11
|
+
type JsonSchema<Value = any> = Draft2020.JSONSchema<Value>;
|
|
13
12
|
type JsonSchemaKeywords = typeof Draft2020.keywords[number];
|
|
14
13
|
declare enum JsonSchemaXNativeType {
|
|
15
14
|
BigInt = "bigint",
|
|
@@ -95,16 +94,16 @@ interface JsonSchemaConverter {
|
|
|
95
94
|
/**
|
|
96
95
|
* Determines whether this converter can handle the given schema.
|
|
97
96
|
*/
|
|
98
|
-
condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection):
|
|
97
|
+
condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): boolean;
|
|
99
98
|
/**
|
|
100
99
|
* Converts an ORPC schema to a JSON Schema representation.
|
|
101
100
|
*/
|
|
102
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection):
|
|
101
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
103
102
|
}
|
|
104
103
|
declare class DelegatingJsonSchemaConverter implements Pick<JsonSchemaConverter, 'convert'> {
|
|
105
104
|
private readonly converters;
|
|
106
105
|
constructor(converters?: JsonSchemaConverter[]);
|
|
107
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection):
|
|
106
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2,14 +2,13 @@ import * as Draft2020 from 'json-schema-typed/draft-2020-12';
|
|
|
2
2
|
export { Format as JsonSchemaFormat, TypeName as JsonSchemaType } from 'json-schema-typed/draft-2020-12';
|
|
3
3
|
import { AnySchema, RouterContract } from '@orpc/contract';
|
|
4
4
|
export { AnySchema, Schema } from '@orpc/contract';
|
|
5
|
-
import { Promisable } from '@orpc/shared';
|
|
6
5
|
import { Context } from '@orpc/server';
|
|
7
6
|
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
8
7
|
import { ClientContext } from '@orpc/client';
|
|
9
8
|
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
10
9
|
import { StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
11
10
|
|
|
12
|
-
type JsonSchema = Draft2020.JSONSchema
|
|
11
|
+
type JsonSchema<Value = any> = Draft2020.JSONSchema<Value>;
|
|
13
12
|
type JsonSchemaKeywords = typeof Draft2020.keywords[number];
|
|
14
13
|
declare enum JsonSchemaXNativeType {
|
|
15
14
|
BigInt = "bigint",
|
|
@@ -95,16 +94,16 @@ interface JsonSchemaConverter {
|
|
|
95
94
|
/**
|
|
96
95
|
* Determines whether this converter can handle the given schema.
|
|
97
96
|
*/
|
|
98
|
-
condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection):
|
|
97
|
+
condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): boolean;
|
|
99
98
|
/**
|
|
100
99
|
* Converts an ORPC schema to a JSON Schema representation.
|
|
101
100
|
*/
|
|
102
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection):
|
|
101
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
103
102
|
}
|
|
104
103
|
declare class DelegatingJsonSchemaConverter implements Pick<JsonSchemaConverter, 'convert'> {
|
|
105
104
|
private readonly converters;
|
|
106
105
|
constructor(converters?: JsonSchemaConverter[]);
|
|
107
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection):
|
|
106
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -844,13 +844,14 @@ class DelegatingJsonSchemaConverter {
|
|
|
844
844
|
constructor(converters = []) {
|
|
845
845
|
this.converters = converters;
|
|
846
846
|
}
|
|
847
|
-
|
|
847
|
+
convert(schema, direction) {
|
|
848
848
|
for (const converter of this.converters) {
|
|
849
|
-
if (
|
|
849
|
+
if (converter.condition(schema, direction)) {
|
|
850
850
|
return converter.convert(schema, direction);
|
|
851
851
|
}
|
|
852
852
|
}
|
|
853
|
-
const
|
|
853
|
+
const result = schema?.["~standard"].validate(void 0);
|
|
854
|
+
const optional = result instanceof Promise ? false : !result?.issues?.length;
|
|
854
855
|
if (schema && "jsonSchema" in schema["~standard"] && schema["~standard"].jsonSchema) {
|
|
855
856
|
try {
|
|
856
857
|
return [
|
|
@@ -907,23 +908,23 @@ class SmartCoercionHandlerPlugin {
|
|
|
907
908
|
return {
|
|
908
909
|
...options,
|
|
909
910
|
clientInterceptors: [
|
|
910
|
-
|
|
911
|
+
({ next, input, ...interceptorOptions }) => {
|
|
911
912
|
const inputSchemas = interceptorOptions.procedure["~orpc"].inputSchemas;
|
|
912
913
|
if (!inputSchemas) {
|
|
913
914
|
return next();
|
|
914
915
|
}
|
|
915
|
-
const coercedInput =
|
|
916
|
+
const coercedInput = this.coerceValue(inputSchemas, input);
|
|
916
917
|
return next({ ...interceptorOptions, input: coercedInput });
|
|
917
918
|
},
|
|
918
919
|
...toArray(options.clientInterceptors)
|
|
919
920
|
]
|
|
920
921
|
};
|
|
921
922
|
}
|
|
922
|
-
|
|
923
|
+
coerceValue(schemas, value) {
|
|
923
924
|
for (const schema of schemas) {
|
|
924
925
|
let converted = this.cache.get(schema);
|
|
925
926
|
if (!converted) {
|
|
926
|
-
converted =
|
|
927
|
+
converted = this.converter.convert(schema, "input");
|
|
927
928
|
this.cache.set(schema, converted);
|
|
928
929
|
}
|
|
929
930
|
value = this.coercer.coerce(converted, value);
|
|
@@ -962,7 +963,7 @@ class SmartCoercionLinkPlugin {
|
|
|
962
963
|
if (!outputSchemas) {
|
|
963
964
|
return output;
|
|
964
965
|
}
|
|
965
|
-
const coercedOutput =
|
|
966
|
+
const coercedOutput = this.coerceValue(outputSchemas, output);
|
|
966
967
|
return coercedOutput;
|
|
967
968
|
} catch (error) {
|
|
968
969
|
if (!(error instanceof ORPCError) || !error.defined) {
|
|
@@ -974,18 +975,18 @@ class SmartCoercionLinkPlugin {
|
|
|
974
975
|
throw error;
|
|
975
976
|
}
|
|
976
977
|
const cloned = cloneORPCError(error);
|
|
977
|
-
cloned.data =
|
|
978
|
+
cloned.data = this.coerceValue([dataSchema], cloned.data);
|
|
978
979
|
throw cloned;
|
|
979
980
|
}
|
|
980
981
|
}
|
|
981
982
|
]
|
|
982
983
|
};
|
|
983
984
|
}
|
|
984
|
-
|
|
985
|
+
coerceValue(schemas, value) {
|
|
985
986
|
for (const schema of schemas) {
|
|
986
987
|
let converted = this.cache.get(schema);
|
|
987
988
|
if (!converted) {
|
|
988
|
-
converted =
|
|
989
|
+
converted = this.converter.convert(schema, "output");
|
|
989
990
|
this.cache.set(schema, converted);
|
|
990
991
|
}
|
|
991
992
|
value = this.coercer.coerce(converted, value);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/json-schema",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.19",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@standard-schema/spec": "^1.1.0",
|
|
29
29
|
"json-schema-typed": "^8.0.2",
|
|
30
|
-
"@orpc/
|
|
31
|
-
"@orpc/
|
|
32
|
-
"@orpc/
|
|
33
|
-
"@orpc/
|
|
30
|
+
"@orpc/contract": "2.0.0-beta.19",
|
|
31
|
+
"@orpc/client": "2.0.0-beta.19",
|
|
32
|
+
"@orpc/server": "2.0.0-beta.19",
|
|
33
|
+
"@orpc/shared": "2.0.0-beta.19"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"zod": "^4.4.3"
|