Skip to content

Commit

Permalink
feat: Entity fully denormalizes & Entity -> FlatEntity for non-nested (
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed May 4, 2020
1 parent 546ad79 commit dd5e513
Show file tree
Hide file tree
Showing 24 changed files with 873 additions and 659 deletions.
105 changes: 63 additions & 42 deletions packages/normalizr/src/__tests__/__snapshots__/index.test.js.snap
Expand Up @@ -3,8 +3,8 @@
exports[`denormalize denormalizes arrays with objects inside 1`] = `
Array [
Object {
"data": Object {
"id": 1,
"data": Tacos {
"id": "1",
"type": "foo",
},
},
Expand All @@ -13,12 +13,12 @@ Array [

exports[`denormalize denormalizes entities 1`] = `
Array [
Object {
"id": 1,
Tacos {
"id": "1",
"type": "foo",
},
Object {
"id": 2,
Tacos {
"id": "2",
"type": "bar",
},
]
Expand All @@ -27,8 +27,8 @@ Array [
exports[`denormalize denormalizes ignoring unfound entities in arrays 1`] = `
Array [
Array [
Object {
"id": 1,
Tacos {
"id": "1",
"type": "foo",
},
],
Expand All @@ -40,8 +40,8 @@ exports[`denormalize denormalizes ignoring unfound entities in arrays 2`] = `
Array [
Object {
"results": Array [
Object {
"id": 1,
Tacos {
"id": "1",
"type": "foo",
},
],
Expand All @@ -52,11 +52,21 @@ Array [

exports[`denormalize denormalizes nested entities 1`] = `
Array [
Object {
"author": "8472",
Article {
"author": User {
"id": "8472",
"name": "Paul",
},
"body": "This article is great.",
"comments": Array [
"comment-123-4738",
Comment {
"comment": "I like it!",
"id": "comment-123-4738",
"user": User {
"id": "10293",
"name": "Jane",
},
},
],
"id": "123",
"title": "A Great Article",
Expand All @@ -69,12 +79,12 @@ exports[`denormalize denormalizes schema with extra members 1`] = `
Array [
Object {
"data": Array [
Object {
"id": 1,
Tacos {
"id": "1",
"type": "foo",
},
Object {
"id": 2,
Tacos {
"id": "2",
"type": "bar",
},
],
Expand All @@ -99,12 +109,12 @@ exports[`denormalize denormalizes schema with extra members but not set 1`] = `
Array [
Object {
"data": Array [
Object {
"id": 1,
Tacos {
"id": "1",
"type": "foo",
},
Object {
"id": 2,
Tacos {
"id": "2",
"type": "bar",
},
],
Expand All @@ -113,16 +123,18 @@ Array [
]
`;

exports[`denormalize denormalizes with function as idAttribute 1`] = `
exports[`denormalize denormalizes with function as pk() 1`] = `
Array [
Array [
Object {
Patron {
"guest": null,
"id": "1",
"name": "Esther",
},
Object {
"guest": "guest-2-1",
Patron {
"guest": Guest {
"guestId": 1,
},
"id": "2",
"name": "Tom",
},
Expand All @@ -140,16 +152,25 @@ Array [
]
`;

exports[`denormalize denormalizes without entities fills undefined 2`] = `
Array [
Immutable.Map {
"data": undefined,
},
false,
]
`;

exports[`denormalize set to undefined if schema key is not in entities 1`] = `
Array [
Object {
"author": "8472",
"comments": Array [
"1",
],
Article {
"author": undefined,
"body": "",
"comments": Array [],
"id": "123",
"title": "",
},
true,
false,
]
`;

Expand Down Expand Up @@ -215,11 +236,11 @@ Object {
"entities": Object {
"Tacos": Object {
"1": Tacos {
"id": 1,
"id": "1",
"type": "foo",
},
"2": Tacos {
"id": 2,
"id": "2",
"type": "bar",
},
},
Expand All @@ -240,7 +261,7 @@ Object {
"friends": Array [
"123",
],
"id": 123,
"id": "123",
},
},
},
Expand Down Expand Up @@ -291,11 +312,11 @@ Object {
"entities": Object {
"Tacos": Object {
"1": Tacos {
"id": 1,
"id": "1",
"type": "foo",
},
"2": Tacos {
"id": 2,
"id": "2",
"type": "bar",
},
},
Expand Down Expand Up @@ -326,11 +347,11 @@ Object {
"entities": Object {
"Tacos": Object {
"1": Tacos {
"id": 1,
"id": "1",
"type": "foo",
},
"2": Tacos {
"id": 2,
"id": "2",
"type": "bar",
},
},
Expand All @@ -350,11 +371,11 @@ Object {
"entities": Object {
"MyTaco": Object {
"1": MyTaco {
"id": 1,
"id": "1",
"type": "foo",
},
"2": MyTaco {
"id": 2,
"id": "2",
"type": "bar2",
},
},
Expand Down Expand Up @@ -382,11 +403,11 @@ Object {
"entities": Object {
"MyTaco": Object {
"1": MyTaco {
"id": 1,
"id": "1",
"type": "foo",
},
"2": MyTaco {
"id": 2,
"id": "2",
"type": "bar2",
},
},
Expand Down

0 comments on commit dd5e513

Please sign in to comment.