zustand-querystring 0.6.2 → 0.6.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/dist/index.d.mts CHANGED
@@ -3,10 +3,6 @@ import { StoreMutatorIdentifier, StateCreator } from 'zustand/vanilla';
3
3
  type DeepSelect<T> = T extends object ? {
4
4
  [P in keyof T]?: DeepSelect<T[P]> | boolean;
5
5
  } : boolean;
6
- /** Maps T to only the fields marked as selected in S. `false` excludes, everything else includes. */
7
- type ApplySelect<T, S> = [S] extends [false] ? never : S extends object ? T extends object ? {
8
- [P in keyof S & keyof T as [ApplySelect<T[P], S[P]>] extends [never] ? never : P]: ApplySelect<T[P], S[P]>;
9
- } : never : T;
10
6
  interface QueryStringParam {
11
7
  key: string;
12
8
  value: string | string[];
@@ -46,18 +42,20 @@ interface QueryStringMap<S, U extends object = Record<string, unknown>> {
46
42
  to: (state: S, pathname: string) => U;
47
43
  from: (urlState: U, pathname: string) => Partial<S>;
48
44
  }
49
- interface QueryStringOptions<T, K extends string | false = string | false, S extends DeepSelect<T> = DeepSelect<T>, U extends object = Record<string, unknown>> {
45
+ /** Helper to create a typed map infers U from `to`'s return type. */
46
+ declare function createMap<S, U extends object>(map: QueryStringMap<S, U>): QueryStringMap<S, U>;
47
+ interface QueryStringOptions<T, K extends string | false = string | false> {
50
48
  url?: string;
51
- select?: (pathname: string) => S;
49
+ select?: (pathname: string) => DeepSelect<T>;
52
50
  key?: K;
53
51
  prefix?: string;
54
52
  format?: QueryStringFormatFor<K>;
55
53
  syncNull?: boolean;
56
54
  syncUndefined?: boolean;
57
55
  /** Bidirectional mapping between store state shape and URL state shape. */
58
- map?: QueryStringMap<ApplySelect<T, S>, U>;
56
+ map?: QueryStringMap<T>;
59
57
  }
60
- type QueryString = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = [], const S extends DeepSelect<T> = DeepSelect<T>, U extends object = Record<string, unknown>>(initializer: StateCreator<T, Mps, Mcs>, options?: QueryStringOptions<T, string | false, S, U>) => StateCreator<T, Mps, Mcs>;
58
+ type QueryString = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, Mps, Mcs>, options?: QueryStringOptions<T>) => StateCreator<T, Mps, Mcs>;
61
59
  declare const querystring: QueryString;
62
60
 
63
- export { type ParseContext, type QueryStringFormat, type QueryStringFormatFor, type QueryStringFormatNamespaced, type QueryStringFormatStandalone, type QueryStringMap, type QueryStringOptions, type QueryStringParam, type QueryStringParams, querystring };
61
+ export { type ParseContext, type QueryStringFormat, type QueryStringFormatFor, type QueryStringFormatNamespaced, type QueryStringFormatStandalone, type QueryStringMap, type QueryStringOptions, type QueryStringParam, type QueryStringParams, createMap, querystring };
package/dist/index.d.ts CHANGED
@@ -3,10 +3,6 @@ import { StoreMutatorIdentifier, StateCreator } from 'zustand/vanilla';
3
3
  type DeepSelect<T> = T extends object ? {
4
4
  [P in keyof T]?: DeepSelect<T[P]> | boolean;
5
5
  } : boolean;
6
- /** Maps T to only the fields marked as selected in S. `false` excludes, everything else includes. */
7
- type ApplySelect<T, S> = [S] extends [false] ? never : S extends object ? T extends object ? {
8
- [P in keyof S & keyof T as [ApplySelect<T[P], S[P]>] extends [never] ? never : P]: ApplySelect<T[P], S[P]>;
9
- } : never : T;
10
6
  interface QueryStringParam {
11
7
  key: string;
12
8
  value: string | string[];
@@ -46,18 +42,20 @@ interface QueryStringMap<S, U extends object = Record<string, unknown>> {
46
42
  to: (state: S, pathname: string) => U;
47
43
  from: (urlState: U, pathname: string) => Partial<S>;
48
44
  }
49
- interface QueryStringOptions<T, K extends string | false = string | false, S extends DeepSelect<T> = DeepSelect<T>, U extends object = Record<string, unknown>> {
45
+ /** Helper to create a typed map infers U from `to`'s return type. */
46
+ declare function createMap<S, U extends object>(map: QueryStringMap<S, U>): QueryStringMap<S, U>;
47
+ interface QueryStringOptions<T, K extends string | false = string | false> {
50
48
  url?: string;
51
- select?: (pathname: string) => S;
49
+ select?: (pathname: string) => DeepSelect<T>;
52
50
  key?: K;
53
51
  prefix?: string;
54
52
  format?: QueryStringFormatFor<K>;
55
53
  syncNull?: boolean;
56
54
  syncUndefined?: boolean;
57
55
  /** Bidirectional mapping between store state shape and URL state shape. */
58
- map?: QueryStringMap<ApplySelect<T, S>, U>;
56
+ map?: QueryStringMap<T>;
59
57
  }
60
- type QueryString = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = [], const S extends DeepSelect<T> = DeepSelect<T>, U extends object = Record<string, unknown>>(initializer: StateCreator<T, Mps, Mcs>, options?: QueryStringOptions<T, string | false, S, U>) => StateCreator<T, Mps, Mcs>;
58
+ type QueryString = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, Mps, Mcs>, options?: QueryStringOptions<T>) => StateCreator<T, Mps, Mcs>;
61
59
  declare const querystring: QueryString;
62
60
 
63
- export { type ParseContext, type QueryStringFormat, type QueryStringFormatFor, type QueryStringFormatNamespaced, type QueryStringFormatStandalone, type QueryStringMap, type QueryStringOptions, type QueryStringParam, type QueryStringParams, querystring };
61
+ export { type ParseContext, type QueryStringFormat, type QueryStringFormatFor, type QueryStringFormatNamespaced, type QueryStringFormatStandalone, type QueryStringMap, type QueryStringOptions, type QueryStringParam, type QueryStringParams, createMap, querystring };
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/index.ts
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
+ createMap: () => createMap,
22
23
  querystring: () => querystring
23
24
  });
24
25
  module.exports = __toCommonJS(src_exports);
@@ -397,6 +398,9 @@ function createFormat(options = {}) {
397
398
  var marked = createFormat();
398
399
 
399
400
  // src/middleware.ts
401
+ function createMap(map) {
402
+ return map;
403
+ }
400
404
  var compact = (newState, initialState, syncNull = false, syncUndefined = false) => {
401
405
  const output = {};
402
406
  const removed = [];
@@ -667,6 +671,7 @@ var queryStringImpl = (fn, options) => (set, get, api) => {
667
671
  var querystring = queryStringImpl;
668
672
  // Annotate the CommonJS export names for ESM import in node:
669
673
  0 && (module.exports = {
674
+ createMap,
670
675
  querystring
671
676
  });
672
677
  /* v8 ignore next 4 -- @preserve: defensive - handles escape char at very end of source */
package/dist/index.mjs CHANGED
@@ -4,6 +4,9 @@ import {
4
4
 
5
5
  // src/middleware.ts
6
6
  import { isEqual, mergeWith } from "lodash-es";
7
+ function createMap(map) {
8
+ return map;
9
+ }
7
10
  var compact = (newState, initialState, syncNull = false, syncUndefined = false) => {
8
11
  const output = {};
9
12
  const removed = [];
@@ -273,5 +276,6 @@ var queryStringImpl = (fn, options) => (set, get, api) => {
273
276
  };
274
277
  var querystring = queryStringImpl;
275
278
  export {
279
+ createMap,
276
280
  querystring
277
281
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zustand-querystring",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",