@tiesen/effect-tanstack-query 0.0.19 → 0.0.21

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as TanstackQueryOptionsProxy, t as SubscriptionOptions } from "./types-CJQT8COr.mjs";
1
+ import { n as TanstackQueryOptionsProxy, t as SubscriptionOptions } from "./types-BarbB5aY.mjs";
2
2
  import { Service } from "effect/Context";
3
3
  import { ManagedRuntime } from "effect/ManagedRuntime";
4
4
  //#region src/create-proxy.d.ts
@@ -41,6 +41,6 @@ import { ManagedRuntime } from "effect/ManagedRuntime";
41
41
  * }))
42
42
  * ```
43
43
  */
44
- declare function createTanstackQueryOptionsProxy<TServiceTag, TService>(tag: Service<TServiceTag, TService>, runtime: ManagedRuntime<TServiceTag, never>): TanstackQueryOptionsProxy<TService>;
44
+ export declare function createTanstackQueryOptionsProxy<TServiceTag, TService>(tag: Service<TServiceTag, TService>, runtime: ManagedRuntime<TServiceTag, never>): TanstackQueryOptionsProxy<TService>;
45
45
  //#endregion
46
- export { type SubscriptionOptions, type TanstackQueryOptionsProxy, createTanstackQueryOptionsProxy };
46
+ export type { SubscriptionOptions, TanstackQueryOptionsProxy };
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===`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};
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=/* @__PURE__ */ 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-CJQT8COr.mjs";
1
+ import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-BarbB5aY.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
package/dist/react.mjs CHANGED
@@ -1 +1 @@
1
- import{hashKey as e}from"@tanstack/query-core";import*as t from"react";function n(n){let i=t.useRef(n);i.current=n;let a=t.useRef(new Set),o=t.useCallback(e=>{a.current.add(e)},[]),s=t.useRef(()=>{}),c=t.useCallback(()=>{if(s.current(),p(l),!n.enabled)return;let e=n.subscriptionFn({autoReconnect:i.current.autoReconnect,keepAlive:i.current.keepAlive,onStarted:()=>{i.current.onStarted?.(),p(e=>({...e,status:`pending`,error:null}))},onData:e=>{i.current.onData?.(e),p(t=>({...t,status:`pending`,data:e,error:null}))},onError:e=>{i.current.onError?.(e),p(t=>({...t,status:`error`,error:e}))},onConnectionChange:e=>{i.current.onConnectionChange?.(e),p(t=>{switch(e.status){case`connecting`:return{...t,status:`connecting`,error:e.error??null};case`pending`:return t;case`idle`:return{...t,status:`idle`,data:null,error:null};default:return t}})}});s.current=()=>e()},[e(n.subcriptionKey),n.enabled]),l=t.useCallback(()=>n.enabled?{data:null,error:null,status:`connecting`,reset:c}:{data:null,error:null,status:`idle`,reset:c},[n.enabled,c]),u=t.useRef(l()),[d,f]=t.useState(r(u,o));d.reset=c;let p=t.useCallback(e=>{let t=u.current,n=u.current=e(t),i=!1;for(let e of a.current)if(t[e]!==n[e]){i=!0;break}i&&f(r(u,o))},[o]);return t.useEffect(()=>{if(n.enabled)return c(),()=>s.current()},[e(n.subcriptionKey),n.enabled]),d}function r(e,t){return new Proxy(e.current,{get(n,r){return t(r),e.current[r]}})}export{n as useSubscription};
1
+ import{hashKey as e}from"@tanstack/query-core";import*as t from"react";function n(n){let i=t.useRef(n);i.current=n;let a=t.useRef(/* @__PURE__ */ new Set),o=t.useCallback(e=>{a.current.add(e)},[]),s=t.useRef(()=>{}),c=t.useCallback(()=>{if(s.current(),p(l),!n.enabled)return;let e=n.subscriptionFn({autoReconnect:i.current.autoReconnect,keepAlive:i.current.keepAlive,onStarted:()=>{i.current.onStarted?.(),p(e=>({...e,status:`pending`,error:null}))},onData:e=>{i.current.onData?.(e),p(t=>({...t,status:`pending`,data:e,error:null}))},onError:e=>{i.current.onError?.(e),p(t=>({...t,status:`error`,error:e}))},onConnectionChange:e=>{i.current.onConnectionChange?.(e),p(t=>{switch(e.status){case`connecting`:return{...t,status:`connecting`,error:e.error??null};case`pending`:return t;case`idle`:return{...t,status:`idle`,data:null,error:null};default:return t}})}});s.current=()=>e()},[e(n.subcriptionKey),n.enabled]),l=t.useCallback(()=>n.enabled?{data:null,error:null,status:`connecting`,reset:c}:{data:null,error:null,status:`idle`,reset:c},[n.enabled,c]),u=t.useRef(l()),[d,f]=t.useState(r(u,o));d.reset=c;let p=t.useCallback(e=>{let t=u.current,n=u.current=e(t),i=!1;for(let e of a.current)if(t[e]!==n[e]){i=!0;break}i&&f(r(u,o))},[o]);return t.useEffect(()=>{if(n.enabled)return c(),()=>s.current()},[e(n.subcriptionKey),n.enabled]),d}function r(e,t){return new Proxy(e.current,{get(n,r){return t(r),e.current[r]}})}export{n as useSubscription};
@@ -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";
@@ -5,48 +6,18 @@ import { Client } from "effect/unstable/httpapi/HttpApiClient";
5
6
  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
- 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;
16
- queryOptions: Method extends 'GET' ? <TQuery = QueryOptions<UnwrapCodec<Success>, UnwrapCodec<Error>>>(input: MakeOptionalInput<([Params] extends [never] ? unknown : {
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<TQuery, 'queryKey' | 'queryFn'>) => TQuery : never;
23
- subscriptionOptions: Success extends StreamSse<SseEventFromData<infer StreamSuccess>, infer StreamError, infer _StreamValue> ? (input: MakeOptionalInput<([Params] extends [never] ? unknown : {
24
- params: UnwrapCodec<Params>;
25
- }) & ([Query] extends [never] ? unknown : {
26
- query: UnwrapCodec<Query>;
27
- }) & ([Headers] extends [never] ? unknown : {
28
- headers: UnwrapCodec<Headers>;
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>>;
37
- mutationOptions: Method extends 'GET' ? never : <TMutation = MutationOptions<UnwrapCodec<Success>, UnwrapCodec<Error>, UnwrapCodec<Payload>>>(input: MakeOptionalInput<([Params] extends [never] ? unknown : {
38
- params: UnwrapCodec<Params>;
39
- }) & ([Headers] extends [never] ? unknown : {
40
- headers: UnwrapCodec<Headers>;
41
- })>, options?: Omit<TMutation, 'mutationKey' | 'mutationFn'>) => TMutation;
42
- getQueryKey: Method extends 'GET' ? (input?: Partial<MakeOptionalInput<([Params] extends [never] ? unknown : {
43
- params: UnwrapCodec<Params>;
44
- }) & ([Query] extends [never] ? unknown : {
45
- query: UnwrapCodec<Query>;
46
- }) & ([Headers] extends [never] ? unknown : {
47
- headers: UnwrapCodec<Headers>;
48
- })>>) => QueryKey : never;
9
+ type TanstackQueryOptionsProxyInternal<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> ? {
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;
49
18
  } : T extends object ? { readonly [K in keyof T as K extends symbol ? never : K]: TanstackQueryOptionsProxy<T[K]>; } : T;
19
+ type StripNever<T> = T extends ((...args: any[]) => any) ? T : T extends object ? { [K in keyof T as [T[K]] extends [never] ? never : K]: StripNever<T[K]>; } : T;
20
+ type TanstackQueryOptionsProxy<T> = StripNever<TanstackQueryOptionsProxyInternal<T>>;
50
21
  interface SubscriptionOptions<TData, TError> {
51
22
  /**
52
23
  * Determines whether the subscription is active. If set to `false`, the subscription will not be initiated.
@@ -120,5 +91,14 @@ type UseSubscriptionReturns<TData, TError> = {
120
91
  });
121
92
  type UnwrapCodec<T> = T extends Schema<unknown> ? Schema.Type<T> : T extends object ? { [K in keyof T]: UnwrapCodec<T[K]>; } : T;
122
93
  type MakeOptionalInput<T> = keyof T extends never ? void | undefined : T;
94
+ type MakeInput<Headers, Params, Query, Payload> = MakeOptionalInput<([Headers] extends [never] ? unknown : {
95
+ headers: UnwrapCodec<Headers>;
96
+ }) & ([Params] extends [never] ? unknown : {
97
+ params: UnwrapCodec<Params>;
98
+ }) & ([Query] extends [never] ? unknown : {
99
+ query: UnwrapCodec<Query>;
100
+ }) & ([Payload] extends [never] ? unknown : {
101
+ payload: UnwrapCodec<Payload>;
102
+ })>;
123
103
  //#endregion
124
104
  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-CJQT8COr.mjs";
1
+ import { r as UseSubscriptionReturns, t as SubscriptionOptions } from "./types-BarbB5aY.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.19",
3
+ "version": "0.0.21",
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": [
@@ -59,19 +59,19 @@
59
59
  "typecheck": "tsc --noEmit"
60
60
  },
61
61
  "devDependencies": {
62
- "@types/react": "^19.2.18",
62
+ "@types/react": "^19.3.0",
63
63
  "@types/vue": "^2.0.0",
64
- "oxfmt": "^0.63.0",
65
- "oxlint": "^1.78.0",
66
- "tegami": "^1.3.5",
67
- "tsdown": "^0.22.14",
64
+ "oxfmt": "^0.68.0",
65
+ "oxlint": "^1.83.0",
66
+ "tegami": "^1.5.0",
67
+ "tsdown": "^0.23.0",
68
68
  "typescript": "^7.0.2"
69
69
  },
70
70
  "peerDependencies": {
71
- "@tanstack/query-core": ">=5.100.0",
72
- "effect": ">=4.0.0-rc.108 || >=4.0.0",
73
- "react": ">=19.2.8",
74
- "vue": ">=3.5.40"
71
+ "@tanstack/query-core": ">=5.103.0",
72
+ "effect": ">=4.0.0-rc.115",
73
+ "react": ">=19.0.0",
74
+ "vue": ">=3.0.0"
75
75
  },
76
76
  "peerDependenciesMeta": {
77
77
  "react": {
@@ -81,8 +81,8 @@
81
81
  "optional": true
82
82
  }
83
83
  },
84
- "packageManager": "bun@1.3.0",
84
+ "packageManager": "bun@1.4.0",
85
85
  "patchedDependencies": {
86
- "tegami@1.3.5": "patches/tegami@1.3.5.patch"
86
+ "tegami@1.5.0": "patches/tegami@1.5.0.patch"
87
87
  }
88
88
  }