<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.

Ver código
// 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 / eventoTipoPor defectoDescripció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.

blue#8996F6
teal#91CAA2
pink#FBB2EA
yellow#e6a735
purple#BC8BB1
cyan#B8C0F9
red#FC7855
green#50A76A
slate#96A3AC
charcoal#639CAB
lightYellow#eed5a6
darkYellow#c09443
cobalt#596CF2
Ver código
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

Ver código
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

Ver código
readableFileSize(5242880)           // "5 MB"
getFileTypeFromFile(file)           // "image" | "video" | "pdf" | …
const file = await urlToImageFile(url)
Prop / slot / eventoTipoPor defectoDescripción
getFileTypeFromFile / getFileTypeFromMimeType / getFileTypeFromUrlFileMediaType | undefined—video, image, gif, pdf, doc o presentation.
getSupportedMimeTypesstring[]—MIME soportados por tipo.
getFileNameExtension / getFileNameWithoutExtension / getFileFormatstring | undefined—Partes del nombre y formato.
isImageFileFormatSupported / isVideoFileFormatSupported(InBrowser)boolean—Validación de formatos.
readableFileSizestring—Bytes → B/KB/MB/GB/TB.
urlToImageFile / base64ToFilePromise<File>—Construye un File.
imageFileToBase64 / imageUrlToBase64Promise<string>—File o URL → base64.
getHash(buffer, algorithm?)Promise<string>—Hash (SHA-256 por defecto).

<getUrlParamValue · isDebugModeParam · isDebugMode · useDevMode>
  • useDevMode().isDev → false
  • isDebugModeParam() → 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)
Ver código
const { isDev, isProd } = useDevMode();   // false
getUrlParamValue("tab");                  // también en SSR (useRequestURL)
isDebugModeParam();                       // ?isDebugMode=true
isDebugMode();                            // desarrollo o ?isDebugMode=true (se mantiene al navegar)
Copyright © 2026 vicci · base