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 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" 42 for integer fields
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
- ### Real-world HTTP benchmark (autocannon, 10 connections, 5s)
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 | ata | ajv | |
117
+ | Payload | ajv (default) | ata | delta |
113
118
  |---|---|---|---|
114
- | 1 user (0.1KB) | 65.7K req/sec | 65.7K req/sec | equal |
115
- | 10 users (0.9KB) | 57.2K | 55.3K | +3% |
116
- | 50 users (4.6KB) | 36.0K | 33.8K | +6% |
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
- ### Where ata really shines
123
+ HTTP + JSON.parse + routing dominate the pipeline, so validator choice is small on throughput. The real difference is elsewhere.
120
124
 
121
- | Scenario | ata | ajv | |
125
+ ### Where ata-validator moves the needle
126
+
127
+ | Scenario | ajv | ata | delta |
122
128
  |---|---|---|---|
123
- | **Constructor cold start** | 1.25M ops/sec | 873 ops/sec | **1,432x faster** |
124
- | **Serverless cold start** (50 schemas) | 0.1ms | 23ms | **242x faster** |
125
- | **First validation** (construct + validate) | 15.7K ops/sec | 855 ops/sec | **18x faster** |
126
- | **ReDoS protection** (catastrophic pattern) | 0.3ms | 765ms | **immune** |
127
- | **Batch NDJSON** (10K items, multi-core) | 13.4M/sec | 5.1M/sec | **2.6x faster** |
128
- | **validate(obj)** valid (isolated) | 14.6M ops/sec | 8.3M ops/sec | **1.8x faster** |
129
- | **validate(obj)** invalid (isolated) | 12.9M ops/sec | 8.0M ops/sec | **1.6x faster** |
130
- | **validateJSON(str)** valid | 2.1M ops/sec | 1.9M ops/sec | **1.1x faster** |
131
- | **Fastify startup** (5 routes) | 0.5ms | 6.0ms | **12x faster** |
132
- | **Schema compilation** | 136K ops/sec | 794 ops/sec | **171x faster** |
133
-
134
- ### Things only ata can do
135
-
136
- - **RE2 regex engine** - linear-time guaranteed, immune to ReDoS attacks
137
- - **Multi-core parallel validation** - NDJSON batch at 12.5M items/sec
138
- - **Standard Schema V1** - native support, ajv doesn't have it
139
- - **Lazy compilation** - near-zero constructor, 1,432x faster cold start
140
- - **171x faster compilation** - serverless cold starts, dynamic schemas
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
- * Enable turbo mode: overrides the JSON content-type parser to receive
8
- * the raw Buffer and uses simdjson-backed validateJSON for validation
9
- * instead of V8's JSON.parse path. Incompatible with coerceTypes.
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
- turbo?: boolean
13
+ abortEarly?: boolean
12
14
  }
13
15
 
14
16
  declare const fastifyAta: FastifyPluginCallback<FastifyAtaOptions>
package/index.js CHANGED
@@ -9,6 +9,7 @@ function fastifyAta(fastify, opts, done) {
9
9
  const validatorOpts = {
10
10
  coerceTypes: opts.coerceTypes || false,
11
11
  removeAdditional: opts.removeAdditional || false,
12
+ abortEarly: opts.abortEarly || false,
12
13
  }
13
14
 
14
15
  fastify.setValidatorCompiler(({ schema }) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fastify-ata",
3
- "version": "0.2.23",
4
- "description": "Fastify plugin for ata-validator beats ajv on every valid-path benchmark. 2.7x faster validate(obj), 151x faster compilation, simdjson + multi-core.",
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 <mertcanaltin01@gmail.com>",
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
  },