@effect-app/vue 4.0.0-beta.195 → 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/src/makeClient.ts CHANGED
@@ -3,11 +3,11 @@ import { type InvalidateOptions, type InvalidateQueryFilters, isCancelledError,
3
3
  import { camelCase } from "change-case"
4
4
  import { type Context, Effect, Exit, Hash, type Layer, type ManagedRuntime, S, Struct } from "effect-app"
5
5
  import { type ApiClientFactory, type Req } from "effect-app/client"
6
- import type { ExtractModuleName, HandlerInput, RequestHandler, RequestHandlers, RequestHandlerWithInput, RequestsAny, RequestStreamHandler, RequestStreamHandlerWithInput } from "effect-app/client/clientFor"
6
+ import type { ExtractModuleName, HandlerInput, RequestHandlers, RequestHandlerWithInput, RequestsAny, RequestStreamHandlerWithInput } from "effect-app/client/clientFor"
7
7
  import type { InvalidationCallback } from "effect-app/client/makeClient"
8
8
  import type * as ExitResult from "effect/Exit"
9
9
  import { type Fiber } from "effect/Fiber"
10
- import * as Stream from "effect/Stream"
10
+ import type * as Stream from "effect/Stream"
11
11
  import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"
12
12
  import { type ComputedRef, onBeforeUnmount, ref, type WatchSource } from "vue"
13
13
  import { type Commander, CommanderStatic, type Progress } from "./commander.js"
@@ -20,24 +20,15 @@ import { type Toast } from "./toast.js"
20
20
 
21
21
  export type { Progress }
22
22
 
23
- const mapHandler = <A, E, R, I = void, A2 = A, E2 = E, R2 = R>(
24
- handler: Effect.Effect<A, E, R> | ((i: I) => Effect.Effect<A, E, R>),
25
- map: (self: Effect.Effect<A, E, R>, i: I) => Effect.Effect<A2, E2, R2>
26
- ) => Effect.isEffect(handler) ? map(handler, undefined as any) : (i: I) => map(handler(i), i)
27
-
28
23
  // TODO: optimize - work from encoded shape directly
29
24
  const projectHandler = (
30
- handler: Effect.Effect<any, any, any> | ((i: any) => Effect.Effect<any, any, any>),
25
+ handler: (i: any) => Effect.Effect<any, any, any>,
31
26
  successSchema: S.Top,
32
27
  projectionSchema: S.Top
33
28
  ) => {
34
29
  const encode = S.encodeEffect(successSchema)
35
30
  const decode = S.decodeEffectConcurrently(projectionSchema)
36
- return mapHandler(handler, (self) =>
37
- self.pipe(
38
- Effect.flatMap(encode),
39
- Effect.flatMap(decode)
40
- ))
31
+ return (i: any) => handler(i).pipe(Effect.flatMap(encode), Effect.flatMap(decode))
41
32
  }
42
33
 
43
34
  const projectionSchemaHash = (schema: S.Top) => String(Hash.hash(schema.ast))
@@ -46,53 +37,41 @@ export interface CommandRequestExtensions<RT, Id extends string, I, A, E, R> {
46
37
  /** Defines a Command based on this call, taking the `id` of the call as the `id` of the Command.
47
38
  * The Request function will be taken as the first member of the Command, the Command required input will be the Request input.
48
39
  * see Command.wrap for details */
49
- wrap: Commander.CommanderWrap<RT, Id, Id, undefined, I, A, E, R>
40
+ wrap: <I18nKey extends string = Id, State extends Commander.IntlRecord | undefined = undefined>(
41
+ options?: Commander.FnOptions<Id, I18nKey, State>
42
+ ) => Commander.CommanderWrap<RT, Id, I18nKey, State, I, A, E, R>
50
43
  /** Defines a Command based on this call, taking the `id` of the call as the `id` of the Command.
51
44
  * see Command.fn for details */
52
- fn: Commander.CommanderFn<RT, Id, Id, undefined>
45
+ fn: <I18nKey extends string = Id, State extends Commander.IntlRecord | undefined = undefined>(
46
+ options?: Commander.FnOptions<Id, I18nKey, State>
47
+ ) => Commander.CommanderFn<RT, Id, I18nKey, State>
53
48
  }
54
49
 
55
50
  /** my other doc */
56
- export interface RequestExtWithInput<
57
- RT,
58
- Id extends string,
59
- I,
60
- A,
61
- E,
62
- R
63
- > extends Commander.CommandContextLocal<Id, Id>, CommandRequestExtensions<RT, Id, I, A, E, R> {
64
- /**
65
- * Send the request to the endpoint and return the raw Effect response.
66
- * This does not perform query cache invalidation.
67
- */
68
- request: (i: I) => Effect.Effect<A, E, R>
69
- }
70
-
71
51
  export interface RequestExt<
72
52
  RT,
73
53
  Id extends string,
54
+ I,
74
55
  A,
75
56
  E,
76
57
  R
77
58
  > extends
78
59
  Commander.CommandContextLocal<Id, Id>,
79
- Commander.CommanderWrap<RT, Id, Id, undefined, void, A, E, R>,
80
- CommandRequestExtensions<RT, Id, void, A, E, R>
60
+ Commander.CommanderWrap<RT, Id, Id, undefined, I, A, E, R>,
61
+ CommandRequestExtensions<RT, Id, I, A, E, R>
81
62
  {
82
63
  /**
83
64
  * Send the request to the endpoint and return the raw Effect response.
84
65
  * This does not perform query cache invalidation.
85
66
  */
86
- request: Effect.Effect<A, E, R>
67
+ request: (i: I) => Effect.Effect<A, E, R>
87
68
  }
88
69
 
89
70
  export type CommandRequestWithExtensions<RT, Req> = Req extends
90
- RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer _Request, infer Id>
91
- ? RequestExtWithInput<RT, Id, I, A, E, R>
92
- : Req extends RequestHandler<infer A, infer E, infer R, infer _Request, infer Id> ? RequestExt<RT, Id, A, E, R>
71
+ RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer _Request, infer Id> ? RequestExt<RT, Id, I, A, E, R>
93
72
  : never
94
73
 
95
- export interface QueryExtensionsWithInput<I, A, E, R> {
74
+ export interface QueryExtensions<I, A, E, R> {
96
75
  /**
97
76
  * Send the request to the endpoint and return the raw Effect response.
98
77
  * This does not set up query state tracking.
@@ -100,85 +79,37 @@ export interface QueryExtensionsWithInput<I, A, E, R> {
100
79
  request: (i: I) => Effect.Effect<A, E, R>
101
80
  }
102
81
 
103
- export interface QueryExtensions<A, E, R> {
104
- /**
105
- * Send the request to the endpoint and return the raw Effect response.
106
- * This does not set up query state tracking.
107
- */
108
- request: Effect.Effect<A, E, R>
109
- }
110
-
111
82
  export type QueryRequestWithExtensions<Req> = Req extends
112
- RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer _Request, infer _Id>
113
- ? QueryExtensionsWithInput<I, A, E, R>
114
- : Req extends RequestHandler<infer A, infer E, infer R, infer _Request, infer _Id> ? QueryExtensions<A, E, R>
83
+ RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer _Request, infer _Id> ? QueryExtensions<I, A, E, R>
115
84
  : never
116
85
 
117
86
  type QueryHandler<Req> = Req extends
118
87
  RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id>
119
88
  ? Request["type"] extends "query" ? RequestHandlerWithInput<I, A, E, R, Request, Id> : never
120
- : Req extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id>
121
- ? Request["type"] extends "query" ? RequestHandler<A, E, R, Request, Id> : never
122
89
  : never
123
90
 
124
91
  type CommandHandler<Req> = Req extends
125
92
  RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id>
126
93
  ? Request["type"] extends "command" ? RequestHandlerWithInput<I, A, E, R, Request, Id> : never
127
- : Req extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id>
128
- ? Request["type"] extends "command" ? RequestHandler<A, E, R, Request, Id> : never
129
94
  : never
130
95
 
131
96
  type StreamHandler<Req> = Req extends
132
97
  RequestStreamHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id, infer Final>
133
98
  ? Request["type"] extends "stream" ? RequestStreamHandlerWithInput<I, A, E, R, Request, Id, Final> : never
134
- : Req extends RequestStreamHandler<infer A, infer E, infer R, infer Request, infer Id, infer Final>
135
- ? Request["type"] extends "stream" ? RequestStreamHandler<A, E, R, Request, Id, Final> : never
136
99
  : never
137
100
 
138
101
  export interface MutationExtensions<RT, Id extends string, I, A, E, R> {
139
102
  /** Defines a Command based on this mutation, taking the `id` of the mutation as the `id` of the Command.
140
103
  * The Mutation function will be taken as the first member of the Command, the Command required input will be the Mutation input.
141
104
  * see Command.wrap for details */
142
- wrap: Commander.CommanderWrap<RT, Id, Id, undefined, I, A, E, R>
143
- }
144
-
145
- /** my other doc */
146
- export interface MutationExtWithInput<
147
- RT,
148
- Id extends string,
149
- I,
150
- A,
151
- E,
152
- R,
153
- EA = unknown
154
- > extends MutationExtensions<RT, Id, I, A, E, R> {
155
- /**
156
- * Send the request to the endpoint and return the raw Effect response.
157
- * Also invalidates query caches using the request namespace by default.
158
- * Namespace invalidation targets parent namespace keys
159
- * (for example `$project/$configuration.get` invalidates `$project`).
160
- * Override invalidation in client options via `queryInvalidation`.
161
- *
162
- * Pass `options` to attach a `select` Effect that runs after the mutation
163
- * succeeds (its output is returned to the caller) and/or override the default
164
- * `queryInvalidation`.
165
- */
166
- <B = A, E2 = never, R2 = never>(
167
- input: I,
168
- options?: MutationOptionsBase<A, B, E2, R2>
169
- ): Effect.Effect<B, E | E2, R | R2>
170
-
171
- project: <ProjSchema extends S.Top>(
172
- schema: EA extends ProjSchema["Encoded"] ? ProjSchema : never
173
- ) => MutationExtWithInput<
174
- RT,
175
- Id,
176
- I,
177
- S.Schema.Type<ProjSchema>,
178
- E | S.SchemaError,
179
- R | S.Codec.DecodingServices<ProjSchema>,
180
- S.Codec.Encoded<ProjSchema>
181
- >
105
+ wrap: <I18nKey extends string = Id, State extends Commander.IntlRecord | undefined = undefined>(
106
+ options?: Commander.FnOptions<Id, I18nKey, State>
107
+ ) => Commander.CommanderWrap<RT, Id, I18nKey, State, I, A, E, R>
108
+ /** Defines a Command based on this call, taking the `id` of the mutation as the `id` of the Command.
109
+ * see Command.fn for details */
110
+ fn: <I18nKey extends string = Id, State extends Commander.IntlRecord | undefined = undefined>(
111
+ options?: Commander.FnOptions<Id, I18nKey, State>
112
+ ) => Commander.CommanderFn<RT, Id, I18nKey, State>
182
113
  }
183
114
 
184
115
  /**
@@ -187,24 +118,24 @@ export interface MutationExtWithInput<
187
118
  * Namespace invalidation targets parent namespace keys
188
119
  * (for example `$project/$configuration.get` invalidates `$project`).
189
120
  * Override invalidation in client options via `queryInvalidation`.
121
+ *
122
+ * Pass `options` to attach a `select` Effect that runs after the mutation
123
+ * succeeds (its output is returned to the caller) and/or override the default
124
+ * `queryInvalidation`.
125
+ *
126
+ * When `I = void` the input argument may be omitted.
190
127
  */
191
128
  export interface MutationExt<
192
129
  RT,
193
130
  Id extends string,
131
+ I,
194
132
  A,
195
133
  E,
196
134
  R,
197
135
  EA = unknown
198
- > extends MutationExtensions<RT, Id, void, A, E, R> {
199
- /**
200
- * Send the request to the endpoint and return the raw Effect response.
201
- * Also invalidates query caches using the request namespace by default.
202
- *
203
- * Pass `options` to attach a `select` Effect that runs after the mutation
204
- * succeeds (its output is returned to the caller) and/or override the default
205
- * `queryInvalidation`.
206
- */
136
+ > extends MutationExtensions<RT, Id, I, A, E, R> {
207
137
  <B = A, E2 = never, R2 = never>(
138
+ input: I,
208
139
  options?: MutationOptionsBase<A, B, E2, R2>
209
140
  ): Effect.Effect<B, E | E2, R | R2>
210
141
 
@@ -213,6 +144,7 @@ export interface MutationExt<
213
144
  ) => MutationExt<
214
145
  RT,
215
146
  Id,
147
+ I,
216
148
  S.Schema.Type<ProjSchema>,
217
149
  E | S.SchemaError,
218
150
  R | S.Codec.DecodingServices<ProjSchema>,
@@ -222,9 +154,7 @@ export interface MutationExt<
222
154
 
223
155
  export type MutationWithExtensions<RT, Req> = Req extends
224
156
  RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id>
225
- ? MutationExtWithInput<RT, Id, I, A, E, R, S.Codec.Encoded<Request["success"]>>
226
- : Req extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id>
227
- ? MutationExt<RT, Id, A, E, R, S.Codec.Encoded<Request["success"]>>
157
+ ? MutationExt<RT, Id, I, A, E, R, S.Codec.Encoded<Request["success"]>>
228
158
  : never
229
159
 
230
160
  /**
@@ -233,8 +163,6 @@ export type MutationWithExtensions<RT, Req> = Req extends
233
163
  export type StreamFnStreamExtension<RT, Req> = Req extends
234
164
  RequestStreamHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id, infer _Final>
235
165
  ? Commander.StreamGen<RT, Id, Id, undefined> & Commander.NonGenStream<RT, Id, Id, undefined>
236
- : Req extends RequestStreamHandler<infer _A, infer _E, infer _R, infer _Request, infer Id, infer _Final>
237
- ? Commander.StreamGen<RT, Id, Id, undefined> & Commander.NonGenStream<RT, Id, Id, undefined>
238
166
  : never
239
167
 
240
168
  /**
@@ -246,14 +174,10 @@ export type StreamMutation2WithExtensions<RT, Req> = Req extends
246
174
  & ((input: I) => Stream.Stream<A, E, R>)
247
175
  & {
248
176
  readonly id: Id
249
- readonly wrap: Commander.StreamerWrap<RT, Id, Id, undefined, I, A, E, R>
177
+ readonly wrap: <I18nKey extends string = Id, State extends Commander.IntlRecord | undefined = undefined>(
178
+ options?: Commander.FnOptions<Id, I18nKey, State>
179
+ ) => Commander.StreamerWrap<RT, Id, I18nKey, State, I, A, E, R>
250
180
  }
251
- : Req extends RequestStreamHandler<infer A, infer E, infer R, infer _Request, infer Id, infer _Final> ?
252
- & Stream.Stream<A, E, R>
253
- & {
254
- readonly id: Id
255
- readonly wrap: Commander.StreamerWrap<RT, Id, Id, undefined, void, A, E, R>
256
- }
257
181
  : never
258
182
 
259
183
  // we don't really care about the RT, as we are in charge of ensuring runtime safety anyway
@@ -288,28 +212,14 @@ export type QueryProjection<RT, HandlerReq> = HandlerReq extends
288
212
  >
289
213
  }
290
214
  : {}
291
- : HandlerReq extends RequestHandler<infer _A, infer E, infer R, infer Request, infer Id>
292
- ? Request["type"] extends "query" ? {
293
- project: <ProjSchema extends S.Top>(
294
- schema: S.Codec.Encoded<Request["success"]> extends ProjSchema["Encoded"] ? ProjSchema : never
295
- ) => ProjectResult<
296
- RT,
297
- void,
298
- S.Schema.Type<ProjSchema>,
299
- E | S.SchemaError,
300
- R | S.Codec.DecodingServices<ProjSchema>,
301
- Request,
302
- Id
303
- >
304
- }
305
- : {}
306
215
  : {}
307
216
 
308
- export interface QueriesWithInput<Request extends Req, Id extends string, I, A, E> {
217
+ export interface QueryResultExtensions<Request extends Req, Id extends string, I, A, E> {
309
218
  /**
310
219
  * Read helper for query requests.
311
220
  * Runs as a tracked Vue Query and returns reactive state.
312
221
  * Queries read state and should not be used to mutate it.
222
+ * When `I = void` the input argument may be omitted.
313
223
  */
314
224
  query: ReturnType<typeof useQuery_<I, E, A, Request, Id>>
315
225
  // TODO or suspense as Option?
@@ -319,20 +229,6 @@ export interface QueriesWithInput<Request extends Req, Id extends string, I, A,
319
229
  */
320
230
  suspense: ReturnType<typeof useSuspenseQuery_<I, E, A, Request, Id>>
321
231
  }
322
- export interface QueriesWithoutInput<Request extends Req, Id extends string, A, E> {
323
- /**
324
- * Read helper for query requests.
325
- * Runs as a tracked Vue Query and returns reactive state.
326
- * Queries read state and should not be used to mutate it.
327
- */
328
- query: ReturnType<typeof useQuery_<E, A, Request, Id>>
329
- // TODO or suspense as Option?
330
- /**
331
- * Like `.query`, but returns a Promise for setup-time awaiting.
332
- * Use this when integrating with Vue Suspense / error boundaries.
333
- */
334
- suspense: ReturnType<typeof useSuspenseQuery_<E, A, Request, Id>>
335
- }
336
232
 
337
233
  export type MissingDependencies<RT, R> = {
338
234
  message: "Dependencies required that are not provided by the runtime"
@@ -341,52 +237,33 @@ export type MissingDependencies<RT, R> = {
341
237
 
342
238
  export type Queries<RT, Req> = Req extends
343
239
  RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id>
344
- ? Request["type"] extends "query" ? Exclude<R, RT> extends never ? QueriesWithInput<Request, Id, I, A, E>
345
- : {
346
- query: MissingDependencies<RT, R> & {}
347
- suspense: MissingDependencies<RT, R> & {}
348
- }
240
+ ? Request["type"] extends "query" ? Exclude<R, RT> extends never ? QueryResultExtensions<Request, Id, I, A, E>
241
+ : { query: MissingDependencies<RT, R> & {}; suspense: MissingDependencies<RT, R> & {} }
349
242
  : never
350
- : Req extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id>
351
- ? Request["type"] extends "query" ? Exclude<R, RT> extends never ? QueriesWithoutInput<Request, Id, A, E>
352
- : { query: MissingDependencies<RT, R> & {}; suspense: MissingDependencies<RT, R> & {} }
353
- : never
354
243
  : never
355
244
 
356
- export interface StreamQueriesWithInput<Request extends Req, Id extends string, I, A, E> {
245
+ export interface StreamQueryExtensions<Request extends Req, Id extends string, I, A, E> {
357
246
  /**
358
247
  * Stream helper for stream requests.
359
248
  * Runs as a tracked Vue Query and returns reactive state with accumulated chunks.
360
249
  * Data is an array of all chunks received so far.
250
+ * When `I = void` the input argument may be omitted.
361
251
  */
362
252
  streamQuery: ReturnType<typeof useStreamQuery_<I, E, A, Request, Id>>
363
253
  }
364
- export interface StreamQueriesWithoutInput<Request extends Req, Id extends string, A, E> {
365
- /**
366
- * Stream helper for stream requests.
367
- * Runs as a tracked Vue Query and returns reactive state with accumulated chunks.
368
- * Data is an array of all chunks received so far.
369
- */
370
- streamQuery: ReturnType<typeof useStreamQuery_<E, A, Request, Id>>
371
- }
372
254
 
373
255
  export type StreamQueries<RT, HandlerReq> = HandlerReq extends
374
256
  RequestStreamHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id, infer _Final>
375
- ? Exclude<R, RT> extends never ? StreamQueriesWithInput<Request, Id, I, A, E>
257
+ ? Exclude<R, RT> extends never ? StreamQueryExtensions<Request, Id, I, A, E>
376
258
  : { streamQuery: MissingDependencies<RT, R> & {} }
377
- : HandlerReq extends RequestStreamHandler<infer A, infer E, infer R, infer Request, infer Id, infer _Final>
378
- ? Exclude<R, RT> extends never ? StreamQueriesWithoutInput<Request, Id, A, E>
379
- : { streamQuery: MissingDependencies<RT, R> & {} }
380
259
  : never
381
260
 
382
261
  const _useMutation = makeMutation()
383
262
 
384
- const wrapWithSpan = (self: { id: string; handler: any }, mut: any) => {
263
+ const wrapWithSpan = (self: { id: string }, mut: any) => {
385
264
  const span = (eff: Effect.Effect<any, any, any>) =>
386
265
  Effect.withSpan(`mutation ${self.id}`, {}, { captureStackTrace: false })(eff)
387
- return Effect.isEffect(self.handler)
388
- ? (options?: MutationOptionsBase) => span(mut(options))
389
- : (input: any, options?: MutationOptionsBase) => span(mut(input, options))
266
+ return (input: any, options?: MutationOptionsBase) => span(mut(input, options))
390
267
  }
391
268
 
392
269
  /**
@@ -402,7 +279,7 @@ export const useMutation: typeof _useMutation = (<
402
279
  Request extends Req,
403
280
  Name extends string
404
281
  >(
405
- self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name>
282
+ self: RequestHandlerWithInput<I, A, E, R, Request, Name>
406
283
  ) =>
407
284
  Object.assign(
408
285
  wrapWithSpan(self, _useMutation(self as any)),
@@ -424,7 +301,7 @@ export const useMutationInt = (): typeof _useMutation => {
424
301
  Request extends Req,
425
302
  Name extends string
426
303
  >(
427
- self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name>
304
+ self: RequestHandlerWithInput<I, A, E, R, Request, Name>
428
305
  ) =>
429
306
  Object.assign(
430
307
  wrapWithSpan(self, _useMutation(self as any)),
@@ -462,52 +339,18 @@ export class QueryImpl<R> {
462
339
  * The difference with useQuery is that this function will return a Promise you can await in the Setup,
463
340
  * which ensures that either there always is a latest value, or an error occurs on load.
464
341
  * So that Suspense and error boundaries can be used.
465
- * @deprecated use client helpers instead (.suspense())
466
- */
467
- <
468
- E,
469
- A,
470
- Request extends Req,
471
- Name extends string
472
- >(
473
- self: RequestHandler<A, E, R, Request, Name>
474
- ): {
475
- /**
476
- * The difference with useQuery is that this function will return a Promise you can await in the Setup,
477
- * which ensures that either there always is a latest value, or an error occurs on load.
478
- * So that Suspense and error boundaries can be used.
479
- */
480
- <TData = A>(options?: CustomUndefinedInitialQueryOptions<A, E, TData>): Promise<
481
- readonly [
482
- ComputedRef<AsyncResult.AsyncResult<TData, E>>,
483
- ComputedRef<TData>,
484
- (
485
- options?: RefetchOptions
486
- ) => Effect.Effect<QueryObserverResult<TData, E>>,
487
- UseQueryReturnType<any, any>
488
- ]
489
- >
490
- }
491
- /**
492
- * The difference with useQuery is that this function will return a Promise you can await in the Setup,
493
- * which ensures that either there always is a latest value, or an error occurs on load.
494
- * So that Suspense and error boundaries can be used.
342
+ * When `I = void` the input argument may be omitted.
495
343
  */
496
344
  <
497
- Arg,
345
+ I,
498
346
  E,
499
347
  A,
500
348
  Request extends Req,
501
349
  Name extends string
502
350
  >(
503
- self: RequestHandlerWithInput<Arg, A, E, R, Request, Name>
351
+ self: RequestHandlerWithInput<I, A, E, R, Request, Name>
504
352
  ): {
505
- /**
506
- * The difference with useQuery is that this function will return a Promise you can await in the Setup,
507
- * which ensures that either there always is a latest value, or an error occurs on load.
508
- * So that Suspense and error boundaries can be used.
509
- */
510
- <TData = A>(arg: Arg | WatchSource<Arg>, options?: CustomUndefinedInitialQueryOptions<A, E, TData>): Promise<
353
+ <TData = A>(arg: I | WatchSource<I>, options?: CustomUndefinedInitialQueryOptions<A, E, TData>): Promise<
511
354
  readonly [
512
355
  ComputedRef<AsyncResult.AsyncResult<TData, E>>,
513
356
  ComputedRef<TData>,
@@ -518,8 +361,8 @@ export class QueryImpl<R> {
518
361
  ]
519
362
  >
520
363
  }
521
- } = <Arg, E, A, Request extends Req, Name extends string>(
522
- self: RequestHandlerWithInput<Arg, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name>
364
+ } = <I, E, A, Request extends Req, Name extends string>(
365
+ self: RequestHandlerWithInput<I, A, E, R, Request, Name>
523
366
  ) => {
524
367
  const runPromise = makeRunPromise(this.getRuntime())
525
368
  const q = this.useQuery(self as any) as any
@@ -668,7 +511,6 @@ export const makeClient = <RT_, RTHooks>(
668
511
 
669
512
  const withDefaultInvalidation = (
670
513
  mut: any,
671
- isWithInput: boolean,
672
514
  defaultInvalidation?: MutationOptionsBase["queryInvalidation"]
673
515
  ) => {
674
516
  if (!defaultInvalidation) return mut
@@ -678,9 +520,7 @@ export const makeClient = <RT_, RTHooks>(
678
520
  ? mergeInvalidation(defaultInvalidation, callerOpts.queryInvalidation)
679
521
  : defaultInvalidation
680
522
  })
681
- return isWithInput
682
- ? (input: any, callerOpts?: MutationOptionsBase) => mut(input, apply(callerOpts))
683
- : (callerOpts?: MutationOptionsBase) => mut(apply(callerOpts))
523
+ return (input: any, callerOpts?: MutationOptionsBase) => mut(input, apply(callerOpts))
684
524
  }
685
525
 
686
526
  const makeQueryResources = <Resources extends InvalidationResources>(resources: Resources | undefined) => {
@@ -749,12 +589,13 @@ export const makeClient = <RT_, RTHooks>(
749
589
  return acc
750
590
  }
751
591
  const mut = client[key].handler
752
- const fn = Command.fn(client[key].id)
753
- const wrap = Command.wrap({ mutate: Effect.isEffect(mut) ? () => mut : mut, id: client[key].id })
592
+ const request = mut
593
+ const fn = (options?: any) => Command.fn(client[key].id, options)
594
+ const wrap = (options?: any) => Command.wrap({ mutate: request, id: client[key].id }, options)
754
595
  ;(acc as any)[camelCase(key) + "Request"] = Object.assign(
755
596
  mut,
756
- fn, // to get the i18n key etc.
757
- { wrap, fn }
597
+ Command.fn(client[key].id), // to get the i18n key etc.
598
+ { wrap, fn, request }
758
599
  )
759
600
  return acc
760
601
  },
@@ -797,11 +638,10 @@ export const makeClient = <RT_, RTHooks>(
797
638
  : undefined
798
639
  const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key])
799
640
  const makeProjectedMutation = (handler: any): any => {
800
- const isWithInput = !Effect.isEffect(handler.handler)
801
- const mut: any = withDefaultInvalidation(mutation(handler), isWithInput, mergedInvalidation)
802
- const wrap = Command.wrap({ mutate: mut, id: client[key].id })
641
+ const mut: any = withDefaultInvalidation(mutation(handler), mergedInvalidation)
803
642
  return Object.assign(mut, {
804
- wrap,
643
+ wrap: (options?: any) => Command.wrap({ mutate: mut, id: client[key].id }, options),
644
+ fn: (options?: any) => Command.fn(client[key].id, options),
805
645
  project: (projectionSchema: any) => {
806
646
  const projected = {
807
647
  ...handler,
@@ -845,10 +685,7 @@ export const makeClient = <RT_, RTHooks>(
845
685
  const requestType = client[key].Request.type
846
686
  const fn = Command.fn(client[key].id)
847
687
  const h_ = client[key].handler
848
- const wrapInput = Effect.isEffect(h_)
849
- ? () => h_
850
- : (...args: [any]) => h_(...args)
851
- const request = Effect.isEffect(h_) ? h_ : wrapInput
688
+ const request = h_
852
689
  ;(acc as any)[key] = Object.assign(
853
690
  requestType === "query"
854
691
  ? {
@@ -889,20 +726,18 @@ export const makeClient = <RT_, RTHooks>(
889
726
  })))
890
727
  : undefined
891
728
  const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key])
729
+ const streamCmd = useCommand()
892
730
  return {
893
731
  ...client[key],
894
- request: h_,
732
+ request,
895
733
  streamQuery: useStreamQuery(client[key] as any),
896
- streamFn: useCommand().streamFn(client[key].id as any) as any,
734
+ streamFn: streamCmd.streamFn(client[key].id as any) as any,
897
735
  mutate: (() => {
898
736
  const sm2Act = useStreamMutation2()(client[key] as any, mergedInvalidation)
899
- const originalHandler = (client[key] as any).handler
900
- const sm2Handler = Stream.isStream(originalHandler)
901
- ? (_input: any, _ctx: any) => sm2Act
902
- : (input: any, _ctx: any) => (sm2Act as (i: any) => any)(input)
737
+ const sm2Handler = (input: any, _ctx: any) => (sm2Act as (i: any) => any)(input)
903
738
  return Object.assign(sm2Act, {
904
739
  id: client[key].id,
905
- wrap: useCommand().streamWrap(sm2Handler, client[key].id as any)
740
+ wrap: (options?: any) => streamCmd.streamWrap(sm2Handler, client[key].id as any, options)
906
741
  })
907
742
  })()
908
743
  }
@@ -923,15 +758,16 @@ export const makeClient = <RT_, RTHooks>(
923
758
  : undefined
924
759
  const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key])
925
760
  const makeProjectedMutation = (h: any): any => {
926
- const isWithInput = !Effect.isEffect(h.handler)
927
- const mutate = withDefaultInvalidation(mutation(h), isWithInput, mergedInvalidation)
761
+ const mutate = withDefaultInvalidation(mutation(h), mergedInvalidation)
928
762
  return Object.assign(
929
763
  mutate,
930
764
  {
931
- wrap: Command.wrap({
932
- mutate,
933
- id: client[key].id
934
- }),
765
+ wrap: (options?: any) =>
766
+ Command.wrap({
767
+ mutate,
768
+ id: client[key].id
769
+ }, options),
770
+ fn: (options?: any) => Command.fn(client[key].id, options),
935
771
  project: (projectionSchema: any) => {
936
772
  const projected = {
937
773
  ...h,
@@ -947,8 +783,8 @@ export const makeClient = <RT_, RTHooks>(
947
783
  ...client[key],
948
784
  ...fn, // to get the i18n key etc.
949
785
  request,
950
- fn,
951
- wrap: Command.wrap({ mutate: wrapInput, id: client[key].id })
786
+ fn: (options?: any) => Command.fn(client[key].id, options),
787
+ wrap: (options?: any) => Command.wrap({ mutate: h_, id: client[key].id }, options)
952
788
  }
953
789
  )
954
790
  return acc