@gettersethya/mira-tanstack-adapter 0.1.0-alpha.21 → 0.1.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -160
- package/dist/_core.d.ts +53 -199
- package/dist/_core.d.ts.map +1 -1
- package/dist/_core.js +78 -83
- package/dist/_core.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -34
- package/dist/react.d.ts +0 -173
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -34
- package/dist/react.js.map +0 -1
- package/dist/solid.d.ts +0 -180
- package/dist/solid.d.ts.map +0 -1
- package/dist/solid.js +0 -41
- package/dist/solid.js.map +0 -1
- package/dist/svelte.d.ts +0 -161
- package/dist/svelte.d.ts.map +0 -1
- package/dist/svelte.js +0 -50
- package/dist/svelte.js.map +0 -1
package/dist/_core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_core.d.ts","sourceRoot":"","sources":["../src/_core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"_core.d.ts","sourceRoot":"","sources":["../src/_core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,SAAS,EAMV,MAAM,2BAA2B,CAAA;AAElC;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAA;AAEzD;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,KAAK,EAAE,MAAM,IAAI,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAA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AAC,EAAE,CAAC,CA8DyB,CAAA"}
|
package/dist/_core.js
CHANGED
|
@@ -14,122 +14,117 @@ export const ActionKeys = {
|
|
|
14
14
|
GetFirstOrNone: "getFirstOrNone",
|
|
15
15
|
GetFullList: "getFullList",
|
|
16
16
|
};
|
|
17
|
-
|
|
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:
|
|
33
|
+
queryOptions: { queryKey: key, queryFn: () => handler.raw() }
|
|
21
34
|
});
|
|
22
35
|
}
|
|
23
|
-
|
|
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:
|
|
26
|
-
mutationFn: (input) => handler.raw(input),
|
|
27
|
-
}),
|
|
48
|
+
mutationOptions: { mutationFn: (input) => handler.raw(input) }
|
|
28
49
|
});
|
|
29
50
|
}
|
|
30
51
|
/**
|
|
31
|
-
* Creates a
|
|
52
|
+
* Creates a framework-agnostic collection adapter.
|
|
32
53
|
*
|
|
33
|
-
*
|
|
34
|
-
* (getList, getOne, getFirstOrNone, getFullList) with `queryKey` and
|
|
35
|
-
* and every mutation method (create, update, delete)
|
|
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
|
-
*
|
|
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)`
|
|
43
|
-
* `queryClient.invalidateQueries` with the appropriate key prefix.
|
|
65
|
+
* `invalidateOne(queryClient, id)` helpers.
|
|
44
66
|
*
|
|
45
|
-
* @
|
|
46
|
-
*
|
|
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 {
|
|
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
|
|
58
|
-
*
|
|
59
|
-
*
|
|
75
|
+
* const client = createMiraClient("/api").withCollections(
|
|
76
|
+
* { posts: PostCollection },
|
|
77
|
+
* { adapter: collectionAdapter },
|
|
78
|
+
* )
|
|
60
79
|
*
|
|
61
|
-
*
|
|
62
|
-
* const
|
|
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(
|
|
76
|
-
return function adaptCollectionClient(client, name) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
getOne: (id, options) => enrichQuery(client.getOne(id, options), [name, ActionKeys.GetOne, id, options ?? {}]
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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: () => enrichMutation(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":"
|
|
1
|
+
{"version":3,"file":"_core.js","sourceRoot":"","sources":["../src/_core.ts"],"names":[],"mappings":"AAwCA;;;;;;;;;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;AAOV;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CACzB,OAAU,EACV,GAAa;IAEb,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC5B,QAAQ,EAAE,GAAG;QACb,YAAY,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE;KAC9D,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAU;IAEV,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC5B,eAAe,EAAE,EAAE,UAAU,EAAE,CAAC,KAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;KACxF,CAAC,CAAA;AACJ,CAAC;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,SAAS,qBAAqB,CACnC,MAA8B,EAC9B,IAAY,EACZ,IAAO;QAEP,MAAM,gBAAgB,GAAwB;YAC5C,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;YAChB,IAAI,EAAE,GAAG,E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,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAC7C,MAAM,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAC7C,MAAM,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAE7C;;;eAGG;YACH,aAAa,EAAE,CAAC,WAAyE,EAAE,EAAE,CAC3F,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAErD;;eAEG;YACH,aAAa,EAAE,CACb,WAAyE,EACzE,EAAU,EACV,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,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 {
|
|
2
|
-
export
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
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
|
|
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":"
|
|
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.
|
|
3
|
+
"version": "0.1.0-alpha.23",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "TanStack Query
|
|
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.
|
|
24
|
+
"@gettersethya/mira-client": "0.1.0-alpha.23"
|
|
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
|
package/dist/react.d.ts.map
DELETED
|
@@ -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"}
|