@orpc/arktype 2.0.0-beta.48 → 2.0.0-beta.49
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 +4 -4
- package/dist/converter.d.ts +29 -0
- package/dist/converter.js +84 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +26 -28
- package/dist/converter.d.mts +0 -29
- package/dist/converter.mjs +0 -73
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
6
6
|
</a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/@orpc/arktype">
|
|
8
|
-
<img alt="
|
|
8
|
+
<img alt="monthly downloads" src="https://img.shields.io/npm/dm/%40orpc%2Farktype?logo=npm" />
|
|
9
9
|
</a>
|
|
10
10
|
<a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
|
|
11
11
|
<img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
|
|
@@ -41,10 +41,11 @@ export const router = {
|
|
|
41
41
|
Then call them from a client that knows every input and output, without generating anything:
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
|
-
import type { RouterClient } from '@orpc/server'
|
|
45
|
-
import type { router } from './router'
|
|
46
44
|
import { createORPCClient } from '@orpc/client'
|
|
47
45
|
import { RPCLink } from '@orpc/client/fetch'
|
|
46
|
+
import type { RouterClient } from '@orpc/server'
|
|
47
|
+
|
|
48
|
+
import type { router } from './router'
|
|
48
49
|
|
|
49
50
|
const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
|
|
50
51
|
const client: RouterClient<typeof router> = createORPCClient(link)
|
|
@@ -208,7 +209,6 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
208
209
|
<tr>
|
|
209
210
|
<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
211
|
<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>
|
|
212
212
|
</tr>
|
|
213
213
|
</table>
|
|
214
214
|
|
|
@@ -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`, `Date`, `File`, and `Blob`.
|
|
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,84 @@
|
|
|
1
|
+
import { isStandardSchemaOptional, JsonSchemaFormat, JsonSchemaXNativeType, } from '@orpc/json-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Converts ArkType schemas into JSON Schema using ArkType's built-in `toJsonSchema`,
|
|
4
|
+
* with additional support for types such as `bigint`, `Date`, `File`, and `Blob`.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://orpc.dev/docs/integrations/arktype | ArkType Integration}
|
|
7
|
+
*/
|
|
8
|
+
export class ArkTypeToJsonSchemaConverter {
|
|
9
|
+
toJsonSchemaOptions;
|
|
10
|
+
cache;
|
|
11
|
+
constructor({ cache, ...options } = {}) {
|
|
12
|
+
if (cache) {
|
|
13
|
+
this.cache = { input: new WeakMap(), output: new WeakMap() };
|
|
14
|
+
}
|
|
15
|
+
this.toJsonSchemaOptions = {
|
|
16
|
+
...options,
|
|
17
|
+
target: 'draft-2020-12',
|
|
18
|
+
fallback: {
|
|
19
|
+
...(options.fallback && typeof options.fallback !== 'function'
|
|
20
|
+
? options.fallback
|
|
21
|
+
: undefined),
|
|
22
|
+
default: (ctx) => {
|
|
23
|
+
if (ctx.code === 'domain') {
|
|
24
|
+
if (ctx.domain === 'bigint') {
|
|
25
|
+
;
|
|
26
|
+
ctx.base.type = 'string';
|
|
27
|
+
ctx.base.pattern = '^-?[0-9]+$';
|
|
28
|
+
ctx.base['x-native-type'] = JsonSchemaXNativeType.BigInt;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (ctx.code === 'date') {
|
|
32
|
+
;
|
|
33
|
+
ctx.base.type = 'string';
|
|
34
|
+
ctx.base.format = JsonSchemaFormat.DateTime;
|
|
35
|
+
ctx.base['x-native-type'] = JsonSchemaXNativeType.Date;
|
|
36
|
+
}
|
|
37
|
+
else if (ctx.code === 'proto' &&
|
|
38
|
+
(ctx.proto === Blob || ctx.proto.prototype instanceof Blob)) {
|
|
39
|
+
;
|
|
40
|
+
ctx.base.type = 'string';
|
|
41
|
+
ctx.base.contentMediaType = '*/*';
|
|
42
|
+
}
|
|
43
|
+
if (typeof options.fallback === 'function') {
|
|
44
|
+
return options.fallback(ctx);
|
|
45
|
+
}
|
|
46
|
+
if (options.fallback?.default) {
|
|
47
|
+
return options.fallback.default(ctx);
|
|
48
|
+
}
|
|
49
|
+
return ctx.base;
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
condition(schema, _direction) {
|
|
55
|
+
return schema?.['~standard'].vendor === 'arktype';
|
|
56
|
+
}
|
|
57
|
+
convert(schema, direction) {
|
|
58
|
+
const arkTypeSchema = schema;
|
|
59
|
+
if (this.cache) {
|
|
60
|
+
const cached = this.cache[direction].get(arkTypeSchema);
|
|
61
|
+
if (cached) {
|
|
62
|
+
return cached;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const result = this.convertUncached(arkTypeSchema, direction);
|
|
66
|
+
if (this.cache) {
|
|
67
|
+
this.cache[direction].set(arkTypeSchema, result);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
convertUncached(arkTypeSchema, direction) {
|
|
72
|
+
const jsonSchema = this.convertArkType(arkTypeSchema, direction);
|
|
73
|
+
return [jsonSchema, isStandardSchemaOptional(arkTypeSchema, direction)];
|
|
74
|
+
}
|
|
75
|
+
convertArkType(schema, direction) {
|
|
76
|
+
// `toJsonSchema` describes the input side (and keeps `default` annotations),
|
|
77
|
+
// so output conversions go through `.out` to reflect morph outputs and applied defaults.
|
|
78
|
+
const jsonSchema = (direction === 'output' ? schema.out : schema).toJsonSchema(this.toJsonSchemaOptions);
|
|
79
|
+
// Since the default oRPC format is always draft/2020-12,
|
|
80
|
+
// `$schema` can be safely omitted here.
|
|
81
|
+
const { $schema: _schema, ...rest } = jsonSchema;
|
|
82
|
+
return rest;
|
|
83
|
+
}
|
|
84
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './converter.js';
|
package/package.json
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/arktype",
|
|
3
|
-
"
|
|
4
|
-
"version": "2.0.0-beta.48",
|
|
3
|
+
"version": "2.0.0-beta.49",
|
|
5
4
|
"description": "ArkType integration for oRPC: convert ArkType schemas into JSON Schema for OpenAPI generation",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"arktype",
|
|
7
|
+
"json-schema",
|
|
8
|
+
"openapi",
|
|
9
|
+
"orpc",
|
|
10
|
+
"typesafe",
|
|
11
|
+
"typescript",
|
|
12
|
+
"validation"
|
|
10
13
|
],
|
|
11
14
|
"homepage": "https://orpc.dev",
|
|
15
|
+
"license": "MIT",
|
|
12
16
|
"repository": {
|
|
13
17
|
"type": "git",
|
|
14
18
|
"url": "git+https://github.com/middleapi/orpc.git",
|
|
15
19
|
"directory": "packages/arktype"
|
|
16
20
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"json-schema",
|
|
21
|
-
"openapi",
|
|
22
|
-
"validation",
|
|
23
|
-
"typescript",
|
|
24
|
-
"typesafe"
|
|
21
|
+
"funding": [
|
|
22
|
+
"https://github.com/sponsors/dinwwwh",
|
|
23
|
+
"https://opencollective.com/middleapi"
|
|
25
24
|
],
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
26
29
|
"sideEffects": false,
|
|
27
30
|
"exports": {
|
|
28
31
|
"./package.json": "./package.json",
|
|
29
32
|
".": {
|
|
30
|
-
"types": "./dist/index.d.
|
|
31
|
-
"import": "./dist/index.
|
|
32
|
-
"default": "./dist/index.
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"default": "./dist/index.js"
|
|
33
36
|
}
|
|
34
37
|
},
|
|
35
|
-
"files": [
|
|
36
|
-
"dist"
|
|
37
|
-
],
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"@ark/schema": "*",
|
|
40
|
-
"arktype": "*"
|
|
41
|
-
},
|
|
42
38
|
"dependencies": {
|
|
43
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
39
|
+
"@orpc/json-schema": "2.0.0-beta.49"
|
|
44
40
|
},
|
|
45
41
|
"devDependencies": {
|
|
46
42
|
"@ark/schema": "^0.56.8",
|
|
47
43
|
"arktype": "^2.2.9",
|
|
48
44
|
"zod": "^4.6.7"
|
|
49
45
|
},
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@ark/schema": "*",
|
|
48
|
+
"arktype": "*"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {}
|
|
53
51
|
}
|
package/dist/converter.d.mts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/converter.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
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
DELETED
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./converter.mjs";
|