vue-router-query-sync 2.0.0-alpha.0 → 2.0.0-alpha.3

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
@@ -20,43 +20,67 @@ npm install vue-router-query-sync
20
20
 
21
21
  ## `useQueryFilters(schema)`
22
22
 
23
- Returns a reactive object; access fields without `.value`. The type is inferred from the schema.
23
+ Returns `{ filters, patch, reset }`. `filters` is a reactive object of schema fields only
24
+ (no methods on it); access fields without `.value`. The type is inferred from the schema.
24
25
 
25
26
  ```ts
26
27
  import { useQueryFilters, param } from 'vue-router-query-sync'
27
28
 
28
29
  enum SortType { Popular = 'popular', New = 'new' }
29
30
 
30
- const filters = useQueryFilters({
31
+ const { filters, patch, reset } = useQueryFilters({
31
32
  sort: param.enum(SortType, { default: SortType.Popular, history: 'push' }),
32
33
  brands: param.stringArray(), // default: []
33
34
  page: param.number({ default: 1 }),
34
35
  from: param.custom(dateCodec), // default: null
35
36
  })
36
37
 
37
- filters.sort = SortType.New // write -> router navigation
38
- filters.brands // read -> parses route.query
39
- filters.patch({ brands: ['lg'], page: 1 }) // several fields, ONE navigation
40
- filters.reset() // all fields back to defaults (keys removed)
38
+ filters.sort = SortType.New // write -> router navigation
39
+ filters.brands // read -> parses route.query (or pending write)
40
+ patch({ brands: ['lg'], page: 2 }) // several fields, ONE navigation
41
+ reset() // all fields back to defaults (keys removed)
41
42
  ```
42
43
 
43
- - **Read**: `route.query[key]` → `deserialize` → on `undefined`/throw → `default`.
44
+ - **Read**: pending write (same tick) → else `route.query[key]` → `deserialize` → on
45
+ `undefined`/throw → `default`. Reading a field right after writing it returns the new value.
44
46
  - **Write**: `serialize` → if `null` or equal to `serialize(default)` → the key is removed.
45
47
  - Query keys not described in the schema are left untouched.
46
- - `patch` / `reset` are reserved names; using them as param keys throws at creation.
47
- - Destructuring loses reactivity — use Vue's `toRefs(filters)`.
48
+ - Destructuring `filters` loses reactivity use Vue's `toRefs(filters)`.
48
49
 
49
- ## `useQueryParam(key, param)`
50
+ ### Single parameter
50
51
 
51
- Single-parameter wrapper over the same logic. Returns a `WritableComputedRef`.
52
+ There is no separate single-param helper: use a one-key schema and `toRef`.
52
53
 
53
54
  ```ts
54
- import { useQueryParam, param } from 'vue-router-query-sync'
55
+ import { toRef } from 'vue'
56
+ import { useQueryFilters, param } from 'vue-router-query-sync'
55
57
 
56
- const tab = useQueryParam('tab', param.enum(['all', 'favorite'] as const))
58
+ const { filters } = useQueryFilters({ tab: param.enum(['all', 'favorite'] as const) })
59
+ const tab = toRef(filters, 'tab') // WritableComputedRef<'all' | 'favorite' | null>
57
60
  tab.value = 'favorite'
58
61
  ```
59
62
 
63
+ ### `prefix` — namespacing keys
64
+
65
+ When the same schema is used more than once on a page (e.g. one paginated component per
66
+ tab), pass a `prefix` so each instance owns its own URL keys and they don't collide. Field
67
+ names in `filters` stay unprefixed; only the URL key becomes `${prefix}.${key}`.
68
+
69
+ ```ts
70
+ const users = useQueryFilters({ page: param.number({ default: 1 }) }, { prefix: 'users' })
71
+ const orders = useQueryFilters({ page: param.number({ default: 1 }) }, { prefix: 'orders' })
72
+
73
+ users.filters.page = 3 // URL: ?users.page=3
74
+ orders.filters.page = 5 // URL: ?users.page=3&orders.page=5
75
+
76
+ users.filters.page // reads users.page only — independent from orders
77
+ ```
78
+
79
+ Each instance keeps its own state in the URL, so switching between tabs and back restores
80
+ their pagination; a direct link reproduces everything. If you'd rather keep the URL minimal,
81
+ render inactive tabs with `v-if` and call `reset()` in `onUnmounted` to drop the leaving
82
+ tab's keys.
83
+
60
84
  ## `param`
61
85
 
62
86
  All options are shared: `{ default?: T; history?: 'push' | 'replace' }` (`history` defaults to
@@ -98,9 +122,12 @@ const dateCodec = defineCodec<Date | null>({
98
122
 
99
123
  ## Batching & history
100
124
 
101
- Writes made in the same tick are merged into a single navigation via `queueMicrotask`.
102
- If any changed param in the batch has `history: 'push'`, `router.push` is used; otherwise
103
- `router.replace`. Query keys are sorted for a deterministic URL.
125
+ All writes in the same tick field assignments, `patch`, `reset` accumulate into one
126
+ pending batch (kept per router instance) and are applied as a **single** navigation via
127
+ `queueMicrotask`. The batch is layered over the last *scheduled* state, so reads within the
128
+ same tick see pending writes. If any changed param in the batch has `history: 'push'`, the
129
+ whole batch uses `router.push`; otherwise `router.replace`. Query keys are sorted for a
130
+ deterministic URL.
104
131
 
105
132
  ## Playground
106
133
 
@@ -108,8 +135,9 @@ If any changed param in the batch has `history: 'push'`, `router.push` is used;
108
135
  npm run dev
109
136
  ```
110
137
 
111
- A catalog page exercises every param type plus `reset`/`patch`, and a second route uses
112
- `useQueryParam`. The current `route.query` is rendered on screen.
138
+ A catalog page exercises every param type plus `reset`/`patch`, and a second route shows the
139
+ single-parameter pattern (`toRef` over a one-key schema). The current `route.query` is
140
+ rendered on screen.
113
141
 
114
142
  ## License
115
143
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { useQueryFilters } from './useQueryFilters';
2
- export { useQueryParam } from './useQueryParam';
3
2
  export { param } from './param';
4
3
  export { defineCodec } from './defineCodec';
5
- export type { QueryCodec, ParamOptions, Param, FilterSchema, InferFilters, QueryFilters } from './types';
4
+ export type { QueryCodec, ParamOptions, Param, FilterSchema, InferFilters, UseQueryFiltersOptions, UseQueryFiltersReturn } from './types';
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,YAAY,EACV,UAAU,EACV,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,YAAY,EACV,UAAU,EACV,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,SAAS,CAAA"}
package/dist/index.mjs CHANGED
@@ -1,119 +1,140 @@
1
- import { computed as h, reactive as b } from "vue";
2
- import { useRoute as o, useRouter as A } from "vue-router";
3
- function N(e) {
1
+ import { reactive as m, computed as v } from "vue";
2
+ import { useRoute as S, useRouter as P } from "vue-router";
3
+ function A(e) {
4
4
  if (e != null)
5
5
  return Array.isArray(e) ? e.filter((r) => r !== null) : e;
6
6
  }
7
- function S(e, r) {
7
+ function b(e, r) {
8
8
  return e === r ? !0 : Array.isArray(e) && Array.isArray(r) ? e.length !== r.length ? !1 : e.every((t, u) => t === r[u]) : !1;
9
9
  }
10
- const f = /* @__PURE__ */ new WeakMap();
11
- function q(e) {
12
- let r = f.get(e);
13
- return r || (r = { sets: /* @__PURE__ */ new Map(), deletes: /* @__PURE__ */ new Set(), usePush: !1, scheduled: !1 }, f.set(e, r)), r;
14
- }
15
- function y(e, r, t, u) {
16
- const n = q(e);
17
- t === null ? (n.sets.delete(r), n.deletes.add(r)) : (n.deletes.delete(r), n.sets.set(r, t)), u === "push" && (n.usePush = !0), n.scheduled || (n.scheduled = !0, queueMicrotask(() => j(e)));
18
- }
19
- function v(e, r) {
10
+ const g = /* @__PURE__ */ new WeakMap();
11
+ function N(e) {
12
+ let r = g.get(e);
13
+ return r || (r = {
14
+ patch: m(/* @__PURE__ */ new Map()),
15
+ usePush: !1,
16
+ scheduled: !1
17
+ }, g.set(e, r)), r;
18
+ }
19
+ function j(e, r) {
20
+ const t = N(e);
21
+ return t.patch.has(r) ? { pending: !0, value: t.patch.get(r) ?? null } : { pending: !1, value: null };
22
+ }
23
+ function o(e, r, t, u) {
24
+ const l = N(e);
25
+ l.patch.set(r, t), u === "push" && (l.usePush = !0), l.scheduled || (l.scheduled = !0, queueMicrotask(() => O(e)));
26
+ }
27
+ function q(e, r) {
20
28
  const t = Object.keys(e), u = Object.keys(r);
21
29
  if (t.length !== u.length)
22
30
  return !1;
23
- const n = (s, c) => {
24
- if (Array.isArray(s) || Array.isArray(c)) {
25
- const l = Array.isArray(s) ? s : [s], a = Array.isArray(c) ? c : [c];
26
- return l.length === a.length && l.every((z, m) => String(z) === String(a[m]));
31
+ const l = (n, c) => {
32
+ if (Array.isArray(n) || Array.isArray(c)) {
33
+ const a = Array.isArray(n) ? n : [n], d = Array.isArray(c) ? c : [c];
34
+ return a.length === d.length && a.every((f, i) => String(f) === String(d[i]));
27
35
  }
28
- return String(s) === String(c);
36
+ return String(n) === String(c);
29
37
  };
30
- return t.every((s) => s in r && n(e[s], r[s]));
38
+ return t.every((n) => n in r && l(e[n], r[n]));
31
39
  }
32
- function j(e) {
33
- const r = f.get(e);
40
+ function O(e) {
41
+ const r = g.get(e);
34
42
  if (!r)
35
43
  return;
36
- f.delete(e);
37
- const t = e.currentRoute.value.query, u = {};
38
- for (const [c, l] of Object.entries(t))
39
- l !== null && (u[c] = Array.isArray(l) ? l.filter((a) => a !== null) : l);
40
- r.deletes.forEach((c) => delete u[c]), r.sets.forEach((c, l) => {
41
- u[l] = c;
42
- });
43
- const n = {};
44
- for (const c of Object.keys(u).sort())
45
- n[c] = u[c];
46
- if (v(t, n))
44
+ if (r.scheduled = !1, r.patch.size === 0) {
45
+ r.usePush = !1;
47
46
  return;
48
- (r.usePush ? e.push({ query: n }) : e.replace({ query: n })).catch(() => {
47
+ }
48
+ const t = r.usePush;
49
+ r.usePush = !1;
50
+ const u = e.currentRoute.value.query, l = {};
51
+ for (const [f, i] of Object.entries(u))
52
+ i !== null && (l[f] = Array.isArray(i) ? i.filter((s) => s !== null) : i);
53
+ const n = new Map(r.patch);
54
+ n.forEach((f, i) => {
55
+ f === null ? delete l[i] : l[i] = f;
49
56
  });
50
- }
51
- function g(e, r, t) {
52
- const u = N(e[r]);
53
- if (u === void 0)
54
- return t.default;
57
+ const c = {};
58
+ for (const f of Object.keys(l).sort())
59
+ c[f] = l[f];
60
+ const a = () => {
61
+ n.forEach((f, i) => {
62
+ r.patch.get(i) === f && r.patch.delete(i);
63
+ });
64
+ };
65
+ if (q(u, c)) {
66
+ a();
67
+ return;
68
+ }
69
+ (t ? e.push({ query: c }) : e.replace({ query: c })).then(a, a);
70
+ }
71
+ function w(e, r, t, u) {
72
+ const l = j(r, t);
73
+ let n;
74
+ if (l.pending) {
75
+ if (l.value === null)
76
+ return u.default;
77
+ n = A(l.value);
78
+ } else
79
+ n = A(e.query[t]);
80
+ if (n === void 0)
81
+ return u.default;
55
82
  try {
56
- const n = t.codec.deserialize(u);
57
- return n === void 0 ? t.default : n;
83
+ const c = u.codec.deserialize(n);
84
+ return c === void 0 ? u.default : c;
58
85
  } catch {
59
- return t.default;
86
+ return u.default;
60
87
  }
61
88
  }
62
- function i(e, r, t, u) {
63
- const n = t.codec.serialize(u), s = t.codec.serialize(t.default);
64
- n === null || S(n, s) ? y(e, r, null, t.history) : y(e, r, n, t.history);
65
- }
66
- const k = ["patch", "reset"];
67
- function V(e) {
68
- for (const l of k)
69
- if (l in e)
70
- throw new Error(
71
- `[vue-router-query-sync] "${l}" is a reserved method name and cannot be used as a param key.`
72
- );
73
- const r = o(), t = A(), u = Object.keys(e), n = {};
74
- for (const l of u)
75
- n[l] = h({
76
- get: () => g(r.query, l, e[l]),
77
- set: (a) => i(t, l, e[l], a)
78
- });
79
- return b({ ...n, patch: (l) => {
80
- for (const a of Object.keys(l))
81
- a in e && i(t, a, e[a], l[a]);
82
- }, reset: () => {
83
- for (const l of u)
84
- i(t, l, e[l], e[l].default);
85
- } });
89
+ function z(e, r, t, u) {
90
+ const l = t.codec.serialize(u), n = t.codec.serialize(t.default);
91
+ l === null || b(l, n) ? o(e, r, null, t.history) : o(e, r, l, t.history);
86
92
  }
87
- function C(e, r) {
88
- const t = o(), u = A();
89
- return h({
90
- get: () => g(t.query, e, r),
91
- set: (n) => i(u, e, r, n)
93
+ function k(e, r, t, u) {
94
+ let l = !1, n, c;
95
+ return v({
96
+ get: () => {
97
+ const a = w(e, r, t, u), d = u.codec.serialize(a);
98
+ return l && b(d, c) ? n : (l = !0, n = a, c = d, a);
99
+ },
100
+ set: (a) => z(r, t, u, a)
92
101
  });
93
102
  }
94
- function d(e) {
103
+ function $(e, r = {}) {
104
+ const t = S(), u = P(), l = Object.keys(e), { prefix: n } = r, c = (s) => n ? `${n}.${s}` : s, a = {};
105
+ for (const s of l)
106
+ a[s] = k(t, u, c(s), e[s]);
107
+ return { filters: m(a), patch: (s) => {
108
+ for (const h of Object.keys(s))
109
+ h in e && z(u, c(h), e[h], s[h]);
110
+ }, reset: () => {
111
+ for (const s of l)
112
+ z(u, c(s), e[s], e[s].default);
113
+ } };
114
+ }
115
+ function y(e) {
95
116
  return Array.isArray(e) ? e[0] ?? "" : e;
96
117
  }
97
- function w(e) {
118
+ function F(e) {
98
119
  return { codec: {
99
120
  serialize: (t) => t === null || t === "" ? null : t,
100
- deserialize: (t) => d(t)
121
+ deserialize: (t) => y(t)
101
122
  }, default: (e == null ? void 0 : e.default) ?? null, history: (e == null ? void 0 : e.history) ?? "replace" };
102
123
  }
103
- function E(e) {
124
+ function M(e) {
104
125
  return { codec: {
105
126
  serialize: (t) => t === null ? null : String(t),
106
127
  deserialize: (t) => {
107
- const u = d(t), n = Number(u);
108
- return u === "" || Number.isNaN(n) ? void 0 : n;
128
+ const u = y(t), l = Number(u);
129
+ return u === "" || Number.isNaN(l) ? void 0 : l;
109
130
  }
110
131
  }, default: (e == null ? void 0 : e.default) ?? null, history: (e == null ? void 0 : e.history) ?? "replace" };
111
132
  }
112
- function O(e) {
133
+ function R(e) {
113
134
  return { codec: {
114
135
  serialize: (t) => t === null ? null : t ? "true" : "false",
115
136
  deserialize: (t) => {
116
- const u = d(t);
137
+ const u = y(t);
117
138
  if (u === "true")
118
139
  return !0;
119
140
  if (u === "false")
@@ -121,30 +142,30 @@ function O(e) {
121
142
  }
122
143
  }, default: (e == null ? void 0 : e.default) ?? null, history: (e == null ? void 0 : e.history) ?? "replace" };
123
144
  }
124
- function R(e) {
145
+ function E(e) {
125
146
  return { codec: {
126
147
  serialize: (t) => t.length === 0 ? null : [...t],
127
148
  deserialize: (t) => Array.isArray(t) ? [...t] : [t]
128
149
  }, default: (e == null ? void 0 : e.default) ?? [], history: (e == null ? void 0 : e.history) ?? "replace" };
129
150
  }
130
- function P(e) {
151
+ function K(e) {
131
152
  return Object.entries(e).filter(([r]) => Number.isNaN(Number(r))).map(([, r]) => r);
132
153
  }
133
- function Q(e, r) {
134
- const t = Array.isArray(e) ? [...e] : P(e), u = new Set(t);
154
+ function C(e, r) {
155
+ const t = Array.isArray(e) ? [...e] : K(e), u = new Set(t);
135
156
  return { codec: {
136
- serialize: (s) => s === null ? null : String(s),
137
- deserialize: (s) => {
138
- const c = d(s);
157
+ serialize: (n) => n === null ? null : String(n),
158
+ deserialize: (n) => {
159
+ const c = y(n);
139
160
  if (u.has(c))
140
161
  return c;
141
- const l = Number(c);
142
- if (c !== "" && !Number.isNaN(l) && u.has(l))
143
- return l;
162
+ const a = Number(c);
163
+ if (c !== "" && !Number.isNaN(a) && u.has(a))
164
+ return a;
144
165
  }
145
166
  }, default: (r == null ? void 0 : r.default) ?? null, history: (r == null ? void 0 : r.history) ?? "replace" };
146
167
  }
147
- function F(e, r) {
168
+ function Q(e, r) {
148
169
  return {
149
170
  codec: {
150
171
  serialize: (u) => u === null ? null : e.serialize(u),
@@ -154,20 +175,19 @@ function F(e, r) {
154
175
  history: (r == null ? void 0 : r.history) ?? "replace"
155
176
  };
156
177
  }
157
- const D = {
158
- string: w,
159
- number: E,
160
- boolean: O,
161
- stringArray: R,
162
- enum: Q,
163
- custom: F
178
+ const B = {
179
+ string: F,
180
+ number: M,
181
+ boolean: R,
182
+ stringArray: E,
183
+ enum: C,
184
+ custom: Q
164
185
  };
165
- function W(e) {
186
+ function D(e) {
166
187
  return e;
167
188
  }
168
189
  export {
169
- W as defineCodec,
170
- D as param,
171
- V as useQueryFilters,
172
- C as useQueryParam
190
+ D as defineCodec,
191
+ B as param,
192
+ $ as useQueryFilters
173
193
  };
@@ -0,0 +1,10 @@
1
+ import { Router } from 'vue-router';
2
+ type Serialized = string | string[];
3
+ export interface PendingRead {
4
+ pending: boolean;
5
+ value: Serialized | null;
6
+ }
7
+ export declare function readPending(router: Router, key: string): PendingRead;
8
+ export declare function scheduleWrite(router: Router, key: string, value: Serialized | null, history: 'push' | 'replace'): void;
9
+ export {};
10
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/internal/batch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmC,MAAM,EAAE,MAAM,YAAY,CAAA;AAEzE,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AA2BnC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,UAAU,GAAG,IAAI,CAAA;CACzB;AAGD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAMpE;AAGD,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,GAAG,IAAI,EACxB,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,IAAI,CAUN"}
@@ -1,5 +1,5 @@
1
- import { LocationQuery, Router } from 'vue-router';
1
+ import { RouteLocationNormalizedLoaded, Router } from 'vue-router';
2
2
  import { Param } from '../types';
3
- export declare function readField<Out>(query: LocationQuery, key: string, p: Param<Out>): Out;
3
+ export declare function readField<Out>(route: RouteLocationNormalizedLoaded, router: Router, key: string, p: Param<Out>): Out;
4
4
  export declare function writeField<Out>(router: Router, key: string, p: Param<Out>, value: Out): void;
5
5
  //# sourceMappingURL=field.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/internal/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAMrC,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CAWpF;AAGD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAQ5F"}
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/internal/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAOrC,wBAAgB,SAAS,CAAC,GAAG,EAC3B,KAAK,EAAE,6BAA6B,EACpC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GACZ,GAAG,CAoBL;AAGD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAQ5F"}
package/dist/types.d.ts CHANGED
@@ -15,8 +15,12 @@ export type FilterSchema = Record<string, Param<unknown>>;
15
15
  export type InferFilters<S extends FilterSchema> = {
16
16
  [K in keyof S]: S[K] extends Param<infer O> ? O : never;
17
17
  };
18
- export type QueryFilters<S extends FilterSchema> = InferFilters<S> & {
18
+ export interface UseQueryFiltersOptions {
19
+ prefix?: string;
20
+ }
21
+ export interface UseQueryFiltersReturn<S extends FilterSchema> {
22
+ filters: InferFilters<S>;
19
23
  patch(partial: Partial<InferFilters<S>>): void;
20
24
  reset(): void;
21
- };
25
+ }
22
26
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,UAAU,CAAC,CAAC;IAE3B,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;IAE7C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAA;CACnD;AAGD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAC5B,OAAO,CAAC,EAAE,CAAC,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B,CAAA;AAGD,MAAM,WAAW,KAAK,CAAC,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;IACtB,OAAO,EAAE,GAAG,CAAA;IACZ,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAGD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;AAGzD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI;KAChD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACxD,CAAA;AAGD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG;IACnE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;IAC9C,KAAK,IAAI,IAAI,CAAA;CACd,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,UAAU,CAAC,CAAC;IAE3B,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;IAE7C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAA;CACnD;AAGD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAC5B,OAAO,CAAC,EAAE,CAAC,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B,CAAA;AAGD,MAAM,WAAW,KAAK,CAAC,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;IACtB,OAAO,EAAE,GAAG,CAAA;IACZ,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAGD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;AAGzD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI;KAChD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACxD,CAAA;AAGD,MAAM,WAAW,sBAAsB;IAGrC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,MAAM,WAAW,qBAAqB,CAAC,CAAC,SAAS,YAAY;IAC3D,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;IACxB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;IAC9C,KAAK,IAAI,IAAI,CAAA;CACd"}
@@ -1,3 +1,3 @@
1
- import { FilterSchema, QueryFilters } from './types';
2
- export declare function useQueryFilters<S extends FilterSchema>(schema: S): QueryFilters<S>;
1
+ import { FilterSchema, UseQueryFiltersOptions, UseQueryFiltersReturn } from './types';
2
+ export declare function useQueryFilters<S extends FilterSchema>(schema: S, options?: UseQueryFiltersOptions): UseQueryFiltersReturn<S>;
3
3
  //# sourceMappingURL=useQueryFilters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useQueryFilters.d.ts","sourceRoot":"","sources":["../src/useQueryFilters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAMzD,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAoClF"}
1
+ {"version":3,"file":"useQueryFilters.d.ts","sourceRoot":"","sources":["../src/useQueryFilters.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,YAAY,EAGZ,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAiChB,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACpD,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CAAC,CAAC,CAAC,CA6B1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-router-query-sync",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Reactive, typed view of Vue Router query params with codecs and defaults",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -1,3 +0,0 @@
1
- import { Router } from 'vue-router';
2
- export declare function scheduleQuery(router: Router, key: string, value: string | string[] | null, history: 'push' | 'replace'): void;
3
- //# sourceMappingURL=queryQueue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queryQueue.d.ts","sourceRoot":"","sources":["../../src/internal/queryQueue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,MAAM,EAAE,MAAM,YAAY,CAAA;AAsBzE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAC/B,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,IAAI,CAiBN"}
@@ -1,4 +0,0 @@
1
- import { WritableComputedRef } from 'vue';
2
- import { Param } from './types';
3
- export declare function useQueryParam<Out>(key: string, p: Param<Out>): WritableComputedRef<Out>;
4
- //# sourceMappingURL=useQueryParam.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQueryParam.d.ts","sourceRoot":"","sources":["../src/useQueryParam.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,KAAK,CAAA;AAE9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAOvF"}