Skip to content

Commit

Permalink
Properly type fetchById and ensure returns null if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
wernst committed May 2, 2024
1 parent a59738a commit 02284c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-books-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@triplit/client': patch
---

Properly type fetchById and ensure returns null if not found
6 changes: 4 additions & 2 deletions packages/client/src/triplit-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class TriplitClient<M extends ClientSchema | undefined = undefined> {
id: string,
queryParams?: FetchByIdQueryParams<M, CN>,
options?: Partial<FetchOptions>
) {
): Promise<ClientFetchResultEntity<ClientQuery<M, CN>> | null> {
this.logger.debug(
'fetchById START',
collectionName,
Expand All @@ -371,7 +371,9 @@ export class TriplitClient<M extends ClientSchema | undefined = undefined> {
queryParams,
options
);
return results.get(id);
const entity = results.get(id);
if (!entity) return null;
return entity;
}

async fetchOne<CQ extends ClientQuery<M, any>>(
Expand Down

0 comments on commit 02284c0

Please sign in to comment.