@effect-app/vue 2.14.0 → 2.15.0
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/CHANGELOG.md +15 -0
- package/_cjs/index.cjs +0 -22
- package/_cjs/index.cjs.map +1 -1
- package/_cjs/makeClient.cjs +169 -72
- package/_cjs/makeClient.cjs.map +1 -1
- package/_cjs/mutate.cjs +84 -101
- package/_cjs/mutate.cjs.map +1 -1
- package/_cjs/query.cjs +9 -52
- package/_cjs/query.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/makeClient.d.ts +87 -70
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +164 -84
- package/dist/mutate.d.ts +18 -26
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +67 -84
- package/dist/query.d.ts +10 -24
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +13 -55
- package/package.json +8 -48
- package/src/index.ts +0 -2
- package/src/makeClient.ts +463 -227
- package/src/mutate.ts +111 -141
- package/src/query.ts +30 -116
- package/_cjs/hooks.cjs +0 -28
- package/_cjs/hooks.cjs.map +0 -1
- package/_cjs/makeClient2.cjs +0 -221
- package/_cjs/makeClient2.cjs.map +0 -1
- package/_cjs/mutate2.cjs +0 -118
- package/_cjs/mutate2.cjs.map +0 -1
- package/_cjs/query2.cjs +0 -105
- package/_cjs/query2.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -3
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js +0 -4
- package/dist/makeClient2.d.ts +0 -74
- package/dist/makeClient2.d.ts.map +0 -1
- package/dist/makeClient2.js +0 -187
- package/dist/mutate2.d.ts +0 -42
- package/dist/mutate2.d.ts.map +0 -1
- package/dist/mutate2.js +0 -88
- package/dist/query2.d.ts +0 -23
- package/dist/query2.d.ts.map +0 -1
- package/dist/query2.js +0 -97
- package/src/hooks.ts +0 -4
- package/src/makeClient2.ts +0 -353
- package/src/mutate2.ts +0 -197
- package/src/query2.ts +0 -205
package/src/query2.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
import * as Result from "@effect-rx/rx/Result"
|
|
6
|
-
import type {
|
|
7
|
-
InitialDataFunction,
|
|
8
|
-
QueryKey,
|
|
9
|
-
QueryObserverOptions,
|
|
10
|
-
QueryObserverResult,
|
|
11
|
-
RefetchOptions,
|
|
12
|
-
UseQueryReturnType
|
|
13
|
-
} from "@tanstack/vue-query"
|
|
14
|
-
import { useQuery } from "@tanstack/vue-query"
|
|
15
|
-
import { Cause, Effect, Option, Runtime, S } from "effect-app"
|
|
16
|
-
import { ServiceUnavailableError } from "effect-app/client"
|
|
17
|
-
import type { RequestHandler, RequestHandlerWithInput, TaggedRequestClassAny } from "effect-app/client/clientFor"
|
|
18
|
-
import { isHttpRequestError, isHttpResponseError } from "effect-app/http/http-client"
|
|
19
|
-
import { computed, ref } from "vue"
|
|
20
|
-
import type { ComputedRef, ShallowRef, WatchSource } from "vue"
|
|
21
|
-
import { getRuntime, makeQueryKey, reportRuntimeError } from "./lib.js"
|
|
22
|
-
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
24
|
-
export interface QueryObserverOptionsCustom<
|
|
25
|
-
TQueryFnData = unknown,
|
|
26
|
-
TError = Error,
|
|
27
|
-
TData = TQueryFnData,
|
|
28
|
-
TQueryData = TQueryFnData,
|
|
29
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
30
|
-
TPageParam = never
|
|
31
|
-
> extends
|
|
32
|
-
Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, "queryKey" | "queryFn">
|
|
33
|
-
{}
|
|
34
|
-
|
|
35
|
-
export interface KnownFiberFailure<E> extends Runtime.FiberFailure {
|
|
36
|
-
readonly [Runtime.FiberFailureCauseId]: Cause.Cause<E>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const makeQuery2 = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>) => {
|
|
40
|
-
// TODO: options
|
|
41
|
-
// declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryReturnType<TData, TError>;
|
|
42
|
-
// declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryDefinedReturnType<TData, TError>;
|
|
43
|
-
// declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, queryClient?: QueryClient): UseQueryReturnType<TData, TError>;
|
|
44
|
-
const useSafeQuery_ = <I, A, E, Request extends TaggedRequestClassAny>(
|
|
45
|
-
q:
|
|
46
|
-
| RequestHandlerWithInput<I, A, E, R, Request>
|
|
47
|
-
| RequestHandler<A, E, R, Request>,
|
|
48
|
-
arg?: I | WatchSource<I>,
|
|
49
|
-
options: QueryObserverOptionsCustom<unknown, KnownFiberFailure<E>, A> = {} // TODO
|
|
50
|
-
) => {
|
|
51
|
-
const runPromise = Runtime.runPromise(getRuntime(runtime))
|
|
52
|
-
const arr = arg
|
|
53
|
-
const req: { value: I } = !arg
|
|
54
|
-
? undefined
|
|
55
|
-
: typeof arr === "function"
|
|
56
|
-
? ({
|
|
57
|
-
get value() {
|
|
58
|
-
return (arr as any)()
|
|
59
|
-
}
|
|
60
|
-
} as any)
|
|
61
|
-
: ref(arg)
|
|
62
|
-
const queryKey = makeQueryKey(q)
|
|
63
|
-
const handler = q.handler
|
|
64
|
-
const r = useQuery<unknown, KnownFiberFailure<E>, A>(
|
|
65
|
-
Effect.isEffect(handler)
|
|
66
|
-
? {
|
|
67
|
-
...options,
|
|
68
|
-
retry: (retryCount, error) => {
|
|
69
|
-
if (Runtime.isFiberFailure(error)) {
|
|
70
|
-
const cause = error[Runtime.FiberFailureCauseId]
|
|
71
|
-
const sq = Cause.squash(cause)
|
|
72
|
-
if (!isHttpRequestError(sq) && !isHttpResponseError(sq) && !S.is(ServiceUnavailableError)(sq)) {
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return retryCount < 5
|
|
78
|
-
},
|
|
79
|
-
queryKey,
|
|
80
|
-
queryFn: ({ signal }) =>
|
|
81
|
-
runPromise(
|
|
82
|
-
handler
|
|
83
|
-
.pipe(
|
|
84
|
-
Effect.tapDefect(reportRuntimeError),
|
|
85
|
-
Effect.withSpan(`query ${q.name}`, { captureStackTrace: false })
|
|
86
|
-
),
|
|
87
|
-
{ signal }
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
: {
|
|
91
|
-
...options,
|
|
92
|
-
retry: (retryCount, error) => {
|
|
93
|
-
if (Runtime.isFiberFailure(error)) {
|
|
94
|
-
const cause = error[Runtime.FiberFailureCauseId]
|
|
95
|
-
const sq = Cause.squash(cause)
|
|
96
|
-
if (!isHttpRequestError(sq) && !isHttpResponseError(sq) && !S.is(ServiceUnavailableError)(sq)) {
|
|
97
|
-
return false
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return retryCount < 5
|
|
102
|
-
},
|
|
103
|
-
queryKey: [...queryKey, req],
|
|
104
|
-
queryFn: ({ signal }) =>
|
|
105
|
-
runPromise(
|
|
106
|
-
handler(req.value)
|
|
107
|
-
.pipe(
|
|
108
|
-
Effect.tapDefect(reportRuntimeError),
|
|
109
|
-
Effect.withSpan(`query ${q.name}`, { captureStackTrace: false })
|
|
110
|
-
),
|
|
111
|
-
{ signal }
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
const result = computed(() =>
|
|
117
|
-
swrToQuery({
|
|
118
|
-
error: r.error.value ?? undefined,
|
|
119
|
-
data: r.data.value,
|
|
120
|
-
isValidating: r.isFetching.value
|
|
121
|
-
})
|
|
122
|
-
)
|
|
123
|
-
const latestSuccess = computed(() => Option.getOrUndefined(Result.value(result.value)))
|
|
124
|
-
return [
|
|
125
|
-
result,
|
|
126
|
-
latestSuccess,
|
|
127
|
-
// one thing to keep in mind is that span will be disconnected as Context does not pass from outside.
|
|
128
|
-
// TODO: consider how we should handle the Result here which is `QueryObserverResult<A, KnownFiberFailure<E>>`
|
|
129
|
-
// and always ends up in the success channel, even when error..
|
|
130
|
-
(options?: RefetchOptions) => Effect.promise(() => r.refetch(options)),
|
|
131
|
-
r
|
|
132
|
-
] as const
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function swrToQuery<E, A>(r: {
|
|
136
|
-
error: KnownFiberFailure<E> | undefined
|
|
137
|
-
data: A | undefined
|
|
138
|
-
isValidating: boolean
|
|
139
|
-
}): Result.Result<A, E> {
|
|
140
|
-
if (r.error) {
|
|
141
|
-
return Result.failureWithPrevious(
|
|
142
|
-
r.error[Runtime.FiberFailureCauseId],
|
|
143
|
-
r.data === undefined ? Option.none() : Option.some(Result.success(r.data)),
|
|
144
|
-
r.isValidating
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
if (r.data !== undefined) {
|
|
148
|
-
return Result.success<A, E>(r.data, r.isValidating)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return Result.initial(r.isValidating)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function useSafeQuery<E, A, Request extends TaggedRequestClassAny>(
|
|
155
|
-
self: RequestHandler<A, E, R, Request>,
|
|
156
|
-
options?: QueryObserverOptionsCustom<A, E> & { initialData: A | InitialDataFunction<A> }
|
|
157
|
-
): readonly [
|
|
158
|
-
ComputedRef<Result.Result<A, E>>,
|
|
159
|
-
ComputedRef<A>,
|
|
160
|
-
(options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
|
|
161
|
-
UseQueryReturnType<any, any>
|
|
162
|
-
]
|
|
163
|
-
function useSafeQuery<Arg, E, A, Request extends TaggedRequestClassAny>(
|
|
164
|
-
self: RequestHandlerWithInput<Arg, A, E, R, Request>,
|
|
165
|
-
arg: Arg | WatchSource<Arg>,
|
|
166
|
-
options?: QueryObserverOptionsCustom<A, E> & { initialData: A | InitialDataFunction<A> }
|
|
167
|
-
): readonly [
|
|
168
|
-
ComputedRef<Result.Result<A, E>>,
|
|
169
|
-
ComputedRef<A>,
|
|
170
|
-
(options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
|
|
171
|
-
UseQueryReturnType<any, any>
|
|
172
|
-
]
|
|
173
|
-
function useSafeQuery<E, A, Request extends TaggedRequestClassAny>(
|
|
174
|
-
self: RequestHandler<A, E, R, Request>,
|
|
175
|
-
options?: QueryObserverOptionsCustom<A, E>
|
|
176
|
-
): readonly [
|
|
177
|
-
ComputedRef<Result.Result<A, E>>,
|
|
178
|
-
ComputedRef<A | undefined>,
|
|
179
|
-
(options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
|
|
180
|
-
UseQueryReturnType<any, any>
|
|
181
|
-
]
|
|
182
|
-
function useSafeQuery<Arg, E, A, Request extends TaggedRequestClassAny>(
|
|
183
|
-
self: RequestHandlerWithInput<Arg, A, E, R, Request>,
|
|
184
|
-
arg: Arg | WatchSource<Arg>,
|
|
185
|
-
options?: QueryObserverOptionsCustom<A, E>
|
|
186
|
-
): readonly [
|
|
187
|
-
ComputedRef<Result.Result<A, E>>,
|
|
188
|
-
ComputedRef<A | undefined>,
|
|
189
|
-
(options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
|
|
190
|
-
UseQueryReturnType<any, any>
|
|
191
|
-
]
|
|
192
|
-
function useSafeQuery(
|
|
193
|
-
self: any,
|
|
194
|
-
argOrOptions?: any,
|
|
195
|
-
options?: any
|
|
196
|
-
) {
|
|
197
|
-
return Effect.isEffect(self.handler)
|
|
198
|
-
? useSafeQuery_(self, undefined, argOrOptions)
|
|
199
|
-
: useSafeQuery_(self, argOrOptions, options)
|
|
200
|
-
}
|
|
201
|
-
return useSafeQuery
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
205
|
-
export interface MakeQuery2<R> extends ReturnType<typeof makeQuery2<R>> {}
|