@effect-app/vue 4.0.0-beta.0 → 4.0.0-beta.10
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 +77 -0
- package/dist/experimental/commander.d.ts +3 -3
- package/dist/experimental/commander.d.ts.map +1 -1
- package/dist/experimental/commander.js +3 -3
- package/dist/form.d.ts +2 -3
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +1 -1
- package/dist/lib.d.ts +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +2 -2
- package/dist/makeClient.d.ts +8 -8
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +4 -4
- package/dist/mutate.d.ts +5 -5
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +11 -11
- package/dist/query.d.ts +10 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +13 -13
- package/package.json +8 -9
- package/src/experimental/commander.ts +4 -4
- package/src/form.ts +6 -7
- package/src/lib.ts +1 -1
- package/src/makeClient.ts +11 -11
- package/src/mutate.ts +13 -13
- package/src/query.ts +28 -28
- package/test/Mutation.test.ts +13 -13
- package/test/dist/stubs.d.ts +17 -13
- package/test/dist/stubs.d.ts.map +1 -1
package/src/mutate.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import * as Result from "@effect-atom/atom/Result"
|
|
3
2
|
import { type InvalidateOptions, type InvalidateQueryFilters, type QueryClient, useQueryClient } from "@tanstack/vue-query"
|
|
4
3
|
import { type Cause, Effect, type Exit, Option } from "effect-app"
|
|
5
4
|
import { type Req } from "effect-app/client"
|
|
6
5
|
import type { ClientForOptions, RequestHandler, RequestHandlerWithInput } from "effect-app/client/clientFor"
|
|
7
6
|
import { tuple } from "effect-app/Function"
|
|
7
|
+
import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"
|
|
8
8
|
import { computed, type ComputedRef, shallowRef } from "vue"
|
|
9
9
|
import { makeQueryKey } from "./lib.js"
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ export const getQueryKey = (h: { id: string; options?: ClientForOptions }) => {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function mutationResultToVue<A, E>(
|
|
22
|
-
mutationResult:
|
|
22
|
+
mutationResult: AsyncResult.AsyncResult<A, E>
|
|
23
23
|
): Res<A, E> {
|
|
24
24
|
switch (mutationResult._tag) {
|
|
25
25
|
case "Initial": {
|
|
@@ -49,20 +49,20 @@ export interface Res<A, E> {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export function make<A, E, R>(self: Effect.Effect<A, E, R>) {
|
|
52
|
-
const result = shallowRef(
|
|
52
|
+
const result = shallowRef(AsyncResult.initial() as AsyncResult.AsyncResult<A, E>)
|
|
53
53
|
|
|
54
54
|
const execute = Effect
|
|
55
55
|
.sync(() => {
|
|
56
|
-
result.value =
|
|
56
|
+
result.value = AsyncResult.waiting(result.value)
|
|
57
57
|
})
|
|
58
58
|
.pipe(
|
|
59
59
|
Effect.andThen(self),
|
|
60
60
|
Effect.exit,
|
|
61
|
-
Effect.map(
|
|
61
|
+
Effect.map(AsyncResult.fromExit),
|
|
62
62
|
Effect.flatMap((r) => Effect.sync(() => result.value = r))
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
const latestSuccess = computed(() => Option.getOrUndefined(
|
|
65
|
+
const latestSuccess = computed(() => Option.getOrUndefined(AsyncResult.value(result.value)))
|
|
66
66
|
|
|
67
67
|
return tuple(result, latestSuccess, execute)
|
|
68
68
|
}
|
|
@@ -103,38 +103,38 @@ export interface MutationOptions<A, E, R, A2 = A, E2 = E, R2 = R, I = void> exte
|
|
|
103
103
|
export const asResult: {
|
|
104
104
|
<A, E, R>(
|
|
105
105
|
handler: Effect.Effect<A, E, R>
|
|
106
|
-
): readonly [ComputedRef<
|
|
106
|
+
): readonly [ComputedRef<AsyncResult.AsyncResult<A, E>>, Effect.Effect<Exit.Exit<A, E>, never, R>]
|
|
107
107
|
<Args extends readonly any[], A, E, R>(
|
|
108
108
|
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
109
|
-
): readonly [ComputedRef<
|
|
109
|
+
): readonly [ComputedRef<AsyncResult.AsyncResult<A, E>>, (...args: Args) => Effect.Effect<Exit.Exit<A, E>, never, R>]
|
|
110
110
|
} = <Args extends readonly any[], A, E, R>(
|
|
111
111
|
handler: Effect.Effect<A, E, R> | ((...args: Args) => Effect.Effect<A, E, R>)
|
|
112
112
|
) => {
|
|
113
|
-
const state = shallowRef<
|
|
113
|
+
const state = shallowRef<AsyncResult.AsyncResult<A, E>>(AsyncResult.initial())
|
|
114
114
|
|
|
115
115
|
const act = Effect.isEffect(handler)
|
|
116
116
|
? Effect
|
|
117
117
|
.sync(() => {
|
|
118
|
-
state.value =
|
|
118
|
+
state.value = AsyncResult.initial(true)
|
|
119
119
|
})
|
|
120
120
|
.pipe(
|
|
121
121
|
Effect.andThen(Effect.suspend(() =>
|
|
122
122
|
handler.pipe(
|
|
123
123
|
Effect.exit,
|
|
124
|
-
Effect.tap((exit) => Effect.sync(() => (state.value =
|
|
124
|
+
Effect.tap((exit) => Effect.sync(() => (state.value = AsyncResult.fromExit(exit))))
|
|
125
125
|
)
|
|
126
126
|
))
|
|
127
127
|
)
|
|
128
128
|
: (...args: Args) =>
|
|
129
129
|
Effect
|
|
130
130
|
.sync(() => {
|
|
131
|
-
state.value =
|
|
131
|
+
state.value = AsyncResult.initial(true)
|
|
132
132
|
})
|
|
133
133
|
.pipe(
|
|
134
134
|
Effect.andThen(Effect.suspend(() =>
|
|
135
135
|
handler(...args).pipe(
|
|
136
136
|
Effect.exit,
|
|
137
|
-
Effect.tap((exit) => Effect.sync(() => (state.value =
|
|
137
|
+
Effect.tap((exit) => Effect.sync(() => (state.value = AsyncResult.fromExit(exit))))
|
|
138
138
|
)
|
|
139
139
|
))
|
|
140
140
|
)
|
package/src/query.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
import * as Result from "@effect-atom/atom/Result"
|
|
6
5
|
import { type DefaultError, type Enabled, 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
6
|
import { Array, Cause, Effect, Exit, flow, Option, S, type ServiceMap } from "effect-app"
|
|
8
7
|
import { type Req } from "effect-app/client"
|
|
@@ -10,6 +9,7 @@ import type { RequestHandler, RequestHandlerWithInput } from "effect-app/client/
|
|
|
10
9
|
import { ServiceUnavailableError } from "effect-app/client/errors"
|
|
11
10
|
import { type Span } from "effect/Tracer"
|
|
12
11
|
import { isHttpClientError } from "effect/unstable/http/HttpClientError"
|
|
12
|
+
import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"
|
|
13
13
|
import { computed, type ComputedRef, type MaybeRefOrGetter, ref, shallowRef, watch, type WatchSource } from "vue"
|
|
14
14
|
import { makeQueryKey, reportRuntimeError } from "./lib.js"
|
|
15
15
|
|
|
@@ -93,7 +93,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
93
93
|
arg: I | WatchSource<I> | undefined,
|
|
94
94
|
options?: CustomUndefinedInitialQueryOptions<A, E, TData>
|
|
95
95
|
): readonly [
|
|
96
|
-
ComputedRef<
|
|
96
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
97
97
|
ComputedRef<TData | undefined>,
|
|
98
98
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>, never, never>,
|
|
99
99
|
UseQueryDefinedReturnType<TData, KnownFiberFailure<E>>
|
|
@@ -103,7 +103,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
103
103
|
arg: I | WatchSource<I> | undefined,
|
|
104
104
|
options: CustomDefinedInitialQueryOptions<A, E, TData>
|
|
105
105
|
): readonly [
|
|
106
|
-
ComputedRef<
|
|
106
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
107
107
|
ComputedRef<TData>,
|
|
108
108
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>, never, never>,
|
|
109
109
|
UseQueryDefinedReturnType<TData, KnownFiberFailure<E>>
|
|
@@ -113,7 +113,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
113
113
|
arg: I | WatchSource<I> | undefined,
|
|
114
114
|
options: CustomDefinedPlaceholderQueryOptions<A, E, TData>
|
|
115
115
|
): readonly [
|
|
116
|
-
ComputedRef<
|
|
116
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
117
117
|
ComputedRef<TData>,
|
|
118
118
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>, never, never>,
|
|
119
119
|
UseQueryDefinedReturnType<TData, KnownFiberFailure<E>>
|
|
@@ -202,7 +202,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
202
202
|
)
|
|
203
203
|
|
|
204
204
|
const latestSuccess = shallowRef<TData>()
|
|
205
|
-
const result = computed(():
|
|
205
|
+
const result = computed((): AsyncResult.AsyncResult<TData, E> =>
|
|
206
206
|
swrToQuery({
|
|
207
207
|
error: r.error.value ?? undefined,
|
|
208
208
|
data: r.data.value === undefined ? latestSuccess.value : r.data.value, // we fall back to existing data, as tanstack query might loose it when the key changes
|
|
@@ -210,7 +210,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
210
210
|
})
|
|
211
211
|
)
|
|
212
212
|
// not using `computed` here as we have a circular dependency
|
|
213
|
-
watch(result, (value) => latestSuccess.value = Option.getOrUndefined(
|
|
213
|
+
watch(result, (value) => latestSuccess.value = Option.getOrUndefined(AsyncResult.value(value)), { immediate: true })
|
|
214
214
|
|
|
215
215
|
return [
|
|
216
216
|
result,
|
|
@@ -231,21 +231,21 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
231
231
|
error: KnownFiberFailure<E> | undefined
|
|
232
232
|
data: A | undefined
|
|
233
233
|
isValidating: boolean
|
|
234
|
-
}):
|
|
234
|
+
}): AsyncResult.AsyncResult<A, E> {
|
|
235
235
|
if (r.error !== undefined) {
|
|
236
|
-
return
|
|
236
|
+
return AsyncResult.failureWithPrevious(
|
|
237
237
|
r.error.effectCause,
|
|
238
238
|
{
|
|
239
|
-
previous: r.data === undefined ? Option.none() : Option.some(
|
|
239
|
+
previous: r.data === undefined ? Option.none() : Option.some(AsyncResult.success(r.data)),
|
|
240
240
|
waiting: r.isValidating
|
|
241
241
|
}
|
|
242
242
|
)
|
|
243
243
|
}
|
|
244
244
|
if (r.data !== undefined) {
|
|
245
|
-
return
|
|
245
|
+
return AsyncResult.success<A, E>(r.data, { waiting: r.isValidating })
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
return
|
|
248
|
+
return AsyncResult.initial(r.isValidating)
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
const useQuery: {
|
|
@@ -263,7 +263,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
263
263
|
<TData = A>(
|
|
264
264
|
options: CustomDefinedInitialQueryOptions<A, KnownFiberFailure<E>, TData>
|
|
265
265
|
): readonly [
|
|
266
|
-
ComputedRef<
|
|
266
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
267
267
|
ComputedRef<TData>,
|
|
268
268
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
|
|
269
269
|
UseQueryReturnType<any, any>
|
|
@@ -271,7 +271,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
271
271
|
<TData = A>(
|
|
272
272
|
options: CustomDefinedPlaceholderQueryOptions<A, E, TData>
|
|
273
273
|
): readonly [
|
|
274
|
-
ComputedRef<
|
|
274
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
275
275
|
ComputedRef<TData>,
|
|
276
276
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>, never, never>,
|
|
277
277
|
UseQueryDefinedReturnType<TData, KnownFiberFailure<E>>
|
|
@@ -281,7 +281,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
281
281
|
* Effect results are passed to the caller, including errors.
|
|
282
282
|
*/
|
|
283
283
|
<TData = A>(options?: CustomUndefinedInitialQueryOptions<A, KnownFiberFailure<E>, TData>): readonly [
|
|
284
|
-
ComputedRef<
|
|
284
|
+
ComputedRef<AsyncResult.AsyncResult<A, E>>,
|
|
285
285
|
ComputedRef<A | undefined>,
|
|
286
286
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
|
|
287
287
|
UseQueryReturnType<any, any>
|
|
@@ -302,7 +302,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
302
302
|
arg: Arg | WatchSource<Arg>,
|
|
303
303
|
options: CustomDefinedInitialQueryOptions<A, KnownFiberFailure<E>, TData>
|
|
304
304
|
): readonly [
|
|
305
|
-
ComputedRef<
|
|
305
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
306
306
|
ComputedRef<TData>,
|
|
307
307
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
|
|
308
308
|
UseQueryReturnType<any, any>
|
|
@@ -315,7 +315,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
315
315
|
arg: Arg | WatchSource<Arg>,
|
|
316
316
|
options: CustomDefinedPlaceholderQueryOptions<A, KnownFiberFailure<E>, TData>
|
|
317
317
|
): readonly [
|
|
318
|
-
ComputedRef<
|
|
318
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
319
319
|
ComputedRef<TData>,
|
|
320
320
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
|
|
321
321
|
UseQueryReturnType<any, any>
|
|
@@ -328,7 +328,7 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
328
328
|
arg: Arg | WatchSource<Arg>,
|
|
329
329
|
options?: CustomUndefinedInitialQueryOptions<A, KnownFiberFailure<E>, TData>
|
|
330
330
|
): readonly [
|
|
331
|
-
ComputedRef<
|
|
331
|
+
ComputedRef<AsyncResult.AsyncResult<TData, E>>,
|
|
332
332
|
ComputedRef<TData | undefined>,
|
|
333
333
|
(options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
|
|
334
334
|
UseQueryReturnType<any, any>
|
|
@@ -350,31 +350,31 @@ export const makeQuery = <R>(getRuntime: () => ServiceMap.ServiceMap<R>) => {
|
|
|
350
350
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
351
351
|
export interface MakeQuery2<R> extends ReturnType<typeof makeQuery<R>> {}
|
|
352
352
|
|
|
353
|
-
function orPrevious<E, A>(result:
|
|
354
|
-
return
|
|
355
|
-
?
|
|
353
|
+
function orPrevious<E, A>(result: AsyncResult.AsyncResult<A, E>) {
|
|
354
|
+
return AsyncResult.isFailure(result) && Option.isSome(result.previousSuccess)
|
|
355
|
+
? AsyncResult.success(result.previousSuccess.value, { waiting: result.waiting })
|
|
356
356
|
: result
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
export function composeQueries<
|
|
360
|
-
R extends Record<string,
|
|
360
|
+
R extends Record<string, AsyncResult.AsyncResult<any, any>>
|
|
361
361
|
>(
|
|
362
362
|
results: R,
|
|
363
363
|
renderPreviousOnFailure?: boolean
|
|
364
|
-
):
|
|
364
|
+
): AsyncResult.AsyncResult<
|
|
365
365
|
{
|
|
366
|
-
[Property in keyof R]: R[Property] extends
|
|
366
|
+
[Property in keyof R]: R[Property] extends AsyncResult.AsyncResult<infer A, any> ? A
|
|
367
367
|
: never
|
|
368
368
|
},
|
|
369
369
|
{
|
|
370
|
-
[Property in keyof R]: R[Property] extends
|
|
370
|
+
[Property in keyof R]: R[Property] extends AsyncResult.AsyncResult<any, infer E> ? E
|
|
371
371
|
: never
|
|
372
372
|
}[keyof R]
|
|
373
373
|
> {
|
|
374
374
|
const values = renderPreviousOnFailure
|
|
375
375
|
? Object.values(results).map(orPrevious)
|
|
376
376
|
: Object.values(results)
|
|
377
|
-
const error = values.find(
|
|
377
|
+
const error = values.find(AsyncResult.isFailure)
|
|
378
378
|
if (error) {
|
|
379
379
|
return error
|
|
380
380
|
}
|
|
@@ -382,7 +382,7 @@ export function composeQueries<
|
|
|
382
382
|
if (initial.value !== undefined) {
|
|
383
383
|
return initial.value
|
|
384
384
|
}
|
|
385
|
-
const loading = Array.findFirst(values, (x) =>
|
|
385
|
+
const loading = Array.findFirst(values, (x) => AsyncResult.isInitial(x) && x.waiting ? Option.some(x) : Option.none())
|
|
386
386
|
if (loading.value !== undefined) {
|
|
387
387
|
return loading.value
|
|
388
388
|
}
|
|
@@ -390,10 +390,10 @@ export function composeQueries<
|
|
|
390
390
|
const isRefreshing = values.some((x) => x.waiting)
|
|
391
391
|
|
|
392
392
|
const r = Object.entries(results).reduce((prev, [key, value]) => {
|
|
393
|
-
prev[key] =
|
|
393
|
+
prev[key] = AsyncResult.value(value).value
|
|
394
394
|
return prev
|
|
395
395
|
}, {} as any)
|
|
396
|
-
return
|
|
396
|
+
return AsyncResult.success(r, { waiting: isRefreshing })
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
export const useUpdateQuery = () => {
|
package/test/Mutation.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { it } from "@effect/vitest"
|
|
3
3
|
import { Cause, Effect, Exit, Fiber, Option } from "effect-app"
|
|
4
4
|
import { CommandContext, DefaultIntl } from "../src/experimental/commander.js"
|
|
5
|
-
import {
|
|
5
|
+
import { AsyncResult } from "../src/lib.js"
|
|
6
6
|
import { useExperimental } from "./stubs.js"
|
|
7
7
|
|
|
8
8
|
const unwrap = <A, E>(r: Fiber.Fiber<Exit.Exit<A, E>, never>) => Fiber.join(r).pipe(Effect.flatten)
|
|
@@ -88,7 +88,7 @@ describe("alt2", () => {
|
|
|
88
88
|
expect(r).toBe("test-value") // to confirm that the initial function has ran.
|
|
89
89
|
expect(executed).toBe(true) // to confirm that the combinators have ran.
|
|
90
90
|
|
|
91
|
-
expect(command.result.pipe(
|
|
91
|
+
expect(command.result.pipe(AsyncResult.value)).toEqual(Option.some("test-value"))
|
|
92
92
|
|
|
93
93
|
expect(toasts.length).toBe(0)
|
|
94
94
|
|
|
@@ -140,7 +140,7 @@ it.live("works", () =>
|
|
|
140
140
|
expect(r).toBe("test-value") // to confirm that the initial function has ran.
|
|
141
141
|
expect(executed).toBe(true) // to confirm that the combinators have ran.
|
|
142
142
|
|
|
143
|
-
expect(command.result.pipe(
|
|
143
|
+
expect(command.result.pipe(AsyncResult.value)).toEqual(Option.some("test-value"))
|
|
144
144
|
|
|
145
145
|
expect(toasts.length).toBe(0)
|
|
146
146
|
|
|
@@ -187,7 +187,7 @@ it.live("works non-gen", () =>
|
|
|
187
187
|
expect(r).toBe("test-value") // to confirm that the initial function has ran.
|
|
188
188
|
expect(executed).toBe(true) // to confirm that the combinators have ran.
|
|
189
189
|
|
|
190
|
-
expect(command.result.pipe(
|
|
190
|
+
expect(command.result.pipe(AsyncResult.value)).toEqual(Option.some("test-value"))
|
|
191
191
|
|
|
192
192
|
expect(toasts.length).toBe(0)
|
|
193
193
|
}))
|
|
@@ -360,7 +360,7 @@ it.live("interrupted", () =>
|
|
|
360
360
|
expect(Exit.hasInterrupts(r)).toBe(true) // to confirm that the initial function has interrupted
|
|
361
361
|
|
|
362
362
|
expect(command.waiting).toBe(false)
|
|
363
|
-
expect(Exit.hasInterrupts(
|
|
363
|
+
expect(Exit.hasInterrupts(AsyncResult.toExit(command.result))).toBe(true)
|
|
364
364
|
expect(toasts.length).toBe(0) // toast is removed on interruption. TODO: maybe a nicer user experience can be had?
|
|
365
365
|
}))
|
|
366
366
|
|
|
@@ -386,7 +386,7 @@ it.live("fail", () =>
|
|
|
386
386
|
expect(Exit.isFailure(r) && Cause.hasFails(r.cause)).toBe(true) // to confirm that the initial function has failed
|
|
387
387
|
|
|
388
388
|
expect(command.waiting).toBe(false)
|
|
389
|
-
expect(Exit.isFailure(
|
|
389
|
+
expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
|
|
390
390
|
expect(toasts.length).toBe(1) // toast should show error
|
|
391
391
|
expect(toasts[0].message).toBe("Test Action Failed:\nBoom!")
|
|
392
392
|
}))
|
|
@@ -414,7 +414,7 @@ it.live("fail and recover", () =>
|
|
|
414
414
|
expect(r).toBe("recovered") // to confirm that the initial function has failed but we recovered
|
|
415
415
|
|
|
416
416
|
expect(command.waiting).toBe(false)
|
|
417
|
-
expect(
|
|
417
|
+
expect(AsyncResult.toExit(command.result)).toEqual(Exit.succeed("recovered"))
|
|
418
418
|
expect(toasts.length).toBe(1) // toast should show error
|
|
419
419
|
expect(toasts[0].message).toBe("Test Action Success")
|
|
420
420
|
}))
|
|
@@ -442,7 +442,7 @@ it.live("defect", () =>
|
|
|
442
442
|
expect(Exit.isFailure(r) && Cause.hasDies(r.cause)).toBe(true) // to confirm that the initial function has died
|
|
443
443
|
|
|
444
444
|
expect(command.waiting).toBe(false)
|
|
445
|
-
expect(Exit.isFailure(
|
|
445
|
+
expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
|
|
446
446
|
expect(toasts.length).toBe(1) // toast should show error
|
|
447
447
|
expect(toasts[0].message).toBe("Test Action unexpected error, please try again shortly.")
|
|
448
448
|
}))
|
|
@@ -484,7 +484,7 @@ it.live("works with alt", () =>
|
|
|
484
484
|
expect(r).toBe("test-value") // to confirm that the initial function has ran.
|
|
485
485
|
expect(executed).toBe(true) // to confirm that the combinators have ran.
|
|
486
486
|
|
|
487
|
-
expect(command.result.pipe(
|
|
487
|
+
expect(command.result.pipe(AsyncResult.value)).toEqual(Option.some("test-value"))
|
|
488
488
|
|
|
489
489
|
expect(toasts.length).toBe(0)
|
|
490
490
|
}))
|
|
@@ -666,7 +666,7 @@ it.live("interrupted with alt", () =>
|
|
|
666
666
|
expect(Exit.hasInterrupts(r)).toBe(true) // to confirm that the initial function has interrupted
|
|
667
667
|
|
|
668
668
|
expect(command.waiting).toBe(false)
|
|
669
|
-
expect(Exit.hasInterrupts(
|
|
669
|
+
expect(Exit.hasInterrupts(AsyncResult.toExit(command.result))).toBe(true)
|
|
670
670
|
expect(toasts.length).toBe(0) // toast is removed on interruption. TODO: maybe a nicer user experience can be had?
|
|
671
671
|
}))
|
|
672
672
|
|
|
@@ -694,7 +694,7 @@ it.live("fail with alt", () =>
|
|
|
694
694
|
expect(Exit.isFailure(r) && Cause.hasFails(r.cause)).toBe(true) // to confirm that the initial function has failed
|
|
695
695
|
|
|
696
696
|
expect(command.waiting).toBe(false)
|
|
697
|
-
expect(Exit.isFailure(
|
|
697
|
+
expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
|
|
698
698
|
expect(toasts.length).toBe(1) // toast should show error
|
|
699
699
|
expect(toasts[0].message).toBe("Test Action Failed:\nBoom!")
|
|
700
700
|
}))
|
|
@@ -724,7 +724,7 @@ it.live("fail and recover with alt", () =>
|
|
|
724
724
|
expect(r).toBe("recovered") // to confirm that the initial function has failed but we recovered
|
|
725
725
|
|
|
726
726
|
expect(command.waiting).toBe(false)
|
|
727
|
-
expect(
|
|
727
|
+
expect(AsyncResult.toExit(command.result)).toEqual(Exit.succeed("recovered"))
|
|
728
728
|
expect(toasts.length).toBe(1) // toast should show error
|
|
729
729
|
expect(toasts[0].message).toBe("Test Action Success")
|
|
730
730
|
}))
|
|
@@ -754,7 +754,7 @@ it.live("defect with alt", () =>
|
|
|
754
754
|
expect(Exit.isFailure(r) && Cause.hasDies(r.cause)).toBe(true) // to confirm that the initial function has died
|
|
755
755
|
|
|
756
756
|
expect(command.waiting).toBe(false)
|
|
757
|
-
expect(Exit.isFailure(
|
|
757
|
+
expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
|
|
758
758
|
expect(toasts.length).toBe(1) // toast should show error
|
|
759
759
|
expect(toasts[0].message).toBe("Test Action unexpected error, please try again shortly.")
|
|
760
760
|
}))
|
package/test/dist/stubs.d.ts
CHANGED
|
@@ -36,11 +36,11 @@ export declare const Req: <_Self>() => {
|
|
|
36
36
|
readonly success: C["success"] extends infer T ? T extends C["success"] ? T extends S.Top ? T : T extends S.Struct.Fields ? S.Struct<T> : S.Void : never : never;
|
|
37
37
|
readonly error: C extends {
|
|
38
38
|
error: infer E;
|
|
39
|
-
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void :
|
|
39
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never;
|
|
40
40
|
readonly config: Omit<C, "success" | "error">;
|
|
41
41
|
readonly "~decodingServices": S.Codec.DecodingServices<C["success"] extends infer T_1 ? T_1 extends C["success"] ? T_1 extends S.Top ? T_1 : T_1 extends S.Struct.Fields ? S.Struct<T_1> : S.Void : never : never> | S.Codec.DecodingServices<C extends {
|
|
42
42
|
error: infer E;
|
|
43
|
-
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void :
|
|
43
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never>;
|
|
44
44
|
};
|
|
45
45
|
<Tag extends string, Payload_1 extends S.Struct.Fields, C_1 extends Pick<{
|
|
46
46
|
success: S.Top | S.Struct.Fields;
|
|
@@ -54,11 +54,11 @@ export declare const Req: <_Self>() => {
|
|
|
54
54
|
readonly success: C_1["success"] extends infer T ? T extends C_1["success"] ? T extends S.Top ? T : T extends S.Struct.Fields ? S.Struct<T> : S.Void : never : never;
|
|
55
55
|
readonly error: C_1 extends {
|
|
56
56
|
error: infer E;
|
|
57
|
-
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void :
|
|
57
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never;
|
|
58
58
|
readonly config: Omit<C_1, "success" | "error">;
|
|
59
59
|
readonly "~decodingServices": S.Codec.DecodingServices<C_1["success"] extends infer T_1 ? T_1 extends C_1["success"] ? T_1 extends S.Top ? T_1 : T_1 extends S.Struct.Fields ? S.Struct<T_1> : S.Void : never : never> | S.Codec.DecodingServices<C_1 extends {
|
|
60
60
|
error: infer E;
|
|
61
|
-
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void :
|
|
61
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never>;
|
|
62
62
|
};
|
|
63
63
|
<Tag extends string, Payload_2 extends S.Struct.Fields, C_2 extends Pick<{
|
|
64
64
|
success: S.Top | S.Struct.Fields;
|
|
@@ -69,12 +69,14 @@ export declare const Req: <_Self>() => {
|
|
|
69
69
|
readonly fields: {
|
|
70
70
|
readonly _tag: S.tag<Tag>;
|
|
71
71
|
} & Payload_2;
|
|
72
|
-
readonly success: S.
|
|
72
|
+
readonly success: S.Codec<void, void, never, never>;
|
|
73
73
|
readonly error: C_2 extends {
|
|
74
74
|
error: infer E;
|
|
75
|
-
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void :
|
|
75
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never;
|
|
76
76
|
readonly config: Omit<C_2, "success" | "error">;
|
|
77
|
-
readonly "~decodingServices":
|
|
77
|
+
readonly "~decodingServices": S.Codec.DecodingServices<C_2 extends {
|
|
78
|
+
error: infer E;
|
|
79
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never>;
|
|
78
80
|
};
|
|
79
81
|
<Tag extends string, Payload_3 extends S.Struct.Fields, C_3 extends Record<string, any>>(tag: Tag, fields: Payload_3, config: C_3 & RpcContextMap.GetContextConfig<{}>): S.TaggedStruct<Tag, Payload_3> & {
|
|
80
82
|
new (...args: any[]): any;
|
|
@@ -82,12 +84,14 @@ export declare const Req: <_Self>() => {
|
|
|
82
84
|
readonly fields: {
|
|
83
85
|
readonly _tag: S.tag<Tag>;
|
|
84
86
|
} & Payload_3;
|
|
85
|
-
readonly success: S.
|
|
87
|
+
readonly success: S.Codec<void, void, never, never>;
|
|
86
88
|
readonly error: C_3 extends {
|
|
87
89
|
error: infer E;
|
|
88
|
-
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void :
|
|
90
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never;
|
|
89
91
|
readonly config: Omit<C_3, "success" | "error">;
|
|
90
|
-
readonly "~decodingServices":
|
|
92
|
+
readonly "~decodingServices": S.Codec.DecodingServices<C_3 extends {
|
|
93
|
+
error: infer E;
|
|
94
|
+
} ? E extends S.Top ? E : E extends S.Struct.Fields ? S.Struct<E> : S.Void : never>;
|
|
91
95
|
};
|
|
92
96
|
<Tag extends string, Payload_4 extends S.Struct.Fields>(tag: Tag, fields: Payload_4): S.TaggedStruct<Tag, Payload_4> & {
|
|
93
97
|
new (...args: any[]): any;
|
|
@@ -95,10 +99,10 @@ export declare const Req: <_Self>() => {
|
|
|
95
99
|
readonly fields: {
|
|
96
100
|
readonly _tag: S.tag<Tag>;
|
|
97
101
|
} & Payload_4;
|
|
98
|
-
readonly success: S.
|
|
102
|
+
readonly success: S.Codec<void, void, never, never>;
|
|
99
103
|
readonly error: never;
|
|
100
104
|
readonly config: Record<string, never>;
|
|
101
|
-
readonly "~decodingServices":
|
|
105
|
+
readonly "~decodingServices": never;
|
|
102
106
|
};
|
|
103
107
|
};
|
|
104
108
|
declare const GetSomething2_base: S.TaggedStruct<"GetSomething2", {
|
|
@@ -112,7 +116,7 @@ declare const GetSomething2_base: S.TaggedStruct<"GetSomething2", {
|
|
|
112
116
|
id: S.String;
|
|
113
117
|
};
|
|
114
118
|
readonly success: S.NumberFromString;
|
|
115
|
-
readonly error:
|
|
119
|
+
readonly error: never;
|
|
116
120
|
readonly config: Omit<{
|
|
117
121
|
success: S.NumberFromString;
|
|
118
122
|
}, "success" | "error">;
|
package/test/dist/stubs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubs.d.ts","sourceRoot":"","sources":["../stubs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAAU,KAAK,EAA0B,CAAC,EAAE,MAAM,YAAY,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAiB,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG9C,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAElD,OAAO,KAAK,KAAK,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;AA8CxD,eAAO,MAAM,YAAY,GAAI,WAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,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