-
Notifications
You must be signed in to change notification settings - Fork 0
/
document-collection.js.map
1 lines (1 loc) · 12.2 KB
/
document-collection.js.map
1
{"version":3,"file":"document-collection.js","sourceRoot":"","sources":["../src/document-collection.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;;;;;AAG1C,MAAM,gCAAgE,SAAQ,QAAQ;;;oBAC9B,EAAE;oBAExC,IAAI,IAAI,EAAE;mBACX,CAAC;uBACyB,KAAK;;;;;;IAGrC,OAAO,CAAC,iBAA2B;QACtC,OAAO,iBAAiB,CAAC,EAAE,CAAC;;;;;;IAGzB,IAAI,CAAC,EAAU;QAClB,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,EAAE;YACxB,OAAO,IAAI,CAAC;SACf;;QAGD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACvC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBACxB,yBAAU,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC;aAC1B;SACJ;QAED,OAAO,IAAI,CAAC;;;;;;IAGT,IAAI,CAAC,eAA2D;QAEnE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,SAAS,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;;QAGzC,IAAI,IAAI,CAAC,IAAI,IAAI,eAAe,CAAC,IAAI,EAAE;YACnC,IAAI,CAAC,IAAI,CA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import { CacheableHelper } from './services/cacheable-helper.';\nimport { IParamsCollection } from './interfaces/params-collection';\nimport { Resource } from './resource';\nimport { Page } from './services/page';\nimport { Document, SourceType } from './document';\nimport { ICacheable } from './interfaces/cacheable';\nimport { Converter } from './services/converter';\nimport { IDataCollection, ICacheableDataCollection } from './interfaces/data-collection';\nimport { IDataResource, IBasicDataResource } from './interfaces/data-resource';\nimport { isDevMode } from '@angular/core';\n\n// used for collections on relationships, for parent document use DocumentCollection\nexport class RelatedDocumentCollection<R extends Resource = Resource> extends Document implements ICacheable {\n public data: Array<Resource | IBasicDataResource> = [];\n // public data: Array<Resource | IBasicDataResource> = [];\n public page = new Page();\n public ttl = 0;\n public content: 'ids' | 'collection' = 'ids';\n public data_collection: IDataCollection;\n\n public trackBy(iterated_resource: Resource): string {\n return iterated_resource.id;\n }\n\n public find(id: string): R | null {\n if (this.content === 'ids') {\n return null;\n }\n\n // this is the best way: https://jsperf.com/fast-array-foreach\n for (let i = 0; i < this.data.length; i++) {\n if (this.data[i].id === id) {\n return <R>this.data[i];\n }\n }\n\n return null;\n }\n\n public fill(data_collection: IDataCollection | ICacheableDataCollection): void {\n \n this.data_collection = data_collection;\n Converter.buildIncluded(data_collection);\n\n // sometimes get Cannot set property 'number' of undefined (page)\n if (this.page && data_collection.meta) {\n this.page.number = data_collection.meta.page || 1;\n this.page.resources_per_page = data_collection.meta.resources_per_page || null; // @deprecated (v2.0.2)\n this.page.size = data_collection.meta.resources_per_page || null;\n this.page.total_resources = data_collection.meta.total_resources || null;\n }\n\n // convert and add new dataresoures to final collection\n let new_ids = {};\n this.data.length = 0;\n this.builded = data_collection.data && data_collection.data.length === 0;\n for (let dataresource of data_collection.data) {\n try {\n let res = this.getResourceOrFail(dataresource);\n res.fill({ data: dataresource });\n new_ids[dataresource.id] = dataresource.id;\n (<Array<R>>this.data).push(<R>res);\n if (Object.keys(res.attributes).length > 0) {\n this.builded = true;\n }\n } catch (error) {\n this.content = 'ids';\n this.builded = false;\n this.data.push({ id: dataresource.id, type: dataresource.type });\n }\n }\n\n // remove old members of collection (bug, for example, when request something like orders/10/details and has new ids)\n // @todo test with relation.data.filter(resource => resource.id != id );\n for (let i; i < this.data.length; i++) {\n if (!(this.data[i].id in new_ids)) {\n delete this.data[i];\n }\n }\n\n this.meta = data_collection.meta || {};\n\n if ('cache_last_update' in data_collection) {\n this.cache_last_update = data_collection.cache_last_update;\n }\n }\n\n private getResourceOrFail(dataresource: IDataResource): Resource {\n let res = this.find(dataresource.id);\n\n if (res !== null) {\n return res;\n }\n\n let service = Converter.getService(dataresource.type);\n\n // remove when getService return null or catch errors\n // this prvent a fill on undefinied service :/\n if (!service) {\n if (isDevMode()) {\n console.warn(\n 'The relationship ' +\n 'relation_alias?' +\n ' (type ' +\n dataresource.type +\n ') cant be generated because service for this type has not been injected.'\n );\n }\n\n throw new Error('Cant create service for ' + dataresource.type);\n }\n // END remove when getService return null or catch errors\n\n return service.getOrCreateResource(dataresource.id);\n }\n\n public replaceOrAdd(resource: R): void {\n let res = this.find(resource.id);\n if (res === null) {\n (<Array<R>>this.data).push(resource);\n } else {\n res = resource;\n }\n }\n\n public hasMorePages(): boolean | null {\n if (!this.page.size || this.page.size < 1) {\n return null;\n }\n\n let total_resources = this.page.size * (this.page.number - 1) + this.data.length;\n\n return total_resources < this.page.total_resources;\n }\n\n public setLoaded(value: boolean): void {\n // tslint:disable-next-line:deprecation\n this.is_loading = !value;\n this.loaded = value;\n }\n\n public setLoadedAndPropagate(value: boolean): void {\n this.setLoaded(value);\n\n if (this.content === 'ids') {\n return;\n }\n (<Array<R>>this.data).forEach(resource => {\n CacheableHelper.propagateLoaded(resource.relationships, value);\n });\n }\n\n public setBuilded(value: boolean): void {\n this.builded = value;\n }\n\n public setBuildedAndPropagate(value: boolean): void {\n this.setBuilded(value);\n if (this.content === 'ids') {\n return;\n }\n (<Array<R>>this.data).forEach(resource => {\n resource.setLoaded(value);\n });\n }\n\n public setSource(value: SourceType): void {\n this.source = value;\n }\n\n public setSourceAndPropagate(value: SourceType): void {\n this.setSource(value);\n this.data.forEach(resource => {\n if (resource instanceof Resource) {\n resource.setSource(value);\n }\n });\n }\n\n public setCacheLastUpdate(value = Date.now()) {\n this.cache_last_update = value;\n }\n\n public setCacheLastUpdateAndPropagate(value = Date.now()) {\n this.setCacheLastUpdate(value);\n this.data.forEach(resource => {\n if (resource instanceof Resource) {\n resource.setCacheLastUpdate(value);\n }\n });\n }\n\n public toObject(params?: IParamsCollection): IDataCollection {\n if (!this.builded) {\n return { data: this.data };\n }\n\n let data = (<Array<R>>this.data).map(resource => {\n return resource.toObject(params).data;\n });\n\n return {\n data: data\n };\n }\n}\nexport class DocumentCollection<R extends Resource = Resource> extends RelatedDocumentCollection<R> {\n public data: Array<R> = [];\n public content: 'collection' = 'collection';\n}\n"]}