From 0f07ab5de5ae4226d2be4d91244827d8c504f807 Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Tue, 11 Feb 2020 21:09:40 -0800 Subject: [PATCH] Complete initial version of source interface (#34) --- .../Public/AppInstallerRepositorySearch.h | 90 ++++++++++++++++++- .../Public/AppInstallerRepositorySource.h | 31 ++++--- .../AppInstallerSQLiteIndexUtil.h | 2 +- 3 files changed, 108 insertions(+), 15 deletions(-) diff --git a/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySearch.h b/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySearch.h index 80a2f7ef358df..81a9421018775 100644 --- a/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySearch.h +++ b/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySearch.h @@ -1,19 +1,105 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #pragma once +#include + +#include +#include +#include +#include +#include namespace AppInstaller::Repository { + // The type of matching to perform during a search. + enum class MatchType + { + Exact, + Substring, + Wildcard, + Fuzzy, + }; + + // The field to match on. + enum class ApplicationMatchField + { + Id, + Name, + Moniker, + Tag, + Command, + Protocol, + Extension, + }; + + // A single match to be performed during a search. + struct RequestMatch + { + MatchType Type; + std::string Value; + + RequestMatch(MatchType t, std::string v) : Type(t), Value(std::move(v)) {} + }; + + // A match on a specific field to be performed during a search. + struct ApplicationMatchFilter : public RequestMatch + { + ApplicationMatchField Field; + + ApplicationMatchFilter(ApplicationMatchField f, MatchType t, std::string v) : RequestMatch(t, std::move(v)), Field(f) {} + }; + // Container for data used to filter the available manifests in a source. - struct SearchFilter + struct SearchRequest + { + // The generic query matches against a source defined set of fields. + // If not provided, the filters should be used against the entire dataset. + std::optional Query; + + // Specific fields used to filter the data further. + std::vector Filters; + + // The maximum number of results to return. + // The default of 0 will place no limit. + size_t MaximumResults{}; + }; + + // A single application result from a search. + struct IApplication + { + // Gets the id of the application. + virtual std::string GetId() const = 0; + + // Gets the name of the application (the latest name). + virtual std::string GetName() const = 0; + + // Gets a manifest for this application. + // An empty version implies 'latest'. + // An empty channel is the 'general audience'. + virtual Manifest::Manifest GetManifest(std::string_view version, std::string_view channel) const = 0; + + // Gets all versions of this application. + // The pair is . + virtual std::vector> GetVersions() const = 0; + }; + + // A single result from the search. + struct ResultMatch { + // The application found by the search request. + std::unique_ptr Application; + + // The highest order field on which the application matched the search. + ApplicationMatchFilter MatchCriteria; + ResultMatch(std::unique_ptr a, ApplicationMatchFilter f) : Application(std::move(a)), MatchCriteria(std::move(f)) {} }; // Search result data. struct SearchResult { - + // The full set of results from the search. + std::vector Matches; }; } diff --git a/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySource.h b/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySource.h index 92d4d274ef54a..1dd0ffb3fdee6 100644 --- a/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySource.h +++ b/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySource.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include #include #include @@ -11,29 +12,35 @@ namespace AppInstaller::Repository { // Interface for retrieving information about a source without acting on it. - struct ISourceDetails + struct SourceDetails { - // Gets the name of the source. - virtual const std::string& GetName() = 0; + // The name of the source. + std::string Name; - // Gets the type of the source. - virtual const std::string& GetType() = 0; + // The type of the source. + std::string Type; - // Gets the argument used when adding the source. - virtual const std::string& GetArg() = 0; + // The argument used when adding the source. + std::string Arg; - // Gets sources extra data string. - virtual const std::string& GetData() = 0; + // The sources extra data string. + std::string Data; + + // The last time that this source was updated. + std::chrono::system_clock::time_point LastUpdateTime; }; // Interface for interacting with a source from outside of the repository lib. - struct ISource : public ISourceDetails + struct ISource { + // Get the source's details. + virtual const SourceDetails& GetDetails() const = 0; + // Request that the source update its internal data from the upstream location. virtual void Update() = 0; // Execute a search on the source. - virtual SearchResult Search(const SearchFilter& filter) = 0; + virtual SearchResult Search(const SearchRequest& request) const = 0; }; // Adds a new source for the user. @@ -44,7 +51,7 @@ namespace AppInstaller::Repository std::unique_ptr OpenSource(const std::string& name); // Gets the details for all sources. - std::vector> GetSources(); + std::vector GetSources(); // Removes an existing source. void RemoveSource(const std::string& name); diff --git a/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.h b/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.h index 82513fac3b30c..ac27b9d517c79 100644 --- a/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.h +++ b/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.h @@ -48,7 +48,7 @@ extern "C" // Updates the manifest at the repository relative path in the index. // The out value indicates whether the index was modified by the function. - APPINSTALLER_SQLITE_INDEX_API ApdateManifest( + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexUpdateManifest( APPINSTALLER_SQLITE_INDEX_HANDLE index, APPINSTALLER_SQLITE_INDEX_STRING manifestPath, APPINSTALLER_SQLITE_INDEX_STRING relativePath,