eoapi-cdk 11.4.0 → 11.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,17 +3,15 @@ import binascii
3
3
  import enum
4
4
  import json
5
5
  from datetime import datetime
6
- from typing import TYPE_CHECKING, Dict, List, Optional, Union
6
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
7
7
  from urllib.parse import urlparse
8
8
 
9
9
  from fastapi.encoders import jsonable_encoder
10
- from fastapi.exceptions import RequestValidationError
11
10
  from pydantic import (
12
11
  BaseModel,
13
12
  Json,
14
13
  PositiveInt,
15
14
  dataclasses,
16
- error_wrappers,
17
15
  field_validator,
18
16
  )
19
17
  from stac_pydantic import Collection, Item, shared
@@ -107,25 +105,19 @@ class Ingestion(BaseModel):
107
105
  class ListIngestionRequest:
108
106
  status: Status = Status.queued
109
107
  limit: Optional[PositiveInt] = None
110
- next: Optional[str] = None
111
-
112
- def __post_init_post_parse__(self) -> None:
113
- # https://github.com/tiangolo/fastapi/issues/1474#issuecomment-1049987786
114
- if self.next is None:
115
- return
108
+ next: Optional[Any] = None
116
109
 
110
+ @field_validator("next", mode="before")
111
+ @classmethod
112
+ def decode_next_token(cls, v: Optional[str]) -> Optional[Any]:
113
+ """Decode the base64-encoded JSON pagination token supplied as a query param."""
114
+ if v is None:
115
+ return None
117
116
  try:
118
- self.next = json.loads(base64.b64decode(self.next))
117
+ return json.loads(base64.b64decode(v))
119
118
  except (UnicodeDecodeError, binascii.Error) as e:
120
- raise RequestValidationError(
121
- [
122
- error_wrappers.ErrorWrapper(
123
- ValueError(
124
- "Unable to decode next token. Should be base64 encoded JSON"
125
- ),
126
- "query.next",
127
- )
128
- ]
119
+ raise ValueError(
120
+ "Unable to decode next token. Should be base64 encoded JSON"
129
121
  ) from e
130
122
 
131
123
 
@@ -1,7 +1,7 @@
1
1
  from typing import TYPE_CHECKING, List
2
2
 
3
3
  from boto3.dynamodb import conditions
4
- from pydantic import parse_obj_as
4
+ from pydantic import TypeAdapter
5
5
 
6
6
  from . import schemas
7
7
 
@@ -35,7 +35,9 @@ class Database:
35
35
  **{"ExclusiveStartKey": next} if next else {},
36
36
  )
37
37
  return {
38
- "items": parse_obj_as(List[schemas.Ingestion], response["Items"]),
38
+ "items": TypeAdapter(List[schemas.Ingestion]).validate_python(
39
+ response["Items"]
40
+ ),
39
41
  "next": response.get("LastEvaluatedKey"),
40
42
  }
41
43