-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.js.map
1 lines (1 loc) · 22.9 KB
/
resource.js.map
1
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAc,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAI7F,MAAM;;kBACkB,EAAE;oBACA,EAAE;0BACS,EAAE;6BACI,EAAE;qBAClB,EAAE;sBAGT,IAAI;yBACD,KAAK;0BACJ,KAAK;sBACT,IAAI;sBACQ,KAAK;iCACN,CAAC;mBACf,CAAC;;;;;IAGP,KAAK;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;gBACnB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,kBAA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K,CAAC,CAAC;aACjC;SACJ;;;;;;IAGE,kBAAkB,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE;QACxC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;;CAEtC","sourcesContent":["import { CacheMemory } from './services/cachememory';\nimport { IDataResource } from './interfaces/data-resource';\nimport { JsonRipper } from './services/json-ripper';\nimport { CacheableHelper } from './services/cacheable-helper.';\nimport { Core } from './core';\nimport { IResourcesByType } from './interfaces/resources-by-type';\nimport { Service } from './service';\nimport { Base } from './services/base';\nimport { PathBuilder } from './services/path-builder';\nimport { Converter } from './services/converter';\nimport { IDocumentResource, ICacheableDocumentResource } from './interfaces/data-object';\nimport { IAttributes, IParamsResource, ILinks } from './interfaces';\nimport { DocumentCollection } from './document-collection';\nimport { DocumentResource } from './document-resource';\nimport { ICacheable } from './interfaces/cacheable';\nimport { isArray } from 'util';\nimport { Observable, Subject, of } from 'rxjs';\nimport { ResourceRelationshipsConverter } from './services/resource-relationships-converter';\nimport { IRelationships } from './interfaces/relationship';\nimport { SourceType } from './document';\n\nexport class Resource implements ICacheable {\n public id: string = '';\n public type: string = '';\n public attributes: IAttributes = {};\n public relationships: IRelationships = {};\n public links: ILinks = {};\n public meta: { [key: string]: any };\n\n public is_new = true;\n public is_saving = false;\n public is_loading = false;\n public loaded = true;\n public source: SourceType = 'new';\n public cache_last_update = 0;\n public ttl = 0;\n public data_resource: any;\n\n public reset(): void {\n this.id = '';\n this.attributes = {};\n this.is_new = true;\n\n for (const key in this.relationships) {\n this.relationships[key] =\n this.relationships[key] instanceof DocumentCollection ? new DocumentCollection() : new DocumentResource();\n }\n }\n\n public toObject(params?: IParamsResource): IDocumentResource {\n params = { ...{}, ...Base.ParamsResource, ...params };\n\n let relationships = {};\n let included: Array<IDataResource> = [];\n let included_ids: Array<string> = []; // just for control don't repeat any resource\n let included_relationships: Array<string> = params.include || [];\n if (params.include_save) {\n included_relationships = included_relationships.concat(params.include_save);\n }\n\n // REALTIONSHIPS\n for (const relation_alias in this.relationships) {\n let relationship = this.relationships[relation_alias];\n if (relationship instanceof DocumentCollection) {\n // @TODO PABLO: definir cuál va a ser la propiedd indispensable para guardar la relación\n if (!relationship.builded && (!relationship.data || relationship.data.length === 0)) {\n delete relationships[relation_alias];\n } else {\n relationships[relation_alias] = { data: [] };\n }\n\n for (const resource of relationship.data) {\n let reational_object = {\n id: resource.id,\n type: resource.type\n };\n relationships[relation_alias].data.push(reational_object);\n\n // no se agregó aún a included && se ha pedido incluir con el parms.include\n let temporal_id = resource.type + '_' + resource.id;\n if (\n included_ids.indexOf(temporal_id) === -1 &&\n included_relationships &&\n included_relationships.indexOf(relation_alias) !== -1\n ) {\n included_ids.push(temporal_id);\n included.push(resource.toObject({}).data);\n }\n }\n } else {\n // @TODO PABLO: agregué el check de null porque sino fallan las demás condiciones, además es para eliminar la relacxión del back\n if (relationship.data === null || relationship.data === undefined) {\n relationships[relation_alias] = { data: relationship.data };\n continue;\n }\n if (!(relationship instanceof DocumentResource)) {\n console.warn(relationship, ' is not DocumentCollection or DocumentResource');\n }\n\n let relationship_data = <Resource>relationship.data;\n if (relationship.data && !('id' in relationship.data) && Object.keys(relationship.data).length > 0) {\n console.warn(relation_alias + ' defined with hasMany:false, but I have a collection');\n }\n\n if (relationship_data.id && relationship_data.type) {\n relationships[relation_alias] = {\n data: {\n id: relationship_data.id,\n type: relationship_data.type\n }\n };\n // @TODO PABLO: definir cuál va a ser la propiedd indispensable para guardar la relación\n // @WARNING: no borrar la verificación de que no sea null... sino no se van a poder borrar\n } else if (!relationship.builded && !relationship_data.id && !relationship_data.type) {\n delete relationships[relation_alias];\n\n continue;\n }\n\n // no se agregó aún a included && se ha pedido incluir con el parms.include\n let temporal_id = relationship_data.type + '_' + relationship_data.id;\n if (\n included_ids.indexOf(temporal_id) === -1 &&\n included_relationships &&\n included_relationships.indexOf(relation_alias) !== -1\n ) {\n included_ids.push(temporal_id);\n included.push(relationship_data.toObject({}).data);\n }\n }\n }\n\n // just for performance dont copy if not necessary\n let attributes;\n if (this.getService() && this.getService().parseToServer) {\n attributes = { ...{}, ...this.attributes };\n this.getService().parseToServer(attributes);\n } else {\n attributes = this.attributes;\n }\n\n let ret: IDocumentResource = {\n data: {\n type: this.type,\n id: this.id,\n attributes: attributes,\n relationships: relationships\n }\n };\n\n // resource's meta\n if (this.meta) {\n ret.data.meta = this.meta;\n }\n\n // top level meta\n if (params.meta) {\n ret.meta = params.meta;\n }\n\n if (included.length > 0) {\n ret.included = included;\n }\n\n return ret;\n }\n\n public fill(data_object: IDocumentResource | ICacheableDocumentResource): boolean {\n this.id = data_object.data.id || '';\n\n // WARNING: leaving previous line for a tiem because this can produce undesired behavior\n // this.attributes = data_object.data.attributes || this.attributes;\n this.attributes = { ...(this.attributes || {}), ...data_object.data.attributes };\n this.data_resource = data_object;\n\n this.is_new = false;\n\n // NOTE: fix if stored resource has no relationships property\n let service = Converter.getService(data_object.data.type);\n\n if (!this.relationships && service) {\n this.relationships = new service.resource().relationships;\n }\n\n // wee need a registered service\n if (!service) {\n return false;\n }\n\n // only ids?\n if (Object.keys(this.attributes).length) {\n // @todo remove this when getResourceService ToDo is fixed\n let srvc = Converter.getService(this.type);\n if (srvc && 'parseFromServer' in srvc) {\n srvc.parseFromServer(this.attributes);\n }\n }\n\n if ('cache_last_update' in data_object.data) {\n this.cache_last_update = data_object.data.cache_last_update;\n }\n\n new ResourceRelationshipsConverter(\n Converter.getService,\n data_object.data.relationships || {},\n this.relationships,\n Converter.buildIncluded(data_object)\n ).buildRelationships();\n\n return true;\n }\n\n public addRelationship<T extends Resource>(resource: T, type_alias?: string) {\n let relation = this.relationships[type_alias || resource.type];\n if (relation instanceof DocumentCollection) {\n relation.replaceOrAdd(resource);\n } else {\n relation.data = resource;\n }\n }\n\n public addRelationships<R extends Resource>(resources: Array<R>, type_alias: string): void {\n if (resources.length === 0) {\n return;\n }\n\n let relation = this.relationships[type_alias];\n if (!(relation instanceof DocumentCollection)) {\n throw new Error('addRelationships require a DocumentCollection (hasMany) relation.');\n }\n\n resources.forEach((resource: Resource) => {\n this.addRelationship(resource, type_alias);\n });\n }\n\n public removeRelationship(type_alias: string, id: string): boolean {\n if (!(type_alias in this.relationships)) {\n return false;\n }\n if (!('data' in this.relationships[type_alias])) {\n return false;\n }\n\n let relation = this.relationships[type_alias];\n if (relation instanceof DocumentCollection) {\n relation.data = relation.data.filter(resource => resource.id !== id);\n if (relation.data.length === 0) {\n // used by toObject() when hasMany is empty\n relation.builded = true;\n }\n } else {\n relation.data = null;\n }\n\n return true;\n }\n\n public hasManyRelated(resource: string): boolean {\n return this.relationships[resource] && (<Array<Resource>>this.relationships[resource].data).length > 0;\n }\n\n public hasOneRelated(resource: string): boolean {\n return Boolean(\n this.relationships[resource] &&\n (<Resource>this.relationships[resource].data).type &&\n (<Resource>this.relationships[resource].data).type !== ''\n );\n }\n\n public restore<T extends Resource>(params: IParamsResource = {}): Observable<object> {\n params.meta = { ...params.meta, ...{ restore: true } };\n\n return this.save(params);\n }\n\n /*\n @return This resource like a service\n */\n public getService(): Service {\n return Converter.getServiceOrFail(this.type);\n }\n\n public delete(): Observable<void> {\n return this.getService().delete(this.id);\n }\n\n public save<T extends Resource>(params?: IParamsResource): Observable<object> {\n params = { ...Base.ParamsResource, ...params };\n if (this.is_saving || !this.loaded) {\n return of({});\n }\n this.is_saving = true;\n\n let subject = new Subject<object>();\n let object = this.toObject(params);\n if (this.id === '') {\n delete object.data.id;\n }\n\n // http request\n let path = new PathBuilder();\n path.applyParams(this.getService(), params);\n if (this.id) {\n path.appendPath(this.id);\n }\n\n Core.exec(path.get(), this.is_new ? 'POST' : 'PATCH', object, true).subscribe(\n success => {\n this.is_saving = false;\n\n // force reload collections cache (example: we add a new element)\n if (!this.id) {\n CacheMemory.getInstance().deprecateCollections(path.get());\n let jsonripper = new JsonRipper();\n jsonripper.deprecateCollection(path.get());\n }\n\n // is a resource?\n if ('id' in success.data) {\n this.id = success.data.id;\n this.fill(<IDocumentResource>success);\n } else if (isArray(success.data)) {\n console.warn('Server return a collection when we save()', success.data);\n }\n\n subject.next(success);\n subject.complete();\n },\n error => {\n this.is_saving = false;\n subject.error('data' in error ? error.data : error);\n }\n );\n\n return subject.asObservable();\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 CacheableHelper.propagateLoaded(this.relationships, value);\n }\n\n /** @todo generate interface */\n public setSource(value: SourceType): void {\n this.source = value;\n }\n\n public setSourceAndPropagate(value: SourceType): void {\n this.setSource(value);\n for (let relationship_alias in this.relationships) {\n let relationship = this.relationships[relationship_alias];\n if (relationship instanceof DocumentCollection) {\n relationship.setSource(value);\n }\n }\n }\n\n public setCacheLastUpdate(value = Date.now()) {\n this.cache_last_update = value;\n }\n}\n"]}