FSharp.Data.Validator 9.0.2

dotnet add package FSharp.Data.Validator --version 9.0.2
                    
NuGet\Install-Package FSharp.Data.Validator -Version 9.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharp.Data.Validator" Version="9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FSharp.Data.Validator" Version="9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="FSharp.Data.Validator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FSharp.Data.Validator --version 9.0.2
                    
#r "nuget: FSharp.Data.Validator, 9.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FSharp.Data.Validator@9.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FSharp.Data.Validator&version=9.0.2
                    
Install as a Cake Addin
#tool nuget:?package=FSharp.Data.Validator&version=9.0.2
                    
Install as a Cake Tool

Code Example:

let isValidDateFormat = isValidDate "yyyy-MM-dd"

let validateDate from until =
    from |>
       (validateOption isValidDateFormat |&&| (fun from ->
            until |> (isNull |=| (isValidDateFormat |&&| greaterOrEqualThen from))))
       
let validateCommonPromo common =
    common |> requiresTextLength promoUniqueLength
       
let validateMode mode common unique =
    mode |> (isEnumCase typeof<PromoMode> |&&| (fun enumStr ->
                let enum = Enum.Parse<PromoMode>(enumStr)
                match enum with
                | PromoMode.COMMON -> validateCommonPromo common
                | PromoMode.UNIQUE -> unique |> (notNull |*&| validateCommonPromo)
                | _ -> ArgumentOutOfRangeException() |> raise))

type Target = {
    AgeFrom: int Nullable 
    AgeUntil: int Nullable
    Country: string | null
    Categories: string[] | null
} with
    interface IValidatable with
        member this.Validate() =
            (not (this.AgeFrom.HasValue && this.AgeUntil.HasValue)
             || (this.AgeFrom.Value <= this.AgeUntil.Value
                 && this.AgeFrom.Value >= 0 && this.AgeUntil.Value <= 100))
            && this.Country |> validateOption isISO3166
            && this.Categories |> validateOptionArray (requiresArrayLength categoryCount
                                                       |*&| requiresTextLength categoryLength)

[<CLIMutable>]
type CreatePromoRequest = {
    [<RequiresLength(descriptionLengthMin, descriptionLengthMax)>]
    Description: string
    
    ImageUrl: string | null
     
    [<Required>]
    Target: Target
    
    [<Required>]
    [<Range(0, 100000000)>]
    MaxCount: int
    
    ActiveFrom: string | null
    
    ActiveUntil: string | null
    
    [<Required>]
    Mode: string
    
    PromoCommon: string | null
    
    PromoUnique: string[] | null
} with
    static member InitFromPromoModel(promo: PromoCode) = {
        Description = promo.description
        ImageUrl = promo.image_url
        Target = {
            AgeFrom = promo.age_from
            AgeUntil = promo.age_until
            Country = promo.country
            Categories = promo.categories
        }
        MaxCount = promo.max_count
        ActiveFrom = promo.active_from
        ActiveUntil = promo.active_until
        Mode = promo.mode
        PromoCommon = promo.promo_common
        PromoUnique = promo.promo_unique
    }
        
    interface IValidatable with
        member this.Validate() =
            (this.Target :> IValidatable).Validate()
            && (this.MaxCount = 1 || this.Mode = "COMMON")
            && this.ImageUrl |> validateOption (requiresTextLength imageUrlLength |&&| isUrl)
            && (this.ActiveFrom, this.ActiveUntil) ||> validateDate
            && (this.Mode, this.PromoCommon, this.PromoUnique) |||> validateMode      
and CreatePromoResponse = CreatePromoRequest

type GetPromoResponse = {
    Description: string
    ImageUrl: string | null
    Target: Target
    MaxCount: int
    ActiveFrom: string | null
    ActiveUntil: string | null
    Mode: string
    PromoCommon: string | null
    PromoUnique: string[] | null
    PromoId: Guid
    CompanyId: Guid
    CompanyName: string
    LikeCount: int
    UsedCount: int
    Active: bool
} with
    static member InitFromPromoModel(promo: PromoCode, companyName: string) = {
        Description = promo.description
        ImageUrl = promo.image_url
        Target = {
            AgeFrom = promo.age_from
            AgeUntil = promo.age_until
            Country = promo.country
            Categories = promo.categories
        }
        MaxCount = promo.max_count
        ActiveFrom = promo.active_from
        ActiveUntil = promo.active_until
        Mode = promo.mode
        PromoCommon = promo.promo_common
        PromoUnique = promo.promo_unique
        PromoId = promo.id
        CompanyId = promo.company_id
        CompanyName = companyName
        LikeCount = promo.like_count
        UsedCount = promo.used_count
        Active = promo.active
    }
    
type UpdatePromoRequest = {
    Description: string | null
    ImageUrl: string | null
    Target: Target | null
    MaxCount: int Nullable
    ActiveFrom: string | null
    ActiveUntil: string | null
} with
    member this.ValidateMaxCount(mode: string) =
        if this.MaxCount.HasValue then
            (this.MaxCount.Value = 1 || mode = "COMMON")
        else true
        
    interface IValidatable with
        member this.Validate() =
            this.Target |> validateOption (fun t -> (t :> IValidatable).Validate())
            && this.Description |> validateOption (requiresTextLength descriptionLength)
            && this.ImageUrl |> validateOption (requiresTextLength imageUrlLength |&&| isUrl)
            && (this.ActiveFrom, this.ActiveUntil) ||> validateDate
            
type PromoFilter = {
    Limit: int
    Offset: int
    SortBy: string
    Country: string[] | null
} with
    static member InitFromQueryRow(ctx: HttpContext) =
        try
            let parseCountries =
                let singleCountries = getQueryParams ctx "country"
                if singleCountries.Length > 0 then
                    singleCountries
                    |> Array.collect _.Split(',')
                    |> Array.map _.ToLower()
                else
                    null
                
            let newFilter = {
                Limit = getQueryParam ((<|) int) 10 ctx "limit"
                Offset = getQueryParam ((<|) int) 0 ctx "offset"
                SortBy = getQueryParam id "created_at" ctx "sort_by"
                Country = parseCountries
            }
            
            if (newFilter :> IValidatable).Validate() then
                Some newFilter
            else
                None
        with
        | _ -> None
        
    interface IValidatable with
        member this.Validate() =
            this.Limit |> valueFrom 0
            && this.Offset |> valueFrom 0
            && this.SortBy |> isIn [| "created_at"; "active_from"; "active_until" |]
            && this.Country |> validateOptionArray (Array.forall isISO3166)
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.2 227 2/13/2025