SPB Git

Repository Public MIT

RegistryModels.swift 7.1 KB 164 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Sources/SPGlassRegistry/RegistryModels.swift8// Module           : SPGlassRegistry9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation4243public enum RegistrySchema {44    /// Version of the registry, manifest, configuration and lock file formats.45    public static let version = 146    public static let indexFileName = "registry.json"47    public static let signatureFileName = "registry.json.sig"48}4950/// `registry.json`: every item and theme with its published versions.51public struct RegistryIndex: Codable, Equatable, Sendable {52    public var schemaVersion: Int53    public var name: String54    public var homepage: String55    public var license: String56    public var items: [RegistryIndexEntry]57    public var themes: [RegistryIndexEntry]5859    public init(schemaVersion: Int = RegistrySchema.version, name: String, homepage: String, license: String, items: [RegistryIndexEntry], themes: [RegistryIndexEntry]) {60        self.schemaVersion = schemaVersion; self.name = name; self.homepage = homepage; self.license = license61        self.items = items; self.themes = themes62    }6364    public func item(_ id: String) -> RegistryIndexEntry? { items.first { $0.id == id } }65    public func theme(_ id: String) -> RegistryIndexEntry? { themes.first { $0.id == id } }66}6768public struct RegistryIndexEntry: Codable, Equatable, Sendable, Identifiable {69    public var id: String70    public var name: String71    public var kind: String72    public var category: String?73    public var summary: String74    public var latest: String75    public var versions: [RegistryIndexVersion]7677    public init(id: String, name: String, kind: String, category: String?, summary: String, latest: String, versions: [RegistryIndexVersion]) {78        self.id = id; self.name = name; self.kind = kind; self.category = category; self.summary = summary79        self.latest = latest; self.versions = versions80    }8182    public func version(_ version: String) -> RegistryIndexVersion? { versions.first { $0.version == version } }83}8485/// One immutable published version: where its manifest (or theme file) is and what its checksum must be.86public struct RegistryIndexVersion: Codable, Equatable, Sendable {87    public var version: String88    /// Path of the manifest (items) or theme file (themes), relative to the registry root.89    public var path: String90    public var sha256: String9192    public init(version: String, path: String, sha256: String) {93        self.version = version; self.path = path; self.sha256 = sha25694    }95}9697/// `components/<id>/<version>/manifest.json`.98public struct ComponentManifest: Codable, Equatable, Sendable, Identifiable {99    public var schemaVersion: Int100    public var id: String101    public var name: String102    public var version: String103    public var description: String104    public var kind: String105    public var category: String?106    public var platforms: [String]107    public var minimumOS: [String: String]108    public var dependencies: [ManifestDependency]109    public var frameworks: [String]110    public var files: [ManifestFile]111    /// Digest of the file list (see `RegistryHash.contentDigest`).112    public var sha256: String113    public var license: String114    public var symbols: [String]115    public var examples: [ManifestExample]116    public var accessibility: [String]117    public var changelog: [ManifestChange]118119    public init(120        schemaVersion: Int = RegistrySchema.version, id: String, name: String, version: String, description: String,121        kind: String, category: String?, platforms: [String], minimumOS: [String: String],122        dependencies: [ManifestDependency], frameworks: [String], files: [ManifestFile], license: String,123        symbols: [String], examples: [ManifestExample], accessibility: [String], changelog: [ManifestChange]124    ) {125        self.schemaVersion = schemaVersion; self.id = id; self.name = name; self.version = version126        self.description = description; self.kind = kind; self.category = category; self.platforms = platforms127        self.minimumOS = minimumOS; self.dependencies = dependencies; self.frameworks = frameworks128        self.files = files; self.sha256 = RegistryHash.contentDigest(of: files); self.license = license129        self.symbols = symbols; self.examples = examples; self.accessibility = accessibility; self.changelog = changelog130    }131132    /// Directory of this version inside the registry, and the place its files are served from.133    public var directory: String { "components/\(id)/\(version)" }134    public var manifestPath: String { "\(directory)/manifest.json" }135    public func registryPath(of file: ManifestFile) -> String { "\(directory)/files/\(file.path)" }136}137138public struct ManifestDependency: Codable, Hashable, Sendable {139    public var id: String140    public var version: String141    public init(id: String, version: String) { self.id = id; self.version = version }142}143144public struct ManifestFile: Codable, Hashable, Sendable {145    /// Destination path, relative to the directory the project installs GlassKit sources into.146    public var path: String147    public var sha256: String148    public var bytes: Int149    public init(path: String, sha256: String, bytes: Int) { self.path = path; self.sha256 = sha256; self.bytes = bytes }150}151152public struct ManifestExample: Codable, Hashable, Sendable {153    public var title: String154    public var code: String155    public init(title: String, code: String) { self.title = title; self.code = code }156}157158public struct ManifestChange: Codable, Hashable, Sendable {159    public var version: String160    public var date: String161    public var changes: [String]162    public init(version: String, date: String, changes: [String]) { self.version = version; self.date = date; self.changes = changes }163}164
Files main
Menu

Theme