@echojs-ecosystem/query 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 +80 -0
- package/dist/index.d.ts +822 -0
- package/dist/index.js +2140 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @echojs-ecosystem/query
|
|
4
|
+
|
|
5
|
+
**Signal-native async cache — queries, mutations, and infinite lists without hooks.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@echojs-ecosystem/query)
|
|
8
|
+
[](https://echojs.dev/docs/packages/query)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Model-first data layer inspired by [TanStack Query](https://tanstack.com/query), adapted for EchoJS signals. No React hooks — use **`createQuery` + `.with()`** inside `createModel`.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **`createQuery`** — declarative cache keys, stale time, retry, abort
|
|
19
|
+
- **Signal state** — `$data`, `$status`, `$error`, `$fetchStatus`
|
|
20
|
+
- **`createMutation`** — optimistic updates & rollback
|
|
21
|
+
- **`createInfiniteQuery`** — paginated / cursor lists
|
|
22
|
+
- **`createQueryClient`** — global invalidation, prefetch, cache control
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @echojs-ecosystem/query @echojs-ecosystem/reactivity
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createQuery, createQueryClient } from "@echojs-ecosystem/query";
|
|
34
|
+
|
|
35
|
+
const client = createQueryClient();
|
|
36
|
+
|
|
37
|
+
export const getUserQuery = createQuery({
|
|
38
|
+
name: "get-user",
|
|
39
|
+
key: ({ id }) => ["user", id],
|
|
40
|
+
fetcher: ({ params, signal }) => fetch(`/api/users/${params.id}`, { signal }).then((r) => r.json()),
|
|
41
|
+
staleTime: "5m",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// In a model — reactive params
|
|
45
|
+
const user = getUserQuery.with(() => ({ id: $userId.value() }), { client });
|
|
46
|
+
|
|
47
|
+
user.data();
|
|
48
|
+
user.isPending();
|
|
49
|
+
user.$data.value();
|
|
50
|
+
await user.refetch();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
| Export | Description |
|
|
56
|
+
|--------|-------------|
|
|
57
|
+
| `createQuery` | Query definition |
|
|
58
|
+
| `.with(params)` / `.withStore()` | Bound instance |
|
|
59
|
+
| `createQueryClient` | Global cache |
|
|
60
|
+
| `createMutation` | Write operations |
|
|
61
|
+
| `createInfiniteQuery` | Paginated data |
|
|
62
|
+
| `focusManager` / `onlineManager` | Refetch triggers |
|
|
63
|
+
|
|
64
|
+
### Cancellation
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
await user.refetch({ abortController: new AbortController() });
|
|
68
|
+
user.cancel({ reason: "navigate-away" });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Related packages
|
|
72
|
+
|
|
73
|
+
| Package | Role |
|
|
74
|
+
|---------|------|
|
|
75
|
+
| [`@echojs-ecosystem/store`](https://www.npmjs.com/package/@echojs-ecosystem/store) | Optional `withStore()` integration |
|
|
76
|
+
| [`@echojs-ecosystem/framework`](https://www.npmjs.com/package/@echojs-ecosystem/framework) | Query provider at app bootstrap |
|
|
77
|
+
|
|
78
|
+
## Documentation
|
|
79
|
+
|
|
80
|
+
[echojs.dev/docs/packages/query](https://echojs.dev/docs/packages/query)
|