Skip to content

Commit

Permalink
Merge branch 'main' into adithyase/customtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaselv authored Apr 10, 2024
2 parents 37f21d5 + ed83c67 commit e36674b
Show file tree
Hide file tree
Showing 200 changed files with 20,678 additions and 1,995 deletions.
8 changes: 8 additions & 0 deletions releasenotes/releasenotes-1.3.0-rc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changes for 1.3.0 [RC]

## Breaking Language changes:


## New API features

## Other:
249 changes: 225 additions & 24 deletions src/libraries/Microsoft.PowerFx.Connectors/ConnectorFunction.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Version Condition=" '$(ReleasePackageVersion)' != '' ">$(ReleasePackageVersion)</Version>
<PackageVersion Condition=" '$(ReleasePackageVersion)' == '' ">$(LocalPackageVersion)</PackageVersion>
<PackageVersion Condition=" '$(ReleasePackageVersion)' != '' ">$(ReleasePackageVersion)</PackageVersion>
<Configurations>Debug;Release</Configurations>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<!-- Nuget Properties -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ internal static ConnectorType GetConnectorType(this OpenApiParameter openApiPara
case "string":

// We don't want to have OptionSets in connections, we'll only get string/number for now in FormulaType
// Anyhow, we'll have schema.Enum content in ConnertorType
// Anyhow, we'll have schema.Enum content in ConnectorType

switch (schema.Format)
{
Expand All @@ -428,8 +428,8 @@ internal static ConnectorType GetConnectorType(this OpenApiParameter openApiPara
case "enum":
if (schema.Enum.All(e => e is OpenApiString))
{
OptionSet os = new OptionSet("enum", schema.Enum.Select(e => new DName((e as OpenApiString).Value)).ToDictionary(k => k, e => e).ToImmutableDictionary());
return new ConnectorType(schema, openApiParameter, os.FormulaType);
OptionSet optionSet = new OptionSet("enum", schema.Enum.Select(e => new DName((e as OpenApiString).Value)).ToDictionary(k => k, e => e).ToImmutableDictionary());
return new ConnectorType(schema, openApiParameter, optionSet.FormulaType);
}
else
{
Expand Down
83 changes: 70 additions & 13 deletions src/libraries/Microsoft.PowerFx.Connectors/Public/ConnectorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,39 @@ public class ConnectorType : SupportsConnectorErrors
// "x-ms-explicit-input"
public bool ExplicitInput { get; }

// "enum"
public bool IsEnum { get; }

// Enumeration value, only defined if IsEnum is true
public FormulaValue[] EnumValues { get; }

// Enumeration display name ("x-ms-enum-display-name"), only defined if IsEnum is true
// If not defined, this array will be empty
// If not defined, this array will be empty
public string[] EnumDisplayNames { get; }

// Option Set, only defined when IsEnum is true and EnumValues is not empty
public OptionSet OptionSet => GetOptionSet();
public Dictionary<string, FormulaValue> Enum => GetEnum();

public Visibility Visibility { get; internal set; }
public Visibility Visibility { get; internal set; }

internal RecordType HiddenRecordType { get; }

// Supports x-ms-dynamic-values or -list locally
public bool SupportsDynamicValuesOrList => DynamicValues != null || DynamicList != null;

// Supports x-ms-dynamic-values or -list locally or anywhere in the tree
public bool ContainsDynamicValuesOrList => SupportsDynamicValuesOrList || (Fields != null && Fields.Any(f => f.ContainsDynamicValuesOrList));

// Supports x-ms-dynamic-schema or -property locally
public bool SupportsDynamicSchemaOrProperty => DynamicSchema != null || DynamicProperty != null;

// Supports x-ms-dynamic-schema or -property locally or anywhere in the tree
public bool ContainsDynamicSchemaOrProperty => SupportsDynamicSchemaOrProperty || (Fields != null && Fields.Any(f => f.ContainsDynamicSchemaOrProperty));

// Supports x-ms-dynamic-values, -list, -schema, or -property locally
public bool SupportsDynamicIntellisense => SupportsDynamicValuesOrList || SupportsDynamicSchemaOrProperty;

// Supports x-ms-dynamic-values, -list, -schema, or -property locally or anywhere in the tree
public bool ContainsDynamicIntellisense => ContainsDynamicValuesOrList || ContainsDynamicSchemaOrProperty;

internal ConnectorDynamicSchema DynamicSchema { get; private set; }

internal ConnectorDynamicProperty DynamicProperty { get; private set; }
Expand All @@ -93,7 +103,7 @@ internal ConnectorType(OpenApiSchema schema, OpenApiParameter openApiParameter,
MediaKind = openApiParameter?.GetMediaKind().ToMediaKind() ?? (Binary ? MediaKind.File : MediaKind.NotBinary);

if (schema != null)
{
{
Description = schema.Description;
DisplayName = schema.GetSummary();
ExplicitInput = schema.GetExplicitInput();
Expand All @@ -104,22 +114,24 @@ internal ConnectorType(OpenApiSchema schema, OpenApiParameter openApiParameter,
if (IsEnum)
{
EnumValues = schema.Enum.Select(oaa =>
{
{
if (OpenApiExtensions.TryGetOpenApiValue(oaa, null, out FormulaValue fv, this))
{
return fv;
}

AddError($"Invalid conversion for type {oaa.GetType().Name} in enum");
return FormulaValue.NewBlank();
}).ToArray();

// x-ms-enum-display-name
EnumDisplayNames = schema.Extensions != null && schema.Extensions.TryGetValue(XMsEnumDisplayName, out IOpenApiExtension enumNames) && enumNames is OpenApiArray oaa
? oaa.Cast<OpenApiString>().Select(oas => oas.Value).ToArray()
: Array.Empty<string>();
: Array.Empty<string>();
}
else
{
// those values are null/empty even if x-ms-dynamic-* could be present and would define possible values
EnumValues = Array.Empty<FormulaValue>();
EnumDisplayNames = Array.Empty<string>();
}
Expand Down Expand Up @@ -176,6 +188,33 @@ internal ConnectorType(OpenApiSchema schema, OpenApiParameter openApiParameter,
AggregateErrors(hiddenFields);
}

internal ConnectorType(ConnectorType connectorType, ConnectorType[] fields, FormulaType formulaType)
{
Binary = connectorType.Binary;
Description = connectorType.Description;
DisplayName = connectorType.DisplayName;
EnumDisplayNames = connectorType.EnumDisplayNames;
EnumValues = connectorType.EnumValues;
ExplicitInput = connectorType.ExplicitInput;
IsEnum = true;
IsRequired = connectorType.IsRequired;
MediaKind = connectorType.MediaKind;
Name = connectorType.Name;
Schema = connectorType.Schema;
Visibility = connectorType.Visibility;

Fields = fields;
FormulaType = formulaType;

DynamicList = null;
DynamicProperty = null;
DynamicSchema = null;
DynamicValues = null;

_errors = connectorType._errors;
_warnings = connectorType._warnings;
}

private void AggregateErrors(ConnectorType[] types)
{
if (types != null)
Expand All @@ -187,14 +226,32 @@ private void AggregateErrors(ConnectorType[] types)
}
}

private OptionSet GetOptionSet()
// Keeping code for creating OptionSet if we need it later

//private OptionSet GetOptionSet()
//{
// if (!IsOptionSet || string.IsNullOrEmpty(Name))
// {
// return null;
// }

// string[] enumValues = EnumValues.Select(ev => ev.ToObject().ToString()).ToArray();
// string[] enumDisplayNames = EnumDisplayNames ?? enumValues;

// return new OptionSet(Name, enumValues.Zip(enumDisplayNames, (ev, dn) => new KeyValuePair<string, string>(ev, dn)).ToDictionary(kvp => new DName(kvp.Key), kvp => new DName(kvp.Value)).ToImmutableDictionary());
//}

private Dictionary<string, FormulaValue> GetEnum()
{
if (!IsEnum || string.IsNullOrEmpty(Name) || EnumValues.Length != EnumDisplayNames.Length)
if (!IsEnum || string.IsNullOrEmpty(Name))
{
return null;
}

return new OptionSet(Name, EnumValues.Select(ev => ev.ToObject().ToString()).Zip(EnumDisplayNames, (ev, dn) => new KeyValuePair<string, string>(ev, dn)).ToDictionary(kvp => new DName(kvp.Key), kvp => new DName(kvp.Value)).ToImmutableDictionary());
}
FormulaValue[] enumValues = EnumValues;
string[] enumDisplayNames = EnumDisplayNames ?? enumValues.Select(ev => ev.ToObject().ToString()).ToArray();

return enumDisplayNames.Zip(enumValues, (dn, ev) => new KeyValuePair<string, FormulaValue>(dn, ev)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class SupportsConnectorErrors

public IReadOnlyCollection<ErrorResourceKey> Warnings => _warnings;

private HashSet<string> _errors = null;
protected HashSet<string> _errors = null;

private HashSet<ErrorResourceKey> _warnings = null;
protected HashSet<ErrorResourceKey> _warnings = null;

protected SupportsConnectorErrors()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public override async Task<ConnectorSuggestions> GetConnectorSuggestionsAsync(Fo
catch (Exception ex)
{
runtimeContext.ExecutionLogger?.LogException(ex, $"Exception in [Texl] {ConnectorFunction.LogFunction(nameof(GetConnectorSuggestionsAsync))} with {LogArguments(arguments)} and position {argPosition} {LogException(ex)}");
throw;

// This is Intellisense and we don't want to throw exceptions to the user
return null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public TexlError EnsureError(DocumentErrorSeverity severity, Token token, ErrorR

if (!HasErrors(token, severity))
{
var err = new TexlError(token, severity, errKey, args);
CollectionUtils.Add(ref _errors, err);
return err;
Error(severity, token, errKey, args);
}

return null;
Expand All @@ -157,6 +155,11 @@ public TexlError Error(TexlNode node, ErrorResourceKey errKey, params object[] a
return Error(DefaultSeverity, node, errKey, args);
}

public TexlError Error(Token token, ErrorResourceKey errKey, params object[] args)
{
return Error(DefaultSeverity, token, errKey, args);
}

public TexlError Error(DocumentErrorSeverity severity, TexlNode node, ErrorResourceKey errKey, params object[] args)
{
Contracts.AssertValue(node);
Expand All @@ -167,6 +170,16 @@ public TexlError Error(DocumentErrorSeverity severity, TexlNode node, ErrorResou
return err;
}

public TexlError Error(DocumentErrorSeverity severity, Token token, ErrorResourceKey errKey, params object[] args)
{
Contracts.AssertValue(token);
Contracts.AssertValue(args);

var err = new TexlError(token, severity, errKey, args);
CollectionUtils.Add(ref _errors, err);
return err;
}

public void Errors(TexlNode node, DType nodeType, KeyValuePair<string, DType> schemaDifference, DType schemaDifferenceType)
{
Contracts.AssertValue(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,21 @@ public NameLookupInfo(BindKind kind, DType type, DPath path, int upCount, object

public bool TryToSymbolEntry(out SymbolEntry x)
{
var ns = this.Data as NameSymbol;
if (ns == null)
if (this.Data is NameSymbol ns)
{
x = null;
return false;
x = new SymbolEntry
{
Name = ns.Name,
DisplayName = this.DisplayName,
Properties = ns.Props,
Type = FormulaType.Build(this.Type),
Slot = ns
};
return true;
}

x = new SymbolEntry
{
Name = ns.Name,
DisplayName = this.DisplayName,
Properties = ns.Props,
Type = FormulaType.Build(this.Type),
Slot = ns
};
return true;
x = null;
return false;
}
}
}
Loading

0 comments on commit e36674b

Please sign in to comment.