Skip to content

Commit 5bd9bae

Browse files
committed
Allow syncing null document data
1 parent 3e74608 commit 5bd9bae

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Allow syncing `null` document data.
13+
1014
## [0.2.0-beta.1] - 2024-05-14
1115

1216
### ⚠️ Breaking Changes

src/store.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,15 @@ export class Store<Schemas extends SchemaCollection = {}> {
6161
): ModelForType<Type, Schemas> | ModelForType<Type, Schemas>[] | null {
6262
document.included?.map((resource) => this.syncResource(resource));
6363

64-
return Array.isArray(document.data)
65-
? document.data.map((resource) => this.syncResource(resource))
66-
: this.syncResource(document.data);
64+
if (Array.isArray(document.data)) {
65+
return document.data.map((resource) => this.syncResource(resource));
66+
}
67+
68+
if (document.data) {
69+
return this.syncResource(document.data);
70+
}
71+
72+
return null;
6773
}
6874

6975
public syncResource<Type extends (keyof Schemas & string) | (string & {})>(

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Model } from './model.ts';
22

33
export interface JsonApiDocument<Type extends string = string> {
4-
data: JsonApiResource<Type> | JsonApiResource<Type>[];
4+
data: JsonApiResource<Type> | JsonApiResource<Type>[] | null;
55
included?: JsonApiResource[];
66
meta?: Record<string, any>;
77
links?: Record<string, any>;

0 commit comments

Comments
 (0)