@tiesen/effect-tanstack-query 0.0.18 → 0.0.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 +7 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/{types-Day-Eet1.d.mts → types-CBIv8Q6_.d.mts} +18 -26
- package/dist/vue.d.mts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -138,6 +138,13 @@ const queryClient = useQueryClient()
|
|
|
138
138
|
void queryClient.invalidateQueries({
|
|
139
139
|
queryKey: api.group.hello.getQueryKey(),
|
|
140
140
|
})
|
|
141
|
+
|
|
142
|
+
// Call Query / Mutate Directly Example
|
|
143
|
+
const result = await api.group.hello.query({
|
|
144
|
+
params: { name: 'John' },
|
|
145
|
+
query: { greeting: 'Hi' },
|
|
146
|
+
})
|
|
147
|
+
const result2 = await api.group.goodbye.mutate({ payload: { name: 'John' } })
|
|
141
148
|
```
|
|
142
149
|
|
|
143
150
|
## Downloads
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as TanstackQueryOptionsProxy, t as SubscriptionOptions } from "./types-
|
|
1
|
+
import { n as TanstackQueryOptionsProxy, t as SubscriptionOptions } from "./types-CBIv8Q6_.mjs";
|
|
2
2
|
import { Service } from "effect/Context";
|
|
3
3
|
import { ManagedRuntime } from "effect/ManagedRuntime";
|
|
4
4
|
//#region src/create-proxy.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"effect/Effect";import*as t from"effect/Fiber";import*as n from"effect/Schedule";import*as r from"effect/Stream";function i(i,a){let o=new Map,s=c=>{let l=c.join(`.`);if(o.has(l))return o.get(l);let u=new Proxy(()=>{},{get(e,t){if(typeof t!=`symbol`&&t!==`then`)return s([...c,String(t)])},apply(o,s,l){let u=c.at(-1),d=c.slice(0,-1),[f,p]=l,m=e.fn(function*(e){let t=yield*i;for(let e of d)t=t[e];return yield*t(e)}),h=(e,t)=>a.runPromise(m(e),{signal:t}),g=(e,t)=>[{type:e},...d,...t?[t]:[]];if(u===`queryOptions`)return{...p,queryKey:g(`query`,f),queryFn:({signal:e})=>h(f,e)};if(u===`getQueryKey`)return g(`query`,f);if(u===`mutationOptions`)return{...p,mutationKey:g(`mutation`,f),mutationFn:e=>h({...f,payload:e})};if(u===`subscriptionOptions`)return{...p,enabled:p?.enabled??!0,subcriptionKey:g(`subscription`,f),subscriptionFn:({autoReconnect:i,keepAlive:o,...s})=>{let{onStarted:c,onData:l,onError:u,onConnectionChange:d}=s,p=n.max([n.exponential(i??0),n.spaced(`30 seconds`),n.recurs(3)]).pipe(n.jittered),h=e.gen(function*(){d?.({status:`connecting`}),c?.();let t=yield*m({...f,responseMode:`response-only`});d?.({status:`pending`});let n=yield*t.stream.pipe(r.decodeText,r.splitLines,r.filter(e=>e.length>0),r.share({capacity:`unbounded`})),a=n.pipe(r.filter(e=>e.startsWith(o?.message??`:keep-alive`)),r.timeout(o?.timeout??`10 seconds`)),s=yield*n.pipe(r.filter(e=>e.startsWith(`data:`)),r.map(e=>e.slice(5).trim()),r.filter(e=>e.length>0),r.mapEffect(t=>e.orElseSucceed(e.try(()=>JSON.parse(t)),()=>t)),r.tap(t=>e.sync(()=>l?.(t))),r.share({capacity:`unbounded`})),u=r.merge(a,s);yield*r.runDrain(u),i&&(yield*e.fail(`restart`))}).pipe(e.tapError(t=>t===`restart`||typeof t==`object`&&t._tag===`HttpClientError`&&t.reason?._tag===`DecodeError`?e.void:e.sync(()=>u?.(t)))),g=(i?h.pipe(e.retry(p)):h).pipe(e.ensuring(e.sync(()=>d?.({status:`idle`}))),e.scoped),_=a.runFork(g);return()=>a.runPromise(t.interrupt(_))}}}});return o.set(l,u),u};return s([])}export{i as createTanstackQueryOptionsProxy};
|
|
1
|
+
import*as e from"effect/Effect";import*as t from"effect/Fiber";import*as n from"effect/Schedule";import*as r from"effect/Stream";function i(i,a){let o=new Map,s=c=>{let l=c.join(`.`);if(o.has(l))return o.get(l);let u=new Proxy(()=>{},{get(e,t){if(typeof t!=`symbol`&&t!==`then`)return s([...c,String(t)])},apply(o,s,l){let u=c.at(-1),d=c.slice(0,-1),[f,p]=l,m=e.fn(function*(e){let t=yield*i;for(let e of d)t=t[e];return yield*t(e)}),h=(e,t)=>a.runPromise(m(e),{signal:t}),g=(e,t)=>[{type:e},...d,...t?[t]:[]];if(u===`query`||u===`mutate`)return h(f);if((u===`queryEffect`||u===`mutateEffect`)&&a.cachedContext)return m(f).pipe(e.provide(a.cachedContext));if(u===`queryOptions`)return{...p,queryKey:g(`query`,f),queryFn:({signal:e})=>h(f,e)};if(u===`getQueryKey`)return g(`query`,f);if(u===`mutationOptions`)return{...p,mutationKey:g(`mutation`,f),mutationFn:e=>h({...f,payload:e})};if(u===`subscriptionOptions`)return{...p,enabled:p?.enabled??!0,subcriptionKey:g(`subscription`,f),subscriptionFn:({autoReconnect:i,keepAlive:o,...s})=>{let{onStarted:c,onData:l,onError:u,onConnectionChange:d}=s,p=n.max([n.exponential(i??0),n.spaced(`30 seconds`),n.recurs(3)]).pipe(n.jittered),h=e.gen(function*(){d?.({status:`connecting`}),c?.();let t=yield*m({...f,responseMode:`response-only`});d?.({status:`pending`});let n=yield*t.stream.pipe(r.decodeText,r.splitLines,r.filter(e=>e.length>0),r.share({capacity:`unbounded`})),a=n.pipe(r.filter(e=>e.startsWith(o?.message??`:keep-alive`)),r.timeout(o?.timeout??`10 seconds`)),s=yield*n.pipe(r.filter(e=>e.startsWith(`data:`)),r.map(e=>e.slice(5).trim()),r.filter(e=>e.length>0),r.mapEffect(t=>e.orElseSucceed(e.try(()=>JSON.parse(t)),()=>t)),r.tap(t=>e.sync(()=>l?.(t))),r.share({capacity:`unbounded`})),u=r.merge(a,s);yield*r.runDrain(u),i&&(yield*e.fail(`restart`))}).pipe(e.tapError(t=>t===`restart`||typeof t==`object`&&t._tag===`HttpClientError`&&t.reason?._tag===`DecodeError`?e.void:e.sync(()=>u?.(t)))),g=(i?h.pipe(e.retry(p)):h).pipe(e.ensuring(e.sync(()=>d?.({status:`idle`}))),e.scoped),_=a.runFork(g);return()=>a.runPromise(t.interrupt(_))}}}});return o.set(l,u),u};return s([])}export{i as createTanstackQueryOptionsProxy};
|
package/dist/react.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-
|
|
1
|
+
import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-CBIv8Q6_.mjs";
|
|
2
2
|
//#region src/react.d.ts
|
|
3
3
|
declare function useSubscription<TData, TError>(opts: SubscriptionOptions<TData, TError>): UseSubscriptionReturns<TData, TError>;
|
|
4
4
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect/Effect";
|
|
1
2
|
import { DefaultError, MutationOptions, QueryKey, QueryObserverOptions } from "@tanstack/query-core";
|
|
2
3
|
import { Input } from "effect/Duration";
|
|
3
4
|
import { Schema } from "effect/Schema";
|
|
@@ -6,32 +7,14 @@ import { HttpApiEndpoint } from "effect/unstable/httpapi/HttpApiEndpoint";
|
|
|
6
7
|
import { SseEventFromData, StreamSse } from "effect/unstable/httpapi/HttpApiSchema";
|
|
7
8
|
//#region src/types.d.ts
|
|
8
9
|
type TanstackQueryOptionsProxy<T> = T extends Client.Method<HttpApiEndpoint<infer _Identifier, infer Method, infer _Path, infer Params, infer Query, infer Payload, infer Headers, infer Success, infer Error, infer _Middleware, infer _MiddlewareService>, infer _Error, infer _Requires> ? {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
params: UnwrapCodec<Params>;
|
|
18
|
-
}) & ([Query] extends [never] ? unknown : {
|
|
19
|
-
query: UnwrapCodec<Query>;
|
|
20
|
-
}) & ([Headers] extends [never] ? unknown : {
|
|
21
|
-
headers: UnwrapCodec<Headers>;
|
|
22
|
-
})>, options?: Omit<SubscriptionOptions<UnwrapCodec<StreamSuccess>, UnwrapCodec<StreamError>>, 'subcriptionKey' | 'subscriptionFn'>) => SubscriptionOptions<UnwrapCodec<StreamSuccess>, UnwrapCodec<StreamError>> : never;
|
|
23
|
-
mutationOptions: Method extends 'GET' ? never : <TMutation = MutationOptions<UnwrapCodec<Success>, UnwrapCodec<Error>, UnwrapCodec<Payload>>>(input: MakeOptionalInput<([Params] extends [never] ? unknown : {
|
|
24
|
-
params: UnwrapCodec<Params>;
|
|
25
|
-
}) & ([Headers] extends [never] ? unknown : {
|
|
26
|
-
headers: UnwrapCodec<Headers>;
|
|
27
|
-
})>, options?: Omit<TMutation, 'mutationKey' | 'mutationFn'>) => TMutation;
|
|
28
|
-
getQueryKey: Method extends 'GET' ? (input?: Partial<MakeOptionalInput<([Params] extends [never] ? unknown : {
|
|
29
|
-
params: UnwrapCodec<Params>;
|
|
30
|
-
}) & ([Query] extends [never] ? unknown : {
|
|
31
|
-
query: UnwrapCodec<Query>;
|
|
32
|
-
}) & ([Headers] extends [never] ? unknown : {
|
|
33
|
-
headers: UnwrapCodec<Headers>;
|
|
34
|
-
})>>) => QueryKey : never;
|
|
10
|
+
query: Method extends 'GET' ? (input: MakeInput<Headers, Params, Query, never>) => UnwrapCodec<Success> | Promise<UnwrapCodec<Success>> : never;
|
|
11
|
+
queryEffect: Method extends 'GET' ? (input: MakeInput<Headers, Params, Query, never>) => Effect<UnwrapCodec<Success>, UnwrapCodec<Error>> : never;
|
|
12
|
+
queryOptions: Method extends 'GET' ? <TQuery = QueryOptions<UnwrapCodec<Success>, UnwrapCodec<Error>>>(input: MakeInput<Headers, Params, Query, never>, options?: Omit<TQuery, 'queryKey' | 'queryFn'>) => TQuery : never;
|
|
13
|
+
subscriptionOptions: Success extends StreamSse<SseEventFromData<infer StreamSuccess>, infer StreamError, infer _StreamValue> ? (input: MakeInput<Headers, Params, Query, never>, options?: Omit<SubscriptionOptions<UnwrapCodec<StreamSuccess>, UnwrapCodec<StreamError>>, 'subcriptionKey' | 'subscriptionFn'>) => SubscriptionOptions<UnwrapCodec<StreamSuccess>, UnwrapCodec<StreamError>> : never;
|
|
14
|
+
mutate: Method extends 'GET' ? never : (input: MakeInput<Headers, Params, never, Payload>) => UnwrapCodec<Success> | Promise<UnwrapCodec<Success>>;
|
|
15
|
+
mutateEffect: Method extends 'GET' ? never : (input: MakeInput<Headers, Params, never, Payload>) => Effect<UnwrapCodec<Success>, UnwrapCodec<Error>>;
|
|
16
|
+
mutationOptions: Method extends 'GET' ? never : <TMutation = MutationOptions<UnwrapCodec<Success>, UnwrapCodec<Error>, UnwrapCodec<Payload>>>(input: MakeInput<Headers, Params, never, never>, options?: Omit<TMutation, 'mutationKey' | 'mutationFn'>) => TMutation;
|
|
17
|
+
getQueryKey: Method extends 'GET' ? (input?: Partial<MakeInput<Headers, Params, Query, never>>) => QueryKey : never;
|
|
35
18
|
} : T extends object ? { readonly [K in keyof T as K extends symbol ? never : K]: TanstackQueryOptionsProxy<T[K]>; } : T;
|
|
36
19
|
interface SubscriptionOptions<TData, TError> {
|
|
37
20
|
/**
|
|
@@ -106,5 +89,14 @@ type UseSubscriptionReturns<TData, TError> = {
|
|
|
106
89
|
});
|
|
107
90
|
type UnwrapCodec<T> = T extends Schema<unknown> ? Schema.Type<T> : T extends object ? { [K in keyof T]: UnwrapCodec<T[K]>; } : T;
|
|
108
91
|
type MakeOptionalInput<T> = keyof T extends never ? void | undefined : T;
|
|
92
|
+
type MakeInput<Headers, Params, Query, Payload> = MakeOptionalInput<([Headers] extends [never] ? unknown : {
|
|
93
|
+
headers: UnwrapCodec<Headers>;
|
|
94
|
+
}) & ([Params] extends [never] ? unknown : {
|
|
95
|
+
params: UnwrapCodec<Params>;
|
|
96
|
+
}) & ([Query] extends [never] ? unknown : {
|
|
97
|
+
query: UnwrapCodec<Query>;
|
|
98
|
+
}) & ([Payload] extends [never] ? unknown : {
|
|
99
|
+
payload: UnwrapCodec<Payload>;
|
|
100
|
+
})>;
|
|
109
101
|
//#endregion
|
|
110
102
|
export { TanstackQueryOptionsProxy as n, UseSubscriptionReturns as r, SubscriptionOptions as t };
|
package/dist/vue.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-
|
|
1
|
+
import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-CBIv8Q6_.mjs";
|
|
2
2
|
import { MaybeRefOrGetter } from "vue";
|
|
3
3
|
//#region src/vue.d.ts
|
|
4
4
|
declare function useSubscription<TData, TError>(optsInput: MaybeRefOrGetter<SubscriptionOptions<TData, TError>>): UseSubscriptionReturns<TData, TError>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiesen/effect-tanstack-query",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Effortlessly bridge Effect HTTP API clients with TanStack Query. Enjoy end-to-end type safety, zero-boilerplate options, and built-in streaming support out of the box.",
|
|
6
6
|
"keywords": [
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@tanstack/query-core": ">=5.100.0",
|
|
72
|
-
"effect": ">=4.0.0-rc.
|
|
72
|
+
"effect": ">=4.0.0-rc.109",
|
|
73
73
|
"react": ">=19.2.8",
|
|
74
74
|
"vue": ">=3.5.40"
|
|
75
75
|
},
|