@effect-app/vue 4.0.0-beta.196 → 4.0.0-beta.197

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
@@ -93,9 +93,18 @@ type CommandHandler<Req> = Req extends
93
93
  ? Request["type"] extends "command" ? RequestHandlerWithInput<I, A, E, R, Request, Id> : never
94
94
  : never
95
95
 
96
- type StreamHandler<Req> = Req extends
96
+ type QueryStreamHandler<Req> = Req extends
97
97
  RequestStreamHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id, infer Final>
98
- ? Request["type"] extends "stream" ? RequestStreamHandlerWithInput<I, A, E, R, Request, Id, Final> : never
98
+ ? [Request["stream"], Request["type"]] extends [true, "query"]
99
+ ? RequestStreamHandlerWithInput<I, A, E, R, Request, Id, Final>
100
+ : never
101
+ : never
102
+
103
+ type CommandStreamHandler<Req> = Req extends
104
+ RequestStreamHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id, infer Final>
105
+ ? [Request["stream"], Request["type"]] extends [true, "command"]
106
+ ? RequestStreamHandlerWithInput<I, A, E, R, Request, Id, Final>
107
+ : never
99
108
  : never
100
109
 
101
110
  export interface MutationExtensions<RT, Id extends string, I, A, E, R> {
@@ -244,18 +253,17 @@ export type Queries<RT, Req> = Req extends
244
253
 
245
254
  export interface StreamQueryExtensions<Request extends Req, Id extends string, I, A, E> {
246
255
  /**
247
- * Stream helper for stream requests.
256
+ * Stream helper for query-stream requests.
248
257
  * Runs as a tracked Vue Query and returns reactive state with accumulated chunks.
249
258
  * Data is an array of all chunks received so far.
250
259
  * When `I = void` the input argument may be omitted.
251
260
  */
252
- streamQuery: ReturnType<typeof useStreamQuery_<I, E, A, Request, Id>>
261
+ query: ReturnType<typeof useStreamQuery_<I, E, A, Request, Id>>
253
262
  }
254
-
255
263
  export type StreamQueries<RT, HandlerReq> = HandlerReq extends
256
264
  RequestStreamHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id, infer _Final>
257
265
  ? Exclude<R, RT> extends never ? StreamQueryExtensions<Request, Id, I, A, E>
258
- : { streamQuery: MissingDependencies<RT, R> & {} }
266
+ : { query: MissingDependencies<RT, R> & {} }
259
267
  : never
260
268
 
261
269
  const _useMutation = makeMutation()
@@ -324,7 +332,7 @@ export class QueryImpl<R> {
324
332
 
325
333
  /**
326
334
  * Stream results are accumulated as an array of chunks and returned as reactive state.
327
- * @deprecated use client helpers instead (.streamQuery())
335
+ * @deprecated use client helpers instead (.query())
328
336
  */
329
337
  readonly useStreamQuery: ReturnType<typeof makeStreamQuery<R>>
330
338
 
@@ -536,15 +544,16 @@ export const makeClient = <RT_, RTHooks>(
536
544
  const queries = Struct.keys(client).reduce(
537
545
  (acc, key) => {
538
546
  const requestType = client[key].Request.type
539
- if (requestType === "query") {
547
+ const isStream = client[key].Request.stream
548
+ if (requestType === "query" && !isStream) {
540
549
  ;(acc as any)[camelCase(key) + "Query"] = Object.assign(useQuery(client[key] as any), {
541
550
  id: client[key].id
542
551
  })
543
552
  ;(acc as any)[camelCase(key) + "SuspenseQuery"] = Object.assign(useSuspenseQuery(client[key] as any), {
544
553
  id: client[key].id
545
554
  })
546
- } else if (requestType === "stream") {
547
- ;(acc as any)[camelCase(key) + "StreamQuery"] = Object.assign(useStreamQuery(client[key] as any), {
555
+ } else if (requestType === "query" && isStream) {
556
+ ;(acc as any)[camelCase(key) + "Query"] = Object.assign(useStreamQuery(client[key] as any), {
548
557
  id: client[key].id
549
558
  })
550
559
  }
@@ -571,9 +580,9 @@ export const makeClient = <RT_, RTHooks>(
571
580
  }
572
581
  & {
573
582
  [
574
- Key in keyof typeof client as StreamHandler<typeof client[Key]> extends never ? never
575
- : `${ToCamel<string & Key>}StreamQuery`
576
- ]: StreamQueries<RT, StreamHandler<typeof client[Key]>>["streamQuery"]
583
+ Key in keyof typeof client as QueryStreamHandler<typeof client[Key]> extends never ? never
584
+ : `${ToCamel<string & Key>}Query`
585
+ ]: StreamQueries<RT, QueryStreamHandler<typeof client[Key]>>["query"]
577
586
  }
578
587
  )
579
588
  return queries
@@ -585,7 +594,7 @@ export const makeClient = <RT_, RTHooks>(
585
594
  const Command = useCommand()
586
595
  const mutations = Struct.keys(client).reduce(
587
596
  (acc, key) => {
588
- if (client[key].Request.type !== "command") {
597
+ if (!(client[key].Request.type === "command" && !client[key].Request.stream)) {
589
598
  return acc
590
599
  }
591
600
  const mut = client[key].handler
@@ -623,7 +632,7 @@ export const makeClient = <RT_, RTHooks>(
623
632
  const queryResources = makeQueryResources(invalidationResources)
624
633
  const mutations = Struct.keys(client).reduce(
625
634
  (acc, key) => {
626
- if (client[key].Request.type !== "command") {
635
+ if (!(client[key].Request.type === "command" && !client[key].Request.stream)) {
627
636
  return acc
628
637
  }
629
638
  const fromRequestConfig = client[key].Request.config?.["invalidatesQueries"] as
@@ -683,11 +692,12 @@ export const makeClient = <RT_, RTHooks>(
683
692
  const extended = Struct.keys(client).reduce(
684
693
  (acc, key) => {
685
694
  const requestType = client[key].Request.type
695
+ const isStream = client[key].Request.stream
686
696
  const fn = Command.fn(client[key].id)
687
697
  const h_ = client[key].handler
688
698
  const request = h_
689
699
  ;(acc as any)[key] = Object.assign(
690
- requestType === "query"
700
+ requestType === "query" && !isStream
691
701
  ? {
692
702
  ...client[key],
693
703
  request,
@@ -711,7 +721,13 @@ export const makeClient = <RT_, RTHooks>(
711
721
  }
712
722
  }
713
723
  }
714
- : requestType === "stream"
724
+ : requestType === "query" && isStream
725
+ ? {
726
+ ...client[key],
727
+ request,
728
+ query: useStreamQuery(client[key] as any)
729
+ }
730
+ : requestType === "command" && isStream
715
731
  ? (() => {
716
732
  const fromRequestConfig = client[key].Request.config?.["invalidatesQueries"] as
717
733
  | InvalidationCallback<InvalidationResourcesFor<M>>
@@ -730,8 +746,8 @@ export const makeClient = <RT_, RTHooks>(
730
746
  return {
731
747
  ...client[key],
732
748
  request,
733
- streamQuery: useStreamQuery(client[key] as any),
734
- streamFn: streamCmd.streamFn(client[key].id as any) as any,
749
+ query: useStreamQuery(client[key] as any),
750
+ fn: streamCmd.streamFn(client[key].id as any) as any,
735
751
  mutate: (() => {
736
752
  const sm2Act = useStreamMutation2()(client[key] as any, mergedInvalidation)
737
753
  const sm2Handler = (input: any, _ctx: any) => (sm2Act as (i: any) => any)(input)
@@ -797,16 +813,16 @@ export const makeClient = <RT_, RTHooks>(
797
813
  & QueryRequestWithExtensions<QueryHandler<typeof client[Key]>>
798
814
  & Queries<RT, QueryHandler<typeof client[Key]>>
799
815
  & QueryProjection<RT, QueryHandler<typeof client[Key]>>)
800
- & (StreamHandler<typeof client[Key]> extends never ? {}
801
- : StreamQueries<RT, StreamHandler<typeof client[Key]>>)
816
+ & (QueryStreamHandler<typeof client[Key]> extends never ? {}
817
+ : StreamQueries<RT, QueryStreamHandler<typeof client[Key]>>)
802
818
  & (CommandHandler<typeof client[Key]> extends never ? {}
803
819
  : CommandRequestWithExtensions<RT | RTHooks, CommandHandler<typeof client[Key]>>)
804
820
  & (CommandHandler<typeof client[Key]> extends never ? {}
805
821
  : { mutate: MutationWithExtensions<RT | RTHooks, CommandHandler<typeof client[Key]>> })
806
- & (StreamHandler<typeof client[Key]> extends never ? {}
822
+ & (CommandStreamHandler<typeof client[Key]> extends never ? {}
807
823
  : {
808
- streamFn: StreamFnStreamExtension<RT | RTHooks, StreamHandler<typeof client[Key]>>
809
- mutate: StreamMutation2WithExtensions<RT | RTHooks, StreamHandler<typeof client[Key]>>
824
+ fn: StreamFnStreamExtension<RT | RTHooks, CommandStreamHandler<typeof client[Key]>>
825
+ mutate: StreamMutation2WithExtensions<RT | RTHooks, CommandStreamHandler<typeof client[Key]>>
810
826
  })
811
827
  & { Input: typeof client[Key] extends RequestHandlerWithInput<infer I, any, any, any, any, any> ? I : never }
812
828
  }