fastify-ata 0.4.2 → 0.5.0
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/package.json +2 -2
- package/test-types.ts +49 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify-ata",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Fastify plugin for ata-validator. Runtime-competitive with the default, 24x faster serverless cold start, Standard Schema V1.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/ata-core/fastify-ata#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"ata-validator": "^0.
|
|
29
|
+
"ata-validator": "^0.18.0",
|
|
30
30
|
"fastify-plugin": "^5.1.0",
|
|
31
31
|
"sanitize-filename": "^1.6.4"
|
|
32
32
|
},
|
package/test-types.ts
CHANGED
|
@@ -36,3 +36,52 @@ app.get('/search', {
|
|
|
36
36
|
void _q
|
|
37
37
|
return { ok: true }
|
|
38
38
|
})
|
|
39
|
+
|
|
40
|
+
// anyOf body narrows to a union
|
|
41
|
+
app.post('/event', {
|
|
42
|
+
schema: {
|
|
43
|
+
body: defineSchema({
|
|
44
|
+
anyOf: [
|
|
45
|
+
{ type: 'object', properties: { kind: { const: 'a' }, n: { type: 'number' } }, required: ['kind', 'n'] },
|
|
46
|
+
{ type: 'object', properties: { kind: { const: 'b' }, s: { type: 'string' } }, required: ['kind', 's'] },
|
|
47
|
+
],
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
}, async (req) => {
|
|
51
|
+
const _exact: Expect<typeof req.body, { kind: 'a'; n: number } | { kind: 'b'; s: string }> = true
|
|
52
|
+
void _exact
|
|
53
|
+
return { ok: true }
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// $ref body resolves the referenced $defs entry
|
|
57
|
+
app.post('/place', {
|
|
58
|
+
schema: {
|
|
59
|
+
body: defineSchema({
|
|
60
|
+
$defs: { Point: { type: 'object', properties: { x: { type: 'number' }, y: { type: 'number' } }, required: ['x', 'y'] } },
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: { at: { $ref: '#/$defs/Point' } },
|
|
63
|
+
required: ['at'],
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
}, async (req) => {
|
|
67
|
+
const _x: number = req.body.at.x
|
|
68
|
+
const _exact: Expect<typeof req.body, { at: { x: number; y: number } }> = true
|
|
69
|
+
void _x; void _exact
|
|
70
|
+
return { ok: true }
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// allOf body narrows to an intersection
|
|
74
|
+
app.post('/merged', {
|
|
75
|
+
schema: {
|
|
76
|
+
body: defineSchema({
|
|
77
|
+
allOf: [
|
|
78
|
+
{ type: 'object', properties: { a: { type: 'number' } }, required: ['a'] },
|
|
79
|
+
{ type: 'object', properties: { b: { type: 'string' } }, required: ['b'] },
|
|
80
|
+
],
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
}, async (req) => {
|
|
84
|
+
const _exact: Expect<typeof req.body, { a: number; b: string }> = true
|
|
85
|
+
void _exact
|
|
86
|
+
return { ok: true }
|
|
87
|
+
})
|