@greenlabs/ppx-spice 0.1.15 → 0.2.0-next.0

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,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Compat the untagged variant
8
+
3
9
  ## 0.1.15
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greenlabs/ppx-spice",
3
- "version": "0.1.15",
3
+ "version": "0.2.0-next.0",
4
4
  "description": "ReScript PPX which generate JSON (de)serializer",
5
5
  "license": "MIT",
6
6
  "author": "Greenlabs Dev <developer@greenlabs.co.kr>",
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "postinstall": "node ./postInstall.js"
20
20
  },
21
- "dependencies": {
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
@@ -17,17 +17,17 @@ let error = (~path=?, message, value) => {
17
17
  Belt.Result.Error({path, message, value})
18
18
  }
19
19
 
20
- let stringToJson = s => Js.Json.string(s)
20
+ let stringToJson = (s): Js.Json.t => Js.Json.String(s)
21
21
  let stringFromJson = j =>
22
- switch Js.Json.decodeString(j) {
23
- | Some(s) => Belt.Result.Ok(s)
24
- | None => Belt.Result.Error({path: "", message: "Not a string", value: j})
22
+ switch (j: Js.Json.t) {
23
+ | Js.Json.String(s) => Belt.Result.Ok(s)
24
+ | _ => Belt.Result.Error({path: "", message: "Not a string", value: j})
25
25
  }
26
26
 
27
- let intToJson = i => Js.Json.number(float_of_int(i))
27
+ let intToJson = (i): Js.Json.t => Js.Json.Number(float_of_int(i))
28
28
  let intFromJson = j =>
29
- switch Js.Json.decodeNumber(j) {
30
- | Some(f) =>
29
+ switch (j: Js.Json.t) {
30
+ | Js.Json.Number(f) =>
31
31
  float_of_int(Js.Math.floor(f)) == f
32
32
  ? Belt.Result.Ok(Js.Math.floor(f))
33
33
  : Belt.Result.Error({path: "", message: "Not an integer", value: j})
@@ -35,44 +35,49 @@ let intFromJson = j =>
35
35
  | _ => Belt.Result.Error({path: "", message: "Not a number", value: j})
36
36
  }
37
37
 
38
- let int64ToJson = i => Js.Json.number(Int64.float_of_bits(i))
38
+ let int64ToJson = (i): Js.Json.t => Js.Json.Number(Int64.float_of_bits(i))
39
39
 
40
40
  let int64FromJson = j =>
41
- switch Js.Json.decodeNumber(j) {
42
- | Some(n) => Belt.Result.Ok(Int64.bits_of_float(n))
43
- | None => error("Not a number", j)
41
+ switch (j: Js.Json.t) {
42
+ | Js.Json.Number(n) => Belt.Result.Ok(Int64.bits_of_float(n))
43
+ | _ => error("Not a number", j)
44
44
  }
45
45
 
46
- let int64ToJsonUnsafe = i => Js.Json.number(Int64.to_float(i))
46
+ let int64ToJsonUnsafe = (i): Js.Json.t => Js.Json.number(Int64.to_float(i))
47
47
 
48
48
  let int64FromJsonUnsafe = j =>
49
- switch Js.Json.decodeNumber(j) {
50
- | Some(n) => Belt.Result.Ok(Int64.of_float(n))
51
- | None => error("Not a number", j)
49
+ switch (j: Js.Json.t) {
50
+ | Js.Json.Number(n) => Belt.Result.Ok(Int64.of_float(n))
51
+ | _ => error("Not a number", j)
52
52
  }
53
53
 
54
- let floatToJson = v => Js.Json.number(v)
54
+ let floatToJson = (v): Js.Json.t => Js.Json.Number(v)
55
55
  let floatFromJson = j =>
56
- switch Js.Json.decodeNumber(j) {
57
- | Some(f) => Belt.Result.Ok(f)
58
- | None => Belt.Result.Error({path: "", message: "Not a number", value: j})
56
+ switch (j: Js.Json.t) {
57
+ | Js.Json.Number(f) => Belt.Result.Ok(f)
58
+ | _ => Belt.Result.Error({path: "", message: "Not a number", value: j})
59
59
  }
60
60
 
61
- let boolToJson = v => Js.Json.boolean(v)
61
+ let boolToJson = (v): Js.Json.t =>
62
+ switch v {
63
+ | true => Js.Json.True
64
+ | false => Js.Json.False
65
+ }
62
66
  let boolFromJson = j =>
63
- switch Js.Json.decodeBoolean(j) {
64
- | Some(b) => Belt.Result.Ok(b)
65
- | None => Belt.Result.Error({path: "", message: "Not a boolean", value: j})
67
+ switch (j: Js.Json.t) {
68
+ | Js.Json.True => Belt.Result.Ok(true)
69
+ | Js.Json.False => Belt.Result.Ok(false)
70
+ | _ => Belt.Result.Error({path: "", message: "Not a boolean", value: j})
66
71
  }
67
72
 
68
- let unitToJson = () => Js.Json.number(0.0)
73
+ let unitToJson = (): Js.Json.t => Js.Json.Number(0.0)
69
74
  let unitFromJson = _ => Belt.Result.Ok()
70
75
 
71
- let arrayToJson = (encoder, arr) => Js.Json.array(Js.Array.map(encoder, arr))
76
+ let arrayToJson = (encoder, arr): Js.Json.t => Js.Json.Array(Js.Array.map(encoder, arr))
72
77
 
73
78
  let arrayFromJson = (decoder, json) =>
74
- switch Js.Json.decodeArray(json) {
75
- | Some(arr) => Js.Array.reducei((acc, jsonI, i) =>
79
+ switch (json: Js.Json.t) {
80
+ | Js.Json.Array(arr) => Js.Array.reducei((acc, jsonI, i) =>
76
81
  switch (acc, decoder(jsonI)) {
77
82
  | (Belt.Result.Error(_), _) => acc
78
83
 
@@ -84,7 +89,7 @@ let arrayFromJson = (decoder, json) =>
84
89
  }
85
90
  , Belt.Result.Ok([]), arr)
86
91
 
87
- | None => Belt.Result.Error({path: "", message: "Not an array", value: json})
92
+ | _ => Belt.Result.Error({path: "", message: "Not an array", value: json})
88
93
  }
89
94
 
90
95
  let listToJson = (encoder, list) => arrayToJson(encoder, Belt.List.toArray(list))
@@ -98,50 +103,49 @@ let filterOptional = arr =>
98
103
  ((k, _, v)) => (k, v),
99
104
  )
100
105
 
101
- let optionToJson = (encoder, opt) =>
106
+ let optionToJson = (encoder, opt): Js.Json.t =>
102
107
  switch opt {
103
108
  | Some(x) => encoder(x)
104
- | None => Js.Json.null
109
+ | None => Js.Json.Null
105
110
  }
106
111
 
107
112
  let optionFromJson = (decoder, json) =>
108
- switch Js.Json.decodeNull(json) {
109
- | Some(_) => Belt.Result.Ok(None)
110
- | None => Belt.Result.map(decoder(json), v => Some(v))
113
+ switch (json: Js.Json.t) {
114
+ | Js.Json.Null => Belt.Result.Ok(None)
115
+ | _ => Belt.Result.map(decoder(json), v => Some(v))
111
116
  }
112
117
 
113
- let resultToJson = (okEncoder, errorEncoder, result) =>
114
- Js.Json.array(
115
- switch result {
116
- | Belt.Result.Ok(v) => [Js.Json.string("Ok"), okEncoder(v)]
117
- | Belt.Result.Error(e) => [Js.Json.string("Error"), errorEncoder(e)]
118
- },
119
- )
118
+ let resultToJson = (okEncoder, errorEncoder, result): Js.Json.t => Js.Json.Array(
119
+ switch result {
120
+ | Belt.Result.Ok(v) => [Js.Json.String("Ok"), okEncoder(v)]
121
+ | Belt.Result.Error(e) => [Js.Json.String("Error"), errorEncoder(e)]
122
+ },
123
+ )
120
124
 
121
125
  let resultFromJson = (okDecoder, errorDecoder, json) =>
122
- switch Js.Json.decodeArray(json) {
123
- | Some([variantConstructorId, payload]) =>
124
- switch Js.Json.decodeString(variantConstructorId) {
125
- | Some("Ok") => okDecoder(payload)->Belt.Result.map(v => Belt.Result.Ok(v))
126
+ switch (json: Js.Json.t) {
127
+ | Js.Json.Array([variantConstructorId, payload]) =>
128
+ switch variantConstructorId {
129
+ | Js.Json.String("Ok") => okDecoder(payload)->Belt.Result.map(v => Belt.Result.Ok(v))
126
130
 
127
- | Some("Error") =>
131
+ | Js.Json.String("Error") =>
128
132
  switch errorDecoder(payload) {
129
133
  | Belt.Result.Ok(v) => Belt.Result.Ok(Belt.Result.Error(v))
130
134
  | Belt.Result.Error(e) => Belt.Result.Error(e)
131
135
  }
132
136
 
133
- | Some(_) => error("Expected either \"Ok\" or \"Error\"", variantConstructorId)
134
- | None => error("Not a string", variantConstructorId)
137
+ | Js.Json.String(_) => error("Expected either \"Ok\" or \"Error\"", variantConstructorId)
138
+ | _ => error("Not a string", variantConstructorId)
135
139
  }
136
- | Some(_) => error("Expected exactly 2 values in array", json)
137
- | None => error("Not an array", json)
140
+ | Js.Json.Array(_) => error("Expected exactly 2 values in array", json)
141
+ | _ => error("Not an array", json)
138
142
  }
139
143
 
140
- let dictToJson = (encoder, dict) => Js.Json.object_(Js.Dict.map(a => encoder(a), dict))
144
+ let dictToJson = (encoder, dict): Js.Json.t => Js.Json.Object(Js.Dict.map((. a) => encoder(a), dict))
141
145
 
142
146
  let dictFromJson = (decoder, json) =>
143
- switch Js.Json.decodeObject(json) {
144
- | Some(dict) =>
147
+ switch (json: Js.Json.t) {
148
+ | Js.Json.Object(dict) =>
145
149
  dict
146
150
  ->Js.Dict.entries
147
151
  ->Belt.Array.reduce(Ok(Js.Dict.empty()), (acc, (key, value)) =>
@@ -155,7 +159,7 @@ let dictFromJson = (decoder, json) =>
155
159
  Ok(prev)
156
160
  }
157
161
  )
158
- | None => Error({path: "", message: "Not a dict", value: json})
162
+ | _ => Error({path: "", message: "Not a dict", value: json})
159
163
  }
160
164
 
161
165
  module Codecs = {
@@ -1,11 +1,11 @@
1
1
  let falseableEncode = (encoder, opt) =>
2
2
  switch opt {
3
- | None => Js.Json.boolean(false)
3
+ | None => Js.Json.False
4
4
  | Some(v) => encoder(v)
5
5
  }
6
6
  let falseableDecode = (decoder, json) =>
7
- switch Js.Json.decodeBoolean(json) {
8
- | Some(false) => Belt.Result.Ok(None)
7
+ switch json {
8
+ | Js.Json.False => Belt.Result.Ok(None)
9
9
  | _ => Belt.Result.map(decoder(json), v => Some(v))
10
10
  }
11
11
  let falseable = (falseableEncode, falseableDecode)
@@ -1,8 +0,0 @@
1
- # Changesets
2
-
3
- Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
- with multi-package repos, or single-package repos to help you version and publish your code. You can
5
- find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6
-
7
- We have a quick list of common questions to get you started engaging with this project in
8
- [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
3
- "changelog": "@changesets/cli/changelog",
4
- "commit": false,
5
- "fixed": [],
6
- "linked": [],
7
- "access": "restricted",
8
- "baseBranch": "main",
9
- "updateInternalDependencies": "patch",
10
- "ignore": []
11
- }