@@ -5,11 +5,7 @@ import {
55 StratName ,
66 UnitLong ,
77} from "@macrostrat/api-types" ;
8- import {
9- addQueryString ,
10- joinURL ,
11- useAPIResult ,
12- } from "@macrostrat/ui-components" ;
8+ import { addQueryString , joinURL } from "@macrostrat/ui-components" ;
139import crossFetch from "cross-fetch" ;
1410import { feature } from "topojson-client" ;
1511import { geoArea } from "d3-geo" ;
@@ -24,12 +20,16 @@ const defaultFetch = createScopedFetch("https://macrostrat.org/api/v2");
2420
2521export type ColumnStatusCode = "in process" | "active" | "obsolete" ;
2622
27- export interface ColumnFetchOptions {
23+ interface FetchBaseOptions {
24+ // The fetch implementation to use
25+ fetch ?: ( url : string , options ?: RequestInit ) => Promise < Response > ;
26+ }
27+
28+ export interface ColumnFetchOptions extends FetchBaseOptions {
2829 apiBaseURL ?: string ;
2930 projectID ?: number ;
3031 statusCode ?: ColumnStatusCode | ColumnStatusCode [ ] ;
3132 format ?: "geojson" | "topojson" | "geojson_bare" ;
32- fetch ?: any ;
3333}
3434
3535export async function fetchAllColumns (
@@ -153,15 +153,17 @@ async function unwrapResponse(res) {
153153 return resData [ "success" ] [ "data" ] ;
154154}
155155
156- export async function fetchLithologies ( fetch = defaultFetch ) {
156+ export async function fetchLithologies ( opts : FetchBaseOptions = { } ) {
157+ const { fetch = defaultFetch } = opts ;
157158 const res = await fetch ( "/defs/lithologies?all" ) ;
158159 return await unwrapResponse ( res ) ;
159160}
160161
161162export async function fetchIntervals (
162163 timescaleID : number | null ,
163- fetch = defaultFetch ,
164+ opts : FetchBaseOptions = { } ,
164165) {
166+ const { fetch = defaultFetch } = opts ;
165167 let url = `/defs/intervals` ;
166168 if ( timescaleID != null ) {
167169 url += `?timescale_id=${ timescaleID } ` ;
@@ -172,15 +174,17 @@ export async function fetchIntervals(
172174 return await unwrapResponse ( res ) ;
173175}
174176
175- export async function fetchEnvironments ( fetch = defaultFetch ) {
177+ export async function fetchEnvironments ( opts : FetchBaseOptions = { } ) {
178+ const { fetch = defaultFetch } = opts ;
176179 const res = await fetch ( "/defs/environments?all" ) ;
177180 return await unwrapResponse ( res ) ;
178181}
179182
180183export async function fetchRefs (
181184 refs : number [ ] ,
182- fetch = defaultFetch ,
185+ opts : FetchBaseOptions = { } ,
183186) : Promise < MacrostratRef [ ] > {
187+ const { fetch = defaultFetch } = opts ;
184188 let url = `/defs/refs` ;
185189 if ( refs . length == 0 ) {
186190 return [ ] ;
@@ -192,8 +196,9 @@ export async function fetchRefs(
192196
193197export async function fetchStratNames (
194198 names : number [ ] ,
195- fetch = defaultFetch ,
199+ opts : FetchBaseOptions = { } ,
196200) : Promise < StratName [ ] > {
201+ const { fetch = defaultFetch } = opts ;
197202 let url = `/defs/strat_names` ;
198203 if ( names . length == 0 ) {
199204 return [ ] ;
@@ -210,8 +215,9 @@ export type ColumnData = {
210215
211216export async function fetchUnits (
212217 columns : number [ ] ,
213- fetch = defaultFetch ,
218+ opts : FetchBaseOptions = { } ,
214219) : Promise < ColumnData [ ] > {
220+ const { fetch = defaultFetch } = opts ;
215221 const params = new URLSearchParams ( ) ;
216222 params . append ( "response" , "long" ) ;
217223
@@ -245,8 +251,9 @@ export async function fetchUnits(
245251
246252export async function fetchColumnUnits (
247253 col_id : number ,
248- fetch = defaultFetch ,
254+ opts : FetchBaseOptions = { } ,
249255) : Promise < ColumnData > {
256+ const { fetch = defaultFetch } = opts ;
250257 const params = new URLSearchParams ( ) ;
251258 params . append ( "response" , "long" ) ;
252259 params . append ( "col_id" , col_id . toString ( ) ) ;
0 commit comments