<Repository> Clase base para los repositorios de front. Usa useRequestFetch, así que en SSR reenvía la cookie de sesión a nuestra propia API (sin ella, recargar una página daría 401).
Convención de nombres: retrieve (GET lista), find (GET por id), search (GET con params), create, update, updatePartial y destroy.
// app/pages/(modules)/projects/repositories/projects.repository.ts
import { Repository } from "#layers/core/app/utils/repository";
class ProjectsRepository extends Repository {
retrieve() {
return this.httpGet<Project[]>("/api/v0/projects");
}
create(data: NewProject) {
return this.httpPost<Project>("/api/v0/projects", data);
}
destroy(id: number) {
return this.httpDelete(`/api/v0/projects/${id}`);
}
}
export const projectsRepository = new ProjectsRepository();| Prop / slot / evento | Tipo | Por defecto | Descripción |
|---|---|---|---|
| httpGet<T>(url) | Promise<T> | — | GET. |
| httpPost<T>(url, body) | Promise<T> | — | POST con JSON. |
| httpPostForm<T>(url, formData) | Promise<T> | — | POST multipart (subida de ficheros). |
| httpPut<T> / httpPatch<T>(url, body) | Promise<T> | — | PUT / PATCH con JSON. |
| httpDelete<T>(url, body?) | Promise<T> | — | DELETE, con body opcional. |
<appColors · getContrastAppColor> Colores de la app con su color de texto de contraste.
const bg = appColors.cobalt; // "#596CF2"
const text = getContrastAppColor(bg); // "#060E47" <formatDate · formatDuracion · formatNumber · formatTimeDiff> formatDuracion(135) → 2h 15m · formatDate(hoy) → 30 nov 2026 · formatNumber(1234567) → 1.2M · formatTimeDiff(45, t) → hace 1 mes
formatDate("2026-11-26T10:00:00Z") // "26 nov 2026"
formatDuracion(135) // "2h 15m"
formatNumber(1234567) // "1.2M"
formatTimeDiff(45, t) // "1 month ago" (t de useI18n()) <utils/file> Tipos de fichero, extensiones, tamaños legibles y conversiones (URL o base64 ↔ File).
readableFileSize(5242880) → 5 MB
readableFileSize(5242880) // "5 MB"
getFileTypeFromFile(file) // "image" | "video" | "pdf" | …
const file = await urlToImageFile(url)| Prop / slot / evento | Tipo | Por defecto | Descripción |
|---|---|---|---|
| getFileTypeFromFile / getFileTypeFromMimeType / getFileTypeFromUrl | FileMediaType | undefined | — | video, image, gif, pdf, doc o presentation. |
| getSupportedMimeTypes | string[] | — | MIME soportados por tipo. |
| getFileNameExtension / getFileNameWithoutExtension / getFileFormat | string | undefined | — | Partes del nombre y formato. |
| isImageFileFormatSupported / isVideoFileFormatSupported(InBrowser) | boolean | — | Validación de formatos. |
| readableFileSize | string | — | Bytes → B/KB/MB/GB/TB. |
| urlToImageFile / base64ToFile | Promise<File> | — | Construye un File. |
| imageFileToBase64 / imageUrlToBase64 | Promise<string> | — | File o URL → base64. |
| getHash(buffer, algorithm?) | Promise<string> | — | Hash (SHA-256 por defecto). |
<getUrlParamValue · isDebugModeParam · isDebugMode · useDevMode> useDevMode().isDev → falseisDebugModeParam() → false (añade ?isDebugMode=true) isDebugMode() → false (siempre true en desarrollo; en producción, con ?isDebugMode=true, que el middleware debug-mode.global mantiene al navegar) const { isDev, isProd } = useDevMode(); // false
getUrlParamValue("tab"); // también en SSR (useRequestURL)
isDebugModeParam(); // ?isDebugMode=true
isDebugMode(); // desarrollo o ?isDebugMode=true (se mantiene al navegar)