@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.
Files changed (50) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/_cjs/index.cjs +0 -22
  3. package/_cjs/index.cjs.map +1 -1
  4. package/_cjs/makeClient.cjs +169 -72
  5. package/_cjs/makeClient.cjs.map +1 -1
  6. package/_cjs/mutate.cjs +84 -101
  7. package/_cjs/mutate.cjs.map +1 -1
  8. package/_cjs/query.cjs +9 -52
  9. package/_cjs/query.cjs.map +1 -1
  10. package/dist/index.d.ts +0 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -3
  13. package/dist/makeClient.d.ts +87 -70
  14. package/dist/makeClient.d.ts.map +1 -1
  15. package/dist/makeClient.js +164 -84
  16. package/dist/mutate.d.ts +18 -26
  17. package/dist/mutate.d.ts.map +1 -1
  18. package/dist/mutate.js +67 -84
  19. package/dist/query.d.ts +10 -24
  20. package/dist/query.d.ts.map +1 -1
  21. package/dist/query.js +13 -55
  22. package/package.json +8 -48
  23. package/src/index.ts +0 -2
  24. package/src/makeClient.ts +463 -227
  25. package/src/mutate.ts +111 -141
  26. package/src/query.ts +30 -116
  27. package/_cjs/hooks.cjs +0 -28
  28. package/_cjs/hooks.cjs.map +0 -1
  29. package/_cjs/makeClient2.cjs +0 -221
  30. package/_cjs/makeClient2.cjs.map +0 -1
  31. package/_cjs/mutate2.cjs +0 -118
  32. package/_cjs/mutate2.cjs.map +0 -1
  33. package/_cjs/query2.cjs +0 -105
  34. package/_cjs/query2.cjs.map +0 -1
  35. package/dist/hooks.d.ts +0 -3
  36. package/dist/hooks.d.ts.map +0 -1
  37. package/dist/hooks.js +0 -4
  38. package/dist/makeClient2.d.ts +0 -74
  39. package/dist/makeClient2.d.ts.map +0 -1
  40. package/dist/makeClient2.js +0 -187
  41. package/dist/mutate2.d.ts +0 -42
  42. package/dist/mutate2.d.ts.map +0 -1
  43. package/dist/mutate2.js +0 -88
  44. package/dist/query2.d.ts +0 -23
  45. package/dist/query2.d.ts.map +0 -1
  46. package/dist/query2.js +0 -97
  47. package/src/hooks.ts +0 -4
  48. package/src/makeClient2.ts +0 -353
  49. package/src/mutate2.ts +0 -197
  50. package/src/query2.ts +0 -205
package/src/mutate.ts CHANGED
@@ -2,14 +2,55 @@
2
2
  import * as Result from "@effect-rx/rx/Result"
3
3
  import type { InvalidateOptions, InvalidateQueryFilters } from "@tanstack/vue-query"
4
4
  import { useQueryClient } from "@tanstack/vue-query"
5
- import { Cause, Effect, Exit, Option, Runtime } from "effect-app"
5
+ import { Cause, Effect, Exit, Option } from "effect-app"
6
+ import type { RequestHandler, RequestHandlerWithInput, TaggedRequestClassAny } from "effect-app/client/clientFor"
6
7
  import { tuple } from "effect-app/Function"
7
- import { dropUndefinedT } from "effect-app/utils"
8
- import { InterruptedException } from "effect/Cause"
9
- import * as Either from "effect/Either"
10
- import type { ComputedRef, Ref, ShallowRef } from "vue"
8
+ import type { ComputedRef, Ref } from "vue"
11
9
  import { computed, ref, shallowRef } from "vue"
12
- import { getRuntime, makeQueryKey, reportRuntimeError } from "./lib.js"
10
+ import { makeQueryKey, reportRuntimeError } from "./lib.js"
11
+
12
+ export const getQueryKey = (h: { name: string }) => {
13
+ const key = makeQueryKey(h)
14
+ const ns = key.filter((_) => _.startsWith("$"))
15
+ // we invalidate the parent namespace e.g $project/$configuration.get, we invalidate $project
16
+ // for $project/$configuration/$something.get, we invalidate $project/$configuration
17
+ const k = ns.length ? ns.length > 1 ? ns.slice(0, ns.length - 1) : ns : undefined
18
+ if (!k) throw new Error("empty query key for: " + h.name)
19
+ return k
20
+ }
21
+
22
+ export function mutationResultToVue<A, E>(
23
+ mutationResult: MutationResult<A, E>
24
+ ): Res<A, E> {
25
+ switch (mutationResult._tag) {
26
+ case "Loading": {
27
+ return { loading: true, data: undefined, error: undefined }
28
+ }
29
+ case "Success": {
30
+ return {
31
+ loading: false,
32
+ data: mutationResult.data,
33
+ error: undefined
34
+ }
35
+ }
36
+ case "Error": {
37
+ return {
38
+ loading: false,
39
+ data: undefined,
40
+ error: mutationResult.error
41
+ }
42
+ }
43
+ case "Initial": {
44
+ return { loading: false, data: undefined, error: undefined }
45
+ }
46
+ }
47
+ }
48
+
49
+ export interface Res<A, E> {
50
+ readonly loading: boolean
51
+ readonly data: A | undefined
52
+ readonly error: E | undefined
53
+ }
13
54
 
14
55
  export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
15
56
  export function make<A, E, R>(self: Effect<A, E, R>) {
@@ -61,24 +102,13 @@ type MaybeRefDeep<T> = MaybeRef<
61
102
  : T
62
103
  >
63
104
 
64
- export interface MutationOptions<A, I = void> {
105
+ export interface MutationOptions {
65
106
  queryInvalidation?: (defaultKey: string[], name: string) => {
66
107
  filters?: MaybeRefDeep<InvalidateQueryFilters> | undefined
67
108
  options?: MaybeRefDeep<InvalidateOptions> | undefined
68
109
  }[]
69
- /** @deprecated use mapHandler with Effect.andThen/tap accordingly */
70
- onSuccess?: (a: A, i: I) => Promise<unknown>
71
110
  }
72
111
 
73
- export const getQueryKey = (h: { name: string }) => {
74
- const key = makeQueryKey(h)
75
- const ns = key.filter((_) => _.startsWith("$"))
76
- // we invalidate the parent namespace e.g $project/$configuration.get, we invalidate $project
77
- // for $project/$configuration/$something.get, we invalidate $project/$configuration
78
- const k = ns.length ? ns.length > 1 ? ns.slice(0, ns.length - 1) : ns : undefined
79
- if (!k) throw new Error("empty query key for: " + h.name)
80
- return k
81
- }
82
112
  // TODO: more efficient invalidation, including args etc
83
113
  // return Effect.promise(() => queryClient.invalidateQueries({
84
114
  // predicate: (_) => nses.includes(_.queryKey.filter((_) => _.startsWith("$")).join("/"))
@@ -90,174 +120,114 @@ export const getQueryKey = (h: { name: string }) => {
90
120
  // }
91
121
  */
92
122
 
93
- export const makeMutation = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>) => {
94
- type HandlerWithInput<I, A, E> = {
95
- handler: (i: I) => Effect<A, E, R>
96
- name: string
97
- }
98
- type Handler<A, E> = { handler: Effect<A, E, R>; name: string }
99
-
123
+ export const makeMutation2 = () => {
100
124
  /**
101
125
  * Pass a function that returns an Effect, e.g from a client action, or an Effect
102
126
  * Returns a tuple with state ref and execution function which reports errors as Toast.
103
127
  */
104
128
  const useSafeMutation: {
105
- <I, E, A>(self: HandlerWithInput<I, A, E>, options?: MutationOptions<A, I>): readonly [
129
+ <I, E, A, R, Request extends TaggedRequestClassAny>(
130
+ self: RequestHandlerWithInput<I, A, E, R, Request>,
131
+ options?: MutationOptions
132
+ ): readonly [
106
133
  Readonly<Ref<MutationResult<A, E>>>,
107
- (
108
- i: I,
109
- signal?: AbortSignal
110
- ) => Promise<Either.Either<A, E>>
134
+ (i: I) => Effect<A, E, R>
111
135
  ]
112
- <E, A>(self: Handler<A, E>, options?: MutationOptions<A>): readonly [
136
+ <E, A, R, Request extends TaggedRequestClassAny>(
137
+ self: RequestHandler<A, E, R, Request>,
138
+ options?: MutationOptions
139
+ ): readonly [
113
140
  Readonly<Ref<MutationResult<A, E>>>,
114
- (
115
- signal?: AbortSignal
116
- ) => Promise<Either.Either<A, E>>
141
+ Effect<A, E, R>
117
142
  ]
118
- } = <I, E, A>(
119
- self: {
120
- handler:
121
- | HandlerWithInput<I, A, E>["handler"]
122
- | Handler<A, E>["handler"]
123
- name: string
124
- },
125
- options?: MutationOptions<A>
143
+ } = <I, E, A, R, Request extends TaggedRequestClassAny>(
144
+ self: RequestHandlerWithInput<I, A, E, R, Request> | RequestHandler<A, E, R, Request>,
145
+ options?: MutationOptions
126
146
  ) => {
127
- const runPromise = Runtime.runPromise(getRuntime(runtime))
128
-
129
147
  const queryClient = useQueryClient()
130
148
  const state: Ref<MutationResult<A, E>> = ref<MutationResult<A, E>>({ _tag: "Initial" }) as any
131
- const onSuccess = options?.onSuccess
132
149
 
133
150
  const invalidateQueries = (
134
151
  filters?: MaybeRefDeep<InvalidateQueryFilters>,
135
152
  options?: MaybeRefDeep<InvalidateOptions>
136
153
  ) => Effect.promise(() => queryClient.invalidateQueries(filters, options))
137
154
 
138
- function handleExit(exit: Exit.Exit<A, E>): Effect<Either.Either<A, E>, never, never> {
155
+ function handleExit(exit: Exit.Exit<A, E>) {
139
156
  return Effect.sync(() => {
140
157
  if (Exit.isSuccess(exit)) {
141
158
  state.value = { _tag: "Success", data: exit.value }
142
- return Either.right(exit.value)
159
+ return
143
160
  }
144
161
 
145
162
  const err = Cause.failureOption(exit.cause)
146
163
  if (Option.isSome(err)) {
147
164
  state.value = { _tag: "Error", error: err.value }
148
- return Either.left(err.value)
149
- }
150
-
151
- const died = Cause.dieOption(exit.cause)
152
- if (Option.isSome(died)) {
153
- throw died.value
154
- }
155
- const interrupted = Cause.interruptOption(exit.cause)
156
- if (Option.isSome(interrupted)) {
157
- throw new InterruptedException()
165
+ return
158
166
  }
159
- throw new Error("Invalid state")
160
167
  })
161
168
  }
162
169
 
163
- const exec = (fst?: I | AbortSignal, snd?: AbortSignal) => {
164
- let effect: Effect<A, E, R>
165
- let signal: AbortSignal | undefined
166
- if (Effect.isEffect(self.handler)) {
167
- effect = self.handler as any
168
- signal = fst as AbortSignal | undefined
169
- } else {
170
- effect = self.handler(fst as I)
171
- signal = snd
172
- }
173
-
174
- const invalidateCache = Effect
175
- .suspend(() => {
176
- const queryKey = getQueryKey(self)
170
+ const invalidateCache = Effect.suspend(() => {
171
+ const queryKey = getQueryKey(self)
177
172
 
178
- if (options?.queryInvalidation) {
179
- const opts = options.queryInvalidation(queryKey, self.name)
180
- if (!opts.length) {
181
- return Effect.void
182
- }
183
- return Effect
184
- .andThen(
185
- Effect.annotateCurrentSpan({ queryKey, opts }),
186
- Effect.forEach(opts, (_) => invalidateQueries(_.filters, _.options), { concurrency: "inherit" })
187
- )
188
- .pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
189
- }
173
+ if (options?.queryInvalidation) {
174
+ const opts = options.queryInvalidation(queryKey, self.name)
175
+ if (!opts.length) {
176
+ return Effect.void
177
+ }
178
+ return Effect
179
+ .andThen(
180
+ Effect.annotateCurrentSpan({ queryKey, opts }),
181
+ Effect.forEach(opts, (_) => invalidateQueries(_.filters, _.options), { concurrency: "inherit" })
182
+ )
183
+ .pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
184
+ }
190
185
 
191
- if (!queryKey) return Effect.void
186
+ if (!queryKey) return Effect.void
192
187
 
193
- return Effect
194
- .andThen(
195
- Effect.annotateCurrentSpan({ queryKey }),
196
- invalidateQueries({ queryKey })
197
- )
198
- .pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
199
- })
188
+ return Effect
189
+ .andThen(
190
+ Effect.annotateCurrentSpan({ queryKey }),
191
+ invalidateQueries({ queryKey })
192
+ )
193
+ .pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
194
+ })
200
195
 
201
- return runPromise(
196
+ const handler = self.handler
197
+ const r = Effect.isEffect(handler)
198
+ ? tuple(
199
+ state,
202
200
  Effect
203
201
  .sync(() => {
204
202
  state.value = { _tag: "Loading" }
205
203
  })
206
204
  .pipe(
207
- Effect.andThen(effect),
208
- Effect.tapBoth({ onFailure: () => invalidateCache, onSuccess: () => invalidateCache }),
209
- Effect.tap((a) =>
210
- onSuccess ? Effect.promise(() => onSuccess(a, (fst !== signal ? fst : undefined) as any)) : Effect.void
211
- ),
205
+ Effect.zipRight(handler),
206
+ Effect.tap(invalidateCache),
212
207
  Effect.tapDefect(reportRuntimeError),
213
- Effect.exit,
214
- Effect.flatMap(handleExit),
208
+ Effect.onExit(handleExit),
215
209
  Effect.withSpan(`mutation ${self.name}`, { captureStackTrace: false })
216
- ),
217
- dropUndefinedT({ signal })
210
+ )
218
211
  )
219
- }
212
+ : tuple(state, (fst: I) => {
213
+ const effect = handler(fst)
214
+ return Effect
215
+ .sync(() => {
216
+ state.value = { _tag: "Loading" }
217
+ })
218
+ .pipe(
219
+ Effect.zipRight(effect),
220
+ Effect.tapBoth({ onFailure: () => invalidateCache, onSuccess: () => invalidateCache }),
221
+ Effect.tapDefect(reportRuntimeError),
222
+ Effect.onExit(handleExit),
223
+ Effect.withSpan(`mutation ${self.name}`, { captureStackTrace: false })
224
+ )
225
+ })
220
226
 
221
- return tuple(
222
- state,
223
- exec
224
- )
227
+ return r as any
225
228
  }
226
229
  return useSafeMutation
227
230
  }
228
231
 
229
232
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
230
- export interface MakeMutation<R> extends ReturnType<typeof makeMutation<R>> {}
231
-
232
- export function mutationResultToVue<A, E>(
233
- mutationResult: MutationResult<A, E>
234
- ): Res<A, E> {
235
- switch (mutationResult._tag) {
236
- case "Loading": {
237
- return { loading: true, data: undefined, error: undefined }
238
- }
239
- case "Success": {
240
- return {
241
- loading: false,
242
- data: mutationResult.data,
243
- error: undefined
244
- }
245
- }
246
- case "Error": {
247
- return {
248
- loading: false,
249
- data: undefined,
250
- error: mutationResult.error
251
- }
252
- }
253
- case "Initial": {
254
- return { loading: false, data: undefined, error: undefined }
255
- }
256
- }
257
- }
258
-
259
- export interface Res<A, E> {
260
- readonly loading: boolean
261
- readonly data: A | undefined
262
- readonly error: E | undefined
263
- }
233
+ export interface MakeMutation2 extends ReturnType<typeof makeMutation2> {}
package/src/query.ts CHANGED
@@ -12,8 +12,9 @@ import type {
12
12
  UseQueryReturnType
13
13
  } from "@tanstack/vue-query"
14
14
  import { useQuery } from "@tanstack/vue-query"
15
- import { Array, Cause, Effect, Option, Runtime, S } from "effect-app"
15
+ import { Cause, Effect, Option, Runtime, S } from "effect-app"
16
16
  import { ServiceUnavailableError } from "effect-app/client"
17
+ import type { RequestHandler, RequestHandlerWithInput, TaggedRequestClassAny } from "effect-app/client/clientFor"
17
18
  import { isHttpRequestError, isHttpResponseError } from "effect-app/http/http-client"
18
19
  import { computed, ref } from "vue"
19
20
  import type { ComputedRef, ShallowRef, WatchSource } from "vue"
@@ -35,31 +36,15 @@ export interface KnownFiberFailure<E> extends Runtime.FiberFailure {
35
36
  readonly [Runtime.FiberFailureCauseId]: Cause.Cause<E>
36
37
  }
37
38
 
38
- export const makeQuery = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>) => {
39
+ export const makeQuery2 = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>) => {
39
40
  // TODO: options
40
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>;
41
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>;
42
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>;
43
- const useSafeQuery_ = <I, A, E>(
44
+ const useSafeQuery_ = <I, A, E, Request extends TaggedRequestClassAny>(
44
45
  q:
45
- | {
46
- readonly handler: (
47
- req: I
48
- ) => Effect<
49
- A,
50
- E,
51
- R
52
- >
53
- name: string
54
- }
55
- | {
56
- readonly handler: Effect<
57
- A,
58
- E,
59
- R
60
- >
61
- name: string
62
- },
46
+ | RequestHandlerWithInput<I, A, E, R, Request>
47
+ | RequestHandler<A, E, R, Request>,
63
48
  arg?: I | WatchSource<I>,
64
49
  options: QueryObserverOptionsCustom<unknown, KnownFiberFailure<E>, A> = {} // TODO
65
50
  ) => {
@@ -136,7 +121,15 @@ export const makeQuery = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>
136
121
  })
137
122
  )
138
123
  const latestSuccess = computed(() => Option.getOrUndefined(Result.value(result.value)))
139
- return [result, latestSuccess, r.refetch, r] as const
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
140
133
  }
141
134
 
142
135
  function swrToQuery<E, A>(r: {
@@ -158,79 +151,46 @@ export const makeQuery = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>
158
151
  return Result.initial(r.isValidating)
159
152
  }
160
153
 
161
- function useSafeQuery<E, A>(
162
- self: {
163
- handler: Effect<A, E, R>
164
- name: string
165
- },
166
- options: QueryObserverOptionsCustom<A, E> & { initialData: A | InitialDataFunction<A> }
154
+ function useSafeQuery<E, A, Request extends TaggedRequestClassAny>(
155
+ self: RequestHandler<A, E, R, Request>,
156
+ options?: QueryObserverOptionsCustom<A, E> & { initialData: A | InitialDataFunction<A> }
167
157
  ): readonly [
168
158
  ComputedRef<Result.Result<A, E>>,
169
159
  ComputedRef<A>,
170
- (options?: RefetchOptions) => Promise<QueryObserverResult<any, any>>,
160
+ (options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
171
161
  UseQueryReturnType<any, any>
172
162
  ]
173
- function useSafeQuery<Arg, E, A>(
174
- self: {
175
- handler: (arg: Arg) => Effect<A, E, R>
176
- name: string
177
- },
163
+ function useSafeQuery<Arg, E, A, Request extends TaggedRequestClassAny>(
164
+ self: RequestHandlerWithInput<Arg, A, E, R, Request>,
178
165
  arg: Arg | WatchSource<Arg>,
179
- options: QueryObserverOptionsCustom<A, E>
166
+ options?: QueryObserverOptionsCustom<A, E> & { initialData: A | InitialDataFunction<A> }
180
167
  ): readonly [
181
168
  ComputedRef<Result.Result<A, E>>,
182
169
  ComputedRef<A>,
183
- (options?: RefetchOptions) => Promise<QueryObserverResult<any, any>>,
170
+ (options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
184
171
  UseQueryReturnType<any, any>
185
172
  ]
186
- function useSafeQuery<E, A>(
187
- self: {
188
- handler: Effect<A, E, R>
189
- name: string
190
- },
173
+ function useSafeQuery<E, A, Request extends TaggedRequestClassAny>(
174
+ self: RequestHandler<A, E, R, Request>,
191
175
  options?: QueryObserverOptionsCustom<A, E>
192
176
  ): readonly [
193
177
  ComputedRef<Result.Result<A, E>>,
194
178
  ComputedRef<A | undefined>,
195
- (options?: RefetchOptions) => Promise<QueryObserverResult<any, any>>,
179
+ (options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
196
180
  UseQueryReturnType<any, any>
197
181
  ]
198
- function useSafeQuery<Arg, E, A>(
199
- self: {
200
- handler: (arg: Arg) => Effect<A, E, R>
201
- name: string
202
- },
182
+ function useSafeQuery<Arg, E, A, Request extends TaggedRequestClassAny>(
183
+ self: RequestHandlerWithInput<Arg, A, E, R, Request>,
203
184
  arg: Arg | WatchSource<Arg>,
204
185
  options?: QueryObserverOptionsCustom<A, E>
205
186
  ): readonly [
206
187
  ComputedRef<Result.Result<A, E>>,
207
188
  ComputedRef<A | undefined>,
208
- (options?: RefetchOptions) => Promise<QueryObserverResult<any, any>>,
189
+ (options?: RefetchOptions) => Effect<QueryObserverResult<A, KnownFiberFailure<E>>>,
209
190
  UseQueryReturnType<any, any>
210
191
  ]
211
192
  function useSafeQuery(
212
193
  self: any,
213
- /*
214
- q:
215
- | {
216
- handler: (
217
- req: I
218
- ) => Effect<
219
- A,
220
- E,
221
- R
222
- >
223
- name: string
224
- }
225
- | {
226
- handler: Effect<
227
- A,
228
- E,
229
- R
230
- >
231
- name: string
232
- },
233
- */
234
194
  argOrOptions?: any,
235
195
  options?: any
236
196
  ) {
@@ -242,50 +202,4 @@ export const makeQuery = <R>(runtime: ShallowRef<Runtime.Runtime<R> | undefined>
242
202
  }
243
203
 
244
204
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
245
- export interface MakeQuery<R> extends ReturnType<typeof makeQuery<R>> {}
246
-
247
- export function composeQueries<
248
- R extends Record<string, Result.Result<any, any>>
249
- >(
250
- results: R,
251
- renderPreviousOnFailure?: boolean
252
- ): Result.Result<
253
- {
254
- [Property in keyof R]: R[Property] extends Result.Result<infer A, any> ? A
255
- : never
256
- },
257
- {
258
- [Property in keyof R]: R[Property] extends Result.Result<any, infer E> ? E
259
- : never
260
- }[keyof R]
261
- > {
262
- const values = renderPreviousOnFailure
263
- ? Object.values(results).map(orPrevious)
264
- : Object.values(results)
265
- const error = values.find(Result.isFailure)
266
- if (error) {
267
- return error
268
- }
269
- const initial = Array.findFirst(values, (x) => x._tag === "Initial" ? Option.some(x) : Option.none())
270
- if (initial.value !== undefined) {
271
- return initial.value
272
- }
273
- const loading = Array.findFirst(values, (x) => Result.isInitial(x) && x.waiting ? Option.some(x) : Option.none())
274
- if (loading.value !== undefined) {
275
- return loading.value
276
- }
277
-
278
- const isRefreshing = values.some((x) => x.waiting)
279
-
280
- const r = Object.entries(results).reduce((prev, [key, value]) => {
281
- prev[key] = Result.value(value).value
282
- return prev
283
- }, {} as any)
284
- return Result.success(r, isRefreshing)
285
- }
286
-
287
- function orPrevious<E, A>(result: Result.Result<A, E>) {
288
- return Result.isFailure(result) && Option.isSome(result.previousValue)
289
- ? Result.success(result.previousValue.value, result.waiting)
290
- : result
291
- }
205
+ export interface MakeQuery2<R> extends ReturnType<typeof makeQuery2<R>> {}
package/_cjs/hooks.cjs DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _mutate = require("./mutate.cjs");
7
- Object.keys(_mutate).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _mutate[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _mutate[key];
14
- }
15
- });
16
- });
17
- var _query = require("./query.cjs");
18
- Object.keys(_query).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _query[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _query[key];
25
- }
26
- });
27
- });
28
- //# sourceMappingURL=hooks.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.cjs","names":["_mutate","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_query"],"sources":["../src/hooks.ts"],"sourcesContent":[null],"mappings":";;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}