Skip to content

Commit

Permalink
fix: update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSiu committed Mar 24, 2024
1 parent 8d6e967 commit a76bb1e
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 170 deletions.
147 changes: 79 additions & 68 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* Represents the search options for querying.
*/
interface XCQueryOption {
/**
* Group
*
* Use the grp tag to narrow down your search to a specific group. This tag is particularly useful in combination with one of the other tags. Valid group values are birds, grasshoppers and bats. You can also use their respective ids (1 to 3), so grp:2 will restrict your search to grasshoppers. Soundscapes are a special case, as these recordings may include multiple groups. Use grp:soundscape or grp:0 to search these.
*/
grp?: "soundscape" | "birds" | "grasshoppers" | "bats" | 0 | 1 | 2 | 3;
grp?: "soundscape" | "birds" | "grasshoppers" | "bats" | 0 | 1 | 2 | 3 | (string & {});
/**
* Genus/Subspecies
*
Expand Down Expand Up @@ -40,13 +43,13 @@ interface XCQueryOption {
*
* Two tags (seen and playback respectively) that previously were stored as part of Recordist remarks, but now can be used independently. Both only accept yes and no as input. For example, use seen:yes playback:no to search for recordings where the animal was seen, but not lured by playback.
*/
seen?: "yes" | "no";
seen?: "yes" | "no" | (string & {});
/**
* Animal seen/Playback used
*
* Two tags (seen and playback respectively) that previously were stored as part of Recordist remarks, but now can be used independently. Both only accept yes and no as input. For example, use seen:yes playback:no to search for recordings where the animal was seen, but not lured by playback.
*/
playback?: "yes" | "no";
playback?: "yes" | "no" | (string & {});
/**
* Geographic coordinates
*
Expand Down Expand Up @@ -84,7 +87,7 @@ interface XCQueryOption {
*
* Up until 2022, the 'type' tag used to search a free text field. We have retained the option to search for non-standardized sound types by using the othertype tag. This tag also accepts a 'matches' operator, e.g. othertype:"=wing flapping".
*/
type?: "aberrant" | "alarm call" | "begging call" | "call" | "calling song" | "courtship song" | "dawn song" | "distress call" | "disturbance song" | "drumming" | "duet" | "echolocation" | "female song" | "flight call" | "flight song" | "imitation" | "nocturnal flight call" | "rivalry song" | "searching song" | "social call" | "song" | "subsong";
type?: "aberrant" | "alarm call" | "begging call" | "call" | "calling song" | "courtship song" | "dawn song" | "distress call" | "disturbance song" | "drumming" | "duet" | "echolocation" | "female song" | "flight call" | "flight song" | "imitation" | "nocturnal flight call" | "rivalry song" | "searching song" | "social call" | "song" | "subsong" | (string & {});
/**
* Sound type
*
Expand All @@ -98,19 +101,19 @@ interface XCQueryOption {
*
* Formerly included under 'sound types', the sex tag can now be used independently. Valid values for this tag are: female, male. This tag always uses a 'matches' operator.
*/
sex?: "female" | "male";
sex?: "female" | "male" | (string & {});
/**
* Life stage
*
* Values of the stage tag were previously included under 'sound types' as well. Valid values are: adult, juvenile, nestling, nymph, subadult. This tag always uses a 'matches' operator.
*/
state?: "adult" | "juvenile" | "nestling" | "nymph" | "subadult";
state?: "adult" | "juvenile" | "nestling" | "nymph" | "subadult" | (string & {});
/**
* Recording method
*
* The method tag accepts the following, group-dependent values: emerging from roost, field recording, fluorescent light tag, hand-release, in enclosure, in net, in the hand, roosting, roped, studio recording. Do not forget to enclose the term between double quotes! This tag always uses a 'matches' operator.
*/
method?: "emerging from roost" | "field recording" | "fluorescent light tag" | "hand-release" | "in enclosure" | "in net" | "in the hand" | "roosting" | "roped" | "studio recording";
method?: "emerging from roost" | "field recording" | "fluorescent light tag" | "hand-release" | "in enclosure" | "in net" | "in the hand" | "roosting" | "roped" | "studio recording" | (string & {});
/**
* XC number
*
Expand Down Expand Up @@ -152,7 +155,7 @@ interface XCQueryOption {
*
* The area tag allows you to search by world area. Valid values for this tag are africa, america, asia, australia, europe.
*/
area?: "africa" | "america" | "asia" | "australia" | "europe";
area?: "africa" | "america" | "asia" | "australia" | "europe" | (string & {});
/**
* Additional search tags
*
Expand Down Expand Up @@ -200,7 +203,7 @@ interface XCQueryOption {
*
* The auto tag searches for automatic (non-supervised) recordings. This tag accepts yes and no.
*/
auto?: "yes" | "no";
auto?: "yes" | "no" | (string & {});
/**
* Additional search tags
*
Expand All @@ -220,126 +223,135 @@ interface XCQueryOption {
*/
smp?: number | string;
/**
* Any other custom tags not in the API for compatibility
* Any other custom tags not in the API for compatibility.
*/
[rest: string]: number | string | undefined;
}
/**
* Represents additional options for the wrapper.
*/
interface AdditionalWrapperOption {
/**
* Override the default BASE_URL
* Override the default BASE_URL.
*/
baseUrl?: string;
}

/**
* Represents the response object returned by the Xeno-Canto API.
*/
interface XCResponse {
/**
* the total number of recordings found for this query
* The total number of recordings found for this query.
*/
numRecordings: number;
/**
* the total number of species found for this query
* The total number of species found for this query.
*/
numSpecies: number;
/**
* the page number of the results page that is being displayed
* The page number of the results page that is being displayed.
*/
page: number;
/**
* the total number of pages available for this query
* The total number of pages available for this query.
*/
numPages: number;
/**
* an array of recording objects
* An array of recording objects.
*/
recordings: XCRecording[];
/**
* error type
* Error type, if any.
*/
error?: string;
/**
* error message
* Error message, if any.
*/
message?: string;
}
/**
* Represents a recording entity from the Xeno-Canto API response's "recordings" array.
*/
interface XCRecording {
/**
* the catalogue number of the recording on xeno-canto
* The catalogue number of the recording on xeno-canto.
*/
id: string;
/**
* the generic name of the species
* The generic name of the species.
*/
gen: string;
/**
* the specific name (epithet) of the species
* The specific name (epithet) of the species.
*/
sp: string;
/**
* the subspecies name (subspecific epithet)
* The subspecies name (subspecific epithet).
*/
ssp: string;
/**
* the group to which the species belongs (birds, grasshoppers, bats)
* The group to which the species belongs (birds, grasshoppers, bats).
*/
group: string;
/**
* the English name of the species
* The English name of the species.
*/
en: string;
/**
* the name of the recordist
* The name of the recordist.
*/
rec: string;
/**
* the country where the recording was made
* The country where the recording was made.
*/
cnt: string;
/**
* the name of the locality
* The name of the locality.
*/
loc: string;
/**
* the latitude of the recording in decimal coordinates
* The latitude of the recording in decimal coordinates.
*/
lat: string;
/**
* the longitude of the recording in decimal coordinates
* The longitude of the recording in decimal coordinates.
*/
lng: string;
/**
* TODO: unknown usage
* Elevation (in meter).
*/
alt: string;
/**
* the sound type of the recording (combining both predefined terms such as 'call' or 'song' and additional free text options)
* The sound type of the recording (combining both predefined terms such as 'call' or 'song' and additional free text options).
*/
type: string;
/**
* the sex of the animal
* The sex of the animal.
*/
sex: string;
/**
* the life stage of the animal (adult, juvenile, etc.)
* The life stage of the animal (adult, juvenile, etc.).
*/
stage: string;
/**
* the recording method (field recording, in the hand, etc.)
* The recording method (field recording, in the hand, etc.).
*/
method: string;
/**
* the URL specifying the details of this recording
* The URL specifying the details of this recording.
*/
url: string;
/**
* the URL to the audio file
* The URL to the audio file.
*/
file: string;
/**
* the original file name of the audio file
* The original file name of the audio file.
*/
fileName: string;
/**
* an object with the URLs to the four versions of sonograms
* An object with the URLs to the four versions of sonograms.
*/
sono: {
small: string;
Expand All @@ -348,101 +360,100 @@ interface XCRecording {
full: string;
};
/**
* an object with the URLs to the three versions of oscillograms
* An object with the URLs to the three versions of oscillograms.
*/
osci: {
small: string;
med: string;
large: string;
};
/**
* the URL describing the license of this recording
* The URL describing the license of this recording.
*/
lic: string;
/**
* the current quality rating for the recording
* The current quality rating for the recording.
*/
q: string;
/**
* the length of the recording in minutes
* The length of the recording in minutes.
*/
length: string;
/**
* the time of day that the recording was made
* The time of day that the recording was made.
*/
time: string;
/**
* the date that the recording was made
* The date that the recording was made.
*/
date: string;
/**
* the date that the recording was uploaded to xeno-canto
* The date that the recording was uploaded to xeno-canto.
*/
uploaded: string;
/**
* an array with the identified background species in the recording
* An array with the identified background species in the recording.
*/
also: string[];
/**
* additional remarks by the recordist
* Additional remarks by the recordist.
*/
rmk: string;
/**
* indicates whether the recorded animal was seen
* Indicates whether the recorded animal was seen.
*/
birdSeen: string;
/**
* was the recorded animal seen
* Was the recorded animal seen.
*/
animalSeen: string;
/**
* was playback used to lure the animal
* Was playback used to lure the animal.
*/
playbackUsed: string;
/**
* temperature during recording (applicable to specific groups only)
* Temperature during recording (applicable to specific groups only).
*/
temp: string;
/**
* registration number of specimen (when collected)
* Registration number of specimen (when collected).
*/
regnr: string;
/**
* automatic (non-supervised) recording
* Automatic (non-supervised) recording.
*/
auto: string;
/**
* recording device used
* Recording device used.
*/
dvc: string;
/**
* microphone used
* Microphone used.
*/
mic: string;
/**
* sample rate
* Sample rate.
*/
smp: number;
}

/**
* Constructs a query URL by appending the provided query string to the base URL and
* optionally including additional query options.
* Constructs a query URL by appending the provided query string to the base URL and optionally including additional query options.
*
* @param {string} baseUrl - The base URL to which the query string will be appended.
* @param {string} query - The query string to be appended to the base URL.
* @param {XCQueryOption} [options] - Optional additional query options.
* @param {number} [page] - Optional page number.
* @return {string} The constructed query URL.
* @return {URL} The constructed query URL.
*/
declare function constructQueryUrl(baseUrl: string, query: string, options?: XCQueryOption, page?: number): string;
declare function constructQueryUrl(baseUrl: string, query: string, options?: XCQueryOption, page?: number): URL;
/**
* Converts an XCQueryOption object to a URL-encoded string.
* Converts an XCQueryOption object to a required URL string parameter format. For example: "grp:"birds" cnt:"United States" method:"field recording""
*
* @param {XCQueryOption} option - The XCQueryOption object to convert.
* @return {string} The URL-encoded string representation of the XCQueryOption object.
* @return {URLSearchParams} The URLSearchParams object representing the XCQueryOption object.
*/
declare function convertXCQueryOptionToString(option: XCQueryOption): string;
declare function convertXCQueryOptionToSearchParams(option: XCQueryOption): URLSearchParams;
/**
* Takes a JSON object and converts it into an XCResponse object.
*
Expand All @@ -451,20 +462,20 @@ declare function convertXCQueryOptionToString(option: XCQueryOption): string;
*/
declare function convertJsonToXCResponse(json: any): XCResponse;

declare const BASE_URL = "https://www.xeno-canto.org/api/2/recordings?query=";
declare const BASE_URL = "https://www.xeno-canto.org/api/2/recordings";
/**
* Searches for a query and returns the response and XC response.
* Searches for a query via Fetch API and returns the response and XC response.
*
* @param {string} query - The query to search for.
* @param {XCQueryOption} [options] - Options for the search query.
* @param {number} [page] - The page parameter is optional and is only needed if the results from a given search don't fit in a single page. If specified, page must be an integer between 1 and XCResponse.numPages.
* @param {AdditionalWrapperOption} [additionalOptions] - Additional options for this wrapper.
* @return {Promise<{ response: Response; xcResponse: XCResponse }>} A promise that resolves to an object containing the response from fetch and a XCResponse object.
* @return {Promise<{ url: URL, response: Response; xcResponse: XCResponse }>} A promise that resolves to an object containing the query URL, the response from fetch and a XCResponse object.
*/
declare function search(query: string, options?: XCQueryOption, page?: number, additionalOptions?: AdditionalWrapperOption): Promise<{
url: string;
url: URL;
rawResponse: Response;
xcResponse: XCResponse;
}>;

export { type AdditionalWrapperOption, BASE_URL, type XCQueryOption, type XCRecording, type XCResponse, constructQueryUrl, convertJsonToXCResponse, convertXCQueryOptionToString, search };
export { type AdditionalWrapperOption, BASE_URL, type XCQueryOption, type XCRecording, type XCResponse, constructQueryUrl, convertJsonToXCResponse, convertXCQueryOptionToSearchParams, search };
Loading

0 comments on commit a76bb1e

Please sign in to comment.