@orpc/arktype 2.0.0-beta.47 → 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 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="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Farktype?logo=npm" />
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)
@@ -191,15 +192,14 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
191
192
  <td align="center"><a href="https://kellychan.im/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
192
193
  <td align="center"><a href="https://guyariely.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&amp;v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
193
194
  <td align="center"><a href="https://paulsenon.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&amp;v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
194
- <td align="center"><a href="https://nakasyou.how/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Shotaro Nakamura"><img src="https://avatars.githubusercontent.com/u/79000684?u=f644df3f29f0e8677a90967115774564f1d9d6ab&amp;v=4" width="139" alt="Shotaro Nakamura"/><br />Shotaro Nakamura</a></td>
195
+ <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
195
196
  </tr>
196
197
  <tr>
197
- <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
198
198
  <td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&amp;v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
199
199
  </tr>
200
200
  </table>
201
201
 
202
- With thanks to [39 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
202
+ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
203
203
 
204
204
  ## Open Source Programs
205
205
 
@@ -209,7 +209,6 @@ With thanks to [39 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
209
209
  <tr>
210
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>
211
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&amp;v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
212
- <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&amp;v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
213
212
  </tr>
214
213
  </table>
215
214
 
@@ -1,8 +1,6 @@
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'> {
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'> {
6
4
  /**
7
5
  * Caches conversion results in a WeakMap keyed by the ArkType schema instance,
8
6
  * so converting the same schema again is free.
@@ -16,11 +14,11 @@ interface ArkTypeToJsonSchemaConverterOptions extends Omit<ToJsonSchema.Options,
16
14
  }
17
15
  /**
18
16
  * Converts ArkType schemas into JSON Schema using ArkType's built-in `toJsonSchema`,
19
- * with additional support for types such as `bigint` and `Date`.
17
+ * with additional support for types such as `bigint`, `Date`, `File`, and `Blob`.
20
18
  *
21
19
  * @see {@link https://orpc.dev/docs/integrations/arktype | ArkType Integration}
22
20
  */
23
- declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
21
+ export declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
24
22
  private readonly toJsonSchemaOptions;
25
23
  private readonly cache;
26
24
  constructor({ cache, ...options }?: ArkTypeToJsonSchemaConverterOptions);
@@ -29,6 +27,3 @@ declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
29
27
  private convertUncached;
30
28
  private convertArkType;
31
29
  }
32
-
33
- export { ArkTypeToJsonSchemaConverter };
34
- export type { ArkTypeToJsonSchemaConverterOptions };
@@ -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 CHANGED
@@ -1,34 +1,2 @@
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 };
1
+ export * from './converter.ts';
2
+ export type { JsonSchema } from '@orpc/json-schema';
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
- "type": "module",
4
- "version": "2.0.0-beta.47",
3
+ "version": "2.0.0-beta.49",
5
4
  "description": "ArkType integration for oRPC: convert ArkType schemas into JSON Schema for OpenAPI generation",
6
- "license": "MIT",
7
- "funding": [
8
- "https://github.com/sponsors/dinwwwh",
9
- "https://opencollective.com/middleapi"
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
- "keywords": [
18
- "orpc",
19
- "arktype",
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.mts",
31
- "import": "./dist/index.mjs",
32
- "default": "./dist/index.mjs"
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.47"
39
+ "@orpc/json-schema": "2.0.0-beta.49"
44
40
  },
45
41
  "devDependencies": {
46
- "@ark/schema": "^0.56.7",
47
- "arktype": "^2.2.8",
42
+ "@ark/schema": "^0.56.8",
43
+ "arktype": "^2.2.9",
48
44
  "zod": "^4.6.7"
49
45
  },
50
- "scripts": {
51
- "type:check": "tsc -b"
52
- }
46
+ "peerDependencies": {
47
+ "@ark/schema": "*",
48
+ "arktype": "*"
49
+ },
50
+ "scripts": {}
53
51
  }
package/dist/index.mjs DELETED
@@ -1,66 +0,0 @@
1
- import { JsonSchemaXNativeType, JsonSchemaFormat, isStandardSchemaOptional } from '@orpc/json-schema';
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 };