@greenlabs/ppx-spice 0.2.1-rc.2 → 0.2.2

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/CHANGELOG.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.2.1 (unreleased)
3
+ ## 0.2.3 (unreleased)
4
+
5
+ ## 0.2.2
6
+
7
+ - Support Null https://github.com/green-labs/ppx_spice/pull/80
8
+
9
+ ## 0.2.1
4
10
 
5
11
  - a190663 Utilize Js.Json.Boolean(bool) instead oif Js.Json.True, False https://github.com/green-labs/ppx_spice/pull/58
6
12
  - a190663 Add support of uncurried mode for interface(*.resi) https://github.com/green-labs/ppx_spice/pull/58
7
13
  - Support the compiler v11-rc.5 https://github.com/green-labs/ppx_spice/pull/61
8
14
  - Add the feature of encoding/decoding between the number and (polymorphic)variant with `@spice.as` https://github.com/green-labs/ppx_spice/pull/64
15
+ - Fix generating encode, decode function when `@spice.as` with number https://github.com/green-labs/ppx_spice/pull/74
9
16
 
10
17
  ## 0.2.0
11
18
 
package/README.md CHANGED
@@ -183,11 +183,11 @@ Make sure running tests in `/test`
183
183
  cd test
184
184
 
185
185
  (install dependencies)
186
- yarn
186
+ pnpm install
187
187
 
188
188
  (build --watch)
189
- yarn res:clean && yarn res:watch
189
+ pnpm res:clean && pnpm res:watch
190
190
 
191
191
  (run test --watch)
192
- yarn test:watch
192
+ pnpm test:watch
193
193
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greenlabs/ppx-spice",
3
- "version": "0.2.1-rc.2",
3
+ "version": "0.2.2",
4
4
  "description": "ReScript PPX which generate JSON (de)serializer",
5
5
  "license": "MIT",
6
6
  "author": "Greenlabs Dev <developer@greenlabs.co.kr>",
@@ -21,4 +21,4 @@
21
21
  "devDependencies": {
22
22
  "@changesets/cli": "^2.26.2"
23
23
  }
24
- }
24
+ }
package/ppx-linux.exe CHANGED
Binary file
package/ppx-osx.exe CHANGED
Binary file
package/ppx-windows.exe CHANGED
Binary file
@@ -98,15 +98,15 @@ let listFromJson = (decoder, json) =>
98
98
  Belt.Result.map(arrayFromJson(decoder, json), Belt.List.fromArray)
99
99
 
100
100
  let filterOptional = arr =>
101
- Belt.Array.map(
102
- Belt.Array.keep(arr, ((_, isOptional, x)) => !(isOptional && x == Js.Json.null)),
103
- ((k, _, v)) => (k, v),
104
- )
101
+ Belt.Array.keepMap(arr, ((k, v)) => switch v {
102
+ | Some(v) => Some(k, v)
103
+ | None => None
104
+ })
105
105
 
106
- let optionToJson = (encoder, opt): Js.Json.t =>
106
+ let optionToJson = (encoder, opt): option<Js.Json.t> =>
107
107
  switch opt {
108
- | Some(x) => encoder(x)
109
- | None => Js.Json.Null
108
+ | Some(x) => Some(encoder(x))
109
+ | None => None
110
110
  }
111
111
 
112
112
  let optionFromJson = (decoder, json) =>
@@ -115,6 +115,18 @@ let optionFromJson = (decoder, json) =>
115
115
  | _ => Belt.Result.map(decoder(json), v => Some(v))
116
116
  }
117
117
 
118
+ let nullToJson = (encoder, opt): Js.Json.t =>
119
+ switch opt {
120
+ | Js.Null.Value(x) => encoder(x)
121
+ | Null => Js.Json.Null
122
+ }
123
+
124
+ let nullFromJson = (decoder, json) =>
125
+ switch (json: Js.Json.t) {
126
+ | Js.Json.Null => Ok(Js.Null.Null)
127
+ | _ => Belt.Result.map(decoder(json), v => Js.Null.Value(v))
128
+ }
129
+
118
130
  let resultToJson = (okEncoder, errorEncoder, result): Js.Json.t => Js.Json.Array(
119
131
  switch result {
120
132
  | Ok(v) => [Js.Json.String("Ok"), okEncoder(v)]
Binary file