@gettersethya/mira-tanstack-adapter 0.1.0-alpha.20 → 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.
@@ -1 +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,gBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAA;AAEzE;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,EAC9C,IAAI,EAAE,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,KACtC,OAAO,CAAA;AAEZ;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU;;;;;CAKb,CAAA;AAEV;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAEpE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,SA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 +14,117 @@ export const ActionKeys = {
14
14
  GetFirstOrNone: "getFirstOrNone",
15
15
  GetFullList: "getFullList",
16
16
  };
17
- export function enrichQuery(handler, key, makeQueryOptions) {
17
+ /**
18
+ * Extends a query handler with a `queryKey` and pre-built `queryOptions` object.
19
+ *
20
+ * The returned handler retains all original methods (e.g. `raw()`, `toEffect()`)
21
+ * with `queryKey` and `queryOptions` added as extra properties via `Object.assign`.
22
+ *
23
+ * @template T - The data type returned by the underlying handler.
24
+ * @template H - The handler type, constrained to objects with a zero-arg `raw()` method returning `Promise<T>`.
25
+ * @param handler - The original handler (e.g. from `client.getList()`).
26
+ * @param key - The query key array to associate with this query.
27
+ * @returns The original handler augmented with `queryKey` and `queryOptions`.
28
+ * @see enrichMutation For the mutation equivalent.
29
+ */
30
+ export function enrichQuery(handler, key) {
18
31
  return Object.assign(handler, {
19
32
  queryKey: key,
20
- queryOptions: makeQueryOptions({ queryKey: key, queryFn: () => handler.raw() }),
33
+ queryOptions: { queryKey: key, queryFn: () => handler.raw() }
21
34
  });
22
35
  }
23
- export function enrichMutation(handler, makeMutationOptions) {
36
+ /**
37
+ * Extends a mutation handler with a pre-built `mutationOptions` object.
38
+ *
39
+ * @template TData - The data type returned by the mutation handler.
40
+ * @template TInput - The input data type consumed by the mutation handler.
41
+ * @template H - The handler type, constrained to objects with a single-arg `raw(input)` method.
42
+ * @param handler - The original handler (e.g. from `client.create()`).
43
+ * @returns The original handler augmented with `mutationOptions`.
44
+ * @see enrichQuery For the query equivalent.
45
+ */
46
+ export function enrichMutation(handler) {
24
47
  return Object.assign(handler, {
25
- mutationOptions: makeMutationOptions({
26
- mutationFn: (input) => handler.raw(input),
27
- }),
48
+ mutationOptions: { mutationFn: (input) => handler.raw(input) }
28
49
  });
29
50
  }
30
51
  /**
31
- * Creates a TanStack Query adapter for any {@link CollectionClient}.
52
+ * Creates a framework-agnostic collection adapter.
32
53
  *
33
- * Returns a function that wraps a `CollectionClient` and enriches every query method
34
- * (getList, getOne, getFirstOrNone, getFullList) with `queryKey` and `queryOptions`,
35
- * and every mutation method (create, update, delete) with `mutationOptions`.
54
+ * The adapter wraps a `CollectionClient` and enriches every query method
55
+ * (getList, getOne, getFirstOrNone, getFullList) with `queryKey` and
56
+ * `queryOptions`, and every mutation method (create, update, delete, register)
57
+ * with `mutationOptions`. The produced option objects are plain
58
+ * `{ queryKey, queryFn }` / `{ mutationFn }` shapes, accepted by TanStack Query
59
+ * in every framework — so the package has no runtime dependency on TanStack.
36
60
  *
37
- * Query keys follow a structured pattern: `[collectionName, actionKey, ...params]`.
38
- * This enables fine-grained cache invalidation — for example, invalidating only
39
- * `getOne` queries for a specific record by referencing key `["posts", "getOne", id]`.
61
+ * Query keys follow a structured pattern: `[collectionName, actionKey, ...params]`,
62
+ * enabling fine-grained cache invalidation (e.g. `[name, "getOne", id]`).
40
63
  *
41
64
  * The returned object also exposes `invalidateAll(queryClient)` and
42
- * `invalidateOne(queryClient, id)` convenience methods that call
43
- * `queryClient.invalidateQueries` with the appropriate key prefix.
65
+ * `invalidateOne(queryClient, id)` helpers.
44
66
  *
45
- * @param makeQueryOptions - Framework-specific `queryOptions` factory
46
- * (e.g. from `@tanstack/react-query`, `@tanstack/svelte-query`, or `@tanstack/solid-query`).
47
- * @param makeMutationOptions - Framework-specific `mutationOptions` factory.
48
- * @returns An adapter function that takes a `CollectionClient` and collection name,
49
- * and returns an enhanced client with query/mutation metadata.
67
+ * @returns An adapter function that takes a `CollectionClient` and collection
68
+ * name, and returns an enhanced client with query/mutation metadata.
50
69
  *
51
70
  * @example
52
71
  * ```ts
53
- * import { queryOptions, mutationOptions } from "@tanstack/react-query"
72
+ * import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter"
54
73
  * import { createMiraClient } from "@gettersethya/mira-client"
55
- * import { createCollectionAdapter } from "@gettersethya/mira-tanstack-adapter"
56
74
  *
57
- * const adapt = createCollectionAdapter(queryOptions, mutationOptions)
58
- * const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
59
- * const adapted = adapt(client, "posts")
75
+ * const client = createMiraClient("/api").withCollections(
76
+ * { posts: PostCollection },
77
+ * { adapter: collectionAdapter },
78
+ * )
60
79
  *
61
- * // Use in a React component:
62
- * const { data } = useQuery(adapted.getList({ limit: 10 }).queryOptions)
63
- * const mutation = useMutation(adapted.create().mutationOptions)
64
- *
65
- * // Invalidate after mutation:
66
- * adapted.invalidateAll(queryClient)
67
- * adapted.invalidateOne(queryClient, recordId)
80
+ * const { data } = useQuery(client.posts.getList({ limit: 10 }).queryOptions)
81
+ * const mutation = useMutation(client.posts.create().mutationOptions)
68
82
  * ```
69
83
  *
70
84
  * @see enrichQuery
71
85
  * @see enrichMutation
72
- * @see MakeQueryOptions
73
- * @see MakeMutationOptions
74
86
  */
75
- export function createCollectionAdapter(makeQueryOptions, makeMutationOptions) {
76
- return function adaptCollectionClient(client, name) {
77
- const registerFn = client.register;
78
- return {
79
- ...client,
80
- /**
81
- * Enriched version of `getList` that also returns `queryKey` and `queryOptions`.
82
- * Query key: `[name, "getList", options]`.
83
- */
84
- getList: (options) => enrichQuery(client.getList(options), [name, ActionKeys.GetList, options ?? {}], makeQueryOptions),
85
- /**
86
- * Enriched version of `getOne` that also returns `queryKey` and `queryOptions`.
87
- * Query key: `[name, "getOne", id, options]`.
88
- */
89
- getOne: (id, options) => enrichQuery(client.getOne(id, options), [name, ActionKeys.GetOne, id, options ?? {}], makeQueryOptions),
90
- /**
91
- * Enriched version of `getFirstOrNone` that also returns `queryKey` and `queryOptions`.
92
- * Query key: `[name, "getFirstOrNone", options]`.
93
- */
94
- getFirstOrNone: (filter, options) => enrichQuery(client.getFirstOrNone(filter, options), [name, ActionKeys.GetFirstOrNone, options ?? {}], makeQueryOptions),
95
- /**
96
- * Enriched version of `getFullList` that also returns `queryKey` and `queryOptions`.
97
- * Query key: `[name, "getFullList", options]`.
98
- */
99
- getFullList: (options) => enrichQuery(client.getFullList(options), [name, ActionKeys.GetFullList, options ?? {}], makeQueryOptions),
100
- /**
101
- * Enriched mutation for creating records. Call `raw(input)` to execute.
102
- */
103
- create: () => enrichMutation(client.create(), makeMutationOptions),
104
- /**
105
- * Enriched mutation for updating records. Call `raw(input)` to execute.
106
- */
107
- update: () => enrichMutation(client.update(), makeMutationOptions),
108
- /**
109
- * Enriched mutation for deleting records. Call `raw(input)` to execute.
110
- */
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) } : {}),
87
+ export function createCollectionAdapter() {
88
+ return function adaptCollectionClient(client, name, kind) {
89
+ const kindAuthAdapters = {
90
+ base: () => ({}),
91
+ view: () => ({}),
92
+ auth: (authClient) => ({
93
+ authWithPassword: () => authClient.authWithPassword(),
94
+ register: () => enrichMutation(authClient.register()),
95
+ }),
96
+ };
97
+ const authExtras = kindAuthAdapters[kind](client, name);
98
+ const common = {
99
+ fields: client.fields,
100
+ getList: (options) => enrichQuery(client.getList(options), [name, ActionKeys.GetList, options ?? {}]),
101
+ getOne: (id, options) => enrichQuery(client.getOne(id, options), [name, ActionKeys.GetOne, id, options ?? {}]),
102
+ getFirstOrNone: (filter, options) => enrichQuery(client.getFirstOrNone(filter, options), [name, ActionKeys.GetFirstOrNone, options ?? {}]),
103
+ getFullList: (options) => enrichQuery(client.getFullList(options), [name, ActionKeys.GetFullList, options ?? {}]),
104
+ create: () => enrichMutation(client.create()),
105
+ update: () => enrichMutation(client.update()),
106
+ delete: () => enrichMutation(client.delete()),
117
107
  /**
118
108
  * Invalidates all cached queries for this collection.
119
109
  * Calls `queryClient.invalidateQueries` with key prefix `[name]`.
120
- *
121
- * @param queryClient - Any TanStack Query client with `invalidateQueries`.
122
110
  */
123
111
  invalidateAll: (queryClient) => queryClient.invalidateQueries({ queryKey: [name] }),
124
112
  /**
125
113
  * Invalidates only the `getOne` cache entry for a specific record.
126
- * Calls `queryClient.invalidateQueries` with key `[name, "getOne", id]`.
127
- *
128
- * @param queryClient - Any TanStack Query client with `invalidateQueries`.
129
- * @param id - The record ID whose cached `getOne` entry should be invalidated.
130
114
  */
131
- invalidateOne: (queryClient, id) => queryClient.invalidateQueries({ queryKey: [name, ActionKeys.GetOne, id] }),
115
+ invalidateOne: (queryClient, id) => queryClient.invalidateQueries({ queryKey: [name, ActionKeys.GetOne, id] })
132
116
  };
117
+ // Spread of the concrete head and the generic per-kind extras yields exactly
118
+ // `AdaptedCommon<F, K> & AdaptedAuthByKind<F>[K]` == AdaptedCollectionClient<F, K>.
119
+ return { ...common, ...authExtras };
133
120
  };
134
121
  }
122
+ /**
123
+ * A pre-built {@link createCollectionAdapter | collection adapter}.
124
+ *
125
+ * Framework-agnostic — the option objects it produces satisfy TanStack Query's
126
+ * `useQuery` / `useMutation` (React, Solid) and `createQuery` / `createMutation`
127
+ * (Svelte) inputs.
128
+ */
129
+ export const collectionAdapter = createCollectionAdapter();
135
130
  //# sourceMappingURL=_core.js.map
package/dist/_core.js.map CHANGED
@@ -1 +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,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC5B,QAAQ,EAAE,GAAG;QACb,YAAY,EAAE,gBAAgB,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;KAChF,CAAC,CAAA;AACJ,CAAC;AAuBD,MAAM,UAAU,cAAc,C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UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;SAChF,CAAA;QAED,6EAA6E;QAC7E,oFAAoF;QACpF,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,UAAU,EAAE,CAAA;IACrC,CAAC,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,EAAE,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { ActionKeys, createCollectionAdapter, enrichMutation, enrichQuery, } from "./_core.js";
2
- export type { ActionKey, MakeMutationOptions, MakeQueryOptions, MutationOptionsShape, QueryKey, QueryOptionsShape, } from "./_core.js";
1
+ export type { ActionKey, MutationOptionsShape, QueryKey, QueryOptionsShape } from "./_core.js";
2
+ export { ActionKeys, collectionAdapter, createCollectionAdapter, enrichMutation, enrichQuery } from "./_core.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,oBAAoB,EACpB,QAAQ,EACR,iBAAiB,EAClB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { ActionKeys, createCollectionAdapter, enrichMutation, enrichQuery, } from "./_core.js";
1
+ export { ActionKeys, collectionAdapter, createCollectionAdapter, enrichMutation, enrichQuery } from "./_core.js";
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAA"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@gettersethya/mira-tanstack-adapter",
3
- "version": "0.1.0-alpha.20",
3
+ "version": "0.1.0-alpha.22",
4
4
  "type": "module",
5
- "description": "TanStack Query adapters for @gettersethya/mira client SDK",
5
+ "description": "Framework-agnostic TanStack Query adapter for the @gettersethya/mira client SDK",
6
6
  "author": "Getter Sethya",
7
7
  "license": "MIT",
8
8
  "files": [
@@ -12,46 +12,16 @@
12
12
  ".": {
13
13
  "types": "./dist/index.d.ts",
14
14
  "default": "./dist/index.js"
15
- },
16
- "./react": {
17
- "types": "./dist/react.d.ts",
18
- "default": "./dist/react.js"
19
- },
20
- "./svelte": {
21
- "types": "./dist/svelte.d.ts",
22
- "default": "./dist/svelte.js"
23
- },
24
- "./solid": {
25
- "types": "./dist/solid.d.ts",
26
- "default": "./dist/solid.js"
27
15
  }
28
16
  },
29
17
  "peerDependencies": {
30
- "@gettersethya/mira-client": "*",
31
- "@tanstack/react-query": ">=5.0.0",
32
- "@tanstack/svelte-query": ">=5.0.0",
33
- "@tanstack/solid-query": ">=5.0.0",
34
- "effect": "^4.0.0"
35
- },
36
- "peerDependenciesMeta": {
37
- "@tanstack/react-query": {
38
- "optional": true
39
- },
40
- "@tanstack/svelte-query": {
41
- "optional": true
42
- },
43
- "@tanstack/solid-query": {
44
- "optional": true
45
- }
18
+ "@gettersethya/mira-client": "*"
46
19
  },
47
20
  "devDependencies": {
48
- "@tanstack/react-query": "^5.0.0",
49
- "@tanstack/solid-query": "^5.0.0",
50
- "@tanstack/svelte-query": "^6.0.0",
51
21
  "effect": "^4.0.0",
52
22
  "typescript": "^6.0.3",
53
23
  "vitest": "^5.0.0",
54
- "@gettersethya/mira-client": "0.1.0-alpha.20"
24
+ "@gettersethya/mira-client": "0.1.0-alpha.22"
55
25
  },
56
26
  "publishConfig": {
57
27
  "access": "public"
package/dist/react.d.ts DELETED
@@ -1,173 +0,0 @@
1
- import { ActionKeys } from "./_core.js";
2
- /**
3
- * A pre-built {@link createCollectionAdapter | collection adapter} for **TanStack React Query**.
4
- *
5
- * Uses `queryOptions` and `mutationOptions` from `@tanstack/react-query` to produce
6
- * options objects compatible with `useQuery` and `useMutation`.
7
- *
8
- * @example
9
- * ```tsx
10
- * import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
11
- * import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/react"
12
- * import { createMiraClient } from "@gettersethya/mira-client"
13
- *
14
- * const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
15
- * const api = collectionAdapter(client, "posts")
16
- *
17
- * function PostList() {
18
- * const { data } = useQuery(api.getList({ limit: 10 }).queryOptions)
19
- * const queryClient = useQueryClient()
20
- *
21
- * const mutation = useMutation({
22
- * ...api.create().mutationOptions,
23
- * onSuccess: () => api.invalidateAll(queryClient),
24
- * })
25
- *
26
- * if (!data) return <div>Loading...</div>
27
- * return <ul>{data.items.map(p => <li key={p.id}>{p.title}</li>)}</ul>
28
- * }
29
- * ```
30
- */
31
- export declare const collectionAdapter: <F extends import("@gettersethya/mira-collection").FieldsMap>(client: import("@gettersethya/mira-client").CollectionClient<F>, name: string) => {
32
- invalidateAll: (queryClient: {
33
- invalidateQueries(opts: {
34
- queryKey: import("./_core.js").QueryKey;
35
- }): unknown;
36
- }) => unknown;
37
- invalidateOne: (queryClient: {
38
- invalidateQueries(opts: {
39
- queryKey: import("./_core.js").QueryKey;
40
- }): unknown;
41
- }, id: string) => unknown;
42
- register?: (() => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, import("@gettersethya/mira-collection").RegisterInput<F>>) | undefined;
43
- getList: (options?: {
44
- filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
45
- sort?: (keyof F & string) | undefined;
46
- order?: "asc" | "desc";
47
- cursor?: number | null;
48
- limit?: number;
49
- select?: readonly (keyof F & string)[] | undefined;
50
- expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
51
- retryOptions?: import("@gettersethya/mira-client").RetryOptions;
52
- } | undefined) => {
53
- raw(): Promise<{
54
- items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
55
- nextCursor: number | null;
56
- }>;
57
- toEffect(): import("effect/Effect").Effect<{
58
- items: import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[];
59
- nextCursor: number | null;
60
- }, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
61
- } & {
62
- queryKey: import("./_core.js").QueryKey;
63
- queryOptions: import("@tanstack/react-query").UseQueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
64
- initialData?: unknown;
65
- } & {
66
- queryKey: readonly unknown[] & {
67
- [dataTagSymbol]: unknown;
68
- [dataTagErrorSymbol]: unknown;
69
- };
70
- };
71
- };
72
- getOne: (id: string, options?: {
73
- select?: readonly (keyof F & string)[] | undefined;
74
- expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
75
- retryOptions?: import("@gettersethya/mira-client").RetryOptions;
76
- } | undefined) => {
77
- raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>;
78
- 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>;
79
- } & {
80
- queryKey: import("./_core.js").QueryKey;
81
- queryOptions: import("@tanstack/react-query").UseQueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
82
- initialData?: unknown;
83
- } & {
84
- queryKey: readonly unknown[] & {
85
- [dataTagSymbol]: unknown;
86
- [dataTagErrorSymbol]: unknown;
87
- };
88
- };
89
- };
90
- getFirstOrNone: (filter: (f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode, options?: Omit<{
91
- filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
92
- sort?: (keyof F & string) | undefined;
93
- order?: "asc" | "desc";
94
- cursor?: number | null;
95
- limit?: number;
96
- select?: readonly (keyof F & string)[] | undefined;
97
- expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
98
- retryOptions?: import("@gettersethya/mira-client").RetryOptions;
99
- }, "filter" | "limit" | "cursor"> | undefined) => {
100
- raw(): Promise<import("effect/Option").Option<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>>>;
101
- 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>;
102
- } & {
103
- queryKey: import("./_core.js").QueryKey;
104
- queryOptions: import("@tanstack/react-query").UseQueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
105
- initialData?: unknown;
106
- } & {
107
- queryKey: readonly unknown[] & {
108
- [dataTagSymbol]: unknown;
109
- [dataTagErrorSymbol]: unknown;
110
- };
111
- };
112
- };
113
- getFullList: (options?: (Omit<{
114
- filter?: ((f: import("@gettersethya/mira-client").FilterBuilder<F>) => import("@gettersethya/mira-collection").FilterNode) | undefined;
115
- sort?: (keyof F & string) | undefined;
116
- order?: "asc" | "desc";
117
- cursor?: number | null;
118
- limit?: number;
119
- select?: readonly (keyof F & string)[] | undefined;
120
- expand?: readonly import("@gettersethya/mira-collection").RelationKeys<F>[] | undefined;
121
- retryOptions?: import("@gettersethya/mira-client").RetryOptions;
122
- }, "limit" | "cursor"> & {
123
- limit?: number;
124
- }) | undefined) => {
125
- raw(): Promise<import("@gettersethya/mira-collection").WithExpand<F, readonly import("@gettersethya/mira-collection").RelationKeys<F>[]>[]>;
126
- 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>;
127
- } & {
128
- queryKey: import("./_core.js").QueryKey;
129
- queryOptions: import("@tanstack/react-query").UseQueryOptions<unknown, unknown, unknown, readonly unknown[]> & {
130
- initialData?: unknown;
131
- } & {
132
- queryKey: readonly unknown[] & {
133
- [dataTagSymbol]: unknown;
134
- [dataTagErrorSymbol]: unknown;
135
- };
136
- };
137
- };
138
- create: () => import("@gettersethya/mira-client").ClientHandler<import("@gettersethya/mira-collection").InferRecord<F>, Omit<import("@gettersethya/mira-collection").InferMutationInput<F>, "emailVerified">> & {
139
- mutationOptions: Omit<import("@tanstack/react-query").UseMutationOptions<unknown, unknown, unknown, unknown>, "mutationKey">;
140
- };
141
- update: () => {
142
- raw(input: import("@gettersethya/mira-collection").UpdateInput<F, "base">): Promise<import("@gettersethya/mira-collection").InferRecord<F>>;
143
- 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>;
144
- } & {
145
- mutationOptions: Omit<import("@tanstack/react-query").UseMutationOptions<unknown, unknown, unknown, unknown>, "mutationKey">;
146
- };
147
- delete: () => {
148
- raw(input: string): Promise<void>;
149
- toEffect(input: string): import("effect/Effect").Effect<void, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
150
- } & {
151
- mutationOptions: Omit<import("@tanstack/react-query").UseMutationOptions<unknown, unknown, unknown, unknown>, "mutationKey">;
152
- };
153
- authWithPassword?(): {
154
- raw(input: {
155
- email: string;
156
- password: string;
157
- }): Promise<{
158
- token: string;
159
- record: import("@gettersethya/mira-collection").InferRecord<F>;
160
- }>;
161
- toEffect(input: {
162
- email: string;
163
- password: string;
164
- }): import("effect/Effect").Effect<{
165
- token: string;
166
- record: import("@gettersethya/mira-collection").InferRecord<F>;
167
- }, import("@gettersethya/mira-client").MiraError, import("effect/http/HttpClient").HttpClient>;
168
- };
169
- fields: import("@gettersethya/mira-client").CollectionFileFields<F>;
170
- };
171
- export { ActionKeys };
172
- export type { ActionKey } from "./_core.js";
173
- //# sourceMappingURL=react.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAyD,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA"}
package/dist/react.js DELETED
@@ -1,34 +0,0 @@
1
- import { mutationOptions, queryOptions } from "@tanstack/react-query";
2
- import { createCollectionAdapter, ActionKeys } from "./_core.js";
3
- /**
4
- * A pre-built {@link createCollectionAdapter | collection adapter} for **TanStack React Query**.
5
- *
6
- * Uses `queryOptions` and `mutationOptions` from `@tanstack/react-query` to produce
7
- * options objects compatible with `useQuery` and `useMutation`.
8
- *
9
- * @example
10
- * ```tsx
11
- * import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
12
- * import { collectionAdapter } from "@gettersethya/mira-tanstack-adapter/react"
13
- * import { createMiraClient } from "@gettersethya/mira-client"
14
- *
15
- * const client = createMiraClient({ url: "/api" }).withCollections({ posts: PostCollection })
16
- * const api = collectionAdapter(client, "posts")
17
- *
18
- * function PostList() {
19
- * const { data } = useQuery(api.getList({ limit: 10 }).queryOptions)
20
- * const queryClient = useQueryClient()
21
- *
22
- * const mutation = useMutation({
23
- * ...api.create().mutationOptions,
24
- * onSuccess: () => api.invalidateAll(queryClient),
25
- * })
26
- *
27
- * if (!data) return <div>Loading...</div>
28
- * return <ul>{data.items.map(p => <li key={p.id}>{p.title}</li>)}</ul>
29
- * }
30
- * ```
31
- */
32
- export const collectionAdapter = createCollectionAdapter(queryOptions, mutationOptions);
33
- export { ActionKeys };
34
- //# sourceMappingURL=react.js.map
package/dist/react.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,CAAA"}