@orpc/arktype 2.0.0-beta.22 → 2.0.0-beta.23
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/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.mjs +18 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -2,12 +2,24 @@ import { ToJsonSchema } from '@ark/schema';
|
|
|
2
2
|
import { JsonSchemaConverter, AnySchema, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
|
|
3
3
|
|
|
4
4
|
interface ArkTypeToJsonSchemaConverterOptions extends Omit<ToJsonSchema.Options, 'dialect' | 'target'> {
|
|
5
|
+
/**
|
|
6
|
+
* Caches conversion results in a WeakMap keyed by the ArkType schema instance,
|
|
7
|
+
* so converting the same schema again is free.
|
|
8
|
+
*
|
|
9
|
+
* When enabled, repeated conversions return the same JSON schema object,
|
|
10
|
+
* so treat returned schemas as immutable.
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
cache?: boolean;
|
|
5
15
|
}
|
|
6
16
|
declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
|
|
7
17
|
private readonly toJsonSchemaOptions;
|
|
8
|
-
|
|
18
|
+
private readonly cache;
|
|
19
|
+
constructor({ cache, ...options }?: ArkTypeToJsonSchemaConverterOptions);
|
|
9
20
|
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
10
21
|
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
22
|
+
private convertUncached;
|
|
11
23
|
private convertArkType;
|
|
12
24
|
}
|
|
13
25
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,24 @@ import { ToJsonSchema } from '@ark/schema';
|
|
|
2
2
|
import { JsonSchemaConverter, AnySchema, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
|
|
3
3
|
|
|
4
4
|
interface ArkTypeToJsonSchemaConverterOptions extends Omit<ToJsonSchema.Options, 'dialect' | 'target'> {
|
|
5
|
+
/**
|
|
6
|
+
* Caches conversion results in a WeakMap keyed by the ArkType schema instance,
|
|
7
|
+
* so converting the same schema again is free.
|
|
8
|
+
*
|
|
9
|
+
* When enabled, repeated conversions return the same JSON schema object,
|
|
10
|
+
* so treat returned schemas as immutable.
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
cache?: boolean;
|
|
5
15
|
}
|
|
6
16
|
declare class ArkTypeToJsonSchemaConverter implements JsonSchemaConverter {
|
|
7
17
|
private readonly toJsonSchemaOptions;
|
|
8
|
-
|
|
18
|
+
private readonly cache;
|
|
19
|
+
constructor({ cache, ...options }?: ArkTypeToJsonSchemaConverterOptions);
|
|
9
20
|
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
10
21
|
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
22
|
+
private convertUncached;
|
|
11
23
|
private convertArkType;
|
|
12
24
|
}
|
|
13
25
|
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,11 @@ import { JsonSchemaXNativeType, JsonSchemaFormat } from '@orpc/json-schema';
|
|
|
2
2
|
|
|
3
3
|
class ArkTypeToJsonSchemaConverter {
|
|
4
4
|
toJsonSchemaOptions;
|
|
5
|
-
|
|
5
|
+
cache;
|
|
6
|
+
constructor({ cache, ...options } = {}) {
|
|
7
|
+
if (cache) {
|
|
8
|
+
this.cache = { input: /* @__PURE__ */ new WeakMap(), output: /* @__PURE__ */ new WeakMap() };
|
|
9
|
+
}
|
|
6
10
|
this.toJsonSchemaOptions = {
|
|
7
11
|
...options,
|
|
8
12
|
target: "draft-2020-12",
|
|
@@ -36,6 +40,19 @@ class ArkTypeToJsonSchemaConverter {
|
|
|
36
40
|
}
|
|
37
41
|
convert(schema, direction) {
|
|
38
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) {
|
|
39
56
|
const jsonSchema = this.convertArkType(arkTypeSchema, direction);
|
|
40
57
|
let optional = false;
|
|
41
58
|
try {
|
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.23",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"arktype": "*"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@orpc/json-schema": "2.0.0-beta.
|
|
32
|
+
"@orpc/json-schema": "2.0.0-beta.23"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@ark/schema": "^0.56.0",
|