-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloned-document-resource.js.map
1 lines (1 loc) · 6.02 KB
/
cloned-document-resource.js.map
1
{"version":3,"file":"cloned-document-resource.js","sourceRoot":"","sources":["../src/cloned-document-resource.ts"],"names":[],"mappings":";;;;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAmB,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAIjC,MAAM;;;;;;gBAOE,eAAgD,EAChD,eAAyC,EACzC,MAAwB;;QAGxB,IAAI,eAAe,YAAY,QAAQ,EAAE;YACrC,IAAI,CAAC,sBAAsB,GAAG,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAClE;aAAM;YACH,IAAI,CAAC,sBAAsB,GAAG,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;SAC3D;QACD,IAAI,gBAAgB,CAAC,eAAe,CAAC,EAAE;YACnC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;SAChE;aAAM;YACH,IAAI,CAAC,eAAe,GAAG,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;SACpD;QACD,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAClC,IAAI,CAAC,6BAA6B,EAAE,CAAC;QACrC,IAAI,CAAC,wBAAwB,EAAE,CAAC;;;;;IAG7B,iBAAiB;QACpB,OAAO,IAAI,CAAC,eAAe,CAAC;;;;;IAGxB,wBAAwB;QAC5B,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE;YACzE,OAAO,IAAI,CAAC;SACf;;QACD,IAAI,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;QAC3D,IAAI,CAAC,eAAe,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,C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AO,IAAI,CAAC;;;;;IAGR,0BAA0B;QAC9B,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,UAAU,EAAE;YACvF,OAAO,IAAI,CAAC;SACf;QACD,KAAK,IAAI,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE;YACxD,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;gBAC5G,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;aAC1D;SACJ;QAED,OAAO,IAAI,CAAC;;CAEnB","sourcesContent":["import { IDocumentResource } from './interfaces/data-object';\nimport { Resource } from './resource';\nimport { IClonedResource, isClonedResource } from './interfaces/cloned-resource';\nimport { isEqual } from 'lodash';\nimport { IParamsResource } from './interfaces';\nimport { IDataResource } from './interfaces/data-resource';\n\nexport class ClonedDocumentResource {\n // @todo: cannot implement IDocumentResource because toObject returns an object, not an instance,\n // so if something changed in this response, we would have to duplicate code here...\n private resource_object: IDocumentResource;\n private parent_resource_object: IDocumentResource;\n\n public constructor(\n cloned_resource: IClonedResource | IDataResource,\n parent_resource: Resource | IDataResource,\n params?: IParamsResource\n ) {\n // calling toObject two times because we need different objects\n if (parent_resource instanceof Resource) {\n this.parent_resource_object = parent_resource.toObject(params);\n } else {\n this.parent_resource_object = { data: parent_resource };\n }\n if (isClonedResource(cloned_resource)) {\n this.resource_object = cloned_resource.superToObject(params);\n } else {\n this.resource_object = { data: cloned_resource };\n }\n this.removeDuplicatedAttributes();\n this.removeDuplicatedRelationships();\n this.removeDuplicatedIncludes();\n }\n\n public getResourceObject(): IDocumentResource {\n return this.resource_object;\n }\n\n private removeDuplicatedIncludes(): this {\n if (!this.resource_object.included || !this.parent_resource_object.included) {\n return this;\n }\n let parent_included = this.parent_resource_object.included;\n this.resource_object.included = this.resource_object.included.filter(included_resource => {\n return !isEqual(included_resource, parent_included.find(include => include.id === included_resource.id));\n });\n this.resource_object.included = this.resource_object.included.map(included => {\n if (!parent_included.find(include => include.id === included.id)) {\n return included;\n }\n\n return new ClonedDocumentResource(included, parent_included.find(include => include.id === included.id)).getResourceObject()\n .data;\n });\n\n return this;\n }\n\n private removeDuplicatedRelationships(): this {\n if (!this.resource_object.data.relationships || !this.parent_resource_object.data.relationships) {\n return this;\n }\n for (let relationship in this.resource_object.data.relationships) {\n if (\n isEqual(this.resource_object.data.relationships[relationship], this.parent_resource_object.data.relationships[relationship])\n ) {\n delete this.resource_object.data.relationships[relationship];\n }\n }\n\n return this;\n }\n\n private removeDuplicatedAttributes(): this {\n if (!this.resource_object.data.attributes || !this.parent_resource_object.data.attributes) {\n return this;\n }\n for (let attribute in this.resource_object.data.attributes) {\n if (this.resource_object.data.attributes[attribute] === this.parent_resource_object.data.attributes[attribute]) {\n delete this.resource_object.data.attributes[attribute];\n }\n }\n\n return this;\n }\n}\n"]}