Skip to content

Commit 22d4531

Browse files
committed
gleam update
1 parent dea64fd commit 22d4531

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

manifest.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_javascript", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "6EB652538B31E852FE0A8307A8B6314DEB34930944B6DDC41CCC31CA344DA35D" },
6-
{ name = "gleam_json", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB10B0E7BF44282FB25162F1A24C1A025F6B93E777CCF238C4017E4EEF2CDE97" },
7-
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
5+
{ name = "gleam_javascript", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "F98328FCF573DA6F3A35D7F6CB3F9FF19FD5224CCBA9151FCBEAA0B983AF2F58" },
6+
{ name = "gleam_json", version = "2.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "C55C5C2B318533A8072D221C5E06E5A75711C129E420DD1CE463342106012E5D" },
7+
{ name = "gleam_stdlib", version = "0.53.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "53F3E1E56F692C20FA3E0A23650AC46592464E40D8EF3EC7F364FB328E73CDF5" },
88
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
99
]
1010

src/wechat/object.gleam

+15-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
////
2323

2424
import gleam/dict.{type Dict}
25-
import gleam/dynamic.{type DecodeErrors, type Decoder, type Dynamic}
25+
import gleam/dynamic.{type Dynamic}
26+
import gleam/dynamic/decode.{type DecodeError, type Decoder}
2627
import gleam/json.{type Json}
2728
import gleam/list
2829
import gleam/result
@@ -34,6 +35,8 @@ pub type JsObject {
3435
JsObject
3536
}
3637

38+
pub type DecodeErrors = List(DecodeError)
39+
3740
/// error constructors
3841
///
3942
pub type WechatError {
@@ -160,7 +163,7 @@ pub fn literal(ls: List(#(k, v))) -> JsObject {
160163
pub fn int(o: JsObject) -> Result(Int, WechatError) {
161164
o
162165
|> dynamic
163-
|> dynamic.int
166+
|> decode.run(decode.int)
164167
|> result.map_error(WechatDecodeError(_))
165168
}
166169

@@ -169,7 +172,7 @@ pub fn int(o: JsObject) -> Result(Int, WechatError) {
169172
pub fn float(o: JsObject) -> Result(Float, WechatError) {
170173
o
171174
|> dynamic
172-
|> dynamic.float
175+
|> decode.run(decode.float)
173176
|> result.map_error(WechatDecodeError(_))
174177
}
175178

@@ -178,7 +181,7 @@ pub fn float(o: JsObject) -> Result(Float, WechatError) {
178181
pub fn bool(o: JsObject) -> Result(Bool, WechatError) {
179182
o
180183
|> dynamic
181-
|> dynamic.bool
184+
|> decode.run(decode.bool)
182185
|> result.map_error(WechatDecodeError(_))
183186
}
184187

@@ -187,7 +190,7 @@ pub fn bool(o: JsObject) -> Result(Bool, WechatError) {
187190
pub fn string(o: JsObject) -> Result(String, WechatError) {
188191
o
189192
|> dynamic
190-
|> dynamic.string
193+
|> decode.run(decode.string)
191194
|> result.map_error(WechatDecodeError(_))
192195
}
193196

@@ -199,20 +202,24 @@ pub fn field(
199202
name a: name,
200203
of b: Decoder(t),
201204
) -> Result(t, WechatError) {
205+
let decoder = {
206+
use value <- decode.field(a, b)
207+
decode.success(value)
208+
}
202209
o
203210
|> dynamic
204-
|> dynamic.field(a, b)
211+
|> decode.run(decoder)
205212
|> result.map_error(WechatDecodeError(_))
206213
}
207214

208215
/// convert to `list(t)` with `gleam/dynamic`
209216
///
210217
pub fn list(
211218
o: JsObject,
212-
of f: fn(Dynamic) -> Result(t, DecodeErrors),
219+
of f: Decoder(t),
213220
) -> Result(List(t), WechatError) {
214221
o
215222
|> dynamic
216-
|> dynamic.list(f)
223+
|> decode.run(decode.list(f))
217224
|> result.map_error(WechatDecodeError(_))
218225
}

0 commit comments

Comments
 (0)