@queryweave/vue-router 0.1.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QueryWeave contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # `@queryweave/vue-router`
2
+
3
+ A `QueryAdapter` backed by Vue Router.
4
+
5
+ ```ts
6
+ import { createVueRouterAdapter } from "@queryweave/vue-router";
7
+
8
+ const adapter = createVueRouterAdapter(router, {
9
+ onNavigationFailure: (outcome) => report(outcome),
10
+ });
11
+ ```
12
+
13
+ It normalizes router query values, keeps path and hash, observes route changes, and reports
14
+ navigation failures instead of throwing. It owns no codec logic, no validation logic, and no Vue
15
+ binding logic, and depends on `@queryweave/core` alone — router synchronization can be adopted
16
+ without the Vue binding.
17
+
18
+ Vue and Vue Router are peer dependencies.
@@ -0,0 +1,36 @@
1
+ import { QueryAdapter } from "@queryweave/core";
2
+ import { NavigationFailure, Router } from "vue-router";
3
+ //#region src/index.d.ts
4
+ /**
5
+ * Vue Router adapter.
6
+ *
7
+ * This package owns synchronization only. It never decodes, validates, applies defaults, or
8
+ * duplicates the Vue binding.
9
+ */
10
+ /** Reported when a router transition is rejected or redirected. */
11
+ type VueRouterNavigationOutcome = {
12
+ readonly ok: true;
13
+ } | {
14
+ readonly ok: false;
15
+ readonly failure: NavigationFailure | Error;
16
+ };
17
+ /** Options accepted by {@link createVueRouterAdapter}. */
18
+ interface VueRouterAdapterOptions {
19
+ /** Invoked instead of throwing when the router rejects a transition. */
20
+ readonly onNavigationFailure?: ((outcome: VueRouterNavigationOutcome) => void) | undefined;
21
+ }
22
+ /** A Vue Router adapter with deterministic cleanup. */
23
+ interface VueRouterQueryAdapter extends QueryAdapter {
24
+ readonly router: Router;
25
+ dispose(): void;
26
+ }
27
+ /**
28
+ * Create an adapter backed by a Vue Router instance.
29
+ *
30
+ * Path and hash are preserved on every transition; unmanaged query keys are preserved by the
31
+ * runtime that owns the model.
32
+ */
33
+ declare function createVueRouterAdapter(router: Router, options?: VueRouterAdapterOptions): VueRouterQueryAdapter;
34
+ //#endregion
35
+ export { VueRouterAdapterOptions, VueRouterNavigationOutcome, VueRouterQueryAdapter, createVueRouterAdapter };
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;KAYY;WACG;;WACA;WAAoB,SAAS,oBAAoB;;;UAG/C;;WAEN,wBAAwB,SAAS;;;UAI3B,8BAA8B;WACpC,QAAQ;EACjB;;;;;;;;iBA+Cc,uBACd,QAAQ,QACR,UAAS,0BACR"}
package/dist/index.js ADDED
@@ -0,0 +1,103 @@
1
+ import { watch } from "vue";
2
+
3
+ //#region src/index.ts
4
+ function toEntries(query) {
5
+ const entries = [];
6
+ for (const [key, value] of Object.entries(query)) {
7
+ if (value === null) {
8
+ entries.push([key, ""]);
9
+ continue;
10
+ }
11
+ if (typeof value === "string") {
12
+ entries.push([key, value]);
13
+ continue;
14
+ }
15
+ if (value === void 0) continue;
16
+ for (const item of value) entries.push([key, item ?? ""]);
17
+ }
18
+ return entries;
19
+ }
20
+ function toRawQuery(output) {
21
+ const query = {};
22
+ for (const [key, value] of output) {
23
+ const existing = query[key];
24
+ if (existing === void 0) {
25
+ query[key] = value;
26
+ continue;
27
+ }
28
+ if (typeof existing === "string") {
29
+ query[key] = [existing, value];
30
+ continue;
31
+ }
32
+ existing.push(value);
33
+ }
34
+ return query;
35
+ }
36
+ /**
37
+ * Create an adapter backed by a Vue Router instance.
38
+ *
39
+ * Path and hash are preserved on every transition; unmanaged query keys are preserved by the
40
+ * runtime that owns the model.
41
+ */
42
+ function createVueRouterAdapter(router, options = {}) {
43
+ const listeners = /* @__PURE__ */ new Set();
44
+ let stopWatching;
45
+ let disposed = false;
46
+ const read = () => toEntries(router.currentRoute.value.query);
47
+ const notify = () => {
48
+ const input = read();
49
+ for (const listener of [...listeners]) listener(input);
50
+ };
51
+ const report = (outcome) => {
52
+ options.onNavigationFailure?.(outcome);
53
+ };
54
+ const navigate = async (next, mode) => {
55
+ if (disposed) throw new Error("This Vue Router query adapter was disposed.");
56
+ const route = router.currentRoute.value;
57
+ const target = {
58
+ path: route.path,
59
+ hash: route.hash,
60
+ query: toRawQuery(next)
61
+ };
62
+ try {
63
+ const failure = await (mode === "replace" ? router.replace(target) : router.push(target));
64
+ report(failure === void 0 || failure === null ? { ok: true } : {
65
+ ok: false,
66
+ failure
67
+ });
68
+ } catch (error) {
69
+ report({
70
+ ok: false,
71
+ failure: error instanceof Error ? error : new Error(String(error))
72
+ });
73
+ }
74
+ };
75
+ const attach = () => {
76
+ stopWatching ??= watch(() => router.currentRoute.value.fullPath, () => {
77
+ notify();
78
+ }, { flush: "post" });
79
+ };
80
+ return {
81
+ router,
82
+ read,
83
+ push: async (next) => navigate(next, "push"),
84
+ replace: async (next) => navigate(next, "replace"),
85
+ subscribe: (listener) => {
86
+ attach();
87
+ listeners.add(listener);
88
+ return () => {
89
+ listeners.delete(listener);
90
+ };
91
+ },
92
+ dispose: () => {
93
+ disposed = true;
94
+ listeners.clear();
95
+ stopWatching?.();
96
+ stopWatching = void 0;
97
+ }
98
+ };
99
+ }
100
+
101
+ //#endregion
102
+ export { createVueRouterAdapter };
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { QueryAdapter, QueryChangeListener, QueryEntry, QueryOutput } from \"@queryweave/core\";\nimport { watch } from \"vue\";\nimport type { LocationQuery, LocationQueryRaw, NavigationFailure, Router } from \"vue-router\";\n\n/**\n * Vue Router adapter.\n *\n * This package owns synchronization only. It never decodes, validates, applies defaults, or\n * duplicates the Vue binding.\n */\n\n/** Reported when a router transition is rejected or redirected. */\nexport type VueRouterNavigationOutcome =\n | { readonly ok: true }\n | { readonly ok: false; readonly failure: NavigationFailure | Error };\n\n/** Options accepted by {@link createVueRouterAdapter}. */\nexport interface VueRouterAdapterOptions {\n /** Invoked instead of throwing when the router rejects a transition. */\n readonly onNavigationFailure?: ((outcome: VueRouterNavigationOutcome) => void) | undefined;\n}\n\n/** A Vue Router adapter with deterministic cleanup. */\nexport interface VueRouterQueryAdapter extends QueryAdapter {\n readonly router: Router;\n dispose(): void;\n}\n\nfunction toEntries(query: LocationQuery): QueryOutput {\n const entries: QueryEntry[] = [];\n for (const [key, value] of Object.entries(query)) {\n if (value === null) {\n entries.push([key, \"\"]);\n continue;\n }\n if (typeof value === \"string\") {\n entries.push([key, value]);\n continue;\n }\n if (value === undefined) {\n continue;\n }\n for (const item of value) {\n entries.push([key, item ?? \"\"]);\n }\n }\n return entries;\n}\n\nfunction toRawQuery(output: QueryOutput): LocationQueryRaw {\n const query: Record<string, string | string[]> = {};\n for (const [key, value] of output) {\n const existing = query[key];\n if (existing === undefined) {\n query[key] = value;\n continue;\n }\n if (typeof existing === \"string\") {\n query[key] = [existing, value];\n continue;\n }\n existing.push(value);\n }\n return query;\n}\n\n/**\n * Create an adapter backed by a Vue Router instance.\n *\n * Path and hash are preserved on every transition; unmanaged query keys are preserved by the\n * runtime that owns the model.\n */\nexport function createVueRouterAdapter(\n router: Router,\n options: VueRouterAdapterOptions = {},\n): VueRouterQueryAdapter {\n const listeners = new Set<QueryChangeListener>();\n let stopWatching: (() => void) | undefined;\n let disposed = false;\n\n const read = (): QueryOutput => toEntries(router.currentRoute.value.query);\n\n const notify = (): void => {\n const input = read();\n for (const listener of [...listeners]) {\n listener(input);\n }\n };\n\n const report = (outcome: VueRouterNavigationOutcome): void => {\n options.onNavigationFailure?.(outcome);\n };\n\n const navigate = async (next: QueryOutput, mode: \"push\" | \"replace\"): Promise<void> => {\n if (disposed) {\n throw new Error(\"This Vue Router query adapter was disposed.\");\n }\n const route = router.currentRoute.value;\n const target = { path: route.path, hash: route.hash, query: toRawQuery(next) };\n try {\n const failure = await (mode === \"replace\" ? router.replace(target) : router.push(target));\n report(failure === undefined || failure === null ? { ok: true } : { ok: false, failure });\n } catch (error) {\n report({ ok: false, failure: error instanceof Error ? error : new Error(String(error)) });\n }\n };\n\n const attach = (): void => {\n stopWatching ??= watch(\n () => router.currentRoute.value.fullPath,\n () => {\n notify();\n },\n { flush: \"post\" },\n );\n };\n\n return {\n router,\n read,\n push: async (next) => navigate(next, \"push\"),\n replace: async (next) => navigate(next, \"replace\"),\n subscribe: (listener) => {\n attach();\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose: () => {\n disposed = true;\n listeners.clear();\n stopWatching?.();\n stopWatching = undefined;\n },\n };\n}\n"],"mappings":";;;AA4BA,SAAS,UAAU,OAAmC;CACpD,MAAM,UAAwB,CAAC;CAC/B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAAG;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AO,EAAE,IAAI,KAAK,IAAI;IAAE,IAAI;IAAO;GAAQ,CAAC;EAC1F,SAAS,OAAO;GACd,OAAO;IAAE,IAAI;IAAO,SAAS,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;GAAE,CAAC;EAC1F;CACF;CAEA,MAAM,eAAqB;EACzB,iBAAiB,YACT,OAAO,aAAa,MAAM,gBAC1B;GACJ,OAAO;EACT,GACA,EAAE,OAAO,OAAO,CAClB;CACF;CAEA,OAAO;EACL;EACA;EACA,MAAM,OAAO,SAAS,SAAS,MAAM,MAAM;EAC3C,SAAS,OAAO,SAAS,SAAS,MAAM,SAAS;EACjD,YAAY,aAAa;GACvB,OAAO;GACP,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,eAAe;GACb,WAAW;GACX,UAAU,MAAM;GAChB,eAAe;GACf,eAAe;EACjB;CACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@queryweave/vue-router",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Vue Router adapter contracts for QueryWeave.",
5
+ "keywords": [
6
+ "query",
7
+ "state",
8
+ "url",
9
+ "vue",
10
+ "vue-router"
11
+ ],
12
+ "homepage": "https://github.com/boussadjra/queryweave#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/boussadjra/queryweave/issues"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/boussadjra/queryweave.git",
20
+ "directory": "packages/vue-router"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true
39
+ },
40
+ "dependencies": {
41
+ "@queryweave/core": "0.1.0-alpha.1"
42
+ },
43
+ "devDependencies": {
44
+ "vue": "3.5.40",
45
+ "vue-router": "5.2.0",
46
+ "@queryweave/typescript-config": "0.0.0"
47
+ },
48
+ "peerDependencies": {
49
+ "vue": ">=3.5.0 <4",
50
+ "vue-router": ">=5.2.0 <6"
51
+ },
52
+ "engines": {
53
+ "node": ">=24.18.0"
54
+ },
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "dev": "tsdown --watch",
58
+ "typecheck": "tsc -p tsconfig.json",
59
+ "test:types": "tsc -p tsconfig.json",
60
+ "package:check": "publint --strict && attw --pack . --profile esm-only",
61
+ "clean": "node ../../scripts/clean-package.mjs"
62
+ }
63
+ }