|
| 1 | +type queryClientValue |
| 2 | +type fetchMeta |
| 3 | + |
| 4 | +type notifyOnChangePropsKeys = [ |
| 5 | + | #error |
| 6 | + | #isError |
| 7 | + | #isIdle |
| 8 | + | #isLoading |
| 9 | + | #isLoadingError |
| 10 | + | #isRefetchError |
| 11 | + | #isSuccess |
| 12 | + | #status |
| 13 | + | #tracked |
| 14 | +] |
| 15 | + |
| 16 | +type infiniteQueryObserverResultProps = [ |
| 17 | + | #error |
| 18 | + | #isError |
| 19 | + | #isIdle |
| 20 | + | #isLoading |
| 21 | + | #isLoadingError |
| 22 | + | #isRefetchError |
| 23 | + | #isSuccess |
| 24 | + | #status |
| 25 | + | #tracked |
| 26 | +] |
| 27 | + |
| 28 | +type fetchContext |
| 29 | + |
| 30 | +type queryBehavior = {onFetch: fetchContext => unit} |
| 31 | + |
| 32 | +type getPreviousPageParamFunction<'data> = { |
| 33 | + firstPage: 'data, |
| 34 | + allPages: array<'data>, |
| 35 | +} |
| 36 | + |
| 37 | +type getNextPageParamFunction<'data> = { |
| 38 | + lastPage: 'data, |
| 39 | + allPages: array<'data>, |
| 40 | +} |
| 41 | + |
| 42 | +@deriving(abstract) |
| 43 | +type queryObserverOptions<'error, 'data, 'queryData, 'queryKey, 'pageParam> = { |
| 44 | + @optional retry: ReactQuery_Types.retryValue<'error>, |
| 45 | + @optional retryDelay: ReactQuery_Types.retryValue<'error>, |
| 46 | + @optional cacheTime: int, |
| 47 | + @optional isDataEqual: (option<'data>, 'data) => bool, |
| 48 | + @optional |
| 49 | + queryFn: ReactQuery_Types.queryFunctionContext<'queryKey, 'pageParam> => Js.Promise.t<'queryData>, |
| 50 | + @optional queryHash: string, |
| 51 | + @optional queryKey: 'queryKey, |
| 52 | + @optional queryKeyHashFn: 'queryKey => string, |
| 53 | + @optional initialData: unit => 'data, |
| 54 | + @optional initialDataUpdatedAt: unit => option<int>, |
| 55 | + @optional behavior: queryBehavior, // Revisar context type |
| 56 | + @optional structuralSharing: bool, |
| 57 | + @optional getPreviousPageParam: getPreviousPageParamFunction<'data>, |
| 58 | + @optional getNextPageParam: getNextPageParamFunction<'data>, |
| 59 | + @optional _defaulted: bool, |
| 60 | + @optional enabled: bool, |
| 61 | + @optional staleTime: int, |
| 62 | + @optional refetchInterval: ReactQuery_Types.refetchIntervalValue, |
| 63 | + @optional refetchIntervalInBackground: bool, |
| 64 | + @optional refetchOnWindowFocus: ReactQuery_Types.boolOrAlwaysValue, |
| 65 | + @optional refetchOnReconnect: ReactQuery_Types.boolOrAlwaysValue, |
| 66 | + @optional refetchOnMount: ReactQuery_Types.boolOrAlwaysValue, |
| 67 | + @optional retryOnMount: bool, |
| 68 | + @optional notifyOnChangeProps: array<notifyOnChangePropsKeys>, |
| 69 | + @optional notifyOnChangePropsExclusions: array<bool>, |
| 70 | + @optional onSuccess: 'data => unit, |
| 71 | + @optional onError: 'error => unit, |
| 72 | + @optional onSettled: (option<'data>, option<'error>) => unit, |
| 73 | + @optional useErrorBoundary: bool, |
| 74 | + @optional select: 'queryData => 'data, |
| 75 | + @optional suspense: bool, |
| 76 | + @optional keepPreviousData: bool, |
| 77 | + @optional placeholderData: ReactQuery_Types.placeholderDataValue, |
| 78 | + @optional optimisticResults: bool, |
| 79 | +} |
| 80 | + |
| 81 | +type defaultOptions<'error, 'data, 'queryData, 'queryKey, 'pageParam> = { |
| 82 | + queries: option<queryObserverOptions<'error, 'data, 'queryData, 'queryKey, 'pageParam>>, |
| 83 | +} |
| 84 | + |
| 85 | +type invalidateQueryFilter = { |
| 86 | + refetchActive: option<bool>, |
| 87 | + refetchInactive: option<bool>, |
| 88 | +} |
| 89 | + |
| 90 | +type clientRefetchOptions = {throwOnError: option<bool>} |
| 91 | + |
| 92 | +type invalidateQueryOptions<'queryKey> = { |
| 93 | + queryKey: option<'queryKey>, |
| 94 | + filters: option<invalidateQueryFilter>, |
| 95 | + refetchOptions: option<clientRefetchOptions>, |
| 96 | +} |
| 97 | + |
| 98 | +type refetchQueriesOptions<'queryKey> = { |
| 99 | + queryKey: option<'queryKey>, |
| 100 | + filters: option<ReactQuery_Types.queryFilter<'queryKey>>, |
| 101 | + refetchOptions: option<clientRefetchOptions>, |
| 102 | +} |
| 103 | + |
| 104 | +type cancelQueriesOptions<'queryKey> = { |
| 105 | + queryKey: option<'queryKey>, |
| 106 | + filters: option<ReactQuery_Types.queryFilter<'queryKey>>, |
| 107 | +} |
| 108 | + |
| 109 | +type queryState<'queryData, 'queryError> = { |
| 110 | + data: option<'queryData>, |
| 111 | + dataUpdateCount: int, |
| 112 | + dataUpdatedAt: int, |
| 113 | + error: Js.Nullable.t<'queryError>, |
| 114 | + errorUpdateCount: int, |
| 115 | + errorUpdatedAt: int, |
| 116 | + fetchFailureCount: int, |
| 117 | + fetchMeta: fetchMeta, |
| 118 | + isFetching: bool, |
| 119 | + isInvalidated: bool, |
| 120 | + isPaused: bool, |
| 121 | + status: ReactQuery_Types.queryStatus, |
| 122 | +} |
| 123 | + |
| 124 | +@deriving(abstract) |
| 125 | +type fetchQueryOptions<'queryKey, 'queryData, 'queryError, 'pageParam> = { |
| 126 | + @optional queryKey: 'queryKey, |
| 127 | + @optional |
| 128 | + queryFn: ReactQuery_Types.queryFunctionContext<'queryKey, 'pageParam> => Js.Promise.t<'queryData>, |
| 129 | + @optional retry: ReactQuery_Types.retryValue<'queryError>, |
| 130 | + @optional retryOnMount: bool, |
| 131 | + @optional retryDelay: ReactQuery_Types.retryDelayValue<'queryError>, |
| 132 | + @optional staleTime: ReactQuery_Types.timeValue, |
| 133 | + @optional queryKeyHashFn: 'queryKey => string, |
| 134 | + @optional refetchOnMount: ReactQuery_Types.boolOrAlwaysValue, |
| 135 | + @optional structuralSharing: bool, |
| 136 | + @optional initialData: 'queryData => 'queryData, |
| 137 | + @optional initialDataUpdatedAt: unit => int, |
| 138 | +} |
| 139 | + |
| 140 | +type queryClient<'queryKey, 'queryData, 'queryError, 'pageParams> = { |
| 141 | + fetchQuery: fetchQueryOptions<'queryKey, 'queryData, 'queryError, 'pageParams> => Js.Promise.t< |
| 142 | + 'queryData, |
| 143 | + >, |
| 144 | + fetchInfiniteQuery: fetchQueryOptions< |
| 145 | + 'queryKey, |
| 146 | + 'queryData, |
| 147 | + 'queryError, |
| 148 | + 'pageParams, |
| 149 | + > => Js.Promise.t<ReactQuery_Types.infiniteData<'queryData, 'pageParams>>, |
| 150 | + prefetchQuery: fetchQueryOptions<'queryKey, 'queryData, 'queryError, 'pageParams> => Js.Promise.t< |
| 151 | + unit, |
| 152 | + >, |
| 153 | + prefetchInfiniteQuery: fetchQueryOptions< |
| 154 | + 'queryKey, |
| 155 | + 'queryData, |
| 156 | + 'queryError, |
| 157 | + 'pageParams, |
| 158 | + > => Js.Promise.t<unit>, |
| 159 | + getQueryData: 'queryKey => option<'queryData>, |
| 160 | + setQueryData: ('queryKey, option<'queryData>) => 'queryData, |
| 161 | + getQueryState: ( |
| 162 | + 'queryKey, |
| 163 | + ReactQuery_Types.queryFilter<'queryKey>, |
| 164 | + ) => queryState<'queryData, 'queryError>, |
| 165 | + setQueriesData: ( |
| 166 | + ReactQuery_Types.queryDataKeyOrFilterValue<'queryKey>, |
| 167 | + option<'queryData> => 'queryData, |
| 168 | + ) => unit, |
| 169 | + invalidateQueries: ( |
| 170 | + option<ReactQuery_Types.queryFilter<'queryKey>>, |
| 171 | + option<clientRefetchOptions>, |
| 172 | + ) => Js.Promise.t<unit>, |
| 173 | + refetchQueries: ( |
| 174 | + option<ReactQuery_Types.queryFilter<'queryKey>>, |
| 175 | + option<clientRefetchOptions>, |
| 176 | + ) => Js.Promise.t<unit>, |
| 177 | + cancelQueries: option<ReactQuery_Types.queryFilter<'queryKey>> => Js.Promise.t<unit>, |
| 178 | + removeQueries: option<ReactQuery_Types.queryFilter<'queryKey>> => Js.Promise.t<unit>, |
| 179 | + resetQueries: ( |
| 180 | + option<ReactQuery_Types.queryFilter<'queryKey>>, |
| 181 | + option<clientRefetchOptions>, |
| 182 | + ) => Js.Promise.t<unit>, |
| 183 | + isFetching: option<ReactQuery_Types.queryFilter<'queryKey>> => bool, |
| 184 | + isMutating: option<ReactQuery_Types.queryFilter<'queryKey>> => bool, |
| 185 | + // setDefaultOptions |
| 186 | + // getDefaultOptions |
| 187 | + // setQueryDefaults |
| 188 | + // getQueryDefaults |
| 189 | + // getQueryCache |
| 190 | + // setQueryCache |
| 191 | + // getMutationCache |
| 192 | + // setMutationCache |
| 193 | + clear: unit => unit, |
| 194 | +} |
| 195 | + |
| 196 | +@module("react-query") |
| 197 | +external useQueryClient: unit => queryClient<'queryKey, 'queryData, 'queryError, 'pageParams> = |
| 198 | + "useQueryClient" |
| 199 | + |
| 200 | +module Provider = { |
| 201 | + @new @module("react-query") |
| 202 | + external createClient: unit => queryClientValue = "QueryClient" |
| 203 | + |
| 204 | + @module("react-query") @react.component |
| 205 | + external make: ( |
| 206 | + ~client: queryClientValue, |
| 207 | + ~contextSharing: bool=?, |
| 208 | + ~children: React.element, |
| 209 | + ) => React.element = "QueryClientProvider" |
| 210 | +} |
0 commit comments