@real-router/search-schema-plugin 0.2.8 → 0.2.9
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/dist/cjs/index.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core/api");const t=`[search-schema-plugin]`;function n(e){let t=new Set;for(let n of e)if(n.path&&n.path.length>0){let e=n.path[0],r=typeof e==`object`&&`key`in e?e.key:e;t.add(String(r))}return t}function r(e,t){let n={};for(let r of Object.keys(e))t.has(r)||(n[r]=e[r]);return n}var i=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n.mode??`development`,this.#r=n.strict??!1,this.#i=n.onError,this.#l(),this.#a=this.#e.addInterceptor(`forwardState`,(e,t,n)=>{let r=e(t,n);return this.#c(r)}),this.#o=this.#e.addInterceptor(`add`,(e,t,n)=>{e(t,n),this.#f(t,n?.parent)})}getPlugin(){return{teardown:()=>{this.#a(),this.#o()}}}#s(e){return this.#e.getRouteConfig(e)?.searchSchema}#c(e){let i=this.#s(e.name);if(!i)return e;let a=i[`~standard`].validate(e.params);if(a instanceof Promise)throw TypeError(`${t} Async schema validation is not supported. Route "${e.name}" returned a Promise from ~standard.validate().`);if(`value`in a){let t=this.#r?a.value:{...e.params,...a.value};return{...e,params:t}}if(this.#i)return{...e,params:this.#i(e.name,e.params,a.issues)};this.#n===`development`&&console.error(`${t} Route "${e.name}": invalid search params`,a.issues);let o=n(a.issues),s=r(e.params,o),c=this.#t.get(e.name)?.defaultParams,l=c?{...c,...s}:s;return{...e,params:l}}#l(){if(this.#n!==`development`)return;let e=this.#e.getTree();e&&this.#u(e)}#u(e){if(e.fullName&&this.#d(e.fullName),e.children instanceof Map)for(let t of e.children.values())t&&typeof t==`object`&&this.#u(t)}#d(e){let n=this.#s(e);if(!n)return;let r=this.#t.get(e)?.defaultParams;if(!r)return;let i=n[`~standard`].validate(r);i instanceof Promise||`issues`in i&&console.warn(`${t} Route "${e}": defaultParams do not pass searchSchema`,i.issues)}#f(e,t=``){if(this.#n===`development`){for(let n of e)if(n.name){let e=t?`${t}.${n.name}`:n.name;this.#d(e),n.children&&this.#f(n.children,e)}}}};const a=new Set([`development`,`production`]);function o(e){if(e.mode!==void 0&&!a.has(e.mode))throw TypeError(`${t} Invalid mode: "${e.mode}". Must be "development" or "production".`);if(e.strict!==void 0&&typeof e.strict!=`boolean`)throw TypeError(`${t} Invalid strict option: expected boolean, got ${typeof e.strict}.`);if(e.onError!==void 0&&typeof e.onError!=`function`)throw TypeError(`${t} Invalid onError: expected function, got ${typeof e.onError}.`)}function s(t={}){o(t);let n=Object.freeze({...t});return t=>new i((0,e.getPluginApi)(t),(0,e.getRoutesApi)(t),n).getPlugin()}exports.searchSchemaPlugin=s;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/search-schema-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
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,7 +46,7 @@
|
|
|
46
46
|
"homepage": "https://github.com/greydragon888/real-router",
|
|
47
47
|
"sideEffects": false,
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@real-router/core": "^0.
|
|
49
|
+
"@real-router/core": "^0.55.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"test": "vitest",
|