@f1studio/form-spec 5.0.0-alpha.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Designer.d.ts +89 -0
- package/FormSpec.TS/Components/HelloComponent.js +68 -0
- package/FormSpec.TS/Components/HelloComponent.js.map +1 -0
- package/FormSpec.TS/Components/HelloComponent.ts.map +1 -0
- package/FormSpec.TS/Designer.js +526 -0
- package/FormSpec.TS/Designer.js.map +1 -0
- package/FormSpec.TS/Designer.ts.map +1 -0
- package/FormSpec.TS/FormSpec.js +5400 -0
- package/FormSpec.TS/FormSpec.js.map +1 -0
- package/FormSpec.TS/FormSpec.ts.map +1 -0
- package/FormSpec.TS/FormSpecHelpers.js +382 -0
- package/FormSpec.TS/FormSpecHelpers.js.map +1 -0
- package/FormSpec.TS/FormSpecHelpers.ts.map +1 -0
- package/FormSpec.TS/Helpers.js +732 -0
- package/FormSpec.TS/Helpers.js.map +1 -0
- package/FormSpec.TS/Helpers.ts.map +1 -0
- package/FormSpec.TS/Interfaces.js +257 -0
- package/FormSpec.TS/Interfaces.js.map +1 -0
- package/FormSpec.TS/Interfaces.ts.map +1 -0
- package/FormSpec.TS/Interop/FormSpec.Api.Helpers.js +854 -0
- package/FormSpec.TS/Interop/FormSpec.Api.Helpers.js.map +1 -0
- package/FormSpec.TS/Interop/FormSpec.Api.Helpers.ts.map +1 -0
- package/FormSpec.TS/Interop/FormSpec.Api.Option.js +1961 -0
- package/FormSpec.TS/Interop/FormSpec.Api.Option.js.map +1 -0
- package/FormSpec.TS/Interop/FormSpec.Api.Option.ts.map +1 -0
- package/FormSpec.TS/Interop/FormSpec.Values.Api.Option.js +1367 -0
- package/FormSpec.TS/Interop/FormSpec.Values.Api.Option.js.map +1 -0
- package/FormSpec.TS/Interop/FormSpec.Values.Api.Option.ts.map +1 -0
- package/FormSpec.TS/Logging/LogTypes.js +347 -0
- package/FormSpec.TS/Logging/LogTypes.js.map +1 -0
- package/FormSpec.TS/Logging/LogTypes.ts.map +1 -0
- package/FormSpec.TS/Migrator.js +230 -0
- package/FormSpec.TS/Migrator.js.map +1 -0
- package/FormSpec.TS/Migrator.ts.map +1 -0
- package/FormSpec.TS/PathwayDataExtractor.js +361 -0
- package/FormSpec.TS/PathwayDataExtractor.js.map +1 -0
- package/FormSpec.TS/PathwayDataExtractor.ts.map +1 -0
- package/FormSpec.TS/PathwayExecutor.js +1321 -0
- package/FormSpec.TS/PathwayExecutor.js.map +1 -0
- package/FormSpec.TS/PathwayExecutor.ts.map +1 -0
- package/FormSpec.TS/PathwayValidator.js +346 -0
- package/FormSpec.TS/PathwayValidator.js.map +1 -0
- package/FormSpec.TS/PathwayValidator.ts.map +1 -0
- package/FormSpec.TS/PluginInterface.js +171 -0
- package/FormSpec.TS/PluginInterface.js.map +1 -0
- package/FormSpec.TS/PluginInterface.ts.map +1 -0
- package/FormSpec.TS/Prelude.js +59 -0
- package/FormSpec.TS/Prelude.js.map +1 -0
- package/FormSpec.TS/Prelude.ts.map +1 -0
- package/FormSpec.TS/Renderers/FormSpecMarkdownRenderer.js +958 -0
- package/FormSpec.TS/Renderers/FormSpecMarkdownRenderer.js.map +1 -0
- package/FormSpec.TS/Renderers/FormSpecMarkdownRenderer.ts.map +1 -0
- package/FormSpec.TS/Renderers/MermaidRenderer.js +228 -0
- package/FormSpec.TS/Renderers/MermaidRenderer.js.map +1 -0
- package/FormSpec.TS/Renderers/MermaidRenderer.ts.map +1 -0
- package/FormSpec.TS/Renderers/PathwayRenderers.js +190 -0
- package/FormSpec.TS/Renderers/PathwayRenderers.js.map +1 -0
- package/FormSpec.TS/Renderers/PathwayRenderers.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Base.fs +511 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Base.fs.js +437 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Base.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Base.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Error.fs +16 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Error.fs.js +73 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Error.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Error.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Extensions.fs +50 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Extensions.fs.js +72 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Extensions.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Extensions.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Fable.Form.fableproj +28 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Field.fs +24 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Field.fs.js +56 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Field.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Field.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Fable.Form.Simple.fableproj +31 -0
- package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Form.fs +178 -0
- package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Form.fs.js +464 -0
- package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Form.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Form.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Extensions.fs +17 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Hooks.fs +152 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Hooks.fs.js +25 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Hooks.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Hooks.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Types.fableproj +28 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.fs +218 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.fs.js +37 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.Types.fableproj +27 -0
- package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.fs +82 -0
- package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.fs.js +7 -0
- package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/BorderStyle.fs +59 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Colors.fs +154 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Colors.fs.js +32 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Colors.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Colors.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Feliz.fableproj +42 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Fonts.fs +240 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/GridTypes.fs +24 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Html.fs +826 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Interop.fs +83 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Interop.fs.js +292 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Interop.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Interop.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Key.fs +65 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Key.fs.js +229 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Key.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Key.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Length.fs +91 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Locale.fs +876 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Properties.fs +4080 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Properties.fs.js +133 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Properties.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Properties.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/React.fs +656 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/React.fs.js +561 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/React.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/React.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactDOM.fs +25 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactDOM.fs.js +46 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactDOM.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactDOM.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactInterop.js +63 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactInterop.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactTypes.fs +41 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactTypes.fs.js +7 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactTypes.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactTypes.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/StyleTypes.fs +53 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/StyleTypes.fs.js +7 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/StyleTypes.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/StyleTypes.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Styles.fs +5740 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Svg.fs +1455 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Svg.fs.js +39 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Svg.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Svg.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/TextDecorationLine.fs +13 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/TextDecorationStyle.fs +33 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Transform.fs +181 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/TransformOrigin.fs +17 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/TransitionProperty.fs +162 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Types.fs +13 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Types.fs.js +7 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Types.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Feliz.2.7.0/Types.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Decode.fs +1768 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Decode.fs.js +2337 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Decode.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Decode.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs +811 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs.js +465 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Extra.fs +47 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Extra.fs.js +18 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Extra.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Extra.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Thoth.Json.fableproj +34 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Types.fs +68 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Types.fs.js +355 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Types.fs.js.map +1 -0
- package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Types.fs.ts.map +1 -0
- package/FormSpec.TS/fable_modules/project_cracked.json +1 -0
- package/FormSpec.d.ts +1257 -0
- package/FormSpecHelpers.d.ts +50 -0
- package/Helpers.d.ts +147 -0
- package/Interfaces.d.ts +70 -0
- package/Interop/FormSpec.Api.Helpers.d.ts +247 -0
- package/Interop/FormSpec.Api.Helpers.d.ts.map +1 -0
- package/Interop/FormSpec.Api.Option.d.ts +384 -0
- package/Interop/FormSpec.Api.Option.d.ts.map +1 -0
- package/Interop/FormSpec.Values.Api.Option.d.ts +324 -0
- package/Interop/FormSpec.Values.Api.Option.d.ts.map +1 -0
- package/Migrator.d.ts +59 -0
- package/PathwayDataExtractor.d.ts +19 -0
- package/PathwayExecutor.d.ts +210 -0
- package/PathwayValidator.d.ts +52 -0
- package/PluginInterface.d.ts +36 -0
- package/Prelude.d.ts +11 -0
- package/README.TS.md +622 -0
- package/README.md +85 -0
- package/package.json +39 -0
- package/src/Components/HelloComponent.ts +48 -0
- package/src/Components/HelloComponent.ts.map +1 -0
- package/src/Designer.ts +389 -0
- package/src/Designer.ts.map +1 -0
- package/src/FormSpec.ts +3114 -0
- package/src/FormSpec.ts.map +1 -0
- package/src/FormSpecHelpers.ts +374 -0
- package/src/FormSpecHelpers.ts.map +1 -0
- package/src/Helpers.ts +765 -0
- package/src/Helpers.ts.map +1 -0
- package/src/Interfaces.ts +166 -0
- package/src/Interfaces.ts.map +1 -0
- package/src/Interop/FormSpec.Api.Helpers.ts +872 -0
- package/src/Interop/FormSpec.Api.Helpers.ts.map +1 -0
- package/src/Interop/FormSpec.Api.Option.ts +1618 -0
- package/src/Interop/FormSpec.Api.Option.ts.map +1 -0
- package/src/Interop/FormSpec.Values.Api.Option.ts +1214 -0
- package/src/Interop/FormSpec.Values.Api.Option.ts.map +1 -0
- package/src/Logging/LogTypes.ts +212 -0
- package/src/Logging/LogTypes.ts.map +1 -0
- package/src/Migrator.ts +156 -0
- package/src/Migrator.ts.map +1 -0
- package/src/PathwayDataExtractor.ts +290 -0
- package/src/PathwayDataExtractor.ts.map +1 -0
- package/src/PathwayExecutor.ts +1102 -0
- package/src/PathwayExecutor.ts.map +1 -0
- package/src/PathwayValidator.ts +244 -0
- package/src/PathwayValidator.ts.map +1 -0
- package/src/PluginInterface.ts +79 -0
- package/src/PluginInterface.ts.map +1 -0
- package/src/Prelude.ts +21 -0
- package/src/Prelude.ts.map +1 -0
- package/src/Renderers/FormSpecMarkdownRenderer.ts +874 -0
- package/src/Renderers/FormSpecMarkdownRenderer.ts.map +1 -0
- package/src/Renderers/MermaidRenderer.ts +218 -0
- package/src/Renderers/MermaidRenderer.ts.map +1 -0
- package/src/Renderers/PathwayRenderers.ts +200 -0
- package/src/Renderers/PathwayRenderers.ts.map +1 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
namespace Thoth.Json
|
|
2
|
+
|
|
3
|
+
open System.Text.RegularExpressions
|
|
4
|
+
|
|
5
|
+
[<RequireQualifiedAccess>]
|
|
6
|
+
module Encode =
|
|
7
|
+
|
|
8
|
+
open System.Collections.Generic
|
|
9
|
+
open System.Globalization
|
|
10
|
+
open Fable.Core
|
|
11
|
+
open Fable.Core.JsInterop
|
|
12
|
+
|
|
13
|
+
[<Emit("Array.from($0)")>]
|
|
14
|
+
let private arrayFrom (x: JsonValue seq) : JsonValue = jsNative
|
|
15
|
+
|
|
16
|
+
///**Description**
|
|
17
|
+
/// Encode a string
|
|
18
|
+
///
|
|
19
|
+
///**Parameters**
|
|
20
|
+
/// * `value` - parameter of type `string`
|
|
21
|
+
///
|
|
22
|
+
///**Output Type**
|
|
23
|
+
/// * `Value`
|
|
24
|
+
///
|
|
25
|
+
///**Exceptions**
|
|
26
|
+
///
|
|
27
|
+
let inline string (value: string) : JsonValue = box value
|
|
28
|
+
|
|
29
|
+
let inline char (value: char) : JsonValue = box value
|
|
30
|
+
|
|
31
|
+
///**Description**
|
|
32
|
+
/// Encode a GUID
|
|
33
|
+
///
|
|
34
|
+
///**Parameters**
|
|
35
|
+
/// * `value` - parameter of type `System.Guid`
|
|
36
|
+
///
|
|
37
|
+
///**Output Type**
|
|
38
|
+
/// * `Value`
|
|
39
|
+
///
|
|
40
|
+
///**Exceptions**
|
|
41
|
+
///
|
|
42
|
+
let guid (value: System.Guid) : JsonValue = box (value.ToString())
|
|
43
|
+
|
|
44
|
+
///**Description**
|
|
45
|
+
/// Encode a Float. `Infinity` and `NaN` are encoded as `null`.
|
|
46
|
+
///
|
|
47
|
+
///**Parameters**
|
|
48
|
+
/// * `value` - parameter of type `float`
|
|
49
|
+
///
|
|
50
|
+
///**Output Type**
|
|
51
|
+
/// * `Value`
|
|
52
|
+
///
|
|
53
|
+
///**Exceptions**
|
|
54
|
+
///
|
|
55
|
+
let inline float (value: float) : JsonValue = box value
|
|
56
|
+
|
|
57
|
+
let inline float32 (value: float32) : JsonValue = box value
|
|
58
|
+
|
|
59
|
+
///**Description**
|
|
60
|
+
/// Encode a Decimal.
|
|
61
|
+
///
|
|
62
|
+
///**Parameters**
|
|
63
|
+
/// * `value` - parameter of type `decimal`
|
|
64
|
+
///
|
|
65
|
+
///**Output Type**
|
|
66
|
+
/// * `Value`
|
|
67
|
+
///
|
|
68
|
+
///**Exceptions**
|
|
69
|
+
///
|
|
70
|
+
let decimal (value: decimal) : JsonValue = value.ToString() |> string
|
|
71
|
+
|
|
72
|
+
///**Description**
|
|
73
|
+
/// Encode null
|
|
74
|
+
///
|
|
75
|
+
///**Parameters**
|
|
76
|
+
///
|
|
77
|
+
///**Output Type**
|
|
78
|
+
/// * `Value`
|
|
79
|
+
///
|
|
80
|
+
///**Exceptions**
|
|
81
|
+
///
|
|
82
|
+
let nil: JsonValue = box null
|
|
83
|
+
|
|
84
|
+
///**Description**
|
|
85
|
+
/// Encode a bool
|
|
86
|
+
///**Parameters**
|
|
87
|
+
/// * `value` - parameter of type `bool`
|
|
88
|
+
///
|
|
89
|
+
///**Output Type**
|
|
90
|
+
/// * `Value`
|
|
91
|
+
///
|
|
92
|
+
///**Exceptions**
|
|
93
|
+
///
|
|
94
|
+
let inline bool (value: bool) : JsonValue = box value
|
|
95
|
+
|
|
96
|
+
///**Description**
|
|
97
|
+
/// Encode an object
|
|
98
|
+
///
|
|
99
|
+
///**Parameters**
|
|
100
|
+
/// * `values` - parameter of type `(string * Value) list`
|
|
101
|
+
///
|
|
102
|
+
///**Output Type**
|
|
103
|
+
/// * `Value`
|
|
104
|
+
///
|
|
105
|
+
///**Exceptions**
|
|
106
|
+
///
|
|
107
|
+
let object (values: (string * JsonValue) seq) : JsonValue =
|
|
108
|
+
let o = obj ()
|
|
109
|
+
|
|
110
|
+
for (key, value) in values do
|
|
111
|
+
o?(key) <- value
|
|
112
|
+
|
|
113
|
+
box o
|
|
114
|
+
|
|
115
|
+
///**Description**
|
|
116
|
+
/// Encode an array
|
|
117
|
+
///
|
|
118
|
+
///**Parameters**
|
|
119
|
+
/// * `values` - parameter of type `Value array`
|
|
120
|
+
///
|
|
121
|
+
///**Output Type**
|
|
122
|
+
/// * `Value`
|
|
123
|
+
///
|
|
124
|
+
///**Exceptions**
|
|
125
|
+
///
|
|
126
|
+
let inline array (values: JsonValue array) : JsonValue = box values
|
|
127
|
+
|
|
128
|
+
///**Description**
|
|
129
|
+
/// Encode a list
|
|
130
|
+
///**Parameters**
|
|
131
|
+
/// * `values` - parameter of type `Value list`
|
|
132
|
+
///
|
|
133
|
+
///**Output Type**
|
|
134
|
+
/// * `Value`
|
|
135
|
+
///
|
|
136
|
+
///**Exceptions**
|
|
137
|
+
///
|
|
138
|
+
let list (values: JsonValue list) : JsonValue =
|
|
139
|
+
// Don't use List.toArray as it may create a typed array
|
|
140
|
+
arrayFrom values
|
|
141
|
+
|
|
142
|
+
let seq (values: JsonValue seq) : JsonValue = arrayFrom values
|
|
143
|
+
|
|
144
|
+
///**Description**
|
|
145
|
+
/// Encode a dictionary
|
|
146
|
+
///**Parameters**
|
|
147
|
+
/// * `values` - parameter of type `Map<string, Value>`
|
|
148
|
+
///
|
|
149
|
+
///**Output Type**
|
|
150
|
+
/// * `Value`
|
|
151
|
+
///
|
|
152
|
+
///**Exceptions**
|
|
153
|
+
///
|
|
154
|
+
let dict (values: Map<string, JsonValue>) : JsonValue =
|
|
155
|
+
values |> Map.toList |> object
|
|
156
|
+
|
|
157
|
+
let bigint (value: bigint) : JsonValue = box (value.ToString())
|
|
158
|
+
|
|
159
|
+
let datetimeOffset (value: System.DateTimeOffset) : JsonValue =
|
|
160
|
+
value.ToString("O", CultureInfo.InvariantCulture) |> string
|
|
161
|
+
|
|
162
|
+
/// **Description**
|
|
163
|
+
/// Encode a timespan
|
|
164
|
+
/// **Parameters**
|
|
165
|
+
/// * `value` - parameter of type `System.TimeSpan`
|
|
166
|
+
///
|
|
167
|
+
/// **Output Type**
|
|
168
|
+
/// * `Value`
|
|
169
|
+
///
|
|
170
|
+
/// **Exceptions**
|
|
171
|
+
///
|
|
172
|
+
let timespan (value: System.TimeSpan) : JsonValue =
|
|
173
|
+
value.ToString() |> string
|
|
174
|
+
|
|
175
|
+
let inline sbyte (value: sbyte) : JsonValue = box value
|
|
176
|
+
|
|
177
|
+
let inline byte (value: byte) : JsonValue = box value
|
|
178
|
+
|
|
179
|
+
let inline int16 (value: int16) : JsonValue = box value
|
|
180
|
+
|
|
181
|
+
let inline uint16 (value: uint16) : JsonValue = box value
|
|
182
|
+
|
|
183
|
+
let inline int (value: int) : JsonValue = box value
|
|
184
|
+
|
|
185
|
+
let inline uint32 (value: uint32) : JsonValue = box value
|
|
186
|
+
|
|
187
|
+
let int64 (value: int64) : JsonValue =
|
|
188
|
+
box (value.ToString(CultureInfo.InvariantCulture))
|
|
189
|
+
|
|
190
|
+
let uint64 (value: uint64) : JsonValue =
|
|
191
|
+
box (value.ToString(CultureInfo.InvariantCulture))
|
|
192
|
+
|
|
193
|
+
let unit () : JsonValue = box null
|
|
194
|
+
|
|
195
|
+
let tuple2 (enc1: Encoder<'T1>) (enc2: Encoder<'T2>) (v1, v2) : JsonValue =
|
|
196
|
+
box
|
|
197
|
+
[|
|
|
198
|
+
enc1 v1
|
|
199
|
+
enc2 v2
|
|
200
|
+
|]
|
|
201
|
+
|
|
202
|
+
let tuple3
|
|
203
|
+
(enc1: Encoder<'T1>)
|
|
204
|
+
(enc2: Encoder<'T2>)
|
|
205
|
+
(enc3: Encoder<'T3>)
|
|
206
|
+
(v1, v2, v3)
|
|
207
|
+
: JsonValue
|
|
208
|
+
=
|
|
209
|
+
box
|
|
210
|
+
[|
|
|
211
|
+
enc1 v1
|
|
212
|
+
enc2 v2
|
|
213
|
+
enc3 v3
|
|
214
|
+
|]
|
|
215
|
+
|
|
216
|
+
let tuple4
|
|
217
|
+
(enc1: Encoder<'T1>)
|
|
218
|
+
(enc2: Encoder<'T2>)
|
|
219
|
+
(enc3: Encoder<'T3>)
|
|
220
|
+
(enc4: Encoder<'T4>)
|
|
221
|
+
(v1, v2, v3, v4)
|
|
222
|
+
: JsonValue
|
|
223
|
+
=
|
|
224
|
+
box
|
|
225
|
+
[|
|
|
226
|
+
enc1 v1
|
|
227
|
+
enc2 v2
|
|
228
|
+
enc3 v3
|
|
229
|
+
enc4 v4
|
|
230
|
+
|]
|
|
231
|
+
|
|
232
|
+
let tuple5
|
|
233
|
+
(enc1: Encoder<'T1>)
|
|
234
|
+
(enc2: Encoder<'T2>)
|
|
235
|
+
(enc3: Encoder<'T3>)
|
|
236
|
+
(enc4: Encoder<'T4>)
|
|
237
|
+
(enc5: Encoder<'T5>)
|
|
238
|
+
(v1, v2, v3, v4, v5)
|
|
239
|
+
: JsonValue
|
|
240
|
+
=
|
|
241
|
+
box
|
|
242
|
+
[|
|
|
243
|
+
enc1 v1
|
|
244
|
+
enc2 v2
|
|
245
|
+
enc3 v3
|
|
246
|
+
enc4 v4
|
|
247
|
+
enc5 v5
|
|
248
|
+
|]
|
|
249
|
+
|
|
250
|
+
let tuple6
|
|
251
|
+
(enc1: Encoder<'T1>)
|
|
252
|
+
(enc2: Encoder<'T2>)
|
|
253
|
+
(enc3: Encoder<'T3>)
|
|
254
|
+
(enc4: Encoder<'T4>)
|
|
255
|
+
(enc5: Encoder<'T5>)
|
|
256
|
+
(enc6: Encoder<'T6>)
|
|
257
|
+
(v1, v2, v3, v4, v5, v6)
|
|
258
|
+
: JsonValue
|
|
259
|
+
=
|
|
260
|
+
box
|
|
261
|
+
[|
|
|
262
|
+
enc1 v1
|
|
263
|
+
enc2 v2
|
|
264
|
+
enc3 v3
|
|
265
|
+
enc4 v4
|
|
266
|
+
enc5 v5
|
|
267
|
+
enc6 v6
|
|
268
|
+
|]
|
|
269
|
+
|
|
270
|
+
let tuple7
|
|
271
|
+
(enc1: Encoder<'T1>)
|
|
272
|
+
(enc2: Encoder<'T2>)
|
|
273
|
+
(enc3: Encoder<'T3>)
|
|
274
|
+
(enc4: Encoder<'T4>)
|
|
275
|
+
(enc5: Encoder<'T5>)
|
|
276
|
+
(enc6: Encoder<'T6>)
|
|
277
|
+
(enc7: Encoder<'T7>)
|
|
278
|
+
(v1, v2, v3, v4, v5, v6, v7)
|
|
279
|
+
: JsonValue
|
|
280
|
+
=
|
|
281
|
+
box
|
|
282
|
+
[|
|
|
283
|
+
enc1 v1
|
|
284
|
+
enc2 v2
|
|
285
|
+
enc3 v3
|
|
286
|
+
enc4 v4
|
|
287
|
+
enc5 v5
|
|
288
|
+
enc6 v6
|
|
289
|
+
enc7 v7
|
|
290
|
+
|]
|
|
291
|
+
|
|
292
|
+
let tuple8
|
|
293
|
+
(enc1: Encoder<'T1>)
|
|
294
|
+
(enc2: Encoder<'T2>)
|
|
295
|
+
(enc3: Encoder<'T3>)
|
|
296
|
+
(enc4: Encoder<'T4>)
|
|
297
|
+
(enc5: Encoder<'T5>)
|
|
298
|
+
(enc6: Encoder<'T6>)
|
|
299
|
+
(enc7: Encoder<'T7>)
|
|
300
|
+
(enc8: Encoder<'T8>)
|
|
301
|
+
(v1, v2, v3, v4, v5, v6, v7, v8)
|
|
302
|
+
: JsonValue
|
|
303
|
+
=
|
|
304
|
+
box
|
|
305
|
+
[|
|
|
306
|
+
enc1 v1
|
|
307
|
+
enc2 v2
|
|
308
|
+
enc3 v3
|
|
309
|
+
enc4 v4
|
|
310
|
+
enc5 v5
|
|
311
|
+
enc6 v6
|
|
312
|
+
enc7 v7
|
|
313
|
+
enc8 v8
|
|
314
|
+
|]
|
|
315
|
+
|
|
316
|
+
let map
|
|
317
|
+
(keyEncoder: Encoder<'key>)
|
|
318
|
+
(valueEncoder: Encoder<'value>)
|
|
319
|
+
(values: Map<'key, 'value>)
|
|
320
|
+
: JsonValue
|
|
321
|
+
=
|
|
322
|
+
values
|
|
323
|
+
|> Map.toList
|
|
324
|
+
|> List.map (tuple2 keyEncoder valueEncoder)
|
|
325
|
+
|> list
|
|
326
|
+
|
|
327
|
+
////////////
|
|
328
|
+
// Enum ///
|
|
329
|
+
/////////
|
|
330
|
+
|
|
331
|
+
module Enum =
|
|
332
|
+
|
|
333
|
+
let byte<'TEnum when 'TEnum: enum<byte>> (value: 'TEnum) : JsonValue =
|
|
334
|
+
LanguagePrimitives.EnumToValue value |> byte
|
|
335
|
+
|
|
336
|
+
let sbyte<'TEnum when 'TEnum: enum<sbyte>> (value: 'TEnum) : JsonValue =
|
|
337
|
+
LanguagePrimitives.EnumToValue value |> sbyte
|
|
338
|
+
|
|
339
|
+
let int16<'TEnum when 'TEnum: enum<int16>> (value: 'TEnum) : JsonValue =
|
|
340
|
+
LanguagePrimitives.EnumToValue value |> int16
|
|
341
|
+
|
|
342
|
+
let uint16<'TEnum when 'TEnum: enum<uint16>>
|
|
343
|
+
(value: 'TEnum)
|
|
344
|
+
: JsonValue
|
|
345
|
+
=
|
|
346
|
+
LanguagePrimitives.EnumToValue value |> uint16
|
|
347
|
+
|
|
348
|
+
let int<'TEnum when 'TEnum: enum<int>> (value: 'TEnum) : JsonValue =
|
|
349
|
+
LanguagePrimitives.EnumToValue value |> int
|
|
350
|
+
|
|
351
|
+
let uint32<'TEnum when 'TEnum: enum<uint32>>
|
|
352
|
+
(value: 'TEnum)
|
|
353
|
+
: JsonValue
|
|
354
|
+
=
|
|
355
|
+
LanguagePrimitives.EnumToValue value |> uint32
|
|
356
|
+
|
|
357
|
+
/// **Description**
|
|
358
|
+
///
|
|
359
|
+
/// The DateTime is always encoded using UTC representation
|
|
360
|
+
///
|
|
361
|
+
/// **Parameters**
|
|
362
|
+
/// * `value` - parameter of type `System.DateTime`
|
|
363
|
+
///
|
|
364
|
+
/// **Output Type**
|
|
365
|
+
/// * `Value`
|
|
366
|
+
///
|
|
367
|
+
/// **Exceptions**
|
|
368
|
+
///
|
|
369
|
+
let datetime (value: System.DateTime) : JsonValue =
|
|
370
|
+
value.ToString("O", CultureInfo.InvariantCulture) |> string
|
|
371
|
+
|
|
372
|
+
///**Description**
|
|
373
|
+
/// Convert a `Value` into a prettified string.
|
|
374
|
+
///**Parameters**
|
|
375
|
+
/// * `space` - parameter of type `int` - Amount of indentation
|
|
376
|
+
/// * `value` - parameter of type `obj` - Value to convert
|
|
377
|
+
///
|
|
378
|
+
///**Output Type**
|
|
379
|
+
/// * `string`
|
|
380
|
+
///
|
|
381
|
+
///**Exceptions**
|
|
382
|
+
///
|
|
383
|
+
let toString (space: int) (value: JsonValue) : string =
|
|
384
|
+
JS.JSON.stringify (value, space = space)
|
|
385
|
+
|
|
386
|
+
///**Description**
|
|
387
|
+
/// Encode an option
|
|
388
|
+
///**Parameters**
|
|
389
|
+
/// * `encoder` - parameter of type `'a -> Value`
|
|
390
|
+
///
|
|
391
|
+
///**Output Type**
|
|
392
|
+
/// * `'a option -> Value`
|
|
393
|
+
///
|
|
394
|
+
///**Exceptions**
|
|
395
|
+
///
|
|
396
|
+
let option (encoder: 'a -> JsonValue) =
|
|
397
|
+
Option.map encoder >> Option.defaultWith (fun _ -> nil)
|
|
398
|
+
|
|
399
|
+
//////////////////
|
|
400
|
+
// Reflection ///
|
|
401
|
+
////////////////
|
|
402
|
+
|
|
403
|
+
open FSharp.Reflection
|
|
404
|
+
open Fable.Core.DynamicExtensions
|
|
405
|
+
|
|
406
|
+
// As generics are erased by Fable, let's just do an unsafe cast for performance
|
|
407
|
+
let inline boxEncoder (d: Encoder<'T>) : BoxedEncoder = !!d
|
|
408
|
+
|
|
409
|
+
let inline unboxEncoder (d: BoxedEncoder) : Encoder<'T> = !!d
|
|
410
|
+
|
|
411
|
+
let rec private autoEncodeRecordsAndUnions
|
|
412
|
+
extra
|
|
413
|
+
(caseStrategy: CaseStrategy)
|
|
414
|
+
(skipNullField: bool)
|
|
415
|
+
(t: System.Type)
|
|
416
|
+
: BoxedEncoder
|
|
417
|
+
=
|
|
418
|
+
// Add the encoder to extra in case one of the fields is recursive
|
|
419
|
+
let encoderRef = ref Unchecked.defaultof<_>
|
|
420
|
+
|
|
421
|
+
let extra =
|
|
422
|
+
// As of 3.7.17 Fable assigns empty name to anonymous record, we shouldn't add them to the map to avoid conflicts.
|
|
423
|
+
// Anonymous records cannot be recursive anyways, see #144
|
|
424
|
+
match t.FullName with
|
|
425
|
+
| "" -> extra
|
|
426
|
+
| fullName -> extra |> Map.add fullName encoderRef
|
|
427
|
+
|
|
428
|
+
let encoder =
|
|
429
|
+
if
|
|
430
|
+
FSharpType.IsRecord(
|
|
431
|
+
t,
|
|
432
|
+
allowAccessToPrivateRepresentation = true
|
|
433
|
+
)
|
|
434
|
+
then
|
|
435
|
+
let setters =
|
|
436
|
+
FSharpType.GetRecordFields(
|
|
437
|
+
t,
|
|
438
|
+
allowAccessToPrivateRepresentation = true
|
|
439
|
+
)
|
|
440
|
+
|> Array.map (fun fi ->
|
|
441
|
+
let targetKey =
|
|
442
|
+
Util.Casing.convert caseStrategy fi.Name
|
|
443
|
+
|
|
444
|
+
let encode =
|
|
445
|
+
autoEncoder
|
|
446
|
+
extra
|
|
447
|
+
caseStrategy
|
|
448
|
+
skipNullField
|
|
449
|
+
fi.PropertyType
|
|
450
|
+
|
|
451
|
+
fun (source: obj) (target: JsonValue) ->
|
|
452
|
+
let value = FSharpValue.GetRecordField(source, fi)
|
|
453
|
+
|
|
454
|
+
if
|
|
455
|
+
not skipNullField
|
|
456
|
+
|| (skipNullField && not (isNull value))
|
|
457
|
+
then // Discard null fields
|
|
458
|
+
target.[targetKey] <- encode value
|
|
459
|
+
|
|
460
|
+
target
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
fun (source: obj) ->
|
|
464
|
+
(JsonValue(), setters)
|
|
465
|
+
||> Seq.fold (fun target set -> set source target)
|
|
466
|
+
elif
|
|
467
|
+
FSharpType.IsUnion(t, allowAccessToPrivateRepresentation = true)
|
|
468
|
+
then
|
|
469
|
+
fun (value: obj) ->
|
|
470
|
+
let info, fields =
|
|
471
|
+
FSharpValue.GetUnionFields(
|
|
472
|
+
value,
|
|
473
|
+
t,
|
|
474
|
+
allowAccessToPrivateRepresentation = true
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
match fields.Length with
|
|
478
|
+
| 0 -> string info.Name
|
|
479
|
+
| len ->
|
|
480
|
+
let fieldTypes = info.GetFields()
|
|
481
|
+
let target = Array.zeroCreate<JsonValue> (len + 1)
|
|
482
|
+
target.[0] <- string info.Name
|
|
483
|
+
|
|
484
|
+
for i = 1 to len do
|
|
485
|
+
let encode =
|
|
486
|
+
autoEncoder
|
|
487
|
+
extra
|
|
488
|
+
caseStrategy
|
|
489
|
+
skipNullField
|
|
490
|
+
fieldTypes.[i - 1].PropertyType
|
|
491
|
+
|
|
492
|
+
target.[i] <- encode fields.[i - 1]
|
|
493
|
+
|
|
494
|
+
array target
|
|
495
|
+
else
|
|
496
|
+
// Don't use failwithf here, for some reason F#/Fable compiles it as a function
|
|
497
|
+
// when the return type is a function too, so it doesn't fail immediately
|
|
498
|
+
sprintf
|
|
499
|
+
"""Cannot generate auto encoder for %s. Please pass an extra encoder.
|
|
500
|
+
|
|
501
|
+
Documentation available at: https://thoth-org.github.io/Thoth.Json/documentation/auto/extra-coders.html#ready-to-use-extra-coders"""
|
|
502
|
+
t.FullName
|
|
503
|
+
|> failwith
|
|
504
|
+
|
|
505
|
+
encoderRef.Value <- encoder
|
|
506
|
+
encoder
|
|
507
|
+
|
|
508
|
+
and private autoEncoder
|
|
509
|
+
(extra: Map<string, ref<BoxedEncoder>>)
|
|
510
|
+
caseStrategy
|
|
511
|
+
(skipNullField: bool)
|
|
512
|
+
(t: System.Type)
|
|
513
|
+
: BoxedEncoder
|
|
514
|
+
=
|
|
515
|
+
let fullname = t.FullName
|
|
516
|
+
|
|
517
|
+
match Map.tryFind fullname extra with
|
|
518
|
+
| Some encoderRef -> fun v -> encoderRef.contents v
|
|
519
|
+
| None ->
|
|
520
|
+
if t.IsArray then
|
|
521
|
+
let encoder =
|
|
522
|
+
t.GetElementType()
|
|
523
|
+
|> autoEncoder extra caseStrategy skipNullField
|
|
524
|
+
|
|
525
|
+
fun (value: obj) -> value :?> obj seq |> Seq.map encoder |> seq
|
|
526
|
+
elif t.IsEnum then
|
|
527
|
+
let enumType = System.Enum.GetUnderlyingType(t).FullName
|
|
528
|
+
|
|
529
|
+
if enumType = typeof<sbyte>.FullName then
|
|
530
|
+
boxEncoder sbyte
|
|
531
|
+
elif enumType = typeof<byte>.FullName then
|
|
532
|
+
boxEncoder byte
|
|
533
|
+
elif enumType = typeof<int16>.FullName then
|
|
534
|
+
boxEncoder int16
|
|
535
|
+
elif enumType = typeof<uint16>.FullName then
|
|
536
|
+
boxEncoder uint16
|
|
537
|
+
elif enumType = typeof<int>.FullName then
|
|
538
|
+
boxEncoder int
|
|
539
|
+
elif enumType = typeof<uint32>.FullName then
|
|
540
|
+
boxEncoder uint32
|
|
541
|
+
else
|
|
542
|
+
failwithf
|
|
543
|
+
"""Cannot generate auto encoder for %s.
|
|
544
|
+
Thoth.Json.Net only support the following enum types:
|
|
545
|
+
- sbyte
|
|
546
|
+
- byte
|
|
547
|
+
- int16
|
|
548
|
+
- uint16
|
|
549
|
+
- int
|
|
550
|
+
- uint32
|
|
551
|
+
|
|
552
|
+
If you can't use one of these types, please pass an extra encoder.
|
|
553
|
+
|
|
554
|
+
Documentation available at: https://thoth-org.github.io/Thoth.Json/documentation/auto/extra-coders.html#ready-to-use-extra-coders
|
|
555
|
+
"""
|
|
556
|
+
t.FullName
|
|
557
|
+
elif t.IsGenericType then
|
|
558
|
+
if FSharpType.IsTuple(t) then
|
|
559
|
+
let encoders =
|
|
560
|
+
FSharpType.GetTupleElements(t)
|
|
561
|
+
|> Array.map (
|
|
562
|
+
autoEncoder extra caseStrategy skipNullField
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
fun (value: obj) ->
|
|
566
|
+
FSharpValue.GetTupleFields(value)
|
|
567
|
+
|> Seq.mapi (fun i x -> encoders.[i] x)
|
|
568
|
+
|> seq
|
|
569
|
+
else
|
|
570
|
+
let fullname = t.GetGenericTypeDefinition().FullName
|
|
571
|
+
|
|
572
|
+
if fullname = typedefof<obj option>.FullName then
|
|
573
|
+
// Evaluate lazily so we don't need to generate the encoder for null values
|
|
574
|
+
let encoder =
|
|
575
|
+
lazy
|
|
576
|
+
t.GenericTypeArguments.[0]
|
|
577
|
+
|> autoEncoder extra caseStrategy skipNullField
|
|
578
|
+
|> option
|
|
579
|
+
|> boxEncoder
|
|
580
|
+
|
|
581
|
+
boxEncoder (fun (value: obj) ->
|
|
582
|
+
if isNull value then
|
|
583
|
+
nil
|
|
584
|
+
else
|
|
585
|
+
encoder.Value value
|
|
586
|
+
)
|
|
587
|
+
elif
|
|
588
|
+
fullname = typedefof<obj list>.FullName
|
|
589
|
+
|| fullname = typedefof<Set<string>>.FullName
|
|
590
|
+
|| fullname = typedefof<obj seq>.FullName
|
|
591
|
+
then
|
|
592
|
+
let encoder =
|
|
593
|
+
t.GenericTypeArguments.[0]
|
|
594
|
+
|> autoEncoder extra caseStrategy skipNullField
|
|
595
|
+
|
|
596
|
+
fun (value: obj) ->
|
|
597
|
+
value :?> obj seq |> Seq.map encoder |> seq
|
|
598
|
+
elif fullname = typedefof<Map<string, obj>>.FullName then
|
|
599
|
+
let keyType = t.GenericTypeArguments.[0]
|
|
600
|
+
|
|
601
|
+
let valueEncoder =
|
|
602
|
+
t.GenericTypeArguments.[1]
|
|
603
|
+
|> autoEncoder extra caseStrategy skipNullField
|
|
604
|
+
|
|
605
|
+
if
|
|
606
|
+
keyType.FullName = typeof<string>.FullName
|
|
607
|
+
|| keyType.FullName = typeof<System.Guid>.FullName
|
|
608
|
+
then
|
|
609
|
+
fun value ->
|
|
610
|
+
// Fable compiles Guids as strings so this works, but maybe we should make the conversion explicit
|
|
611
|
+
// (see dotnet version) in case Fable implementation of Guids change
|
|
612
|
+
(JsonValue(), value :?> Map<string, obj>)
|
|
613
|
+
||> Seq.fold (fun target (KeyValue(k, v)) ->
|
|
614
|
+
target.[k] <- valueEncoder v
|
|
615
|
+
target
|
|
616
|
+
)
|
|
617
|
+
else
|
|
618
|
+
let keyEncoder =
|
|
619
|
+
keyType
|
|
620
|
+
|> autoEncoder extra caseStrategy skipNullField
|
|
621
|
+
|
|
622
|
+
fun value ->
|
|
623
|
+
value :?> Map<string, obj>
|
|
624
|
+
|> Seq.map (fun (KeyValue(k, v)) ->
|
|
625
|
+
array
|
|
626
|
+
[|
|
|
627
|
+
keyEncoder k
|
|
628
|
+
valueEncoder v
|
|
629
|
+
|]
|
|
630
|
+
)
|
|
631
|
+
|> seq
|
|
632
|
+
else
|
|
633
|
+
autoEncodeRecordsAndUnions
|
|
634
|
+
extra
|
|
635
|
+
caseStrategy
|
|
636
|
+
skipNullField
|
|
637
|
+
t
|
|
638
|
+
else if fullname = typeof<bool>.FullName then
|
|
639
|
+
boxEncoder bool
|
|
640
|
+
elif fullname = typeof<unit>.FullName then
|
|
641
|
+
boxEncoder unit
|
|
642
|
+
elif fullname = typeof<string>.FullName then
|
|
643
|
+
boxEncoder string
|
|
644
|
+
elif fullname = typeof<char>.FullName then
|
|
645
|
+
boxEncoder char
|
|
646
|
+
elif fullname = typeof<sbyte>.FullName then
|
|
647
|
+
boxEncoder sbyte
|
|
648
|
+
elif fullname = typeof<byte>.FullName then
|
|
649
|
+
boxEncoder byte
|
|
650
|
+
elif fullname = typeof<int16>.FullName then
|
|
651
|
+
boxEncoder int16
|
|
652
|
+
elif fullname = typeof<uint16>.FullName then
|
|
653
|
+
boxEncoder uint16
|
|
654
|
+
elif fullname = typeof<int>.FullName then
|
|
655
|
+
boxEncoder int
|
|
656
|
+
elif fullname = typeof<uint32>.FullName then
|
|
657
|
+
boxEncoder uint32
|
|
658
|
+
elif fullname = typeof<float>.FullName then
|
|
659
|
+
boxEncoder float
|
|
660
|
+
elif fullname = typeof<float32>.FullName then
|
|
661
|
+
boxEncoder float32
|
|
662
|
+
// These number types require extra libraries in Fable. To prevent penalizing
|
|
663
|
+
// all users, extra encoders (withInt64, etc) must be passed when they're needed.
|
|
664
|
+
|
|
665
|
+
// elif fullname = typeof<int64>.FullName then
|
|
666
|
+
// boxEncoder int64
|
|
667
|
+
// elif fullname = typeof<uint64>.FullName then
|
|
668
|
+
// boxEncoder uint64
|
|
669
|
+
// elif fullname = typeof<bigint>.FullName then
|
|
670
|
+
// boxEncoder bigint
|
|
671
|
+
// elif fullname = typeof<decimal>.FullName then
|
|
672
|
+
// boxEncoder decimal
|
|
673
|
+
elif fullname = typeof<System.DateTime>.FullName then
|
|
674
|
+
boxEncoder datetime
|
|
675
|
+
elif fullname = typeof<System.DateTimeOffset>.FullName then
|
|
676
|
+
boxEncoder datetimeOffset
|
|
677
|
+
elif fullname = typeof<System.TimeSpan>.FullName then
|
|
678
|
+
boxEncoder timespan
|
|
679
|
+
elif fullname = typeof<System.Guid>.FullName then
|
|
680
|
+
boxEncoder guid
|
|
681
|
+
elif fullname = typeof<obj>.FullName then
|
|
682
|
+
boxEncoder id
|
|
683
|
+
else
|
|
684
|
+
autoEncodeRecordsAndUnions extra caseStrategy skipNullField t
|
|
685
|
+
|
|
686
|
+
let private makeExtra (extra: ExtraCoders option) =
|
|
687
|
+
match extra with
|
|
688
|
+
| None -> Map.empty
|
|
689
|
+
| Some e -> Map.map (fun _ (enc, _) -> ref enc) e.Coders
|
|
690
|
+
|
|
691
|
+
type Auto =
|
|
692
|
+
static member generateBoxedEncoderCached
|
|
693
|
+
(
|
|
694
|
+
t: System.Type,
|
|
695
|
+
?caseStrategy: CaseStrategy,
|
|
696
|
+
?extra: ExtraCoders,
|
|
697
|
+
?skipNullField: bool
|
|
698
|
+
)
|
|
699
|
+
: BoxedEncoder
|
|
700
|
+
=
|
|
701
|
+
let caseStrategy = defaultArg caseStrategy PascalCase
|
|
702
|
+
let skipNullField = defaultArg skipNullField true
|
|
703
|
+
|
|
704
|
+
let key =
|
|
705
|
+
t.FullName
|
|
706
|
+
|> (+) (Operators.string caseStrategy)
|
|
707
|
+
|> (+) (
|
|
708
|
+
extra
|
|
709
|
+
|> Option.map (fun e -> e.Hash)
|
|
710
|
+
|> Option.defaultValue ""
|
|
711
|
+
)
|
|
712
|
+
|
|
713
|
+
Util.CachedEncoders.GetOrAdd(
|
|
714
|
+
key,
|
|
715
|
+
fun _ ->
|
|
716
|
+
autoEncoder (makeExtra extra) caseStrategy skipNullField t
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
static member inline generateEncoderCached<'T>
|
|
720
|
+
(
|
|
721
|
+
?caseStrategy: CaseStrategy,
|
|
722
|
+
?extra: ExtraCoders,
|
|
723
|
+
?skipNullField: bool
|
|
724
|
+
)
|
|
725
|
+
: Encoder<'T>
|
|
726
|
+
=
|
|
727
|
+
Auto.generateBoxedEncoderCached (
|
|
728
|
+
typeof<'T>,
|
|
729
|
+
?caseStrategy = caseStrategy,
|
|
730
|
+
?extra = extra
|
|
731
|
+
)
|
|
732
|
+
|> unboxEncoder
|
|
733
|
+
|
|
734
|
+
static member generateBoxedEncoder
|
|
735
|
+
(
|
|
736
|
+
t: System.Type,
|
|
737
|
+
?caseStrategy: CaseStrategy,
|
|
738
|
+
?extra: ExtraCoders,
|
|
739
|
+
?skipNullField: bool
|
|
740
|
+
)
|
|
741
|
+
: BoxedEncoder
|
|
742
|
+
=
|
|
743
|
+
let caseStrategy = defaultArg caseStrategy PascalCase
|
|
744
|
+
let skipNullField = defaultArg skipNullField true
|
|
745
|
+
autoEncoder (makeExtra extra) caseStrategy skipNullField t
|
|
746
|
+
|
|
747
|
+
static member inline generateEncoder<'T>
|
|
748
|
+
(
|
|
749
|
+
?caseStrategy: CaseStrategy,
|
|
750
|
+
?extra: ExtraCoders,
|
|
751
|
+
?skipNullField: bool
|
|
752
|
+
)
|
|
753
|
+
: Encoder<'T>
|
|
754
|
+
=
|
|
755
|
+
Auto.generateBoxedEncoder (
|
|
756
|
+
typeof<'T>,
|
|
757
|
+
?caseStrategy = caseStrategy,
|
|
758
|
+
?extra = extra,
|
|
759
|
+
?skipNullField = skipNullField
|
|
760
|
+
)
|
|
761
|
+
|> unboxEncoder
|
|
762
|
+
|
|
763
|
+
static member inline toString
|
|
764
|
+
(
|
|
765
|
+
space: int,
|
|
766
|
+
value: 'T,
|
|
767
|
+
?caseStrategy: CaseStrategy,
|
|
768
|
+
?extra: ExtraCoders,
|
|
769
|
+
?skipNullField: bool
|
|
770
|
+
)
|
|
771
|
+
: string
|
|
772
|
+
=
|
|
773
|
+
let encoder =
|
|
774
|
+
Auto.generateEncoder (
|
|
775
|
+
?caseStrategy = caseStrategy,
|
|
776
|
+
?extra = extra,
|
|
777
|
+
?skipNullField = skipNullField
|
|
778
|
+
)
|
|
779
|
+
|
|
780
|
+
encoder value |> toString space
|
|
781
|
+
|
|
782
|
+
static member inline toString
|
|
783
|
+
(
|
|
784
|
+
value: 'T,
|
|
785
|
+
?caseStrategy: CaseStrategy,
|
|
786
|
+
?extra: ExtraCoders,
|
|
787
|
+
?skipNullField: bool
|
|
788
|
+
)
|
|
789
|
+
: string
|
|
790
|
+
=
|
|
791
|
+
Auto.toString (
|
|
792
|
+
0,
|
|
793
|
+
value,
|
|
794
|
+
?caseStrategy = caseStrategy,
|
|
795
|
+
?extra = extra,
|
|
796
|
+
?skipNullField = skipNullField
|
|
797
|
+
)
|
|
798
|
+
|
|
799
|
+
///**Description**
|
|
800
|
+
/// Convert a `Value` into a prettified string.
|
|
801
|
+
///**Parameters**
|
|
802
|
+
/// * `space` - parameter of type `int` - Amount of indentation
|
|
803
|
+
/// * `value` - parameter of type `obj` - Value to convert
|
|
804
|
+
///
|
|
805
|
+
///**Output Type**
|
|
806
|
+
/// * `string`
|
|
807
|
+
///
|
|
808
|
+
///**Exceptions**
|
|
809
|
+
///
|
|
810
|
+
[<System.Obsolete("Please use toString instead")>]
|
|
811
|
+
let encode (space: int) (value: JsonValue) : string = toString space value
|