@rine-kit/pubg-tools 0.1.1 → 0.1.3
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/schema-shape.d.ts +1 -0
- package/dist/schema-shape.js +36 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function schemaShape(schema: unknown): unknown;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const KEEP = ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'minLength', 'maxLength', 'minItems', 'maxItems', 'pattern'];
|
|
2
|
+
export function schemaShape(schema) {
|
|
3
|
+
if (typeof schema !== 'object' || schema === null)
|
|
4
|
+
return schema;
|
|
5
|
+
const s = schema;
|
|
6
|
+
const out = {};
|
|
7
|
+
const enumValues = Array.isArray(s.enum) ? s.enum : 'const' in s ? [s.const] : undefined;
|
|
8
|
+
if (enumValues)
|
|
9
|
+
out.enum = [...enumValues].sort();
|
|
10
|
+
else if (typeof s.type === 'string')
|
|
11
|
+
out.type = s.type === 'number' && s.multipleOf === 1 ? 'integer' : s.type;
|
|
12
|
+
for (const key of KEEP)
|
|
13
|
+
if (key in s)
|
|
14
|
+
out[key] = s[key];
|
|
15
|
+
if (s.properties && typeof s.properties === 'object') {
|
|
16
|
+
out.properties = Object.fromEntries(Object.entries(s.properties)
|
|
17
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
18
|
+
.map(([k, v]) => [k, schemaShape(v)]));
|
|
19
|
+
out.required = Array.isArray(s.required) ? [...s.required].sort() : [];
|
|
20
|
+
out.additionalProperties = s.additionalProperties === false ? false : true;
|
|
21
|
+
}
|
|
22
|
+
if (s.items)
|
|
23
|
+
out.items = schemaShape(s.items);
|
|
24
|
+
const union = (s.anyOf ?? s.oneOf);
|
|
25
|
+
if (union) {
|
|
26
|
+
const shapes = union.map(schemaShape);
|
|
27
|
+
// TypeBox spells an enum as a union of one-value literals, zod as one enum: both mean the same thing.
|
|
28
|
+
if (shapes.every((shape) => Array.isArray(shape.enum) && Object.keys(shape).length === 1)) {
|
|
29
|
+
out.enum = shapes.flatMap((shape) => shape.enum).sort();
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
out.anyOf = shapes.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rine-kit/pubg-tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The PUBG tool catalogue shared by every host: names, descriptions, validated inputs (zod) and the call into PubgDomainService. Hosts add only identity resolution and result delivery. Extracted from Lab's plugins/pubg.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"zod": "^4.6.7",
|
|
22
|
-
"@rine-kit/pubg-domain": "0.1.
|
|
22
|
+
"@rine-kit/pubg-domain": "0.1.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^26.6.5",
|