@tiesen/effect-tanstack-query 0.0.17 → 0.0.19
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 +2 -2
- package/dist/index.mjs +1 -1
- package/dist/react.d.mts +3 -3
- package/dist/{types-A-WfeH_j.d.mts → types-CJQT8COr.d.mts} +17 -3
- package/dist/vue.d.mts +3 -3
- package/package.json +1 -1
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 {
|
|
1
|
+
import { n as TanstackQueryOptionsProxy, t as SubscriptionOptions } from "./types-CJQT8COr.mjs";
|
|
2
2
|
import { Service } from "effect/Context";
|
|
3
3
|
import { ManagedRuntime } from "effect/ManagedRuntime";
|
|
4
4
|
//#region src/create-proxy.d.ts
|
|
@@ -43,4 +43,4 @@ import { ManagedRuntime } from "effect/ManagedRuntime";
|
|
|
43
43
|
*/
|
|
44
44
|
declare function createTanstackQueryOptionsProxy<TServiceTag, TService>(tag: Service<TServiceTag, TService>, runtime: ManagedRuntime<TServiceTag, never>): TanstackQueryOptionsProxy<TService>;
|
|
45
45
|
//#endregion
|
|
46
|
-
export { type TanstackQueryOptionsProxy, createTanstackQueryOptionsProxy };
|
|
46
|
+
export { type SubscriptionOptions, type TanstackQueryOptionsProxy, createTanstackQueryOptionsProxy };
|
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===`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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-CJQT8COr.mjs";
|
|
2
2
|
//#region src/react.d.ts
|
|
3
|
-
declare function useSubscription<TData, TError>(opts: SubscriptionOptions<TData, TError>):
|
|
3
|
+
declare function useSubscription<TData, TError>(opts: SubscriptionOptions<TData, TError>): UseSubscriptionReturns<TData, TError>;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { type SubscriptionOptions, type SubscriptionReturns, useSubscription };
|
|
5
|
+
export { type SubscriptionOptions, type UseSubscriptionReturns as SubscriptionReturns, useSubscription };
|
|
@@ -6,6 +6,13 @@ import { HttpApiEndpoint } from "effect/unstable/httpapi/HttpApiEndpoint";
|
|
|
6
6
|
import { SseEventFromData, StreamSse } from "effect/unstable/httpapi/HttpApiSchema";
|
|
7
7
|
//#region src/types.d.ts
|
|
8
8
|
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
|
+
query: Method extends 'GET' ? (input: MakeOptionalInput<([Params] extends [never] ? unknown : {
|
|
10
|
+
params: UnwrapCodec<Params>;
|
|
11
|
+
}) & ([Query] extends [never] ? unknown : {
|
|
12
|
+
query: UnwrapCodec<Query>;
|
|
13
|
+
}) & ([Headers] extends [never] ? unknown : {
|
|
14
|
+
headers: UnwrapCodec<Headers>;
|
|
15
|
+
})>) => UnwrapCodec<Success> | Promise<UnwrapCodec<Success>> : never;
|
|
9
16
|
queryOptions: Method extends 'GET' ? <TQuery = QueryOptions<UnwrapCodec<Success>, UnwrapCodec<Error>>>(input: MakeOptionalInput<([Params] extends [never] ? unknown : {
|
|
10
17
|
params: UnwrapCodec<Params>;
|
|
11
18
|
}) & ([Query] extends [never] ? unknown : {
|
|
@@ -20,6 +27,13 @@ type TanstackQueryOptionsProxy<T> = T extends Client.Method<HttpApiEndpoint<infe
|
|
|
20
27
|
}) & ([Headers] extends [never] ? unknown : {
|
|
21
28
|
headers: UnwrapCodec<Headers>;
|
|
22
29
|
})>, options?: Omit<SubscriptionOptions<UnwrapCodec<StreamSuccess>, UnwrapCodec<StreamError>>, 'subcriptionKey' | 'subscriptionFn'>) => SubscriptionOptions<UnwrapCodec<StreamSuccess>, UnwrapCodec<StreamError>> : never;
|
|
30
|
+
mutate: Method extends 'GET' ? never : (input: MakeOptionalInput<([Params] extends [never] ? unknown : {
|
|
31
|
+
params: UnwrapCodec<Params>;
|
|
32
|
+
}) & ([Headers] extends [never] ? unknown : {
|
|
33
|
+
headers: UnwrapCodec<Headers>;
|
|
34
|
+
}) & ([Payload] extends [never] ? unknown : {
|
|
35
|
+
payload: UnwrapCodec<Payload>;
|
|
36
|
+
})>) => UnwrapCodec<Success> | Promise<UnwrapCodec<Success>>;
|
|
23
37
|
mutationOptions: Method extends 'GET' ? never : <TMutation = MutationOptions<UnwrapCodec<Success>, UnwrapCodec<Error>, UnwrapCodec<Payload>>>(input: MakeOptionalInput<([Params] extends [never] ? unknown : {
|
|
24
38
|
params: UnwrapCodec<Params>;
|
|
25
39
|
}) & ([Headers] extends [never] ? unknown : {
|
|
@@ -80,12 +94,12 @@ interface SubscriptionOptions<TData, TError> {
|
|
|
80
94
|
/**
|
|
81
95
|
* Callback invoked when the connection's status changes
|
|
82
96
|
*/
|
|
83
|
-
onConnectionChange?: (result: Partial<
|
|
97
|
+
onConnectionChange?: (result: Partial<UseSubscriptionReturns<TData, TError>>) => void;
|
|
84
98
|
}
|
|
85
99
|
type QueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
|
|
86
100
|
subscribed?: boolean;
|
|
87
101
|
};
|
|
88
|
-
type
|
|
102
|
+
type UseSubscriptionReturns<TData, TError> = {
|
|
89
103
|
reset: () => void;
|
|
90
104
|
} & ({
|
|
91
105
|
status: 'idle';
|
|
@@ -107,4 +121,4 @@ type SubscriptionReturns<TData, TError> = {
|
|
|
107
121
|
type UnwrapCodec<T> = T extends Schema<unknown> ? Schema.Type<T> : T extends object ? { [K in keyof T]: UnwrapCodec<T[K]>; } : T;
|
|
108
122
|
type MakeOptionalInput<T> = keyof T extends never ? void | undefined : T;
|
|
109
123
|
//#endregion
|
|
110
|
-
export {
|
|
124
|
+
export { TanstackQueryOptionsProxy as n, UseSubscriptionReturns as r, SubscriptionOptions as t };
|
package/dist/vue.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-CJQT8COr.mjs";
|
|
2
2
|
import { MaybeRefOrGetter } from "vue";
|
|
3
3
|
//#region src/vue.d.ts
|
|
4
|
-
declare function useSubscription<TData, TError>(optsInput: MaybeRefOrGetter<SubscriptionOptions<TData, TError>>):
|
|
4
|
+
declare function useSubscription<TData, TError>(optsInput: MaybeRefOrGetter<SubscriptionOptions<TData, TError>>): UseSubscriptionReturns<TData, TError>;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { type SubscriptionOptions, type SubscriptionReturns, useSubscription };
|
|
6
|
+
export { type SubscriptionOptions, type UseSubscriptionReturns as SubscriptionReturns, useSubscription };
|
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.19",
|
|
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": [
|