query-optimistic 0.4.0 → 0.4.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.
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Core types for query-toolkit
3
+ * Framework-agnostic definitions
4
+ */
5
+ /** Extract the ID from an entity */
6
+ type IdGetter<T> = (item: T) => string;
7
+ /** Optimistic status for pending mutations */
8
+ type OptimisticStatus = 'pending' | 'success' | 'error';
9
+ /** Wraps an entity with optimistic metadata */
10
+ type Optimistic<T> = T & {
11
+ _optimistic?: {
12
+ id: string;
13
+ status: OptimisticStatus;
14
+ error?: string;
15
+ };
16
+ };
17
+ /** Collection definition for arrays of items */
18
+ interface CollectionDef<TData, TParams = void> {
19
+ readonly _type: 'collection';
20
+ readonly name: string;
21
+ readonly id: IdGetter<TData>;
22
+ readonly fetch: (params: TParams) => Promise<TData[]>;
23
+ }
24
+ /** Entity definition for single items */
25
+ interface EntityDef<TData, TParams = void> {
26
+ readonly _type: 'entity';
27
+ readonly name: string;
28
+ readonly fetch: (params: TParams) => Promise<TData>;
29
+ }
30
+ /** Mutation definition */
31
+ interface MutationDef<TParams, TResponse = void> {
32
+ readonly _type: 'mutation';
33
+ readonly name?: string;
34
+ readonly mutate: (params: TParams) => Promise<TResponse>;
35
+ }
36
+ /** Unified definition type */
37
+ type AnyDef = CollectionDef<any, any> | EntityDef<any, any>;
38
+ /** Optimistic action types */
39
+ type OptimisticAction = 'prepend' | 'append' | 'update' | 'delete' | 'replace';
40
+ /** Optimistic update instruction */
41
+ interface OptimisticInstruction<T = any> {
42
+ target: CollectionDef<T, any> | EntityDef<T, any>;
43
+ action: OptimisticAction;
44
+ data?: Partial<T>;
45
+ id?: string;
46
+ where?: (item: T) => boolean;
47
+ update?: (item: T) => T;
48
+ }
49
+ /** Options for query execution */
50
+ interface QueryOptions {
51
+ enabled?: boolean;
52
+ staleTime?: number;
53
+ cacheTime?: number;
54
+ refetchOnMount?: boolean;
55
+ refetchOnWindowFocus?: boolean;
56
+ refetchInterval?: number | false;
57
+ }
58
+ /** Options for paginated queries */
59
+ interface PaginatedOptions extends QueryOptions {
60
+ getNextPageParam?: (lastPage: any[], allPages: any[][]) => unknown | undefined;
61
+ }
62
+
63
+ /** Transaction returned from channel methods */
64
+ interface OptimisticTransaction {
65
+ target: CollectionDef<any, any> | EntityDef<any, any>;
66
+ action: 'prepend' | 'append' | 'update' | 'delete' | 'replace';
67
+ data?: any;
68
+ id?: string;
69
+ where?: (item: any) => boolean;
70
+ update?: (item: any) => any;
71
+ sync?: boolean;
72
+ rollback: () => void;
73
+ }
74
+ /** Options for channel operations */
75
+ interface ChannelOptions {
76
+ /**
77
+ * Only apply updates to queries whose params partially match this object.
78
+ * All key-value pairs in scope must exist in the query's params.
79
+ * @example
80
+ * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id)
81
+ * // Only affects queries with params containing chain: 'solana'
82
+ */
83
+ scope?: Record<string, unknown>;
84
+ }
85
+ /** Channel for a collection - provides typed optimistic mutation methods */
86
+ declare class CollectionChannel<TEntity> {
87
+ private readonly target;
88
+ private readonly options?;
89
+ private readonly optimisticId;
90
+ constructor(target: CollectionDef<TEntity, any>, options?: ChannelOptions | undefined);
91
+ /**
92
+ * Prepend an item to the collection
93
+ * @returns Rollback function to undo the change
94
+ */
95
+ prepend(data: TEntity, options?: {
96
+ sync?: boolean;
97
+ }): () => void;
98
+ /**
99
+ * Append an item to the collection
100
+ * @returns Rollback function to undo the change
101
+ */
102
+ append(data: TEntity, options?: {
103
+ sync?: boolean;
104
+ }): () => void;
105
+ /**
106
+ * Update an item in the collection by ID
107
+ * @returns Rollback function to undo the change
108
+ */
109
+ update(id: string, updateFn: (item: TEntity) => TEntity, options?: {
110
+ sync?: boolean;
111
+ }): () => void;
112
+ /**
113
+ * Update items matching a predicate
114
+ * @returns Rollback function to undo the change
115
+ */
116
+ updateWhere(where: (item: TEntity) => boolean, updateFn: (item: TEntity) => TEntity): () => void;
117
+ /**
118
+ * Delete an item from the collection by ID
119
+ * @returns Rollback function to undo the change
120
+ */
121
+ delete(id: string): () => void;
122
+ /**
123
+ * Delete items matching a predicate
124
+ * @returns Rollback function to undo the change
125
+ */
126
+ deleteWhere(where: (item: TEntity) => boolean): () => void;
127
+ }
128
+ /** Channel for an entity - provides typed optimistic mutation methods */
129
+ declare class EntityChannel<TEntity> {
130
+ private readonly target;
131
+ constructor(target: EntityDef<TEntity, any>);
132
+ /**
133
+ * Update the entity
134
+ * @returns Rollback function to undo the change
135
+ */
136
+ update(updateFn: (item: TEntity) => TEntity, options?: {
137
+ sync?: boolean;
138
+ }): () => void;
139
+ /**
140
+ * Replace the entity with new data
141
+ * @returns Rollback function to undo the change
142
+ */
143
+ replace(data: TEntity, options?: {
144
+ sync?: boolean;
145
+ }): () => void;
146
+ }
147
+ /**
148
+ * Channel function for optimistic mutations.
149
+ * Call with a collection or entity to get typed mutation methods.
150
+ *
151
+ * @example
152
+ * // Standalone usage
153
+ * const rollback = channel(usersCollection).prepend({ id: '1', name: 'John' });
154
+ * // Later, to undo:
155
+ * rollback();
156
+ *
157
+ * @example
158
+ * // Update an entity
159
+ * channel(userEntity).update(user => ({ ...user, name: 'Jane' }));
160
+ *
161
+ * @example
162
+ * // Scoped update
163
+ * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id);
164
+ * // Only affects queries with params containing chain: 'solana'
165
+ */
166
+ interface Channel {
167
+ <TEntity>(target: CollectionDef<TEntity, any>, options?: ChannelOptions): CollectionChannel<TEntity>;
168
+ <TEntity>(target: EntityDef<TEntity, any>): EntityChannel<TEntity>;
169
+ }
170
+ /**
171
+ * Create a channel for optimistic mutations.
172
+ * Use this to apply immediate UI updates that can be rolled back.
173
+ *
174
+ * @example
175
+ * const rollback = channel(usersCollection).prepend(newUser);
176
+ * try {
177
+ * await api.createUser(newUser);
178
+ * } catch (error) {
179
+ * rollback(); // Undo the optimistic update
180
+ * }
181
+ *
182
+ * @example
183
+ * // Scoped update - only affects queries with matching params
184
+ * channel(ordersCollection, { scope: { chain: 'solana', status: 'pending' } }).delete(id);
185
+ */
186
+ declare const channel: Channel;
187
+
188
+ export { type AnyDef as A, type Channel as C, EntityChannel as E, type IdGetter as I, type MutationDef as M, type Optimistic as O, type PaginatedOptions as P, type QueryOptions as Q, type ChannelOptions as a, CollectionChannel as b, type CollectionDef as c, type EntityDef as d, type OptimisticAction as e, type OptimisticInstruction as f, type OptimisticStatus as g, type OptimisticTransaction as h, channel as i };
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Core types for query-toolkit
3
+ * Framework-agnostic definitions
4
+ */
5
+ /** Extract the ID from an entity */
6
+ type IdGetter<T> = (item: T) => string;
7
+ /** Optimistic status for pending mutations */
8
+ type OptimisticStatus = 'pending' | 'success' | 'error';
9
+ /** Wraps an entity with optimistic metadata */
10
+ type Optimistic<T> = T & {
11
+ _optimistic?: {
12
+ id: string;
13
+ status: OptimisticStatus;
14
+ error?: string;
15
+ };
16
+ };
17
+ /** Collection definition for arrays of items */
18
+ interface CollectionDef<TData, TParams = void> {
19
+ readonly _type: 'collection';
20
+ readonly name: string;
21
+ readonly id: IdGetter<TData>;
22
+ readonly fetch: (params: TParams) => Promise<TData[]>;
23
+ }
24
+ /** Entity definition for single items */
25
+ interface EntityDef<TData, TParams = void> {
26
+ readonly _type: 'entity';
27
+ readonly name: string;
28
+ readonly fetch: (params: TParams) => Promise<TData>;
29
+ }
30
+ /** Mutation definition */
31
+ interface MutationDef<TParams, TResponse = void> {
32
+ readonly _type: 'mutation';
33
+ readonly name?: string;
34
+ readonly mutate: (params: TParams) => Promise<TResponse>;
35
+ }
36
+ /** Unified definition type */
37
+ type AnyDef = CollectionDef<any, any> | EntityDef<any, any>;
38
+ /** Optimistic action types */
39
+ type OptimisticAction = 'prepend' | 'append' | 'update' | 'delete' | 'replace';
40
+ /** Optimistic update instruction */
41
+ interface OptimisticInstruction<T = any> {
42
+ target: CollectionDef<T, any> | EntityDef<T, any>;
43
+ action: OptimisticAction;
44
+ data?: Partial<T>;
45
+ id?: string;
46
+ where?: (item: T) => boolean;
47
+ update?: (item: T) => T;
48
+ }
49
+ /** Options for query execution */
50
+ interface QueryOptions {
51
+ enabled?: boolean;
52
+ staleTime?: number;
53
+ cacheTime?: number;
54
+ refetchOnMount?: boolean;
55
+ refetchOnWindowFocus?: boolean;
56
+ refetchInterval?: number | false;
57
+ }
58
+ /** Options for paginated queries */
59
+ interface PaginatedOptions extends QueryOptions {
60
+ getNextPageParam?: (lastPage: any[], allPages: any[][]) => unknown | undefined;
61
+ }
62
+
63
+ /** Transaction returned from channel methods */
64
+ interface OptimisticTransaction {
65
+ target: CollectionDef<any, any> | EntityDef<any, any>;
66
+ action: 'prepend' | 'append' | 'update' | 'delete' | 'replace';
67
+ data?: any;
68
+ id?: string;
69
+ where?: (item: any) => boolean;
70
+ update?: (item: any) => any;
71
+ sync?: boolean;
72
+ rollback: () => void;
73
+ }
74
+ /** Options for channel operations */
75
+ interface ChannelOptions {
76
+ /**
77
+ * Only apply updates to queries whose params partially match this object.
78
+ * All key-value pairs in scope must exist in the query's params.
79
+ * @example
80
+ * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id)
81
+ * // Only affects queries with params containing chain: 'solana'
82
+ */
83
+ scope?: Record<string, unknown>;
84
+ }
85
+ /** Channel for a collection - provides typed optimistic mutation methods */
86
+ declare class CollectionChannel<TEntity> {
87
+ private readonly target;
88
+ private readonly options?;
89
+ private readonly optimisticId;
90
+ constructor(target: CollectionDef<TEntity, any>, options?: ChannelOptions | undefined);
91
+ /**
92
+ * Prepend an item to the collection
93
+ * @returns Rollback function to undo the change
94
+ */
95
+ prepend(data: TEntity, options?: {
96
+ sync?: boolean;
97
+ }): () => void;
98
+ /**
99
+ * Append an item to the collection
100
+ * @returns Rollback function to undo the change
101
+ */
102
+ append(data: TEntity, options?: {
103
+ sync?: boolean;
104
+ }): () => void;
105
+ /**
106
+ * Update an item in the collection by ID
107
+ * @returns Rollback function to undo the change
108
+ */
109
+ update(id: string, updateFn: (item: TEntity) => TEntity, options?: {
110
+ sync?: boolean;
111
+ }): () => void;
112
+ /**
113
+ * Update items matching a predicate
114
+ * @returns Rollback function to undo the change
115
+ */
116
+ updateWhere(where: (item: TEntity) => boolean, updateFn: (item: TEntity) => TEntity): () => void;
117
+ /**
118
+ * Delete an item from the collection by ID
119
+ * @returns Rollback function to undo the change
120
+ */
121
+ delete(id: string): () => void;
122
+ /**
123
+ * Delete items matching a predicate
124
+ * @returns Rollback function to undo the change
125
+ */
126
+ deleteWhere(where: (item: TEntity) => boolean): () => void;
127
+ }
128
+ /** Channel for an entity - provides typed optimistic mutation methods */
129
+ declare class EntityChannel<TEntity> {
130
+ private readonly target;
131
+ constructor(target: EntityDef<TEntity, any>);
132
+ /**
133
+ * Update the entity
134
+ * @returns Rollback function to undo the change
135
+ */
136
+ update(updateFn: (item: TEntity) => TEntity, options?: {
137
+ sync?: boolean;
138
+ }): () => void;
139
+ /**
140
+ * Replace the entity with new data
141
+ * @returns Rollback function to undo the change
142
+ */
143
+ replace(data: TEntity, options?: {
144
+ sync?: boolean;
145
+ }): () => void;
146
+ }
147
+ /**
148
+ * Channel function for optimistic mutations.
149
+ * Call with a collection or entity to get typed mutation methods.
150
+ *
151
+ * @example
152
+ * // Standalone usage
153
+ * const rollback = channel(usersCollection).prepend({ id: '1', name: 'John' });
154
+ * // Later, to undo:
155
+ * rollback();
156
+ *
157
+ * @example
158
+ * // Update an entity
159
+ * channel(userEntity).update(user => ({ ...user, name: 'Jane' }));
160
+ *
161
+ * @example
162
+ * // Scoped update
163
+ * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id);
164
+ * // Only affects queries with params containing chain: 'solana'
165
+ */
166
+ interface Channel {
167
+ <TEntity>(target: CollectionDef<TEntity, any>, options?: ChannelOptions): CollectionChannel<TEntity>;
168
+ <TEntity>(target: EntityDef<TEntity, any>): EntityChannel<TEntity>;
169
+ }
170
+ /**
171
+ * Create a channel for optimistic mutations.
172
+ * Use this to apply immediate UI updates that can be rolled back.
173
+ *
174
+ * @example
175
+ * const rollback = channel(usersCollection).prepend(newUser);
176
+ * try {
177
+ * await api.createUser(newUser);
178
+ * } catch (error) {
179
+ * rollback(); // Undo the optimistic update
180
+ * }
181
+ *
182
+ * @example
183
+ * // Scoped update - only affects queries with matching params
184
+ * channel(ordersCollection, { scope: { chain: 'solana', status: 'pending' } }).delete(id);
185
+ */
186
+ declare const channel: Channel;
187
+
188
+ export { type AnyDef as A, type Channel as C, EntityChannel as E, type IdGetter as I, type MutationDef as M, type Optimistic as O, type PaginatedOptions as P, type QueryOptions as Q, type ChannelOptions as a, CollectionChannel as b, type CollectionDef as c, type EntityDef as d, type OptimisticAction as e, type OptimisticInstruction as f, type OptimisticStatus as g, type OptimisticTransaction as h, channel as i };
@@ -1,5 +1,5 @@
1
- import { I as IdGetter, C as CollectionDef, E as EntityDef, M as MutationDef, O as Optimistic } from '../types-BOq5W_Qm.mjs';
2
- export { A as AnyDef, a as OptimisticAction, b as OptimisticInstruction, c as OptimisticStatus, P as PaginatedOptions, Q as QueryOptions } from '../types-BOq5W_Qm.mjs';
1
+ import { I as IdGetter, c as CollectionDef, d as EntityDef, M as MutationDef, O as Optimistic } from '../channel-OFFEKFI1.mjs';
2
+ export { A as AnyDef, C as Channel, a as ChannelOptions, b as CollectionChannel, E as EntityChannel, e as OptimisticAction, f as OptimisticInstruction, g as OptimisticStatus, h as OptimisticTransaction, P as PaginatedOptions, Q as QueryOptions, i as channel } from '../channel-OFFEKFI1.mjs';
3
3
  import { QueryClient } from '@tanstack/react-query';
4
4
 
5
5
  /**
@@ -118,129 +118,4 @@ declare class QueryRegistry {
118
118
  /** Singleton registry instance */
119
119
  declare const registry: QueryRegistry;
120
120
 
121
- /** Transaction returned from channel methods */
122
- interface OptimisticTransaction {
123
- target: CollectionDef<any, any> | EntityDef<any, any>;
124
- action: 'prepend' | 'append' | 'update' | 'delete' | 'replace';
125
- data?: any;
126
- id?: string;
127
- where?: (item: any) => boolean;
128
- update?: (item: any) => any;
129
- sync?: boolean;
130
- rollback: () => void;
131
- }
132
- /** Options for channel operations */
133
- interface ChannelOptions {
134
- /**
135
- * Only apply updates to queries whose params partially match this object.
136
- * All key-value pairs in scope must exist in the query's params.
137
- * @example
138
- * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id)
139
- * // Only affects queries with params containing chain: 'solana'
140
- */
141
- scope?: Record<string, unknown>;
142
- }
143
- /** Channel for a collection - provides typed optimistic mutation methods */
144
- declare class CollectionChannel<TEntity> {
145
- private readonly target;
146
- private readonly options?;
147
- private readonly optimisticId;
148
- constructor(target: CollectionDef<TEntity, any>, options?: ChannelOptions | undefined);
149
- /**
150
- * Prepend an item to the collection
151
- * @returns Rollback function to undo the change
152
- */
153
- prepend(data: TEntity, options?: {
154
- sync?: boolean;
155
- }): () => void;
156
- /**
157
- * Append an item to the collection
158
- * @returns Rollback function to undo the change
159
- */
160
- append(data: TEntity, options?: {
161
- sync?: boolean;
162
- }): () => void;
163
- /**
164
- * Update an item in the collection by ID
165
- * @returns Rollback function to undo the change
166
- */
167
- update(id: string, updateFn: (item: TEntity) => TEntity, options?: {
168
- sync?: boolean;
169
- }): () => void;
170
- /**
171
- * Update items matching a predicate
172
- * @returns Rollback function to undo the change
173
- */
174
- updateWhere(where: (item: TEntity) => boolean, updateFn: (item: TEntity) => TEntity): () => void;
175
- /**
176
- * Delete an item from the collection by ID
177
- * @returns Rollback function to undo the change
178
- */
179
- delete(id: string): () => void;
180
- /**
181
- * Delete items matching a predicate
182
- * @returns Rollback function to undo the change
183
- */
184
- deleteWhere(where: (item: TEntity) => boolean): () => void;
185
- }
186
- /** Channel for an entity - provides typed optimistic mutation methods */
187
- declare class EntityChannel<TEntity> {
188
- private readonly target;
189
- constructor(target: EntityDef<TEntity, any>);
190
- /**
191
- * Update the entity
192
- * @returns Rollback function to undo the change
193
- */
194
- update(updateFn: (item: TEntity) => TEntity, options?: {
195
- sync?: boolean;
196
- }): () => void;
197
- /**
198
- * Replace the entity with new data
199
- * @returns Rollback function to undo the change
200
- */
201
- replace(data: TEntity, options?: {
202
- sync?: boolean;
203
- }): () => void;
204
- }
205
- /**
206
- * Channel function for optimistic mutations.
207
- * Call with a collection or entity to get typed mutation methods.
208
- *
209
- * @example
210
- * // Standalone usage
211
- * const rollback = channel(usersCollection).prepend({ id: '1', name: 'John' });
212
- * // Later, to undo:
213
- * rollback();
214
- *
215
- * @example
216
- * // Update an entity
217
- * channel(userEntity).update(user => ({ ...user, name: 'Jane' }));
218
- *
219
- * @example
220
- * // Scoped update
221
- * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id);
222
- * // Only affects queries with params containing chain: 'solana'
223
- */
224
- interface Channel {
225
- <TEntity>(target: CollectionDef<TEntity, any>, options?: ChannelOptions): CollectionChannel<TEntity>;
226
- <TEntity>(target: EntityDef<TEntity, any>): EntityChannel<TEntity>;
227
- }
228
- /**
229
- * Create a channel for optimistic mutations.
230
- * Use this to apply immediate UI updates that can be rolled back.
231
- *
232
- * @example
233
- * const rollback = channel(usersCollection).prepend(newUser);
234
- * try {
235
- * await api.createUser(newUser);
236
- * } catch (error) {
237
- * rollback(); // Undo the optimistic update
238
- * }
239
- *
240
- * @example
241
- * // Scoped update - only affects queries with matching params
242
- * channel(ordersCollection, { scope: { chain: 'solana', status: 'pending' } }).delete(id);
243
- */
244
- declare const channel: Channel;
245
-
246
- export { type Channel, type ChannelOptions, CollectionChannel, CollectionDef, EntityChannel, EntityDef, IdGetter, MutationDef, Optimistic, type OptimisticTransaction, type RegisteredCollection, type RegisteredEntity, type RegisteredEntry, type RegisteredPaginatedCollection, channel, defineCollection, defineEntity, defineMutation, registry };
121
+ export { CollectionDef, EntityDef, IdGetter, MutationDef, Optimistic, type RegisteredCollection, type RegisteredEntity, type RegisteredEntry, type RegisteredPaginatedCollection, defineCollection, defineEntity, defineMutation, registry };
@@ -1,5 +1,5 @@
1
- import { I as IdGetter, C as CollectionDef, E as EntityDef, M as MutationDef, O as Optimistic } from '../types-BOq5W_Qm.js';
2
- export { A as AnyDef, a as OptimisticAction, b as OptimisticInstruction, c as OptimisticStatus, P as PaginatedOptions, Q as QueryOptions } from '../types-BOq5W_Qm.js';
1
+ import { I as IdGetter, c as CollectionDef, d as EntityDef, M as MutationDef, O as Optimistic } from '../channel-OFFEKFI1.js';
2
+ export { A as AnyDef, C as Channel, a as ChannelOptions, b as CollectionChannel, E as EntityChannel, e as OptimisticAction, f as OptimisticInstruction, g as OptimisticStatus, h as OptimisticTransaction, P as PaginatedOptions, Q as QueryOptions, i as channel } from '../channel-OFFEKFI1.js';
3
3
  import { QueryClient } from '@tanstack/react-query';
4
4
 
5
5
  /**
@@ -118,129 +118,4 @@ declare class QueryRegistry {
118
118
  /** Singleton registry instance */
119
119
  declare const registry: QueryRegistry;
120
120
 
121
- /** Transaction returned from channel methods */
122
- interface OptimisticTransaction {
123
- target: CollectionDef<any, any> | EntityDef<any, any>;
124
- action: 'prepend' | 'append' | 'update' | 'delete' | 'replace';
125
- data?: any;
126
- id?: string;
127
- where?: (item: any) => boolean;
128
- update?: (item: any) => any;
129
- sync?: boolean;
130
- rollback: () => void;
131
- }
132
- /** Options for channel operations */
133
- interface ChannelOptions {
134
- /**
135
- * Only apply updates to queries whose params partially match this object.
136
- * All key-value pairs in scope must exist in the query's params.
137
- * @example
138
- * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id)
139
- * // Only affects queries with params containing chain: 'solana'
140
- */
141
- scope?: Record<string, unknown>;
142
- }
143
- /** Channel for a collection - provides typed optimistic mutation methods */
144
- declare class CollectionChannel<TEntity> {
145
- private readonly target;
146
- private readonly options?;
147
- private readonly optimisticId;
148
- constructor(target: CollectionDef<TEntity, any>, options?: ChannelOptions | undefined);
149
- /**
150
- * Prepend an item to the collection
151
- * @returns Rollback function to undo the change
152
- */
153
- prepend(data: TEntity, options?: {
154
- sync?: boolean;
155
- }): () => void;
156
- /**
157
- * Append an item to the collection
158
- * @returns Rollback function to undo the change
159
- */
160
- append(data: TEntity, options?: {
161
- sync?: boolean;
162
- }): () => void;
163
- /**
164
- * Update an item in the collection by ID
165
- * @returns Rollback function to undo the change
166
- */
167
- update(id: string, updateFn: (item: TEntity) => TEntity, options?: {
168
- sync?: boolean;
169
- }): () => void;
170
- /**
171
- * Update items matching a predicate
172
- * @returns Rollback function to undo the change
173
- */
174
- updateWhere(where: (item: TEntity) => boolean, updateFn: (item: TEntity) => TEntity): () => void;
175
- /**
176
- * Delete an item from the collection by ID
177
- * @returns Rollback function to undo the change
178
- */
179
- delete(id: string): () => void;
180
- /**
181
- * Delete items matching a predicate
182
- * @returns Rollback function to undo the change
183
- */
184
- deleteWhere(where: (item: TEntity) => boolean): () => void;
185
- }
186
- /** Channel for an entity - provides typed optimistic mutation methods */
187
- declare class EntityChannel<TEntity> {
188
- private readonly target;
189
- constructor(target: EntityDef<TEntity, any>);
190
- /**
191
- * Update the entity
192
- * @returns Rollback function to undo the change
193
- */
194
- update(updateFn: (item: TEntity) => TEntity, options?: {
195
- sync?: boolean;
196
- }): () => void;
197
- /**
198
- * Replace the entity with new data
199
- * @returns Rollback function to undo the change
200
- */
201
- replace(data: TEntity, options?: {
202
- sync?: boolean;
203
- }): () => void;
204
- }
205
- /**
206
- * Channel function for optimistic mutations.
207
- * Call with a collection or entity to get typed mutation methods.
208
- *
209
- * @example
210
- * // Standalone usage
211
- * const rollback = channel(usersCollection).prepend({ id: '1', name: 'John' });
212
- * // Later, to undo:
213
- * rollback();
214
- *
215
- * @example
216
- * // Update an entity
217
- * channel(userEntity).update(user => ({ ...user, name: 'Jane' }));
218
- *
219
- * @example
220
- * // Scoped update
221
- * channel(ordersCollection, { scope: { chain: 'solana' } }).delete(id);
222
- * // Only affects queries with params containing chain: 'solana'
223
- */
224
- interface Channel {
225
- <TEntity>(target: CollectionDef<TEntity, any>, options?: ChannelOptions): CollectionChannel<TEntity>;
226
- <TEntity>(target: EntityDef<TEntity, any>): EntityChannel<TEntity>;
227
- }
228
- /**
229
- * Create a channel for optimistic mutations.
230
- * Use this to apply immediate UI updates that can be rolled back.
231
- *
232
- * @example
233
- * const rollback = channel(usersCollection).prepend(newUser);
234
- * try {
235
- * await api.createUser(newUser);
236
- * } catch (error) {
237
- * rollback(); // Undo the optimistic update
238
- * }
239
- *
240
- * @example
241
- * // Scoped update - only affects queries with matching params
242
- * channel(ordersCollection, { scope: { chain: 'solana', status: 'pending' } }).delete(id);
243
- */
244
- declare const channel: Channel;
245
-
246
- export { type Channel, type ChannelOptions, CollectionChannel, CollectionDef, EntityChannel, EntityDef, IdGetter, MutationDef, Optimistic, type OptimisticTransaction, type RegisteredCollection, type RegisteredEntity, type RegisteredEntry, type RegisteredPaginatedCollection, channel, defineCollection, defineEntity, defineMutation, registry };
121
+ export { CollectionDef, EntityDef, IdGetter, MutationDef, Optimistic, type RegisteredCollection, type RegisteredEntity, type RegisteredEntry, type RegisteredPaginatedCollection, defineCollection, defineEntity, defineMutation, registry };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AnyDef, C as CollectionDef, E as EntityDef, I as IdGetter, M as MutationDef, O as Optimistic, a as OptimisticAction, b as OptimisticInstruction, c as OptimisticStatus, P as PaginatedOptions, Q as QueryOptions } from './types-BOq5W_Qm.mjs';
2
- export { Channel, ChannelOptions, CollectionChannel, EntityChannel, OptimisticTransaction, RegisteredCollection, RegisteredEntity, RegisteredEntry, RegisteredPaginatedCollection, channel, defineCollection, defineEntity, defineMutation, registry } from './core/index.mjs';
1
+ export { A as AnyDef, C as Channel, a as ChannelOptions, b as CollectionChannel, c as CollectionDef, E as EntityChannel, d as EntityDef, I as IdGetter, M as MutationDef, O as Optimistic, e as OptimisticAction, f as OptimisticInstruction, g as OptimisticStatus, h as OptimisticTransaction, P as PaginatedOptions, Q as QueryOptions, i as channel } from './channel-OFFEKFI1.mjs';
2
+ export { RegisteredCollection, RegisteredEntity, RegisteredEntry, RegisteredPaginatedCollection, defineCollection, defineEntity, defineMutation, registry } from './core/index.mjs';
3
3
  export { EntityResult, OptimisticConfig, PaginatedQueryResult, QueryResult, UseMutationOptions, UseQueryHookOptions, useMutation, useQuery } from './react/index.mjs';
4
4
  import '@tanstack/react-query';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AnyDef, C as CollectionDef, E as EntityDef, I as IdGetter, M as MutationDef, O as Optimistic, a as OptimisticAction, b as OptimisticInstruction, c as OptimisticStatus, P as PaginatedOptions, Q as QueryOptions } from './types-BOq5W_Qm.js';
2
- export { Channel, ChannelOptions, CollectionChannel, EntityChannel, OptimisticTransaction, RegisteredCollection, RegisteredEntity, RegisteredEntry, RegisteredPaginatedCollection, channel, defineCollection, defineEntity, defineMutation, registry } from './core/index.js';
1
+ export { A as AnyDef, C as Channel, a as ChannelOptions, b as CollectionChannel, c as CollectionDef, E as EntityChannel, d as EntityDef, I as IdGetter, M as MutationDef, O as Optimistic, e as OptimisticAction, f as OptimisticInstruction, g as OptimisticStatus, h as OptimisticTransaction, P as PaginatedOptions, Q as QueryOptions, i as channel } from './channel-OFFEKFI1.js';
2
+ export { RegisteredCollection, RegisteredEntity, RegisteredEntry, RegisteredPaginatedCollection, defineCollection, defineEntity, defineMutation, registry } from './core/index.js';
3
3
  export { EntityResult, OptimisticConfig, PaginatedQueryResult, QueryResult, UseMutationOptions, UseQueryHookOptions, useMutation, useQuery } from './react/index.js';
4
4
  import '@tanstack/react-query';