use-abcd 0.0.1 → 0.1.0

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
@@ -29,7 +29,7 @@ bun add use-abcd
29
29
  ## Quick Example
30
30
 
31
31
  ```typescript
32
- import { useCrud } from "use-crud";
32
+ import { useCrud } from "use-abcd";
33
33
 
34
34
  type Todo = {
35
35
  id: string;
@@ -88,6 +88,8 @@ function TodoList() {
88
88
  }
89
89
  ```
90
90
 
91
+ > **Note**: This is a single-file library with a focused scope. Please read the source code for a deeper understanding of its implementation and capabilities.
92
+
91
93
  ## License
92
94
 
93
95
  MIT
package/dist/useCrud.d.ts CHANGED
@@ -28,8 +28,6 @@ export declare type CrudConfig<T extends Item = Item, C = any> = {
28
28
  getServerSnapshot?: () => StoreState<T>;
29
29
  };
30
30
 
31
- export declare function customLog(title?: string, ...messages: any[]): void;
32
-
33
31
  /**
34
32
  * Cache implementation for storing and managing fetch results
35
33
  * with configurable age and capacity limits.
@@ -54,14 +52,14 @@ export declare type FetchFn<T extends Item = Item> = (option: QueryOption) => Pr
54
52
 
55
53
  export declare type Item = {
56
54
  id: string;
57
- } & Record<string, unknown>;
55
+ } & Record<string, any>;
58
56
 
59
57
  export declare type ItemWithState<T extends Item = Item> = {
60
58
  data: T;
61
- state: "create" | "update" | "delete" | "idle" | "error";
59
+ state: TransitionStates;
62
60
  optimistic: boolean;
63
61
  errors: string[];
64
- input?: T;
62
+ action?: [TransitionStates, T];
65
63
  };
66
64
 
67
65
  export declare type QueryOption = {
@@ -86,6 +84,8 @@ export declare type TransitionFn<T extends Item = Item> = (item: Partial<T>, opt
86
84
  id: string;
87
85
  }>;
88
86
 
87
+ export declare type TransitionStates = "create" | "update" | "delete" | "idle" | "error" | "changed";
88
+
89
89
  export declare type Updater<T> = (updatable: T) => void;
90
90
 
91
91
  /**
@@ -101,18 +101,21 @@ export declare function useCrud<T extends Item = Item, C extends Record<string,
101
101
  items: {
102
102
  id: string;
103
103
  data: T;
104
- state: "create" | "update" | "delete" | "idle" | "error";
104
+ state: TransitionStates;
105
105
  optimistic: boolean;
106
106
  errors: string[];
107
- input?: T;
107
+ action?: [TransitionStates, T];
108
108
  }[];
109
109
  metadata: unknown;
110
110
  isLoading: boolean;
111
111
  hasError: boolean;
112
112
  errors: string[];
113
113
  create: (item: Omit<T, "id">) => void;
114
- update: (item: T, updater: Updater<T>, isOptimistic?: boolean) => void;
115
- remove: (item: T) => void;
114
+ update: (item: ItemWithState<T>, updater: Updater<T>, isOptimistic?: boolean) => void;
115
+ change: (item: ItemWithState<T>, updater: Updater<T>) => void;
116
+ retry: (item: ItemWithState<T>) => void;
117
+ save: (item: ItemWithState<T>) => void;
118
+ remove: (item: ItemWithState<T>) => void;
116
119
  cancelFetch: () => void;
117
120
  cancelOperation: (id: string) => void;
118
121
  };
@@ -128,8 +131,11 @@ export declare function useCrudOperations<T extends Item = Item, C extends Recor
128
131
  fetch: () => void;
129
132
  refetch: () => void;
130
133
  create: (item: Omit<T, "id">) => void;
131
- update: (item: T, updater: Updater<T>, isOptimistic?: boolean) => void;
132
- remove: (item: T) => void;
134
+ update: (item: ItemWithState<T>, updater: Updater<T>, isOptimistic?: boolean) => void;
135
+ change: (item: ItemWithState<T>, updater: Updater<T>) => void;
136
+ save: (item: ItemWithState<T>) => void;
137
+ retry: (item: ItemWithState<T>) => void;
138
+ remove: (item: ItemWithState<T>) => void;
133
139
  cancelFetch: () => void;
134
140
  cancelOperation: (id: string) => void;
135
141
  };