commit 0f07ab5de5ae4226d2be4d91244827d8c504f807
parent 749ea6340d1fa3f86908ef030ee71b840d501e0f
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Tue, 11 Feb 2020 21:09:40 -0800
Complete initial version of source interface (#34)
Diffstat:
3 files changed, 108 insertions(+), 15 deletions(-)
diff --git 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 <Manifest/Manifest.h>
+
+#include <memory>
+#include <optional>
+#include <string>
+#include <string_view>
+#include <vector>
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<RequestMatch> Query;
+
+ // Specific fields used to filter the data further.
+ std::vector<ApplicationMatchFilter> 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 <version, channel>.
+ virtual std::vector<std::pair<std::string, std::string>> GetVersions() const = 0;
+ };
+
+ // A single result from the search.
+ struct ResultMatch
{
+ // The application found by the search request.
+ std::unique_ptr<IApplication> Application;
+
+ // The highest order field on which the application matched the search.
+ ApplicationMatchFilter MatchCriteria;
+ ResultMatch(std::unique_ptr<IApplication> 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<ResultMatch> Matches;
};
}
diff --git a/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySource.h b/src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySource.h
@@ -3,6 +3,7 @@
#pragma once
#include <Public/AppInstallerRepositorySearch.h>
+#include <chrono>
#include <memory>
#include <string>
#include <vector>
@@ -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<ISource> OpenSource(const std::string& name);
// Gets the details for all sources.
- std::vector<std::unique_ptr<ISourceDetails>> GetSources();
+ std::vector<SourceDetails> GetSources();
// Removes an existing source.
void RemoveSource(const std::string& name);
diff --git 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,