diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..351a582 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,27 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-reportgenerator-globaltool": { + "version": "5.4.7", + "commands": [ + "reportgenerator" + ], + "rollForward": false + }, + "fantomas": { + "version": "7.0.1", + "commands": [ + "fantomas" + ], + "rollForward": false + }, + "fsdocs-tool": { + "version": "20.0.1", + "commands": [ + "fsdocs" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..869005a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,296 @@ +# EditorConfig is awesome: +http://EditorConfig.org + +# top-most EditorConfig file +root = true + +############################### +# Core EditorConfig Options # +############################### +# All files +[*] # Do not apply to all files not to break something +guidelines = 120 dashed, 130 +# Either crlf | lf, default is system-dependent (when not specified at all) +# end_of_line=crlf +# Remove whitespace at the end of any line + +# Visual Studio Solution Files +[*.sln] +indent_style = tab + +# Code files +[*.{cs,csx,fs,fsi,fsx}] +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space # default=space +indent_size = 4 # default=4 +charset = utf-8 + +# Project files and app specific XML files +[*.{csproj,fsproj,shproj,sfproj,projitems,props,xaml,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +# XML configuration files +[{app.config,nuget.config,packages.config,web.config}] +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +# XML files +[*.xml] +trim_trailing_whitespace = false # do not trim as it affects CData +insert_final_newline = true +indent_style = space +indent_size = 2 + +# JSON and YAML files +[*.{json,yml,yaml}] +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +# Proto files +[*.proto] +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 + +# Markdown Files +[*.{md,mdx}] +trim_trailing_whitespace = false + +# Bash Files +[*.{sh}] +end_of_line = lf + +# Batch Files +[*.{cmd,bat}] +end_of_line = crlf + +# Powershell Files +[*.{ps1, psm1}] +end_of_line = crlf + +# Paket files +[paket.*] +trim_trailing_whitespace = true +indent_size = 2 + +[*.paket.references] +trim_trailing_whitespace = true +indent_size = 2 + +############################### +# F# Coding Conventions # +############################### +# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html + +# filetypes that need to be formatted by Fantomas: +[*.{fs,fsi,fsx}] + +# files to be ignored for Fantomas may go into this file, if present: +# .fantomasignore + +# indentation size, default=4 +indent_size=4 + +# line length before it gets broken down into multiple lines +# default 120 +max_line_length=130 + +# Either crlf | lf, default is system-dependent (when not specified at all) +# end_of_line=crlf + +# Whether end-of-file has a newline, default=true +insert_final_newline=true + +# false: someLineOfCode +# true: someLineOfCode; +# default false +fsharp_semicolon_at_end_of_line=false + +# false: f(1,2) +# true: f(1, 2) +# default true +fsharp_space_before_parameter=true + +# false: Option.map(fun x -> x) +# true: Option.map (fun x -> x) +# default true +fsharp_space_before_lowercase_invocation=true + +# false: x.ToString() +# true: x.ToString () +# default false +fsharp_space_before_uppercase_invocation=true + +# false: new Ship(withBeans) +# true: new Ship (withBeans) +# default false +fsharp_space_before_class_constructor=true + +# false: __.member Foo(x) = x +# true: __.member Foo (x) = x +# default false +fsharp_space_before_member=true + +# false: type Point = { x: int; y: int } +# true: type Point = { x : int; y : int } +# default false +fsharp_space_before_colon=true + +# false: (a,b,c) +# true: (a, b, c) +# default true +fsharp_space_after_comma=true + +# false: [a; b; 42] +# true: [a ; b ; 42] +# default false +fsharp_space_before_semicolon=false + +# false: [a;b;42] +# true: [a; b; 42] +# default true +fsharp_space_after_semicolon=true + +# false: let a = [1;2;3] +# true: let a = [ 1;2;3 ] +# default true +fsharp_space_around_delimiter=true + +# breaks an if-then-else in smaller parts if it is on one line +# default 40 +fsharp_max_if_then_else_short_width=60 + +# breaks an infix operator expression if it is on one line +# infix: a + b + c +# default 50 +fsharp_max_infix_operator_expression=60 + +# breaks a single-line record declaration +# i.e. if this gets too wide: { X = 10; Y = 12 } +# default 40 +fsharp_max_record_width=80 + +# breaks a record into one item per line if items exceed this number +# i.e. if set to 1, this will be on three lines: { X = 10; Y = 12 } +# requires fsharp_record_multiline_formatter=number_of_items to take effect +# default 1 +fsharp_max_record_number_of_items=1 + +# whether to use line-length (by counting chars) or items (by counting fields) +# for the record settings above +# either number_of_items or character_width +# default character_width +fsharp_record_multiline_formatter=character_width + +# breaks a single line array or list if it exceeds this size +# default 40 +fsharp_max_array_or_list_width=100 + +# breaks an array or list into one item per line if items exceeds this number +# i.e. if set to 1, this will be shown on three lines [1; 2; 3] +# requires fsharp_array_or_list_multiline_formatter=number_of_items to take effect +# default 1 +fsharp_max_array_or_list_number_of_items=1 + +# whether to use line-length (by counting chars) or items (by counting fields) +# for the list and array settings above +# either number_of_items or character_width +# default character_width +fsharp_array_or_list_multiline_formatter=character_width + +# maximum with of a value binding, does not include keyword "let" +# default 80 +fsharp_max_value_binding_width=100 + +# maximum width for function and member binding (rh-side) +# default 40 +fsharp_max_function_binding_width=80 + +# maximum width for expressions like X.DoY().GetZ(10).Help() +# default 50 +fsharp_max_dot_get_expression_width=80 + +# whether open/close brackets go on the same column +# cramped: type Range = +# { From: float +# To: float } +# aligned: type Range = +# { +# From: float +# To: float +# } +# stroustrup: type Range = { +# From: float +# To: float +# } +# default cramped +fsharp_multiline_bracket_style=stroustrup + +# whether to move the beginning of compuitation expression to the new line +# true: let x = +# computation { +# ... +# } +# false: let x = computation { +# .. +# } +fsharp_newline_before_multiline_computation_expression=false + +# whether a newline should be placed before members +# false: type Range = +# { From: float } +# member this.Length = this.To - this.From +# true: type Range = +# { From: float } +# +# member this.Length = this.To - this.From +# default false +fsharp_newline_between_type_definition_and_members=true + +# if a function sign exceeds max_line_length, then: +# false: do not place the equal-sign on a single line +# true: place the equal-sign on a single line +# default false +fsharp_align_function_signature_to_indentation=false + +# see docs: https://github.com/fsprojects/fantomas/blob/master/docs/Documentation.md#fsharp_alternative_long_member_definitions +# default false +fsharp_alternative_long_member_definitions=true + +# places closing paren in lambda on a newline in multiline lambdas +# default false +fsharp_multi_line_lambda_closing_newline=true + +# allows the 'else'-branch to be aligned at same level as 'else' if the ret type allows it +# false: match x with +# | null -> () +# | _ -> () +# true: match x with +# | null -> () +# | _ -> +# () +# default false +fsharp_keep_indent_in_branch=true + +# whether a bar is placed before DU +# false: type MyDU = Short of int +# true: type MyDU = | Short of int +# default false +fsharp_bar_before_discriminated_union_declaration=false + +# multiline, nested expressions must be surrounded by blank lines +# default true +fsharp_blank_lines_around_nested_multiline_expressions=false + +# set maximal number of consecutive blank lines to keep from original source +# it doesn't change number of new blank lines generated by Fantomas +fsharp_keep_max_number_of_blank_lines=2 diff --git a/.fantomasignore b/.fantomasignore new file mode 100644 index 0000000..d9f2aa7 --- /dev/null +++ b/.fantomasignore @@ -0,0 +1,2 @@ +# Ignore AssemblyInfo files +AssemblyInfo.fs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..9c8817e --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,6 @@ +# This file contains a list of git hashes of revisions to be ignored by git +# These revisions are considered "unimportant" in +# that they are unlikely to be what you are interested in when blaming. +# Like formatting with Fantomas +# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view +# Add formatting commits here diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cb6f883 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,27 @@ +# Auto detect text files +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp text=auto eol=lf +*.vb diff=csharp text=auto eol=lf +*.fs diff=csharp text=auto eol=lf +*.fsi diff=csharp text=auto eol=lf +*.fsx diff=csharp text=auto eol=lf +*.sln text eol=crlf merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union +*.sh text eol=lf + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..1464891 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,30 @@ +## Description + +Please insert a description of your problem or question. + +## Error messages, screenshots + +Please add any error logs or screenshots if available. + +## Failing test, failing GitHub repo, or reproduction steps + +Please add either a failing test, a GitHub repo of the problem or detailed reproduction steps. + +## Expected Behavior + +Please define what you would expect the behavior to be like. + +## Known workarounds + +Please provide a description of any known workarounds. + +## Other information + +* Operating System: + - [ ] windows [insert version here] + - [ ] macOs [insert version] + - [ ] linux [insert flavor/version here] +* Platform + - [ ] ios + - [ ] maccatalyst +* Branch or release version: diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..b735373 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..066b2d9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ab249a8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,25 @@ +## Proposed Changes + +Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. + +## Types of changes + +What types of changes does your code introduce to FSharp.Azure.Cosmos? +_Put an `x` in the boxes that apply_ + +- [ ] Bugfix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) + + +## Checklist + +_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ + +- [ ] Build and tests pass locally +- [ ] I have added tests that prove my fix is effective or that my feature works (if appropriate) +- [ ] I have added necessary documentation (if appropriate) + +## Further comments + +If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..8690c43 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,57 @@ +We prefer the latest F# 9 features over the old syntax + +Prefer `voption` over `option` + +Prefer `task` CE over `async` CE + +This is how you define a non-default F# class constructor: +```fsharp +type DerivedClass = + inherit BaseClass + + new (``arguments here``) as ``created object`` + = + // create any objects used in the base class constructor + let fieldValue = "" + { + inherit + BaseClass (``arguments here``) + } + then + ``created object``.otherField <- fieldValue + + [] + val mutable otherField : FieldType +``` + +Always prefer F# class initializers over property assignment! **You absolutely must use F# class initializers instead of property assignment**! + +Class declaration: +``` F# +type MyClass (someConstructorParam : string) = + member ReadOnlyProperty = someConstructorParam + + member val MutableProperty1 = "" with get, set + member val MutableProperty2 = "" with get, set +``` + +Wrong: +``` F# +let myClass = MyClass("some value") +myClass.MutableProperty1 <- "new value" +myClass.MutableProperty2 <- "new value" +``` + +Right: +``` F# +let myClass = + MyClass( + // constructor parameters go first without names + "some value", + // then mutable properties go next with names + MutableProperty1 = "new value", + MutableProperty2 = + // operations must be placed into parentheses + (5 |> string) + ) +``` diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ad2ada8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,43 @@ +name: Build main + +on: + push: + branches: + - main + pull_request: + branches: + - '**' # all branches + +jobs: + build: + strategy: + matrix: + configuration: [Debug, Release] + runs-on: macos-26 + + steps: + - uses: actions/checkout@v4 + - name: Setup necessary dotnet SDKs + uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + dotnet-version: | + 9.x + 8.x + + - name: Build via Bash + if: runner.os != 'Windows' + run: | + chmod +x ./build.sh + ./build.sh + env: + CI: true + CONFIGURATION: ${{ matrix.configuration }} + ENABLE_COVERAGE: true + - name: Build via Windows + if: runner.os == 'Windows' + run: ./build.cmd + env: + CI: true + CONFIGURATION: ${{ matrix.configuration }} + ENABLE_COVERAGE: true diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml new file mode 100644 index 0000000..c022eb3 --- /dev/null +++ b/.github/workflows/copilot-setup-steps.yml @@ -0,0 +1,37 @@ +name: "Copilot Setup Steps" + +# Automatically run the setup steps when they are changed to allow for easy validation, and +# allow manual testing through the repository's "Actions" tab +on: + workflow_dispatch: + push: + paths: + - .github/workflows/copilot-setup-steps.yml + pull_request: + paths: + - .github/workflows/copilot-setup-steps.yml + +jobs: + # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. + copilot-setup-steps: + runs-on: macos-26 + + # Set the permissions to the lowest permissions possible needed for your steps. + # Copilot will be given its own token for its operations. + permissions: + # If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete. + contents: read + + # You can define any steps you want, and they will run before the agent starts. + # If you do not check out your code, Copilot will do this for you. + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup necessary dotnet SDKs + uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + dotnet-version: | + 9.x + 8.x diff --git a/.github/workflows/fsdocs-gh-pages.yml b/.github/workflows/fsdocs-gh-pages.yml new file mode 100644 index 0000000..0ebb9ec --- /dev/null +++ b/.github/workflows/fsdocs-gh-pages.yml @@ -0,0 +1,61 @@ +name: Deploy Docs + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Setup necessary dotnet SDKs + uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + dotnet-version: | + 9.x + + - name: Build Docs + run: | + chmod +x ./build.sh + ./build.sh builddocs + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: docs/ + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/publish_ci.yml b/.github/workflows/publish_ci.yml new file mode 100644 index 0000000..06e97e9 --- /dev/null +++ b/.github/workflows/publish_ci.yml @@ -0,0 +1,65 @@ +name: Publish to GitHub + +on: + push: + branches: + - main + +env: + CONFIGURATION: Release + +jobs: + build: + # Sets permissions of the GITHUB_TOKEN to allow release creating + permissions: + packages: write + environment: + name: nuget + runs-on: macos-26 + + steps: + - uses: actions/checkout@v4 + + - name: Setup necessary dotnet SDKs + uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + dotnet-version: | + 9.x + 8.x + + - name: Add the GitHub source + run: dotnet nuget add source --name "github.com" "https://nuget.pkg.github.com/fsprojects/index.json" + + - name: Ensure NuGet package source mapping + shell: pwsh + run: | + $nugetConfigPath = "$HOME/.nuget/NuGet/NuGet.Config" + [xml]$nugetConfig = Get-Content $nugetConfigPath + + $packageSourceMapping = $nugetConfig.configuration.packageSourceMapping + if ($packageSourceMapping -ne $null) { + $packageSourceMapping.RemoveAll() + } else { + $packageSourceMapping = $nugetConfig.CreateElement("packageSourceMapping") + $nugetConfig.configuration.AppendChild($packageSourceMapping) + } + + $nugetSource = $nugetConfig.CreateElement("packageSource") + $nugetSource.SetAttribute("key", "nuget.org") + $nugetPattern = $nugetConfig.CreateElement("package") + $nugetPattern.SetAttribute("pattern", "*") + $nugetSource.AppendChild($nugetPattern) + $packageSourceMapping.AppendChild($nugetSource) + + $nugetConfig.Save($nugetConfigPath) + + - name: Publish to GitHub + env: + NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FAKE_DETAILED_ERRORS: true + ENABLE_COVERAGE: false # AltCover doesn't work with Release builds, reports lower coverage than actual + run: | + chmod +x ./build.sh + ./build.sh "PublishToGitHub" diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml new file mode 100644 index 0000000..36d3b34 --- /dev/null +++ b/.github/workflows/publish_release.yml @@ -0,0 +1,36 @@ +name: Publish to NuGet + +on: + push: + tags: + - 'releases/*' + +env: + CONFIGURATION: Release +jobs: + build: + # Sets permissions of the GITHUB_TOKEN to allow release creating + permissions: + contents: write + environment: + name: nuget + runs-on: macos-26 + steps: + - uses: actions/checkout@v4 + - name: Setup necessary dotnet SDKs + uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + dotnet-version: | + 9.x + 8.x + + - name: Publish to NuGet + env: + NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FAKE_DETAILED_ERRORS: true + ENABLE_COVERAGE: false # AltCover doesn't work with Release builds, reports lower coverage than actual + run: | + chmod +x ./build.sh + ./build.sh Publish diff --git a/.gitignore b/.gitignore index 2dec2d9..0175fb0 100644 --- a/.gitignore +++ b/.gitignore @@ -152,6 +152,9 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user +# JustCode is a .NET coding add-in +.JustCode + # TeamCity is a build add-in _TeamCity* @@ -421,3 +424,12 @@ FodyWeavers.xsd *.msix *.msm *.msp + +# JetBrains Rider +*.sln.iml + +# fsdocs generated +tmp/ +temp/ +.fsdocs +docs/ diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 0000000..c618150 --- /dev/null +++ b/.mcp.json @@ -0,0 +1,12 @@ +{ + "servers": { + "Microsoft Docs": { + "type": "http", + "url": "https://learn.microsoft.com/api/mcp" + }, + "GitHub": { + "type": "http", + "url": "https://api.githubcopilot.com/mcp/" + } + } +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..d566ef1 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + "recommendations": [ + "ionide.ionide-paket", + "ionide.ionide-fsharp", + "ionide.ionide-fake", + "ms-dotnettools.csharp", + "editorConfig.editorConfig" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5388848 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "dotnet.defaultSolution": "Apple.CryptoKit.slnx", + "FSharp.fsacRuntime":"netcore", + "FSharp.enableAnalyzers": false, + "FSharp.analyzersPath": [ + "./packages/analyzers" + ] +} diff --git a/Apple.CryptoKit.slnf b/Apple.CryptoKit.slnf new file mode 100644 index 0000000..368652f --- /dev/null +++ b/Apple.CryptoKit.slnf @@ -0,0 +1,9 @@ +{ + "solution": { + "path": "Apple.CryptoKit.slnx", + "projects": [ + "src\\Apple.CryptoKit.csproj", + "tests\\Apple.CryptoKit.Tests.csproj" + ] + } +} \ No newline at end of file diff --git a/Apple.CryptoKit.slnx b/Apple.CryptoKit.slnx new file mode 100644 index 0000000..bf02d11 --- /dev/null +++ b/Apple.CryptoKit.slnx @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c9443b5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added +* Initial implementation of CGN like wrapper around KeychainStorage +* CI and CD infrastructure diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..286c18a --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,41 @@ + + + + + Apple;CryptoKit;CGN + https://github.com/Ecierge/Apple.CryptoKit + false + LICENSE + README.md + + + git + XperiAndri, alekseybailo, DrBrown777 + https://github.com/Ecierge/Apple.CryptoKit + + true + + true + snupkg + true + + + + Ecierge.$(MSBuildProjectName) + 13.0 + 9.0 + enable + true + false + + + + + + + + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..484ac5a --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,47 @@ + + + + + <_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/ + <_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json + <_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)-$(OS) + <_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild-$(NETCoreSdkVersion)-$(OS) + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..e9b9497 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..b9f6df4 --- /dev/null +++ b/build.cmd @@ -0,0 +1 @@ +dotnet run --project ./build/build.fsproj -- -t %* diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..0783d63 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@" diff --git a/build/Changelog.fs b/build/Changelog.fs new file mode 100644 index 0000000..27ceada --- /dev/null +++ b/build/Changelog.fs @@ -0,0 +1,233 @@ +module Changelog + +open System +open Fake.Core +open Fake.IO + +let isEmptyChange = + function + | Changelog.Change.Added s + | Changelog.Change.Changed s + | Changelog.Change.Deprecated s + | Changelog.Change.Fixed s + | Changelog.Change.Removed s + | Changelog.Change.Security s + | Changelog.Change.Custom (_, s) -> String.IsNullOrWhiteSpace s.CleanedText + +let tagFromVersionNumber versionNumber = sprintf "releases/%s" versionNumber + +let failOnEmptyChangelog (latestEntry : Changelog.ChangelogEntry) = + let isEmpty = + (latestEntry.Changes |> Seq.forall isEmptyChange) + || latestEntry.Changes |> Seq.isEmpty + + if isEmpty then + failwith "No changes in CHANGELOG. Please add your changes under a heading specified in https://keepachangelog.com/" + +let mkLinkReference (newVersion : SemVerInfo) (changelog : Changelog.Changelog) (gitHubRepoUrl : string) = + if changelog.Entries |> List.isEmpty then + // No actual changelog entries yet: link reference will just point to the Git tag + sprintf "[%s]: %s/releases/tag/%s" newVersion.AsString gitHubRepoUrl (tagFromVersionNumber newVersion.AsString) + else + let versionTuple version = (version.Major, version.Minor, version.Patch) + // Changelog entries come already sorted, most-recent first, by the Changelog module + let prevEntry = + changelog.Entries + |> List.skipWhile (fun entry -> + entry.SemVer.PreRelease.IsSome + || versionTuple entry.SemVer = versionTuple newVersion + ) + |> List.tryHead + + let linkTarget = + match prevEntry with + | Some entry -> + sprintf + "%s/compare/%s...%s" + gitHubRepoUrl + (tagFromVersionNumber entry.SemVer.AsString) + (tagFromVersionNumber newVersion.AsString) + | None -> sprintf "%s/releases/tag/%s" gitHubRepoUrl (tagFromVersionNumber newVersion.AsString) + + sprintf "[%s]: %s" newVersion.AsString linkTarget + +let mkReleaseNotes changelog (latestEntry : Changelog.ChangelogEntry) gitHubRepoUrl = + let linkReference = mkLinkReference latestEntry.SemVer changelog gitHubRepoUrl + + if String.isNullOrEmpty linkReference then + latestEntry.ToString () + else + // Add link reference target to description before building release notes, since in main changelog file it's at the bottom of the file + let description = + match latestEntry.Description with + | None -> linkReference + | Some desc when desc.Contains (linkReference) -> desc + | Some desc -> sprintf "%s\n\n%s" (desc.Trim ()) linkReference + + { latestEntry with Description = Some description }.ToString () + +let getVersionNumber envVarName ctx = + let args = ctx.Context.Arguments + + let verArg = + args + |> List.tryHead + |> Option.defaultWith (fun () -> Environment.environVarOrDefault envVarName "") + + if SemVer.isValid verArg then + verArg + elif verArg.StartsWith ("v") && SemVer.isValid verArg.[1..] then + let target = ctx.Context.FinalTarget + + Trace.traceImportantfn + "Please specify a version number without leading 'v' next time, e.g. \"./build.sh %s %s\" rather than \"./build.sh %s %s\"" + target + verArg.[1..] + target + verArg + + verArg.[1..] + elif String.isNullOrEmpty verArg then + let target = ctx.Context.FinalTarget + + Trace.traceErrorfn + "Please specify a version number, either at the command line (\"./build.sh %s 1.0.0\") or in the %s environment variable" + target + envVarName + + failwith "No version number found" + else + Trace.traceErrorfn "Please specify a valid version number: %A could not be recognized as a version number" verArg + + failwith "Invalid version number" + +let mutable changelogBackupFilename = "" + +let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gitHubRepoUrl ctx = + + let verStr = ctx |> getVersionNumber "RELEASE_VERSION" + + let description, unreleasedChanges = + match changelog.Unreleased with + | None -> None, [] + | Some u -> u.Description, u.Changes + + let newVersion = SemVer.parse verStr + + changelog.Entries + |> List.tryFind (fun entry -> entry.SemVer = newVersion) + |> Option.iter (fun entry -> + Trace.traceErrorfn + "Version %s already exists in %s, released on %s" + verStr + changelogPath + (if entry.Date.IsSome then + entry.Date.Value.ToString ("yyyy-MM-dd") + else + "(no date specified)") + + failwith "Can't release with a duplicate version number" + ) + + changelog.Entries + |> List.tryFind (fun entry -> entry.SemVer > newVersion) + |> Option.iter (fun entry -> + Trace.traceErrorfn + "You're trying to release version %s, but a later version %s already exists, released on %s" + verStr + entry.SemVer.AsString + (if entry.Date.IsSome then + entry.Date.Value.ToString ("yyyy-MM-dd") + else + "(no date specified)") + + failwith "Can't release with a version number older than an existing release" + ) + + let versionTuple version = (version.Major, version.Minor, version.Patch) + + let prereleaseEntries = + changelog.Entries + |> List.filter (fun entry -> + entry.SemVer.PreRelease.IsSome + && versionTuple entry.SemVer = versionTuple newVersion + ) + + let prereleaseChanges = + prereleaseEntries + |> List.collect (fun entry -> entry.Changes |> List.filter (not << isEmptyChange)) + |> List.distinct + + let assemblyVersion, nugetVersion = Changelog.parseVersions newVersion.AsString + + let newEntry = + Changelog.ChangelogEntry.New ( + assemblyVersion.Value, + nugetVersion.Value, + Some System.DateTime.Today, + description, + unreleasedChanges @ prereleaseChanges, + false + ) + + let newChangelog = + Changelog.Changelog.New (changelog.Header, changelog.Description, None, newEntry :: changelog.Entries) + + // Save changelog to temporary file before making any edits + changelogBackupFilename <- System.IO.Path.GetTempFileName () + + changelogPath |> Shell.copyFile changelogBackupFilename + + Target.activateFinal "DeleteChangelogBackupFile" + + newChangelog |> Changelog.save changelogPath + + // Now update the link references at the end of the file + let linkReferenceForLatestEntry = mkLinkReference newVersion changelog gitHubRepoUrl + + let linkReferenceForUnreleased = + sprintf "[Unreleased]: %s/compare/%s...%s" gitHubRepoUrl (tagFromVersionNumber newVersion.AsString) "HEAD" + + let tailLines = File.read changelogPath |> List.ofSeq |> List.rev + + let isRef (line : string) = + System.Text.RegularExpressions.Regex.IsMatch (line, @"^\[.+?\]:\s?[a-z]+://.*$") + + let linkReferenceTargets = + tailLines + |> List.skipWhile String.isNullOrWhiteSpace + |> List.takeWhile isRef + |> List.rev // Now most recent entry is at the head of the list + + let newLinkReferenceTargets = + match linkReferenceTargets with + | [] -> [ linkReferenceForUnreleased; linkReferenceForLatestEntry ] + | first :: rest when first |> String.startsWith "[Unreleased]:" -> + linkReferenceForUnreleased + :: linkReferenceForLatestEntry + :: rest + | first :: rest -> + linkReferenceForUnreleased + :: linkReferenceForLatestEntry + :: first + :: rest + + let blankLineCount = + tailLines + |> Seq.takeWhile String.isNullOrWhiteSpace + |> Seq.length + + let linkRefCount = linkReferenceTargets |> List.length + + let skipCount = blankLineCount + linkRefCount + + let updatedLines = + List.rev (tailLines |> List.skip skipCount) + @ newLinkReferenceTargets + + File.write false changelogPath updatedLines + + // If build fails after this point but before we commit changes, undo our modifications + Target.activateBuildFailure "RevertChangelog" + + newEntry diff --git a/build/FsDocs.fs b/build/FsDocs.fs new file mode 100644 index 0000000..8c16481 --- /dev/null +++ b/build/FsDocs.fs @@ -0,0 +1,224 @@ +namespace Fake.DotNet + +open Fake.Core +open Fake.IO +open Fake.IO.FileSystemOperators + +/// +/// Contains tasks to interact with fsdocs tool to +/// process F# script files, markdown and for generating API documentation. +/// +[] +module Fsdocs = + + /// + /// Fsdocs build command parameters and options + /// + type BuildCommandParams = { + /// Input directory of content (default: docs) + Input : string option + + /// Project files to build API docs for outputs, defaults to all packable projects + Projects : seq option + + /// Output Directory (default output for build and tmp/watch for watch) + Output : string option + + /// Disable generation of API docs + NoApiDocs : bool option + + /// Evaluate F# fragments in scripts + Eval : bool option + + /// Save images referenced in docs + SaveImages : bool option + + /// Add line numbers + LineNumbers : bool option + + /// Additional substitution parameters for templates + Parameters : seq option + + /// Disable project cracking. + IgnoreProjects : bool option + + /// In API doc generation qualify the output by the collection name, e.g. 'reference/FSharp.Core/...' instead of 'reference/...' . + Qualify : bool option + + /// The tool will also generate documentation for non-public members + NoPublic : bool option + + /// Do not copy default content styles, javascript or use default templates + NoDefaultContent : bool option + + /// Clean the output directory + Clean : bool option + + /// Display version information + Version : bool option + + /// Provide properties to dotnet msbuild, e.g. --properties Configuration=Release Version=3.4 + Properties : string option + + /// Additional arguments passed down as otherflags to the F# compiler when the API is being generated. + /// Note that these arguments are trimmed, this is to overcome a limitation in the command line argument + /// processing. A typical use-case would be to pass an addition assembly reference. + /// Example --fscoptions " -r:MyAssembly.dll" + FscOptions : string option + + /// Fail if docs are missing or can't be generated + Strict : bool option + + /// Source folder at time of component build (<FsDocsSourceFolder>) + SourceFolder : string option + + /// Source repository for github links (<FsDocsSourceRepository>) + SourceRepository : string option + + /// Assume comments in F# code are markdown (<UsesMarkdownComments>) + MdComments : bool option + } with + + /// Parameter default values. + static member Default = { + Input = None + Projects = None + Output = None + NoApiDocs = None + Eval = None + SaveImages = None + LineNumbers = None + Parameters = None + IgnoreProjects = None + Qualify = None + NoPublic = None + NoDefaultContent = None + Clean = None + Version = None + Properties = None + FscOptions = None + Strict = None + SourceFolder = None + SourceRepository = None + MdComments = None + } + + /// + /// Fsdocs watch command parameters and options + /// + type WatchCommandParams = { + /// Do not serve content when watching. + NoServer : bool option + + /// Do not launch a browser window. + NoLaunch : bool option + + /// URL extension to launch http://localhost:/%s. + Open : string option + + /// Port to serve content for http://localhost serving. + Port : int option + + /// Build Commands + BuildCommandParams : BuildCommandParams option + } with + + /// Parameter default values. + static member Default = { + NoServer = None + NoLaunch = None + Open = None + Port = None + BuildCommandParams = None + } + + let internal buildBuildCommandParams (buildParams : BuildCommandParams) = + let buildSubstitutionParameters (subParameters : seq) = + seq { + yield "--parameters" + for (key, value) in subParameters do + yield key + yield value + } + |> String.concat " " + + System.Text.StringBuilder () + |> StringBuilder.appendIfSome buildParams.Input (sprintf "--input %s") + |> StringBuilder.appendIfSome buildParams.Projects (fun projects -> $"""--projects %s{projects |> String.concat " "}""") + |> StringBuilder.appendIfSome buildParams.Output (sprintf "--output %s") + |> StringBuilder.appendIfSome buildParams.NoApiDocs (fun _ -> "--noapidocs") + |> StringBuilder.appendIfSome buildParams.Eval (fun _ -> "--eval") + |> StringBuilder.appendIfSome buildParams.SaveImages (fun _ -> "--saveimages") + |> StringBuilder.appendIfSome buildParams.LineNumbers (fun _ -> "--linenumbers") + |> StringBuilder.appendIfSome buildParams.Parameters (fun parameters -> buildSubstitutionParameters parameters) + |> StringBuilder.appendIfSome buildParams.IgnoreProjects (fun _ -> "--ignoreprojects") + |> StringBuilder.appendIfSome buildParams.Qualify (fun _ -> "--qualify") + |> StringBuilder.appendIfSome buildParams.NoPublic (fun _ -> "--nonpublic") + |> StringBuilder.appendIfSome buildParams.NoDefaultContent (fun _ -> "--nodefaultcontent") + |> StringBuilder.appendIfSome buildParams.Clean (fun _ -> "--clean") + |> StringBuilder.appendIfSome buildParams.Version (fun _ -> "--version") + |> StringBuilder.appendIfSome buildParams.Properties (sprintf "--properties %s") + |> StringBuilder.appendIfSome buildParams.FscOptions (sprintf "--fscoptions %s") + |> StringBuilder.appendIfSome buildParams.Strict (fun _ -> "--strict") + |> StringBuilder.appendIfSome buildParams.SourceFolder (sprintf "--sourcefolder %s") + |> StringBuilder.appendIfSome buildParams.SourceRepository (sprintf "--sourcerepo %s") + |> StringBuilder.appendIfSome buildParams.MdComments (fun _ -> "--mdcomments") + |> StringBuilder.toText + |> String.trim + + let internal buildWatchCommandParams (watchParams : WatchCommandParams) = + System.Text.StringBuilder () + |> StringBuilder.appendIfSome watchParams.NoServer (fun _ -> "--noserver") + |> StringBuilder.appendIfSome watchParams.NoLaunch (fun _ -> "--nolaunch") + |> StringBuilder.appendIfSome watchParams.Open (sprintf "--open %s") + |> StringBuilder.appendIfSome watchParams.Port (sprintf "--port %i") + |> StringBuilder.appendIfSome watchParams.BuildCommandParams buildBuildCommandParams + |> StringBuilder.toText + |> String.trim + + + let cleanCache (workingDirectory) = Shell.cleanDirs [ workingDirectory ".fsdocs" ] + + /// + /// Build documentation using fsdocs build command + /// + /// + /// Function used to overwrite the dotnetOptions. + /// Function used to overwrite the build command default parameters. + /// + /// + /// + /// Fsdocs.build (fun p -> { p with Clean = Some(true); Strict = Some(true) }) + /// + /// + let build dotnetOptions setBuildParams = + let buildParams = setBuildParams BuildCommandParams.Default + let formattedParameters = buildBuildCommandParams buildParams + + // let dotnetOptions = (fun (buildOptions: DotNet.Options) -> buildOptions) + let result = DotNet.exec dotnetOptions "fsdocs build" formattedParameters + + if 0 <> result.ExitCode then + failwithf "fsdocs build failed with exit code '%d'" result.ExitCode + + /// + /// Watch documentation using fsdocs watch command + /// + /// + /// Function used to overwrite the dotnetOptions. + /// Function used to overwrite the watch command default parameters. + /// + /// + /// + /// Fsdocs.watch (fun p -> { p with Port = Some(3005) }) + /// + /// + let watch dotnetOptions setWatchParams = + let watchParams = setWatchParams WatchCommandParams.Default + let formattedParameters = buildWatchCommandParams watchParams + + // let dotnetOptions = (fun (buildOptions: DotNet.Options) -> buildOptions) + let result = DotNet.exec dotnetOptions "fsdocs watch" formattedParameters + + if 0 <> result.ExitCode then + failwithf "fsdocs watch failed with exit code '%d'" result.ExitCode diff --git a/build/Properties/launchSettings.json b/build/Properties/launchSettings.json new file mode 100644 index 0000000..f0c59e8 --- /dev/null +++ b/build/Properties/launchSettings.json @@ -0,0 +1,24 @@ +{ + "profiles": { + "BuildAndTest": { + "commandName": "Project", + "commandLineArgs": "--target DotnetTest" + }, + "Publish": { + "commandName": "Project", + "commandLineArgs": "--target Publish" + }, + "PublishToGitHub": { + "commandName": "Project", + "commandLineArgs": "--target PublishToGitHub" + }, + "BuildDocs": { + "commandName": "Project", + "commandLineArgs": "--target BuildDocs" + }, + "Release": { + "commandName": "Project", + "commandLineArgs": "--target Release 1.0.0" + } + } +} diff --git a/build/build.fs b/build/build.fs new file mode 100644 index 0000000..c59b898 --- /dev/null +++ b/build/build.fs @@ -0,0 +1,742 @@ +open System +open Fake.Core +open Fake.DotNet +open Fake.Tools +open Fake.IO +open Fake.IO.FileSystemOperators +open Fake.IO.Globbing.Operators +open Fake.Core.TargetOperators +open Fake.Api +open Fake.BuildServer +open Argu + +let environVarAsBoolOrDefault varName defaultValue = + let truthyConsts = [ "1"; "Y"; "YES"; "T"; "TRUE" ] + Environment.environVar varName + |> ValueOption.ofObj + |> ValueOption.map (fun envvar -> + truthyConsts + |> List.exists (fun ``const`` -> String.Equals (``const``, envvar, StringComparison.InvariantCultureIgnoreCase)) + ) + |> ValueOption.defaultValue defaultValue + +//----------------------------------------------------------------------------- +// Metadata and Configuration +//----------------------------------------------------------------------------- + +let rootDirectory = __SOURCE_DIRECTORY__ ".." + +let productName = "Apple.CryptoKit" + +let sln = rootDirectory "Apple.CryptoKit.slnf" + +let srcCodeGlob = + !!(rootDirectory "src/**/*.fs") + ++ (rootDirectory "src/**/*.fsx") + -- (rootDirectory "src/**/obj/**/*.fs") + +let testsCodeGlob = + !!(rootDirectory "tests/**/*.fs") + ++ (rootDirectory "tests/**/*.fsx") + -- (rootDirectory "tests/**/obj/**/*.fs") + +let srcGlob = rootDirectory "src/**/*.??proj" + +let testsGlob = rootDirectory "tests/**/*.??proj" + +let srcAndTest = !!srcGlob ++ testsGlob + +let distDir = rootDirectory "dist" + +let distGlob = distDir "*.nupkg" + +let testResultsDir = rootDirectory "TestResults" + +let coverageReportDir = rootDirectory "docs" "coverage" + +let docsDir = rootDirectory "docs" + +let docsSrcDir = rootDirectory "docsSrc" + +let temp = rootDirectory "temp" + +let watchDocsDir = temp "watch-docs" + +let gitOwner = "Ecierge" +let gitRepoName = "Apple.CryptoKit" + +let gitHubRepoUrl = $"https://github.com/%s{gitOwner}/%s{gitRepoName}" + +let documentationRootUrl = $"https://%s{gitOwner}.github.io/%s{gitRepoName}" + +let releaseBranch = "main" +let readme = "README.md" +let changelogFile = "CHANGELOG.md" + +let READMElink = Uri (Uri (gitHubRepoUrl), $"blob/{releaseBranch}/{readme}") +let CHANGELOGlink = Uri (Uri (gitHubRepoUrl), $"blob/{releaseBranch}/{changelogFile}") + +let changelogPath = rootDirectory changelogFile + +let changelog = Fake.Core.Changelog.load changelogPath + +let mutable latestEntry = + if Seq.isEmpty changelog.Entries then + Changelog.ChangelogEntry.New ("0.0.1", "0.0.1-alpha.1", Some DateTime.Today, None, [], false) + else + changelog.LatestEntry + +let mutable changelogBackupFilename = "" + +let publishUrl = "https://www.nuget.org" + +let enableCodeCoverage = environVarAsBoolOrDefault "ENABLE_COVERAGE" false + +let githubToken = Environment.environVarOrNone "GITHUB_TOKEN" + +let nugetToken = Environment.environVarOrNone "NUGET_TOKEN" + +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- + + +let isRelease (targets : Target list) = + targets + |> Seq.map (fun t -> t.Name) + |> Seq.exists ((=) "PublishToNuGet") + +let invokeAsync f = async { f () } + +let configuration (targets : Target list) = + let defaultVal = if isRelease targets then "Release" else "Debug" + + match Environment.environVarOrDefault "CONFIGURATION" defaultVal with + | "Debug" -> DotNet.BuildConfiguration.Debug + | "Release" -> DotNet.BuildConfiguration.Release + | config -> DotNet.BuildConfiguration.Custom config + +let failOnBadExitAndPrint (p : ProcessResult) = + if p.ExitCode <> 0 then + p.Errors |> Seq.iter Trace.traceError + + failwithf "failed with exitcode %d" p.ExitCode + +let isPublishToGitHub ctx = ctx.Context.FinalTarget = "PublishToGitHub" + +let isCI = lazy environVarAsBoolOrDefault "CI" false + +// CI Servers can have bizarre failures that have nothing to do with your code +let rec retryIfInCI times fn = + match isCI.Value with + | true -> + if times > 1 then + try + fn () + with _ -> + retryIfInCI (times - 1) fn + else + fn () + | _ -> fn () + +let failOnWrongBranch () = + if Git.Information.getBranchName "" <> releaseBranch then + failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch + + +module dotnet = + let watch cmdParam program args = DotNet.exec cmdParam $"watch %s{program}" args + + let run cmdParam args = DotNet.exec cmdParam "run" args + + let tool optionConfig (command : string) args = + DotNet.exec optionConfig command args + |> failOnBadExitAndPrint + + let reportgenerator optionConfig args = tool optionConfig "reportgenerator" args + + let sourcelink optionConfig args = tool optionConfig "sourcelink" args + + let fcswatch optionConfig args = tool optionConfig "fcswatch" args + + let fsharpAnalyzer optionConfig args = tool optionConfig "fsharp-analyzers" args + + let fantomas args = DotNet.exec id "fantomas" args + +module FSharpAnalyzers = + type Arguments = + | Project of string + | Analyzers_Path of string + | Fail_On_Warnings of string list + | Ignore_Files of string list + | Verbose + + interface IArgParserTemplate with + member s.Usage = "" + + +module DocsTool = + let quoted s = $"\"%s{s}\"" + + let fsDocsDotnetOptions (o : DotNet.Options) = { o with WorkingDirectory = rootDirectory } + + let fsDocsBuildParams configuration (p : Fsdocs.BuildCommandParams) = { + p with + Clean = Some true + Input = Some (quoted docsSrcDir) + Output = Some (quoted docsDir) + Eval = Some true + Projects = Some (Seq.map quoted (!!srcGlob)) + Properties = Some ($"Configuration=%s{configuration}") + Parameters = + Some [ + // https://fsprojects.github.io/FSharp.Formatting/content.html#Templates-and-Substitutions + "root", quoted $"{documentationRootUrl}/" + "fsdocs-collection-name", quoted productName + "fsdocs-repository-branch", quoted releaseBranch + "fsdocs-package-version", quoted latestEntry.NuGetVersion + "fsdocs-readme-link", quoted (READMElink.ToString ()) + "fsdocs-release-notes-link", quoted (CHANGELOGlink.ToString ()) + "fsdocs-logo-src", + quoted ( + "https://raw.githubusercontent.com/fsprojects/FSharp.Azure.Cosmos/refs/heads/main/docsSrc/content/logo.png" + ) + ] + Strict = Some true + } + + let cleanDocsCache () = Fsdocs.cleanCache rootDirectory + + let build (configuration) = Fsdocs.build fsDocsDotnetOptions (fsDocsBuildParams configuration) + + + let watch (configuration) = + let buildParams bp = + let bp = + Option.defaultValue Fsdocs.BuildCommandParams.Default bp + |> fsDocsBuildParams configuration + + { bp with Output = Some watchDocsDir; Strict = None } + + Fsdocs.watch fsDocsDotnetOptions (fun p -> { p with BuildCommandParams = Some (buildParams p.BuildCommandParams) }) + +let allReleaseChecks () = failOnWrongBranch () +//Changelog.failOnEmptyChangelog latestEntry + + +let failOnLocalBuild () = + if not isCI.Value then + failwith "Not on CI. If you want to publish, please use CI." + +let failOnCIBuild () = + if isCI.Value then + failwith "On CI. If you want to run this target, please use a local build." + +let allPublishChecks () = failOnLocalBuild () +//Changelog.failOnEmptyChangelog latestEntry + +//----------------------------------------------------------------------------- +// Target Implementations +//----------------------------------------------------------------------------- + +/// So we don't require always being on the latest MSBuild.StructuredLogger +let disableBinLog (p : MSBuild.CliArguments) = { p with DisableInternalBinLog = true } + +let clean _ = + [ "bin"; "temp"; distDir; coverageReportDir; testResultsDir ] + |> Shell.cleanDirs + + !!srcGlob ++ testsGlob + |> Seq.collect (fun p -> + [ "bin"; "obj" ] + |> Seq.map (fun sp -> IO.Path.GetDirectoryName p sp) + ) + |> Shell.cleanDirs + +let dotnetRestore _ = + [ sln ] + |> Seq.map (fun dir -> + fun () -> + let args = [] |> String.concat " " + + DotNet.restore + (fun c -> { + c with + MSBuildParams = disableBinLog c.MSBuildParams + Common = c.Common |> DotNet.Options.withCustomParams (Some (args)) + }) + dir + ) + |> Seq.iter (retryIfInCI 10) + +let dotnetToolRestore _ = + let result = + fun () -> DotNet.exec id "tool" "restore" + |> (retryIfInCI 10) + + + if not result.OK then + failwithf "Failed to restore .NET tools: %A" result.Errors + +let dotnetWorkloadRestore _ = + let result = + fun () -> DotNet.exec id "workload" "restore" + |> (retryIfInCI 10) + + if not result.OK then + failwithf "Failed to restore .NET workloads: %A" result.Errors + +let updateChangelog ctx = + latestEntry <- + if not <| isPublishToGitHub ctx then + Changelog.updateChangelog changelogPath changelog gitHubRepoUrl ctx + elif Seq.isEmpty changelog.Entries then + latestEntry + else + let latest = changelog.LatestEntry + let semVer = { + latest.SemVer with + Original = None + Patch = latest.SemVer.Patch + 1u + PreRelease = PreRelease.TryParse "ci" + } + { + latest with + SemVer = semVer + NuGetVersion = semVer.AsString + AssemblyVersion = semVer.AsString + } + +let revertChangelog _ = + if String.isNotNullOrEmpty Changelog.changelogBackupFilename then + Changelog.changelogBackupFilename + |> Shell.copyFile changelogPath + +let deleteChangelogBackupFile _ = + if String.isNotNullOrEmpty Changelog.changelogBackupFilename then + Shell.rm Changelog.changelogBackupFilename + +let getPackageVersionProperty publishToGitHub = + if publishToGitHub then + let runId = Environment.environVar "GITHUB_RUN_ID" + $"/p:PackageVersion=%s{latestEntry.NuGetVersion}-%s{runId}" + else + $"/p:PackageVersion=%s{latestEntry.NuGetVersion}" + +let dotnetBuild ctx = + + let publishToGitHub = isPublishToGitHub ctx + + let args = [ getPackageVersionProperty publishToGitHub; "--no-restore" ] + + DotNet.build + (fun c -> { + c with + Configuration = configuration (ctx.Context.AllExecutingTargets) + Common = c.Common |> DotNet.Options.withAdditionalArgs args + MSBuildParams = { + (disableBinLog c.MSBuildParams) with + Properties = [ + if publishToGitHub then + ("DebugType", "embedded") + ("EmbedAllSources", "true") + ] + } + }) + sln + +let fsharpAnalyzers _ = + let argParser = ArgumentParser.Create (programName = "fsharp-analyzers") + + !!srcGlob + |> Seq.iter (fun proj -> + let args = + [ + FSharpAnalyzers.Analyzers_Path (rootDirectory "packages/analyzers") + FSharpAnalyzers.Arguments.Project proj + FSharpAnalyzers.Arguments.Fail_On_Warnings [ "BDH0002" ] + FSharpAnalyzers.Arguments.Ignore_Files [ "*AssemblyInfo.fs" ] + FSharpAnalyzers.Verbose + ] + |> argParser.PrintCommandLineArgumentsFlat + + dotnet.fsharpAnalyzer id args + ) + +let dotnetTest ctx = + // Create test results directory if it doesn't exist + Directory.create testResultsDir + + let args = [ + "--no-build" + if enableCodeCoverage then + "--collect:\"Code Coverage\"" + "--results-directory" + testResultsDir + "--logger:trx" // Enable TRX report generation + ] + + DotNet.test + (fun c -> { + c with + MSBuildParams = disableBinLog c.MSBuildParams + Configuration = configuration (ctx.Context.AllExecutingTargets) + Common = c.Common |> DotNet.Options.withAdditionalArgs args + }) + sln + +let generateCoverageReport _ = + + let coverageFiles = !!(testResultsDir "*/coverage.cobertura.xml") + + let sourceDirs = !!srcGlob |> Seq.map Path.getDirectory |> String.concat ";" + + let independentArgs = [ + sprintf "-reports:\"%s\"" (coverageFiles |> String.concat ";") + sprintf "-targetdir:\"%s\"" coverageReportDir + // Add source dir + sprintf "-sourcedirs:\"%s\"" sourceDirs + // Ignore test assemblies + sprintf "-assemblyfilters:\"%s\"" "-*.Tests" + // Generate HTML and Cobertura reports + sprintf "-reporttypes:%s" "Html;Cobertura" + ] + + let args = independentArgs |> String.concat " " + + dotnet.reportgenerator id args + +let showCoverageReport _ = + failOnCIBuild () + + coverageReportDir "index.html" + |> Command.ShellCommand + |> CreateProcess.fromCommand + |> Proc.start + |> ignore + + +let watchTests _ = + !!testsGlob + |> Seq.map (fun proj -> + fun () -> + dotnet.watch + (fun opt -> + opt + |> DotNet.Options.withWorkingDirectory (IO.Path.GetDirectoryName proj) + ) + "test" + "" + |> ignore + ) + |> Seq.iter (invokeAsync >> Async.Catch >> Async.Ignore >> Async.Start) + + printfn "Press Ctrl+C (or Ctrl+Break) to stop..." + + let cancelEvent = + Console.CancelKeyPress + |> Async.AwaitEvent + |> Async.RunSynchronously + + cancelEvent.Cancel <- true + +let generateAssemblyInfo _ = + + let (|Fsproj|Csproj|Vbproj|) (projFileName : string) = + match projFileName with + | f when f.EndsWith ("fsproj") -> Fsproj + | f when f.EndsWith ("csproj") -> Csproj + | f when f.EndsWith ("vbproj") -> Vbproj + | _ -> failwithf "Project file %s not supported. Unknown project type." projFileName + + let releaseChannel = + match latestEntry.SemVer.PreRelease with + | Some pr -> pr.Name + | _ -> "release" + + let getAssemblyInfoAttributes projectName = [ + AssemblyInfo.Title (projectName) + AssemblyInfo.Product productName + AssemblyInfo.Version latestEntry.AssemblyVersion + AssemblyInfo.Metadata ("ReleaseDate", latestEntry.Date.Value.ToString ("o")) + AssemblyInfo.FileVersion latestEntry.AssemblyVersion + AssemblyInfo.InformationalVersion latestEntry.AssemblyVersion + AssemblyInfo.Metadata ("ReleaseChannel", releaseChannel) + AssemblyInfo.Metadata ("GitHash", Git.Information.getCurrentSHA1 (null)) + ] + + let getProjectDetails (projectPath : string) = + let projectName = IO.Path.GetFileNameWithoutExtension (projectPath) + + (projectPath, projectName, IO.Path.GetDirectoryName (projectPath), (getAssemblyInfoAttributes projectName)) + + !!srcGlob + |> Seq.map getProjectDetails + |> Seq.iter (fun (projFileName, _, folderName, attributes) -> + match projFileName with + | Fsproj -> AssemblyInfoFile.createFSharp (folderName "AssemblyInfo.fs") attributes + | Csproj -> AssemblyInfoFile.createCSharp ((folderName "Properties") "AssemblyInfo.cs") attributes + | Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName "My Project") "AssemblyInfo.vb") attributes + ) + +let dotnetPack ctx = + // Get release notes with properly-linked version number + let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl + + let args = [ getPackageVersionProperty (isPublishToGitHub ctx); $"/p:PackageReleaseNotes=\"{releaseNotes}\"" ] + + DotNet.pack + (fun c -> { + c with + MSBuildParams = disableBinLog c.MSBuildParams + Configuration = configuration (ctx.Context.AllExecutingTargets) + OutputPath = Some distDir + Common = c.Common |> DotNet.Options.withAdditionalArgs args + }) + sln + +let sourceLinkTest _ = + !!distGlob + |> Seq.iter (fun nupkg -> dotnet.sourcelink id $"test %s{nupkg}") + +type PushSource = + | NuGet + | GitHub + +let publishTo (source : PushSource) _ = + allPublishChecks () + + distGlob + |> DotNet.nugetPush (fun o -> { + o with + Common = { + o.Common with + WorkingDirectory = "dist" + CustomParams = Some "--skip-duplicate" + } + PushParams = { + o.PushParams with + // TODO: Uncomment when migrated to F# 9 + //NoSymbols = source.IsGitHub + Source = + match source with + | NuGet -> Some "nuget.org" + | GitHub -> Some "github.com" + ApiKey = + match source with + | NuGet -> nugetToken + | GitHub -> githubToken + } + }) + +let gitRelease _ = + allReleaseChecks () + + let releaseNotesGitCommitFormat = latestEntry.ToString () + + Git.Staging.stageFile "" (rootDirectory "CHANGELOG.md") + |> ignore + + !!(rootDirectory "src/**/AssemblyInfo.fs") + ++ (rootDirectory "tests/**/AssemblyInfo.fs") + |> Seq.iter (Git.Staging.stageFile "" >> ignore) + + let msg = $"release: bump version to `%s{latestEntry.NuGetVersion}`\n\n%s{releaseNotesGitCommitFormat}" + + Git.Commit.exec "" msg + + Target.deactivateBuildFailure "RevertChangelog" + + Git.Branches.push "" + + let tag = Changelog.tagFromVersionNumber latestEntry.NuGetVersion + + Git.Branches.tag "" tag + Git.Branches.pushTag "" "origin" tag + +let githubRelease _ = + allPublishChecks () + + let token = + match githubToken with + | Some s -> s + | _ -> failwith "please set the `GITHUB_TOKEN` environment variable to a github personal access token with repo access." + + let files = !!distGlob + // Get release notes with properly-linked version number + let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl + + GitHub.createClientWithToken token + |> GitHub.draftNewRelease + gitOwner + gitRepoName + (Changelog.tagFromVersionNumber latestEntry.NuGetVersion) + (latestEntry.SemVer.PreRelease <> None) + (releaseNotes |> Seq.singleton) + |> GitHub.uploadFiles files + |> GitHub.publishDraft + |> Async.RunSynchronously + +let formatCode _ = + let result = dotnet.fantomas $"{rootDirectory}" + + if not result.OK then + printfn "Errors while formatting all files: %A" result.Messages + +let checkFormatCode ctx = + let result = dotnet.fantomas $"{rootDirectory} --check" + + if result.ExitCode = 0 then + Trace.log "No files need formatting" + elif result.ExitCode = 99 then + failwith "Some files need formatting, check output for more info" + else + Trace.logf "Errors while formatting: %A" result.Errors + + +let cleanDocsCache _ = DocsTool.cleanDocsCache () + +let buildDocs ctx = + let configuration = configuration (ctx.Context.AllExecutingTargets) + DocsTool.build (string configuration) + +let watchDocs ctx = + let configuration = configuration (ctx.Context.AllExecutingTargets) + DocsTool.watch (string configuration) + + +let initTargets (ctx : Context.FakeExecutionContext) = + BuildServer.install [ GitHubActions.Installer ] + + let isPublishToGitHub = + ctx.Arguments + |> Seq.pairwise + |> Seq.exists (fun (arg, value) -> + (String.Equals (arg, "-t", StringComparison.OrdinalIgnoreCase) + || String.Equals (arg, "--target", StringComparison.OrdinalIgnoreCase)) + && String.Equals (value, "PublishToGitHub", StringComparison.OrdinalIgnoreCase) + ) + + /// Defines a dependency - y is dependent on x. Finishes the chain. + let (==>!) x y = x ==> y |> ignore + + /// Defines a soft dependency. x must run before y, if it is present, but y does not require x to be run. Finishes the chain. + let (?=>!) x y = x ?=> y |> ignore + //----------------------------------------------------------------------------- + // Hide Secrets in Logger + //----------------------------------------------------------------------------- + Option.iter (TraceSecrets.register "") githubToken + Option.iter (TraceSecrets.register "") nugetToken + //----------------------------------------------------------------------------- + // Target Declaration + //----------------------------------------------------------------------------- + + Target.create "Clean" clean + Target.create "DotnetRestore" dotnetRestore + Target.create "DotnetToolRestore" dotnetToolRestore + Target.create "DotnetWorkloadRestore" dotnetWorkloadRestore + Target.create "UpdateChangelog" updateChangelog + Target.createBuildFailure "RevertChangelog" revertChangelog // Do NOT put this in the dependency chain + Target.createFinal "DeleteChangelogBackupFile" deleteChangelogBackupFile // Do NOT put this in the dependency chain + Target.create "DotnetBuild" dotnetBuild + Target.create "FSharpAnalyzers" fsharpAnalyzers + Target.create "DotnetTest" dotnetTest + Target.create "GenerateCoverageReport" generateCoverageReport + Target.create "ShowCoverageReport" showCoverageReport + Target.create "WatchTests" watchTests + Target.create "GenerateAssemblyInfo" generateAssemblyInfo + Target.create "DotnetPack" dotnetPack + Target.create "SourceLinkTest" sourceLinkTest + Target.create "PublishToNuGet" (publishTo NuGet) + Target.create "PublishToGitHub" (publishTo GitHub) + Target.create "GitRelease" gitRelease + Target.create "GitHubRelease" githubRelease + Target.create "FormatCode" formatCode + Target.create "CheckFormatCode" checkFormatCode + Target.create "Release" ignore // For local + Target.create "Publish" ignore //For CI + Target.create "CleanDocsCache" cleanDocsCache + Target.create "BuildDocs" buildDocs + Target.create "WatchDocs" watchDocs + + //----------------------------------------------------------------------------- + // Target Dependencies + //----------------------------------------------------------------------------- + + + // Only call Clean if DotnetPack was in the call chain + // Ensure Clean is called before DotnetRestore + "Clean" ?=>! "DotnetRestore" + + "Clean" ==>! "DotnetPack" + + // Only call GenerateAssemblyInfo if GitRelease was in the call chain + // Ensure GenerateAssemblyInfo is called after DotnetRestore and before DotnetBuild + "DotnetRestore" ?=>! "GenerateAssemblyInfo" + + "GenerateAssemblyInfo" ?=>! "DotnetBuild" + + // Ensure UpdateChangelog is called after DotnetRestore + "DotnetRestore" ?=>! "UpdateChangelog" + + "UpdateChangelog" ?=>! "GenerateAssemblyInfo" + + "CleanDocsCache" ==>! "BuildDocs" + + "DotnetBuild" ?=>! "BuildDocs" + + "DotnetBuild" ==>! "BuildDocs" + + "DotnetBuild" ==>! "WatchDocs" + + "DotnetTest" ==> "GenerateCoverageReport" + ==>! "ShowCoverageReport" + + "UpdateChangelog" + ==> "GenerateAssemblyInfo" + ==> "GitRelease" + ==>! "Release" + + "DotnetWorkloadRestore" ==>! "DotnetRestore" + + "DotnetWorkloadRestore" =?> ("CheckFormatCode", isCI.Value) + ==> "DotnetRestore" + ==> "DotnetBuild" + ==> "DotnetTest" + ==> "DotnetPack" + ==> "PublishToNuGet" + ==> "GitHubRelease" + ==>! "Publish" + + "DotnetWorkloadRestore" + =?> ("CheckFormatCode", isCI.Value) + =?> ("GenerateAssemblyInfo", isPublishToGitHub) + ==> "DotnetRestore" + ==> "DotnetBuild" + ==> "DotnetTest" + ==> "DotnetPack" + ==>! "PublishToGitHub" + + "DotnetRestore" ==>! "WatchTests" + + //"DotnetToolRestore" ?=>! "DotnetRestore" + "DotnetToolRestore" ==>! "BuildDocs" + "DotnetToolRestore" ?=>! "CheckFormatCode" + "DotnetToolRestore" ?=>! "FormatCode" + +//----------------------------------------------------------------------------- +// Target Start +//----------------------------------------------------------------------------- +[] +let main argv = + + let ctx = + argv + |> Array.toList + |> Context.FakeExecutionContext.Create false "build.fsx" + + Context.setExecutionContext (Context.RuntimeContext.Fake ctx) + initTargets ctx + Target.runOrDefaultWithArguments "DotnetPack" + + 0 // return an integer exit code diff --git a/build/build.fsproj b/build/build.fsproj new file mode 100644 index 0000000..6bf8ba5 --- /dev/null +++ b/build/build.fsproj @@ -0,0 +1,40 @@ + + + Exe + net9.0 + 3390;$(WarnOn) + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docsSrc/Explanations/Background.md b/docsSrc/Explanations/Background.md new file mode 100644 index 0000000..269579b --- /dev/null +++ b/docsSrc/Explanations/Background.md @@ -0,0 +1,69 @@ +--- +title: Background +category: Explanations +categoryindex: 3 +index: 1 +--- + +# Background + +## Cosmos DB and F# Integration + +Azure Cosmos DB is Microsoft's globally distributed, multi-model database service. While the .NET SDK provides excellent functionality, using it directly from F# can lead to code that doesn't feel idiomatic to the language. +Also `RequestOptions` pattern is not the best option is Cosmos DB operation features discoverability, where F# computation expressions shine and simplify operation definitions. + +FSharp.Azure.Cosmos addresses this by providing F#-first abstractions over the Cosmos DB SDK, focusing on: + +1. **Type-Safe Responses**: Using discriminated unions to handle response status codes as values instead of exceptions +2. **F# Computation Expressions**: Natural syntax for database operations like read, write, update, and delete +3. **Resource Management**: Better control over database resources through F# idioms + +## Response Handling + +Traditional .NET exception handling can be verbose and error-prone: +``` F# +try + let! response = container.CreateItemAsync(item) + // Handle success +with +| :? CosmosException as ex when ex.StatusCode = HttpStatusCode.Conflict -> + // Handle conflict +| :? CosmosException as ex when ex.StatusCode = HttpStatusCode.TooManyRequests -> + // Handle rate limiting +``` +FSharp.Azure.Cosmos transforms this into a more F#-like pattern: +``` F# +let! response = container.ExecuteAsync operation +match response with +| Created item -> // Handle success +| Conflict -> // Handle conflict +| TooManyRequests -> // Handle rate limiting +``` +## Computation Expressions + +The library provides computation expressions for all major operations: +``` F# +let createOperation = create { + item person + partitionKey person.TenantId + consistencyLevel ConsistencyLevel.Eventual + preTrigger "preTrigger" + postTrigger "postTrigger" +} +``` +This approach: +- Simplifies request options definition +- Allows to define an operation template and reuse it + +## Query Extensions + +Modern applications often need to handle large result sets efficiently. The library provides extensions for working with `FeedIterator` and `IQueryable` results using `TaskSeq`-based iteration +``` F# +let! people = + container + .GetItemLinqQueryable() + .Where(fun p -> p.Name = name && p.TenantId = tenantId) + |> CancellableTaskSeq.ofAsyncEnumerable cancellationToken + |> TaskSeq.toListAsync +``` +This approach ensures efficient query execution and resource management in F# while maintaining idiomatic practices. diff --git a/docsSrc/How_Tos/Doing_A_Thing.md b/docsSrc/How_Tos/Doing_A_Thing.md new file mode 100644 index 0000000..071e5c1 --- /dev/null +++ b/docsSrc/How_Tos/Doing_A_Thing.md @@ -0,0 +1,14 @@ +--- +title: How To do a first thing +category: How To Guides +categoryindex: 2 +index: 1 +--- + +# How To do a first thing + +The best way to use IObservable is to use one .Subscribe()-method which will take function parameters (which will be "injected" to the right place). + +Use Rx (or R3) when you need async events to communicate with each other, e.g.: +- Events, WebServices, Threads, Timers, AutoComplete, Drag & Drop, ... + diff --git a/docsSrc/How_Tos/Doing_Another_Thing.md b/docsSrc/How_Tos/Doing_Another_Thing.md new file mode 100644 index 0000000..03064b3 --- /dev/null +++ b/docsSrc/How_Tos/Doing_Another_Thing.md @@ -0,0 +1,9 @@ +--- +title: How To do a second thing +category: How To Guides +categoryindex: 2 +index: 2 +--- + +# How To do a second thing + diff --git a/docsSrc/Tutorials/Getting_Started.md b/docsSrc/Tutorials/Getting_Started.md new file mode 100644 index 0000000..0478a68 --- /dev/null +++ b/docsSrc/Tutorials/Getting_Started.md @@ -0,0 +1,68 @@ +--- +title: Getting Started +category: Tutorials +categoryindex: 1 +index: 1 +--- + +# Getting Started + +## Installation + +First, add the NuGet package to your project: +``` +dotnet add package FSharp.Azure.Cosmos +``` +## Basic Setup + +Here's a minimal example to get started: +``` F# +open Microsoft.Azure.Cosmos +open FSharp.Azure.Cosmos +``` + +``` F# +// Create the client +let client = CosmosClient(connectionString = "your_connection_string") + +// Get database and container +let database = client.GetDatabase("your_database") +let container = database.GetContainer("your_container") + +// Define a simple record type +type Person = { + TenantId : string + Id: string + Name: string + Age: int +} + +// Create an item using computation expression +let createPerson = task { + let person = { TenantId = "Customer1"; Id = "1"; Name = "John"; Age = 30 } + let operation = create { + item person + partitionKey person.TenantId + } + match! container.ExecuteAsync operation with + | Created item -> printfn "Created: %A" item + | Conflict -> printfn "Item already exists" + | _ -> () +} + +// Query items using TaskSeq +let queryPeople = task { + let query = QueryDefinition "SELECT * FROM c WHERE c.age > 25" + let! results = + container.GetItemQueryIterator(query) + |> TaskSeq.ofFeedIterator + |> TaskSeq.toArrayAsync + + printfn "Found people: %A" results +} +``` +## Next Steps + +- Check out the [How-To Guides](../How_Tos/Doing_A_Thing.html) for common scenarios +- Read the [Background](../Explanations/Background.html) for deeper understanding +- Browse the [API Reference](../reference/index.html) for detailed documentation diff --git a/docsSrc/_menu-item_template.html b/docsSrc/_menu-item_template.html new file mode 100644 index 0000000..dc1b656 --- /dev/null +++ b/docsSrc/_menu-item_template.html @@ -0,0 +1 @@ +
  • {{fsdocs-menu-item-content}}
  • \ No newline at end of file diff --git a/docsSrc/_menu_template.html b/docsSrc/_menu_template.html new file mode 100644 index 0000000..066716c --- /dev/null +++ b/docsSrc/_menu_template.html @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/docsSrc/_template.html b/docsSrc/_template.html new file mode 100644 index 0000000..2e69546 --- /dev/null +++ b/docsSrc/_template.html @@ -0,0 +1,166 @@ + + + + + + {{fsdocs-page-title}} + + + + + + + + + + + + + + + + {{fsdocs-watch-script}} + + + + + + +
    + {{fsdocs-content}} + {{fsdocs-tooltips}} +
    + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docsSrc/content/fsdocs-custom.css b/docsSrc/content/fsdocs-custom.css new file mode 100644 index 0000000..62b2801 --- /dev/null +++ b/docsSrc/content/fsdocs-custom.css @@ -0,0 +1,15 @@ +.fsharp-icon-logo { + width: 25px; + margin-top: -2px; + -webkit-filter: grayscale(100%) brightness(1) invert(1); /* Safari 6.0 - 9.0 */ + filter: grayscale(100%) brightness(1) invert(1); +} + + +body .navbar .dropdown-menu .active .bi { + display: block !important; +} + +nav.navbar .dropdown-item img.fsharp-icon-logo { + margin-right: 0px; +} diff --git a/docsSrc/content/fsdocs-dark.css b/docsSrc/content/fsdocs-dark.css new file mode 100644 index 0000000..001b653 --- /dev/null +++ b/docsSrc/content/fsdocs-dark.css @@ -0,0 +1,50 @@ +@import url('https://raw.githubusercontent.com/tonsky/FiraCode/fixed/distr/fira_code.css'); +@import url('https://fonts.googleapis.com/css2?family=Hind+Vadodara&family=Roboto+Mono&display=swap'); +/*-------------------------------------------------------------------------- + Formatting for page & standard document content +/*--------------------------------------------------------------------------*/ + +:root { + --fsdocs-text-color:#d1d1d1; + --fsdocs-pre-border-color: #000000; + --fsdocs-pre-border-color-top: #070707; + --fsdocs-pre-background-color: #1E1E1E; + --fsdocs-pre-color: #e2e2e2; + --fsdocs-table-pre-background-color: #1d1d1d; + --fsdocs-table-pre-color: #c9c9c9; + + --fsdocs-code-strings-color: #ea9a75; + --fsdocs-code-printf-color: #E0C57F; + --fsdocs-code-escaped-color: #EA8675; + --fsdocs-code-identifiers-color: var(--fsdocs-text-color); + --fsdocs-code-module-color: #43AEC6; + --fsdocs-code-reference-color: #6a8dd8; + --fsdocs-code-value-color: #43AEC6; + --fsdocs-code-interface-color: #43AEC6; + --fsdocs-code-typearg-color: #43AEC6; + --fsdocs-code-disposable-color: #2f798a; + --fsdocs-code-property-color: #43AEC6; + --fsdocs-code-punctuation-color: #43AEC6; + --fsdocs-code-punctuation2-color: #e1e1e1; + --fsdocs-code-function-color: #e1e1e1; + --fsdocs-code-function2-color: #43AEC6; + --fsdocs-code-activepattern-color: #4ec9b0; + --fsdocs-code-unioncase-color: #4ec9b0; + --fsdocs-code-enumeration-color: #4ec9b0; + --fsdocs-code-keywords-color: #2248c4; + --fsdocs-code-comment-color: #329215; + --fsdocs-code-operators-color: #af75c1; + --fsdocs-code-numbers-color: #96C71D; + --fsdocs-code-linenumbers-color: #80b0b0; + --fsdocs-code-mutable-color: #997f0c; + --fsdocs-code-inactive-color: #808080; + --fsdocs-code-preprocessor-color: #af75c1; + --fsdocs-code-fsioutput-color: #808080; + --fsdocs-code-tooltip-color: #d1d1d1; +} + + +.fsdocs-source-link img { + -webkit-filter: grayscale(100%) brightness(1) invert(1); /* Safari 6.0 - 9.0 */ + filter: grayscale(100%) brightness(1) invert(1); +} \ No newline at end of file diff --git a/docsSrc/content/fsdocs-light.css b/docsSrc/content/fsdocs-light.css new file mode 100644 index 0000000..318ccd9 --- /dev/null +++ b/docsSrc/content/fsdocs-light.css @@ -0,0 +1,43 @@ +@import url('https://fonts.googleapis.com/css2?family=Hind+Vadodara&family=Roboto+Mono&display=swap'); +/*-------------------------------------------------------------------------- + Formatting for page & standard document content +/*--------------------------------------------------------------------------*/ + +:root { + --fsdocs-text-color:#262626; + --fsdocs-pre-border-color: #d8d8d8; + --fsdocs-pre-border-color-top: #e3e3e3; + --fsdocs-pre-background-color: #f3f4f7; + --fsdocs-pre-color: #8e0e2b; + --fsdocs-table-pre-background-color: #fff7ed; + --fsdocs-table-pre-color: #837b79; + + --fsdocs-code-strings-color: #dd1144; + --fsdocs-code-printf-color: #E0C57F; + --fsdocs-code-escaped-color: #EA8675; + --fsdocs-code-identifiers-color: var(--fsdocs-text-color); + --fsdocs-code-module-color: #009999; + --fsdocs-code-reference-color: #4974D1; + --fsdocs-code-value-color: #43AEC6; + --fsdocs-code-interface-color: #43AEC6; + --fsdocs-code-typearg-color: #43AEC6; + --fsdocs-code-disposable-color: #43AEC6; + --fsdocs-code-property-color: #43AEC6; + --fsdocs-code-punctuation-color: #43AEC6; + --fsdocs-code-punctuation2-color: #var(--fsdocs-text-color); + --fsdocs-code-function-color: #e1e1e1; + --fsdocs-code-function2-color: #990000; + --fsdocs-code-activepattern-color: #4ec9b0; + --fsdocs-code-unioncase-color: #4ec9b0; + --fsdocs-code-enumeration-color: #4ec9b0; + --fsdocs-code-keywords-color: #b68015; + --fsdocs-code-comment-color: #808080; + --fsdocs-code-operators-color: #af75c1; + --fsdocs-code-numbers-color: #009999; + --fsdocs-code-linenumbers-color: #80b0b0; + --fsdocs-code-mutable-color: #d1d1d1; + --fsdocs-code-inactive-color: #808080; + --fsdocs-code-preprocessor-color: #af75c1; + --fsdocs-code-fsioutput-color: #808080; + --fsdocs-code-tooltip-color: #d1d1d1; +} diff --git a/docsSrc/content/fsdocs-main.css b/docsSrc/content/fsdocs-main.css new file mode 100644 index 0000000..2ad1582 --- /dev/null +++ b/docsSrc/content/fsdocs-main.css @@ -0,0 +1,604 @@ +@import url('https://fonts.googleapis.com/css2?family=Hind+Vadodara&family=Roboto+Mono&display=swap'); +/*-------------------------------------------------------------------------- + Formatting for page & standard document content +/*--------------------------------------------------------------------------*/ + +body { + font-family: 'Hind Vadodara', sans-serif; + /* padding-top: 0px; + padding-bottom: 40px; +*/ +} + +blockquote { + margin: 0 1em 0 0.25em; + margin-top: 0px; + margin-right: 1em; + margin-bottom: 0px; + margin-left: 0.25em; + padding: 0 .75em 0 1em; + border-left: 1px solid #777; + border-right: 0px solid #777; +} + +/* Format the heading - nicer spacing etc. */ +.masthead { + overflow: hidden; +} + + .masthead .muted a { + text-decoration: none; + color: #999999; + } + + .masthead ul, .masthead li { + margin-bottom: 0px; + } + + .masthead .nav li { + margin-top: 15px; + font-size: 110%; + } + + .masthead h3 { + margin-top: 15px; + margin-bottom: 5px; + font-size: 170%; + } + +/*-------------------------------------------------------------------------- + Formatting fsdocs-content +/*--------------------------------------------------------------------------*/ + +/* Change font sizes for headings etc. */ +#fsdocs-content h1 { + margin: 30px 0px 15px 0px; + /* font-weight: 400; */ + font-size: 2rem; + letter-spacing: 1.78px; + line-height: 2.5rem; + font-weight: 400; +} + +#fsdocs-content h2 { + font-size: 1.6rem; + margin: 20px 0px 10px 0px; + font-weight: 400; +} + +#fsdocs-content h3 { + font-size: 1.2rem; + margin: 15px 0px 10px 0px; + font-weight: 400; +} + +#fsdocs-content hr { + margin: 0px 0px 20px 0px; +} + +#fsdocs-content li { + font-size: 1.0rem; + line-height: 1.375rem; + letter-spacing: 0.01px; + font-weight: 500; + margin: 0px 0px 15px 0px; +} + +#fsdocs-content p { + font-size: 1.0rem; + line-height: 1.375rem; + letter-spacing: 0.01px; + font-weight: 500; + color: var(--fsdocs-text-color);; +} + +#fsdocs-content a:not(.btn) { + color: #4974D1; +} +/* remove the default bootstrap bold on dt elements */ +#fsdocs-content dt { + font-weight: normal; +} + + + +/*-------------------------------------------------------------------------- + Formatting tables in fsdocs-content, using learn.microsoft.com tables +/*--------------------------------------------------------------------------*/ + +#fsdocs-content .table { + table-layout: auto; + width: 100%; + font-size: 0.875rem; +} + + #fsdocs-content .table caption { + font-size: 0.8rem; + font-weight: 600; + letter-spacing: 2px; + text-transform: uppercase; + padding: 1.125rem; + border-width: 0 0 1px; + border-style: solid; + border-color: #e3e3e3; + text-align: right; + } + + #fsdocs-content .table td, + #fsdocs-content .table th { + display: table-cell; + word-wrap: break-word; + padding: 0.75rem 1rem 0.75rem 0rem; + line-height: 1.5; + vertical-align: top; + border-top: 1px solid #e3e3e3; + border-right: 0; + border-left: 0; + border-bottom: 0; + border-style: solid; + } + + /* suppress the top line on inner lists such as tables of exceptions */ + #fsdocs-content .table .fsdocs-exception-list td, + #fsdocs-content .table .fsdocs-exception-list th { + border-top: 0 + } + + #fsdocs-content .table td p:first-child, + #fsdocs-content .table th p:first-child { + margin-top: 0; + } + + #fsdocs-content .table td.nowrap, + #fsdocs-content .table th.nowrap { + white-space: nowrap; + } + + #fsdocs-content .table td.is-narrow, + #fsdocs-content .table th.is-narrow { + width: 15%; + } + + #fsdocs-content .table th:not([scope='row']) { + border-top: 0; + border-bottom: 1px; + } + + #fsdocs-content .table > caption + thead > tr:first-child > td, + #fsdocs-content .table > colgroup + thead > tr:first-child > td, + #fsdocs-content .table > thead:first-child > tr:first-child > td { + border-top: 0; + } + + #fsdocs-content .table table-striped > tbody > tr:nth-of-type(odd) { + background-color: var(--box-shadow-light); + } + + #fsdocs-content .table.min { + width: unset; + } + + #fsdocs-content .table.is-left-aligned td:first-child, + #fsdocs-content .table.is-left-aligned th:first-child { + padding-left: 0; + } + + #fsdocs-content .table.is-left-aligned td:first-child a, + #fsdocs-content .table.is-left-aligned th:first-child a { + outline-offset: -0.125rem; + } + +@media screen and (max-width: 767px), screen and (min-resolution: 120dpi) and (max-width: 767.9px) { + #fsdocs-content .table.is-stacked-mobile td:nth-child(1) { + display: block; + width: 100%; + padding: 1rem 0; + } + + #fsdocs-content .table.is-stacked-mobile td:not(:nth-child(1)) { + display: block; + border-width: 0; + padding: 0 0 1rem; + } +} + +#fsdocs-content .table.has-inner-borders th, +#fsdocs-content .table.has-inner-borders td { + border-right: 1px solid #e3e3e3; +} + + #fsdocs-content .table.has-inner-borders th:last-child, + #fsdocs-content .table.has-inner-borders td:last-child { + border-right: none; + } + +.fsdocs-entity-list .fsdocs-entity-name { + width: 25%; + font-weight: bold; +} + +.fsdocs-member-list .fsdocs-member-usage { + width: 35%; +} + +/*-------------------------------------------------------------------------- + Formatting xmldoc sections in fsdocs-content +/*--------------------------------------------------------------------------*/ + +.fsdocs-xmldoc, .fsdocs-entity-xmldoc, .fsdocs-member-xmldoc { + font-size: 1.0rem; + line-height: 1.375rem; + letter-spacing: 0.01px; + font-weight: 500; + color: var(--fsdocs-text-color);; +} + +.fsdocs-xmldoc h1 { + font-size: 1.2rem; + margin: 10px 0px 0px 0px; +} + +.fsdocs-xmldoc h2 { + font-size: 1.2rem; + margin: 10px 0px 0px 0px; +} + +.fsdocs-xmldoc h3 { + font-size: 1.1rem; + margin: 10px 0px 0px 0px; +} + +/* #fsdocs-nav .searchbox { + margin-top: 30px; + margin-bottom: 30px; +} */ + +#fsdocs-nav img.logo{ + width:90%; + /* height:140px; */ + /* margin:10px 0px 0px 20px; */ + margin-top:40px; + border-style:none; +} + +#fsdocs-nav input{ + /* margin-left: 20px; */ + margin-right: 20px; + margin-top: 20px; + margin-bottom: 20px; + width: 93%; + -webkit-border-radius: 0; + border-radius: 0; +} + +#fsdocs-nav { + /* margin-left: -5px; */ + /* width: 90%; */ + font-size:0.95rem; +} + +#fsdocs-nav li.nav-header{ + /* margin-left: -5px; */ + /* width: 90%; */ + padding-left: 0; + color: var(--fsdocs-text-color);; + text-transform: none; + font-size:16px; + margin-top: 9px; + font-weight: bold; +} + +#fsdocs-nav a{ + padding-left: 0; + color: #6c6c6d; + /* margin-left: 5px; */ + /* width: 90%; */ +} + +/*-------------------------------------------------------------------------- + Formatting pre and code sections in fsdocs-content (code highlighting is + further below) +/*--------------------------------------------------------------------------*/ + +#fsdocs-content code { + /* font-size: 0.83rem; */ + font: 0.85rem 'Roboto Mono', monospace; + background-color: #f7f7f900; + border: 0px; + padding: 0px; + /* word-wrap: break-word; */ + /* white-space: pre; */ +} + +/* omitted */ +#fsdocs-content span.omitted { + background: #3c4e52; + border-radius: 5px; + color: #808080; + padding: 0px 0px 1px 0px; +} + +#fsdocs-content pre .fssnip code { + font: 0.86rem 'Roboto Mono', monospace; +} + +#fsdocs-content table.pre, +#fsdocs-content pre.fssnip, +#fsdocs-content pre { + line-height: 13pt; + border: 0px solid var(--fsdocs-pre-border-color); + border-top: 0px solid var(--fsdocs-pre-border-color-top); + border-collapse: separate; + white-space: pre; + font: 0.86rem 'Roboto Mono', monospace; + width: 100%; + margin: 10px 0px 20px 0px; + background-color: var(--fsdocs-pre-background-color); + padding: 10px; + border-radius: 5px; + color: var(--fsdocs-pre-color); + max-width: none; + box-sizing: border-box; +} + +#fsdocs-content pre.fssnip code { + font: 0.86rem 'Roboto Mono', monospace; + font-weight: 600; +} + +#fsdocs-content table.pre { + background-color: var(--fsdocs-table-pre-background-color);; +} + +#fsdocs-content table.pre pre { + padding: 0px; + margin: 0px; + border-radius: 0px; + width: 100%; + background-color: var(--fsdocs-table-pre-background-color); + color: var(--fsdocs-table-pre-color); +} + +#fsdocs-content table.pre td { + padding: 0px; + white-space: normal; + margin: 0px; + width: 100%; +} + +#fsdocs-content table.pre td.lines { + width: 30px; +} + + +#fsdocs-content pre { + word-wrap: inherit; +} + +.fsdocs-example-header { + font-size: 1.0rem; + line-height: 1.375rem; + letter-spacing: 0.01px; + font-weight: 700; + color: var(--fsdocs-text-color);; +} + +/*-------------------------------------------------------------------------- + Formatting github source links +/*--------------------------------------------------------------------------*/ + +.fsdocs-source-link { + float: right; + text-decoration: none; +} + + .fsdocs-source-link img { + border-style: none; + margin-left: 10px; + width: auto; + height: 1.4em; + } + + .fsdocs-source-link .hover { + display: none; + } + + .fsdocs-source-link:hover .hover { + display: block; + } + + .fsdocs-source-link .normal { + display: block; + } + + .fsdocs-source-link:hover .normal { + display: none; + } + +/*-------------------------------------------------------------------------- + Formatting logo +/*--------------------------------------------------------------------------*/ + +#fsdocs-logo { + width:40px; + height:40px; + margin:10px 0px 0px 0px; + border-style:none; +} + +/*-------------------------------------------------------------------------- + +/*--------------------------------------------------------------------------*/ + +#fsdocs-content table.pre pre { + padding: 0px; + margin: 0px; + border: none; +} + +/*-------------------------------------------------------------------------- + Remove formatting from links +/*--------------------------------------------------------------------------*/ + +#fsdocs-content h1 a, +#fsdocs-content h1 a:hover, +#fsdocs-content h1 a:focus, +#fsdocs-content h2 a, +#fsdocs-content h2 a:hover, +#fsdocs-content h2 a:focus, +#fsdocs-content h3 a, +#fsdocs-content h3 a:hover, +#fsdocs-content h3 a:focus, +#fsdocs-content h4 a, +#fsdocs-content h4 a:hover, #fsdocs-content +#fsdocs-content h4 a:focus, +#fsdocs-content h5 a, +#fsdocs-content h5 a:hover, +#fsdocs-content h5 a:focus, +#fsdocs-content h6 a, +#fsdocs-content h6 a:hover, +#fsdocs-content h6 a:focus { + color: var(--fsdocs-text-color);; + text-decoration: none; + text-decoration-style: none; + /* outline: none */ +} + +/*-------------------------------------------------------------------------- + Formatting for F# code snippets +/*--------------------------------------------------------------------------*/ + +.fsdocs-param-name, +.fsdocs-return-name, +.fsdocs-param { + font-weight: 900; + font-size: 0.85rem; + font-family: 'Roboto Mono', monospace; +} +/* strings --- and stlyes for other string related formats */ +#fsdocs-content span.s { + color: var(--fsdocs-code-strings-color); +} +/* printf formatters */ +#fsdocs-content span.pf { + color: var(--fsdocs-code-printf-color); +} +/* escaped chars */ +#fsdocs-content span.e { + color: var(--fsdocs-code-escaped-color); +} + +/* identifiers --- and styles for more specific identifier types */ +#fsdocs-content span.id { + color: var(--fsdocs-identifiers-color);; +} +/* module */ +#fsdocs-content span.m { + color:var(--fsdocs-code-module-color); +} +/* reference type */ +#fsdocs-content span.rt { + color: var(--fsdocs-code-reference-color); +} +/* value type */ +#fsdocs-content span.vt { + color: var(--fsdocs-code-value-color); +} +/* interface */ +#fsdocs-content span.if { + color: var(--fsdocs-code-interface-color); +} +/* type argument */ +#fsdocs-content span.ta { + color: var(--fsdocs-code-typearg-color); +} +/* disposable */ +#fsdocs-content span.d { + color: var(--fsdocs-code-disposable-color); +} +/* property */ +#fsdocs-content span.prop { + color: var(--fsdocs-code-property-color); +} +/* punctuation */ +#fsdocs-content span.p { + color: var(--fsdocs-code-punctuation-color); +} +#fsdocs-content span.pn { + color: var(--fsdocs-code-punctuation2-color); +} +/* function */ +#fsdocs-content span.f { + color: var(--fsdocs-code-function-color); +} +#fsdocs-content span.fn { + color: var(--fsdocs-code-function2-color); +} +/* active pattern */ +#fsdocs-content span.pat { + color: var(--fsdocs-code-activepattern-color); +} +/* union case */ +#fsdocs-content span.u { + color: var(--fsdocs-code-unioncase-color); +} +/* enumeration */ +#fsdocs-content span.e { + color: var(--fsdocs-code-enumeration-color); +} +/* keywords */ +#fsdocs-content span.k { + color: var(--fsdocs-code-keywords-color); + /* font-weight: bold; */ +} +/* comment */ +#fsdocs-content span.c { + color: var(--fsdocs-code-comment-color); + font-weight: 400; + font-style: italic; +} +/* operators */ +#fsdocs-content span.o { + color: var(--fsdocs-code-operators-color); +} +/* numbers */ +#fsdocs-content span.n { + color: var(--fsdocs-code-numbers-color); +} +/* line number */ +#fsdocs-content span.l { + color: var(--fsdocs-code-linenumbers-color); +} +/* mutable var or ref cell */ +#fsdocs-content span.v { + color: var(--fsdocs-code-mutable-color); + font-weight: bold; +} +/* inactive code */ +#fsdocs-content span.inactive { + color: var(--fsdocs-code-inactive-color); +} +/* preprocessor */ +#fsdocs-content span.prep { + color: var(--fsdocs-code-preprocessor-color); +} +/* fsi output */ +#fsdocs-content span.fsi { + color: var(--fsdocs-code-fsioutput-color); +} + +/* tool tip */ +div.fsdocs-tip { + background: #475b5f; + border-radius: 4px; + font: 0.85rem 'Roboto Mono', monospace; + padding: 6px 8px 6px 8px; + display: none; + color: var(--fsdocs-code-tooltip-color); + pointer-events: none; +} + + div.fsdocs-tip code { + color: var(--fsdocs-code-tooltip-color); + font: 0.85rem 'Roboto Mono', monospace; + } diff --git a/docsSrc/content/logo.png b/docsSrc/content/logo.png new file mode 100644 index 0000000..91da3ba Binary files /dev/null and b/docsSrc/content/logo.png differ diff --git a/docsSrc/content/logo.svg b/docsSrc/content/logo.svg new file mode 100644 index 0000000..0eb629c --- /dev/null +++ b/docsSrc/content/logo.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docsSrc/content/navbar-fixed-left.css b/docsSrc/content/navbar-fixed-left.css new file mode 100644 index 0000000..28e4c57 --- /dev/null +++ b/docsSrc/content/navbar-fixed-left.css @@ -0,0 +1,91 @@ +/* CSS for Bootstrap 5 Fixed Left Sidebar Navigation */ + + + +@media (min-width: 992px){ + + body { + padding-left: 300px; + padding-right: 60px; + } + + #fsdocs-logo { + width:140px; + height:140px; + margin:10px 0px 0px 0px; + border-style:none; + } + + + nav.navbar { + position: fixed; + left: 0; + width: 300px; + bottom: 0; + top: 0; + overflow-y: auto; + overflow-x: hidden; + display: block; + border-right: 1px solid #cecece; + } + + nav.navbar>.container { + flex-direction: column; + padding: 0; + } + + nav.navbar .navbar-nav { + flex-direction: column; + } + nav.navbar .navbar-collapse { + width: 100%; + } + + nav.navbar .navbar-nav { + width: 100%; + } + + nav.navbar .navbar-nav .dropdown-menu { + position: static; + display: block; + } + + nav.navbar .dropdown { + margin-bottom: 5px; + font-size: 14px; + } + + nav.navbar .dropdown-item { + white-space: normal; + font-size: 14px; + vertical-align: middle; + } + + nav.navbar .dropdown-item img { + margin-right: 5px; + } + + nav.navbar .dropdown-toggle { + cursor: default; + } + + nav.navbar .dropdown-menu { + border-radius: 0; + border-left: 0; + border-right: 0; + } + + nav.navbar .dropdown-toggle:not(#bd-theme)::after { + display: none; + } + + .dropdown-menu[data-bs-popper] { + top: auto; + left: auto; + margin-top: auto; + } + + .nav-link:focus, .nav-link:hover { + color: auto; + } +} \ No newline at end of file diff --git a/docsSrc/content/theme-toggle.js b/docsSrc/content/theme-toggle.js new file mode 100644 index 0000000..c208c08 --- /dev/null +++ b/docsSrc/content/theme-toggle.js @@ -0,0 +1,68 @@ +/*! + * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2011-2022 The Bootstrap Authors + * Licensed under the Creative Commons Attribution 3.0 Unported License. + */ + +(() => { + 'use strict' + + const storedTheme = localStorage.getItem('theme') + + const getPreferredTheme = () => { + if (storedTheme) { + return storedTheme + } + + return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' + } + + const setTheme = function (theme) { + const fsdocsTheme = document.getElementById("fsdocs-theme") + const re = /fsdocs-.*.css/ + if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) { + document.documentElement.setAttribute('data-bs-theme', 'dark') + fsdocsTheme.setAttribute("href", fsdocsTheme.getAttribute("href").replace(re,"fsdocs-dark.css")) + + } else { + document.documentElement.setAttribute('data-bs-theme', theme) + + fsdocsTheme.setAttribute("href", fsdocsTheme.getAttribute("href").replace(re,`fsdocs-${theme}.css`)) + } + } + + setTheme(getPreferredTheme()) + + const showActiveTheme = theme => { + const activeThemeIcon = document.getElementById('theme-icon-active') + const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`) + const svgOfActiveBtn = btnToActive.querySelector('i').getAttribute('class') + + document.querySelectorAll('[data-bs-theme-value]').forEach(element => { + element.classList.remove('active') + }) + + btnToActive.classList.add('active') + activeThemeIcon.setAttribute('class', svgOfActiveBtn) + } + + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { + if (storedTheme !== 'light' || storedTheme !== 'dark') { + setTheme(getPreferredTheme()) + } + }) + + window.addEventListener('DOMContentLoaded', () => { + showActiveTheme(getPreferredTheme()) + + document.querySelectorAll('[data-bs-theme-value]') + .forEach(toggle => { + toggle.addEventListener('click', () => { + const theme = toggle.getAttribute('data-bs-theme-value') + localStorage.setItem('theme', theme) + setTheme(theme) + showActiveTheme(theme) + }) + }) + }) +})() \ No newline at end of file diff --git a/docsSrc/index.md b/docsSrc/index.md new file mode 100644 index 0000000..62a482a --- /dev/null +++ b/docsSrc/index.md @@ -0,0 +1,69 @@ +# Apple.CryptoKit + +.NET bindings for [Apple.CryptoKit](https://developer.apple.com/documentation/cryptokit) framework to use RSA keys in [Uno Platform](https://platform.uno) apps targeting **iOS** and **Mac Catalyst**. + +## Key Features + +CGN-like syntax for Apple KeychainStorage + +--- + +
    +
    +
    +
    + The FSharp.Azure.Cosmos library can be installed from NuGet: +
    PM> Install-Package FSharp.Azure.Cosmos
    +
    +
    +
    +
    + +--- + +
    +
    +
    +
    +
    Tutorials
    +

    Step-by-step guide to get started with FSharp.Azure.Cosmos.

    +
    + +
    +
    +
    +
    +
    +
    How-To Guides
    +

    Guides you through the steps involved in addressing key problems and use-cases.

    +
    + +
    +
    +
    +
    +
    +
    Explanations
    +

    Discusses key topics and concepts at a fairly high level and provide useful background information and explanation..

    +
    + +
    +
    +
    +
    +
    +
    Api Reference
    +

    Contain technical reference for APIs.

    +
    + +
    +
    +
    diff --git a/global.json b/global.json new file mode 100644 index 0000000..45c29e7 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "9.0.305", + "rollForward": "latestMinor" + } +} diff --git a/ApiDefinition.cs b/src/ApiDefinition.cs similarity index 100% rename from ApiDefinition.cs rename to src/ApiDefinition.cs diff --git a/Apple.CryptoKit.csproj b/src/Apple.CryptoKit.csproj similarity index 75% rename from Apple.CryptoKit.csproj rename to src/Apple.CryptoKit.csproj index f1e741d..50f09bf 100644 --- a/Apple.CryptoKit.csproj +++ b/src/Apple.CryptoKit.csproj @@ -16,19 +16,19 @@ - - - Framework - - - + + + Framework + + + - - - Framework - - - + + + Framework + + +