angular-t9n
Version:
A translation tool for Angular i18n
2 lines (1 loc) • 1.31 kB
JavaScript
import{a as u}from"./chunk-FK6IRHWX.js";import{a as _}from"./chunk-4NKRI2IB.js";import{F as p,G as l,U as a,_ as f,da as c,m as h,q as s,w as m,yc as d}from"./chunk-IRWV2DJQ.js";var y=(()=>{let i=class i{constructor(){this._translationService=c(_),this._http=c(d)}orphan(e){return this._translationService.root.pipe(p(1),s(t=>t._links.orphan.href.replace("{id}",e)),a(t=>this._http.get(t)))}orphans(e){let t=u(e);return this._translationService.root.pipe(p(1),s(r=>r._links.orphans.href),a(r=>this._http.get(r,{params:t})))}deleteOrphan(e){return this._http.delete(e._links.self.href)}migrateOrphan(e,t){return this._http.request("DELETE",e._links.self.href,{body:t})}autoMigrateOrphans(e){return this._fetchOrphans().pipe(a(t=>{let r=t.filter(n=>this._canMigrate(n,e)).map(n=>this.migrateOrphan(n,n._embedded.similar[0]).pipe(l(n)));return r.length?m(r):h([])}))}_fetchOrphans(e=0){return this.orphans({page:e,entriesPerPage:250}).pipe(a(t=>t._links.next?this._fetchOrphans(++e).pipe(s(r=>t._embedded.entries.concat(r))):h(t._embedded.entries)))}_canMigrate(e,t){let r=e._embedded?.similar;return r&&r[0].distance<=t&&r.filter(n=>n.distance===r[0].distance).length===1}};i.\u0275fac=function(t){return new(t||i)},i.\u0275prov=f({token:i,factory:i.\u0275fac,providedIn:"root"});let o=i;return o})();export{y as a};