@orpc/arktype 2.0.0-beta.47 → 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 +2 -3
- package/dist/converter.d.mts +29 -0
- package/dist/converter.mjs +73 -0
- package/dist/index.d.mts +2 -34
- package/dist/index.mjs +1 -66
- package/package.json +4 -4
- package/dist/index.d.ts +0 -34
package/README.md
CHANGED
|
@@ -191,15 +191,14 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
191
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>
|
|
192
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>
|
|
193
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>
|
|
194
|
-
<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>
|
|
195
195
|
</tr>
|
|
196
196
|
<tr>
|
|
197
|
-
<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>
|
|
198
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>
|
|
199
198
|
</tr>
|
|
200
199
|
</table>
|
|
201
200
|
|
|
202
|
-
With thanks to [
|
|
201
|
+
With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
203
202
|
|
|
204
203
|
## Open Source Programs
|
|
205
204
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ToJsonSchema } from "@ark/schema";
|
|
2
|
+
import type { AnySchema, JsonSchema, JsonSchemaConverter, JsonSchemaConverterDirection } from "@orpc/json-schema";
|
|
3
|
+
export interface ArkTypeToJsonSchemaConverterOptions extends Omit<ToJsonSchema.Options, "dialect" | "target"> {
|
|
4
|
+
/**
|
|
5
|
+
* Caches conversion results in a WeakMap keyed by the ArkType 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 ArkType schemas into JSON Schema using ArkType's built-in `toJsonSchema`,
|
|
17
|
+
* with additional support for types such as `bigint` and `Date`.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/integrations/arktype | ArkType Integration}
|
|
20
|
+
*/
|
|
21
|
+
export declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
|
|
22
|
+
private readonly toJsonSchemaOptions;
|
|
23
|
+
private readonly cache;
|
|
24
|
+
constructor({ cache, ...options }?: ArkTypeToJsonSchemaConverterOptions);
|
|
25
|
+
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
26
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
27
|
+
private convertUncached;
|
|
28
|
+
private convertArkType;
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isStandardSchemaOptional, JsonSchemaFormat, JsonSchemaXNativeType } from "@orpc/json-schema";
|
|
2
|
+
|
|
3
|
+
export class ArkTypeToJsonSchemaConverter {
|
|
4
|
+
toJsonSchemaOptions;
|
|
5
|
+
cache;
|
|
6
|
+
constructor({ cache, ...options } = {}) {
|
|
7
|
+
if (cache) {
|
|
8
|
+
this.cache = {
|
|
9
|
+
input: new WeakMap(),
|
|
10
|
+
output: new WeakMap()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
this.toJsonSchemaOptions = {
|
|
14
|
+
...options,
|
|
15
|
+
target: "draft-2020-12",
|
|
16
|
+
fallback: {
|
|
17
|
+
...options.fallback && typeof options.fallback !== "function" ? options.fallback : undefined,
|
|
18
|
+
default: (ctx) => {
|
|
19
|
+
if (ctx.code === "domain") {
|
|
20
|
+
if (ctx.domain === "bigint") {
|
|
21
|
+
;
|
|
22
|
+
ctx.base.type = "string";
|
|
23
|
+
ctx.base.pattern = "^-?[0-9]+$";
|
|
24
|
+
ctx.base["x-native-type"] = JsonSchemaXNativeType.BigInt;
|
|
25
|
+
}
|
|
26
|
+
} else if (ctx.code === "date") {
|
|
27
|
+
;
|
|
28
|
+
ctx.base.type = "string";
|
|
29
|
+
ctx.base.format = JsonSchemaFormat.DateTime;
|
|
30
|
+
ctx.base["x-native-type"] = JsonSchemaXNativeType.Date;
|
|
31
|
+
}
|
|
32
|
+
if (typeof options.fallback === "function") {
|
|
33
|
+
return options.fallback(ctx);
|
|
34
|
+
}
|
|
35
|
+
if (options.fallback?.default) {
|
|
36
|
+
return options.fallback.default(ctx);
|
|
37
|
+
}
|
|
38
|
+
return ctx.base;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
condition(schema, _direction) {
|
|
44
|
+
return schema?.["~standard"].vendor === "arktype";
|
|
45
|
+
}
|
|
46
|
+
convert(schema, direction) {
|
|
47
|
+
const arkTypeSchema = schema;
|
|
48
|
+
if (this.cache) {
|
|
49
|
+
const cached = this.cache[direction].get(arkTypeSchema);
|
|
50
|
+
if (cached) {
|
|
51
|
+
return cached;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const result = this.convertUncached(arkTypeSchema, direction);
|
|
55
|
+
if (this.cache) {
|
|
56
|
+
this.cache[direction].set(arkTypeSchema, result);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
convertUncached(arkTypeSchema, direction) {
|
|
61
|
+
const jsonSchema = this.convertArkType(arkTypeSchema, direction);
|
|
62
|
+
return [jsonSchema, isStandardSchemaOptional(arkTypeSchema, direction)];
|
|
63
|
+
}
|
|
64
|
+
convertArkType(schema, direction) {
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const jsonSchema = (direction === "output" ? schema.out : schema).toJsonSchema(this.toJsonSchemaOptions);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
const { $schema, ...rest } = jsonSchema;
|
|
71
|
+
return rest;
|
|
72
|
+
}
|
|
73
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,34 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { JsonSchema } from '@orpc/json-schema';
|
|
4
|
-
|
|
5
|
-
interface ArkTypeToJsonSchemaConverterOptions extends Omit<ToJsonSchema.Options, 'dialect' | 'target'> {
|
|
6
|
-
/**
|
|
7
|
-
* Caches conversion results in a WeakMap keyed by the ArkType 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 ArkType schemas into JSON Schema using ArkType's built-in `toJsonSchema`,
|
|
19
|
-
* with additional support for types such as `bigint` and `Date`.
|
|
20
|
-
*
|
|
21
|
-
* @see {@link https://orpc.dev/docs/integrations/arktype | ArkType Integration}
|
|
22
|
-
*/
|
|
23
|
-
declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
|
|
24
|
-
private readonly toJsonSchemaOptions;
|
|
25
|
-
private readonly cache;
|
|
26
|
-
constructor({ cache, ...options }?: ArkTypeToJsonSchemaConverterOptions);
|
|
27
|
-
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
28
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
29
|
-
private convertUncached;
|
|
30
|
-
private convertArkType;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { ArkTypeToJsonSchemaConverter };
|
|
34
|
-
export type { ArkTypeToJsonSchemaConverterOptions };
|
|
1
|
+
export * from "./converter.mjs";
|
|
2
|
+
export type { JsonSchema } from "@orpc/json-schema";
|
package/dist/index.mjs
CHANGED
|
@@ -1,66 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class ArkTypeToJsonSchemaConverter {
|
|
4
|
-
toJsonSchemaOptions;
|
|
5
|
-
cache;
|
|
6
|
-
constructor({ cache, ...options } = {}) {
|
|
7
|
-
if (cache) {
|
|
8
|
-
this.cache = { input: /* @__PURE__ */ new WeakMap(), output: /* @__PURE__ */ new WeakMap() };
|
|
9
|
-
}
|
|
10
|
-
this.toJsonSchemaOptions = {
|
|
11
|
-
...options,
|
|
12
|
-
target: "draft-2020-12",
|
|
13
|
-
fallback: {
|
|
14
|
-
...options.fallback && typeof options.fallback !== "function" ? options.fallback : void 0,
|
|
15
|
-
default: (ctx) => {
|
|
16
|
-
if (ctx.code === "domain") {
|
|
17
|
-
if (ctx.domain === "bigint") {
|
|
18
|
-
ctx.base.type = "string";
|
|
19
|
-
ctx.base.pattern = "^-?[0-9]+$";
|
|
20
|
-
ctx.base["x-native-type"] = JsonSchemaXNativeType.BigInt;
|
|
21
|
-
}
|
|
22
|
-
} else if (ctx.code === "date") {
|
|
23
|
-
ctx.base.type = "string";
|
|
24
|
-
ctx.base.format = JsonSchemaFormat.DateTime;
|
|
25
|
-
ctx.base["x-native-type"] = JsonSchemaXNativeType.Date;
|
|
26
|
-
}
|
|
27
|
-
if (typeof options.fallback === "function") {
|
|
28
|
-
return options.fallback(ctx);
|
|
29
|
-
}
|
|
30
|
-
if (options.fallback?.default) {
|
|
31
|
-
return options.fallback.default(ctx);
|
|
32
|
-
}
|
|
33
|
-
return ctx.base;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
condition(schema, _direction) {
|
|
39
|
-
return schema?.["~standard"].vendor === "arktype";
|
|
40
|
-
}
|
|
41
|
-
convert(schema, direction) {
|
|
42
|
-
const arkTypeSchema = schema;
|
|
43
|
-
if (this.cache) {
|
|
44
|
-
const cached = this.cache[direction].get(arkTypeSchema);
|
|
45
|
-
if (cached) {
|
|
46
|
-
return cached;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const result = this.convertUncached(arkTypeSchema, direction);
|
|
50
|
-
if (this.cache) {
|
|
51
|
-
this.cache[direction].set(arkTypeSchema, result);
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
convertUncached(arkTypeSchema, direction) {
|
|
56
|
-
const jsonSchema = this.convertArkType(arkTypeSchema, direction);
|
|
57
|
-
return [jsonSchema, isStandardSchemaOptional(arkTypeSchema, direction)];
|
|
58
|
-
}
|
|
59
|
-
convertArkType(schema, direction) {
|
|
60
|
-
const jsonSchema = (direction === "output" ? schema.out : schema).toJsonSchema(this.toJsonSchemaOptions);
|
|
61
|
-
const { $schema, ...rest } = jsonSchema;
|
|
62
|
-
return rest;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { ArkTypeToJsonSchemaConverter };
|
|
1
|
+
export * from "./converter.mjs";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/arktype",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.48",
|
|
5
5
|
"description": "ArkType integration for oRPC: convert ArkType schemas into JSON Schema for OpenAPI generation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"arktype": "*"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
43
|
+
"@orpc/json-schema": "2.0.0-beta.48"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ark/schema": "^0.56.
|
|
47
|
-
"arktype": "^2.2.
|
|
46
|
+
"@ark/schema": "^0.56.8",
|
|
47
|
+
"arktype": "^2.2.9",
|
|
48
48
|
"zod": "^4.6.7"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
package/dist/index.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ToJsonSchema } from '@ark/schema';
|
|
2
|
-
import { JsonSchemaConverter, AnySchema, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
|
|
3
|
-
export { JsonSchema } from '@orpc/json-schema';
|
|
4
|
-
|
|
5
|
-
interface ArkTypeToJsonSchemaConverterOptions extends Omit<ToJsonSchema.Options, 'dialect' | 'target'> {
|
|
6
|
-
/**
|
|
7
|
-
* Caches conversion results in a WeakMap keyed by the ArkType 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 ArkType schemas into JSON Schema using ArkType's built-in `toJsonSchema`,
|
|
19
|
-
* with additional support for types such as `bigint` and `Date`.
|
|
20
|
-
*
|
|
21
|
-
* @see {@link https://orpc.dev/docs/integrations/arktype | ArkType Integration}
|
|
22
|
-
*/
|
|
23
|
-
declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
|
|
24
|
-
private readonly toJsonSchemaOptions;
|
|
25
|
-
private readonly cache;
|
|
26
|
-
constructor({ cache, ...options }?: ArkTypeToJsonSchemaConverterOptions);
|
|
27
|
-
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
28
|
-
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
29
|
-
private convertUncached;
|
|
30
|
-
private convertArkType;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { ArkTypeToJsonSchemaConverter };
|
|
34
|
-
export type { ArkTypeToJsonSchemaConverterOptions };
|