@gettersethya/mira-tanstack-adapter 0.1.0-alpha.17 → 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 +25 -3
- package/dist/{src/_core.d.ts → _core.d.ts} +59 -56
- 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 +11 -4
- 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/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { ActionKeys } from "./_core.js";
|
|
2
|
+
/**
|
|
3
|
+
* A pre-built {@link createCollectionAdapter | collection adapter} for **TanStack Solid Query**.
|
|
4
|
+
*
|
|
5
|
+
* Uses `queryOptions` and `mutationOptions` from `@tanstack/solid-query` to produce
|
|
6
|
+
* options objects compatible with `createQuery` and `createMutation`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { createQuery, createMutation, useQueryClient } from "@tanstack/solid-query"
|
|
11
|
+
* import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/solid"
|
|
12
|
+
* import { createMiraClient } from "@gettersethya/mira-client"
|
|
13
|
+
* import { PostCollection } from "../collections"
|
|
14
|
+
*
|
|
15
|
+
* const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
|
|
16
|
+
* const api = collectionAdapter(client, "posts")
|
|
17
|
+
* const queryClient = useQueryClient()
|
|
18
|
+
*
|
|
19
|
+
* function PostList() {
|
|
20
|
+
* const query = createQuery(() => api.getList({ limit: 10 }).queryOptions)
|
|
21
|
+
*
|
|
22
|
+
* const mutation = createMutation(() => ({
|
|
23
|
+
* ...api.create().mutationOptions,
|
|
24
|
+
* onSuccess: () => api.invalidateAll(queryClient),
|
|
25
|
+
* }))
|
|
26
|
+
*
|
|
27
|
+
* return (
|
|
28
|
+
* <div>
|
|
29
|
+
* <Show when={query.isLoading}><p>Loading...</p></Show>
|
|
30
|
+
* <Show when={query.data}>
|
|
31
|
+
* <ul>{query.data!.items.map(p => <li>{p.title}</li>)}</ul>
|
|
32
|
+
* </Show>
|
|
33
|
+
* </div>
|
|
34
|
+
* )
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const collectionAdapter: <F extends import("@gettersethya/mira-collection").FieldsMap>(client: import("@gettersethya/mira-client").CollectionClient<F>, name: string) => {
|
|
39
|
+
invalidateAll: (queryClient: {
|
|
40
|
+
invalidateQueries(opts: {
|
|
41
|
+
queryKey: import("./_core.js").QueryKey;
|
|
42
|
+
}): unknown;
|
|
43
|
+
}) => unknown;
|
|
44
|
+
invalidateOne: (queryClient: {
|
|
45
|
+
invalidateQueries(opts: {
|
|
46
|
+
queryKey: import("./_core.js").QueryKey;
|
|
47
|
+
}): unknown;
|
|
48
|
+
}, id: string) => unknown;
|
|
49
|
+
register?: (() => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, import("@gettersethya/mira-collection").RegisterInput<F>>) | undefined;
|
|
50
|
+
getList: (options?: {
|
|
51
|
+
filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
|
|
52
|
+
sort?: (keyof F & string) | undefined;
|
|
53
|
+
order?: "asc" | "desc";
|
|
54
|
+
cursor?: number | null;
|
|
55
|
+
limit?: number;
|
|
56
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
57
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
58
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
59
|
+
} | undefined) => {
|
|
60
|
+
raw(): Promise<{
|
|
61
|
+
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
62
|
+
nextCursor: number | null;
|
|
63
|
+
}>;
|
|
64
|
+
toEffect(): import("effect/Effect").Effect<{
|
|
65
|
+
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
66
|
+
nextCursor: number | null;
|
|
67
|
+
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
68
|
+
} & {
|
|
69
|
+
queryKey: import("./_core.js").QueryKey;
|
|
70
|
+
queryOptions: import("@tanstack/solid-query").QueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
|
|
71
|
+
initialData: unknown;
|
|
72
|
+
} & {
|
|
73
|
+
queryKey: readonly unknown[] & {
|
|
74
|
+
[dataTagSymbol]: unknown;
|
|
75
|
+
[dataTagErrorSymbol]: unknown;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
getOne: (id: string, options?: {
|
|
80
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
81
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
82
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
83
|
+
} | undefined) => {
|
|
84
|
+
raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>;
|
|
85
|
+
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>;
|
|
86
|
+
} & {
|
|
87
|
+
queryKey: import("./_core.js").QueryKey;
|
|
88
|
+
queryOptions: import("@tanstack/solid-query").QueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
|
|
89
|
+
initialData: unknown;
|
|
90
|
+
} & {
|
|
91
|
+
queryKey: readonly unknown[] & {
|
|
92
|
+
[dataTagSymbol]: unknown;
|
|
93
|
+
[dataTagErrorSymbol]: unknown;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
getFirstOrNone: (filter: (f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode, options?: Omit<{
|
|
98
|
+
filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
|
|
99
|
+
sort?: (keyof F & string) | undefined;
|
|
100
|
+
order?: "asc" | "desc";
|
|
101
|
+
cursor?: number | null;
|
|
102
|
+
limit?: number;
|
|
103
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
104
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
105
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
106
|
+
}, "filter" | "limit" | "cursor"> | undefined) => {
|
|
107
|
+
raw(): Promise<import("effect/Option").Option<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>>;
|
|
108
|
+
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>;
|
|
109
|
+
} & {
|
|
110
|
+
queryKey: import("./_core.js").QueryKey;
|
|
111
|
+
queryOptions: import("@tanstack/solid-query").QueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
|
|
112
|
+
initialData: unknown;
|
|
113
|
+
} & {
|
|
114
|
+
queryKey: readonly unknown[] & {
|
|
115
|
+
[dataTagSymbol]: unknown;
|
|
116
|
+
[dataTagErrorSymbol]: unknown;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
getFullList: (options?: (Omit<{
|
|
121
|
+
filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
|
|
122
|
+
sort?: (keyof F & string) | undefined;
|
|
123
|
+
order?: "asc" | "desc";
|
|
124
|
+
cursor?: number | null;
|
|
125
|
+
limit?: number;
|
|
126
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
127
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
128
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
129
|
+
}, "limit" | "cursor"> & {
|
|
130
|
+
limit?: number;
|
|
131
|
+
}) | undefined) => {
|
|
132
|
+
raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[]>;
|
|
133
|
+
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>;
|
|
134
|
+
} & {
|
|
135
|
+
queryKey: import("./_core.js").QueryKey;
|
|
136
|
+
queryOptions: import("@tanstack/solid-query").QueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
|
|
137
|
+
initialData: unknown;
|
|
138
|
+
} & {
|
|
139
|
+
queryKey: readonly unknown[] & {
|
|
140
|
+
[dataTagSymbol]: unknown;
|
|
141
|
+
[dataTagErrorSymbol]: unknown;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
create: () => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, Omit<import("@gettersethya/mira-collection").InferMutationInput<F>, "emailVerified">> & {
|
|
146
|
+
mutationOptions: Omit<import("@tanstack/solid-query").MutationOptions<unknown, unknown, unknown, unknown>, "mutationKey">;
|
|
147
|
+
};
|
|
148
|
+
update: () => {
|
|
149
|
+
raw(input: import("@gettersethya/mira-collection").UpdateInput<F, "base">): Promise<import("@gettersethya/mira-collection").InferRecord<F>>;
|
|
150
|
+
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>;
|
|
151
|
+
} & {
|
|
152
|
+
mutationOptions: Omit<import("@tanstack/solid-query").MutationOptions<unknown, unknown, unknown, unknown>, "mutationKey">;
|
|
153
|
+
};
|
|
154
|
+
delete: () => {
|
|
155
|
+
raw(input: string): Promise<void>;
|
|
156
|
+
toEffect(input: string): import("effect/Effect").Effect<void, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
157
|
+
} & {
|
|
158
|
+
mutationOptions: Omit<import("@tanstack/solid-query").MutationOptions<unknown, unknown, unknown, unknown>, "mutationKey">;
|
|
159
|
+
};
|
|
160
|
+
authWithPassword?(): {
|
|
161
|
+
raw(input: {
|
|
162
|
+
email: string;
|
|
163
|
+
password: string;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
token: string;
|
|
166
|
+
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
167
|
+
}>;
|
|
168
|
+
toEffect(input: {
|
|
169
|
+
email: string;
|
|
170
|
+
password: string;
|
|
171
|
+
}): import("effect/Effect").Effect<{
|
|
172
|
+
token: string;
|
|
173
|
+
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
174
|
+
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
175
|
+
};
|
|
176
|
+
fields: import("@gettersethya/mira-client").CollectionFileFields<F>;
|
|
177
|
+
};
|
|
178
|
+
export { ActionKeys };
|
|
179
|
+
export type { ActionKey } from "./_core.js";
|
|
180
|
+
//# sourceMappingURL=solid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAyD,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mutationOptions, queryOptions } from "@tanstack/solid-query";
|
|
2
|
+
import { createCollectionAdapter, ActionKeys } from "./_core.js";
|
|
3
|
+
/**
|
|
4
|
+
* A pre-built {@link createCollectionAdapter | collection adapter} for **TanStack Solid Query**.
|
|
5
|
+
*
|
|
6
|
+
* Uses `queryOptions` and `mutationOptions` from `@tanstack/solid-query` to produce
|
|
7
|
+
* options objects compatible with `createQuery` and `createMutation`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { createQuery, createMutation, useQueryClient } from "@tanstack/solid-query"
|
|
12
|
+
* import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/solid"
|
|
13
|
+
* import { createMiraClient } from "@gettersethya/mira-client"
|
|
14
|
+
* import { PostCollection } from "../collections"
|
|
15
|
+
*
|
|
16
|
+
* const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
|
|
17
|
+
* const api = collectionAdapter(client, "posts")
|
|
18
|
+
* const queryClient = useQueryClient()
|
|
19
|
+
*
|
|
20
|
+
* function PostList() {
|
|
21
|
+
* const query = createQuery(() => api.getList({ limit: 10 }).queryOptions)
|
|
22
|
+
*
|
|
23
|
+
* const mutation = createMutation(() => ({
|
|
24
|
+
* ...api.create().mutationOptions,
|
|
25
|
+
* onSuccess: () => api.invalidateAll(queryClient),
|
|
26
|
+
* }))
|
|
27
|
+
*
|
|
28
|
+
* return (
|
|
29
|
+
* <div>
|
|
30
|
+
* <Show when={query.isLoading}><p>Loading...</p></Show>
|
|
31
|
+
* <Show when={query.data}>
|
|
32
|
+
* <ul>{query.data!.items.map(p => <li>{p.title}</li>)}</ul>
|
|
33
|
+
* </Show>
|
|
34
|
+
* </div>
|
|
35
|
+
* )
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const collectionAdapter = createCollectionAdapter(queryOptions, mutationOptions);
|
|
40
|
+
export { ActionKeys };
|
|
41
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { ActionKeys } from "./_core.js";
|
|
2
|
+
import type { MakeMutationOptions, MakeQueryOptions } from "./_core.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a {@link createCollectionAdapter | collection adapter} for **TanStack Svelte Query**.
|
|
5
|
+
*
|
|
6
|
+
* Unlike the React and Solid entries, this entry cannot ship a pre-built adapter:
|
|
7
|
+
* `@tanstack/svelte-query` v6 brands its option objects with a `unique symbol`
|
|
8
|
+
* that is not exported from the package, so any pre-built value re-exposed here
|
|
9
|
+
* fails declaration emit (`TS2527`). Accepting the factories as arguments keeps
|
|
10
|
+
* this entry emit-safe: inference happens in the consumer's project, where the
|
|
11
|
+
* branded types resolve in memory.
|
|
12
|
+
*
|
|
13
|
+
* Uses `queryOptions` and `mutationOptions` from `@tanstack/svelte-query` to produce
|
|
14
|
+
* options objects compatible with `createQuery` and `createMutation`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```svelte
|
|
18
|
+
* <script lang="ts">
|
|
19
|
+
* import { createQuery, createMutation, getQueryClient, mutationOptions, queryOptions } from "@tanstack/svelte-query"
|
|
20
|
+
* import { createSvelteCollectionAdapter } from "@gettersethya/mira-tanstack-adapter/svelte"
|
|
21
|
+
* import { createMiraClient } from "@gettersethya/mira-client"
|
|
22
|
+
* import { PostCollection } from "../collections"
|
|
23
|
+
*
|
|
24
|
+
* const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
|
|
25
|
+
* const collectionAdapter = createSvelteCollectionAdapter(queryOptions, mutationOptions)
|
|
26
|
+
* const api = collectionAdapter(client, "posts")
|
|
27
|
+
*
|
|
28
|
+
* const query = createQuery(() => api.getList({ limit: 10 }).queryOptions)
|
|
29
|
+
* const queryClient = getQueryClient()
|
|
30
|
+
*
|
|
31
|
+
* async function handleCreate() {
|
|
32
|
+
* const mutation = createMutation(() => ({
|
|
33
|
+
* ...api.create().mutationOptions,
|
|
34
|
+
* onSuccess: () => api.invalidateAll(queryClient),
|
|
35
|
+
* }))
|
|
36
|
+
* $mutation.mutate({ title: "New Post" })
|
|
37
|
+
* }
|
|
38
|
+
* </script>
|
|
39
|
+
*
|
|
40
|
+
* {#if $query.isLoading}
|
|
41
|
+
* <p>Loading...</p>
|
|
42
|
+
* {:else}
|
|
43
|
+
* <ul>{#each $query.data?.items ?? [] as post}<li>{post.title}</li>{/each}</ul>
|
|
44
|
+
* {/if}
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createSvelteCollectionAdapter<FQ extends MakeQueryOptions, FM extends MakeMutationOptions>(makeQueryOptions: FQ, makeMutationOptions: FM): <F extends import("@gettersethya/mira-collection").FieldsMap>(client: import("@gettersethya/mira-client").CollectionClient<F>, name: string) => {
|
|
48
|
+
invalidateAll: (queryClient: {
|
|
49
|
+
invalidateQueries(opts: {
|
|
50
|
+
queryKey: import("./_core.js").QueryKey;
|
|
51
|
+
}): unknown;
|
|
52
|
+
}) => unknown;
|
|
53
|
+
invalidateOne: (queryClient: {
|
|
54
|
+
invalidateQueries(opts: {
|
|
55
|
+
queryKey: import("./_core.js").QueryKey;
|
|
56
|
+
}): unknown;
|
|
57
|
+
}, id: string) => unknown;
|
|
58
|
+
register?: (() => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, import("@gettersethya/mira-collection").RegisterInput<F>>) | undefined;
|
|
59
|
+
getList: (options?: {
|
|
60
|
+
filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
|
|
61
|
+
sort?: (keyof F & string) | undefined;
|
|
62
|
+
order?: "asc" | "desc";
|
|
63
|
+
cursor?: number | null;
|
|
64
|
+
limit?: number;
|
|
65
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
66
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
67
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
68
|
+
} | undefined) => {
|
|
69
|
+
raw(): Promise<{
|
|
70
|
+
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
71
|
+
nextCursor: number | null;
|
|
72
|
+
}>;
|
|
73
|
+
toEffect(): import("effect/Effect").Effect<{
|
|
74
|
+
items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
|
|
75
|
+
nextCursor: number | null;
|
|
76
|
+
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
77
|
+
} & {
|
|
78
|
+
queryKey: import("./_core.js").QueryKey;
|
|
79
|
+
queryOptions: ReturnType<FQ>;
|
|
80
|
+
};
|
|
81
|
+
getOne: (id: string, options?: {
|
|
82
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
83
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
84
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
85
|
+
} | undefined) => {
|
|
86
|
+
raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>;
|
|
87
|
+
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>;
|
|
88
|
+
} & {
|
|
89
|
+
queryKey: import("./_core.js").QueryKey;
|
|
90
|
+
queryOptions: ReturnType<FQ>;
|
|
91
|
+
};
|
|
92
|
+
getFirstOrNone: (filter: (f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode, options?: Omit<{
|
|
93
|
+
filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
|
|
94
|
+
sort?: (keyof F & string) | undefined;
|
|
95
|
+
order?: "asc" | "desc";
|
|
96
|
+
cursor?: number | null;
|
|
97
|
+
limit?: number;
|
|
98
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
99
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
100
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
101
|
+
}, "filter" | "limit" | "cursor"> | undefined) => {
|
|
102
|
+
raw(): Promise<import("effect/Option").Option<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>>;
|
|
103
|
+
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>;
|
|
104
|
+
} & {
|
|
105
|
+
queryKey: import("./_core.js").QueryKey;
|
|
106
|
+
queryOptions: ReturnType<FQ>;
|
|
107
|
+
};
|
|
108
|
+
getFullList: (options?: (Omit<{
|
|
109
|
+
filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
|
|
110
|
+
sort?: (keyof F & string) | undefined;
|
|
111
|
+
order?: "asc" | "desc";
|
|
112
|
+
cursor?: number | null;
|
|
113
|
+
limit?: number;
|
|
114
|
+
select?: readonly (keyof F & string)[] | undefined;
|
|
115
|
+
expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
|
|
116
|
+
retryOptions?: import("@gettersethya/mira-client").RetryOptions;
|
|
117
|
+
}, "limit" | "cursor"> & {
|
|
118
|
+
limit?: number;
|
|
119
|
+
}) | undefined) => {
|
|
120
|
+
raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[]>;
|
|
121
|
+
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>;
|
|
122
|
+
} & {
|
|
123
|
+
queryKey: import("./_core.js").QueryKey;
|
|
124
|
+
queryOptions: ReturnType<FQ>;
|
|
125
|
+
};
|
|
126
|
+
create: () => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, Omit<import("@gettersethya/mira-collection").InferMutationInput<F>, "emailVerified">> & {
|
|
127
|
+
mutationOptions: ReturnType<FM>;
|
|
128
|
+
};
|
|
129
|
+
update: () => {
|
|
130
|
+
raw(input: import("@gettersethya/mira-collection").UpdateInput<F, "base">): Promise<import("@gettersethya/mira-collection").InferRecord<F>>;
|
|
131
|
+
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>;
|
|
132
|
+
} & {
|
|
133
|
+
mutationOptions: ReturnType<FM>;
|
|
134
|
+
};
|
|
135
|
+
delete: () => {
|
|
136
|
+
raw(input: string): Promise<void>;
|
|
137
|
+
toEffect(input: string): import("effect/Effect").Effect<void, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
138
|
+
} & {
|
|
139
|
+
mutationOptions: ReturnType<FM>;
|
|
140
|
+
};
|
|
141
|
+
authWithPassword?(): {
|
|
142
|
+
raw(input: {
|
|
143
|
+
email: string;
|
|
144
|
+
password: string;
|
|
145
|
+
}): Promise<{
|
|
146
|
+
token: string;
|
|
147
|
+
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
148
|
+
}>;
|
|
149
|
+
toEffect(input: {
|
|
150
|
+
email: string;
|
|
151
|
+
password: string;
|
|
152
|
+
}): import("effect/Effect").Effect<{
|
|
153
|
+
token: string;
|
|
154
|
+
record: import("@gettersethya/mira-collection").InferRecord<F>;
|
|
155
|
+
}, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
|
|
156
|
+
};
|
|
157
|
+
fields: import("@gettersethya/mira-client").CollectionFileFields<F>;
|
|
158
|
+
};
|
|
159
|
+
export { ActionKeys };
|
|
160
|
+
export type { ActionKey } from "./_core.js";
|
|
161
|
+
//# sourceMappingURL=svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,UAAU,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,6BAA6B,CAAC,EAAE,SAAS,gBAAgB,EAAE,EAAE,SAAS,mBAAmB,EACvG,gBAAgB,EAAE,EAAE,EACpB,mBAAmB,EAAE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGxB;AACD,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createCollectionAdapter, ActionKeys } from "./_core.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a {@link createCollectionAdapter | collection adapter} for **TanStack Svelte Query**.
|
|
4
|
+
*
|
|
5
|
+
* Unlike the React and Solid entries, this entry cannot ship a pre-built adapter:
|
|
6
|
+
* `@tanstack/svelte-query` v6 brands its option objects with a `unique symbol`
|
|
7
|
+
* that is not exported from the package, so any pre-built value re-exposed here
|
|
8
|
+
* fails declaration emit (`TS2527`). Accepting the factories as arguments keeps
|
|
9
|
+
* this entry emit-safe: inference happens in the consumer's project, where the
|
|
10
|
+
* branded types resolve in memory.
|
|
11
|
+
*
|
|
12
|
+
* Uses `queryOptions` and `mutationOptions` from `@tanstack/svelte-query` to produce
|
|
13
|
+
* options objects compatible with `createQuery` and `createMutation`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```svelte
|
|
17
|
+
* <script lang="ts">
|
|
18
|
+
* import { createQuery, createMutation, getQueryClient, mutationOptions, queryOptions } from "@tanstack/svelte-query"
|
|
19
|
+
* import { createSvelteCollectionAdapter } from "@gettersethya/mira-tanstack-adapter/svelte"
|
|
20
|
+
* import { createMiraClient } from "@gettersethya/mira-client"
|
|
21
|
+
* import { PostCollection } from "../collections"
|
|
22
|
+
*
|
|
23
|
+
* const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
|
|
24
|
+
* const collectionAdapter = createSvelteCollectionAdapter(queryOptions, mutationOptions)
|
|
25
|
+
* const api = collectionAdapter(client, "posts")
|
|
26
|
+
*
|
|
27
|
+
* const query = createQuery(() => api.getList({ limit: 10 }).queryOptions)
|
|
28
|
+
* const queryClient = getQueryClient()
|
|
29
|
+
*
|
|
30
|
+
* async function handleCreate() {
|
|
31
|
+
* const mutation = createMutation(() => ({
|
|
32
|
+
* ...api.create().mutationOptions,
|
|
33
|
+
* onSuccess: () => api.invalidateAll(queryClient),
|
|
34
|
+
* }))
|
|
35
|
+
* $mutation.mutate({ title: "New Post" })
|
|
36
|
+
* }
|
|
37
|
+
* </script>
|
|
38
|
+
*
|
|
39
|
+
* {#if $query.isLoading}
|
|
40
|
+
* <p>Loading...</p>
|
|
41
|
+
* {:else}
|
|
42
|
+
* <ul>{#each $query.data?.items ?? [] as post}<li>{post.title}</li>{/each}</ul>
|
|
43
|
+
* {/if}
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function createSvelteCollectionAdapter(makeQueryOptions, makeMutationOptions) {
|
|
47
|
+
return createCollectionAdapter(makeQueryOptions, makeMutationOptions);
|
|
48
|
+
}
|
|
49
|
+
export { ActionKeys };
|
|
50
|
+
//# sourceMappingURL=svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.js","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,6BAA6B,CAC3C,gBAAoB,EACpB,mBAAuB;IAEvB,OAAO,uBAAuB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAA;AACvE,CAAC;AACD,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gettersethya/mira-tanstack-adapter",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TanStack Query adapters for @gettersethya/mira client SDK",
|
|
6
6
|
"author": "Getter Sethya",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
12
16
|
"./react": {
|
|
13
17
|
"types": "./dist/react.d.ts",
|
|
14
18
|
"default": "./dist/react.js"
|
|
@@ -42,17 +46,20 @@
|
|
|
42
46
|
},
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@tanstack/react-query": "^5.0.0",
|
|
49
|
+
"@tanstack/solid-query": "^5.0.0",
|
|
50
|
+
"@tanstack/svelte-query": "^6.0.0",
|
|
45
51
|
"effect": "^4.0.0",
|
|
46
52
|
"typescript": "^6.0.3",
|
|
47
53
|
"vitest": "^5.0.0",
|
|
48
|
-
"@gettersethya/mira-client": "0.1.0-alpha.
|
|
54
|
+
"@gettersethya/mira-client": "0.1.0-alpha.20"
|
|
49
55
|
},
|
|
50
56
|
"publishConfig": {
|
|
51
57
|
"access": "public"
|
|
52
58
|
},
|
|
53
59
|
"scripts": {
|
|
54
|
-
"build": "tsc",
|
|
60
|
+
"build": "node scripts/clean-dist.ts && tsc -p tsconfig.build.json && node scripts/check-exports.ts",
|
|
55
61
|
"typecheck": "tsc --noEmit",
|
|
56
|
-
"test": "vitest run"
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"check:pack": "node scripts/check-exports.ts"
|
|
57
64
|
}
|
|
58
65
|
}
|
package/dist/src/_core.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAEtF;;;;GAIG;AACH,MAAM,MAAM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
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { MutableRef } from "effect";
|
|
4
|
-
import { ActionKeys, createCollectionAdapter, enrichMutation, enrichQuery } from "../src/_core.js";
|
|
5
|
-
import { makeClientHandler, makeMutationHandler } from "@gettersethya/mira-client";
|
|
6
|
-
import { makeCollectionClient } from "@gettersethya/mira-client";
|
|
7
|
-
import { BaseCollection } from "@gettersethya/mira-client";
|
|
8
|
-
import { Field } from "@gettersethya/mira-client";
|
|
9
|
-
const Posts = BaseCollection.define("posts", { title: Field.text() });
|
|
10
|
-
function makeTestClient() {
|
|
11
|
-
const execute = (req) => Effect.gen(function* () {
|
|
12
|
-
if (req.method === "DELETE")
|
|
13
|
-
return undefined;
|
|
14
|
-
if (req.url.includes("auth-with-password"))
|
|
15
|
-
return { token: "tok", record: { id: "1", created: "", updated: "", title: "" } };
|
|
16
|
-
if (req.method === "GET")
|
|
17
|
-
return { items: [], nextCursor: null };
|
|
18
|
-
return { id: "1", created: "", updated: "", title: "test" };
|
|
19
|
-
});
|
|
20
|
-
return makeCollectionClient({
|
|
21
|
-
collectionName: "posts",
|
|
22
|
-
schema: Posts.schema,
|
|
23
|
-
fields: Posts.fields,
|
|
24
|
-
execute,
|
|
25
|
-
baseUrl: "http://localhost",
|
|
26
|
-
authTokenRef: null,
|
|
27
|
-
loggedInRef: null,
|
|
28
|
-
fileTokenCacheRef: MutableRef.make(new Map()),
|
|
29
|
-
isAuth: false,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const identity = (opts) => opts;
|
|
33
|
-
const adapter = createCollectionAdapter(identity, identity);
|
|
34
|
-
describe("ActionKeys", () => {
|
|
35
|
-
it("has the correct constant values", () => {
|
|
36
|
-
expect(ActionKeys.GetList).toBe("getList");
|
|
37
|
-
expect(ActionKeys.GetOne).toBe("getOne");
|
|
38
|
-
expect(ActionKeys.GetFirstOrNone).toBe("getFirstOrNone");
|
|
39
|
-
expect(ActionKeys.GetFullList).toBe("getFullList");
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe("enrichQuery", () => {
|
|
43
|
-
it("attaches queryKey and queryOptions to handler", async () => {
|
|
44
|
-
const handler = makeClientHandler(Effect.succeed(42));
|
|
45
|
-
const enriched = enrichQuery(handler, ["col", "getList", {}], identity);
|
|
46
|
-
expect(enriched.queryKey).toEqual(["col", "getList", {}]);
|
|
47
|
-
expect(enriched.queryOptions.queryKey).toEqual(["col", "getList", {}]);
|
|
48
|
-
expect(await enriched.queryOptions.queryFn()).toBe(42);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe("enrichMutation", () => {
|
|
52
|
-
it("attaches mutationOptions to handler", async () => {
|
|
53
|
-
const handler = makeMutationHandler((x) => Effect.succeed(x.toUpperCase()));
|
|
54
|
-
const enriched = enrichMutation(handler, identity);
|
|
55
|
-
expect(await enriched.mutationOptions.mutationFn("hello")).toBe("HELLO");
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe("createCollectionAdapter", () => {
|
|
59
|
-
const client = makeTestClient();
|
|
60
|
-
const adapted = adapter(client, "posts");
|
|
61
|
-
it("getList — query key shape [name, GetList, options]", () => {
|
|
62
|
-
const handler = adapted.getList({ limit: 5 });
|
|
63
|
-
expect(handler.queryKey).toEqual(["posts", ActionKeys.GetList, { limit: 5 }]);
|
|
64
|
-
});
|
|
65
|
-
it("getList with no options — options defaults to {}", () => {
|
|
66
|
-
const handler = adapted.getList();
|
|
67
|
-
expect(handler.queryKey).toEqual(["posts", ActionKeys.GetList, {}]);
|
|
68
|
-
});
|
|
69
|
-
it("getList — queryOptions.queryKey matches queryKey", () => {
|
|
70
|
-
const handler = adapted.getList();
|
|
71
|
-
expect(handler.queryOptions.queryKey).toEqual(handler.queryKey);
|
|
72
|
-
});
|
|
73
|
-
it("getList — queryOptions.queryFn resolves the raw value", async () => {
|
|
74
|
-
const handler = adapted.getList();
|
|
75
|
-
const result = await handler.queryOptions.queryFn();
|
|
76
|
-
expect(result).toEqual({ items: [], nextCursor: null });
|
|
77
|
-
});
|
|
78
|
-
it("getOne — query key shape [name, GetOne, id, options]", () => {
|
|
79
|
-
const handler = adapted.getOne("abc123");
|
|
80
|
-
expect(handler.queryKey[0]).toBe("posts");
|
|
81
|
-
expect(handler.queryKey[1]).toBe(ActionKeys.GetOne);
|
|
82
|
-
expect(handler.queryKey[2]).toBe("abc123");
|
|
83
|
-
});
|
|
84
|
-
it("getFirstOrNone — query key shape includes options", () => {
|
|
85
|
-
const handler = adapted.getFirstOrNone((f) => f.field("title").eq("hi"), { sort: "title" });
|
|
86
|
-
expect(handler.queryKey[1]).toBe(ActionKeys.GetFirstOrNone);
|
|
87
|
-
expect(handler.queryKey[2]).toEqual({ sort: "title" });
|
|
88
|
-
});
|
|
89
|
-
it("getFullList — query key shape", () => {
|
|
90
|
-
const handler = adapted.getFullList();
|
|
91
|
-
expect(handler.queryKey).toEqual(["posts", ActionKeys.GetFullList, {}]);
|
|
92
|
-
});
|
|
93
|
-
it("create — mutationOptions.mutationFn delegates to handler.raw", async () => {
|
|
94
|
-
const result = await adapted.create().mutationOptions.mutationFn({ title: "hi" });
|
|
95
|
-
expect(result).toMatchObject({ id: "1" });
|
|
96
|
-
});
|
|
97
|
-
it("update — mutationOptions.mutationFn delegates to handler.raw", async () => {
|
|
98
|
-
const result = await adapted.update().mutationOptions.mutationFn({ id: "x", data: { title: "new" } });
|
|
99
|
-
expect(result).toMatchObject({ id: "1" });
|
|
100
|
-
});
|
|
101
|
-
it("delete — mutationOptions.mutationFn delegates to handler.raw", async () => {
|
|
102
|
-
const result = await adapted.delete().mutationOptions.mutationFn("abc");
|
|
103
|
-
expect(result).toBeUndefined();
|
|
104
|
-
});
|
|
105
|
-
it("invalidateAll calls invalidateQueries with collection key", () => {
|
|
106
|
-
const calls = [];
|
|
107
|
-
const mockQC = { invalidateQueries: (opts) => { calls.push(opts); } };
|
|
108
|
-
adapted.invalidateAll(mockQC);
|
|
109
|
-
expect(calls[0]).toEqual({ queryKey: ["posts"] });
|
|
110
|
-
});
|
|
111
|
-
it("invalidateOne calls invalidateQueries with [name, GetOne, id]", () => {
|
|
112
|
-
const calls = [];
|
|
113
|
-
const mockQC = { invalidateQueries: (opts) => { calls.push(opts); } };
|
|
114
|
-
adapted.invalidateOne(mockQC, "rec-1");
|
|
115
|
-
expect(calls[0]).toEqual({ queryKey: ["posts", ActionKeys.GetOne, "rec-1"] });
|
|
116
|
-
});
|
|
117
|
-
it("non-overridden fields pass through from original client", () => {
|
|
118
|
-
const original = makeTestClient();
|
|
119
|
-
const wrapped = adapter(original, "posts");
|
|
120
|
-
expect(wrapped.fields).toBe(original.fields);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
//# sourceMappingURL=tanstack-core.test.js.map
|