UNPKG

angular-t9n

Version:

A translation tool for Angular i18n

2 lines (1 loc) 1.33 kB
import{a as _}from"./chunk-SWXDJEZV.js";import{a as d}from"./chunk-IZB6ZOII.js";import{F as p,G as m,Lc as f,U as a,_ as l,da as h,m as o,q as s,w as c}from"./chunk-XN5ZPBP6.js";var M=(()=>{class n{constructor(r,t){this._translationService=r,this._http=t}orphan(r){return this._translationService.root.pipe(p(1),s(t=>t._links.orphan.href.replace("{id}",r)),a(t=>this._http.get(t)))}orphans(r){let t=_(r);return this._translationService.root.pipe(p(1),s(e=>e._links.orphans.href),a(e=>this._http.get(e,{params:t})))}deleteOrphan(r){return this._http.delete(r._links.self.href)}migrateOrphan(r,t){return this._http.request("DELETE",r._links.self.href,{body:t})}autoMigrateOrphans(r){return this._fetchOrphans().pipe(a(t=>{let e=t.filter(i=>this._canMigrate(i,r)).map(i=>this.migrateOrphan(i,i._embedded.similar[0]).pipe(m(i)));return e.length?c(e):o([])}))}_fetchOrphans(r=0){return this.orphans({page:r,entriesPerPage:250}).pipe(a(t=>t._links.next?this._fetchOrphans(++r).pipe(s(e=>t._embedded.entries.concat(e))):o(t._embedded.entries)))}_canMigrate(r,t){let e=r._embedded?.similar;return e&&e[0].distance<=t&&e.filter(i=>i.distance===e[0].distance).length===1}static{this.\u0275fac=function(t){return new(t||n)(h(d),h(f))}}static{this.\u0275prov=l({token:n,factory:n.\u0275fac,providedIn:"root"})}}return n})();export{M as a};