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

General version updates #35

Merged
merged 5 commits into from
Nov 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"version": 1,
"isRoot": true,
"tools": {
"fantomas-tool": {
"version": "4.6.4",
"fantomas": {
"version": "5.1.3",
"commands": [
"fantomas"
]
},
"fable": {
"version": "3.7.0",
"version": "3.7.20",
"commands": [
"fable"
]
Expand Down
82 changes: 11 additions & 71 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,25 @@
name: Build
name: Build main

on:
push:
branches: [main]
branches: [main, dev]
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [main]

env:
configuration: Release
productNamespacePrefix: "Mondocks"
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
build:
runs-on: windows-latest
outputs:
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: "recursive"

- name: Install .NET Core
uses: actions/setup-dotnet@v1
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: NBGV
id: nbgv
uses: dotnet/nbgv@master
with:
setAllVars: true

- name: NuGet Restore
run: dotnet restore

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1

- name: Install local tools
run: dotnet tool restore
- name: Build
run: dotnet build --configuration ${{ env.configuration }}

- name: Create NuGet Artifacts
uses: actions/upload-artifact@master
with:
name: nuget
path: "**/*.nupkg"

release:
runs-on: ubuntu-latest
needs: build
if: contains(github.event.pull_request.labels.*.name, 'release') && github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download NuGet Packages
uses: actions/download-artifact@v2
with:
name: nuget

- name: Changelog
uses: glennawatson/ChangeLog@v1
id: changelog

- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ needs.build.outputs.nbgv }}
release_name: ${{ needs.build.outputs.nbgv }}
body: |
${{ steps.changelog.outputs.commitLog }}
- name: NuGet Push
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
SOURCE_URL: https://api.nuget.org/v3/index.json
run: |
dotnet nuget push -s ${{ env.SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg
run: dotnet fsi tools.fsx
11 changes: 4 additions & 7 deletions Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@

<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageTags>mongodb;fsharp;nosql;library;dotnet;dotnet5;dotnet-core;fable;node</PackageTags>
<PackageTags>mongodb;fsharp;nosql;library;dotnet;dotnet-core;fable;node</PackageTags>
<RepositoryUrl>https://github.com/AngelMunoz/Mondocks.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/AngelMunoz/Mondocks</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/AngelMunoz/Mondocks</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<None Include="$(MSBuildThisFileDirectory)\LICENSE" Pack="true" PackagePath="" />
<None Include="$(MSBuildThisFileDirectory)\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\LICENSE" Pack="true" PackagePath="" />
<None Include="$(MSBuildThisFileDirectory)\README.md" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ RUN apt-get update \
# Install .NET Core SDK

# When updating the SDK version, the sha512 value a few lines down must also be updated.
ENV DOTNET_SDK_VERSION 5.0.100
ENV DOTNET_SDK_VERSION 6.0.403

RUN dotnet_sdk_version=5.0.100 \
RUN dotnet_sdk_version=6.0.403 \
&& curl -SL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$dotnet_sdk_version/dotnet-sdk-$dotnet_sdk_version-linux-x64.tar.gz \
&& dotnet_sha512='bec37bfb327c45cc01fd843ef93b22b556f753b04724bba501622df124e7e144c303a4d7e931b5dbadbd4f7b39e5adb8f601cb6293e317ad46d8fe7d52aa9a09' \
&& dotnet_sha512='779b3e24a889dbb517e5ff5359dab45dd3296160e4cb5592e6e41ea15cbf87279f08405febf07517aa02351f953b603e59648550a096eefcb0a20fdaf03fadde' \
&& echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
&& mkdir -p /usr/share/dotnet \
&& tar -ozxf dotnet.tar.gz -C /usr/share/dotnet \
Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ There are three ways ways to ineract with it

- If your editor supports doc comments, you should be able to see samples as well, part of the source code is documented that way, you should even see examples in the editor tooltips in some cases

# Serialization

This might be very important for you, in case the default serialization strategy doesn't work for you, you should be able to fall back to the core `Mondocks` library where the general abstractions are defined.

For example in Fable we just use `JSON.stringify(value)`

```fsharp
module Json =
let Serialize value = toPlainJsObj value |> JSON.stringify

module Aggregation =

let count = CountCommandBuilder(Json.Serialize)
```

and in .NET we use System.Text.Json

```fsharp
module Json =
// ... a bunch of converters ...
type Serializer() =
static member Serialize<'T>(value: 'T, [<Optional>] ?options: JsonSerializerOptions) =
JsonSerializer.Serialize<'T>(value, defaultArg options defaults)

module Aggregation =
let count = CountCommandBuilder(Json.Serializer.Serialize)
```

If our current serialization strategy doesn't work for you (or want to support something like Thoth.Json), you may supply a serialization function for your builder

```fsharp

module MyAggregation =

let serialize (value: obj) =
// ... do the serialization thing ...

let myCount = CountCommandBuilder(fun value -> serialize value)
```

# Goals

- Emit 100% compatible json with https://docs.mongodb.com/manual/reference/command/ and https://docs.mongodb.com/manual/reference/mongodb-extended-json
Expand All @@ -137,3 +177,11 @@ This is a work in progress, you can help providing feedback about it's usage

> Thanks for the early feedback in twitter from Isaac, Zaid, Alexey, Alexander, and the F# community
> you can follow it on the first [issue](https://github.com/AngelMunoz/Mondocks/issues/1)

```

```

```

```
2 changes: 1 addition & 1 deletion samples/Aggregation/Aggregation.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<ProjectReference Include="..\..\src\Mondocks.Net\Mondocks.Net.fsproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion samples/Commands/Commands.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<ProjectReference Include="..\..\src\Mondocks.Net\Mondocks.Net.fsproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion samples/Indexes/Indexes.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<ProjectReference Include="..\..\src\Mondocks.Net\Mondocks.Net.fsproj" />
</ItemGroup>

Expand Down
5 changes: 2 additions & 3 deletions src/Mondocks.Fable/Mondocks.Fable.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<WarnOn>3390;$(WarnOn)</WarnOn>
Expand All @@ -19,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fable.Core" Version="3.6.1" />
<PackageReference Include="Fable.Core" Version="3.7.1" />
<ProjectReference Include="..\Mondocks\Mondocks.fsproj" />
</ItemGroup>

Expand Down
3 changes: 1 addition & 2 deletions src/Mondocks.Net/Aggregation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ open Mondocks.Net.Json
module Aggregation =
/// <summary>Creates an count command for documents in the specified collection</summary>
/// <returns>returns a <see cref="Mondocks.Aggregation.Count.CountCommandBuilder">CountCommandBuilder</see></returns>
let count =
CountCommandBuilder(Serializer.Serialize)
let count = CountCommandBuilder(Serializer.Serialize)

/// <summary>Creates an update command for documents in the specified collection</summary>
/// <param name="collection">The name of the collection to perform this query against</param>
Expand Down
7 changes: 3 additions & 4 deletions src/Mondocks.Net/Mondocks.Net.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<WarnOn>3390;$(WarnOn)</WarnOn>
Expand All @@ -14,8 +13,8 @@
<Compile Include="Query.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.14.1" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
<PackageReference Include="MongoDB.Bson" Version="2.18.0" />
<PackageReference Include="System.Text.Json" Version="6.0.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mondocks\Mondocks.fsproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/Mondocks.Net/Query.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Mondocks.Queries

open Mondocks.Net.Json
open System.Runtime.InteropServices
open System.Text.Json

[<AutoOpen>]
module Query =
Expand Down
19 changes: 8 additions & 11 deletions src/Mondocks.Net/Serialization.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Json =
open System
open System.Text.Json
open System.Text.Json.Serialization
open System.Runtime.InteropServices
open MongoDB.Bson

type ObjectIdConverter() =
Expand Down Expand Up @@ -33,10 +34,7 @@ module Json =

override _.Write(writer: Utf8JsonWriter, value: DateTime, options: JsonSerializerOptions) =
let stringValue =
DateTimeOffset
.op_Implicit(value)
.ToUnixTimeMilliseconds()
|> string
DateTimeOffset.op_Implicit(value).ToUnixTimeMilliseconds() |> string

writer.WriteStartObject()
writer.WritePropertyName("$date")
Expand Down Expand Up @@ -140,15 +138,17 @@ module Json =

type BsonNullConverter() =
inherit JsonConverter<BsonNull>()

override _.Read(reader: byref<Utf8JsonReader>, typeToConvert: Type, options: JsonSerializerOptions) =
BsonNull.Value

override _.Write(writer: Utf8JsonWriter, value: BsonNull, options: JsonSerializerOptions) =
writer.WriteNullValue()

let private defaults =
let options = JsonSerializerOptions()
options.DefaultIgnoreCondition <- JsonIgnoreCondition.WhenWritingDefault
let options =
JsonSerializerOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)

options.Converters.Add(ObjectIdConverter())
options.Converters.Add(DateTimeConverter())
options.Converters.Add(DateTimeOffsetConverter())
Expand All @@ -160,8 +160,5 @@ module Json =
options

type Serializer() =
static member Serialize<'T>(value: 'T) =
JsonSerializer.Serialize<'T>(value, defaults)

static member Serialize<'T>(value: 'T, options: JsonSerializerOptions) =
JsonSerializer.Serialize<'T>(value, options)
static member Serialize<'T>(value: 'T, [<Optional>] ?options: JsonSerializerOptions) =
JsonSerializer.Serialize<'T>(value, defaultArg options defaults)