@braine/quantum-query 1.1.1 → 1.2.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 +81 -6
- package/dist/index.cjs +1312 -137
- package/dist/index.d.cts +298 -9
- package/dist/index.d.ts +298 -9
- package/dist/index.js +1301 -136
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -114,15 +114,90 @@ const users = await api.get('/users');
|
|
|
114
114
|
|
|
115
115
|
---
|
|
116
116
|
|
|
117
|
+
## Data Integrity (Runtime Safety)
|
|
118
|
+
|
|
119
|
+
Don't trust the backend. Validate it. We support **Zod**, **Valibot**, or **Yup** directly.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { z } from 'zod';
|
|
123
|
+
|
|
124
|
+
const UserSchema = z.object({
|
|
125
|
+
id: z.string(),
|
|
126
|
+
name: z.string()
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// 1. Runtime Validation: Throws error if API returns garbage
|
|
130
|
+
// 2. Auto-Typing: 'user' is inferred as { id: string, name: string }
|
|
131
|
+
const user = await api.get('/me', {
|
|
132
|
+
schema: UserSchema
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Enterprise Query Features ✨
|
|
139
|
+
|
|
140
|
+
TanStack Query-level features with simpler API:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { useQuery, usePaginatedQuery, useInfiniteQuery, useMutation } from '@braine/quantum-query';
|
|
144
|
+
|
|
145
|
+
// Background refetch (stale-while-revalidate)
|
|
146
|
+
const { data, isStale } = useQuery({
|
|
147
|
+
queryKey: ['user'],
|
|
148
|
+
queryFn: () => api.get('/me'),
|
|
149
|
+
staleTime: 30000,
|
|
150
|
+
refetchOnWindowFocus: true // Auto-refresh on tab return
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Pagination
|
|
154
|
+
const { data, nextPage, hasNext } = usePaginatedQuery({
|
|
155
|
+
queryKey: ['users'],
|
|
156
|
+
queryFn: (page) => api.get(`/users?page=${page}`)
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Infinite Scroll
|
|
160
|
+
const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
|
|
161
|
+
queryKey: ['feed'],
|
|
162
|
+
queryFn: ({ pageParam }) => api.get(`/feed?cursor=${pageParam}`),
|
|
163
|
+
getNextPageParam: (last) => last.nextCursor
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Optimistic Updates
|
|
167
|
+
const addTodo = useMutation({
|
|
168
|
+
mutationFn: (todo) => api.post('/todos', todo),
|
|
169
|
+
onMutate: async (newTodo) => {
|
|
170
|
+
// Instant UI update
|
|
171
|
+
const prev = optimisticHelpers.getQueryData(['todos']);
|
|
172
|
+
optimisticHelpers.setQueryData(['todos'], old => [...old, newTodo]);
|
|
173
|
+
return { prev };
|
|
174
|
+
},
|
|
175
|
+
onError: (err, vars, ctx) => {
|
|
176
|
+
// Auto-rollback on error
|
|
177
|
+
optimisticHelpers.setQueryData(['todos'], ctx.prev);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
117
184
|
## Comparison
|
|
118
185
|
|
|
119
|
-
| Feature | Redux Toolkit | TanStack Query | **Quantum-Query** |
|
|
186
|
+
| Feature | Redux Toolkit + RTK Query | TanStack Query | **Quantum-Query** |
|
|
120
187
|
| :--- | :--- | :--- | :--- |
|
|
121
|
-
| **
|
|
122
|
-
| **Boilerplate** | High | Medium | **
|
|
123
|
-
| **Performance** |
|
|
124
|
-
| **
|
|
125
|
-
| **
|
|
188
|
+
| **State + Queries** | Separate (Redux + RTK) | Queries only | **Unified** ✅ |
|
|
189
|
+
| **Boilerplate** | High | Medium | **Minimal** ✅ |
|
|
190
|
+
| **Performance** | Good | Good | **O(1) Reactivity** ✅ |
|
|
191
|
+
| **Pagination** | Yes | Yes | **Yes** ✅ |
|
|
192
|
+
| **Infinite Scroll** | Yes | Yes | **Yes** ✅ |
|
|
193
|
+
| **Optimistic Updates** | Manual | Yes | **Yes** ✅ |
|
|
194
|
+
| **Bundle Size** | ~40kb | ~13kb | **~8kb** ✅ |
|
|
195
|
+
| **Learning Curve** | Steep | Medium | **Gentle** ✅ |
|
|
196
|
+
|
|
197
|
+
**Alpha Status:** Battle-testing in progress. Use for new projects, migrate carefully for production.
|
|
198
|
+
|
|
199
|
+
---
|
|
126
200
|
|
|
127
201
|
## License
|
|
128
202
|
MIT
|
|
203
|
+
# -braine-quantum-query
|