---
title: "Retrievers"
description: "Referencia completa de AbstractBaseRetriever, AbstractXmlRetriever, XsdRetriever y XsltRetriever."
canonical_url: "https://nodecfdi.com/packages/xml-resource-retriever/api-reference/retrievers"
---

> Index of every page on this site: [llms.txt](https://nodecfdi.com/llms.txt)

Todas las clases de retrievers se exportan como exportaciones nombradas desde `@nodecfdi/xml-resource-retriever`.

```ts
import {
  AbstractBaseRetriever,
  AbstractXmlRetriever,
  XsdRetriever,
  XsltRetriever,
} from '@nodecfdi/xml-resource-retriever';
```

## `AbstractBaseRetriever`

Clase base abstracta que implementa `RetrieverInterface`.

### Constructor

```ts
declare abstract class AbstractBaseRetriever {
  protected constructor(basePath: string, downloader?: DownloaderInterface);
}
```

Si no se proporciona `downloader`, utiliza `new NodeDownloader()`.

### Métodos públicos

<table>
<thead>
  <tr>
    <th>
      Método
    </th>
    
    <th>
      Firma
    </th>
    
    <th>
      Descripción
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        getBasePath
      </code>
    </td>
    
    <td>
      <code>
        () => string
      </code>
    </td>
    
    <td>
      Devuelve la ruta base configurada en el constructor.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        getDownloader
      </code>
    </td>
    
    <td>
      <code>
        () => DownloaderInterface
      </code>
    </td>
    
    <td>
      Devuelve la instancia actual del descargador.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        setDownloader
      </code>
    </td>
    
    <td>
      <code>
        (downloader: DownloaderInterface) => void
      </code>
    </td>
    
    <td>
      Reemplaza el descargador utilizado por el retriever.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        buildPath
      </code>
    </td>
    
    <td>
      <code>
        (url: string) => string
      </code>
    </td>
    
    <td>
      Calcula la ruta local segura donde se guardará <code>
        url
      </code>
      
       usando <code>
        resolveLocalFilePath
      </code>
      
      . Lanza <code>
        Error
      </code>
      
       si la URL es inválida o intenta salir de <code>
        basePath
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        download
      </code>
    </td>
    
    <td>
      <code>
        (url: string) => Promise<string>
      </code>
    </td>
    
    <td>
      Descarga <code>
        url
      </code>
      
       sin sus dependencias, crea los directorios necesarios, ejecuta <code>
        checkIsValidDownloadedFile
      </code>
      
       y devuelve la ruta local.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        retrieve
      </code>
    </td>
    
    <td>
      <code>
        (url: string) => Promise<string>
      </code>
    </td>
    
    <td>
      Método abstracto para descargar un recurso y sus dependencias.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        retrieveHistory
      </code>
    </td>
    
    <td>
      <code>
        () => Record<string, string>
      </code>
    </td>
    
    <td>
      Devuelve una copia plana (<code>
        Object.fromEntries
      </code>
      
      ) del historial de la última operación <code>
        retrieve()
      </code>
      
       (<code>
        { [url]: localPath }
      </code>
      
      ).
    </td>
  </tr>
</tbody>
</table>

### Métodos protegidos

<table>
<thead>
  <tr>
    <th>
      Método
    </th>
    
    <th>
      Firma
    </th>
    
    <th>
      Descripción
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        clearHistory
      </code>
    </td>
    
    <td>
      <code>
        () => void
      </code>
    </td>
    
    <td>
      Vacía el mapa interno de historial.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        addToHistory
      </code>
    </td>
    
    <td>
      <code>
        (source: string, localPath: string) => void
      </code>
    </td>
    
    <td>
      Registra una URL y su ruta local en el historial.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hasInHistory
      </code>
    </td>
    
    <td>
      <code>
        (source: string) => boolean
      </code>
    </td>
    
    <td>
      Indica si una URL ya fue registrada en el historial.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        getFromHistory
      </code>
    </td>
    
    <td>
      <code>
        (source: string) => string | undefined
      </code>
    </td>
    
    <td>
      Obtiene la ruta local registrada para <code>
        source
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        historySize
      </code>
    </td>
    
    <td>
      <code>
        () => number
      </code>
    </td>
    
    <td>
      Devuelve la cantidad de recursos registrados en el historial.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        urlParts
      </code>
    </td>
    
    <td>
      <code>
        (url: string) => UrlParts | undefined
      </code>
    </td>
    
    <td>
      Analiza una URL HTTP/HTTPS delegando en <code>
        parseHttpUrlParts
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        checkIsValidDownloadedFile
      </code>
    </td>
    
    <td>
      <code>
        (source: string, localPath: string) => Promise<void>
      </code>
    </td>
    
    <td>
      Método abstracto ejecutado tras descargar un archivo en <code>
        download()
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

---

## `AbstractXmlRetriever`

Extiende `AbstractBaseRetriever` e implementa la descarga recursiva y concurrente de documentos XML con reescritura de rutas relativas.

### Constructor

```ts
declare abstract class AbstractXmlRetriever extends AbstractBaseRetriever {
  public constructor(basePath: string, downloader?: DownloaderInterface);
}
```

### Métodos públicos

- `retrieve(url: string): Promise<string>`: limpia el historial y descarga `url` junto con todos los recursos enlazados de forma recursiva, reescribiendo los atributos coincidentes a rutas relativas.

### Métodos protegidos

<table>
<thead>
  <tr>
    <th>
      Método
    </th>
    
    <th>
      Firma
    </th>
    
    <th>
      Valor por defecto / Comportamiento
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        checkIsValidDownloadedFile
      </code>
    </td>
    
    <td>
      <code>
        (source: string, localPath: string) => Promise<void>
      </code>
    </td>
    
    <td>
      Llama a <code>
        validateDownloadedXmlFile(source, localPath)
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        maxDepth
      </code>
    </td>
    
    <td>
      <code>
        () => number
      </code>
    </td>
    
    <td>
      <code>
        50
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        maxResources
      </code>
    </td>
    
    <td>
      <code>
        () => number
      </code>
    </td>
    
    <td>
      <code>
        500
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        maxConcurrentDownloads
      </code>
    </td>
    
    <td>
      <code>
        () => number
      </code>
    </td>
    
    <td>
      <code>
        6
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        searchNamespace
      </code>
    </td>
    
    <td>
      <code>
        () => string
      </code>
    </td>
    
    <td>
      Abstracto. Namespace XML donde se buscan los elementos enlazados.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        searchElements
      </code>
    </td>
    
    <td>
      <code>
        () => (SearchElement | Record<string, string>)[]
      </code>
    </td>
    
    <td>
      Abstracto. Lista de pares <code>
        { element, attribute }
      </code>
      
       a inspeccionar y reescribir.
    </td>
  </tr>
</tbody>
</table>

---

## `XsdRetriever`

Extiende `AbstractXmlRetriever` para esquemas XML (XSD).

- **searchNamespace()**: `'http://www.w3.org/2001/XMLSchema'`
- **searchElements()**:

  - `{ element: 'import', attribute: 'schemaLocation' }`
  - `{ element: 'include', attribute: 'schemaLocation' }`

---

## `XsltRetriever`

Extiende `AbstractXmlRetriever` para hojas de transformación XSLT.

- **searchNamespace()**: `'http://www.w3.org/1999/XSL/Transform'`
- **searchElements()**:

  - `{ element: 'import', attribute: 'href' }`
  - `{ element: 'include', attribute: 'href' }`

## Sitemap

See the full [sitemap](https://nodecfdi.com/sitemap.md) for all pages.
