Skip to content
Open
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
106 changes: 106 additions & 0 deletions src/libraries/Microsoft.PowerFx.Connectors/ConnectorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,139 @@
// Licensed under the MIT license.
namespace Microsoft.PowerFx.Connectors
{
/// <summary>
/// Contains constant values for x-ms-* OpenAPI extensions used in connectors.
/// </summary>
public static class Constants
{
/// <summary>
/// The x-ms-ai-sensitivity extension name.
/// </summary>
public const string XMsAiSensitivity = "x-ms-ai-sensitivity";

/// <summary>
/// The x-bodyName extension name.
/// </summary>
public const string XMsBodyName = "x-bodyName";

/// <summary>
/// The x-ms-capabilities extension name.
/// </summary>
public const string XMsCapabilities = "x-ms-capabilities";

/// <summary>
/// The x-ms-dynamic-list extension name.
/// </summary>
public const string XMsDynamicList = "x-ms-dynamic-list";

/// <summary>
/// The x-ms-dynamic-properties extension name.
/// </summary>
public const string XMsDynamicProperties = "x-ms-dynamic-properties";

/// <summary>
/// The x-ms-dynamic-schema extension name.
/// </summary>
public const string XMsDynamicSchema = "x-ms-dynamic-schema";

/// <summary>
/// The x-ms-dynamic-values extension name.
/// </summary>
public const string XMsDynamicValues = "x-ms-dynamic-values";

/// <summary>
/// The x-ms-enum extension name.
/// </summary>
public const string XMsEnum = "x-ms-enum";

/// <summary>
/// The x-ms-enum-display-name extension name.
/// </summary>
public const string XMsEnumDisplayName = "x-ms-enum-display-name";

/// <summary>
/// The x-ms-enum-values extension name.
/// </summary>
public const string XMsEnumValues = "x-ms-enum-values";

/// <summary>
/// The x-ms-explicit-input extension name.
/// </summary>
public const string XMsExplicitInput = "x-ms-explicit-input";

/// <summary>
/// The x-ms-keyOrder extension name.
/// </summary>
public const string XMsKeyOrder = "x-ms-keyOrder";

/// <summary>
/// The x-ms-keyType extension name.
/// </summary>
public const string XMsKeyType = "x-ms-keyType";

/// <summary>
/// The x-ms-media-kind extension name.
/// </summary>
public const string XMsMediaKind = "x-ms-media-kind";

/// <summary>
/// The x-ms-notification-content extension name.
/// </summary>
public const string XMsNotificationContent = "x-ms-notification-content";

/// <summary>
/// The x-ms-notification-url extension name.
/// </summary>
public const string XMsNotificationUrl = "x-ms-notification-url";

/// <summary>
/// The x-ms-pageable extension name.
/// </summary>
public const string XMsPageable = "x-ms-pageable";

/// <summary>
/// The x-ms-permission extension name.
/// </summary>
public const string XMsPermission = "x-ms-permission";

/// <summary>
/// The x-ms-property-entity-type extension name.
/// </summary>
public const string XMsPropertyEntityType = "x-ms-property-entity-type";

/// <summary>
/// The x-ms-relationships extension name.
/// </summary>
public const string XMsRelationships = "x-ms-relationships";

/// <summary>
/// The x-ms-require-user-confirmation extension name.
/// </summary>
public const string XMsRequireUserConfirmation = "x-ms-require-user-confirmation";

/// <summary>
/// The x-ms-sort extension name.
/// </summary>
public const string XMsSort = "x-ms-sort";

/// <summary>
/// The x-ms-summary extension name.
/// </summary>
public const string XMsSummary = "x-ms-summary";

/// <summary>
/// The x-ms-trigger extension name.
/// </summary>
public const string XMsTrigger = "x-ms-trigger";

/// <summary>
/// The x-ms-url-encoding extension name.
/// </summary>
public const string XMsUrlEncoding = "x-ms-url-encoding";

/// <summary>
/// The x-ms-visibility extension name.
/// </summary>
public const string XMsVisibility = "x-ms-visibility";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@

namespace Microsoft.PowerFx.Connectors
{
/// <summary>
/// "x-ms-ai-sensitivity" enum.
/// </summary>
public enum AiSensitivity : int
{
// "x-ms-ai-sensitivity" is not corresponding to any valid value (normally, only "low", "high")
/// <summary>
/// "x-ms-ai-sensitivity" is not corresponding to any valid value (normally, only "low", "high")
/// </summary>
Unknown = -1,

// "x-ms-ai-sensitivity" is not defined
/// <summary>
/// "x-ms-ai-sensitivity" is not defined
/// </summary>
None = 0,

// "x-ms-ai-sensitivity" is "low"
/// <summary>
/// "x-ms-ai-sensitivity" is "low"
/// </summary>
Low,

// "x-ms-ai-sensitivity" is "high"
/// <summary>
/// "x-ms-ai-sensitivity" is "high"
/// </summary>
High
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

namespace Microsoft.PowerFx.Connectors
{
/// <summary>
/// Base class for runtime connector context.
/// </summary>
public abstract class BaseRuntimeConnectorContext
{
/// <summary>
/// Gets the HTTP message invoker for the specified namespace.
/// </summary>
public abstract HttpMessageInvoker GetInvoker(string @namespace);

/// <summary>
/// Gets the time zone information.
/// </summary>
public abstract TimeZoneInfo TimeZoneInfo { get; }

/// <summary>
/// Gets a value indicating whether to throw on error.
/// </summary>
public virtual bool ThrowOnError { get; } = false;

internal virtual bool ReturnRawResults { get; } = false;
Expand All @@ -24,8 +36,14 @@ internal BaseRuntimeConnectorContext WithRawResults()
}
}

/// <summary>
/// Extension methods for runtime connector context.
/// </summary>
public static class RuntimeConnectorContextExtensions
{
/// <summary>
/// Adds a runtime context to the service provider.
/// </summary>
public static BasicServiceProvider AddRuntimeContext(this BasicServiceProvider serviceProvider, BaseRuntimeConnectorContext context)
{
return serviceProvider.AddService(typeof(BaseRuntimeConnectorContext), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

namespace Microsoft.PowerFx.Connectors
{
/// <summary>
/// Extension methods for CDP-related types.
/// </summary>
public static class CdpExtensions
{
/// <summary>
/// Tries to get the external table name and foreign key for a field in a RecordType.
/// </summary>
public static bool TryGetFieldExternalTableName(this RecordType recordType, string fieldName, out string tableName, out string foreignKey)
{
if (recordType is not CdpRecordType cdpRecordType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

namespace Microsoft.PowerFx.Connectors
{
// Created by TabularService.GetTableValue
// Doesn't contain any ServiceProvider which is runtime only
/// <summary>
/// Represents a table value created by TabularService.GetTableValue. Does not contain any ServiceProvider which is runtime only.
/// </summary>
public class CdpTableValue : TableValue, IRefreshable, IDelegatableTableValue
{
/// <summary>
/// Gets a value indicating whether the table is delegable.
/// </summary>
public bool IsDelegable => _tabularService.IsDelegable;

protected internal readonly CdpService _tabularService;
Expand Down Expand Up @@ -48,6 +52,9 @@ internal CdpTableValue(IRContext irContext)
_cachedRows = null;
}

/// <summary>
/// Gets the rows of the table, fetching and caching them if necessary.
/// </summary>
public override IEnumerable<DValue<RecordValue>> Rows
{
get
Expand All @@ -67,6 +74,9 @@ public override IEnumerable<DValue<RecordValue>> Rows
}
}

/// <summary>
/// Gets the supported delegation features for this table.
/// </summary>
public DelegationParameterFeatures SupportedFeatures => DelegationParameterFeatures.Filter |
DelegationParameterFeatures.Top |
DelegationParameterFeatures.Columns | // $select
Expand All @@ -75,17 +85,26 @@ public override IEnumerable<DValue<RecordValue>> Rows
DelegationParameterFeatures.ApplyTopLevelAggregation |
DelegationParameterFeatures.Count;

/// <summary>
/// Asynchronously gets the rows of the table.
/// </summary>
public async Task<IReadOnlyCollection<DValue<RecordValue>>> GetRowsAsync(IServiceProvider services, DelegationParameters parameters, CancellationToken cancel)
{
var rows = await _tabularService.GetItemsAsync(services, parameters, cancel).ConfigureAwait(false);
return rows;
}

/// <summary>
/// Refreshes the cached rows.
/// </summary>
public void Refresh()
{
_cachedRows = null;
}

/// <summary>
/// Asynchronously executes a query and returns the result as a FormulaValue.
/// </summary>
public async Task<FormulaValue> ExecuteQueryAsync(IServiceProvider services, DelegationParameters parameters, CancellationToken cancel)
{
if (parameters == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

namespace Microsoft.PowerFx.Connectors
{
// Wraps ConnectorSuggestions (defined in PFx.Core) to add ConnectorType (Pfx.Connectors only)
/// <summary>
/// Wraps ConnectorSuggestions to add ConnectorType for enhanced suggestions.
/// </summary>
public class ConnectorEnhancedSuggestions
{
/// <summary>
/// Gets the connector type associated with the suggestions.
/// </summary>
public ConnectorType ConnectorType { get; }

/// <summary>
/// Gets the connector suggestions.
/// </summary>
public ConnectorSuggestions ConnectorSuggestions { get; }

internal ConnectorEnhancedSuggestions(SuggestionMethod suggestionMethod, IReadOnlyList<ConnectorSuggestion> suggestions, ConnectorType connectorType = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@

namespace Microsoft.PowerFx.Connectors
{
// x-ms-keyType
/// <summary>
/// Specifies the key type for a connector (x-ms-keyType).
/// </summary>
public enum ConnectorKeyType
{
/// <summary>
/// Undefined key type.
/// </summary>
Undefined = -1,

// "primary"
/// <summary>
/// Primary key type.
/// </summary>
Primary,

// "none"
/// <summary>
/// No key type.
/// </summary>
None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,48 @@

namespace Microsoft.PowerFx.Connectors
{
/// <summary>
/// Logger for connector operations.
/// </summary>
public abstract class ConnectorLogger
{
protected abstract void Log(ConnectorLog log);

/// <summary>
/// Logs an informational message.
/// </summary>
public virtual void LogInformation(string message)
{
Log(new ConnectorLog(LogCategory.Information, message));
}

/// <summary>
/// Logs a debug message.
/// </summary>
public virtual void LogDebug(string message)
{
Log(new ConnectorLog(LogCategory.Debug, message));
}

/// <summary>
/// Logs an error message.
/// </summary>
public virtual void LogError(string message)
{
Log(new ConnectorLog(LogCategory.Error, message));
}

/// <summary>
/// Logs a warning message.
/// </summary>
public virtual void LogWarning(string message)
{
Log(new ConnectorLog(LogCategory.Warning, message));
}

/// <summary>
/// Logs an exception with a message.
/// </summary>
public virtual void LogException(Exception ex, string message)
{
Log(new ConnectorLog(LogCategory.Exception, message, ex));
Expand Down
Loading