Skip to content

Commit

Permalink
Complete initial version of source interface (microsoft#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS authored Feb 12, 2020
1 parent 749ea63 commit 0f07ab5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once
#include <Public/AppInstallerRepositorySearch.h>

#include <chrono>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -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.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f07ab5

Please sign in to comment.