@effect-app/vue 4.0.0-beta.194 → 4.0.0-beta.196
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 +14 -0
- package/dist/commander.d.ts +9 -1
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +1 -1
- package/dist/lib.d.ts +2 -3
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +2 -4
- package/dist/makeClient.d.ts +39 -126
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +25 -36
- package/dist/mutate.d.ts +12 -25
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +20 -28
- package/dist/query.d.ts +9 -37
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +23 -49
- package/package.json +2 -2
- package/src/commander.ts +13 -0
- package/src/lib.ts +2 -8
- package/src/makeClient.ts +80 -244
- package/src/mutate.ts +38 -101
- package/src/query.ts +47 -146
- package/test/dist/stubs.d.ts +28 -304
- package/test/dist/stubs.d.ts.map +1 -1
- package/test/makeClient.test.ts +12 -6
package/src/mutate.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { matchQuery } from "@tanstack/query-core"
|
|
|
3
3
|
import { type InvalidateOptions, type InvalidateQueryFilters, type QueryClient, useQueryClient } from "@tanstack/vue-query"
|
|
4
4
|
import { type Cause, Effect, Exit, Option } from "effect-app"
|
|
5
5
|
import { type InvalidationKey, InvalidationKeysFromServer, makeInvalidationKeysService, makeQueryKey, type Req } from "effect-app/client"
|
|
6
|
-
import type { ClientForOptions,
|
|
6
|
+
import type { ClientForOptions, RequestHandlerWithInput } from "effect-app/client/clientFor"
|
|
7
7
|
import { tuple } from "effect-app/Function"
|
|
8
8
|
import * as Ref from "effect/Ref"
|
|
9
9
|
import * as Stream from "effect/Stream"
|
|
@@ -96,44 +96,27 @@ export interface MutationOptionsBase<A = unknown, B = A, E2 = never, R2 = never>
|
|
|
96
96
|
select?: (result: A) => Effect.Effect<B, E2, R2>
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export const asResult
|
|
100
|
-
<A, E, R>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
): readonly [ComputedRef<AsyncResult.AsyncResult<A, E>>, (...args: Args) => Effect.Effect<Exit.Exit<A, E>, never, R>]
|
|
106
|
-
} = <Args extends readonly any[], A, E, R>(
|
|
107
|
-
handler: Effect.Effect<A, E, R> | ((...args: Args) => Effect.Effect<A, E, R>)
|
|
108
|
-
) => {
|
|
99
|
+
export const asResult = <Args extends readonly any[], A, E, R>(
|
|
100
|
+
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
101
|
+
): readonly [
|
|
102
|
+
ComputedRef<AsyncResult.AsyncResult<A, E>>,
|
|
103
|
+
(...args: Args) => Effect.Effect<Exit.Exit<A, E>, never, R>
|
|
104
|
+
] => {
|
|
109
105
|
const state = shallowRef<AsyncResult.AsyncResult<A, E>>(AsyncResult.initial())
|
|
110
106
|
|
|
111
|
-
const act =
|
|
112
|
-
|
|
107
|
+
const act = (...args: Args) =>
|
|
108
|
+
Effect
|
|
113
109
|
.sync(() => {
|
|
114
110
|
state.value = AsyncResult.initial(true)
|
|
115
111
|
})
|
|
116
112
|
.pipe(
|
|
117
113
|
Effect.andThen(Effect.suspend(() =>
|
|
118
|
-
handler.pipe(
|
|
114
|
+
handler(...args).pipe(
|
|
119
115
|
Effect.exit,
|
|
120
116
|
Effect.tap((exit) => Effect.sync(() => (state.value = AsyncResult.fromExit(exit))))
|
|
121
117
|
)
|
|
122
118
|
))
|
|
123
119
|
)
|
|
124
|
-
: (...args: Args) =>
|
|
125
|
-
Effect
|
|
126
|
-
.sync(() => {
|
|
127
|
-
state.value = AsyncResult.initial(true)
|
|
128
|
-
})
|
|
129
|
-
.pipe(
|
|
130
|
-
Effect.andThen(Effect.suspend(() =>
|
|
131
|
-
handler(...args).pipe(
|
|
132
|
-
Effect.exit,
|
|
133
|
-
Effect.tap((exit) => Effect.sync(() => (state.value = AsyncResult.fromExit(exit))))
|
|
134
|
-
)
|
|
135
|
-
))
|
|
136
|
-
)
|
|
137
120
|
|
|
138
121
|
return tuple(computed(() => state.value), act) as any
|
|
139
122
|
}
|
|
@@ -143,16 +126,9 @@ export const asResult: {
|
|
|
143
126
|
* (keeping `waiting: true`) and is finalised (with `waiting: false`) once the
|
|
144
127
|
* stream terminates successfully. Errors are surfaced as `AsyncResult.failure`.
|
|
145
128
|
*/
|
|
146
|
-
export const asStreamResult
|
|
147
|
-
<A, E, R>
|
|
148
|
-
|
|
149
|
-
): readonly [ComputedRef<AsyncResult.AsyncResult<A, E>>, Effect.Effect<void, never, R>]
|
|
150
|
-
<Args extends readonly any[], A, E, R>(
|
|
151
|
-
handler: (...args: Args) => Stream.Stream<A, E, R>
|
|
152
|
-
): readonly [ComputedRef<AsyncResult.AsyncResult<A, E>>, (...args: Args) => Effect.Effect<void, never, R>]
|
|
153
|
-
} = <Args extends readonly any[], A, E, R>(
|
|
154
|
-
handler: Stream.Stream<A, E, R> | ((...args: Args) => Stream.Stream<A, E, R>)
|
|
155
|
-
) => {
|
|
129
|
+
export const asStreamResult = <Args extends readonly any[], A, E, R>(
|
|
130
|
+
handler: (...args: Args) => Stream.Stream<A, E, R>
|
|
131
|
+
): readonly [ComputedRef<AsyncResult.AsyncResult<A, E>>, (...args: Args) => Effect.Effect<void, never, R>] => {
|
|
156
132
|
const state = shallowRef<AsyncResult.AsyncResult<A, E>>(AsyncResult.initial())
|
|
157
133
|
|
|
158
134
|
const runStream = (stream: Stream.Stream<A, E, R>): Effect.Effect<void, never, R> =>
|
|
@@ -187,9 +163,7 @@ export const asStreamResult: {
|
|
|
187
163
|
)
|
|
188
164
|
)
|
|
189
165
|
|
|
190
|
-
const act =
|
|
191
|
-
? runStream(handler)
|
|
192
|
-
: (...args: Args) => runStream(handler(...args))
|
|
166
|
+
const act = (...args: Args) => runStream(handler(...args))
|
|
193
167
|
|
|
194
168
|
return tuple(computed(() => state.value), act) as any
|
|
195
169
|
}
|
|
@@ -336,7 +310,10 @@ export const invalidateQueries = (
|
|
|
336
310
|
return handle
|
|
337
311
|
}
|
|
338
312
|
|
|
339
|
-
|
|
313
|
+
/**
|
|
314
|
+
* A callable mutation result. When `I = void` the input argument may be omitted.
|
|
315
|
+
*/
|
|
316
|
+
export interface MutationFn<I, A, E, R, Id extends string> {
|
|
340
317
|
<B = A, E2 = never, R2 = never>(
|
|
341
318
|
input: I,
|
|
342
319
|
options?: MutationOptionsBase<A, B, E2, R2>
|
|
@@ -344,38 +321,17 @@ export interface MutationFnWithInput<I, A, E, R, Id extends string> {
|
|
|
344
321
|
readonly id: Id
|
|
345
322
|
}
|
|
346
323
|
|
|
347
|
-
export interface MutationFn<A, E, R, Id extends string> {
|
|
348
|
-
<B = A, E2 = never, R2 = never>(
|
|
349
|
-
options?: MutationOptionsBase<A, B, E2, R2>
|
|
350
|
-
): Effect.Effect<B, E | E2, R | R2>
|
|
351
|
-
readonly id: Id
|
|
352
|
-
}
|
|
353
|
-
|
|
354
324
|
export const makeMutation = () => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Pass an Effect, e.g from a client action
|
|
365
|
-
* Executes query cache invalidation based on default rules or provided option.
|
|
366
|
-
*/
|
|
367
|
-
<E, A, R, Request extends Req, Id extends string>(
|
|
368
|
-
self: RequestHandler<A, E, R, Request, Id>
|
|
369
|
-
): MutationFn<A, E, R, Id>
|
|
370
|
-
} = <I, E, A, R, Request extends Req, Id extends string>(
|
|
371
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>
|
|
372
|
-
) => {
|
|
325
|
+
/**
|
|
326
|
+
* Pass a function that returns an Effect, e.g from a client action.
|
|
327
|
+
* Executes query cache invalidation based on default rules or provided option.
|
|
328
|
+
* When `I = void` the input argument may be omitted.
|
|
329
|
+
*/
|
|
330
|
+
const useMutation = <I, E, A, R, Request extends Req, Id extends string>(
|
|
331
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Id>
|
|
332
|
+
): MutationFn<I, A, E, R, Id> => {
|
|
373
333
|
const queryClient = useQueryClient()
|
|
374
|
-
const
|
|
375
|
-
const r = Effect.isEffect(handler)
|
|
376
|
-
? (options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler)
|
|
377
|
-
: (i: I, options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler(i), i)
|
|
378
|
-
|
|
334
|
+
const r = (i: I, options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(self.handler(i), i)
|
|
379
335
|
return Object.assign(r, { id: self.id }) as any
|
|
380
336
|
}
|
|
381
337
|
return useMutation
|
|
@@ -385,29 +341,15 @@ export const makeMutation = () => {
|
|
|
385
341
|
export const useMakeMutation = () => {
|
|
386
342
|
const queryClient = useQueryClient()
|
|
387
343
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
* Pass an Effect, e.g from a client action
|
|
398
|
-
* Executes query cache invalidation based on default rules or provided option.
|
|
399
|
-
*/
|
|
400
|
-
<E, A, R, Request extends Req, Id extends string>(
|
|
401
|
-
self: RequestHandler<A, E, R, Request, Id>
|
|
402
|
-
): MutationFn<A, E, R, Id>
|
|
403
|
-
} = <I, E, A, R, Request extends Req, Id extends string>(
|
|
404
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>
|
|
405
|
-
) => {
|
|
406
|
-
const handler = self.handler
|
|
407
|
-
const r = Effect.isEffect(handler)
|
|
408
|
-
? (options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler)
|
|
409
|
-
: (i: I, options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler(i), i)
|
|
410
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Pass a function that returns an Effect, e.g from a client action.
|
|
346
|
+
* Executes query cache invalidation based on default rules or provided option.
|
|
347
|
+
* When `I = void` the input argument may be omitted.
|
|
348
|
+
*/
|
|
349
|
+
const useMutation = <I, E, A, R, Request extends Req, Id extends string>(
|
|
350
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Id>
|
|
351
|
+
): MutationFn<I, A, E, R, Id> => {
|
|
352
|
+
const r = (i: I, options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(self.handler(i), i)
|
|
411
353
|
return Object.assign(r, { id: self.id }) as any
|
|
412
354
|
}
|
|
413
355
|
return useMutation
|
|
@@ -430,7 +372,7 @@ export const makeStreamMutation2 = () => {
|
|
|
430
372
|
self: {
|
|
431
373
|
id: string
|
|
432
374
|
options?: ClientForOptions
|
|
433
|
-
handler:
|
|
375
|
+
handler: (i: any) => Stream.Stream<any, any, any>
|
|
434
376
|
},
|
|
435
377
|
mergedInvalidation?: MutationOptionsBase["queryInvalidation"]
|
|
436
378
|
) => {
|
|
@@ -454,11 +396,6 @@ export const makeStreamMutation2 = () => {
|
|
|
454
396
|
)
|
|
455
397
|
})
|
|
456
398
|
|
|
457
|
-
|
|
458
|
-
const act = Stream.isStream(handler)
|
|
459
|
-
? Stream.unwrap(makeInvocationEffect(undefined, handler))
|
|
460
|
-
: (i: any) => Stream.unwrap(makeInvocationEffect(i, (handler as (i: any) => Stream.Stream<any, any, any>)(i)))
|
|
461
|
-
|
|
462
|
-
return act
|
|
399
|
+
return (i: any) => Stream.unwrap(makeInvocationEffect(i, self.handler(i)))
|
|
463
400
|
}
|
|
464
401
|
}
|
package/src/query.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { type DefaultError, type Enabled, experimental_streamedQuery as streamedQuery, type InitialDataFunction, type NonUndefinedGuard, type PlaceholderDataFunction, type QueryKey, type QueryObserverOptions, type QueryObserverResult, type RefetchOptions, useQuery as useTanstackQuery, useQueryClient, type UseQueryDefinedReturnType, type UseQueryReturnType } from "@tanstack/vue-query"
|
|
7
7
|
import { Array, Cause, type Context, Effect, Exit, Option, S } from "effect-app"
|
|
8
8
|
import { makeQueryKey, type Req } from "effect-app/client"
|
|
9
|
-
import type {
|
|
9
|
+
import type { RequestHandlerWithInput, RequestStreamHandlerWithInput } from "effect-app/client/clientFor"
|
|
10
10
|
import { CauseException, ServiceUnavailableError } from "effect-app/client/errors"
|
|
11
11
|
import * as Channel from "effect/Channel"
|
|
12
12
|
import * as Pull from "effect/Pull"
|
|
@@ -141,9 +141,7 @@ function streamToAsyncIterableWithCauseException<A, E, R>(
|
|
|
141
141
|
export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
142
142
|
const useQuery_: {
|
|
143
143
|
<I, A, E, Request extends Req, Name extends string>(
|
|
144
|
-
q:
|
|
145
|
-
| RequestHandlerWithInput<I, A, E, R, Request, Name>
|
|
146
|
-
| RequestHandler<A, E, R, Request, Name>
|
|
144
|
+
q: RequestHandlerWithInput<I, A, E, R, Request, Name>
|
|
147
145
|
): {
|
|
148
146
|
<TData = A>(
|
|
149
147
|
arg: I | WatchSource<I> | undefined,
|
|
@@ -176,9 +174,7 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
176
174
|
]
|
|
177
175
|
}
|
|
178
176
|
} = <I, A, E, Request extends Req, Name extends string>(
|
|
179
|
-
q:
|
|
180
|
-
| RequestHandlerWithInput<I, A, E, R, Request, Name>
|
|
181
|
-
| RequestHandler<A, E, R, Request, Name>
|
|
177
|
+
q: RequestHandlerWithInput<I, A, E, R, Request, Name>
|
|
182
178
|
) =>
|
|
183
179
|
<TData = A>(
|
|
184
180
|
arg: I | WatchSource<I> | undefined,
|
|
@@ -189,19 +185,17 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
189
185
|
// we wrap into CauseException because we want to keep the full cause of the failure.
|
|
190
186
|
const runPromise = makeRunPromise(getRuntime())
|
|
191
187
|
const arr = arg
|
|
192
|
-
const req: { value: I } = !arg
|
|
193
|
-
? undefined
|
|
188
|
+
const req: { value: I } | undefined = !arg
|
|
189
|
+
? undefined
|
|
194
190
|
: typeof arr === "function"
|
|
195
191
|
? ({
|
|
196
192
|
get value() {
|
|
197
193
|
return (arr as any)()
|
|
198
194
|
}
|
|
199
195
|
})
|
|
200
|
-
: ref(arg)
|
|
196
|
+
: ref(arg) as any
|
|
201
197
|
const queryKey = makeQueryKey(q)
|
|
202
198
|
const projectionHash = (q as { queryKeyProjectionHash?: string }).queryKeyProjectionHash
|
|
203
|
-
const baseQueryKey = projectionHash === undefined ? queryKey : [...queryKey, projectionHash]
|
|
204
|
-
const handler = q.handler
|
|
205
199
|
|
|
206
200
|
const defaultOptions = {
|
|
207
201
|
// we do not want to throw errors, because we turn the success and error responses into a Result type
|
|
@@ -213,57 +207,31 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
213
207
|
throwOnError: false
|
|
214
208
|
}
|
|
215
209
|
|
|
216
|
-
const r = useTanstackQuery<A, CauseException<E>, TData>(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return false
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return retryCount < 5
|
|
229
|
-
},
|
|
230
|
-
queryKey: baseQueryKey,
|
|
231
|
-
queryFn: ({ meta, signal }) =>
|
|
232
|
-
runPromise(
|
|
233
|
-
handler
|
|
234
|
-
.pipe(
|
|
235
|
-
Effect.tapCauseIf(Cause.hasDies, (cause) => reportRuntimeError(cause)),
|
|
236
|
-
Effect.withSpan(`query ${q.id}`, {}, { captureStackTrace: false }),
|
|
237
|
-
meta?.["span"] ? Effect.withParentSpan(meta["span"] as Span) : (_) => _
|
|
238
|
-
),
|
|
239
|
-
{ signal }
|
|
240
|
-
)
|
|
210
|
+
const r = useTanstackQuery<A, CauseException<E>, TData>({
|
|
211
|
+
...defaultOptions,
|
|
212
|
+
...options,
|
|
213
|
+
retry: (retryCount, error) => {
|
|
214
|
+
if (error instanceof CauseException) {
|
|
215
|
+
if (!isHttpClientError(error.cause) && !S.is(ServiceUnavailableError)(error.cause)) {
|
|
216
|
+
return false
|
|
217
|
+
}
|
|
241
218
|
}
|
|
242
|
-
: {
|
|
243
|
-
...defaultOptions,
|
|
244
|
-
...options,
|
|
245
|
-
retry: (retryCount, error) => {
|
|
246
|
-
if (error instanceof CauseException) {
|
|
247
|
-
if (!isHttpClientError(error.cause) && !S.is(ServiceUnavailableError)(error.cause)) {
|
|
248
|
-
return false
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
219
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
)
|
|
220
|
+
return retryCount < 5
|
|
221
|
+
},
|
|
222
|
+
queryKey: projectionHash === undefined ? [...queryKey, req] : [...queryKey, req, projectionHash],
|
|
223
|
+
queryFn: ({ meta, signal }) =>
|
|
224
|
+
runPromise(
|
|
225
|
+
q
|
|
226
|
+
.handler(req?.value as I)
|
|
227
|
+
.pipe(
|
|
228
|
+
Effect.tapCauseIf(Cause.hasDies, (cause) => reportRuntimeError(cause)),
|
|
229
|
+
Effect.withSpan(`query ${q.id}`, {}, { captureStackTrace: false }),
|
|
230
|
+
meta?.["span"] ? Effect.withParentSpan(meta["span"] as Span) : (_) => _
|
|
231
|
+
),
|
|
232
|
+
{ signal }
|
|
233
|
+
)
|
|
234
|
+
})
|
|
267
235
|
|
|
268
236
|
const latestSuccess = shallowRef<TData>()
|
|
269
237
|
const result = computed((): AsyncResult.AsyncResult<TData, E> =>
|
|
@@ -294,55 +262,14 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
294
262
|
const useQuery: {
|
|
295
263
|
/**
|
|
296
264
|
* Effect results are passed to the caller, including errors.
|
|
265
|
+
* When `I = void` the input argument may be omitted.
|
|
297
266
|
* @deprecated use client helpers instead (.query())
|
|
298
267
|
*/
|
|
299
|
-
<E, A, Request extends Req, Name extends string>(
|
|
300
|
-
self:
|
|
301
|
-
): {
|
|
302
|
-
// required options, with initialData
|
|
303
|
-
/**
|
|
304
|
-
* Effect results are passed to the caller, including errors.
|
|
305
|
-
*/
|
|
306
|
-
<TData = A>(
|
|
307
|
-
options: CustomDefinedInitialQueryOptions<A, CauseException<E>, TData>
|
|
308
|
-
): readonly [
|
|
309
|
-
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
310
|
-
ComputedRef<TData>,
|
|
311
|
-
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, CauseException<E>>>,
|
|
312
|
-
UseQueryReturnType<any, any>
|
|
313
|
-
]
|
|
314
|
-
<TData = A>(
|
|
315
|
-
options: CustomDefinedPlaceholderQueryOptions<A, E, TData>
|
|
316
|
-
): readonly [
|
|
317
|
-
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
318
|
-
ComputedRef<TData>,
|
|
319
|
-
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, CauseException<E>>>,
|
|
320
|
-
UseQueryDefinedReturnType<TData, CauseException<E>>
|
|
321
|
-
]
|
|
322
|
-
// optional options, optional A
|
|
323
|
-
/**
|
|
324
|
-
* Effect results are passed to the caller, including errors.
|
|
325
|
-
*/
|
|
326
|
-
<TData = A>(options?: CustomUndefinedInitialQueryOptions<A, CauseException<E>, TData>): readonly [
|
|
327
|
-
ComputedRef<AsyncResult.AsyncResult<A, E>>,
|
|
328
|
-
ComputedRef<A | undefined>,
|
|
329
|
-
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, CauseException<E>>>,
|
|
330
|
-
UseQueryReturnType<any, any>
|
|
331
|
-
]
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Effect results are passed to the caller, including errors.
|
|
335
|
-
* @deprecated use client helpers instead (.query())
|
|
336
|
-
*/
|
|
337
|
-
<Arg, E, A, Request extends Req, Name extends string>(
|
|
338
|
-
self: RequestHandlerWithInput<Arg, A, E, R, Request, Name>
|
|
268
|
+
<I, E, A, Request extends Req, Name extends string>(
|
|
269
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Name>
|
|
339
270
|
): {
|
|
340
|
-
// required options, with initialData
|
|
341
|
-
/**
|
|
342
|
-
* Effect results are passed to the caller, including errors.
|
|
343
|
-
*/
|
|
344
271
|
<TData = A>(
|
|
345
|
-
arg:
|
|
272
|
+
arg: I | WatchSource<I>,
|
|
346
273
|
options: CustomDefinedInitialQueryOptions<A, CauseException<E>, TData>
|
|
347
274
|
): readonly [
|
|
348
275
|
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
@@ -350,12 +277,8 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
350
277
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, CauseException<E>>>,
|
|
351
278
|
UseQueryReturnType<any, any>
|
|
352
279
|
]
|
|
353
|
-
// required options, with placeholderData
|
|
354
|
-
/**
|
|
355
|
-
* Effect results are passed to the caller, including errors.
|
|
356
|
-
*/
|
|
357
280
|
<TData = A>(
|
|
358
|
-
arg:
|
|
281
|
+
arg: I | WatchSource<I>,
|
|
359
282
|
options: CustomDefinedPlaceholderQueryOptions<A, CauseException<E>, TData>
|
|
360
283
|
): readonly [
|
|
361
284
|
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
@@ -363,12 +286,8 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
363
286
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, CauseException<E>>>,
|
|
364
287
|
UseQueryReturnType<any, any>
|
|
365
288
|
]
|
|
366
|
-
// optional options, optional A
|
|
367
|
-
/**
|
|
368
|
-
* Effect results are passed to the caller, including errors.
|
|
369
|
-
*/
|
|
370
289
|
<TData = A>(
|
|
371
|
-
arg:
|
|
290
|
+
arg: I | WatchSource<I>,
|
|
372
291
|
options?: CustomUndefinedInitialQueryOptions<A, CauseException<E>, TData>
|
|
373
292
|
): readonly [
|
|
374
293
|
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
@@ -377,16 +296,12 @@ export const makeQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
377
296
|
UseQueryReturnType<any, any>
|
|
378
297
|
]
|
|
379
298
|
}
|
|
380
|
-
} = (
|
|
299
|
+
} = ((
|
|
381
300
|
self: any
|
|
382
301
|
) => {
|
|
383
302
|
const q = useQuery_(self)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
Effect.isEffect(self.handler)
|
|
387
|
-
? q(undefined, argOrOptions)
|
|
388
|
-
: q(argOrOptions, options)
|
|
389
|
-
}
|
|
303
|
+
return (arg?: any, options?: any) => q(arg, options)
|
|
304
|
+
}) as any
|
|
390
305
|
return useQuery
|
|
391
306
|
}
|
|
392
307
|
|
|
@@ -402,17 +317,14 @@ type StreamQueryResult<A, E> = readonly [
|
|
|
402
317
|
|
|
403
318
|
export const makeStreamQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
404
319
|
const streamQuery_: {
|
|
405
|
-
<E, A, Request extends Req, Name extends string>(
|
|
406
|
-
q:
|
|
407
|
-
): () => StreamQueryResult<A, E>
|
|
408
|
-
<Arg, E, A, Request extends Req, Name extends string>(
|
|
409
|
-
q: RequestStreamHandlerWithInput<Arg, A, E, R, Request, Name>
|
|
410
|
-
): (arg: Arg | WatchSource<Arg>) => StreamQueryResult<A, E>
|
|
320
|
+
<I, E, A, Request extends Req, Name extends string>(
|
|
321
|
+
q: RequestStreamHandlerWithInput<I, A, E, R, Request, Name>
|
|
322
|
+
): (arg: I | WatchSource<I>) => StreamQueryResult<A, E>
|
|
411
323
|
} = (q: any) => (arg?: any) => {
|
|
412
324
|
const context = getRuntime()
|
|
413
325
|
const arr = arg
|
|
414
|
-
const req: { value: any } = !arg
|
|
415
|
-
? undefined
|
|
326
|
+
const req: { value: any } | undefined = !arg
|
|
327
|
+
? undefined
|
|
416
328
|
: typeof arr === "function"
|
|
417
329
|
? ({
|
|
418
330
|
get value() {
|
|
@@ -421,8 +333,6 @@ export const makeStreamQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
421
333
|
})
|
|
422
334
|
: ref(arg)
|
|
423
335
|
const queryKey = makeQueryKey(q)
|
|
424
|
-
const handler = q.handler
|
|
425
|
-
const isWithInput = typeof handler === "function"
|
|
426
336
|
|
|
427
337
|
const r = useTanstackQuery<any[], CauseException<any>, any[]>(
|
|
428
338
|
{
|
|
@@ -435,12 +345,10 @@ export const makeStreamQuery = <R>(getRuntime: () => Context.Context<R>) => {
|
|
|
435
345
|
}
|
|
436
346
|
return retryCount < 5
|
|
437
347
|
},
|
|
438
|
-
queryKey:
|
|
348
|
+
queryKey: [...queryKey, req],
|
|
439
349
|
queryFn: streamedQuery({
|
|
440
350
|
streamFn: () => {
|
|
441
|
-
const stream =
|
|
442
|
-
? handler(req.value)
|
|
443
|
-
: handler
|
|
351
|
+
const stream = q.handler(req?.value)
|
|
444
352
|
return streamToAsyncIterableWithCauseException(stream, context, q.id)
|
|
445
353
|
}
|
|
446
354
|
})
|
|
@@ -525,20 +433,13 @@ export const useUpdateQuery = () => {
|
|
|
525
433
|
const queryClient = useQueryClient()
|
|
526
434
|
|
|
527
435
|
const f: {
|
|
528
|
-
<A>(
|
|
529
|
-
query: RequestHandler<A, any, any, any, any>,
|
|
530
|
-
updater: (data: NoInfer<A>) => NoInfer<A>
|
|
531
|
-
): void
|
|
532
436
|
<I, A>(
|
|
533
437
|
query: RequestHandlerWithInput<I, A, any, any, any, any>,
|
|
534
438
|
input: I,
|
|
535
439
|
updater: (data: NoInfer<A>) => NoInfer<A>
|
|
536
440
|
): void
|
|
537
|
-
} = (query: any,
|
|
538
|
-
const
|
|
539
|
-
const key = updaterMaybe !== undefined
|
|
540
|
-
? [...makeQueryKey(query), updateOrInput]
|
|
541
|
-
: makeQueryKey(query)
|
|
441
|
+
} = (query: any, input: any, updater: any) => {
|
|
442
|
+
const key = [...makeQueryKey(query), input]
|
|
542
443
|
const data = queryClient.getQueryData(key)
|
|
543
444
|
if (data) {
|
|
544
445
|
queryClient.setQueryData(key, updater)
|