fastify-ata 0.2.23 → 0.3.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/README.md +47 -27
- package/index.d.ts +6 -4
- package/index.js +1 -0
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -44,11 +44,14 @@ All your existing JSON Schema route definitions work as-is.
|
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
46
|
fastify.register(fastifyAta, {
|
|
47
|
-
coerceTypes: true, // convert "42"
|
|
47
|
+
coerceTypes: true, // convert "42" -> 42 for integer fields
|
|
48
48
|
removeAdditional: true, // strip properties not in schema
|
|
49
|
+
abortEarly: true, // skip detailed error collection (faster invalid path)
|
|
49
50
|
})
|
|
50
51
|
```
|
|
51
52
|
|
|
53
|
+
`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.
|
|
54
|
+
|
|
52
55
|
## Standalone Mode (Pre-compiled)
|
|
53
56
|
|
|
54
57
|
Drop-in replacement for `@fastify/ajv-compiler/standalone`. Same API.
|
|
@@ -107,37 +110,54 @@ Works with Fastify v5's Standard Schema support, tRPC, TanStack Form, Drizzle OR
|
|
|
107
110
|
|
|
108
111
|
## Performance
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
All numbers below are reproducible on M4 Pro / Node 25 with the benchmarks in this repo and in `ata-validator/benchmark`. Run-to-run noise is roughly +/- 5% at these scales.
|
|
114
|
+
|
|
115
|
+
### Fastify pipeline (autocannon, 10 connections, pipelining 10)
|
|
111
116
|
|
|
112
|
-
| Payload |
|
|
117
|
+
| Payload | ajv (default) | ata | delta |
|
|
113
118
|
|---|---|---|---|
|
|
114
|
-
|
|
|
115
|
-
| 10
|
|
116
|
-
|
|
|
117
|
-
| 100 users (9.1KB) | 24.6K | 22.6K | +9% |
|
|
119
|
+
| valid (10 fields) | ~70,000 req/s | ~70,500 req/s | tied |
|
|
120
|
+
| invalid (10 fields) | ~51,000 req/s | ~52,500 req/s | +3% |
|
|
121
|
+
| invalid (abortEarly) | ~51,000 req/s | ~52,800 req/s | +3.5% |
|
|
118
122
|
|
|
119
|
-
|
|
123
|
+
HTTP + JSON.parse + routing dominate the pipeline, so validator choice is small on throughput. The real difference is elsewhere.
|
|
120
124
|
|
|
121
|
-
|
|
125
|
+
### Where ata-validator moves the needle
|
|
126
|
+
|
|
127
|
+
| Scenario | ajv | ata | delta |
|
|
122
128
|
|---|---|---|---|
|
|
123
|
-
| **
|
|
124
|
-
| **
|
|
125
|
-
| **
|
|
126
|
-
| **ReDoS
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
| **Serverless cold start** (10 routes, first request) | 12.4 ms | 0.5 ms | **24x faster** |
|
|
130
|
+
| **Startup** (200 routes) | 7.0 ms | 2.4 ms | **2.9x faster** |
|
|
131
|
+
| **Invalid validation** (with abortEarly) | ~15 ns/op | 3.7 ns/op | **4x faster** |
|
|
132
|
+
| **ReDoS pattern** `^(a+)+$` | 765 ms | 0.3 ms | **immune (RE2)** |
|
|
133
|
+
|
|
134
|
+
Serverless cold start is the scenario that matters for Vercel, Cloudflare Workers, Fly.io and similar platforms. On a long-running box the gap closes, so classic servers will not see a throughput jump.
|
|
135
|
+
|
|
136
|
+
### Build-time compile (optional)
|
|
137
|
+
|
|
138
|
+
For browser / edge deployments, ata ships an `ata compile` CLI that turns a JSON Schema into a self-contained `.mjs` plus TypeScript declarations.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npx ata compile schemas/user.json -o src/user.validator.mjs --name User
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
A 10-field schema produces:
|
|
145
|
+
|
|
146
|
+
| Variant | Raw | Gzipped |
|
|
147
|
+
|---|---|---|
|
|
148
|
+
| ata runtime bundle | 117 KB | 27 KB |
|
|
149
|
+
| `ata compile` standard | 4.9 KB | **1.2 KB** |
|
|
150
|
+
| `ata compile --abort-early` | 1.3 KB | **0.6 KB** |
|
|
151
|
+
|
|
152
|
+
Generated file has zero runtime dependency on `ata-validator`. `isValid` is emitted as a TypeScript type predicate, so consumers get narrowing out of the box.
|
|
153
|
+
|
|
154
|
+
### Features worth calling out
|
|
155
|
+
|
|
156
|
+
- **RE2 regex** - linear-time guaranteed, immune to catastrophic backtracking
|
|
157
|
+
- **simdjson** - SIMD-accelerated JSON parsing for buffer-input paths
|
|
158
|
+
- **Multi-core** - `countValid(ndjsonBuf)` validates many messages in one native call
|
|
159
|
+
- **Standard Schema V1** - native support, works with Fastify v5, tRPC, TanStack Form, Drizzle
|
|
160
|
+
- **Draft 2020-12 and Draft 7** - 98.5% compliance on the official JSON Schema Test Suite
|
|
141
161
|
|
|
142
162
|
## License
|
|
143
163
|
|
package/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { FastifyPluginCallback } from 'fastify'
|
|
2
2
|
|
|
3
3
|
interface FastifyAtaOptions {
|
|
4
|
+
/** Convert "42" -> 42 for integer fields, etc. */
|
|
4
5
|
coerceTypes?: boolean
|
|
6
|
+
/** Strip properties that are not declared in the schema. */
|
|
5
7
|
removeAdditional?: boolean
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* Skip detailed error collection on validation failure. Returns a shared
|
|
10
|
+
* stub error object instead. Useful for high-throughput route guards that
|
|
11
|
+
* only care about reject/accept.
|
|
10
12
|
*/
|
|
11
|
-
|
|
13
|
+
abortEarly?: boolean
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
declare const fastifyAta: FastifyPluginCallback<FastifyAtaOptions>
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify-ata",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Fastify plugin for ata-validator
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"ata-validator",
|
|
20
20
|
"standard-schema"
|
|
21
21
|
],
|
|
22
|
-
"author": "Mert Can Altin <
|
|
22
|
+
"author": "Mert Can Altin <mertgold60@gmail.com>",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/ata-core/fastify-ata/issues"
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"homepage": "https://github.com/ata-core/fastify-ata#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"ata-validator": "^0.11.0",
|
|
30
|
-
"fastify-ata": "^0.2.21",
|
|
31
30
|
"fastify-plugin": "^5.1.0",
|
|
32
31
|
"sanitize-filename": "^1.6.4"
|
|
33
32
|
},
|