fastify-ata 0.4.0 → 0.4.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.
Files changed (2) hide show
  1. package/README.md +40 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -44,6 +44,37 @@ fastify.listen({ port: 3000 })
44
44
 
45
45
  All your existing JSON Schema route definitions work as-is.
46
46
 
47
+ ## TypeScript
48
+
49
+ Write plain JSON Schema and get typed route handlers, no builder DSL. Add the `AtaTypeProvider` and author schemas with `defineSchema`:
50
+
51
+ ```ts
52
+ import Fastify from 'fastify'
53
+ import fastifyAta from 'fastify-ata'
54
+ import { defineSchema } from 'ata-validator'
55
+
56
+ const app = Fastify().withTypeProvider<fastifyAta.AtaTypeProvider>()
57
+ await app.register(fastifyAta)
58
+
59
+ app.post('/user', {
60
+ schema: {
61
+ body: defineSchema({
62
+ type: 'object',
63
+ properties: { name: { type: 'string' }, age: { type: 'integer' } },
64
+ required: ['name'],
65
+ }),
66
+ },
67
+ }, (req, reply) => {
68
+ req.body.name // string
69
+ req.body.age // number | undefined
70
+ reply.send({ ok: true })
71
+ })
72
+ ```
73
+
74
+ `defineSchema` preserves the schema's literal types, so `request.body`, `request.query`, `request.params`, and `request.headers` are inferred from the schema. Same idea as `@fastify/type-provider-typebox`, from plain JSON Schema.
75
+
76
+ `ata-validator` falls back to a pure-JS engine where the native addon is not available (Cloudflare Workers, browsers, Bun), so fastify-ata runs in those environments too.
77
+
47
78
  ## Options
48
79
 
49
80
  ```js
@@ -51,9 +82,18 @@ fastify.register(fastifyAta, {
51
82
  coerceTypes: true, // convert "42" -> 42 for integer fields
52
83
  removeAdditional: true, // strip properties not in schema
53
84
  abortEarly: true, // skip detailed error collection (faster invalid path)
85
+ prettyErrors: true, // 400 message carries the ATA code + a did-you-mean
54
86
  })
55
87
  ```
56
88
 
89
+ With `prettyErrors`, a failed request returns a compiler-style message instead of the plain ajv text:
90
+
91
+ ```
92
+ body must have required property 'name' [ATA7001] (did you mean `name` instead of `nme`?)
93
+ ```
94
+
95
+ Off by default to keep the ajv-compatible message shape.
96
+
57
97
  `abortEarly` replaces the error list with a shared stub. Good for public endpoints where only the accept/reject decision reaches the caller. On a 10-property schema the invalid path drops from roughly 15 ns/op to 3.7 ns/op.
58
98
 
59
99
  ## Standalone Mode (Pre-compiled)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-ata",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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.17.0",
29
+ "ata-validator": "^0.17.4",
30
30
  "fastify-plugin": "^5.1.0",
31
31
  "sanitize-filename": "^1.6.4"
32
32
  },