@leodamours/jsonapi-client 1.0.2 → 1.0.4
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.
- package/README.md +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,6 +147,27 @@ await api.findAll(User, {
|
|
|
147
147
|
});
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
+
## Type-Safe Included Resources
|
|
151
|
+
|
|
152
|
+
When using `include`, the response's `included` array contains mixed resource types. Use `isResourceOf` from the DSL to narrow them:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import { isResourceOf } from "@leodamours/jsonapi-dsl";
|
|
156
|
+
|
|
157
|
+
const result = await api.findOne(Post, "1", {
|
|
158
|
+
include: "author.company,comments",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const users = result.included?.filter(isResourceOf(User));
|
|
162
|
+
// ^? InferResource<typeof User>[]
|
|
163
|
+
|
|
164
|
+
const companies = result.included?.filter(isResourceOf(Company));
|
|
165
|
+
// ^? InferResource<typeof Company>[]
|
|
166
|
+
|
|
167
|
+
const comments = result.included?.filter(isResourceOf(Comment));
|
|
168
|
+
// ^? InferResource<typeof Comment>[]
|
|
169
|
+
```
|
|
170
|
+
|
|
150
171
|
## Serialization Utilities
|
|
151
172
|
|
|
152
173
|
Lower-level serialization functions are exported for custom use:
|
package/package.json
CHANGED