floppy-disk 3.4.0 → 3.5.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/README.md CHANGED
@@ -96,6 +96,8 @@ function PlantDetail({ id }) {
96
96
  }
97
97
  ```
98
98
 
99
+ <br>
100
+
99
101
  ---
100
102
 
101
103
  Read the docs → https://floppy-disk.vercel.app
@@ -1,4 +1,4 @@
1
- import { type InitStoreOptions, type SetState } from "../vanilla.mjs";
1
+ import { type InitStoreOptions, type SetStateInput } from "../vanilla.mjs";
2
2
  /**
3
3
  * Represents the state of a mutation.
4
4
  *
@@ -105,7 +105,7 @@ export type MutationOptions<TData, TVariable, TError = Error> = InitStoreOptions
105
105
  * const { isPending } = useCreateUser();
106
106
  * const result = await useCreateUser.execute({ name: 'John' });
107
107
  *
108
- * @see https://floppy-disk.vercel.app/docs/async/mutation
108
+ * @see https://floppy-disk.vercel.app/docs/mutation
109
109
  */
110
110
  export declare const createMutation: <TData, TVariable = undefined, TError = Error>(mutationFn: (variable: TVariable, stateBeforeExecute: MutationState<TData, TVariable, TError>) => Promise<TData>, options?: MutationOptions<TData, TVariable, TError>) => (() => MutationState<TData, TVariable, TError>) & {
111
111
  subscribe: (subscriber: import("../vanilla.d.mts").Subscriber<MutationState<TData, TVariable, TError>>) => () => void;
@@ -118,7 +118,7 @@ export declare const createMutation: <TData, TVariable = undefined, TError = Err
118
118
  * - Intended for advanced use cases.
119
119
  * - Prefer using provided mutation actions (`execute`, `reset`) instead.
120
120
  */
121
- setState: (value: SetState<MutationState<TData, TVariable, TError>>) => void;
121
+ setState: (value: SetStateInput<MutationState<TData, TVariable, TError>>) => void;
122
122
  /**
123
123
  * Executes the mutation.
124
124
  *
@@ -1,4 +1,5 @@
1
- import { type InitStoreOptions, type SetState } from "../vanilla.mjs";
1
+ import { type InitStoreOptions, type SetStateInput } from "../vanilla.mjs";
2
+ import type { StoreKey } from "./create-stores.mjs";
2
3
  /**
3
4
  * Represents the state of a query.
4
5
  *
@@ -68,7 +69,7 @@ export type QueryState<TData, TError> = {
68
69
  * @remarks
69
70
  * Controls caching, retry behavior, lifecycle, and side effects of an async operation.
70
71
  */
71
- export type QueryOptions<TData, TVariable extends Record<string, any>, TError = Error> = InitStoreOptions<QueryState<TData, TError>, {
72
+ export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, {
72
73
  variableHash: string;
73
74
  }> & {
74
75
  /**
@@ -164,9 +165,9 @@ export type QueryOptions<TData, TVariable extends Record<string, any>, TError =
164
165
  * // ...
165
166
  * }
166
167
  *
167
- * @see https://floppy-disk.vercel.app/docs/async/query
168
+ * @see https://floppy-disk.vercel.app/docs/query
168
169
  */
169
- export declare const createQuery: <TData, TVariable extends Record<string, any> = never, TError = Error>(queryFn: (variable: TVariable, currentState: QueryState<TData, TError>, variableHash: string) => Promise<TData>, options?: QueryOptions<TData, TVariable, TError>) => ((variable?: TVariable) => ((options?: {
170
+ export declare const createQuery: <TData, TVariable extends StoreKey = never, TError = Error>(queryFn: (variable: TVariable, currentState: QueryState<TData, TError>, variableHash: string) => Promise<TData>, options?: QueryOptions<TData, TVariable, TError>) => ((variable?: TVariable) => ((options?: {
170
171
  /**
171
172
  * Whether the query should be ravalidated automatically on mount.
172
173
  *
@@ -218,6 +219,7 @@ export declare const createQuery: <TData, TVariable extends Record<string, any>
218
219
  initialData?: never;
219
220
  initialDataIsStale?: never;
220
221
  })) => QueryState<TData, TError>) & {
222
+ variableHash: string;
221
223
  /**
222
224
  * Internal data, do not mutate!
223
225
  */
@@ -345,7 +347,7 @@ export declare const createQuery: <TData, TVariable extends Record<string, any>
345
347
  subscribe: (subscriber: import("../vanilla.d.mts").Subscriber<QueryState<TData, TError>>) => () => void;
346
348
  getSubscribers: () => Set<import("../vanilla.d.mts").Subscriber<QueryState<TData, TError>>>;
347
349
  getState: () => QueryState<TData, TError>;
348
- setState: (value: SetState<QueryState<TData, TError>>) => void;
350
+ setState: (value: SetStateInput<QueryState<TData, TError>>) => void;
349
351
  }) & {
350
352
  /**
351
353
  * Executes all query instances.
@@ -25,7 +25,7 @@ import { type InitStoreOptions } from "../vanilla.mjs";
25
25
  *
26
26
  * useMyStore.setState({ foo: 2 }); // only components using foo will re-render
27
27
  *
28
- * @see https://floppy-disk.vercel.app/docs/sync/store
28
+ * @see https://floppy-disk.vercel.app/docs/store
29
29
  */
30
30
  export declare const createStore: <TState extends Record<string, any>>(initialState: TState, options?: InitStoreOptions<TState>) => ((options?: {
31
31
  /**
@@ -1,4 +1,8 @@
1
1
  import { type InitStoreOptions } from "../vanilla.mjs";
2
+ type GoodInputForHash = string | number | boolean | null | Date;
3
+ export type StoreKey = GoodInputForHash | {
4
+ [key: string | number]: StoreKey | StoreKey[];
5
+ };
2
6
  /**
3
7
  * Creates a factory for multiple stores identified by a key.
4
8
  *
@@ -30,9 +34,9 @@ import { type InitStoreOptions } from "../vanilla.mjs";
30
34
  * return <div>{state.name}</div>;
31
35
  * }
32
36
  *
33
- * @see https://floppy-disk.vercel.app/docs/sync/stores
37
+ * @see https://floppy-disk.vercel.app/docs/stores
34
38
  */
35
- export declare const createStores: <TState extends Record<string, any>, TKey extends Record<string, any>>(initialState: TState, options?: InitStoreOptions<TState, {
39
+ export declare const createStores: <TState extends Record<string, any>, TKey extends StoreKey>(initialState: TState, options?: InitStoreOptions<TState, {
36
40
  key: TKey;
37
41
  keyHash: string;
38
42
  }>) => (key?: TKey) => ((options?: {
@@ -44,10 +48,11 @@ export declare const createStores: <TState extends Record<string, any>, TKey ext
44
48
  initialState?: Partial<TState>;
45
49
  }) => TState) & {
46
50
  delete: () => boolean;
47
- setState: (value: import("../vanilla.d.mts").SetState<TState>) => void;
51
+ setState: (value: import("../vanilla.d.mts").SetStateInput<TState>) => void;
48
52
  getState: () => TState;
49
53
  subscribe: (subscriber: import("../vanilla.d.mts").Subscriber<TState>) => () => void;
50
54
  getSubscribers: () => Set<import("../vanilla.d.mts").Subscriber<TState>>;
51
55
  key: TKey;
52
56
  keyHash: string;
53
57
  };
58
+ export {};
@@ -21,7 +21,7 @@ import { type MutationOptions, type MutationState } from "./create-mutation.mjs"
21
21
  * - Only the latest execution is allowed to update the state.
22
22
  * - Results from previous executions are ignored if a newer one exists.
23
23
  *
24
- * @see https://floppy-disk.vercel.app/docs/async/mutation
24
+ * @see https://floppy-disk.vercel.app/docs/mutation
25
25
  */
26
26
  export declare const useMutation: <TData, TVariable = undefined, TError = Error>(
27
27
  /**
package/esm/react.mjs CHANGED
@@ -482,7 +482,8 @@ const createQuery = (queryFn, options = {}) => {
482
482
  console.debug("Manual setState (not via provided actions) on query store");
483
483
  store.setState(value);
484
484
  },
485
- ...internals.get(store)
485
+ ...internals.get(store),
486
+ variableHash
486
487
  });
487
488
  };
488
489
  return Object.assign(getStore, {
@@ -1,11 +1,4 @@
1
- /**
2
- * Represents a partial state update.
3
- *
4
- * Can be either:
5
- * - A partial object to merge into the current state
6
- * - A function that receives the current state and returns a partial update
7
- */
8
- export type SetState<TState> = Partial<TState> | ((state: TState) => Partial<TState>);
1
+ export type SetStateInput<TState> = Partial<TState> | ((state: TState) => Partial<TState>);
9
2
  /**
10
3
  * A subscriber function that is called whenever the state updates.
11
4
  *
@@ -30,7 +23,7 @@ export type Subscriber<TState> = (state: TState, prevState: TState, changedKeys:
30
23
  * - By default, `setState` is **disabled on the server** to prevent accidental shared state between requests.
31
24
  */
32
25
  export type StoreApi<TState extends Record<string, any>> = {
33
- setState: (value: SetState<TState>) => void;
26
+ setState: (value: SetStateInput<TState>) => void;
34
27
  getState: () => TState;
35
28
  subscribe: (subscriber: Subscriber<TState>) => () => void;
36
29
  getSubscribers: () => Set<Subscriber<TState>>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "floppy-disk",
3
3
  "description": "Lightweight unified state management for sync and async data.",
4
4
  "private": false,
5
- "version": "3.4.0",
5
+ "version": "3.5.1",
6
6
  "keywords": [
7
7
  "utilities",
8
8
  "store",
@@ -68,6 +68,7 @@
68
68
  }
69
69
  }
70
70
  },
71
+ "packageManager": "pnpm@10.32.1",
71
72
  "peerDependencies": {
72
73
  "@types/react": ">=17.0",
73
74
  "react": ">=17.0"
@@ -80,4 +81,4 @@
80
81
  "optional": true
81
82
  }
82
83
  }
83
- }
84
+ }
@@ -1,4 +1,4 @@
1
- import { type InitStoreOptions, type SetState } from "../vanilla.ts";
1
+ import { type InitStoreOptions, type SetStateInput } from "../vanilla.ts";
2
2
  /**
3
3
  * Represents the state of a mutation.
4
4
  *
@@ -105,7 +105,7 @@ export type MutationOptions<TData, TVariable, TError = Error> = InitStoreOptions
105
105
  * const { isPending } = useCreateUser();
106
106
  * const result = await useCreateUser.execute({ name: 'John' });
107
107
  *
108
- * @see https://floppy-disk.vercel.app/docs/async/mutation
108
+ * @see https://floppy-disk.vercel.app/docs/mutation
109
109
  */
110
110
  export declare const createMutation: <TData, TVariable = undefined, TError = Error>(mutationFn: (variable: TVariable, stateBeforeExecute: MutationState<TData, TVariable, TError>) => Promise<TData>, options?: MutationOptions<TData, TVariable, TError>) => (() => MutationState<TData, TVariable, TError>) & {
111
111
  subscribe: (subscriber: import("../vanilla.ts").Subscriber<MutationState<TData, TVariable, TError>>) => () => void;
@@ -118,7 +118,7 @@ export declare const createMutation: <TData, TVariable = undefined, TError = Err
118
118
  * - Intended for advanced use cases.
119
119
  * - Prefer using provided mutation actions (`execute`, `reset`) instead.
120
120
  */
121
- setState: (value: SetState<MutationState<TData, TVariable, TError>>) => void;
121
+ setState: (value: SetStateInput<MutationState<TData, TVariable, TError>>) => void;
122
122
  /**
123
123
  * Executes the mutation.
124
124
  *
@@ -1,4 +1,5 @@
1
- import { type InitStoreOptions, type SetState } from "../vanilla.ts";
1
+ import { type InitStoreOptions, type SetStateInput } from "../vanilla.ts";
2
+ import type { StoreKey } from "./create-stores.ts";
2
3
  /**
3
4
  * Represents the state of a query.
4
5
  *
@@ -68,7 +69,7 @@ export type QueryState<TData, TError> = {
68
69
  * @remarks
69
70
  * Controls caching, retry behavior, lifecycle, and side effects of an async operation.
70
71
  */
71
- export type QueryOptions<TData, TVariable extends Record<string, any>, TError = Error> = InitStoreOptions<QueryState<TData, TError>, {
72
+ export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, {
72
73
  variableHash: string;
73
74
  }> & {
74
75
  /**
@@ -164,9 +165,9 @@ export type QueryOptions<TData, TVariable extends Record<string, any>, TError =
164
165
  * // ...
165
166
  * }
166
167
  *
167
- * @see https://floppy-disk.vercel.app/docs/async/query
168
+ * @see https://floppy-disk.vercel.app/docs/query
168
169
  */
169
- export declare const createQuery: <TData, TVariable extends Record<string, any> = never, TError = Error>(queryFn: (variable: TVariable, currentState: QueryState<TData, TError>, variableHash: string) => Promise<TData>, options?: QueryOptions<TData, TVariable, TError>) => ((variable?: TVariable) => ((options?: {
170
+ export declare const createQuery: <TData, TVariable extends StoreKey = never, TError = Error>(queryFn: (variable: TVariable, currentState: QueryState<TData, TError>, variableHash: string) => Promise<TData>, options?: QueryOptions<TData, TVariable, TError>) => ((variable?: TVariable) => ((options?: {
170
171
  /**
171
172
  * Whether the query should be ravalidated automatically on mount.
172
173
  *
@@ -218,6 +219,7 @@ export declare const createQuery: <TData, TVariable extends Record<string, any>
218
219
  initialData?: never;
219
220
  initialDataIsStale?: never;
220
221
  })) => QueryState<TData, TError>) & {
222
+ variableHash: string;
221
223
  /**
222
224
  * Internal data, do not mutate!
223
225
  */
@@ -345,7 +347,7 @@ export declare const createQuery: <TData, TVariable extends Record<string, any>
345
347
  subscribe: (subscriber: import("../vanilla.ts").Subscriber<QueryState<TData, TError>>) => () => void;
346
348
  getSubscribers: () => Set<import("../vanilla.ts").Subscriber<QueryState<TData, TError>>>;
347
349
  getState: () => QueryState<TData, TError>;
348
- setState: (value: SetState<QueryState<TData, TError>>) => void;
350
+ setState: (value: SetStateInput<QueryState<TData, TError>>) => void;
349
351
  }) & {
350
352
  /**
351
353
  * Executes all query instances.
@@ -25,7 +25,7 @@ import { type InitStoreOptions } from "../vanilla.ts";
25
25
  *
26
26
  * useMyStore.setState({ foo: 2 }); // only components using foo will re-render
27
27
  *
28
- * @see https://floppy-disk.vercel.app/docs/sync/store
28
+ * @see https://floppy-disk.vercel.app/docs/store
29
29
  */
30
30
  export declare const createStore: <TState extends Record<string, any>>(initialState: TState, options?: InitStoreOptions<TState>) => ((options?: {
31
31
  /**
@@ -1,4 +1,8 @@
1
1
  import { type InitStoreOptions } from "../vanilla.ts";
2
+ type GoodInputForHash = string | number | boolean | null | Date;
3
+ export type StoreKey = GoodInputForHash | {
4
+ [key: string | number]: StoreKey | StoreKey[];
5
+ };
2
6
  /**
3
7
  * Creates a factory for multiple stores identified by a key.
4
8
  *
@@ -30,9 +34,9 @@ import { type InitStoreOptions } from "../vanilla.ts";
30
34
  * return <div>{state.name}</div>;
31
35
  * }
32
36
  *
33
- * @see https://floppy-disk.vercel.app/docs/sync/stores
37
+ * @see https://floppy-disk.vercel.app/docs/stores
34
38
  */
35
- export declare const createStores: <TState extends Record<string, any>, TKey extends Record<string, any>>(initialState: TState, options?: InitStoreOptions<TState, {
39
+ export declare const createStores: <TState extends Record<string, any>, TKey extends StoreKey>(initialState: TState, options?: InitStoreOptions<TState, {
36
40
  key: TKey;
37
41
  keyHash: string;
38
42
  }>) => (key?: TKey) => ((options?: {
@@ -44,10 +48,11 @@ export declare const createStores: <TState extends Record<string, any>, TKey ext
44
48
  initialState?: Partial<TState>;
45
49
  }) => TState) & {
46
50
  delete: () => boolean;
47
- setState: (value: import("../vanilla.ts").SetState<TState>) => void;
51
+ setState: (value: import("../vanilla.ts").SetStateInput<TState>) => void;
48
52
  getState: () => TState;
49
53
  subscribe: (subscriber: import("../vanilla.ts").Subscriber<TState>) => () => void;
50
54
  getSubscribers: () => Set<import("../vanilla.ts").Subscriber<TState>>;
51
55
  key: TKey;
52
56
  keyHash: string;
53
57
  };
58
+ export {};
@@ -21,7 +21,7 @@ import { type MutationOptions, type MutationState } from "./create-mutation.ts";
21
21
  * - Only the latest execution is allowed to update the state.
22
22
  * - Results from previous executions are ignored if a newer one exists.
23
23
  *
24
- * @see https://floppy-disk.vercel.app/docs/async/mutation
24
+ * @see https://floppy-disk.vercel.app/docs/mutation
25
25
  */
26
26
  export declare const useMutation: <TData, TVariable = undefined, TError = Error>(
27
27
  /**
package/react.js CHANGED
@@ -484,7 +484,8 @@ const createQuery = (queryFn, options = {}) => {
484
484
  console.debug("Manual setState (not via provided actions) on query store");
485
485
  store.setState(value);
486
486
  },
487
- ...internals.get(store)
487
+ ...internals.get(store),
488
+ variableHash
488
489
  });
489
490
  };
490
491
  return Object.assign(getStore, {
@@ -1,11 +1,4 @@
1
- /**
2
- * Represents a partial state update.
3
- *
4
- * Can be either:
5
- * - A partial object to merge into the current state
6
- * - A function that receives the current state and returns a partial update
7
- */
8
- export type SetState<TState> = Partial<TState> | ((state: TState) => Partial<TState>);
1
+ export type SetStateInput<TState> = Partial<TState> | ((state: TState) => Partial<TState>);
9
2
  /**
10
3
  * A subscriber function that is called whenever the state updates.
11
4
  *
@@ -30,7 +23,7 @@ export type Subscriber<TState> = (state: TState, prevState: TState, changedKeys:
30
23
  * - By default, `setState` is **disabled on the server** to prevent accidental shared state between requests.
31
24
  */
32
25
  export type StoreApi<TState extends Record<string, any>> = {
33
- setState: (value: SetState<TState>) => void;
26
+ setState: (value: SetStateInput<TState>) => void;
34
27
  getState: () => TState;
35
28
  subscribe: (subscriber: Subscriber<TState>) => () => void;
36
29
  getSubscribers: () => Set<Subscriber<TState>>;