@orpc/valibot 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/converter.d.mts +32 -0
- package/dist/converter.mjs +123 -0
- package/dist/index.d.mts +2 -37
- package/dist/index.mjs +1 -97
- package/package.json +2 -2
- package/dist/index.d.ts +0 -37
package/README.md
CHANGED
|
@@ -156,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
156
156
|
<td align="center"><a href="https://github.com/christ12938?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
|
|
157
157
|
<td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
158
158
|
<td align="center"><a href="https://github.com/itigoore01?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="167" alt="shota"/><br />shota</a></td>
|
|
159
|
+
<td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
|
|
159
160
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
160
|
-
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
161
161
|
</tr>
|
|
162
162
|
<tr>
|
|
163
|
+
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
163
164
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
164
165
|
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
165
166
|
</tr>
|
|
@@ -190,10 +191,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
190
191
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
191
192
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
192
193
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
193
|
-
<td align="center"><a href="https://
|
|
194
|
+
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
194
195
|
</tr>
|
|
195
196
|
<tr>
|
|
196
|
-
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
197
197
|
<td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
198
198
|
</tr>
|
|
199
199
|
</table>
|
|
@@ -206,7 +206,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
206
206
|
|
|
207
207
|
<table>
|
|
208
208
|
<tr>
|
|
209
|
-
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude
|
|
209
|
+
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
|
|
210
|
+
<td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
|
|
211
|
+
<td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
|
|
210
212
|
</tr>
|
|
211
213
|
</table>
|
|
212
214
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AnySchema, JsonSchema, JsonSchemaConverter, JsonSchemaConverterDirection } from "@orpc/json-schema";
|
|
2
|
+
import type { ConversionConfig } from "@valibot/to-json-schema";
|
|
3
|
+
export interface ValibotToJsonSchemaConverterOptions extends Omit<ConversionConfig, "target" | "typeMode" | "overrideRef"> {
|
|
4
|
+
/**
|
|
5
|
+
* Caches conversion results in a WeakMap keyed by the Valibot schema instance,
|
|
6
|
+
* so converting the same schema again is free.
|
|
7
|
+
*
|
|
8
|
+
* When enabled, repeated conversions return the same JSON schema object,
|
|
9
|
+
* so treat returned schemas as immutable.
|
|
10
|
+
*
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
cache?: boolean | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts Valibot schemas into JSON Schema using Valibot's built-in `toJsonSchema`,
|
|
17
|
+
* with additional support for types such as `v.bigint()`, `v.date()`, `v.set()`, and `v.map()`.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/integrations/valibot | Valibot Integration}
|
|
20
|
+
*/
|
|
21
|
+
export declare class ValibotToJsonSchemaConverter implements JsonSchemaConverter {
|
|
22
|
+
private readonly conversionConfig;
|
|
23
|
+
private readonly cache;
|
|
24
|
+
constructor({ cache, ...conversionConfig }?: ValibotToJsonSchemaConverterOptions);
|
|
25
|
+
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
26
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
27
|
+
private convertUncached;
|
|
28
|
+
private createConversionConfig;
|
|
29
|
+
private overrideSchema;
|
|
30
|
+
private convertNativeType;
|
|
31
|
+
private convertWithin;
|
|
32
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { isStandardSchemaOptional, JsonSchemaFormat, JsonSchemaXNativeType } from "@orpc/json-schema";
|
|
2
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
3
|
+
import { any, tuple } from "valibot";
|
|
4
|
+
const NESTED_CONVERSION_SENTINEL = /* @__PURE__ */ any();
|
|
5
|
+
|
|
6
|
+
export class ValibotToJsonSchemaConverter {
|
|
7
|
+
conversionConfig;
|
|
8
|
+
cache;
|
|
9
|
+
constructor({ cache, ...conversionConfig } = {}) {
|
|
10
|
+
this.conversionConfig = conversionConfig;
|
|
11
|
+
if (cache) {
|
|
12
|
+
this.cache = {
|
|
13
|
+
input: new WeakMap(),
|
|
14
|
+
output: new WeakMap()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
condition(schema, _direction) {
|
|
19
|
+
return schema?.["~standard"].vendor === "valibot";
|
|
20
|
+
}
|
|
21
|
+
convert(schema, direction) {
|
|
22
|
+
const valibotSchema = schema;
|
|
23
|
+
if (this.cache) {
|
|
24
|
+
const cached = this.cache[direction].get(valibotSchema);
|
|
25
|
+
if (cached) {
|
|
26
|
+
return cached;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const result = this.convertUncached(valibotSchema, direction);
|
|
30
|
+
if (this.cache) {
|
|
31
|
+
this.cache[direction].set(valibotSchema, result);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
convertUncached(valibotSchema, direction) {
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const { $schema, ...jsonSchema } = toJsonSchema(valibotSchema, this.createConversionConfig(direction));
|
|
39
|
+
return [jsonSchema, isStandardSchemaOptional(valibotSchema, direction)];
|
|
40
|
+
}
|
|
41
|
+
createConversionConfig(direction) {
|
|
42
|
+
return {
|
|
43
|
+
errorMode: "ignore",
|
|
44
|
+
...this.conversionConfig,
|
|
45
|
+
target: "draft-2020-12",
|
|
46
|
+
typeMode: direction,
|
|
47
|
+
overrideSchema: (context) => this.overrideSchema(context, direction)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
overrideSchema(context, direction) {
|
|
51
|
+
const jsonSchema = this.convertNativeType(context, direction);
|
|
52
|
+
return jsonSchema ? this.conversionConfig.overrideSchema?.({
|
|
53
|
+
...context,
|
|
54
|
+
jsonSchema,
|
|
55
|
+
errors: undefined
|
|
56
|
+
}) ?? jsonSchema : this.conversionConfig.overrideSchema?.(context);
|
|
57
|
+
}
|
|
58
|
+
convertNativeType(context, direction) {
|
|
59
|
+
switch (context.valibotSchema.type) {
|
|
60
|
+
case "bigint": return {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"pattern": "^-?[0-9]+$",
|
|
63
|
+
"x-native-type": JsonSchemaXNativeType.BigInt
|
|
64
|
+
};
|
|
65
|
+
case "date": return {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"format": JsonSchemaFormat.DateTime,
|
|
68
|
+
"x-native-type": JsonSchemaXNativeType.Date
|
|
69
|
+
};
|
|
70
|
+
case "set": {
|
|
71
|
+
const { value } = context.valibotSchema;
|
|
72
|
+
return {
|
|
73
|
+
"type": "array",
|
|
74
|
+
"uniqueItems": true,
|
|
75
|
+
"items": this.convertWithin(context, [value], direction)[0],
|
|
76
|
+
"x-native-type": JsonSchemaXNativeType.Set
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
case "map": {
|
|
80
|
+
const { key, value } = context.valibotSchema;
|
|
81
|
+
return {
|
|
82
|
+
"type": "array",
|
|
83
|
+
"items": {
|
|
84
|
+
type: "array",
|
|
85
|
+
prefixItems: this.convertWithin(context, [key, value], direction),
|
|
86
|
+
maxItems: 2,
|
|
87
|
+
minItems: 2
|
|
88
|
+
},
|
|
89
|
+
"x-native-type": JsonSchemaXNativeType.Map
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
convertWithin(parent, schemas, direction) {
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
const wrapper = tuple([NESTED_CONVERSION_SENTINEL, ...schemas]);
|
|
98
|
+
let child;
|
|
99
|
+
const { prefixItems } = toJsonSchema(wrapper, {
|
|
100
|
+
...this.createConversionConfig(direction),
|
|
101
|
+
definitions: {},
|
|
102
|
+
overrideSchema: (context) => {
|
|
103
|
+
if (context.valibotSchema === NESTED_CONVERSION_SENTINEL) {
|
|
104
|
+
child = context;
|
|
105
|
+
mergeConversionContext(child, parent);
|
|
106
|
+
} else if (context.valibotSchema !== wrapper) {
|
|
107
|
+
return this.overrideSchema(context, direction);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
mergeConversionContext(parent, child);
|
|
112
|
+
return prefixItems.slice(1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function mergeConversionContext(target, source) {
|
|
116
|
+
|
|
117
|
+
if (!source.referenceMap.size) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
source.referenceMap.forEach((referenceId, schema) => target.referenceMap.set(schema, referenceId));
|
|
121
|
+
source.getterMap.forEach((schema, getter) => target.getterMap.set(getter, schema));
|
|
122
|
+
Object.assign(target.definitions, source.definitions);
|
|
123
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { JsonSchema } from
|
|
3
|
-
import { ConversionConfig } from '@valibot/to-json-schema';
|
|
4
|
-
|
|
5
|
-
interface ValibotToJsonSchemaConverterOptions extends Omit<ConversionConfig, 'target' | 'typeMode' | 'overrideRef'> {
|
|
6
|
-
/**
|
|
7
|
-
* Caches conversion results in a WeakMap keyed by the Valibot schema instance,
|
|
8
|
-
* so converting the same schema again is free.
|
|
9
|
-
*
|
|
10
|
-
* When enabled, repeated conversions return the same JSON schema object,
|
|
11
|
-
* so treat returned schemas as immutable.
|
|
12
|
-
*
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
cache?: boolean | undefined;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Converts Valibot schemas into JSON Schema using Valibot's built-in `toJsonSchema`,
|
|
19
|
-
* with additional support for types such as `v.bigint()`, `v.date()`, `v.set()`, and `v.map()`.
|
|
20
|
-
*
|
|
21
|
-
* @see {@link https://orpc.dev/docs/integrations/valibot | Valibot Integration}
|
|
22
|
-
*/
|
|
23
|
-
declare class ValibotToJsonSchemaConverter implements JsonSchemaConverter {
|
|
24
|
-
private readonly conversionConfig;
|
|
25
|
-
private readonly cache;
|
|
26
|
-
constructor({ cache, ...conversionConfig }?: ValibotToJsonSchemaConverterOptions);
|
|
27
|
-
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
28
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
29
|
-
private convertUncached;
|
|
30
|
-
private createConversionConfig;
|
|
31
|
-
private overrideSchema;
|
|
32
|
-
private convertNativeType;
|
|
33
|
-
private convertWithin;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { ValibotToJsonSchemaConverter };
|
|
37
|
-
export type { ValibotToJsonSchemaConverterOptions };
|
|
1
|
+
export * from "./converter.mjs";
|
|
2
|
+
export type { JsonSchema } from "@orpc/json-schema";
|
package/dist/index.mjs
CHANGED
|
@@ -1,97 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
3
|
-
import { any, tuple } from 'valibot';
|
|
4
|
-
|
|
5
|
-
const NESTED_CONVERSION_SENTINEL = any();
|
|
6
|
-
class ValibotToJsonSchemaConverter {
|
|
7
|
-
conversionConfig;
|
|
8
|
-
cache;
|
|
9
|
-
constructor({ cache, ...conversionConfig } = {}) {
|
|
10
|
-
this.conversionConfig = conversionConfig;
|
|
11
|
-
if (cache) {
|
|
12
|
-
this.cache = { input: /* @__PURE__ */ new WeakMap(), output: /* @__PURE__ */ new WeakMap() };
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
condition(schema, _direction) {
|
|
16
|
-
return schema?.["~standard"].vendor === "valibot";
|
|
17
|
-
}
|
|
18
|
-
convert(schema, direction) {
|
|
19
|
-
const valibotSchema = schema;
|
|
20
|
-
if (this.cache) {
|
|
21
|
-
const cached = this.cache[direction].get(valibotSchema);
|
|
22
|
-
if (cached) {
|
|
23
|
-
return cached;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const result = this.convertUncached(valibotSchema, direction);
|
|
27
|
-
if (this.cache) {
|
|
28
|
-
this.cache[direction].set(valibotSchema, result);
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
convertUncached(valibotSchema, direction) {
|
|
33
|
-
const { $schema, ...jsonSchema } = toJsonSchema(valibotSchema, this.createConversionConfig(direction));
|
|
34
|
-
return [jsonSchema, isStandardSchemaOptional(valibotSchema, direction)];
|
|
35
|
-
}
|
|
36
|
-
createConversionConfig(direction) {
|
|
37
|
-
return {
|
|
38
|
-
errorMode: "ignore",
|
|
39
|
-
...this.conversionConfig,
|
|
40
|
-
target: "draft-2020-12",
|
|
41
|
-
typeMode: direction,
|
|
42
|
-
overrideSchema: (context) => this.overrideSchema(context, direction)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
overrideSchema(context, direction) {
|
|
46
|
-
const jsonSchema = this.convertNativeType(context, direction);
|
|
47
|
-
return jsonSchema ? this.conversionConfig.overrideSchema?.({ ...context, jsonSchema, errors: void 0 }) ?? jsonSchema : this.conversionConfig.overrideSchema?.(context);
|
|
48
|
-
}
|
|
49
|
-
convertNativeType(context, direction) {
|
|
50
|
-
switch (context.valibotSchema.type) {
|
|
51
|
-
case "bigint":
|
|
52
|
-
return { "type": "string", "pattern": "^-?[0-9]+$", "x-native-type": JsonSchemaXNativeType.BigInt };
|
|
53
|
-
case "date":
|
|
54
|
-
return { "type": "string", "format": JsonSchemaFormat.DateTime, "x-native-type": JsonSchemaXNativeType.Date };
|
|
55
|
-
case "set": {
|
|
56
|
-
const { value } = context.valibotSchema;
|
|
57
|
-
return { "type": "array", "uniqueItems": true, "items": this.convertWithin(context, [value], direction)[0], "x-native-type": JsonSchemaXNativeType.Set };
|
|
58
|
-
}
|
|
59
|
-
case "map": {
|
|
60
|
-
const { key, value } = context.valibotSchema;
|
|
61
|
-
return {
|
|
62
|
-
"type": "array",
|
|
63
|
-
"items": { type: "array", prefixItems: this.convertWithin(context, [key, value], direction), maxItems: 2, minItems: 2 },
|
|
64
|
-
"x-native-type": JsonSchemaXNativeType.Map
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
convertWithin(parent, schemas, direction) {
|
|
70
|
-
const wrapper = tuple([NESTED_CONVERSION_SENTINEL, ...schemas]);
|
|
71
|
-
let child;
|
|
72
|
-
const { prefixItems } = toJsonSchema(wrapper, {
|
|
73
|
-
...this.createConversionConfig(direction),
|
|
74
|
-
definitions: {},
|
|
75
|
-
overrideSchema: (context) => {
|
|
76
|
-
if (context.valibotSchema === NESTED_CONVERSION_SENTINEL) {
|
|
77
|
-
child = context;
|
|
78
|
-
mergeConversionContext(child, parent);
|
|
79
|
-
} else if (context.valibotSchema !== wrapper) {
|
|
80
|
-
return this.overrideSchema(context, direction);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
mergeConversionContext(parent, child);
|
|
85
|
-
return prefixItems.slice(1);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function mergeConversionContext(target, source) {
|
|
89
|
-
if (!source.referenceMap.size) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
source.referenceMap.forEach((referenceId, schema) => target.referenceMap.set(schema, referenceId));
|
|
93
|
-
source.getterMap.forEach((schema, getter) => target.getterMap.set(getter, schema));
|
|
94
|
-
Object.assign(target.definitions, source.definitions);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export { ValibotToJsonSchemaConverter };
|
|
1
|
+
export * from "./converter.mjs";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/valibot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.48",
|
|
5
5
|
"description": "Valibot integration for oRPC: convert Valibot schemas into JSON Schema for OpenAPI generation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"valibot": ">=1.5.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
42
|
+
"@orpc/json-schema": "2.0.0-beta.48",
|
|
43
43
|
"@valibot/to-json-schema": "^1.8.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
package/dist/index.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { JsonSchemaConverter, AnySchema, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
|
|
2
|
-
export { JsonSchema } from '@orpc/json-schema';
|
|
3
|
-
import { ConversionConfig } from '@valibot/to-json-schema';
|
|
4
|
-
|
|
5
|
-
interface ValibotToJsonSchemaConverterOptions extends Omit<ConversionConfig, 'target' | 'typeMode' | 'overrideRef'> {
|
|
6
|
-
/**
|
|
7
|
-
* Caches conversion results in a WeakMap keyed by the Valibot schema instance,
|
|
8
|
-
* so converting the same schema again is free.
|
|
9
|
-
*
|
|
10
|
-
* When enabled, repeated conversions return the same JSON schema object,
|
|
11
|
-
* so treat returned schemas as immutable.
|
|
12
|
-
*
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
cache?: boolean | undefined;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Converts Valibot schemas into JSON Schema using Valibot's built-in `toJsonSchema`,
|
|
19
|
-
* with additional support for types such as `v.bigint()`, `v.date()`, `v.set()`, and `v.map()`.
|
|
20
|
-
*
|
|
21
|
-
* @see {@link https://orpc.dev/docs/integrations/valibot | Valibot Integration}
|
|
22
|
-
*/
|
|
23
|
-
declare class ValibotToJsonSchemaConverter implements JsonSchemaConverter {
|
|
24
|
-
private readonly conversionConfig;
|
|
25
|
-
private readonly cache;
|
|
26
|
-
constructor({ cache, ...conversionConfig }?: ValibotToJsonSchemaConverterOptions);
|
|
27
|
-
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
28
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
29
|
-
private convertUncached;
|
|
30
|
-
private createConversionConfig;
|
|
31
|
-
private overrideSchema;
|
|
32
|
-
private convertNativeType;
|
|
33
|
-
private convertWithin;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { ValibotToJsonSchemaConverter };
|
|
37
|
-
export type { ValibotToJsonSchemaConverterOptions };
|