@real-router/search-schema-plugin 0.2.0 → 0.2.2

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 +23 -0
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -172,6 +172,29 @@ router.usePlugin(
172
172
  );
173
173
  ```
174
174
 
175
+ ## Schema ↔ Format Coercion
176
+
177
+ The plugin validates **decoded** values (not raw URL strings). The coercion from URL string to typed value happens at the `search-params` layer, controlled by `queryParams` options on the router. Align your schema types with the format options:
178
+
179
+ | Schema | Required `queryParams` option | URL example | Plugin sees |
180
+ | ---------------------- | ------------------------------------ | ---------------- | ----------------- |
181
+ | `z.boolean()` | `booleanFormat: "auto"` (default) | `?compact=true` | `{ compact: true }` |
182
+ | `z.boolean()` | `booleanFormat: "empty-true"` | `?compact` | `{ compact: true }` |
183
+ | `z.number().int()` | `numberFormat: "auto"` (default) | `?page=2` | `{ page: 2 }` |
184
+ | `z.string()` | Any | `?q=hello` | `{ q: "hello" }` |
185
+ | `z.array(z.string())` | `arrayFormat: "brackets"` (or other) | `?tags[]=a&tags[]=b` | `{ tags: ["a", "b"] }` |
186
+
187
+ **Gotcha — mismatched config:** if schema declares `z.boolean()` but `booleanFormat: "none"` is set, the plugin receives the string `"true"` / `"false"` and Zod's `z.boolean()` will reject it. Fix:
188
+
189
+ - Switch to `booleanFormat: "auto"` (recommended), OR
190
+ - Use `z.coerce.boolean()` in the schema (accepts strings)
191
+
192
+ Same applies for numbers — use `z.coerce.number()` if `numberFormat: "none"` is set.
193
+
194
+ **Recommended baseline:** keep `queryParams` defaults (`booleanFormat: "auto"`, `numberFormat: "auto"`, `nullFormat: "default"`) unless you have a specific URL aesthetic preference. Defaults align well with typical Zod/Valibot/ArkType schemas.
195
+
196
+ See [@real-router/core — Params Contract](../core/README.md#params-contract) for the full type-to-URL mapping.
197
+
175
198
  ## Documentation
176
199
 
177
200
  Full documentation: [Wiki — search-schema-plugin](https://github.com/greydragon888/real-router/wiki/search-schema-plugin)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/search-schema-plugin",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "commonjs",
5
5
  "description": "Runtime search parameter validation via Standard Schema for Real-Router",
6
6
  "main": "./dist/cjs/index.js",
@@ -46,15 +46,15 @@
46
46
  "homepage": "https://github.com/greydragon888/real-router",
47
47
  "sideEffects": false,
48
48
  "dependencies": {
49
- "@real-router/core": "^0.47.0"
49
+ "@real-router/core": "^0.48.1"
50
50
  },
51
51
  "scripts": {
52
52
  "test": "vitest",
53
53
  "test:properties": "vitest run --config vitest.config.properties.mts",
54
- "build": "tsdown --config-loader unrun",
55
54
  "type-check": "tsc --noEmit",
56
55
  "lint": "eslint --cache --ext .ts src/ tests/ --fix --max-warnings 0",
57
56
  "lint:package": "publint",
58
- "lint:types": "attw --pack ."
57
+ "lint:types": "attw --pack .",
58
+ "bundle": "tsdown --config-loader unrun"
59
59
  }
60
60
  }