// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation import TSCBasic import llbuild2fx extension Keys { struct SourceCode: BuildKey { struct ValueType: Codable, FXValue { let code: String } enum SourceCodeError: Error { case unitNotFound } let sourceTreeId: LLBDataID let unitName: UnitName static let versionDependencies: [any FXVersioning.Type] = [UnitMapOfSourceTree.self] func computeValue(_ ctx: BuildContext) async throws -> ValueType { let unitMap = try await ctx.request(UnitMapOfSourceTree(sourceTreeId: sourceTreeId)) guard let unitInfo = unitMap.units[unitName] else { throw SourceCodeError.unitNotFound } let contents = try await ctx.load(unitInfo.blobId) let code = try await String(decoding: Data(ctx.read(blob: contents.blob!)), as: UTF8.self) return ValueType(code: code) } } }