Skip to content

Commit b188262

Browse files
committed
chore: Add Collections types [resolve #11]
1 parent 89fdaa7 commit b188262

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/hooks/useCollections.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { useCallback, useEffect, useState, useMemo } from 'react';
22
import StacApi from '../stac-api';
3-
import type { GenericObject, LoadingState } from '../types';
3+
import type { LoadingState } from '../types';
4+
import type { CollectionsResponse } from '../types/stac';
45
import debounce from '../utils/debounce';
56

67
type StacCollectionsHook = {
7-
collections?: GenericObject,
8+
collections?: CollectionsResponse,
89
reload: () => void,
910
state: LoadingState
1011
};
1112

1213
function useCollections(stacApi: StacApi): StacCollectionsHook {
13-
const [ collections, setCollections ] = useState<GenericObject>();
14+
const [ collections, setCollections ] = useState<CollectionsResponse>();
1415
const [ state, setState ] = useState<LoadingState>('IDLE');
1516

1617
const _getCollections = useCallback(

src/types/stac.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,44 @@ export type Item = {
5454
links: Link[]
5555
assets: ItemAsset[]
5656
}
57+
58+
type Role = 'licensor' | 'producer' | 'processor' | 'host';
59+
60+
export type Provider = {
61+
name: string,
62+
description?: string,
63+
roles?: Role[],
64+
url: string
65+
}
66+
67+
type SpatialExtent = {
68+
bbox: number[][]
69+
}
70+
71+
type TemporalExtent = {
72+
interval: string | null[][]
73+
}
74+
75+
export type Extent = {
76+
spatial: SpatialExtent,
77+
temporal: TemporalExtent,
78+
}
79+
80+
export type Collection = {
81+
type: 'Collection',
82+
stac_version: string,
83+
stac_extensions?: string[],
84+
id: string,
85+
title?: string,
86+
keywords?: string[],
87+
license: string,
88+
providers: Provider[],
89+
extent: Extent,
90+
links: Link[]
91+
assets: GenericObject,
92+
}
93+
94+
export type CollectionsResponse = {
95+
collections: Collection[],
96+
links: Link[]
97+
}

0 commit comments

Comments
 (0)