{"expireTime":9007200821629985000,"key":"gatsby-plugin-mdx-entire-payload-644c3e8fc0af7c5389389cefd859c72b-","val":{"mdast":{"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"The dynamic schema lets you choose a schema based on the data that is being normalized. \nFor its shape, this schema takes a function that will be called with the data. The return value of\nthat function will then be used to continue the normalizing. ","position":{"start":{"line":2,"column":1,"offset":1},"end":{"line":4,"column":62,"offset":250},"indent":[1,1]}},{"type":"emphasis","children":[{"type":"text","value":"This is useful if you have \nnon-homogeneous arrays or union types.","position":{"start":{"line":4,"column":63,"offset":251},"end":{"line":5,"column":39,"offset":317},"indent":[1]}}],"position":{"start":{"line":4,"column":62,"offset":250},"end":{"line":5,"column":40,"offset":318},"indent":[1]}}],"position":{"start":{"line":2,"column":1,"offset":1},"end":{"line":5,"column":40,"offset":318},"indent":[1,1,1]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Params","position":{"start":{"line":7,"column":4,"offset":323},"end":{"line":7,"column":10,"offset":329},"indent":[]}}],"position":{"start":{"line":7,"column":1,"offset":320},"end":{"line":7,"column":10,"offset":329},"indent":[]}},{"type":"code","lang":"js","meta":null,"value":"new DynamicSchema(shape: (*) => Schema);","position":{"start":{"line":8,"column":1,"offset":330},"end":{"line":10,"column":4,"offset":380},"indent":[1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"shape","position":{"start":{"line":12,"column":5,"offset":386},"end":{"line":12,"column":10,"offset":391},"indent":[]}}],"position":{"start":{"line":12,"column":1,"offset":382},"end":{"line":12,"column":11,"offset":392},"indent":[]}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"type:","position":{"start":{"line":13,"column":3,"offset":395},"end":{"line":13,"column":8,"offset":400},"indent":[]}}],"position":{"start":{"line":13,"column":1,"offset":393},"end":{"line":13,"column":10,"offset":402},"indent":[]}},{"type":"text","value":" ","position":{"start":{"line":13,"column":10,"offset":402},"end":{"line":13,"column":11,"offset":403},"indent":[]}},{"type":"inlineCode","value":"(*) => Schema","position":{"start":{"line":13,"column":11,"offset":403},"end":{"line":13,"column":26,"offset":418},"indent":[]}},{"type":"text","value":"  ","position":{"start":{"line":13,"column":26,"offset":418},"end":{"line":13,"column":28,"offset":420},"indent":[]}}],"position":{"start":{"line":13,"column":1,"offset":393},"end":{"line":13,"column":28,"offset":420},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"A function that will be given the current data that must return a schema to \nnormalize it with.","position":{"start":{"line":15,"column":1,"offset":422},"end":{"line":16,"column":19,"offset":517},"indent":[1]}}],"position":{"start":{"line":15,"column":1,"offset":422},"end":{"line":16,"column":19,"offset":517},"indent":[1]}},{"type":"code","lang":"js","meta":null,"value":"const group = new EntitySchema('group');\nconst user = new EntitySchema('user');\n\nconst groupOrUser = new DynamicSchema((data) => {\n    const schemaTypes = {group, user};\n    return schemaTypes[data.type];\n});","position":{"start":{"line":18,"column":1,"offset":519},"end":{"line":26,"column":4,"offset":737},"indent":[1,1,1,1,1,1,1,1]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Methods","position":{"start":{"line":29,"column":4,"offset":743},"end":{"line":29,"column":11,"offset":750},"indent":[]}}],"position":{"start":{"line":29,"column":1,"offset":740},"end":{"line":29,"column":11,"offset":750},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".normalize()","position":{"start":{"line":31,"column":5,"offset":756},"end":{"line":31,"column":17,"offset":768},"indent":[]}}],"position":{"start":{"line":31,"column":1,"offset":752},"end":{"line":31,"column":17,"offset":768},"indent":[]}},{"type":"jsx","value":"<Normalize />","position":{"start":{"line":32,"column":1,"offset":769},"end":{"line":32,"column":14,"offset":782},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":".denormalize()","position":{"start":{"line":34,"column":5,"offset":788},"end":{"line":34,"column":19,"offset":802},"indent":[]}}],"position":{"start":{"line":34,"column":1,"offset":784},"end":{"line":34,"column":19,"offset":802},"indent":[]}},{"type":"jsx","value":"<Denormalize />","position":{"start":{"line":35,"column":1,"offset":803},"end":{"line":35,"column":16,"offset":818},"indent":[]}},{"type":"heading","depth":2,"children":[{"type":"text","value":"Examples","position":{"start":{"line":38,"column":4,"offset":824},"end":{"line":38,"column":12,"offset":832},"indent":[]}}],"position":{"start":{"line":38,"column":1,"offset":821},"end":{"line":38,"column":12,"offset":832},"indent":[]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Non-homogeneous Array","position":{"start":{"line":40,"column":5,"offset":838},"end":{"line":40,"column":26,"offset":859},"indent":[]}}],"position":{"start":{"line":40,"column":1,"offset":834},"end":{"line":40,"column":26,"offset":859},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"If you have a array that contains multiple types of object the ArraySchema alone wont quite work\nbecause it can only handle homogeneous arrays. The dynamic schema can let you inspect each item\nand choose the appropriate schema to normalize it with.","position":{"start":{"line":41,"column":1,"offset":860},"end":{"line":43,"column":56,"offset":1108},"indent":[1,1]}}],"position":{"start":{"line":41,"column":1,"offset":860},"end":{"line":43,"column":56,"offset":1108},"indent":[1,1]}},{"type":"code","lang":"js","meta":"live=true","value":"function () {\n    const account = new EntitySchema('account', {shape: {}});\n    const group = new EntitySchema('group', {shape: {}});\n    const user = new EntitySchema('user', {shape: {}});\n\n    const thing = new DynamicSchema((data) => {\n        const schemaTypes = {\n            account,\n            group,\n            user\n        };\n        const schema = schemaTypes[data.type];\n        if(!schema) throw `No schema found for ${data.type}`;\n        return schema;\n    });\n\n\n    return <JSON>{new ArraySchema(thing).normalize([\n        {id: '1', type: 'user', name: 'Steve'},\n        {id: '2', type: 'group', name: 'Steves Group'},\n        {id: '3', type: 'account', name: 'Steves Account'}\n    ])}</JSON>;\n}","position":{"start":{"line":45,"column":1,"offset":1110},"end":{"line":69,"column":4,"offset":1842},"indent":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}},{"type":"heading","depth":3,"children":[{"type":"text","value":"Union Type","position":{"start":{"line":73,"column":5,"offset":1850},"end":{"line":73,"column":15,"offset":1860},"indent":[]}}],"position":{"start":{"line":73,"column":1,"offset":1846},"end":{"line":73,"column":15,"offset":1860},"indent":[]}},{"type":"paragraph","children":[{"type":"text","value":"Similar to the above example, DynamicSchemas can be used when a key in an object\ncontains more than one data type.","position":{"start":{"line":74,"column":1,"offset":1861},"end":{"line":75,"column":34,"offset":1975},"indent":[1]}}],"position":{"start":{"line":74,"column":1,"offset":1861},"end":{"line":75,"column":34,"offset":1975},"indent":[1]}},{"type":"code","lang":"js","meta":null,"value":"function () {\n    const account = new EntitySchema('account');\n    const group = new EntitySchema('group');\n    const accountOrGroup = DynamicSchema((data) => {\n        const schemaTypes = {group, user};\n        return schemaTypes[data.type];\n    });\n\n    const user = new EntitySchema('user', {shape: {\n        parent: accountOrGroup\n    });\n\n    const userList = new ArraySchema(user);\n    \n    return <JSON>{userList.normalize([\n        {id: '1', parent: {id: 'a1', name: 'account 1'}},\n        {id: '2', parent: {id: 'g1', name: 'group 1'}},\n        {id: '3', parent: {id: 'g2', name: 'group 2'}}\n    ])}</JSON>;\n\n}","position":{"start":{"line":77,"column":1,"offset":1977},"end":{"line":99,"column":4,"offset":2606},"indent":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}},{"type":"export","value":"export const _frontmatter = {\"title\":\"Dynamic Schema\",\"group\":\"Enty\"}","position":{"start":{"line":103,"column":1,"offset":2610},"end":{"line":103,"column":70,"offset":2679},"indent":[]}}],"position":{"start":{"line":1,"column":1,"offset":0},"end":{"line":103,"column":70,"offset":2679}}},"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\": \"Dynamic 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 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, \"The dynamic schema lets you choose a schema based on the data that is being normalized.\\nFor its shape, this schema takes a function that will be called with the data. The return value of\\nthat function will then be used to continue the normalizing. \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"This is useful if you have\\nnon-homogeneous arrays or union types.\")), mdx(\"h2\", null, \"Params\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"new DynamicSchema(shape: (*) => Schema);\\n\")), mdx(\"h3\", null, \"shape\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"type:\"), \" \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"(*) => Schema\"), \"  \"), mdx(\"p\", null, \"A function that will be given the current data that must return a schema to\\nnormalize it with.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"const group = new EntitySchema('group');\\nconst user = new EntitySchema('user');\\n\\nconst groupOrUser = new DynamicSchema((data) => {\\n    const schemaTypes = {group, user};\\n    return schemaTypes[data.type];\\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  }), mdx(\"h2\", null, \"Examples\"), mdx(\"h3\", null, \"Non-homogeneous Array\"), mdx(\"p\", null, \"If you have a array that contains multiple types of object the ArraySchema alone wont quite work\\nbecause it can only handle homogeneous arrays. The dynamic schema can let you inspect each item\\nand choose the appropriate schema to normalize it with.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\",\n    \"metastring\": \"live=true\",\n    \"live\": \"true\"\n  }), \"function () {\\n    const account = new EntitySchema('account', {shape: {}});\\n    const group = new EntitySchema('group', {shape: {}});\\n    const user = new EntitySchema('user', {shape: {}});\\n\\n    const thing = new DynamicSchema((data) => {\\n        const schemaTypes = {\\n            account,\\n            group,\\n            user\\n        };\\n        const schema = schemaTypes[data.type];\\n        if(!schema) throw `No schema found for ${data.type}`;\\n        return schema;\\n    });\\n\\n\\n    return <JSON>{new ArraySchema(thing).normalize([\\n        {id: '1', type: 'user', name: 'Steve'},\\n        {id: '2', type: 'group', name: 'Steves Group'},\\n        {id: '3', type: 'account', name: 'Steves Account'}\\n    ])}</JSON>;\\n}\\n\")), mdx(\"h3\", null, \"Union Type\"), mdx(\"p\", null, \"Similar to the above example, DynamicSchemas can be used when a key in an object\\ncontains more than one data type.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-js\"\n  }), \"function () {\\n    const account = new EntitySchema('account');\\n    const group = new EntitySchema('group');\\n    const accountOrGroup = DynamicSchema((data) => {\\n        const schemaTypes = {group, user};\\n        return schemaTypes[data.type];\\n    });\\n\\n    const user = new EntitySchema('user', {shape: {\\n        parent: accountOrGroup\\n    });\\n\\n    const userList = new ArraySchema(user);\\n    \\n    return <JSON>{userList.normalize([\\n        {id: '1', parent: {id: 'a1', name: 'account 1'}},\\n        {id: '2', parent: {id: 'g1', name: 'group 1'}},\\n        {id: '3', parent: {id: 'g2', name: 'group 2'}}\\n    ])}</JSON>;\\n\\n}\\n\")));\n}\n;\nMDXContent.isMDXComponent = true;","rawMDXOutput":"/* @jsx mdx */\nimport { mdx } from '@mdx-js/react';\n/* @jsx mdx */\n\nexport const _frontmatter = {\n  \"title\": \"Dynamic 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 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>{`The dynamic schema lets you choose a schema based on the data that is being normalized.\nFor its shape, this schema takes a function that will be called with the data. The return value of\nthat function will then be used to continue the normalizing. `}<em parentName=\"p\">{`This is useful if you have\nnon-homogeneous arrays or union types.`}</em></p>\n    <h2>{`Params`}</h2>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`new DynamicSchema(shape: (*) => Schema);\n`}</code></pre>\n    <h3>{`shape`}</h3>\n    <p><strong parentName=\"p\">{`type:`}</strong>{` `}<inlineCode parentName=\"p\">{`(*) => Schema`}</inlineCode>{`  `}</p>\n    <p>{`A function that will be given the current data that must return a schema to\nnormalize it with.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`const group = new EntitySchema('group');\nconst user = new EntitySchema('user');\n\nconst groupOrUser = new DynamicSchema((data) => {\n    const schemaTypes = {group, user};\n    return schemaTypes[data.type];\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    <h2>{`Examples`}</h2>\n    <h3>{`Non-homogeneous Array`}</h3>\n    <p>{`If you have a array that contains multiple types of object the ArraySchema alone wont quite work\nbecause it can only handle homogeneous arrays. The dynamic schema can let you inspect each item\nand choose the appropriate schema to normalize it with.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\",\n        \"metastring\": \"live=true\",\n        \"live\": \"true\"\n      }}>{`function () {\n    const account = new EntitySchema('account', {shape: {}});\n    const group = new EntitySchema('group', {shape: {}});\n    const user = new EntitySchema('user', {shape: {}});\n\n    const thing = new DynamicSchema((data) => {\n        const schemaTypes = {\n            account,\n            group,\n            user\n        };\n        const schema = schemaTypes[data.type];\n        if(!schema) throw \\`No schema found for \\${data.type}\\`;\n        return schema;\n    });\n\n\n    return <JSON>{new ArraySchema(thing).normalize([\n        {id: '1', type: 'user', name: 'Steve'},\n        {id: '2', type: 'group', name: 'Steves Group'},\n        {id: '3', type: 'account', name: 'Steves Account'}\n    ])}</JSON>;\n}\n`}</code></pre>\n    <h3>{`Union Type`}</h3>\n    <p>{`Similar to the above example, DynamicSchemas can be used when a key in an object\ncontains more than one data type.`}</p>\n    <pre><code parentName=\"pre\" {...{\n        \"className\": \"language-js\"\n      }}>{`function () {\n    const account = new EntitySchema('account');\n    const group = new EntitySchema('group');\n    const accountOrGroup = DynamicSchema((data) => {\n        const schemaTypes = {group, user};\n        return schemaTypes[data.type];\n    });\n\n    const user = new EntitySchema('user', {shape: {\n        parent: accountOrGroup\n    });\n\n    const userList = new ArraySchema(user);\n    \n    return <JSON>{userList.normalize([\n        {id: '1', parent: {id: 'a1', name: 'account 1'}},\n        {id: '2', parent: {id: 'g1', name: 'group 1'}},\n        {id: '3', parent: {id: 'g2', name: 'group 2'}}\n    ])}</JSON>;\n\n}\n`}</code></pre>\n\n    </MDXLayout>;\n}\n\n;\nMDXContent.isMDXComponent = true;"}}