Skip to content

Commit

Permalink
Merge pull request #9 from cjkoepke/master
Browse files Browse the repository at this point in the history
chore: support batch
  • Loading branch information
bigirishlion authored Jun 7, 2024
2 parents 0ba9b85 + b2a3622 commit cd323ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Binary file added src/.DS_Store
Binary file not shown.
22 changes: 13 additions & 9 deletions src/classes/providers/HandleClientProvider.abstract.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ export abstract class HandleClientProvider<T = {}> {
* @param {HEX} handle - The handle supplied to the lookup.
* @returns
*/
protected async __handleResponse<T>(api: Promise<Response>, handle: Readable) {
protected async __handleResponse<T>(api: Promise<Response>, handle?: Readable) {
return api
.then((res) => res.json() as T)
.catch((e) => {
console.error(
`Something went wrong while fetching this Handle: ${handle.value}.${
isHex(handle.value)
? ` You may need to convert the Handle name to UTF-8 before providing it to this function.`
: ''
} Here is the full error:`,
e
);
if (handle) {
console.error(
`Something went wrong while fetching this Handle: ${handle.value}.${
isHex(handle.value)
? ` You may need to convert the Handle name to UTF-8 before providing it to this function.`
: ''
} Here is the full error:`,
e
);
} else {
console.error(e);
}

return {} as T;
});
Expand Down
17 changes: 17 additions & 0 deletions src/classes/providers/KoraLabsProvider.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ export class KoraLabsProvider extends HandleClientProvider<IHandle> {
);
};

/**
* Retrieves all data associated with a list of given handles.
*
* @param {HEX[]} handles - The handles to lookup, in HEX format.
* @returns {Promise<IHandle[]>} - A promise that resolves to an array of handle data.
*/
getAllDataBatch = async (handles: HEX[]): Promise<IHandle[]> => {
const names = handles.map((h) => HandleClient.getNormalizedName(h).value);
return this.__handleResponse<IHandle[]>(
fetch(`${this.apiUrl}/handles/list`, {
headers: this.headers,
method: 'POST',
body: JSON.stringify(names)
})
);
};

/**
* Retrieves all personalized data associated with a given handle.
*
Expand Down

0 comments on commit cd323ee

Please sign in to comment.