@gettersethya/mira-tanstack-adapter 0.1.0-alpha.21 → 0.1.0-alpha.22
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 +158 -160
- package/dist/_core.d.ts +53 -199
- package/dist/_core.d.ts.map +1 -1
- package/dist/_core.js +78 -83
- package/dist/_core.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -34
- package/dist/react.d.ts +0 -173
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -34
- package/dist/react.js.map +0 -1
- package/dist/solid.d.ts +0 -180
- package/dist/solid.d.ts.map +0 -1
- package/dist/solid.js +0 -41
- package/dist/solid.js.map +0 -1
- package/dist/svelte.d.ts +0 -161
- package/dist/svelte.d.ts.map +0 -1
- package/dist/svelte.js +0 -50
- package/dist/svelte.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,160 +1,158 @@
|
|
|
1
|
-
# @gettersethya/mira-tanstack-adapter
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@gettersethya/mira-tanstack-adapter)
|
|
4
|
-
|
|
5
|
-
> **Early pre-alpha.** Breaking changes may occur without notice.
|
|
6
|
-
|
|
7
|
-
TanStack Query
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Setup
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// ["posts", "
|
|
137
|
-
// ["posts", "
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
See the [Mira root README](https://github.com/gettersethya/mira) for collection definitions, field types, rules, and client usage.
|
|
1
|
+
# @gettersethya/mira-tanstack-adapter
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@gettersethya/mira-tanstack-adapter)
|
|
4
|
+
|
|
5
|
+
> **Early pre-alpha.** Breaking changes may occur without notice.
|
|
6
|
+
|
|
7
|
+
Framework-agnostic TanStack Query adapter for
|
|
8
|
+
[@gettersethya/mira-client](https://www.npmjs.com/package/@gettersethya/mira-client).
|
|
9
|
+
Wraps a collection client's methods with `queryOptions` and `mutationOptions`,
|
|
10
|
+
with structured query keys for fine-grained cache invalidation.
|
|
11
|
+
|
|
12
|
+
The option objects are plain `{ queryKey, queryFn }` / `{ mutationFn }` shapes,
|
|
13
|
+
so this package has **no runtime dependency on TanStack** — `useQuery` /
|
|
14
|
+
`useMutation` (React, Solid) and `createQuery` / `createMutation` (Svelte) all
|
|
15
|
+
accept them and infer `data`.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @gettersethya/mira-tanstack-adapter
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`@gettersethya/mira-client` is a required peer dependency. Install whichever
|
|
24
|
+
TanStack Query package your framework uses separately.
|
|
25
|
+
|
|
26
|
+
## Setup
|
|
27
|
+
|
|
28
|
+
Pass `collectionAdapter` to `withCollections` and every accessor is enriched in
|
|
29
|
+
one call:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { createMiraClient } from "@gettersethya/mira-client"
|
|
33
|
+
import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter"
|
|
34
|
+
import { Posts, Users } from "./collections.js"
|
|
35
|
+
|
|
36
|
+
export const client = createMiraClient("/api").withCollections(
|
|
37
|
+
{ posts: Posts, users: Users },
|
|
38
|
+
{ adapter: collectionAdapter },
|
|
39
|
+
)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Queries
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { useQuery } from "@tanstack/react-query"
|
|
46
|
+
import { client } from "./setup.js"
|
|
47
|
+
|
|
48
|
+
function PostList() {
|
|
49
|
+
const { data, isLoading } = useQuery(
|
|
50
|
+
client.posts.getList({
|
|
51
|
+
filter: (f) => f.field("published").eq(true),
|
|
52
|
+
limit: 10,
|
|
53
|
+
}).queryOptions
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if (isLoading) return <p>Loading...</p>
|
|
57
|
+
return <ul>{data?.items.map(p => <li key={p.id}>{p.title}</li>)}</ul>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function PostDetail({ id }: { id: string }) {
|
|
61
|
+
const { data } = useQuery(client.posts.getOne(id).queryOptions)
|
|
62
|
+
return <h1>{data?.title}</h1>
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Mutations
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
70
|
+
import { client } from "./setup.js"
|
|
71
|
+
|
|
72
|
+
function PostActions() {
|
|
73
|
+
const queryClient = useQueryClient()
|
|
74
|
+
|
|
75
|
+
const create = useMutation({
|
|
76
|
+
...client.posts.create().mutationOptions,
|
|
77
|
+
onSuccess: () => client.posts.invalidateAll(queryClient),
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const update = useMutation({
|
|
81
|
+
...client.posts.update().mutationOptions,
|
|
82
|
+
onSuccess: (post) => client.posts.invalidateOne(queryClient, post.id),
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const remove = useMutation({
|
|
86
|
+
...client.posts.delete().mutationOptions,
|
|
87
|
+
onSuccess: () => client.posts.invalidateAll(queryClient),
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<button onClick={() => create.mutate({ title: "New Post", published: false })}>
|
|
92
|
+
Create
|
|
93
|
+
</button>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Solid and Svelte
|
|
99
|
+
|
|
100
|
+
The same call shape works everywhere — the adapter is framework-agnostic:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Solid — createQuery / createMutation from @tanstack/solid-query
|
|
104
|
+
createQuery(() => client.posts.getList({ limit: 10 }).queryOptions)
|
|
105
|
+
|
|
106
|
+
// Svelte — reactive getters from @tanstack/svelte-query
|
|
107
|
+
createQuery(() => client.posts.getList({ limit: 10 }).queryOptions)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Per-collection usage
|
|
111
|
+
|
|
112
|
+
If you prefer to adapt a single collection (for example with `createMiraClient().collection(def)`),
|
|
113
|
+
call the adapter directly:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter"
|
|
117
|
+
|
|
118
|
+
const postsApi = collectionAdapter(client.collection(Posts), Posts.name, Posts.schema["x-collection-kind"])
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Or build one yourself with the framework-agnostic factory:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { createCollectionAdapter } from "@gettersethya/mira-tanstack-adapter"
|
|
125
|
+
|
|
126
|
+
const collectionAdapter = createCollectionAdapter()
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Query key structure
|
|
130
|
+
|
|
131
|
+
The adapter produces structured query keys for fine-grained cache invalidation:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// ["posts", "getList", { limit, filter, sort, order, cursor, select, expand }]
|
|
135
|
+
// ["posts", "getOne", "post-id", {}]
|
|
136
|
+
// ["posts", "getFirstOrNone", { filter, sort, order, select, expand }]
|
|
137
|
+
// ["posts", "getFullList", { limit, filter, sort, order, select, expand }]
|
|
138
|
+
|
|
139
|
+
// Invalidate all queries for a collection
|
|
140
|
+
queryClient.invalidateQueries({ queryKey: ["posts"] })
|
|
141
|
+
|
|
142
|
+
// Invalidate only list queries
|
|
143
|
+
queryClient.invalidateQueries({ queryKey: ["posts", "getList"] })
|
|
144
|
+
|
|
145
|
+
// Invalidate a specific record
|
|
146
|
+
queryClient.invalidateQueries({ queryKey: ["posts", "getOne", "post-id"] })
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The adapter also exposes two helpers:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
client.posts.invalidateAll(queryClient) // invalidates all posts queries
|
|
153
|
+
client.posts.invalidateOne(queryClient, postId) // invalidates the getOne query for postId
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## More
|
|
157
|
+
|
|
158
|
+
See the [Mira root README](https://github.com/gettersethya/mira) for collection definitions, field types, rules, and client usage.
|
package/dist/_core.d.ts
CHANGED
|
@@ -1,47 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdaptedCollectionClient, AdaptedMutationOptions, AdaptedQueryOptions, CollectionClient, CollectionKind, FieldsMap } from "@gettersethya/mira-client";
|
|
2
2
|
/**
|
|
3
3
|
* A readonly array of unknown values used as a TanStack Query query key.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```ts
|
|
7
|
-
* const key: QueryKey = ["
|
|
7
|
+
* const key: QueryKey = ["todos", "getList", { limit: 10 }]
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
10
|
export type QueryKey = ReadonlyArray<unknown>;
|
|
11
11
|
/**
|
|
12
|
-
* Shape expected by TanStack Query's `
|
|
12
|
+
* Shape expected by TanStack Query's `useQuery` for a query returning `T`.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* The adapter produces plain objects of this shape (it does not import the
|
|
15
|
+
* framework): `useQuery` / `createQuery` accept them directly and infer `data`.
|
|
15
16
|
*/
|
|
16
|
-
export type QueryOptionsShape<T> =
|
|
17
|
-
queryKey: QueryKey;
|
|
18
|
-
queryFn: () => Promise<T>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Shape expected by TanStack Query's `mutationOptions` for a mutation consuming `TInput` and returning `TData`.
|
|
22
|
-
*
|
|
23
|
-
* @template TData - The data type returned by the mutation function.
|
|
24
|
-
* @template TInput - The input data type consumed by the mutation function.
|
|
25
|
-
*/
|
|
26
|
-
export type MutationOptionsShape<TData, TInput> = {
|
|
27
|
-
mutationFn: (input: TInput) => Promise<TData>;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Signature for the framework-provided `queryOptions` factory.
|
|
31
|
-
* TanStack Query in each framework exports a `queryOptions` function that accepts
|
|
32
|
-
* a {@link QueryOptionsShape} and returns a framework-specific options object.
|
|
33
|
-
* The return type is intentionally `unknown`: each framework returns its own
|
|
34
|
-
* options shape, which callers narrow via `ReturnType` in {@link enrichQuery}.
|
|
35
|
-
*/
|
|
36
|
-
export type MakeQueryOptions = <T>(opts: QueryOptionsShape<T>) => unknown;
|
|
17
|
+
export type QueryOptionsShape<T> = AdaptedQueryOptions<T>;
|
|
37
18
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* a {@link MutationOptionsShape} and returns a framework-specific options object.
|
|
41
|
-
* The return type is intentionally `unknown`: each framework returns its own
|
|
42
|
-
* options shape, which callers narrow via `ReturnType` in {@link enrichMutation}.
|
|
19
|
+
* Shape expected by TanStack Query's `useMutation` for a mutation consuming
|
|
20
|
+
* `TInput` and returning `TData`.
|
|
43
21
|
*/
|
|
44
|
-
export type
|
|
22
|
+
export type MutationOptionsShape<TData, TInput> = AdaptedMutationOptions<TData, TInput>;
|
|
45
23
|
/**
|
|
46
24
|
* A map of human-readable action names to their string key values.
|
|
47
25
|
* Used internally to build structured query keys that include the action being performed.
|
|
@@ -65,209 +43,85 @@ export type ActionKey = (typeof ActionKeys)[keyof typeof ActionKeys];
|
|
|
65
43
|
/**
|
|
66
44
|
* Extends a query handler with a `queryKey` and pre-built `queryOptions` object.
|
|
67
45
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* original methods (e.g. `raw()`, `toEffect()`) with `queryKey` and `queryOptions`
|
|
71
|
-
* added as extra properties via `Object.assign`.
|
|
46
|
+
* The returned handler retains all original methods (e.g. `raw()`, `toEffect()`)
|
|
47
|
+
* with `queryKey` and `queryOptions` added as extra properties via `Object.assign`.
|
|
72
48
|
*
|
|
73
49
|
* @template T - The data type returned by the underlying handler.
|
|
74
50
|
* @template H - The handler type, constrained to objects with a zero-arg `raw()` method returning `Promise<T>`.
|
|
75
|
-
* @template F - The framework `queryOptions` factory. Its return type is preserved
|
|
76
|
-
* via `ReturnType`, so framework-specific option fields survive.
|
|
77
51
|
* @param handler - The original handler (e.g. from `client.getList()`).
|
|
78
52
|
* @param key - The query key array to associate with this query.
|
|
79
|
-
* @param makeQueryOptions - Framework-specific `queryOptions` factory.
|
|
80
53
|
* @returns The original handler augmented with `queryKey` and `queryOptions`.
|
|
81
54
|
* @see enrichMutation For the mutation equivalent.
|
|
82
55
|
*/
|
|
83
|
-
export declare function enrichQuery<
|
|
84
|
-
raw(): Promise<
|
|
85
|
-
}
|
|
56
|
+
export declare function enrichQuery<H extends {
|
|
57
|
+
raw(): Promise<unknown>;
|
|
58
|
+
}>(handler: H, key: QueryKey): H & {
|
|
86
59
|
queryKey: QueryKey;
|
|
87
|
-
queryOptions:
|
|
60
|
+
queryOptions: {
|
|
61
|
+
queryKey: QueryKey;
|
|
62
|
+
queryFn: H["raw"];
|
|
63
|
+
};
|
|
88
64
|
};
|
|
89
65
|
/**
|
|
90
66
|
* Extends a mutation handler with a pre-built `mutationOptions` object.
|
|
91
67
|
*
|
|
92
|
-
* Uses the provided {@link MakeMutationOptions} factory to convert the handler into
|
|
93
|
-
* a TanStack Query-compatible mutation options object. The returned handler retains all
|
|
94
|
-
* original methods with `mutationOptions` added as an extra property via `Object.assign`.
|
|
95
|
-
*
|
|
96
68
|
* @template TData - The data type returned by the mutation handler.
|
|
97
69
|
* @template TInput - The input data type consumed by the mutation handler.
|
|
98
|
-
* @template H - The handler type, constrained to objects with a single-arg `raw(input)` method
|
|
99
|
-
* @template F - The framework `mutationOptions` factory. Its return type is preserved
|
|
100
|
-
* via `ReturnType`, so framework-specific option fields survive.
|
|
70
|
+
* @template H - The handler type, constrained to objects with a single-arg `raw(input)` method.
|
|
101
71
|
* @param handler - The original handler (e.g. from `client.create()`).
|
|
102
|
-
* @param makeMutationOptions - Framework-specific `mutationOptions` factory.
|
|
103
72
|
* @returns The original handler augmented with `mutationOptions`.
|
|
104
73
|
* @see enrichQuery For the query equivalent.
|
|
105
74
|
*/
|
|
106
|
-
export declare function enrichMutation<
|
|
107
|
-
raw(input:
|
|
108
|
-
}
|
|
109
|
-
mutationOptions:
|
|
75
|
+
export declare function enrichMutation<H extends {
|
|
76
|
+
raw(input: never): Promise<unknown>;
|
|
77
|
+
}>(handler: H): H & {
|
|
78
|
+
mutationOptions: {
|
|
79
|
+
mutationFn: H["raw"];
|
|
80
|
+
};
|
|
110
81
|
};
|
|
111
82
|
/**
|
|
112
|
-
* Creates a
|
|
83
|
+
* Creates a framework-agnostic collection adapter.
|
|
113
84
|
*
|
|
114
|
-
*
|
|
115
|
-
* (getList, getOne, getFirstOrNone, getFullList) with `queryKey` and
|
|
116
|
-
* and every mutation method (create, update, delete)
|
|
85
|
+
* The adapter wraps a `CollectionClient` and enriches every query method
|
|
86
|
+
* (getList, getOne, getFirstOrNone, getFullList) with `queryKey` and
|
|
87
|
+
* `queryOptions`, and every mutation method (create, update, delete, register)
|
|
88
|
+
* with `mutationOptions`. The produced option objects are plain
|
|
89
|
+
* `{ queryKey, queryFn }` / `{ mutationFn }` shapes, accepted by TanStack Query
|
|
90
|
+
* in every framework — so the package has no runtime dependency on TanStack.
|
|
117
91
|
*
|
|
118
|
-
* Query keys follow a structured pattern: `[collectionName, actionKey, ...params]
|
|
119
|
-
*
|
|
120
|
-
* `getOne` queries for a specific record by referencing key `["posts", "getOne", id]`.
|
|
92
|
+
* Query keys follow a structured pattern: `[collectionName, actionKey, ...params]`,
|
|
93
|
+
* enabling fine-grained cache invalidation (e.g. `[name, "getOne", id]`).
|
|
121
94
|
*
|
|
122
95
|
* The returned object also exposes `invalidateAll(queryClient)` and
|
|
123
|
-
* `invalidateOne(queryClient, id)`
|
|
124
|
-
* `queryClient.invalidateQueries` with the appropriate key prefix.
|
|
96
|
+
* `invalidateOne(queryClient, id)` helpers.
|
|
125
97
|
*
|
|
126
|
-
* @
|
|
127
|
-
*
|
|
128
|
-
* @param makeMutationOptions - Framework-specific `mutationOptions` factory.
|
|
129
|
-
* @returns An adapter function that takes a `CollectionClient` and collection name,
|
|
130
|
-
* and returns an enhanced client with query/mutation metadata.
|
|
98
|
+
* @returns An adapter function that takes a `CollectionClient` and collection
|
|
99
|
+
* name, and returns an enhanced client with query/mutation metadata.
|
|
131
100
|
*
|
|
132
101
|
* @example
|
|
133
102
|
* ```ts
|
|
134
|
-
* import {
|
|
103
|
+
* import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter"
|
|
135
104
|
* import { createMiraClient } from "@gettersethya/mira-client"
|
|
136
|
-
* import { createCollectionAdapter } from "@gettersethya/mira-tanstack-adapter"
|
|
137
105
|
*
|
|
138
|
-
* const
|
|
139
|
-
*
|
|
140
|
-
*
|
|
106
|
+
* const client = createMiraClient("/api").withCollections(
|
|
107
|
+
* { posts: PostCollection },
|
|
108
|
+
* { adapter: collectionAdapter },
|
|
109
|
+
* )
|
|
141
110
|
*
|
|
142
|
-
*
|
|
143
|
-
* const
|
|
144
|
-
* const mutation = useMutation(adapted.create().mutationOptions)
|
|
145
|
-
*
|
|
146
|
-
* // Invalidate after mutation:
|
|
147
|
-
* adapted.invalidateAll(queryClient)
|
|
148
|
-
* adapted.invalidateOne(queryClient, recordId)
|
|
111
|
+
* const { data } = useQuery(client.posts.getList({ limit: 10 }).queryOptions)
|
|
112
|
+
* const mutation = useMutation(client.posts.create().mutationOptions)
|
|
149
113
|
* ```
|
|
150
114
|
*
|
|
151
115
|
* @see enrichQuery
|
|
152
116
|
* @see enrichMutation
|
|
153
|
-
* @see MakeQueryOptions
|
|
154
|
-
* @see MakeMutationOptions
|
|
155
117
|
*/
|
|
156
|
-
export declare function createCollectionAdapter<
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
queryKey: QueryKey;
|
|
166
|
-
}): unknown;
|
|
167
|
-
}) => unknown;
|
|
168
|
-
/**
|
|
169
|
-
* Invalidates only the `getOne` cache entry for a specific record.
|
|
170
|
-
* Calls `queryClient.invalidateQueries` with key `[name, "getOne", id]`.
|
|
171
|
-
*
|
|
172
|
-
* @param queryClient - Any TanStack Query client with `invalidateQueries`.
|
|
173
|
-
* @param id - The record ID whose cached `getOne` entry should be invalidated.
|
|
174
|
-
*/
|
|
175
|
-
invalidateOne: (queryClient: {
|
|
176
|
-
invalidateQueries(opts: {
|
|
177
|
-
queryKey: QueryKey;
|
|
178
|
-
}): unknown;
|
|
179
|
-
}, id: string) => unknown;
|
|
180
|
-
register?: (() => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, import("@gettersethya/mira-collection").RegisterInput<F>>) | undefined;
|
|
181
|
-
/**
|
|
182
|
-
* Enriched version of `getList` that also returns `queryKey` and `queryOptions`.
|
|
183
|
-
* Query key: `[name, "getList", options]`.
|
|
184
|
-
*/
|
|
185
|
-
getList: (options?: Parameters<CollectionClient<F>["getList"]>[0]) => {
|
|
186
|
-
raw(): Promise<{
|
|
187
|
-
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
188
|
-
nextCursor: number | null;
|
|
189
|
-
}>;
|
|
190
|
-
toEffect(): import("effect/Effect").Effect<{
|
|
191
|
-
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
192
|
-
nextCursor: number | null;
|
|
193
|
-
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
194
|
-
} & {
|
|
195
|
-
queryKey: QueryKey;
|
|
196
|
-
queryOptions: ReturnType<FQ>;
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Enriched version of `getOne` that also returns `queryKey` and `queryOptions`.
|
|
200
|
-
* Query key: `[name, "getOne", id, options]`.
|
|
201
|
-
*/
|
|
202
|
-
getOne: (id: string, options?: Parameters<CollectionClient<F>["getOne"]>[1]) => {
|
|
203
|
-
raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>;
|
|
204
|
-
toEffect(): import("effect/Effect").Effect<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
205
|
-
} & {
|
|
206
|
-
queryKey: QueryKey;
|
|
207
|
-
queryOptions: ReturnType<FQ>;
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Enriched version of `getFirstOrNone` that also returns `queryKey` and `queryOptions`.
|
|
211
|
-
* Query key: `[name, "getFirstOrNone", options]`.
|
|
212
|
-
*/
|
|
213
|
-
getFirstOrNone: (filter: (f: FilterBuilder<F>) => FilterNode, options?: Parameters<CollectionClient<F>["getFirstOrNone"]>[1]) => {
|
|
214
|
-
raw(): Promise<import("effect/Option").Option<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>>;
|
|
215
|
-
toEffect(): import("effect/Effect").Effect<import("effect/Option").Option<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
216
|
-
} & {
|
|
217
|
-
queryKey: QueryKey;
|
|
218
|
-
queryOptions: ReturnType<FQ>;
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* Enriched version of `getFullList` that also returns `queryKey` and `queryOptions`.
|
|
222
|
-
* Query key: `[name, "getFullList", options]`.
|
|
223
|
-
*/
|
|
224
|
-
getFullList: (options?: Parameters<CollectionClient<F>["getFullList"]>[0]) => {
|
|
225
|
-
raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[]>;
|
|
226
|
-
toEffect(): import("effect/Effect").Effect<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[], import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
227
|
-
} & {
|
|
228
|
-
queryKey: QueryKey;
|
|
229
|
-
queryOptions: ReturnType<FQ>;
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Enriched mutation for creating records. Call `raw(input)` to execute.
|
|
233
|
-
*/
|
|
234
|
-
create: () => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, Omit<import("@gettersethya/mira-collection").InferMutationInput<F>, "emailVerified">> & {
|
|
235
|
-
mutationOptions: ReturnType<FM>;
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* Enriched mutation for updating records. Call `raw(input)` to execute.
|
|
239
|
-
*/
|
|
240
|
-
update: () => {
|
|
241
|
-
raw(input: import("@gettersethya/mira-collection").UpdateInput<F, "base">): Promise<import("@gettersethya/mira-collection").InferRecord<F>>;
|
|
242
|
-
toEffect(input: import("@gettersethya/mira-collection").UpdateInput<F, "base">): import("effect/Effect").Effect<import("@gettersethya/mira-collection").InferRecord<F>, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
243
|
-
} & {
|
|
244
|
-
mutationOptions: ReturnType<FM>;
|
|
245
|
-
};
|
|
246
|
-
/**
|
|
247
|
-
* Enriched mutation for deleting records. Call `raw(input)` to execute.
|
|
248
|
-
*/
|
|
249
|
-
delete: () => {
|
|
250
|
-
raw(input: string): Promise<void>;
|
|
251
|
-
toEffect(input: string): import("effect/Effect").Effect<void, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
252
|
-
} & {
|
|
253
|
-
mutationOptions: ReturnType<FM>;
|
|
254
|
-
};
|
|
255
|
-
authWithPassword?(): {
|
|
256
|
-
raw(input: {
|
|
257
|
-
email: string;
|
|
258
|
-
password: string;
|
|
259
|
-
}): Promise<{
|
|
260
|
-
token: string;
|
|
261
|
-
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
262
|
-
}>;
|
|
263
|
-
toEffect(input: {
|
|
264
|
-
email: string;
|
|
265
|
-
password: string;
|
|
266
|
-
}): import("effect/Effect").Effect<{
|
|
267
|
-
token: string;
|
|
268
|
-
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
269
|
-
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
270
|
-
};
|
|
271
|
-
fields: import("@gettersethya/mira-client").CollectionFileFields<F>;
|
|
272
|
-
};
|
|
118
|
+
export declare function createCollectionAdapter(): <F extends FieldsMap, K extends CollectionKind = "base">(client: CollectionClient<F, K>, name: string, kind: K) => AdaptedCollectionClient<F, K>;
|
|
119
|
+
/**
|
|
120
|
+
* A pre-built {@link createCollectionAdapter | collection adapter}.
|
|
121
|
+
*
|
|
122
|
+
* Framework-agnostic — the option objects it produces satisfy TanStack Query's
|
|
123
|
+
* `useQuery` / `useMutation` (React, Solid) and `createQuery` / `createMutation`
|
|
124
|
+
* (Svelte) inputs.
|
|
125
|
+
*/
|
|
126
|
+
export declare const collectionAdapter: <F extends FieldsMap, K extends CollectionKind = "base">(client: CollectionClient<F, K>, name: string, kind: K) => AdaptedCollectionClient<F, K>;
|
|
273
127
|
//# sourceMappingURL=_core.d.ts.map
|