Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion TablePro/Core/Services/Export/ExportFormatCatalog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ internal enum ExportFormatCatalog {
"csv", "json", "sql", "xlsx", "md", "parquet", "mql"
]

// scripts/release/registry.py writes no exportFormatIds yet, so Parquet stays offered by hand until it does.
private static let unlistedInstallable = [
InstallableExportFormat(
formatId: "parquet",
displayName: "Parquet",
registryPluginId: "com.TablePro.ParquetExportPlugin"
)
]

internal static func installable(in manifest: RegistryManifest?) -> [InstallableExportFormat] {
(manifest?.plugins ?? []).flatMap { plugin in
let listed = (manifest?.plugins ?? []).flatMap { plugin in
(plugin.exportFormatIds ?? []).map { formatId in
InstallableExportFormat(formatId: formatId, displayName: plugin.name, registryPluginId: plugin.id)
}
}
let listedFormatIds = Set(listed.map(\.formatId))
return listed + unlistedInstallable.filter { !listedFormatIds.contains($0.formatId) }
}

@MainActor
Expand Down
47 changes: 35 additions & 12 deletions TableProTests/Core/Export/ExportFormatCatalogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,45 @@ struct ExportFormatCatalogTests {
)
}

@Test("The manifest's export-format ids are what the catalog offers to install")
private let handParquet = InstallableExportFormat(
formatId: "parquet",
displayName: "Parquet",
registryPluginId: "com.TablePro.ParquetExportPlugin"
)

@Test("Parquet is offered while the manifest names no export format")
@MainActor
func installableComesFromTheManifest() {
let listed = manifest([
func parquetOfferedWithoutManifestFormats() {
let unlisted = manifest([
registryPlugin(id: "com.TablePro.OracleDriver", name: "Oracle Driver", exportFormatIds: nil),
registryPlugin(id: "com.TablePro.ParquetExportPlugin", name: "Parquet Export", exportFormatIds: ["parquet"])
registryPlugin(id: "com.TablePro.ParquetExportPlugin", name: "Parquet Export", exportFormatIds: nil)
])

#expect(ExportFormatCatalog.installable(in: listed) == [
InstallableExportFormat(
formatId: "parquet",
displayName: "Parquet Export",
registryPluginId: "com.TablePro.ParquetExportPlugin"
)
#expect(ExportFormatCatalog.installable(in: nil) == [handParquet])
#expect(ExportFormatCatalog.installable(in: unlisted) == [handParquet])
#expect(ExportFormatCatalog.notInstalled(installedFormatIds: [], manifest: nil) == [handParquet])
#expect(ExportFormatCatalog.notInstalled(installedFormatIds: ["parquet"], manifest: nil).isEmpty)
}

@Test("A format the manifest lists is offered once, from the manifest")
@MainActor
func manifestFormatsReplaceTheHandEntry() {
let listed = manifest([
registryPlugin(id: "com.TablePro.ParquetExportPlugin", name: "Parquet Export", exportFormatIds: ["parquet"]),
registryPlugin(id: "com.example.AvroExport", name: "Avro Export", exportFormatIds: ["avro"])
])
#expect(ExportFormatCatalog.notInstalled(installedFormatIds: ["parquet"], manifest: listed).isEmpty)
#expect(ExportFormatCatalog.notInstalled(installedFormatIds: [], manifest: nil).isEmpty)
let parquet = InstallableExportFormat(
formatId: "parquet",
displayName: "Parquet Export",
registryPluginId: "com.TablePro.ParquetExportPlugin"
)
let avro = InstallableExportFormat(
formatId: "avro",
displayName: "Avro Export",
registryPluginId: "com.example.AvroExport"
)

#expect(ExportFormatCatalog.installable(in: listed) == [parquet, avro])
#expect(ExportFormatCatalog.notInstalled(installedFormatIds: ["parquet"], manifest: listed) == [avro])
}
}
Loading