Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : ORIX App Universe8 * File : src/lib/releases/store.ts9 * Module : lib10 * 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 { db } from "../database/db";44import { compareVersions } from "./version";45import { getApp } from "../catalog";4647export type ReleaseState = "note" | "discovered" | "validated" | "invalid" | "held" | "published" | "withdrawn";48export type Release = {49 id: number; slug: string; source: "spbgit" | "manual"; repo: string | null; tag: string; version: string | null; prerelease: number;50 tag_date: string | null; subject: string | null; asset_name: string; asset_size: number | null;51 sha256_declared: string | null; sha256_computed: string | null; source_url: string | null;52 state: ReleaseState; reason: string | null; signature: string | null; artifact: string | null; notes: string | null;53 discovered_at: string; checked_at: string | null; approved_at: string | null; approved_by: string | null; published_at: string | null;54};55export type Signature = { platform: string; notarized: boolean | null; stapler?: string; gatekeeper?: string; codesign?: string; teamId?: string | null };5657const all = (sql: string, ...p: (string | number | null)[]) => db().prepare(sql).all(...p) as unknown as Release[];5859export const releasesFor = (slug: string) => all("SELECT * FROM releases WHERE slug = ? ORDER BY coalesce(tag_date, discovered_at) DESC", slug);60export const allReleases = () => all("SELECT * FROM releases ORDER BY coalesce(tag_date, discovered_at) DESC");61export const releaseById = (id: number) => all("SELECT * FROM releases WHERE id = ?", id)[0] ?? null;6263/** Published downloadable artifacts of an application, newest version first. */64export function publishedArtifacts(slug: string): Release[] {65 return all("SELECT * FROM releases WHERE slug = ? AND state = 'published' AND artifact IS NOT NULL", slug)66 .sort((a, b) => compareVersions(b.version ?? b.tag, a.version ?? a.tag));67}6869/** What a release is called on a page: a pre-release keeps its full tag ("1.0.0-beta.1"), a stable one its version. */70export const versionLabel = (r: Pick<Release, "version" | "tag" | "prerelease">): string => (r.prerelease ? r.tag.replace(/^(?:mac-)?v/, "") : r.version ?? r.tag);7172/**73 * The download offered by default: the highest published *stable* version. Withdrawing it rolls back to the previous one.74 * One exception, decided by the owner in the application's own page (2026-11-25): when the `version` written there names a75 * published pre-release that is newer than every stable version, that pre-release is the default. Any other pre-release76 * stays listed under the other versions and is never offered by default.77 */78export function latestArtifact(slug: string): Release | null {79 const all = publishedArtifacts(slug), stable = all.find((r) => !r.prerelease) ?? null, newest = all[0] ?? null;80 if (newest && newest.prerelease && (!stable || compareVersions(newest.version ?? newest.tag, stable.version ?? stable.tag) > 0)) {81 const declared = getApp(slug)?.app.version ?? null;82 if (declared && declared === versionLabel(newest)) return newest;83 }84 return stable;85}8687export const signatureOf = (r: Release): Signature | null => { try { return r.signature ? (JSON.parse(r.signature) as Signature) : null; } catch { return null; } };88