@gettersethya/mira-tanstack-adapter 0.1.0-alpha.2 → 0.1.0-alpha.20
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 +160 -0
- package/dist/{src/_core.d.ts → _core.d.ts} +62 -59
- package/dist/_core.d.ts.map +1 -0
- package/dist/{src/_core.js → _core.js} +6 -31
- package/dist/_core.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +173 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +34 -0
- package/dist/react.js.map +1 -0
- package/dist/solid.d.ts +180 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +41 -0
- package/dist/solid.js.map +1 -0
- package/dist/svelte.d.ts +161 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +50 -0
- package/dist/svelte.js.map +1 -0
- package/package.json +15 -6
- package/dist/src/_core.d.ts.map +0 -1
- package/dist/src/_core.js.map +0 -1
- package/dist/tests/tanstack-core.test.d.ts +0 -2
- package/dist/tests/tanstack-core.test.d.ts.map +0 -1
- package/dist/tests/tanstack-core.test.js +0 -123
- package/dist/tests/tanstack-core.test.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
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 adapters for [@gettersethya/mira-client](https://www.npmjs.com/package/@gettersethya/mira-client). Wraps collection client methods with `queryOptions` and `mutationOptions`, with structured query keys for fine-grained cache invalidation.
|
|
8
|
+
|
|
9
|
+
Supports React, Svelte, and Solid via separate entry points.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# React
|
|
15
|
+
npm install @gettersethya/mira-tanstack-adapter @tanstack/react-query
|
|
16
|
+
|
|
17
|
+
# Svelte
|
|
18
|
+
npm install @gettersethya/mira-tanstack-adapter @tanstack/svelte-query
|
|
19
|
+
|
|
20
|
+
# Solid
|
|
21
|
+
npm install @gettersethya/mira-tanstack-adapter @tanstack/solid-query
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`@gettersethya/mira-client` is a required peer dependency. Only install the TanStack package for the framework you use.
|
|
25
|
+
|
|
26
|
+
## Setup
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createMiraClient } from "@gettersethya/mira-client"
|
|
30
|
+
import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/react"
|
|
31
|
+
// import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/solid"
|
|
32
|
+
import { Posts } from "./collections.js"
|
|
33
|
+
|
|
34
|
+
const mira = createMiraClient("/api").withCollections({ posts: Posts })
|
|
35
|
+
const postsApi = collectionAdapter(mira, "posts")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Svelte uses a small factory instead of a pre-built adapter (its v6 option
|
|
39
|
+
types cannot be re-exported from another package's declarations):
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { mutationOptions, queryOptions } from "@tanstack/svelte-query"
|
|
43
|
+
import { createSvelteCollectionAdapter } from "@gettersethya/mira-tanstack-adapter/svelte"
|
|
44
|
+
|
|
45
|
+
const collectionAdapter = createSvelteCollectionAdapter(queryOptions, mutationOptions)
|
|
46
|
+
const postsApi = collectionAdapter(mira, "posts")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The framework-agnostic factory also lives at the package root for custom setups:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { queryOptions, mutationOptions } from "@tanstack/react-query"
|
|
53
|
+
import { createCollectionAdapter } from "@gettersethya/mira-tanstack-adapter"
|
|
54
|
+
|
|
55
|
+
const collectionAdapter = createCollectionAdapter(queryOptions, mutationOptions)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Queries
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { useQuery } from "@tanstack/react-query"
|
|
62
|
+
import { postsApi } from "./setup.js"
|
|
63
|
+
|
|
64
|
+
function PostList() {
|
|
65
|
+
const { data, isLoading } = useQuery(
|
|
66
|
+
postsApi.getList({
|
|
67
|
+
filter: (f) => f.field("published").eq(true),
|
|
68
|
+
limit: 10,
|
|
69
|
+
}).queryOptions
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if (isLoading) return <p>Loading...</p>
|
|
73
|
+
return <ul>{data?.items.map(p => <li key={p.id}>{p.title}</li>)}</ul>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function PostDetail({ id }: { id: string }) {
|
|
77
|
+
const { data } = useQuery(postsApi.getOne(id).queryOptions)
|
|
78
|
+
return <h1>{data?.title}</h1>
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Mutations
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
86
|
+
import { postsApi } from "./setup.js"
|
|
87
|
+
|
|
88
|
+
function PostActions() {
|
|
89
|
+
const queryClient = useQueryClient()
|
|
90
|
+
|
|
91
|
+
const create = useMutation({
|
|
92
|
+
...postsApi.create().mutationOptions,
|
|
93
|
+
onSuccess: () => postsApi.invalidateAll(queryClient),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const update = useMutation({
|
|
97
|
+
...postsApi.update().mutationOptions,
|
|
98
|
+
onSuccess: (post) => postsApi.invalidateOne(queryClient, post.id),
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const remove = useMutation({
|
|
102
|
+
...postsApi.delete().mutationOptions,
|
|
103
|
+
onSuccess: () => postsApi.invalidateAll(queryClient),
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<button onClick={() => create.mutate({ title: "New Post", published: false })}>
|
|
108
|
+
Create
|
|
109
|
+
</button>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Svelte and Solid
|
|
115
|
+
|
|
116
|
+
React and Solid expose a pre-built `collectionAdapter`. Svelte exposes a
|
|
117
|
+
`createSvelteCollectionAdapter(queryOptions, mutationOptions)` factory instead
|
|
118
|
+
(see Setup above). Svelte v6 reads options through reactive getters:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// Svelte
|
|
122
|
+
import { createSvelteCollectionAdapter } from "@gettersethya/mira-tanstack-adapter/svelte"
|
|
123
|
+
// use with createQuery / createMutation from @tanstack/svelte-query
|
|
124
|
+
const query = createQuery(() => api.getList({ limit: 10 }).queryOptions)
|
|
125
|
+
|
|
126
|
+
// Solid
|
|
127
|
+
import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/solid"
|
|
128
|
+
// use with createQuery / createMutation from @tanstack/solid-query
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Query key structure
|
|
132
|
+
|
|
133
|
+
The adapter produces structured query keys for fine-grained cache invalidation:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// ["posts", "getList", { limit, filter, sort, order, cursor, select, expand }]
|
|
137
|
+
// ["posts", "getOne", "post-id"]
|
|
138
|
+
// ["posts", "getFirstOrNone", { filter, sort, order, select, expand }]
|
|
139
|
+
// ["posts", "getFullList", { limit, filter, sort, order, select, expand }]
|
|
140
|
+
|
|
141
|
+
// Invalidate all queries for a collection
|
|
142
|
+
queryClient.invalidateQueries({ queryKey: ["posts"] })
|
|
143
|
+
|
|
144
|
+
// Invalidate only list queries
|
|
145
|
+
queryClient.invalidateQueries({ queryKey: ["posts", "getList"] })
|
|
146
|
+
|
|
147
|
+
// Invalidate a specific record
|
|
148
|
+
queryClient.invalidateQueries({ queryKey: ["posts", "getOne", "post-id"] })
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The adapter also exposes two helpers:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
postsApi.invalidateAll(queryClient) // invalidates all posts queries
|
|
155
|
+
postsApi.invalidateOne(queryClient, postId) // invalidates the getOne query for postId
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## More
|
|
159
|
+
|
|
160
|
+
See the [Mira root README](https://github.com/gettersethya/mira) for collection definitions, field types, rules, and client usage.
|
|
@@ -30,14 +30,18 @@ export type MutationOptionsShape<TData, TInput> = {
|
|
|
30
30
|
* Signature for the framework-provided `queryOptions` factory.
|
|
31
31
|
* TanStack Query in each framework exports a `queryOptions` function that accepts
|
|
32
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}.
|
|
33
35
|
*/
|
|
34
|
-
export type MakeQueryOptions = <T>(opts: QueryOptionsShape<T>) =>
|
|
36
|
+
export type MakeQueryOptions = <T>(opts: QueryOptionsShape<T>) => unknown;
|
|
35
37
|
/**
|
|
36
38
|
* Signature for the framework-provided `mutationOptions` factory.
|
|
37
39
|
* TanStack Query in each framework exports a `mutationOptions` function that accepts
|
|
38
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}.
|
|
39
43
|
*/
|
|
40
|
-
export type MakeMutationOptions = <TData, TInput>(opts: MutationOptionsShape<TData, TInput>) =>
|
|
44
|
+
export type MakeMutationOptions = <TData, TInput>(opts: MutationOptionsShape<TData, TInput>) => unknown;
|
|
41
45
|
/**
|
|
42
46
|
* A map of human-readable action names to their string key values.
|
|
43
47
|
* Used internally to build structured query keys that include the action being performed.
|
|
@@ -68,6 +72,8 @@ export type ActionKey = (typeof ActionKeys)[keyof typeof ActionKeys];
|
|
|
68
72
|
*
|
|
69
73
|
* @template T - The data type returned by the underlying handler.
|
|
70
74
|
* @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.
|
|
71
77
|
* @param handler - The original handler (e.g. from `client.getList()`).
|
|
72
78
|
* @param key - The query key array to associate with this query.
|
|
73
79
|
* @param makeQueryOptions - Framework-specific `queryOptions` factory.
|
|
@@ -76,9 +82,9 @@ export type ActionKey = (typeof ActionKeys)[keyof typeof ActionKeys];
|
|
|
76
82
|
*/
|
|
77
83
|
export declare function enrichQuery<T, H extends {
|
|
78
84
|
raw(): Promise<T>;
|
|
79
|
-
}>(handler: H, key: QueryKey, makeQueryOptions:
|
|
85
|
+
}, F extends (opts: QueryOptionsShape<T>) => unknown>(handler: H, key: QueryKey, makeQueryOptions: F): H & {
|
|
80
86
|
queryKey: QueryKey;
|
|
81
|
-
queryOptions:
|
|
87
|
+
queryOptions: ReturnType<F>;
|
|
82
88
|
};
|
|
83
89
|
/**
|
|
84
90
|
* Extends a mutation handler with a pre-built `mutationOptions` object.
|
|
@@ -90,6 +96,8 @@ export declare function enrichQuery<T, H extends {
|
|
|
90
96
|
* @template TData - The data type returned by the mutation handler.
|
|
91
97
|
* @template TInput - The input data type consumed by the mutation handler.
|
|
92
98
|
* @template H - The handler type, constrained to objects with a single-arg `raw(input)` method returning `Promise<TData>`.
|
|
99
|
+
* @template F - The framework `mutationOptions` factory. Its return type is preserved
|
|
100
|
+
* via `ReturnType`, so framework-specific option fields survive.
|
|
93
101
|
* @param handler - The original handler (e.g. from `client.create()`).
|
|
94
102
|
* @param makeMutationOptions - Framework-specific `mutationOptions` factory.
|
|
95
103
|
* @returns The original handler augmented with `mutationOptions`.
|
|
@@ -97,8 +105,8 @@ export declare function enrichQuery<T, H extends {
|
|
|
97
105
|
*/
|
|
98
106
|
export declare function enrichMutation<TData, TInput, H extends {
|
|
99
107
|
raw(input: TInput): Promise<TData>;
|
|
100
|
-
}>(handler: H, makeMutationOptions:
|
|
101
|
-
mutationOptions:
|
|
108
|
+
}, F extends (opts: MutationOptionsShape<TData, TInput>) => unknown>(handler: H, makeMutationOptions: F): H & {
|
|
109
|
+
mutationOptions: ReturnType<F>;
|
|
102
110
|
};
|
|
103
111
|
/**
|
|
104
112
|
* Creates a TanStack Query adapter for any {@link CollectionClient}.
|
|
@@ -145,125 +153,120 @@ export declare function enrichMutation<TData, TInput, H extends {
|
|
|
145
153
|
* @see MakeQueryOptions
|
|
146
154
|
* @see MakeMutationOptions
|
|
147
155
|
*/
|
|
148
|
-
export declare function createCollectionAdapter(makeQueryOptions:
|
|
156
|
+
export declare function createCollectionAdapter<FQ extends MakeQueryOptions, FM extends MakeMutationOptions>(makeQueryOptions: FQ, makeMutationOptions: FM): <F extends FieldsMap>(client: CollectionClient<F>, name: string) => {
|
|
157
|
+
/**
|
|
158
|
+
* Invalidates all cached queries for this collection.
|
|
159
|
+
* Calls `queryClient.invalidateQueries` with key prefix `[name]`.
|
|
160
|
+
*
|
|
161
|
+
* @param queryClient - Any TanStack Query client with `invalidateQueries`.
|
|
162
|
+
*/
|
|
163
|
+
invalidateAll: (queryClient: {
|
|
164
|
+
invalidateQueries(opts: {
|
|
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;
|
|
149
181
|
/**
|
|
150
182
|
* Enriched version of `getList` that also returns `queryKey` and `queryOptions`.
|
|
151
183
|
* Query key: `[name, "getList", options]`.
|
|
152
184
|
*/
|
|
153
185
|
getList: (options?: Parameters<CollectionClient<F>["getList"]>[0]) => {
|
|
154
186
|
raw(): Promise<{
|
|
155
|
-
items: import("@gettersethya/mira-
|
|
187
|
+
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
156
188
|
nextCursor: number | null;
|
|
157
189
|
}>;
|
|
158
190
|
toEffect(): import("effect/Effect").Effect<{
|
|
159
|
-
items: import("@gettersethya/mira-
|
|
191
|
+
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
160
192
|
nextCursor: number | null;
|
|
161
|
-
}, import("@gettersethya/mira-client").MiraError, import("
|
|
193
|
+
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
162
194
|
} & {
|
|
163
195
|
queryKey: QueryKey;
|
|
164
|
-
queryOptions:
|
|
196
|
+
queryOptions: ReturnType<FQ>;
|
|
165
197
|
};
|
|
166
198
|
/**
|
|
167
199
|
* Enriched version of `getOne` that also returns `queryKey` and `queryOptions`.
|
|
168
200
|
* Query key: `[name, "getOne", id, options]`.
|
|
169
201
|
*/
|
|
170
202
|
getOne: (id: string, options?: Parameters<CollectionClient<F>["getOne"]>[1]) => {
|
|
171
|
-
raw(): Promise<import("@gettersethya/mira-
|
|
172
|
-
toEffect(): import("effect/Effect").Effect<import("@gettersethya/mira-
|
|
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>;
|
|
173
205
|
} & {
|
|
174
206
|
queryKey: QueryKey;
|
|
175
|
-
queryOptions:
|
|
207
|
+
queryOptions: ReturnType<FQ>;
|
|
176
208
|
};
|
|
177
209
|
/**
|
|
178
210
|
* Enriched version of `getFirstOrNone` that also returns `queryKey` and `queryOptions`.
|
|
179
211
|
* Query key: `[name, "getFirstOrNone", options]`.
|
|
180
212
|
*/
|
|
181
213
|
getFirstOrNone: (filter: (f: FilterBuilder<F>) => FilterNode, options?: Parameters<CollectionClient<F>["getFirstOrNone"]>[1]) => {
|
|
182
|
-
raw(): Promise<import("effect/Option").Option<import("@gettersethya/mira-
|
|
183
|
-
toEffect(): import("effect/Effect").Effect<import("effect/Option").Option<import("@gettersethya/mira-
|
|
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>;
|
|
184
216
|
} & {
|
|
185
217
|
queryKey: QueryKey;
|
|
186
|
-
queryOptions:
|
|
218
|
+
queryOptions: ReturnType<FQ>;
|
|
187
219
|
};
|
|
188
220
|
/**
|
|
189
221
|
* Enriched version of `getFullList` that also returns `queryKey` and `queryOptions`.
|
|
190
222
|
* Query key: `[name, "getFullList", options]`.
|
|
191
223
|
*/
|
|
192
224
|
getFullList: (options?: Parameters<CollectionClient<F>["getFullList"]>[0]) => {
|
|
193
|
-
raw(): Promise<import("@gettersethya/mira-
|
|
194
|
-
toEffect(): import("effect/Effect").Effect<import("@gettersethya/mira-
|
|
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>;
|
|
195
227
|
} & {
|
|
196
228
|
queryKey: QueryKey;
|
|
197
|
-
queryOptions:
|
|
229
|
+
queryOptions: ReturnType<FQ>;
|
|
198
230
|
};
|
|
199
231
|
/**
|
|
200
232
|
* Enriched mutation for creating records. Call `raw(input)` to execute.
|
|
201
233
|
*/
|
|
202
|
-
create: () => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-
|
|
203
|
-
mutationOptions:
|
|
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>;
|
|
204
236
|
};
|
|
205
237
|
/**
|
|
206
238
|
* Enriched mutation for updating records. Call `raw(input)` to execute.
|
|
207
239
|
*/
|
|
208
240
|
update: () => {
|
|
209
|
-
raw(input:
|
|
210
|
-
|
|
211
|
-
data: Partial<import("@gettersethya/mira-client").InferMutationInput<F>>;
|
|
212
|
-
}): Promise<import("@gettersethya/mira-client").InferRecord<F>>;
|
|
213
|
-
toEffect(input: {
|
|
214
|
-
id: string;
|
|
215
|
-
data: Partial<import("@gettersethya/mira-client").InferMutationInput<F>>;
|
|
216
|
-
}): import("effect/Effect").Effect<import("@gettersethya/mira-client").InferRecord<F>, import("@gettersethya/mira-client").MiraError, import("@effect/platform/HttpClient").HttpClient>;
|
|
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>;
|
|
217
243
|
} & {
|
|
218
|
-
mutationOptions:
|
|
244
|
+
mutationOptions: ReturnType<FM>;
|
|
219
245
|
};
|
|
220
246
|
/**
|
|
221
247
|
* Enriched mutation for deleting records. Call `raw(input)` to execute.
|
|
222
248
|
*/
|
|
223
249
|
delete: () => {
|
|
224
250
|
raw(input: string): Promise<void>;
|
|
225
|
-
toEffect(input: string): import("effect/Effect").Effect<void, import("@gettersethya/mira-client").MiraError, import("
|
|
251
|
+
toEffect(input: string): import("effect/Effect").Effect<void, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
226
252
|
} & {
|
|
227
|
-
mutationOptions:
|
|
253
|
+
mutationOptions: ReturnType<FM>;
|
|
228
254
|
};
|
|
229
|
-
/**
|
|
230
|
-
* Invalidates all cached queries for this collection.
|
|
231
|
-
* Calls `queryClient.invalidateQueries` with key prefix `[name]`.
|
|
232
|
-
*
|
|
233
|
-
* @param queryClient - Any TanStack Query client with `invalidateQueries`.
|
|
234
|
-
*/
|
|
235
|
-
invalidateAll: (queryClient: {
|
|
236
|
-
invalidateQueries(opts: {
|
|
237
|
-
queryKey: QueryKey;
|
|
238
|
-
}): unknown;
|
|
239
|
-
}) => unknown;
|
|
240
|
-
/**
|
|
241
|
-
* Invalidates only the `getOne` cache entry for a specific record.
|
|
242
|
-
* Calls `queryClient.invalidateQueries` with key `[name, "getOne", id]`.
|
|
243
|
-
*
|
|
244
|
-
* @param queryClient - Any TanStack Query client with `invalidateQueries`.
|
|
245
|
-
* @param id - The record ID whose cached `getOne` entry should be invalidated.
|
|
246
|
-
*/
|
|
247
|
-
invalidateOne: (queryClient: {
|
|
248
|
-
invalidateQueries(opts: {
|
|
249
|
-
queryKey: QueryKey;
|
|
250
|
-
}): unknown;
|
|
251
|
-
}, id: string) => unknown;
|
|
252
255
|
authWithPassword?(): {
|
|
253
256
|
raw(input: {
|
|
254
257
|
email: string;
|
|
255
258
|
password: string;
|
|
256
259
|
}): Promise<{
|
|
257
260
|
token: string;
|
|
258
|
-
record: import("@gettersethya/mira-
|
|
261
|
+
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
259
262
|
}>;
|
|
260
263
|
toEffect(input: {
|
|
261
264
|
email: string;
|
|
262
265
|
password: string;
|
|
263
266
|
}): import("effect/Effect").Effect<{
|
|
264
267
|
token: string;
|
|
265
|
-
record: import("@gettersethya/mira-
|
|
266
|
-
}, import("@gettersethya/mira-client").MiraError, import("
|
|
268
|
+
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
269
|
+
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
267
270
|
};
|
|
268
271
|
fields: import("@gettersethya/mira-client").CollectionFileFields<F>;
|
|
269
272
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_core.d.ts","sourceRoot":"","sources":["../src/_core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEvG;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAE7C;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;CAC1B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,CAAC,KAAK,EAAE,MAAM,IAAI;IAChD,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC,CAAA;CAC9C,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAg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"getFirstOrNone",
|
|
15
15
|
GetFullList: "getFullList",
|
|
16
16
|
};
|
|
17
|
-
/**
|
|
18
|
-
* Extends a query handler with a `queryKey` and pre-built `queryOptions` object.
|
|
19
|
-
*
|
|
20
|
-
* Uses the provided {@link MakeQueryOptions} factory to convert the handler into
|
|
21
|
-
* a TanStack Query-compatible options object. The returned handler retains all
|
|
22
|
-
* original methods (e.g. `raw()`, `toEffect()`) with `queryKey` and `queryOptions`
|
|
23
|
-
* added as extra properties via `Object.assign`.
|
|
24
|
-
*
|
|
25
|
-
* @template T - The data type returned by the underlying handler.
|
|
26
|
-
* @template H - The handler type, constrained to objects with a zero-arg `raw()` method returning `Promise<T>`.
|
|
27
|
-
* @param handler - The original handler (e.g. from `client.getList()`).
|
|
28
|
-
* @param key - The query key array to associate with this query.
|
|
29
|
-
* @param makeQueryOptions - Framework-specific `queryOptions` factory.
|
|
30
|
-
* @returns The original handler augmented with `queryKey` and `queryOptions`.
|
|
31
|
-
* @see enrichMutation For the mutation equivalent.
|
|
32
|
-
*/
|
|
33
17
|
export function enrichQuery(handler, key, makeQueryOptions) {
|
|
34
18
|
return Object.assign(handler, {
|
|
35
19
|
queryKey: key,
|
|
36
20
|
queryOptions: makeQueryOptions({ queryKey: key, queryFn: () => handler.raw() }),
|
|
37
21
|
});
|
|
38
22
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Extends a mutation handler with a pre-built `mutationOptions` object.
|
|
41
|
-
*
|
|
42
|
-
* Uses the provided {@link MakeMutationOptions} factory to convert the handler into
|
|
43
|
-
* a TanStack Query-compatible mutation options object. The returned handler retains all
|
|
44
|
-
* original methods with `mutationOptions` added as an extra property via `Object.assign`.
|
|
45
|
-
*
|
|
46
|
-
* @template TData - The data type returned by the mutation handler.
|
|
47
|
-
* @template TInput - The input data type consumed by the mutation handler.
|
|
48
|
-
* @template H - The handler type, constrained to objects with a single-arg `raw(input)` method returning `Promise<TData>`.
|
|
49
|
-
* @param handler - The original handler (e.g. from `client.create()`).
|
|
50
|
-
* @param makeMutationOptions - Framework-specific `mutationOptions` factory.
|
|
51
|
-
* @returns The original handler augmented with `mutationOptions`.
|
|
52
|
-
* @see enrichQuery For the query equivalent.
|
|
53
|
-
*/
|
|
54
23
|
export function enrichMutation(handler, makeMutationOptions) {
|
|
55
24
|
return Object.assign(handler, {
|
|
56
25
|
mutationOptions: makeMutationOptions({
|
|
@@ -105,6 +74,7 @@ export function enrichMutation(handler, makeMutationOptions) {
|
|
|
105
74
|
*/
|
|
106
75
|
export function createCollectionAdapter(makeQueryOptions, makeMutationOptions) {
|
|
107
76
|
return function adaptCollectionClient(client, name) {
|
|
77
|
+
const registerFn = client.register;
|
|
108
78
|
return {
|
|
109
79
|
...client,
|
|
110
80
|
/**
|
|
@@ -139,6 +109,11 @@ export function createCollectionAdapter(makeQueryOptions, makeMutationOptions) {
|
|
|
139
109
|
* Enriched mutation for deleting records. Call `raw(input)` to execute.
|
|
140
110
|
*/
|
|
141
111
|
delete: () => enrichMutation(client.delete(), makeMutationOptions),
|
|
112
|
+
/**
|
|
113
|
+
* Enriched mutation for registering a new auth-collection record.
|
|
114
|
+
* Only present when the underlying collection client exposes `register`.
|
|
115
|
+
*/
|
|
116
|
+
...(registerFn ? { register: () => enrichMutation(registerFn(), makeMutationOptions) } : {}),
|
|
142
117
|
/**
|
|
143
118
|
* Invalidates all cached queries for this collection.
|
|
144
119
|
* Calls `queryClient.invalidateQueries` with key prefix `[name]`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_core.js","sourceRoot":"","sources":["../src/_core.ts"],"names":[],"mappings":"AAoDA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAS,SAAS;IACzB,MAAM,EAAU,QAAQ;IACxB,cAAc,EAAE,gBAAgB;IAChC,WAAW,EAAK,aAAa;CACrB,CAAA;AA8BV,MAAM,UAAU,WAAW,CACzB,OAAoC,EACpC,GAAa,EACb,gBAAkC;IAElC,OA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A;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,cAAc,EACd,WAAW,GACZ,MAAM,YAAY,CAAA;AACnB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EACR,iBAAiB,GAClB,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,cAAc,EACd,WAAW,GACZ,MAAM,YAAY,CAAA"}
|