Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for searchable paths #1367

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/app/src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface DataContextValue {
getExportURL?: DataProviderApi['getExportURL'];
addProgressListener: (cb: ProgressCallback) => void;
removeProgressListener: (cb: ProgressCallback) => void;
getSearchablePaths?: DataProviderApi['getSearchablePaths'];
}

const DataContext = createContext({} as DataContextValue);
Expand Down Expand Up @@ -113,6 +114,7 @@ function DataProvider(props: PropsWithChildren<Props>) {
getExportURL: api.getExportURL?.bind(api),
addProgressListener: api.addProgressListener.bind(api),
removeProgressListener: api.removeProgressListener.bind(api),
getSearchablePaths: api.getSearchablePaths?.bind(api),
}}
>
{children}
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/providers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export abstract class DataProviderApi {
value: Value<D>
): ExportURL;

public getSearchablePaths?(path: string): Promise<string[]>;

public addProgressListener(cb: ProgressCallback): void {
this.progressListeners.add(cb);
cb([...this.progress.values()]); // notify once
Expand Down
9 changes: 9 additions & 0 deletions packages/app/src/providers/h5grove/h5grove-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
H5GroveAttrValuesResponse,
H5GroveDataResponse,
H5GroveEntityResponse,
H5GrovePathsResponse,
} from './models';
import {
convertH5GroveDtype,
Expand Down Expand Up @@ -100,6 +101,14 @@ export class H5GroveApi extends DataProviderApi {
return new URL(`${baseURL as string}/data/?${searchParams.toString()}`);
}

public async getSearchablePaths(path: string): Promise<string[]> {
const { data } = await this.client.get<H5GrovePathsResponse>(`/paths/`, {
params: { path },
});

return data;
}

private async fetchEntity(path: string): Promise<H5GroveEntityResponse> {
const { data } = await handleAxiosError(
() =>
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/providers/h5grove/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ export interface H5GroveAttribute {

export type H5GroveAttrValuesResponse = AttributeValues;
export type H5GroveDataResponse = unknown;

export type H5GrovePathsResponse = string[];
2 changes: 1 addition & 1 deletion packages/h5wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"react": ">=16"
},
"dependencies": {
"h5wasm": "0.4.7",
"h5wasm": "0.4.10",
"nanoid": "4.0.0"
},
"devDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions packages/h5wasm/src/h5wasm-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ export class H5WasmApi extends ProviderApi {
file.close();
}

public async getSearchablePaths(root: string): Promise<string[]> {
const file = await this.file;

const h5wEntity = file.get(root);

if (isH5WasmGroup(h5wEntity)) {
// Build absolute paths since .paths() are relative
return h5wEntity.paths().map((path) => `${root}${path}`);
loichuder marked this conversation as resolved.
Show resolved Hide resolved
}

return [];
}

private async initFile(buffer: ArrayBuffer): Promise<H5WasmFile> {
const { FS } = await h5wasmReady;

Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.