use-abcd 1.6.1 → 1.6.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/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { SyncResponseBody } from './runtime';
1
2
  export type JsonValue = string | number | boolean | null | undefined;
2
3
  export type PlainObject = {
3
4
  [key: string]: JsonValue | PlainObject | JsonValue[] | PlainObject[];
@@ -48,7 +49,7 @@ export type CrudHandler<T extends {
48
49
  }, C> = (params: {
49
50
  query?: C;
50
51
  changes?: Change<T>[];
51
- }, signal?: AbortSignal) => Promise<SyncResponse<T>>;
52
+ }, signal?: AbortSignal) => Promise<SyncResponseBody<T>>;
52
53
  export type Config<T extends {
53
54
  id: string;
54
55
  }, C> = {
package/dist/useCrud.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare function useCrud<T extends {
12
12
  syncing: boolean;
13
13
  fetchStatus: import('./types').FetchState;
14
14
  fetchError: string;
15
+ serverState: unknown;
15
16
  create: (item: Omit<T, "id">) => string;
16
17
  update: (id: string, mutate: (draft: Draft<T>) => void) => void;
17
18
  remove: (id: string) => void;
@@ -16,7 +16,7 @@ export type TreeConfig<T extends object, C, NodeType = string> = Omit<Config<Tre
16
16
  * @returns Object with crud operations, state, and the root node
17
17
  */
18
18
  export declare function useCrudTree<T extends object, C, NodeType = string>(config: TreeConfig<T, C, NodeType>): {
19
- rootNode: any;
19
+ rootNode: Node<T, C, NodeType>;
20
20
  items: Map<string, TreeNode<T, NodeType>>;
21
21
  context: C;
22
22
  syncState: import('./types').SyncState;
@@ -25,6 +25,7 @@ export declare function useCrudTree<T extends object, C, NodeType = string>(conf
25
25
  syncing: boolean;
26
26
  fetchStatus: import('./types').FetchState;
27
27
  fetchError: string;
28
+ serverState: unknown;
28
29
  getNode: (id: string) => Node<T, C, NodeType>;
29
30
  getNodeStatus: (id: string) => {
30
31
  type: import('./types').ChangeType;
@@ -39,7 +40,7 @@ export declare function useCrudTree<T extends object, C, NodeType = string>(conf
39
40
  retrySync: (id?: string) => void;
40
41
  selectNode: (id: string) => void;
41
42
  deselectNode: () => void;
42
- selectedNodeId: any;
43
- selectedNode: any;
43
+ selectedNodeId: string;
44
+ selectedNode: Node<T, C, NodeType>;
44
45
  toJson: () => object;
45
46
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Hook for accessing the serverState of a collection by ID.
3
+ *
4
+ * Use this when you need server-provided metadata (e.g., totals, pagination cursors)
5
+ * in a component that doesn't have access to the full useCrud hook.
6
+ *
7
+ * @param collectionId - The ID of the collection
8
+ * @param defaultValue - Value returned when serverState is undefined
9
+ * @returns The serverState cast to T, or the defaultValue
10
+ */
11
+ export declare function useServerState<T>(collectionId: string, defaultValue: T): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-abcd",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "Simple react hook for CRUD type apps",
5
5
  "repository": {
6
6
  "url": "https://github.com/smtrd3/use-abcd"