@arrirpc/typebox-adapter 0.70.1 → 0.71.1
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.cjs +27 -1
- package/dist/index.mjs +28 -2
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ const jsonSchemaToAtd = require('json-schema-to-atd');
|
|
|
9
9
|
function typeboxAdapter(input) {
|
|
10
10
|
const schema$1 = jsonSchemaToAtd.jsonSchemaToJtdSchema(input);
|
|
11
11
|
const compiled = compiler.TypeCompiler.Compile(input);
|
|
12
|
-
|
|
12
|
+
const result = {
|
|
13
13
|
...schema$1,
|
|
14
14
|
metadata: {
|
|
15
15
|
id: input.$id ?? input.title,
|
|
@@ -43,8 +43,34 @@ function typeboxAdapter(input) {
|
|
|
43
43
|
return compiled.Encode(val);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
},
|
|
47
|
+
"~standard": {
|
|
48
|
+
version: 1,
|
|
49
|
+
vendor: "arri-typebox",
|
|
50
|
+
validate(value) {
|
|
51
|
+
if (compiled.Check(value)) {
|
|
52
|
+
return {
|
|
53
|
+
value
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === "string") {
|
|
57
|
+
const parsedVal = JSON.parse(value);
|
|
58
|
+
if (compiled.Check(parsedVal)) {
|
|
59
|
+
return parsedVal;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const errors = typeboxErrorsToArriError(compiled.Errors(value));
|
|
63
|
+
return {
|
|
64
|
+
issues: errors.errors.map((err) => ({
|
|
65
|
+
message: err.message ?? "Unknown error",
|
|
66
|
+
path: err.instancePath.split("/").filter((item) => item.length > 0)
|
|
67
|
+
}))
|
|
68
|
+
};
|
|
69
|
+
}
|
|
46
70
|
}
|
|
47
71
|
};
|
|
72
|
+
schema.hideInvalidProperties(result);
|
|
73
|
+
return result;
|
|
48
74
|
}
|
|
49
75
|
function typeboxErrorsToArriError(errs) {
|
|
50
76
|
const mappedErrs = [];
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SCHEMA_METADATA, ValidationError } from '@arrirpc/schema';
|
|
1
|
+
import { SCHEMA_METADATA, hideInvalidProperties, ValidationError } from '@arrirpc/schema';
|
|
2
2
|
import { OptionalKind } from '@sinclair/typebox';
|
|
3
3
|
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
|
4
4
|
import { Value } from '@sinclair/typebox/value';
|
|
@@ -7,7 +7,7 @@ import { jsonSchemaToJtdSchema } from 'json-schema-to-atd';
|
|
|
7
7
|
function typeboxAdapter(input) {
|
|
8
8
|
const schema = jsonSchemaToJtdSchema(input);
|
|
9
9
|
const compiled = TypeCompiler.Compile(input);
|
|
10
|
-
|
|
10
|
+
const result = {
|
|
11
11
|
...schema,
|
|
12
12
|
metadata: {
|
|
13
13
|
id: input.$id ?? input.title,
|
|
@@ -41,8 +41,34 @@ function typeboxAdapter(input) {
|
|
|
41
41
|
return compiled.Encode(val);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
},
|
|
45
|
+
"~standard": {
|
|
46
|
+
version: 1,
|
|
47
|
+
vendor: "arri-typebox",
|
|
48
|
+
validate(value) {
|
|
49
|
+
if (compiled.Check(value)) {
|
|
50
|
+
return {
|
|
51
|
+
value
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === "string") {
|
|
55
|
+
const parsedVal = JSON.parse(value);
|
|
56
|
+
if (compiled.Check(parsedVal)) {
|
|
57
|
+
return parsedVal;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const errors = typeboxErrorsToArriError(compiled.Errors(value));
|
|
61
|
+
return {
|
|
62
|
+
issues: errors.errors.map((err) => ({
|
|
63
|
+
message: err.message ?? "Unknown error",
|
|
64
|
+
path: err.instancePath.split("/").filter((item) => item.length > 0)
|
|
65
|
+
}))
|
|
66
|
+
};
|
|
67
|
+
}
|
|
44
68
|
}
|
|
45
69
|
};
|
|
70
|
+
hideInvalidProperties(result);
|
|
71
|
+
return result;
|
|
46
72
|
}
|
|
47
73
|
function typeboxErrorsToArriError(errs) {
|
|
48
74
|
const mappedErrs = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/typebox-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"directory": "languages/ts/ts-schema-typebox-adapter"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"json-schema-to-atd": "0.
|
|
26
|
-
"@arrirpc/schema": "0.
|
|
25
|
+
"json-schema-to-atd": "0.71.1",
|
|
26
|
+
"@arrirpc/schema": "0.71.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@arrirpc/server": "0.
|
|
29
|
+
"@arrirpc/server": "0.71.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@sinclair/typebox": "^0.32"
|