@real-router/validation-plugin 0.13.2 → 0.13.4
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 +20 -2
- package/dist/cjs/index.d.ts +15 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +15 -2
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,10 +54,28 @@ Core's crash guards always run, regardless of whether this plugin is installed.
|
|
|
54
54
|
### `validationPlugin()`
|
|
55
55
|
|
|
56
56
|
```typescript
|
|
57
|
-
function validationPlugin
|
|
57
|
+
function validationPlugin<
|
|
58
|
+
Dependencies extends DefaultDependencies = DefaultDependencies,
|
|
59
|
+
>(): PluginFactory<Dependencies>;
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
Returns a `PluginFactory` to pass to `router.usePlugin()`. Takes no
|
|
62
|
+
Returns a `PluginFactory` to pass to `router.usePlugin()`. Takes no runtime
|
|
63
|
+
arguments; the dependency map is a type parameter, normally inferred from the
|
|
64
|
+
router you register it on (#1621). Spell it explicitly only when inference has
|
|
65
|
+
nothing to work from:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
type Deps = Record<string, number>;
|
|
69
|
+
|
|
70
|
+
const router = createRouter<Deps>(routes);
|
|
71
|
+
|
|
72
|
+
router.usePlugin(validationPlugin()); // inferred
|
|
73
|
+
const factory = validationPlugin<Deps>(); // explicit
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Without the parameter the factory would default to `object`, whose `keyof` is
|
|
77
|
+
`never` — and TypeScript 7 refuses to assign that where `PluginFactory<Deps>` is
|
|
78
|
+
expected for any `Deps` carrying an index signature.
|
|
61
79
|
|
|
62
80
|
Throws `RouterError("VALIDATION_PLUGIN_AFTER_START")` if the router is already active. Always register before `router.start()`.
|
|
63
81
|
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import { PluginFactory } from "@real-router/core";
|
|
1
|
+
import { DefaultDependencies, PluginFactory } from "@real-router/core";
|
|
2
2
|
import { RouterValidator } from "@real-router/core/validation";
|
|
3
3
|
//#region src/validationPlugin.d.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The dependency map is a type parameter so the factory carries the CALLER's
|
|
6
|
+
* `D` rather than the `object` default (#1621). `keyof object` is `never`, so a
|
|
7
|
+
* bare `PluginFactory` types `getDependency` as `(key: never) => never`, which
|
|
8
|
+
* TypeScript 7 refuses to assign where `PluginFactory<D>` is expected for any
|
|
9
|
+
* `D` with an index signature — `usePlugin(validationPlugin())` stops compiling
|
|
10
|
+
* for a consumer whose dependencies are `Record<string, T>`. TS 6 skipped that
|
|
11
|
+
* variance check, so the imprecision was always there and simply invisible.
|
|
12
|
+
*
|
|
13
|
+
* `PluginFactory<never>` does NOT work as a shorthand here (unlike
|
|
14
|
+
* `AnyOptions = Options<never>` in core): it fails on both compilers, because
|
|
15
|
+
* this plugin actually reads dependencies.
|
|
16
|
+
*/
|
|
17
|
+
declare function validationPlugin<Dependencies extends DefaultDependencies = DefaultDependencies>(): PluginFactory<Dependencies>;
|
|
5
18
|
//#endregion
|
|
6
19
|
export { type RouterValidator, validationPlugin };
|
|
7
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;iBAqVgB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
|