improved DataApi types

- Added type definitions for entity data in DataApi, improving type safety across CRUD operations.
- Introduced new test cases in DataApi.spec.ts to validate the behavior of read and create operations, ensuring correct data handling and response types.
- Updated various files to accommodate the new type definitions and ensure compatibility with existing functionality.
This commit is contained in:
dswbx
2025-10-17 09:45:22 +02:00
parent f4a7cde487
commit 0a93a4a16c
13 changed files with 235 additions and 80 deletions
+2 -4
View File
@@ -167,7 +167,6 @@ export type ResponseObject<Body = any, Data = Body extends { data: infer R } ? R
data: Data;
body: Body;
ok: boolean;
status: number;
toJSON(): Data;
};
@@ -177,10 +176,10 @@ export function createResponseProxy<Body = any, Data = any>(
data?: Data,
): ResponseObject<Body, Data> {
let actualData: any = typeof data !== "undefined" ? data : body;
const _props = ["raw", "body", "ok", "status", "res", "data", "toJSON"];
const _props = ["raw", "body", "ok", "res", "data", "toJSON"];
// that's okay, since you have to check res.ok anyway
if (typeof actualData !== "object") {
if (typeof actualData !== "object" || actualData === null) {
actualData = {};
}
@@ -190,7 +189,6 @@ export function createResponseProxy<Body = any, Data = any>(
if (prop === "body") return body;
if (prop === "data") return data;
if (prop === "ok") return raw.ok;
if (prop === "status") return raw.status;
if (prop === "toJSON") {
return () => target;
}