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

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