// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation import TSCBasic import llbuild2fx /// A simplified API for `llbuild2fx` that bundles the arguments of `FXKey.computeValue(_:_)`. public struct BuildContext { fileprivate let functionInterface: FXFunctionInterface fileprivate let context: Context var db: any LLBCASDatabase { context.db } func request(_ key: X) async throws -> X.ValueType { try await functionInterface.request(key, context) } func load(_ id: LLBDataID, type hint: LLBFileType? = nil) async throws -> LLBCASFSNode { try await LLBCASFSClient(context.db).load(id, type: hint, context).get() } func read(blob: LLBCASBlob) async throws -> LLBByteBufferView { try await blob.read(context).get() } } public protocol BuildKey: AsyncFXKey { func computeValue(_ ctx: BuildContext) async throws -> ValueType } extension BuildKey { public func computeValue(_ fi: FXFunctionInterface, _ ctx: Context) async throws -> ValueType { try await computeValue(BuildContext(functionInterface: fi, context: ctx)) } } extension LLBCASFileTree { public static func load(id: LLBDataID, in ctx: BuildContext) async throws -> LLBCASFileTree { try await load(id: id, from: ctx.db, ctx.context).get() } public func remove(path: AbsolutePath, in ctx: BuildContext) async throws -> LLBCASFileTree { try await remove(path: path, in: ctx.db, ctx.context).get() } public func traverse(root: AbsolutePath, in ctx: BuildContext, _ callback: (AbsolutePath, LLBDataID, LLBDirectoryEntry) async throws -> Void) async throws { try await traverse(root: root, in: ctx.db, ctx.context, callback) } }