@effect-app/vue 2.88.2 → 2.89.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/src/makeClient.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import * as Result from "@effect-atom/atom/Result"
3
- import { type InitialDataFunction, type InvalidateOptions, type InvalidateQueryFilters, isCancelledError, type QueryObserverResult, type RefetchOptions, type UseQueryReturnType } from "@tanstack/vue-query"
3
+ import { type InvalidateOptions, type InvalidateQueryFilters, isCancelledError, type QueryObserverResult, type RefetchOptions, type UseQueryReturnType } from "@tanstack/vue-query"
4
4
  import { camelCase } from "change-case"
5
5
  import { Cause, Effect, Exit, type ManagedRuntime, Match, Option, Runtime, S, Struct } from "effect-app"
6
6
  import { type ApiClientFactory, type Req } from "effect-app/client"
@@ -20,7 +20,7 @@ import { Toast } from "./experimental/toast.js"
20
20
  import { buildFieldInfoFromFieldsRoot } from "./form.js"
21
21
  import { reportRuntimeError } from "./lib.js"
22
22
  import { asResult, makeMutation, type MutationOptions, type MutationOptionsBase, mutationResultToVue, type Res, useMakeMutation } from "./mutate.js"
23
- import { type CustomDefinedInitialQueryOptions, type CustomUndefinedInitialQueryOptions, type KnownFiberFailure, makeQuery } from "./query.js"
23
+ import { type CustomUndefinedInitialQueryOptions, type KnownFiberFailure, makeQuery } from "./query.js"
24
24
 
25
25
  const mapHandler = <A, E, R, I = void, A2 = A, E2 = E, R2 = R>(
26
26
  handler: Effect.Effect<A, E, R> | ((i: I) => Effect.Effect<A, E, R>),
@@ -1120,25 +1120,6 @@ export class QueryImpl<R> {
1120
1120
  UseQueryReturnType<any, any>
1121
1121
  ]
1122
1122
  >
1123
- /**
1124
- * The difference with useQuery is that this function will return a Promise you can await in the Setup,
1125
- * which ensures that either there always is a latest value, or an error occurs on load.
1126
- * So that Suspense and error boundaries can be used.
1127
- */
1128
- <TData = A>(
1129
- options?: CustomDefinedInitialQueryOptions<A, E, TData> & {
1130
- initialData: TData | InitialDataFunction<TData>
1131
- }
1132
- ): Promise<
1133
- readonly [
1134
- ComputedRef<Result.Result<TData, E>>,
1135
- ComputedRef<TData>,
1136
- (
1137
- options?: RefetchOptions
1138
- ) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
1139
- UseQueryReturnType<any, any>
1140
- ]
1141
- >
1142
1123
  }
1143
1124
  /**
1144
1125
  * The difference with useQuery is that this function will return a Promise you can await in the Setup,
@@ -1154,24 +1135,6 @@ export class QueryImpl<R> {
1154
1135
  >(
1155
1136
  self: RequestHandlerWithInput<Arg, A, E, R, Request, Name>
1156
1137
  ): {
1157
- /**
1158
- * The difference with useQuery is that this function will return a Promise you can await in the Setup,
1159
- * which ensures that either there always is a latest value, or an error occurs on load.
1160
- * So that Suspense and error boundaries can be used.
1161
- */
1162
- <TData = A>(
1163
- arg: Arg | WatchSource<Arg>,
1164
- options?: CustomDefinedInitialQueryOptions<A, E, TData>
1165
- ): Promise<
1166
- readonly [
1167
- ComputedRef<Result.Result<TData, E>>,
1168
- ComputedRef<TData>,
1169
- (
1170
- options?: RefetchOptions
1171
- ) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
1172
- UseQueryReturnType<any, any>
1173
- ]
1174
- >
1175
1138
  /**
1176
1139
  * The difference with useQuery is that this function will return a Promise you can await in the Setup,
1177
1140
  * which ensures that either there always is a latest value, or an error occurs on load.
@@ -1518,6 +1481,8 @@ export type ToCamel<S extends string | number | symbol> = S extends string
1518
1481
  export interface CommandBase<I = void, A = void> {
1519
1482
  handle: (input: I) => A
1520
1483
  waiting: boolean
1484
+ blocked: boolean
1485
+ allowed: boolean
1521
1486
  action: string
1522
1487
  label: string
1523
1488
  }
package/src/query.ts CHANGED
@@ -55,6 +55,11 @@ export interface CustomDefinedInitialQueryOptions<
55
55
  TQueryKey extends QueryKey = QueryKey
56
56
  > extends CustomUseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
57
57
  initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)
58
+ placeholderData?:
59
+ | undefined
60
+ | NonFunctionGuard<TQueryData>
61
+ | PlaceholderDataFunction<NonFunctionGuard<TQueryData>, TError, NonFunctionGuard<TQueryData>, TQueryKey>
62
+ | undefined
58
63
  }
59
64
 
60
65
  export interface CustomDefinedPlaceholderQueryOptions<
@@ -64,6 +69,7 @@ export interface CustomDefinedPlaceholderQueryOptions<
64
69
  TQueryData = TQueryFnData,
65
70
  TQueryKey extends QueryKey = QueryKey
66
71
  > extends CustomUseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
72
+ initialData?: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>) | undefined
67
73
  placeholderData:
68
74
  | NonFunctionGuard<TQueryData>
69
75
  | PlaceholderDataFunction<NonFunctionGuard<TQueryData>, TError, NonFunctionGuard<TQueryData>, TQueryKey>
@@ -81,7 +87,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
81
87
  | RequestHandler<A, E, R, Request, Name>
82
88
  ): {
83
89
  <TData = A>(
84
- arg?: I | WatchSource<I>,
90
+ arg: I | WatchSource<I> | undefined,
85
91
  options?: CustomUndefinedInitialQueryOptions<A, E, TData>
86
92
  ): readonly [
87
93
  ComputedRef<Result.Result<TData, E>>,
@@ -91,8 +97,8 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
91
97
  ]
92
98
 
93
99
  <TData = A>(
94
- arg?: I | WatchSource<I>,
95
- options?: CustomDefinedInitialQueryOptions<A, E, TData>
100
+ arg: I | WatchSource<I> | undefined,
101
+ options: CustomDefinedInitialQueryOptions<A, E, TData>
96
102
  ): readonly [
97
103
  ComputedRef<Result.Result<TData, E>>,
98
104
  ComputedRef<TData>,
@@ -101,18 +107,8 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
101
107
  ]
102
108
 
103
109
  <TData = A>(
104
- arg?: I | WatchSource<I>,
105
- options?: CustomDefinedPlaceholderQueryOptions<A, E, TData>
106
- ): readonly [
107
- ComputedRef<Result.Result<TData, E>>,
108
- ComputedRef<TData>,
109
- (options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>, never, never>,
110
- UseQueryDefinedReturnType<TData, KnownFiberFailure<E>>
111
- ]
112
-
113
- <TData = A>(
114
- arg?: I | WatchSource<I>,
115
- options?: CustomUseQueryOptions<A, E, TData>
110
+ arg: I | WatchSource<I> | undefined,
111
+ options: CustomDefinedPlaceholderQueryOptions<A, E, TData>
116
112
  ): readonly [
117
113
  ComputedRef<Result.Result<TData, E>>,
118
114
  ComputedRef<TData>,
@@ -126,7 +122,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
126
122
  | RequestHandler<A, E, R, Request, Name>
127
123
  ) =>
128
124
  <TData = A>(
129
- arg?: I | WatchSource<I>,
125
+ arg: I | WatchSource<I> | undefined,
130
126
  // todo QueryKey type would be [string, ...string[]], but with I it would be [string, ...string[], I]
131
127
  options?: any
132
128
  // TODO
@@ -267,7 +263,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
267
263
  UseQueryReturnType<any, any>
268
264
  ]
269
265
  <TData = A>(
270
- options?: CustomDefinedPlaceholderQueryOptions<A, E, TData>
266
+ options: CustomDefinedPlaceholderQueryOptions<A, E, TData>
271
267
  ): readonly [
272
268
  ComputedRef<Result.Result<TData, E>>,
273
269
  ComputedRef<TData>,
@@ -326,8 +322,8 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
326
322
  arg: Arg | WatchSource<Arg>,
327
323
  options?: CustomUndefinedInitialQueryOptions<A, KnownFiberFailure<E>, TData>
328
324
  ): readonly [
329
- ComputedRef<Result.Result<A, E>>,
330
- ComputedRef<A | undefined>,
325
+ ComputedRef<Result.Result<TData, E>>,
326
+ ComputedRef<TData | undefined>,
331
327
  (options?: RefetchOptions) => Effect.Effect<QueryObserverResult<TData, KnownFiberFailure<E>>>,
332
328
  UseQueryReturnType<any, any>
333
329
  ]
@@ -2,6 +2,39 @@
2
2
  import { type Effect } from "effect-app"
3
3
  import { Something, useClient, useExperimental } from "./stubs.js"
4
4
 
5
+ it.skip("works2", () => {
6
+ const { legacy } = useClient()
7
+ const n = legacy.useQuery({
8
+ Request: null as any,
9
+ handler: null as any as (a: string) => Effect.Effect<number>,
10
+ id: "id"
11
+ })
12
+
13
+ const [, z] = n("a")
14
+ const valz = z.value
15
+ expectTypeOf(valz).toEqualTypeOf<number | undefined>()
16
+
17
+ const [, a] = n("a", { placeholderData: () => 123 })
18
+ const val1 = a.value
19
+ expectTypeOf(val1).toEqualTypeOf<number>()
20
+
21
+ const [, bbbb] = n("a", { select: (data) => data.toString() })
22
+ const val = bbbb.value
23
+ expectTypeOf(val).toEqualTypeOf<string | undefined>()
24
+
25
+ const [, ccc] = n("a", { placeholderData: () => 123, select: (data) => data.toString() })
26
+ const val2 = ccc.value
27
+ expectTypeOf(val2).toEqualTypeOf<string>()
28
+
29
+ const [, ddd] = n("a", { initialData: 123, select: (data) => data.toString() })
30
+ const val3 = ddd.value
31
+ expectTypeOf(val3).toEqualTypeOf<string>()
32
+
33
+ const [, eee] = n("a", { initialData: 123, placeholderData: () => 123, select: (data) => data.toString() })
34
+ const val4 = eee.value
35
+ expectTypeOf(val4).toEqualTypeOf<string>()
36
+ })
37
+
5
38
  it.skip("works", () => {
6
39
  const { clientFor, legacy } = useClient()
7
40
  const client = clientFor(Something)