Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build process #1

Merged
merged 12 commits into from
Sep 28, 2022
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,5 @@ coverage.cobertura.xml

# Scripted build artifacts
/_codeCoverage
/_packages
/_packages
*.sbom.*
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,39 @@ The `TParameterProvider` is a type which implements `ITemplateParameterProvider<

This allows you to process parameters as efficiently as possible, based on the types you need to support.

The benchmarks contain an example built over the low-allocation [Corvus.JsonSchema.ExtendedTypes](https://github.com/corvus-dotnet/Corvus.JsonSchema) called `JsonTemplateParameterProvider` that takes a parameter set based on a JSON object, supporting all JSON element types as parameter values.
The package `Corvus.UriTemplates.Resolvers.Json` contains a `JsonTemplateResolver` that takes a parameter set based on a `System.Text.Json.JsonElement` of `JsonValueKind.Object`. Its properties become the named parameters.

```csharp
using JsonDocument jsonValues = JsonDocument.Parse("{ \"foo\": \"bar\", \"bar\": \"baz\", \"baz\": \"bob\" }");
object? nullState = default;
JsonUriTemplateResolver.TryResolveResult(UriTemplate.AsSpan(), false, JsonValues, HandleResult, ref nullState);
JsonUriTemplateResolver.TryResolveResult(UriTemplate.AsSpan(), false, jsonValues.RootElement, HandleResult, ref nullState);

static void HandleResult(ReadOnlySpan<char> resolvedTemplate, ref object? state)
{
Do what you want with the resolved template!
// Do what you want with the resolved template
// (Typically, you use the state you have passed in to pprovide the resolved template
// to the outside world in some form.)
}
```

There are also overloads of `TryResolveResult` which will write to an `IBufferWriter<char>` instead of providing the `ReadOnlySpan<char>` to a callback.

Similarly, a resolver that takes parameters from a `Dictionary<string, object?>` can be found in the package `Corvus.UriTemplates.Resolvers.DictionaryOfObject`.

```csharp
using JsonDocument jsonValues = JsonDocument.Parse("{ \"foo\": \"bar\", \"bar\": \"baz\", \"baz\": \"bob\" }");
object? nullState = default;
JsonUriTemplateResolver.TryResolveResult(UriTemplate.AsSpan(), false, jsonValues.RootElement, HandleResult, ref nullState);

static void HandleResult(ReadOnlySpan<char> resolvedTemplate, ref object? state)
{
// Do what you want with the resolved template
// (Typically, you use the state you have passed in to pprovide the resolved template
// to the outside world in some form.)
}
```

You should examine the implementations of those types if you wish to implement your own low-allocation parameter providers.

## Build and test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Corvus.UriTemplates.Resolvers.Json\Corvus.UriTemplates.Resolvers.Json.csproj" />
<ProjectReference Include="..\Corvus.UriTemplates\Corvus.UriTemplates.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.2" />
<PackageReference Include="Corvus.Json.ExtendedTypes" Version="1.0.0-v1-pre1.174" />
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Copyright (c) Endjin Limited. All rights reserved.
// </copyright>

using System.Text.Json;
using BenchmarkDotNet.Attributes;
using Corvus.Json;

namespace Corvus.UriTemplates.Benchmarking;

Expand All @@ -15,8 +15,8 @@ public class UriTemplateParameterSetting
{
private const string UriTemplate = "http://example.org/location{?value*}";
private static readonly Dictionary<string, string> Values = new() { { "foo", "bar" }, { "bar", "baz" }, { "baz", "bob" } };
private static readonly JsonAny JsonValues = JsonAny.FromProperties(("foo", "bar"), ("bar", "baz"), ("baz", "bob")).AsJsonElementBackedValue();

private readonly JsonDocument jsonValues = JsonDocument.Parse("{ \"foo\": \"bar\", \"bar\": \"baz\", \"baz\": \"bob\" }");
private Tavis.UriTemplates.UriTemplate? tavisTemplate;
private TavisApi.UriTemplate? corvusTavisTemplate;

Expand All @@ -39,6 +39,7 @@ public Task GlobalSetup()
[GlobalCleanup]
public Task GlobalCleanup()
{
this.jsonValues.Dispose();
return Task.CompletedTask;
}

Expand Down Expand Up @@ -69,7 +70,7 @@ public void ResolveUriCorvusTavis()
public void ResolveUriCorvus()
{
object? nullState = default;
JsonUriTemplateResolver.TryResolveResult(UriTemplate.AsSpan(), false, JsonValues, HandleResult, ref nullState);
JsonUriTemplateResolver.TryResolveResult(UriTemplate.AsSpan(), false, this.jsonValues.RootElement, HandleResult, ref nullState);
static void HandleResult(ReadOnlySpan<char> resolvedTemplate, ref object? state)
{
// NOP
Expand Down
133 changes: 48 additions & 85 deletions Solutions/Corvus.UriTemplate.Benchmarking/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@
"Microsoft.Diagnostics.Tracing.TraceEvent": "3.0.2"
}
},
"Corvus.Json.ExtendedTypes": {
"type": "Direct",
"requested": "[1.0.0-v1-pre1.174, )",
"resolved": "1.0.0-v1-pre1.174",
"contentHash": "u/bjziXGWKnkIuZgvwTE0/ngpImRLbXThszBUjxqNXZT21JR50lJue1HiHs1Ckw/0oFsTq65n8ijZAmRpxLdGg==",
"dependencies": {
"CommunityToolkit.HighPerformance": "8.0.0",
"Corvus.Extensions": "1.1.4",
"Microsoft.Extensions.Http": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.ObjectPool": "7.0.0-rc.1.22427.2",
"NodaTime": "3.1.2",
"System.Buffers": "4.5.1",
"System.Collections.Immutable": "7.0.0-rc.1.22426.10",
"System.Text.Json": "7.0.0-rc.1.22426.10"
}
},
"Endjin.RecommendedPractices.GitHub": {
"type": "Direct",
"requested": "[2.1.2, )",
Expand All @@ -58,21 +42,6 @@
"Microsoft.SourceLink.GitHub": "1.1.1"
}
},
"Roslynator.Analyzers": {
"type": "Direct",
"requested": "[4.1.1, )",
"resolved": "4.1.1",
"contentHash": "3cPVlrB1PytlO1ztZZBOExDKQWpMZgI15ZDa0BqLu0l6xv+xIRfEpqjNRcpvUy3aLxWTkPgSKZbbaO+VoFEJ1g=="
},
"StyleCop.Analyzers": {
"type": "Direct",
"requested": "[1.2.0-beta.435, )",
"resolved": "1.2.0-beta.435",
"contentHash": "TADk7vdGXtfTnYCV7GyleaaRTQjfoSfZXprQrVMm7cSJtJbFc1QIbWPyLvrgrfGdfHbGmUPvaN4ODKNxg2jgPQ==",
"dependencies": {
"StyleCop.Analyzers.Unstable": "1.2.0.435"
}
},
"Tavis.UriTemplates": {
"type": "Direct",
"requested": "[1.1.1, )",
Expand All @@ -97,14 +66,6 @@
"resolved": "8.0.0",
"contentHash": "S5Iv1d5UJZNJLJbe/xzJmLqYJ2mhefbLAvhXCZEh3G4sFadUBuQZhQioE4oJG4enY69QMuJX3AX9+6P9rH1bMw=="
},
"Corvus.Extensions": {
"type": "Transitive",
"resolved": "1.1.4",
"contentHash": "WGwNzQDNrlxfH82iRSSXcG92yKhE8xlBMWoSC4dycp0MnH2Mle0TF+Y4keRgDAdDwXg8VC+3paZx64jVG1Jazg==",
"dependencies": {
"System.Interactive": "3.2.0"
}
},
"Endjin.RecommendedPractices": {
"type": "Transitive",
"resolved": "2.1.2",
Expand Down Expand Up @@ -187,45 +148,50 @@
"resolved": "3.1.6",
"contentHash": "jek4XYaQ/PGUwDKKhwR8K47Uh1189PFzMeLqO83mXrXQVIpARZCcfuDedH50YDTepBkfijCZN5U/vZi++erxtg=="
},
"Microsoft.Extensions.DependencyInjection": {
"Microsoft.Extensions.Configuration": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "P7COzZFQKK9YzxomJUl9zXOKkt+5JJ4BIwHl/sN7+gHWAGjY9bD3yqV0Vzf5moGahBVrvL7dWyX1AN2MeoL68g==",
"resolved": "2.1.1",
"contentHash": "LjVKO6P2y52c5ZhTLX/w8zc5H4Y3J/LJsgqTBj49TtFq/hAtVNue/WA0F6/7GMY90xhD7K0MDZ4qpOeWXbLvzg==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0-rc.1.22426.10"
"Microsoft.Extensions.Configuration.Abstractions": "2.1.1"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"Microsoft.Extensions.Configuration.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "DJfKuxPF9IF1BnFxpEYLLXthLg6QEXopGtxGfuSCc3/fWJdnwPwSCTA6DOl5LHtRHogJlq6haL3Ehh+RNVpW7Q=="
"resolved": "2.1.1",
"contentHash": "VfuZJNa0WUshZ/+8BFZAhwFKiKuu/qOUCFntfdLpHj7vcRnsGHqd3G2Hse78DM+pgozczGM63lGPRLmy+uhUOA==",
"dependencies": {
"Microsoft.Extensions.Primitives": "2.1.1"
}
},
"Microsoft.Extensions.Http": {
"Microsoft.Extensions.Configuration.Binder": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "qcNuBOGM2mu+yAUiqCDoRL6vLcW3vfVze/5QAmfWUIg/duUXd2D4kiLvyXiCt4cNWMS5X2Zw5+tlt8c/MnBq1g==",
"resolved": "2.1.1",
"contentHash": "fcLCTS03poWE4v9tSNBr3pWn0QwGgAn1vzqHXlXgvqZeOc7LvQNzaWcKRQZTdEc3+YhQKwMsOtm3VKSA2aWQ8w==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.Logging": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.Logging.Abstractions": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.Options": "7.0.0-rc.1.22426.10"
"Microsoft.Extensions.Configuration": "2.1.1"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "2.1.1",
"contentHash": "MgYpU5cwZohUMKKg3sbPhvGG+eAZ/59E9UwPwlrUkyXU+PGzqwZg9yyQNjhxuAWmoNoFReoemeCku50prYSGzA=="
},
"Microsoft.Extensions.Logging": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "8RkgzXx5vTJGFd60GBlk5vybpEBUXTxfgcRgQw1uaM2kAjovc/Q5xezT+u58xDsy4rLDfd0pGZ6EisV5GOcy4w==",
"resolved": "2.1.1",
"contentHash": "hh+mkOAQDTp6XH80xJt3+wwYVzkbwYQl9XZRCz4Um0JjP/o7N9vHM3rZ6wwwtr+BBe/L6iBO2sz0px6OWBzqZQ==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.Logging.Abstractions": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.Options": "7.0.0-rc.1.22426.10"
"Microsoft.Extensions.Configuration.Binder": "2.1.1",
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.1.1",
"Microsoft.Extensions.Logging.Abstractions": "2.1.1",
"Microsoft.Extensions.Options": "2.1.1"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "ElrDslqtljpyFZTyygITf3VmYEWUE/ZsTaf7jltzbFohp5u51CLQ2OlO0dRSA8CsFqX/Axiu9vMwyUmt8NJo2g=="
"resolved": "2.1.1",
"contentHash": "XRzK7ZF+O6FzdfWrlFTi1Rgj2080ZDsd46vzOjadHUB0Cz5kOvDG8vI7caa5YFrsHQpcfn0DxtjS4E46N4FZsA=="
},
"Microsoft.Extensions.ObjectPool": {
"type": "Transitive",
Expand All @@ -234,17 +200,21 @@
},
"Microsoft.Extensions.Options": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "DQ0guZczQIwu7kGsKy7072ncZOdbHC8r1bWLbh+/NaL/cVC1mrlK8UA8fQP+trtp2YYfOrfaF0wqffYkRdpQKg==",
"resolved": "2.1.1",
"contentHash": "V7lXCU78lAbzaulCGFKojcCyG8RTJicEbiBkPJjFqiqXwndEBBIehdXRMWEVU3UtzQ1yDvphiWUL9th6/4gJ7w==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0-rc.1.22426.10",
"Microsoft.Extensions.Primitives": "7.0.0-rc.1.22426.10"
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.1.1",
"Microsoft.Extensions.Primitives": "2.1.1"
}
},
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "7.0.0-rc.1.22426.10",
"contentHash": "BELLSkZWsX/Y4uNqbCiAnwBH5NnVfMAxs50SXUaV+edkO4rRJdskxHTLMgLCqtnTcy4UnWsERsnj/3zONGlogA=="
"resolved": "2.1.1",
"contentHash": "scJ1GZNIxMmjpENh0UZ8XCQ6vzr/LzeF9WvEA51Ix2OQGAs9WPgPu8ABVUdvpKPLuor/t05gm6menJK3PwqOXg==",
"dependencies": {
"System.Memory": "4.5.1",
"System.Runtime.CompilerServices.Unsafe": "4.5.1"
}
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
Expand Down Expand Up @@ -331,14 +301,6 @@
"System.Xml.XDocument": "4.0.11"
}
},
"NodaTime": {
"type": "Transitive",
"resolved": "3.1.2",
"contentHash": "KAlnzQ2EtrrRhFoVePf2kMc24CXX3mAslfp+LmVQnk6HSZ8whgsHNpfUfO+jWCdMgGKQQKMjNCDgmTopjTPFFA==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "4.7.1"
}
},
"Perfolizer": {
"type": "Transitive",
"resolved": "0.2.1",
Expand Down Expand Up @@ -383,11 +345,6 @@
"Microsoft.NETCore.Targets": "1.0.1"
}
},
"StyleCop.Analyzers.Unstable": {
"type": "Transitive",
"resolved": "1.2.0.435",
"contentHash": "ouwPWZxbOV3SmCZxIRqHvljkSzkCyi1tDoMzQtDb/bRP8ctASV/iRJr+A2Gdj0QLaLmWnqTWDrH82/iP+X80Lg=="
},
"System.AppContext": {
"type": "Transitive",
"resolved": "4.1.0",
Expand Down Expand Up @@ -526,11 +483,6 @@
"System.Runtime.InteropServices": "4.1.0"
}
},
"System.Interactive": {
"type": "Transitive",
"resolved": "3.2.0",
"contentHash": "hoXiC7r+WvT/oQ/QcsCgIJMEcXKXyM26BvIcFVRgEMzXk9URu8oR2ADqrnHwIRiJmxQC/q8b3KTQSkdoFRO4TA=="
},
"System.IO": {
"type": "Transitive",
"resolved": "4.1.0",
Expand Down Expand Up @@ -1154,6 +1106,17 @@
"System.Buffers": "[4.5.1, )",
"System.Collections.Immutable": "[7.0.0-rc.1.22426.10, )"
}
},
"corvus.uritemplates.resolvers.json": {
"type": "Project",
"dependencies": {
"CommunityToolkit.HighPerformance": "[8.0.0, )",
"Corvus.UriTemplates": "[1.0.0, )",
"Microsoft.Extensions.ObjectPool": "[7.0.0-rc.1.22427.2, )",
"System.Buffers": "[4.5.1, )",
"System.Collections.Immutable": "[7.0.0-rc.1.22426.10, )",
"System.Text.Json": "[7.0.0-rc.1.22426.10, )"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="azurepipelines.testlogger" Version="1.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(EndjinProjectPropsPath)" Condition="$(EndjinProjectPropsPath) != ''" />

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Description>Dictionary of object parameter provider for a low allocation implementation of URI template functions conforming to http://tools.ietf.org/html/rfc6570.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.0.0" />
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0-rc.1.22426.10" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="7.0.0-rc.1.22427.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Corvus.UriTemplates\Corvus.UriTemplates.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.435" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Roslynator.Analyzers" Version="4.1.1" />
</ItemGroup>

</Project>
Loading