|
| 1 | +import { GEN3_INDEXD_API } from '../../constants'; |
| 2 | +import { gen3Api } from '../gen3'; |
| 3 | +import { KeyValuePair } from '../../types'; |
| 4 | + |
| 5 | +export interface IndexdMetadataRequestParams { |
| 6 | + limit?: number; |
| 7 | + filters: KeyValuePair[]; |
| 8 | +} |
| 9 | + |
| 10 | +export interface IndexObject { |
| 11 | + acl: string[]; |
| 12 | + authz: string[]; |
| 13 | + baseid: string; |
| 14 | + content_created_date: string | null; |
| 15 | + content_updated_date: string | null; |
| 16 | + created_date: string; |
| 17 | + description: string | null; |
| 18 | + did: string; |
| 19 | + file_name: string; |
| 20 | + form: string | null; |
| 21 | + hashes: { |
| 22 | + crc: string; |
| 23 | + md5: string; |
| 24 | + sha1: string; |
| 25 | + sha256: string; |
| 26 | + sha512: string; |
| 27 | + }; |
| 28 | + metadata: Record<string, unknown>; |
| 29 | + rev: string; |
| 30 | + size: number; |
| 31 | + updated_date: string; |
| 32 | + uploader: string | null; |
| 33 | + urls: string[]; |
| 34 | + urls_metadata: Record<string, Record<string, unknown>>; |
| 35 | + version: string | null; |
| 36 | +} |
| 37 | + |
| 38 | +export interface IndexdResponse { |
| 39 | + acl: string | null; |
| 40 | + authz: string | null; |
| 41 | + file_name: string | null; |
| 42 | + hashes: string | null; |
| 43 | + ids: string | null; |
| 44 | + limit: number; |
| 45 | + metadata: Record<string, unknown>; |
| 46 | + page: number | null; |
| 47 | + did: string; |
| 48 | + size: number | null; |
| 49 | + start: number | null; |
| 50 | + urls: string[]; |
| 51 | + urls_metadata: string | null; |
| 52 | + version: string | null; |
| 53 | + records: Array<IndexObject>; |
| 54 | +} |
| 55 | + |
| 56 | +export const indexdApi = gen3Api.injectEndpoints({ |
| 57 | + endpoints: (builder) => ({ |
| 58 | + getIndexdMetdata: builder.query< |
| 59 | + IndexdResponse, |
| 60 | + IndexdMetadataRequestParams |
| 61 | + >({ |
| 62 | + query: ({ filters, limit = 1000 }: IndexdMetadataRequestParams) => { |
| 63 | + const query = filters.reduce( |
| 64 | + (acc, filter) => `${acc}&${filter.key}=${filter.value}`, |
| 65 | + '', |
| 66 | + ); |
| 67 | + return `${GEN3_INDEXD_API}/index?${query}&limit=${limit}`; |
| 68 | + }, |
| 69 | + }), |
| 70 | + getIndexObject: builder.query<IndexObject, string>({ |
| 71 | + query: (guid) => `${GEN3_INDEXD_API}/index/${guid}`, |
| 72 | + }), |
| 73 | + }), |
| 74 | +}); |
| 75 | + |
| 76 | +export const { |
| 77 | + useGetIndexdMetdataQuery, |
| 78 | + useLazyGetIndexdMetdataQuery, |
| 79 | + useGetIndexObjectQuery, |
| 80 | + useLazyGetIndexObjectQuery, |
| 81 | +} = indexdApi; |
0 commit comments