Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- If an invalid sortby parameter is supplied, a 400 status is returned (instead of 500) with
a helpful error message.
- Bbox queries outside of [-180, -90, 180, 90] return a 400 error
- STAC Items passed to the ingest lambda require the collection field to be set

## [4.5.0]

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ Comprehensive documentation is available at **[stac-utils.github.io/stac-server]

### Quick Links

- **[Getting Started](https://stac-utils.github.io/stac-server/getting-started/overview/)** - Installation and quick setup
- **[Usage Guide](https://stac-utils.github.io/stac-server/usage/)** - Searching, filtering, aggregations, and more
- **[Configuration](https://stac-utils.github.io/stac-server/configuration/)** - Environment variables and collection settings
- **[Deployment](https://stac-utils.github.io/stac-server/deployment/)** - AWS deployment with Serverless Framework
- **[API Reference](https://stac-utils.github.io/stac-server/reference/api/)** - Complete endpoint documentation
- **[Architecture](https://stac-utils.github.io/stac-server/reference/architecture/)** - System design and data flows
- **[Contributing](https://stac-utils.github.io/stac-server/development/contributing/)** - Development setup and guidelines
- **[Getting Started](https://stac-utils.github.io/stac-server/latest/getting-started/overview/)** - Installation and quick setup
- **[Usage Guide](https://stac-utils.github.io/stac-server/latest/usage/)** - Searching, filtering, aggregations, and more
- **[Configuration](https://stac-utils.github.io/stac-server/latest/configuration/)** - Environment variables and collection settings
- **[Deployment](https://stac-utils.github.io/stac-server/latest/deployment/)** - AWS deployment with Serverless Framework
- **[API Reference](https://stac-utils.github.io/stac-server/latest/reference/api/)** - Complete endpoint documentation
- **[Architecture](https://stac-utils.github.io/stac-server/latest/reference/architecture/)** - System design and data flows
- **[Contributing](https://stac-utils.github.io/stac-server/latest/development/contributing/)** - Development setup and guidelines

### Supported Versions

Expand Down
15 changes: 14 additions & 1 deletion src/lib/stac-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ export function isCollection(record) {
return record && record.type === 'Collection'
}

export class InvalidSTACItemException extends Error {
constructor(message) {
super(message)
this.name = this.constructor.name
}
}

export function isItem(record) {
return record && record.type === 'Feature'
if (record && record.type === 'Feature') {
if ('collection' in record) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming we can't do any model validation and are just directly checking for the key since this is just vanilla JS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much, yeah. There is a library (that is used in other places in stac-server) called zod that is pretty similar to pydantic in the JS world, but there isn't the level of integration with the web framework in this case as in the FastAPI world. I definitely thought about adding full on payload model validation, but that would be a significant addition and it felt like a lot for a small bugfix. Definitely open to creating a ticket suggesting adding it...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like all the model stuff should probably come with the typescript change over. I know that's gonna be a substantial move so not sure where that fits on the roadmap.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point, the model/typing integration could work really well.

return true
}
throw new InvalidSTACItemException('STAC Item must specify a collection')
}
return false
}

export function isStacEntity(record) {
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/test-stac-utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// @ts-nocheck

import test from 'ava'
import { getStartAndEndDates } from '../../src/lib/stac-utils.js'
import { getStartAndEndDates, InvalidSTACItemException, isItem } from '../../src/lib/stac-utils.js'
import { loadFixture } from '../helpers/utils.js'

test('getStartandEndDates uses item datetime', (t) => {
const stringDate = '1955-11-05T13:00:00Z'
const { startDate, endDate } = getStartAndEndDates({
type: 'Feature',
id: 'test',
collection: 'test',
properties: {
datetime: stringDate
}
Expand All @@ -24,6 +26,7 @@ test('getStartandEndDates uses item start_datetime and end_datetime', (t) => {
const { startDate, endDate } = getStartAndEndDates({
type: 'Feature',
id: 'test',
collection: 'test',
properties: {
datetime,
start_datetime: startDatetime,
Expand All @@ -40,6 +43,7 @@ test('getStartandEndDates uses item start_datetime and end_datetime with null da
const { startDate, endDate } = getStartAndEndDates({
type: 'Feature',
id: 'test',
collection: 'test',
properties: {
datetime: null,
start_datetime: startDatetime,
Expand All @@ -54,6 +58,7 @@ test('getStartandEndDates returns undefineds if item datetime is null', (t) => {
const { startDate, endDate } = getStartAndEndDates({
type: 'Feature',
id: 'test',
collection: 'test',
properties: {
datetime: null
}
Expand Down Expand Up @@ -135,3 +140,14 @@ test('getStartandEndDates only looks at first collection interval', (t) => {
t.deepEqual(undefined, startDate, 'startDate is not undefined')
t.deepEqual(undefined, endDate, 'endDate is not undefined')
})

test('isItem requires collection field', async (t) => {
const record = await loadFixture('stac/LC80100102015050LGN00.json')
delete record.collection

t.throws(() => {
isItem(record)
}, {
instanceOf: InvalidSTACItemException,
}, 'STAC Item must specify a collection')
})