Skip to content

Commit 501cb82

Browse files
committed
enhance: Remove name in toJSON() for Entities
1 parent 8564893 commit 501cb82

File tree

14 files changed

+92
-112
lines changed

14 files changed

+92
-112
lines changed

.changeset/five-meals-refuse.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@data-client/endpoint': patch
3+
'@data-client/graphql': patch
4+
'@data-client/rest': patch
5+
---
6+
7+
Remove name in toJSON() for Entities

.changeset/four-berries-jog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@data-client/endpoint': patch
3+
'@data-client/graphql': patch
4+
'@data-client/rest': patch
5+
---
6+
7+
Add toString() to Collection

packages/endpoint/src/schemas/Collection.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ export default class CollectionSchema<
121121
return this.schema.schema;
122122
}
123123

124+
toString() {
125+
return this.key;
126+
}
127+
124128
toJSON() {
125129
return {
126-
name: `Collection(${this.schema.schema.name})`,
127-
schema: this.schema.schema.toJSON(),
128130
key: this.key,
131+
schema: this.schema.schema.toJSON(),
129132
};
130133
}
131134

packages/endpoint/src/schemas/EntitySchema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ export default function EntitySchema<TBase extends Constructor>(
2828

2929
static toJSON() {
3030
return {
31-
name: this.name,
32-
schema: this.schema,
3331
key: this.key,
32+
schema: this.schema,
3433
};
3534
}
3635

packages/endpoint/src/schemas/__tests__/__snapshots__/All.test.ts.snap

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ See https://dataclient.io/rest/api/RestEndpoint#parseResponse for more informati
284284
285285
Schema: [
286286
{
287-
"name": "User",
288-
"schema": {},
289-
"key": "User"
287+
"key": "User",
288+
"schema": {}
290289
}
291290
]
292291
Input: "[{"id":5}]""
@@ -297,9 +296,8 @@ exports[`AllSchema normalization (%s) should throw a custom error if data loads
297296
298297
Schema: [
299298
{
300-
"name": "User",
301-
"schema": {},
302-
"key": "User"
299+
"key": "User",
300+
"schema": {}
303301
}
304302
]
305303
Input: "abc""

packages/endpoint/src/schemas/__tests__/__snapshots__/Array.test.js.snap

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,8 @@ See https://dataclient.io/rest/api/RestEndpoint#parseResponse for more informati
446446
447447
Schema: [
448448
{
449-
"name": "User",
450-
"schema": {},
451-
"key": "User"
449+
"key": "User",
450+
"schema": {}
452451
}
453452
]
454453
Input: "[{"id":5}]""
@@ -459,9 +458,8 @@ exports[`ArraySchema normalization (plain) Object should throw a custom error if
459458
460459
Schema: [
461460
{
462-
"name": "User",
463-
"schema": {},
464-
"key": "User"
461+
"key": "User",
462+
"schema": {}
465463
}
466464
]
467465
Input: "abc""
@@ -913,9 +911,8 @@ See https://dataclient.io/rest/api/RestEndpoint#parseResponse for more informati
913911
914912
Schema: [
915913
{
916-
"name": "User",
917-
"schema": {},
918-
"key": "User"
914+
"key": "User",
915+
"schema": {}
919916
}
920917
]
921918
Input: "[{"id":5}]""
@@ -926,9 +923,8 @@ exports[`ArraySchema normalization (schema) Object should throw a custom error i
926923
927924
Schema: [
928925
{
929-
"name": "User",
930-
"schema": {},
931-
"key": "User"
926+
"key": "User",
927+
"schema": {}
932928
}
933929
]
934930
Input: "abc""

packages/endpoint/src/schemas/__tests__/__snapshots__/Collection.test.ts.snap

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,11 @@ exports[`CollectionSchema normalization should throw a custom error if data load
318318
"Unexpected input given to normalize. Expected type to be "object", found "string".
319319
320320
Schema: {
321-
"name": "Collection(Todo)",
321+
"key": "[Todo]",
322322
"schema": {
323-
"name": "Todo",
324-
"schema": {},
325-
"key": "Todo"
326-
},
327-
"key": "[Todo]"
323+
"key": "Todo",
324+
"schema": {}
325+
}
328326
}
329327
Input: "abc""
330328
`;
@@ -333,13 +331,11 @@ exports[`CollectionSchema normalization should throw a custom error if data load
333331
"Unexpected input given to normalize. Expected type to be "object", found "null".
334332
335333
Schema: {
336-
"name": "Collection(Todo)",
334+
"key": "[Todo]",
337335
"schema": {
338-
"name": "Todo",
339-
"schema": {},
340-
"key": "Todo"
341-
},
342-
"key": "[Todo]"
336+
"key": "Todo",
337+
"schema": {}
338+
}
343339
}
344340
Input: "null""
345341
`;

packages/endpoint/src/schemas/__tests__/__snapshots__/Entity.test.ts.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,8 @@ exports[`Entity normalization should throw a custom error if data loads with str
549549
550550
Schema: {
551551
"data": {
552-
"name": "MyEntity",
553-
"schema": {},
554-
"key": "MyEntity"
552+
"key": "MyEntity",
553+
"schema": {}
555554
}
556555
}
557556
Input: "hibho""

packages/endpoint/src/schemas/__tests__/__snapshots__/EntitySchema.test.ts.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,8 @@ exports[`EntitySchema normalization should throw a custom error if data loads wi
561561
562562
Schema: {
563563
"data": {
564-
"name": "EntityMixin",
565-
"schema": {},
566-
"key": "MyData"
564+
"key": "MyData",
565+
"schema": {}
567566
}
568567
}
569568
Input: "hibho""

packages/react/src/__tests__/__snapshots__/integration-endpoint.web.tsx.snap

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,13 @@ exports[`DataProvider useSuspense() should throw errors on malformed response 1`
196196
[Error: Error processing GET http://test.com/article-cooler/878
197197
198198
Full Schema: {
199-
"name": "CoolerArticle",
199+
"key": "CoolerArticle",
200200
"schema": {
201201
"author": {
202-
"name": "User",
203-
"schema": {},
204-
"key": "User"
202+
"key": "User",
203+
"schema": {}
205204
}
206-
},
207-
"key": "CoolerArticle"
205+
}
208206
}
209207
210208
Error:
@@ -417,15 +415,13 @@ exports[`ExternalDataProvider useSuspense() should throw errors on malformed res
417415
[Error: Error processing GET http://test.com/article-cooler/878
418416
419417
Full Schema: {
420-
"name": "CoolerArticle",
418+
"key": "CoolerArticle",
421419
"schema": {
422420
"author": {
423-
"name": "User",
424-
"schema": {},
425-
"key": "User"
421+
"key": "User",
422+
"schema": {}
426423
}
427-
},
428-
"key": "CoolerArticle"
424+
}
429425
}
430426
431427
Error:

0 commit comments

Comments
 (0)