{"expireTime":9007200821600205000,"key":"gatsby-plugin-mdx-entire-payload-a67ed66ce11e7aa62f617a398f4a0ade-","val":{"mdast":{"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"Sometimes a backend will merge two data types together and in the process create an entity that is \nnot possible to normalize - Enty calls this a Tainted Entity. Consider a course page that shows\nthe completion state for the current user. The client makes a request to the course completion\nendpoint and the server responds with a course object with an attached completion. ","position":{"start":{"line":2,"column":1,"offset":1},"end":{"line":5,"column":84,"offset":375},"indent":[1,1,1]}}],"position":{"start":{"line":2,"column":1,"offset":1},"end":{"line":5,"column":84,"offset":375},"indent":[1,1,1]}},{"type":"code","lang":"js","meta":null,"value":"// /course/completion?user=derek.tibbs\n{\n    id: 'mf101',\n    name: 'Making Friends 101'\n    duration: '10 weeks',\n    completion: {\n        id: '456',\n        grade: 'A',\n        user: 'derek.tibbs',\n        completedAt: \"2019-02-20\"\n    }\n}","position":{"start":{"line":8,"column":1,"offset":378},"end":{"line":21,"column":4,"offset":630},"indent":[1,1,1,1,1,1,1,1,1,1,1,1,1]}},{"type":"paragraph","children":[{"type":"text","value":"This works fine for a single page, but when we try to normalize multiple course completions we \nrealise that each different normalization is affecting the ","position":{"start":{"line":23,"column":1,"offset":632},"end":{"line":24,"column":60,"offset":787},"indent":[1]}},{"type":"inlineCode","value":"mf101","position":{"start":{"line":24,"column":60,"offset":787},"end":{"line":24,"column":67,"offset":794},"indent":[]}},{"type":"text","value":" course entity and whoever \nnormalizes last is the winner.","position":{"start":{"line":24,"column":67,"offset":794},"end":{"line":25,"column":31,"offset":852},"indent":[1]}}],"position":{"start":{"line":23,"column":1,"offset":632},"end":{"line":25,"column":31,"offset":852},"indent":[1,1]}},{"type":"paragraph","children":[{"type":"text","value":"The CompositeEntitySchema lets you declare which keys are tainting your entity. Enty is then \nable to extract and normalize them separately.","position":{"start":{"line":27,"column":1,"offset":854},"end":{"line":28,"column":47,"offset":994},"indent":[1]}}],"position":{"start":{"line":27,"column":1,"offset":854},"end":{"line":28,"column":47,"offset":994},"indent":[1]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Params","position":{"start":{"line":31,"column":4,"offset":1000},"end":{"line":31,"column":10,"offset":1006},"indent":[]}}],"position":{"start":{"line":31,"column":1,"offset":997},"end":{"line":31,"column":10,"offset":1006},"indent":[]}},{"type":"code","lang":"flow","meta":null,"value":"new CompositeEntitySchema(\n    name: string,\n    options?: {\n        compositeKeys: {\n            [key: string]: Schema\n        },\n        shape: StructuralSchema,\n        idAttribute: (*) => string\n    }\n);","position":{"start":{"line":32,"column":1,"offset":1007},"end":{"line":43,"column":4,"offset":1226},"indent":[1,1,1,1,1,1,1,1,1,1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"name","position":{"start":{"line":45,"column":5,"offset":1232},"end":{"line":45,"column":9,"offset":1236},"indent":[]}}],"position":{"start":{"line":45,"column":1,"offset":1228},"end":{"line":45,"column":10,"offset":1237},"indent":[]}},{"type":"jsx","value":"<Name />","position":{"start":{"line":46,"column":1,"offset":1238},"end":{"line":46,"column":9,"offset":1246},"indent":[]}},{"type":"code","lang":"js","meta":null,"value":"const course = CompositeEntitySchema('course');","position":{"start":{"line":48,"column":1,"offset":1248},"end":{"line":50,"column":4,"offset":1305},"indent":[1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"options.shape","position":{"start":{"line":52,"column":5,"offset":1311},"end":{"line":52,"column":18,"offset":1324},"indent":[]}}],"position":{"start":{"line":52,"column":1,"offset":1307},"end":{"line":52,"column":19,"offset":1325},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Defines the main shape of the composite entity.","position":{"start":{"line":54,"column":1,"offset":1327},"end":{"line":54,"column":48,"offset":1374},"indent":[]}}],"position":{"start":{"line":54,"column":1,"offset":1327},"end":{"line":54,"column":48,"offset":1374},"indent":[]}},{"type":"code","lang":"js","meta":null,"value":"const course = CompositeEntitySchema('course', {\n    shape: course\n});","position":{"start":{"line":56,"column":1,"offset":1376},"end":{"line":60,"column":4,"offset":1456},"indent":[1,1,1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"options.compositeKeys","position":{"start":{"line":63,"column":5,"offset":1463},"end":{"line":63,"column":26,"offset":1484},"indent":[]}}],"position":{"start":{"line":63,"column":1,"offset":1459},"end":{"line":63,"column":26,"offset":1484},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":64,"column":3,"offset":1487},"end":{"line":64,"column":8,"offset":1492},"indent":[]}}],"position":{"start":{"line":64,"column":1,"offset":1485},"end":{"line":64,"column":10,"offset":1494},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":64,"column":10,"offset":1494},"end":{"line":64,"column":11,"offset":1495},"indent":[]}},{"type":"inlineCode","value":"{[key: string]: Schema}","position":{"start":{"line":64,"column":11,"offset":1495},"end":{"line":64,"column":36,"offset":1520},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":64,"column":36,"offset":1520},"end":{"line":64,"column":38,"offset":1522},"indent":[]}}],"position":{"start":{"line":64,"column":1,"offset":1485},"end":{"line":64,"column":38,"offset":1522},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"An object mapping of the keys that are tainting this entity and the schema that they belong to.","position":{"start":{"line":66,"column":1,"offset":1524},"end":{"line":66,"column":96,"offset":1619},"indent":[]}}],"position":{"start":{"line":66,"column":1,"offset":1524},"end":{"line":66,"column":96,"offset":1619},"indent":[]}},{"type":"code","lang":"js","meta":null,"value":"const completion = new EntitySchema('completion', {shape: new ObjectSchema({}));\nconst course = CompositeEntitySchema('course', {\n   shape: course,\n   compositeKeys: {\n        completion\n   }\n});","position":{"start":{"line":68,"column":1,"offset":1621},"end":{"line":76,"column":4,"offset":1826},"indent":[1,1,1,1,1,1,1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"options.idAttribute","position":{"start":{"line":79,"column":5,"offset":1833},"end":{"line":79,"column":24,"offset":1852},"indent":[]}}],"position":{"start":{"line":79,"column":1,"offset":1829},"end":{"line":79,"column":24,"offset":1852},"indent":[]}},{"type":"jsx","value":"<Id/>","position":{"start":{"line":80,"column":1,"offset":1853},"end":{"line":80,"column":6,"offset":1858},"indent":[]}},{"type":"code","lang":"js","meta":null,"value":"const course = new CompositeEntitySchema('course', {\n    idAttribute: (course) => course.id\n});","position":{"start":{"line":82,"column":1,"offset":1860},"end":{"line":86,"column":4,"offset":1965},"indent":[1,1,1,1]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Methods","position":{"start":{"line":88,"column":4,"offset":1970},"end":{"line":88,"column":11,"offset":1977},"indent":[]}}],"position":{"start":{"line":88,"column":1,"offset":1967},"end":{"line":88,"column":11,"offset":1977},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".normalize()","position":{"start":{"line":90,"column":5,"offset":1983},"end":{"line":90,"column":17,"offset":1995},"indent":[]}}],"position":{"start":{"line":90,"column":1,"offset":1979},"end":{"line":90,"column":17,"offset":1995},"indent":[]}},{"type":"jsx","value":"<Normalize />","position":{"start":{"line":91,"column":1,"offset":1996},"end":{"line":91,"column":14,"offset":2009},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".denormalize()","position":{"start":{"line":93,"column":5,"offset":2015},"end":{"line":93,"column":19,"offset":2029},"indent":[]}}],"position":{"start":{"line":93,"column":1,"offset":2011},"end":{"line":93,"column":19,"offset":2029},"indent":[]}},{"type":"jsx","value":"<Denormalize />","position":{"start":{"line":94,"column":1,"offset":2030},"end":{"line":94,"column":16,"offset":2045},"indent":[]}},{"type":"export","value":"export const _frontmatter = {\"title\":\"Composite Entity Schema\",\"group\":\"Enty\"}","position":{"start":{"line":97,"column":1,"offset":2048},"end":{"line":97,"column":79,"offset":2126},"indent":[]}}],"position":{"start":{"line":1,"column":1,"offset":0},"end":{"line":97,"column":79,"offset":2126}}},"scopeImports":["import React from 'react'"],"scopeIdentifiers":["React"],"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Composite Entity Schema\",\n  \"group\": \"Enty\"\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar Name = makeShortcode(\"Name\");\nvar Id = makeShortcode(\"Id\");\nvar Normalize = makeShortcode(\"Normalize\");\nvar Denormalize = makeShortcode(\"Denormalize\");\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Sometimes a backend will merge two data types together and in the process create an entity that is\\nnot possible to normalize - Enty calls this a Tainted Entity. Consider a course page that shows\\nthe completion state for the current user. The client makes a request to the course completion\\nendpoint and the server responds with a course object with an attached completion. \"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"// /course/completion?user=derek.tibbs\\n{\\n    id: 'mf101',\\n    name: 'Making Friends 101'\\n    duration: '10 weeks',\\n    completion: {\\n        id: '456',\\n        grade: 'A',\\n        user: 'derek.tibbs',\\n        completedAt: \\\"2019-02-20\\\"\\n    }\\n}\\n\")), mdx(\"p\", null, \"This works fine for a single page, but when we try to normalize multiple course completions we\\nrealise that each different normalization is affecting the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"mf101\"), \" course entity and whoever\\nnormalizes last is the winner.\"), mdx(\"p\", null, \"The CompositeEntitySchema lets you declare which keys are tainting your entity. Enty is then\\nable to extract and normalize them separately.\"), mdx(\"h2\", null, \"Params\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-flow\"\n  }), \"new CompositeEntitySchema(\\n    name: string,\\n    options?: {\\n        compositeKeys: {\\n            [key: string]: Schema\\n        },\\n        shape: StructuralSchema,\\n        idAttribute: (*) => string\\n    }\\n);\\n\")), mdx(\"h3\", null, \"name\"), mdx(Name, {\n    mdxType: \"Name\"\n  }), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const course = CompositeEntitySchema('course');\\n\")), mdx(\"h3\", null, \"options.shape\"), mdx(\"p\", null, \"Defines the main shape of the composite entity.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const course = CompositeEntitySchema('course', {\\n    shape: course\\n});\\n\")), mdx(\"h3\", null, \"options.compositeKeys\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"{[key: string]: Schema}\"), \"  \"), mdx(\"p\", null, \"An object mapping of the keys that are tainting this entity and the schema that they belong to.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const completion = new EntitySchema('completion', {shape: new ObjectSchema({}));\\nconst course = CompositeEntitySchema('course', {\\n   shape: course,\\n   compositeKeys: {\\n        completion\\n   }\\n});\\n\")), mdx(\"h3\", null, \"options.idAttribute\"), mdx(Id, {\n    mdxType: \"Id\"\n  }), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const course = new CompositeEntitySchema('course', {\\n    idAttribute: (course) => course.id\\n});\\n\")), mdx(\"h2\", null, \"Methods\"), mdx(\"h3\", null, \".normalize()\"), mdx(Normalize, {\n    mdxType: \"Normalize\"\n  }), mdx(\"h3\", null, \".denormalize()\"), mdx(Denormalize, {\n    mdxType: \"Denormalize\"\n  }));\n}\n;\nMDXContent.isMDXComponent = true;","rawMDXOutput":"/* @jsx mdx */\nimport { mdx } from '@mdx-js/react';\n/* @jsx mdx */\n\nexport const _frontmatter = {\n  \"title\": \"Composite Entity Schema\",\n  \"group\": \"Enty\"\n};\nconst makeShortcode = name => function MDXDefaultShortcode(props) {\n  console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\")\n  return <div {...props}/>\n};\nconst Name = makeShortcode(\"Name\");\nconst Id = makeShortcode(\"Id\");\nconst Normalize = makeShortcode(\"Normalize\");\nconst Denormalize = makeShortcode(\"Denormalize\");\nconst layoutProps = {\n  _frontmatter\n};\nconst MDXLayout = \"wrapper\"\nexport default function MDXContent({\n  components,\n  ...props\n}) {\n  return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\"MDXLayout\">\n    <p>{`Sometimes a backend will merge two data types together and in the process create an entity that is\nnot possible to normalize - Enty calls this a Tainted Entity. Consider a course page that shows\nthe completion state for the current user. The client makes a request to the course completion\nendpoint and the server responds with a course object with an attached completion. `}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`// /course/completion?user=derek.tibbs\n{\n    id: 'mf101',\n    name: 'Making Friends 101'\n    duration: '10 weeks',\n    completion: {\n        id: '456',\n        grade: 'A',\n        user: 'derek.tibbs',\n        completedAt: \"2019-02-20\"\n    }\n}\n`}</code></pre>\n    <p>{`This works fine for a single page, but when we try to normalize multiple course completions we\nrealise that each different normalization is affecting the `}<inlineCode parentName=\"p\">{`mf101`}</inlineCode>{` course entity and whoever\nnormalizes last is the winner.`}</p>\n    <p>{`The CompositeEntitySchema lets you declare which keys are tainting your entity. Enty is then\nable to extract and normalize them separately.`}</p>\n    <h2>{`Params`}</h2>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-flow\"\n      }}>{`new CompositeEntitySchema(\n    name: string,\n    options?: {\n        compositeKeys: {\n            [key: string]: Schema\n        },\n        shape: StructuralSchema,\n        idAttribute: (*) => string\n    }\n);\n`}</code></pre>\n    <h3>{`name`}</h3>\n    <Name mdxType=\"Name\" />\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const course = CompositeEntitySchema('course');\n`}</code></pre>\n    <h3>{`options.shape`}</h3>\n    <p>{`Defines the main shape of the composite entity.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const course = CompositeEntitySchema('course', {\n    shape: course\n});\n`}</code></pre>\n    <h3>{`options.compositeKeys`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`{[key: string]: Schema}`}</inlineCode>{`  `}</p>\n    <p>{`An object mapping of the keys that are tainting this entity and the schema that they belong to.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const completion = new EntitySchema('completion', {shape: new ObjectSchema({}));\nconst course = CompositeEntitySchema('course', {\n   shape: course,\n   compositeKeys: {\n        completion\n   }\n});\n`}</code></pre>\n    <h3>{`options.idAttribute`}</h3>\n    <Id mdxType=\"Id\" />\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const course = new CompositeEntitySchema('course', {\n    idAttribute: (course) => course.id\n});\n`}</code></pre>\n    <h2>{`Methods`}</h2>\n    <h3>{`.normalize()`}</h3>\n    <Normalize mdxType=\"Normalize\" />\n    <h3>{`.denormalize()`}</h3>\n    <Denormalize mdxType=\"Denormalize\" />\n\n    </MDXLayout>;\n}\n\n;\nMDXContent.isMDXComponent = true;"}}