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

fix various issues with link relations #328

Merged
merged 3 commits into from
Dec 15, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Remove use of serverless-psuedo-parameters
- Upgrade to Node 16

### Fixed

- Collections endpoint (/collections) now has `self` and `root` link relations.

### Deprecated

- ES_BATCH_SIZE variable (replaced by INGEST_BATCH_SIZE)
Expand Down
46 changes: 34 additions & 12 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,25 @@ const addCollectionLinks = function (results, endpoint) {
// self link
links.splice(0, 0, {
rel: 'self',
type: 'application/geo+json',
href: `${endpoint}/collections/${id}`
})
// parent catalog
links.push({
rel: 'parent',
href: `${endpoint}/`
type: 'application/geo+json',
href: `${endpoint}`
})
// root catalog
links.push({
rel: 'root',
href: `${endpoint}/`
type: 'application/geo+json',
href: `${endpoint}`
})
// child items
links.push({
rel: 'items',
type: 'application/geo+json',
href: `${endpoint}/collections/${id}/items`
})
})
Expand All @@ -350,21 +354,25 @@ const addItemLinks = function (results, endpoint) {
// self link
links.splice(0, 0, {
rel: 'self',
type: 'application/geo+json',
href: `${endpoint}/collections/${collection}/items/${id}`
})
// parent catalogs
links.push({
rel: 'parent',
type: 'application/json',
href: `${endpoint}/collections/${collection}`
})
links.push({
rel: 'collection',
type: 'application/json',
href: `${endpoint}/collections/${collection}`
})
// root catalog
links.push({
rel: 'root',
href: `${endpoint}/`
type: 'application/geo+json',
href: `${endpoint}`
})
result.type = 'Feature'
return result
Expand All @@ -389,6 +397,7 @@ const collectionsToCatalogLinks = function (results, endpoint) {
const { id } = result
return {
rel: 'child',
type: 'application/geo+json',
href: `${endpoint}/collections/${id}`
}
})
Expand Down Expand Up @@ -627,11 +636,13 @@ const aggregate = async function (queryParameters, backend, endpoint, httpMethod
aggregations,
links: [{
rel: 'self',
type: 'application/json',
href: `${endpoint}/aggregate`
},
{
rel: 'root',
href: `${endpoint}/`
type: 'application/geo+json',
href: `${endpoint}`
}]
}
}
Expand Down Expand Up @@ -666,13 +677,13 @@ const getCatalog = async function (txnEnabled, backend, endpoint = '') {
const links = [
{
rel: 'self',
type: 'application/json',
href: `${endpoint}/`
type: 'application/geo+json',
href: `${endpoint}`
},
{
rel: 'root',
type: 'application/json',
href: `${endpoint}/`
type: 'application/geo+json',
href: `${endpoint}`
},
{
rel: 'conformance',
Expand Down Expand Up @@ -717,8 +728,8 @@ const getCatalog = async function (txnEnabled, backend, endpoint = '') {
if (docsUrl) {
links.push({
rel: 'server',
type: 'text/html',
href: docsUrl,
type: 'text/html'
})
}

Expand All @@ -731,13 +742,24 @@ const getCatalog = async function (txnEnabled, backend, endpoint = '') {
}

const getCollections = async function (backend, endpoint = '') {
// TODO: implement proper pagination, as this will only return up to
// COLLECTION_LIMIT collections
const results = await backend.getCollections(1, COLLECTION_LIMIT)
const linkedCollections = addCollectionLinks(results, endpoint)

// TODO: Attention, this is a SHIM. Implement proper pagination!
const resp = {
collections: results,
links: [],
links: [
{
rel: 'self',
type: 'application/json',
href: `${endpoint}/collections`,
},
{
rel: 'root',
type: 'application/geo+json',
href: `${endpoint}`,
},
],
context: {
page: 1,
limit: COLLECTION_LIMIT,
Expand Down