http-client: Support search, info, and repo sort params

This commit is contained in:
Georgios Jason Efstathiou
2026-07-13 10:53:17 +02:00
parent b201ddd501
commit b32ae47abc
3 changed files with 60 additions and 4 deletions
+25 -1
View File
@@ -7,6 +7,7 @@ import type {
Remote,
Repo,
RepoListQuery,
SearchResult,
TagInfo,
Tree,
TreeStats,
@@ -46,7 +47,9 @@ import type { ZodSchema } from "zod";
import * as z from "zod";
import * as repo from "./lib/repo.js";
import { Fetcher } from "./lib/fetcher.js";
import { Fetcher, ResponseError } from "./lib/fetcher.js";
export { ResponseError };
import {
nodeConfigSchema,
scopeSchema,
@@ -86,6 +89,7 @@ export type {
RepoListQuery,
Review,
Revision,
SearchResult,
SeedingPolicy,
TagInfo,
Tree,
@@ -105,6 +109,15 @@ const nodeSchema = z.object({
description: z.string().optional(),
});
export type Info = z.infer<typeof infoSchema>;
const infoSchema = z.object({
node: nodeSchema,
httpd: z.object({
searchAvailable: z.boolean(),
}),
});
export type NodeIdentity = z.infer<typeof nodeIdentitySchema>;
const nodeIdentitySchema = z.object({
@@ -246,6 +259,17 @@ export class HttpdClient {
);
}
public async getInfo(options?: RequestOptions): Promise<Info> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: "info",
options,
},
infoSchema,
);
}
public async getNodeIdentity(
nid: string,
options?: RequestOptions,
+3 -3
View File
@@ -62,9 +62,9 @@ export class ResponseParseError extends Error {
let description: string;
if (!satisfies(nodeApiVersion, explorerRequiredApiVersion)) {
description = `The node you are fetching from (v${nodeApiVersion}) doesn't match the version requirements of <code>radicle-explorer</code> ${explorerRequiredApiVersion}.`;
description = `The node you are fetching from (v${nodeApiVersion}) doesn’t match the version requirements of <code>radicle-explorer</code> ${explorerRequiredApiVersion}.`;
} else {
description = `The node (v${nodeApiVersion}) matches the version requirement of <code>radicle-explorer</code> (${explorerRequiredApiVersion}), but <code>radicle-explorer</code> isn't able to parse the response.`;
description = `The node (v${nodeApiVersion}) matches the version requirement of <code>radicle-explorer</code> (${explorerRequiredApiVersion}), but <code>radicle-explorer</code> isn’t able to parse the response.`;
}
this.apiVersion = apiVersion;
this.description =
@@ -72,7 +72,7 @@ export class ResponseParseError extends Error {
description,
config.deploymentId
? ""
: "<br/>If you are self-hosting <code>radicle-explorer</code> and run into this error, try to clear the browser's <code>localStorage</code> and the cache.",
: "<br/>If you are self-hosting <code>radicle-explorer</code> and run into this error, try to clear the browser’s <code>localStorage</code> and the cache.",
);
this.method = method;
+32
View File
@@ -87,6 +87,22 @@ const reposSchema = array(repoSchema);
export type Repo = z.infer<typeof repoSchema>;
const searchResultSchema = object({
rid: string(),
payloads: object({
"xyz.radicle.project": object({
name: string(),
description: string(),
defaultBranch: string(),
}).optional(),
}),
delegates: array(authorSchema),
seeds: number(),
});
const searchResultsSchema = array(searchResultSchema);
export type SearchResult = z.infer<typeof searchResultSchema>;
const activitySchema = object({
activity: array(number()),
});
@@ -176,6 +192,7 @@ export type RepoListQuery = {
page?: number;
perPage?: number;
show?: "pinned" | "all";
sort?: "rid" | "activity" | "seeding";
};
export class Client {
#fetcher: Fetcher;
@@ -226,6 +243,21 @@ export class Client {
);
}
public async search(
query: string,
options?: RequestOptions,
): Promise<SearchResult[]> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: "repos/search",
query: { q: query },
options,
},
searchResultsSchema,
);
}
public async getActivity(
rid: string,
options?: RequestOptions,