@@ -2,7 +2,7 @@ import type { Client } from '@orpc/client'
22import type { ErrorFromErrorMap } from '@orpc/contract'
33import type { GetNextPageParamFunction , InfiniteData , InfiniteQueryObserverOptions , MutationObserverOptions , QueryFunction , QueryKey , QueryObserverOptions } from '@tanstack/query-core'
44import type { baseErrorMap } from '../../contract/tests/shared'
5- import type { ProcedureUtils } from './procedure-utils'
5+ import type { experimental_ProcedureUtilsDefaults , ProcedureUtils } from './procedure-utils'
66import { QueryClient , skipToken } from '@tanstack/query-core'
77
88describe ( 'ProcedureUtils' , ( ) => {
@@ -746,3 +746,194 @@ describe('ProcedureUtils', () => {
746746 } )
747747 } )
748748} )
749+
750+ describe ( 'ProcedureUtilsDefaults' , ( ) => {
751+ type TestClientContext = { batch ?: boolean }
752+ type TestInput = { search ?: string }
753+ type TestOutput = { title : string }
754+ type TestError = Error
755+
756+ type TestDefaults = experimental_ProcedureUtilsDefaults < TestClientContext , TestInput , TestOutput , TestError >
757+
758+ it ( 'should have exact same keys as ProcedureUtils excluding call' , ( ) => {
759+ // Ensures every utility method in ProcedureUtils (except 'call') has a corresponding key in ProcedureUtilsDefaults
760+ type ProcedureUtilsKeys = Exclude < keyof ProcedureUtils < any , any , any , any > , 'call' >
761+ type DefaultsKeys = keyof experimental_ProcedureUtilsDefaults < any , any , any , any >
762+
763+ expectTypeOf < DefaultsKeys > ( ) . toEqualTypeOf < ProcedureUtilsKeys > ( )
764+ } )
765+
766+ it ( 'all properties should be optional' , ( ) => {
767+ const emptyDefaults : TestDefaults = { }
768+ expectTypeOf ( emptyDefaults ) . toExtend < TestDefaults > ( )
769+ } )
770+
771+ it ( 'queryKey should accept Partial<QueryKeyOptions>' , ( ) => {
772+ const defaults : TestDefaults = {
773+ queryKey : {
774+ input : { search : 'test' } ,
775+ } ,
776+ }
777+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
778+
779+ const _invalid : TestDefaults = {
780+ queryKey : {
781+ // @ts -expect-error - invalid input type
782+ input : { invalid : 'test' } ,
783+ } ,
784+ }
785+ } )
786+
787+ it ( 'queryOptions should accept Partial<QueryOptionsIn>' , ( ) => {
788+ const defaults : TestDefaults = {
789+ queryOptions : {
790+ input : { search : 'test' } ,
791+ staleTime : 1000 ,
792+ context : { batch : true } ,
793+ } ,
794+ }
795+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
796+
797+ const _invalid : TestDefaults = {
798+ queryOptions : {
799+ // @ts -expect-error - invalid input type
800+ input : { invalid : 'test' } ,
801+ } ,
802+ }
803+ } )
804+
805+ it ( 'experimental_streamedKey should accept Partial<experimental_StreamedKeyOptions>' , ( ) => {
806+ const defaults : TestDefaults = {
807+ experimental_streamedKey : {
808+ input : { search : 'test' } ,
809+ queryFnOptions : { maxChunks : 10 } ,
810+ } ,
811+ }
812+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
813+
814+ const _invalid : TestDefaults = {
815+ experimental_streamedKey : {
816+ // @ts -expect-error - invalid input type
817+ input : { invalid : 'test' } ,
818+ } ,
819+ }
820+ } )
821+
822+ it ( 'experimental_streamedOptions should accept Partial<StreamedOptionsIn>' , ( ) => {
823+ const defaults : TestDefaults = {
824+ experimental_streamedOptions : {
825+ input : { search : 'test' } ,
826+ staleTime : 1000 ,
827+ } ,
828+ }
829+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
830+
831+ const _invalid : TestDefaults = {
832+ experimental_streamedOptions : {
833+ // @ts -expect-error - invalid input type
834+ input : { invalid : 'test' } ,
835+ } ,
836+ }
837+ } )
838+
839+ it ( 'experimental_liveKey should accept Partial<QueryKeyOptions>' , ( ) => {
840+ const defaults : TestDefaults = {
841+ experimental_liveKey : {
842+ input : { search : 'test' } ,
843+ } ,
844+ }
845+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
846+
847+ const _invalid : TestDefaults = {
848+ experimental_liveKey : {
849+ // @ts -expect-error - invalid input type
850+ input : { invalid : 'test' } ,
851+ } ,
852+ }
853+ } )
854+
855+ it ( 'experimental_liveOptions should accept Partial<StreamedOptionsIn>' , ( ) => {
856+ const defaults : TestDefaults = {
857+ experimental_liveOptions : {
858+ input : { search : 'test' } ,
859+ staleTime : 1000 ,
860+ } ,
861+ }
862+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
863+
864+ const _invalid : TestDefaults = {
865+ experimental_liveOptions : {
866+ // @ts -expect-error - invalid input type
867+ input : { invalid : 'test' } ,
868+ } ,
869+ }
870+ } )
871+
872+ it ( 'infiniteKey should accept Partial input, initialPageParam, queryKey' , ( ) => {
873+ const defaults : TestDefaults = {
874+ infiniteKey : {
875+ initialPageParam : 0 ,
876+ queryKey : [ 'custom-key' ] ,
877+ } ,
878+ }
879+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
880+
881+ const _invalid : TestDefaults = {
882+ infiniteKey : {
883+ // @ts -expect-error - invalid input type
884+ input : { invalid : 'test' } ,
885+ } ,
886+ }
887+ } )
888+
889+ it ( 'infiniteOptions should accept Partial<InfiniteOptionsIn>' , ( ) => {
890+ const defaults : TestDefaults = {
891+ infiniteOptions : {
892+ staleTime : 1000 ,
893+ } ,
894+ }
895+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
896+
897+ const _invalid : TestDefaults = {
898+ infiniteOptions : {
899+ // @ts -expect-error - invalid input type
900+ input : { invalid : 'test' } ,
901+ } ,
902+ }
903+ } )
904+
905+ it ( 'mutationKey should accept Partial mutationKey' , ( ) => {
906+ const defaults : TestDefaults = {
907+ mutationKey : {
908+ mutationKey : [ 'custom-mutation-key' ] ,
909+ } ,
910+ }
911+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
912+
913+ const _invalid : TestDefaults = {
914+ mutationKey : {
915+ // @ts -expect-error - invalid mutationKey type
916+ mutationKey : 1 ,
917+ } ,
918+ }
919+ } )
920+
921+ it ( 'mutationOptions should accept Partial<MutationOptionsIn>' , ( ) => {
922+ const defaults : TestDefaults = {
923+ mutationOptions : {
924+ onSuccess : ( output ) => {
925+ expectTypeOf ( output ) . toEqualTypeOf < TestOutput > ( )
926+ } ,
927+ context : { batch : true } ,
928+ } ,
929+ }
930+ expectTypeOf ( defaults ) . toExtend < TestDefaults > ( )
931+
932+ const _invalid : TestDefaults = {
933+ mutationOptions : {
934+ // @ts -expect-error - invalid context type
935+ context : { batch : 'invalid' } ,
936+ } ,
937+ }
938+ } )
939+ } )
0 commit comments