Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : ORIX App Universe8 * File : src/models/filter.ts9 * Module : models10 * Repository : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website : https://www.orixlab.dev12 * Created : 2026-11-2113 * Last Modified : 2026-11-2114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import type { Category, Platform, Status } from "./constants";4445/** The slim, serializable view of an application used by cards, the universe and the client-side catalog. */46export type CardApp = {47 slug: string; name: string; tagline: string; summary: string; category: Category; platforms: Platform[]; status: Status;48 /** Per-platform status where it differs from `status`. */49 platformStatus: Partial<Record<Platform, Status>>;50 version: string | null; icon: string | null; accent: string | null; order: number; updatedAt: string; featured: boolean;51 keywords: string;52 /** What the primary button does; a download or TestFlight action exists only for a verified destination. */53 action: { kind: "download" | "appstore" | "testflight" | "details"; href: string };54};5556export type PlatformFilter = Platform | "universal";57export type SortKey = "featured" | "name" | "updated" | "status";58export type CatalogQuery = { q?: string; platform?: PlatformFilter | ""; category?: Category | ""; status?: Status | ""; sort?: SortKey };5960/** Status of an application on one platform. */61export const statusOn = (a: Pick<CardApp, "status" | "platformStatus">, p: Platform): Status => a.platformStatus?.[p] ?? a.status;6263export const STATUS_RANK: Record<Status, number> = { available: 0, beta: 1, development: 2, "coming-soon": 3, unavailable: 4 };64const fold = (s: string) => s.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();6566/** "Universal" = one application that runs on more than one device family. */67export const isUniversal = (a: Pick<CardApp, "platforms">) => a.platforms.length > 1;6869export function filterApps<T extends CardApp>(apps: T[], query: CatalogQuery): T[] {70 const words = fold(query.q?.trim() ?? "").split(/\s+/).filter(Boolean);71 const out = apps.filter((app) => {72 if (query.platform && (query.platform === "universal" ? !isUniversal(app) : !app.platforms.includes(query.platform))) return false;73 if (query.category && app.category !== query.category) return false;74 if (query.status && app.status !== query.status) return false;75 if (!words.length) return true;76 const hay = fold(`${app.name} ${app.tagline} ${app.summary} ${app.category} ${app.keywords}`);77 return words.every((w) => hay.includes(w));78 });79 const by = query.sort ?? "featured";80 return out.sort((a, b) =>81 by === "name" ? a.name.localeCompare(b.name)82 : by === "updated" ? b.updatedAt.localeCompare(a.updatedAt) || a.order - b.order83 : by === "status" ? STATUS_RANK[a.status] - STATUS_RANK[b.status] || a.order - b.order84 : Number(b.featured) - Number(a.featured) || a.order - b.order);85}86