create-mendix-widget-gleam 2.0.14 → 2.0.15

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.
Files changed (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -1
  3. package/src/index.mjs +22 -7
  4. package/template/gleam.toml +1 -1
  5. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@command.cache +0 -0
  6. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@command.cache_inline +0 -0
  7. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@command.cache_meta +0 -0
  8. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@cursor.cache +0 -0
  9. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@cursor.cache_inline +0 -0
  10. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@cursor.cache_meta +0 -0
  11. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@event.cache +0 -0
  12. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@event.cache_inline +0 -0
  13. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@event.cache_meta +0 -0
  14. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@internal@consts.cache +0 -0
  15. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@internal@consts.cache_inline +0 -0
  16. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@internal@consts.cache_meta +0 -0
  17. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@stdout.cache +0 -0
  18. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@stdout.cache_inline +0 -0
  19. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@stdout.cache_meta +0 -0
  20. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@style.cache +0 -0
  21. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@style.cache_inline +0 -0
  22. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@style.cache_meta +0 -0
  23. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@terminal.cache +0 -0
  24. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@terminal.cache_inline +0 -0
  25. package/tui/build/dev/javascript/etch/_gleam_artefacts/etch@terminal.cache_meta +0 -0
  26. package/tui/build/dev/javascript/etch/etch/command.mjs +479 -0
  27. package/tui/build/dev/javascript/etch/etch/cursor.mjs +164 -0
  28. package/tui/build/dev/javascript/etch/etch/event.mjs +2399 -0
  29. package/tui/build/dev/javascript/etch/etch/internal/consts.mjs +3 -0
  30. package/tui/build/dev/javascript/etch/etch/stdout.mjs +375 -0
  31. package/tui/build/dev/javascript/etch/etch/style.mjs +741 -0
  32. package/tui/build/dev/javascript/etch/etch/terminal.mjs +137 -0
  33. package/tui/build/dev/javascript/etch/gleam.mjs +1 -0
  34. package/tui/build/dev/javascript/etch/input/event_ffi.erl +73 -0
  35. package/tui/build/dev/javascript/etch/input/input_ffi.mjs +192 -0
  36. package/tui/build/dev/javascript/etch/input/signal_handler.erl +33 -0
  37. package/tui/build/dev/javascript/etch/terminal/terminal_ffi.erl +22 -0
  38. package/tui/build/dev/javascript/etch/terminal/terminal_ffi.mjs +37 -0
  39. package/tui/build/dev/javascript/etch/terminal/tty_state.erl +29 -0
  40. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@application.cache +0 -0
  41. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@application.cache_inline +0 -0
  42. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@application.cache_meta +0 -0
  43. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache +0 -0
  44. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_inline +0 -0
  45. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_meta +0 -0
  46. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache +0 -0
  47. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_inline +0 -0
  48. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_meta +0 -0
  49. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache +0 -0
  50. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_inline +0 -0
  51. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_meta +0 -0
  52. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@port.cache +0 -0
  53. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@port.cache_inline +0 -0
  54. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@port.cache_meta +0 -0
  55. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache +0 -0
  56. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_inline +0 -0
  57. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_meta +0 -0
  58. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@reference.cache +0 -0
  59. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@reference.cache_inline +0 -0
  60. package/tui/build/dev/javascript/gleam_erlang/_gleam_artefacts/gleam@erlang@reference.cache_meta +0 -0
  61. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/application.mjs +38 -0
  62. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/atom.mjs +2 -0
  63. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/charlist.mjs +1 -0
  64. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/node.mjs +12 -0
  65. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/port.mjs +1 -0
  66. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/process.mjs +161 -0
  67. package/tui/build/dev/javascript/gleam_erlang/gleam/erlang/reference.mjs +1 -0
  68. package/tui/build/dev/javascript/gleam_erlang/gleam.mjs +1 -0
  69. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@application.erl +43 -0
  70. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@atom.erl +94 -0
  71. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@charlist.erl +42 -0
  72. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@node.erl +80 -0
  73. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@port.erl +8 -0
  74. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@process.erl +868 -0
  75. package/tui/build/dev/javascript/gleam_erlang/gleam@erlang@reference.erl +21 -0
  76. package/tui/build/dev/javascript/gleam_erlang/gleam_erlang_ffi.erl +164 -0
  77. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@array.cache +0 -0
  78. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@array.cache_inline +0 -0
  79. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@array.cache_meta +0 -0
  80. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@promise.cache +0 -0
  81. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@promise.cache_inline +0 -0
  82. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@promise.cache_meta +0 -0
  83. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@symbol.cache +0 -0
  84. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@symbol.cache_inline +0 -0
  85. package/tui/build/dev/javascript/gleam_javascript/_gleam_artefacts/gleam@javascript@symbol.cache_meta +0 -0
  86. package/tui/build/dev/javascript/gleam_javascript/gleam/javascript/array.mjs +24 -0
  87. package/tui/build/dev/javascript/gleam_javascript/gleam/javascript/promise.mjs +105 -0
  88. package/tui/build/dev/javascript/gleam_javascript/gleam/javascript/symbol.mjs +7 -0
  89. package/tui/build/dev/javascript/gleam_javascript/gleam.mjs +1 -0
  90. package/tui/build/dev/javascript/gleam_javascript/gleam_javascript_ffi.mjs +133 -0
  91. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache +0 -0
  92. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_inline +0 -0
  93. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta +0 -0
  94. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache +0 -0
  95. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_inline +0 -0
  96. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta +0 -0
  97. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache +0 -0
  98. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache_inline +0 -0
  99. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@bytes_tree.cache_meta +0 -0
  100. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache +0 -0
  101. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_inline +0 -0
  102. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta +0 -0
  103. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache +0 -0
  104. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_inline +0 -0
  105. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta +0 -0
  106. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache +0 -0
  107. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache_inline +0 -0
  108. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@dynamic@decode.cache_meta +0 -0
  109. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache +0 -0
  110. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache_inline +0 -0
  111. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta +0 -0
  112. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache +0 -0
  113. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache_inline +0 -0
  114. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta +0 -0
  115. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache +0 -0
  116. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache_inline +0 -0
  117. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta +0 -0
  118. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache +0 -0
  119. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache_inline +0 -0
  120. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta +0 -0
  121. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache +0 -0
  122. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache_inline +0 -0
  123. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta +0 -0
  124. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache +0 -0
  125. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache_inline +0 -0
  126. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta +0 -0
  127. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache +0 -0
  128. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache_inline +0 -0
  129. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta +0 -0
  130. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache +0 -0
  131. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_inline +0 -0
  132. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta +0 -0
  133. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache +0 -0
  134. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache_inline +0 -0
  135. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta +0 -0
  136. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache +0 -0
  137. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache_inline +0 -0
  138. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta +0 -0
  139. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache +0 -0
  140. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache_inline +0 -0
  141. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta +0 -0
  142. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache +0 -0
  143. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache_inline +0 -0
  144. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@string_tree.cache_meta +0 -0
  145. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache +0 -0
  146. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_inline +0 -0
  147. package/tui/build/dev/javascript/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta +0 -0
  148. package/tui/build/dev/javascript/gleam_stdlib/dict.mjs +710 -0
  149. package/tui/build/dev/javascript/gleam_stdlib/gleam/bit_array.mjs +286 -0
  150. package/tui/build/dev/javascript/gleam_stdlib/gleam/bool.mjs +295 -0
  151. package/tui/build/dev/javascript/gleam_stdlib/gleam/bytes_tree.mjs +225 -0
  152. package/tui/build/dev/javascript/gleam_stdlib/gleam/dict.mjs +455 -0
  153. package/tui/build/dev/javascript/gleam_stdlib/gleam/dynamic/decode.mjs +993 -0
  154. package/tui/build/dev/javascript/gleam_stdlib/gleam/dynamic.mjs +35 -0
  155. package/tui/build/dev/javascript/gleam_stdlib/gleam/float.mjs +528 -0
  156. package/tui/build/dev/javascript/gleam_stdlib/gleam/function.mjs +6 -0
  157. package/tui/build/dev/javascript/gleam_stdlib/gleam/int.mjs +764 -0
  158. package/tui/build/dev/javascript/gleam_stdlib/gleam/io.mjs +8 -0
  159. package/tui/build/dev/javascript/gleam_stdlib/gleam/list.mjs +3063 -0
  160. package/tui/build/dev/javascript/gleam_stdlib/gleam/option.mjs +386 -0
  161. package/tui/build/dev/javascript/gleam_stdlib/gleam/order.mjs +166 -0
  162. package/tui/build/dev/javascript/gleam_stdlib/gleam/pair.mjs +96 -0
  163. package/tui/build/dev/javascript/gleam_stdlib/gleam/result.mjs +448 -0
  164. package/tui/build/dev/javascript/gleam_stdlib/gleam/set.mjs +413 -0
  165. package/tui/build/dev/javascript/gleam_stdlib/gleam/string.mjs +695 -0
  166. package/tui/build/dev/javascript/gleam_stdlib/gleam/string_tree.mjs +128 -0
  167. package/tui/build/dev/javascript/gleam_stdlib/gleam/uri.mjs +1151 -0
  168. package/tui/build/dev/javascript/gleam_stdlib/gleam.mjs +1 -0
  169. package/tui/build/dev/javascript/gleam_stdlib/gleam@bit_array.erl +347 -0
  170. package/tui/build/dev/javascript/gleam_stdlib/gleam@bool.erl +334 -0
  171. package/tui/build/dev/javascript/gleam_stdlib/gleam@bytes_tree.erl +211 -0
  172. package/tui/build/dev/javascript/gleam_stdlib/gleam@dict.erl +513 -0
  173. package/tui/build/dev/javascript/gleam_stdlib/gleam@dynamic.erl +105 -0
  174. package/tui/build/dev/javascript/gleam_stdlib/gleam@dynamic@decode.erl +1114 -0
  175. package/tui/build/dev/javascript/gleam_stdlib/gleam@float.erl +711 -0
  176. package/tui/build/dev/javascript/gleam_stdlib/gleam@function.erl +18 -0
  177. package/tui/build/dev/javascript/gleam_stdlib/gleam@int.erl +972 -0
  178. package/tui/build/dev/javascript/gleam_stdlib/gleam@io.erl +76 -0
  179. package/tui/build/dev/javascript/gleam_stdlib/gleam@list.erl +2735 -0
  180. package/tui/build/dev/javascript/gleam_stdlib/gleam@option.erl +381 -0
  181. package/tui/build/dev/javascript/gleam_stdlib/gleam@order.erl +188 -0
  182. package/tui/build/dev/javascript/gleam_stdlib/gleam@pair.erl +104 -0
  183. package/tui/build/dev/javascript/gleam_stdlib/gleam@result.erl +500 -0
  184. package/tui/build/dev/javascript/gleam_stdlib/gleam@set.erl +430 -0
  185. package/tui/build/dev/javascript/gleam_stdlib/gleam@string.erl +964 -0
  186. package/tui/build/dev/javascript/gleam_stdlib/gleam@string_tree.erl +202 -0
  187. package/tui/build/dev/javascript/gleam_stdlib/gleam@uri.erl +1042 -0
  188. package/tui/build/dev/javascript/gleam_stdlib/gleam_stdlib.erl +534 -0
  189. package/tui/build/dev/javascript/gleam_stdlib/gleam_stdlib.mjs +1133 -0
  190. package/tui/build/dev/javascript/gleam_version +1 -0
  191. package/tui/build/dev/javascript/prelude.mjs +1575 -0
  192. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache +0 -0
  193. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache_inline +0 -0
  194. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache_meta +0 -0
  195. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui.cache_warnings +0 -0
  196. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache +0 -0
  197. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache_inline +0 -0
  198. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache_meta +0 -0
  199. package/tui/build/dev/javascript/tui/_gleam_artefacts/tui@prompt.cache_warnings +0 -0
  200. package/tui/build/dev/javascript/tui/gleam.mjs +1 -0
  201. package/tui/build/dev/javascript/tui/tui/prompt.mjs +521 -0
  202. package/tui/build/dev/javascript/tui/tui.mjs +334 -0
  203. package/tui/build/dev/javascript/tui/tui_ffi.mjs +32 -0
@@ -0,0 +1,993 @@
1
+ import {
2
+ Ok,
3
+ Error,
4
+ toList,
5
+ Empty as $Empty,
6
+ prepend as listPrepend,
7
+ CustomType as $CustomType,
8
+ isEqual,
9
+ } from "../../gleam.mjs";
10
+ import * as $bit_array from "../../gleam/bit_array.mjs";
11
+ import * as $dict from "../../gleam/dict.mjs";
12
+ import * as $dynamic from "../../gleam/dynamic.mjs";
13
+ import * as $float from "../../gleam/float.mjs";
14
+ import * as $int from "../../gleam/int.mjs";
15
+ import * as $list from "../../gleam/list.mjs";
16
+ import * as $option from "../../gleam/option.mjs";
17
+ import { None, Some } from "../../gleam/option.mjs";
18
+ import {
19
+ index as bare_index,
20
+ int as dynamic_int,
21
+ float as dynamic_float,
22
+ bit_array as dynamic_bit_array,
23
+ list as decode_list,
24
+ dict as decode_dict,
25
+ identity as cast,
26
+ is_null,
27
+ string as dynamic_string,
28
+ } from "../../gleam_stdlib.mjs";
29
+
30
+ export class DecodeError extends $CustomType {
31
+ constructor(expected, found, path) {
32
+ super();
33
+ this.expected = expected;
34
+ this.found = found;
35
+ this.path = path;
36
+ }
37
+ }
38
+ export const DecodeError$DecodeError = (expected, found, path) =>
39
+ new DecodeError(expected, found, path);
40
+ export const DecodeError$isDecodeError = (value) =>
41
+ value instanceof DecodeError;
42
+ export const DecodeError$DecodeError$expected = (value) => value.expected;
43
+ export const DecodeError$DecodeError$0 = (value) => value.expected;
44
+ export const DecodeError$DecodeError$found = (value) => value.found;
45
+ export const DecodeError$DecodeError$1 = (value) => value.found;
46
+ export const DecodeError$DecodeError$path = (value) => value.path;
47
+ export const DecodeError$DecodeError$2 = (value) => value.path;
48
+
49
+ class Decoder extends $CustomType {
50
+ constructor(function$) {
51
+ super();
52
+ this.function = function$;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * A decoder that decodes `Dynamic` values. This decoder never returns an error.
58
+ *
59
+ * ## Examples
60
+ *
61
+ * ```gleam
62
+ * let result = decode.run(dynamic.float(3.14), decode.dynamic)
63
+ * assert result == Ok(dynamic.float(3.14))
64
+ * ```
65
+ */
66
+ export const dynamic = /* @__PURE__ */ new Decoder(decode_dynamic);
67
+
68
+ /**
69
+ * A decoder that decodes `Bool` values.
70
+ *
71
+ * ## Examples
72
+ *
73
+ * ```gleam
74
+ * let result = decode.run(dynamic.bool(True), decode.bool)
75
+ * assert result == Ok(True)
76
+ * ```
77
+ */
78
+ export const bool = /* @__PURE__ */ new Decoder(decode_bool);
79
+
80
+ /**
81
+ * A decoder that decodes `Int` values.
82
+ *
83
+ * This will not coerse float values into int values, so on platforms with
84
+ * distinct runtime int and float types (Erlang, not JavaScript) it will fail,
85
+ * even if the float is a whole number (e.g. 1.0).
86
+ *
87
+ * If you want to decode both ints and floats you may want to use the `one_of`
88
+ * function.
89
+ *
90
+ * ## Examples
91
+ *
92
+ * ```gleam
93
+ * let result = decode.run(dynamic.int(147), decode.int)
94
+ * assert result == Ok(147)
95
+ * ```
96
+ */
97
+ export const int = /* @__PURE__ */ new Decoder(decode_int);
98
+
99
+ /**
100
+ * A decoder that decodes `Float` values.
101
+ *
102
+ * This will not coerse int values into float values, so on platforms with
103
+ * distinct runtime int and float types (Erlang, not JavaScript) it will fail
104
+ * for ints. One time this may happen is when decoding JSON data.
105
+ *
106
+ * If you want to decode both ints and floats you may want to use the `one_of`
107
+ * function.
108
+ *
109
+ * ## Examples
110
+ *
111
+ * ```gleam
112
+ * let result = decode.run(dynamic.float(3.14), decode.float)
113
+ * assert result == Ok(3.14)
114
+ * ```
115
+ */
116
+ export const float = /* @__PURE__ */ new Decoder(decode_float);
117
+
118
+ /**
119
+ * A decoder that decodes `BitArray` values. This decoder never returns an error.
120
+ *
121
+ * ## Examples
122
+ *
123
+ * ```gleam
124
+ * let result = decode.run(dynamic.bit_array(<<5, 7>>), decode.bit_array)
125
+ * assert result == Ok(<<5, 7>>)
126
+ * ```
127
+ */
128
+ export const bit_array = /* @__PURE__ */ new Decoder(decode_bit_array);
129
+
130
+ /**
131
+ * A decoder that decodes `String` values.
132
+ *
133
+ * ## Examples
134
+ *
135
+ * ```gleam
136
+ * let result = decode.run(dynamic.string("Hello!"), decode.string)
137
+ * assert result == Ok("Hello!")
138
+ * ```
139
+ */
140
+ export const string = /* @__PURE__ */ new Decoder(decode_string);
141
+
142
+ /**
143
+ * Run a decoder on a `Dynamic` value, decoding the value if it is of the
144
+ * desired type, or returning errors.
145
+ *
146
+ * ## Examples
147
+ *
148
+ * ```gleam
149
+ * let decoder = {
150
+ * use name <- decode.field("name", decode.string)
151
+ * use email <- decode.field("email", decode.string)
152
+ * decode.success(SignUp(name: name, email: email))
153
+ * }
154
+ *
155
+ * decode.run(data, decoder)
156
+ * ```
157
+ */
158
+ export function run(data, decoder) {
159
+ let $ = decoder.function(data);
160
+ let maybe_invalid_data;
161
+ let errors;
162
+ maybe_invalid_data = $[0];
163
+ errors = $[1];
164
+ if (errors instanceof $Empty) {
165
+ return new Ok(maybe_invalid_data);
166
+ } else {
167
+ return new Error(errors);
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Finalise a decoder having successfully extracted a value.
173
+ *
174
+ * ## Examples
175
+ *
176
+ * ```gleam
177
+ * let data = dynamic.properties([
178
+ * #(dynamic.string("email"), dynamic.string("lucy@example.com")),
179
+ * #(dynamic.string("name"), dynamic.string("Lucy")),
180
+ * ])
181
+ *
182
+ * let decoder = {
183
+ * use name <- decode.field("name", string)
184
+ * use email <- decode.field("email", string)
185
+ * decode.success(SignUp(name: name, email: email))
186
+ * }
187
+ *
188
+ * let result = decode.run(data, decoder)
189
+ * assert result == Ok(SignUp(name: "Lucy", email: "lucy@example.com"))
190
+ * ```
191
+ */
192
+ export function success(data) {
193
+ return new Decoder((_) => { return [data, toList([])]; });
194
+ }
195
+
196
+ function decode_dynamic(data) {
197
+ return [data, toList([])];
198
+ }
199
+
200
+ /**
201
+ * Apply a transformation function to any value decoded by the decoder.
202
+ *
203
+ * ## Examples
204
+ *
205
+ * ```gleam
206
+ * let decoder = decode.int |> decode.map(int.to_string)
207
+ * let result = decode.run(dynamic.int(1000), decoder)
208
+ * assert result == Ok("1000")
209
+ * ```
210
+ */
211
+ export function map(decoder, transformer) {
212
+ return new Decoder(
213
+ (d) => {
214
+ let $ = decoder.function(d);
215
+ let data;
216
+ let errors;
217
+ data = $[0];
218
+ errors = $[1];
219
+ return [transformer(data), errors];
220
+ },
221
+ );
222
+ }
223
+
224
+ /**
225
+ * Apply a transformation function to any errors returned by the decoder.
226
+ */
227
+ export function map_errors(decoder, transformer) {
228
+ return new Decoder(
229
+ (d) => {
230
+ let $ = decoder.function(d);
231
+ let data;
232
+ let errors;
233
+ data = $[0];
234
+ errors = $[1];
235
+ return [data, transformer(errors)];
236
+ },
237
+ );
238
+ }
239
+
240
+ /**
241
+ * Create a new decoder based upon the value of a previous decoder.
242
+ *
243
+ * This may be useful to run one previous decoder to use in further decoding.
244
+ */
245
+ export function then$(decoder, next) {
246
+ return new Decoder(
247
+ (dynamic_data) => {
248
+ let $ = decoder.function(dynamic_data);
249
+ let data;
250
+ let errors;
251
+ data = $[0];
252
+ errors = $[1];
253
+ let decoder$1 = next(data);
254
+ let $1 = decoder$1.function(dynamic_data);
255
+ let layer;
256
+ let data$1;
257
+ layer = $1;
258
+ data$1 = $1[0];
259
+ if (errors instanceof $Empty) {
260
+ return layer;
261
+ } else {
262
+ return [data$1, errors];
263
+ }
264
+ },
265
+ );
266
+ }
267
+
268
+ function run_decoders(loop$data, loop$failure, loop$decoders) {
269
+ while (true) {
270
+ let data = loop$data;
271
+ let failure = loop$failure;
272
+ let decoders = loop$decoders;
273
+ if (decoders instanceof $Empty) {
274
+ return failure;
275
+ } else {
276
+ let decoder = decoders.head;
277
+ let decoders$1 = decoders.tail;
278
+ let $ = decoder.function(data);
279
+ let layer;
280
+ let errors;
281
+ layer = $;
282
+ errors = $[1];
283
+ if (errors instanceof $Empty) {
284
+ return layer;
285
+ } else {
286
+ loop$data = data;
287
+ loop$failure = failure;
288
+ loop$decoders = decoders$1;
289
+ }
290
+ }
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Create a new decoder from several other decoders. Each of the inner
296
+ * decoders is run in turn, and the value from the first to succeed is used.
297
+ *
298
+ * If no decoder succeeds then the errors from the first decoder are used.
299
+ * If you wish for different errors then you may wish to use the
300
+ * `collapse_errors` or `map_errors` functions.
301
+ *
302
+ * ## Examples
303
+ *
304
+ * ```gleam
305
+ * let decoder = decode.one_of(decode.string, or: [
306
+ * decode.int |> decode.map(int.to_string),
307
+ * decode.float |> decode.map(float.to_string),
308
+ * ])
309
+ * assert decode.run(dynamic.int(1000), decoder) == Ok("1000")
310
+ * ```
311
+ */
312
+ export function one_of(first, alternatives) {
313
+ return new Decoder(
314
+ (dynamic_data) => {
315
+ let $ = first.function(dynamic_data);
316
+ let layer;
317
+ let errors;
318
+ layer = $;
319
+ errors = $[1];
320
+ if (errors instanceof $Empty) {
321
+ return layer;
322
+ } else {
323
+ return run_decoders(dynamic_data, layer, alternatives);
324
+ }
325
+ },
326
+ );
327
+ }
328
+
329
+ /**
330
+ * Create a decoder that can refer to itself, useful for decoding deeply
331
+ * nested data.
332
+ *
333
+ * Attempting to create a recursive decoder without this function could result
334
+ * in an infinite loop. If you are using `field` or other `use`able functions
335
+ * then you may not need to use this function.
336
+ *
337
+ * ## Examples
338
+ *
339
+ * ```gleam
340
+ * type Nested {
341
+ * Nested(List(Nested))
342
+ * Value(String)
343
+ * }
344
+ *
345
+ * fn nested_decoder() -> decode.Decoder(Nested) {
346
+ * use <- decode.recursive
347
+ * decode.one_of(decode.string |> decode.map(Value), [
348
+ * decode.list(nested_decoder()) |> decode.map(Nested),
349
+ * ])
350
+ * }
351
+ * ```
352
+ */
353
+ export function recursive(inner) {
354
+ return new Decoder(
355
+ (data) => {
356
+ let decoder = inner();
357
+ return decoder.function(data);
358
+ },
359
+ );
360
+ }
361
+
362
+ /**
363
+ * A decoder that decodes nullable values of a type decoded by with a given
364
+ * decoder.
365
+ *
366
+ * This function can handle common representations of null on all runtimes, such as
367
+ * `nil`, `null`, and `undefined` on Erlang, and `undefined` and `null` on
368
+ * JavaScript.
369
+ *
370
+ * ## Examples
371
+ *
372
+ * ```gleam
373
+ * let result = decode.run(dynamic.int(100), decode.optional(decode.int))
374
+ * assert result == Ok(option.Some(100))
375
+ * ```
376
+ *
377
+ * ```gleam
378
+ * let result = decode.run(dynamic.nil(), decode.optional(decode.int))
379
+ * assert result == Ok(option.None)
380
+ * ```
381
+ */
382
+ export function optional(inner) {
383
+ return new Decoder(
384
+ (data) => {
385
+ let $ = is_null(data);
386
+ if ($) {
387
+ return [new $option.None(), toList([])];
388
+ } else {
389
+ let $1 = inner.function(data);
390
+ let data$1;
391
+ let errors;
392
+ data$1 = $1[0];
393
+ errors = $1[1];
394
+ return [new $option.Some(data$1), errors];
395
+ }
396
+ },
397
+ );
398
+ }
399
+
400
+ /**
401
+ * Construct a decode error for some unexpected dynamic data.
402
+ */
403
+ export function decode_error(expected, found) {
404
+ return toList([
405
+ new DecodeError(expected, $dynamic.classify(found), toList([])),
406
+ ]);
407
+ }
408
+
409
+ function run_dynamic_function(data, name, f) {
410
+ let $ = f(data);
411
+ if ($ instanceof Ok) {
412
+ let data$1 = $[0];
413
+ return [data$1, toList([])];
414
+ } else {
415
+ let placeholder = $[0];
416
+ return [
417
+ placeholder,
418
+ toList([new DecodeError(name, $dynamic.classify(data), toList([]))]),
419
+ ];
420
+ }
421
+ }
422
+
423
+ function decode_bool(data) {
424
+ let $ = isEqual(cast(true), data);
425
+ if ($) {
426
+ return [true, toList([])];
427
+ } else {
428
+ let $1 = isEqual(cast(false), data);
429
+ if ($1) {
430
+ return [false, toList([])];
431
+ } else {
432
+ return [false, decode_error("Bool", data)];
433
+ }
434
+ }
435
+ }
436
+
437
+ function decode_int(data) {
438
+ return run_dynamic_function(data, "Int", dynamic_int);
439
+ }
440
+
441
+ function decode_float(data) {
442
+ return run_dynamic_function(data, "Float", dynamic_float);
443
+ }
444
+
445
+ function decode_bit_array(data) {
446
+ return run_dynamic_function(data, "BitArray", dynamic_bit_array);
447
+ }
448
+
449
+ /**
450
+ * Replace all errors produced by a decoder with one single error for a named
451
+ * expected type.
452
+ *
453
+ * This function may be useful if you wish to simplify errors before
454
+ * presenting them to a user, particularly when using the `one_of` function.
455
+ *
456
+ * ## Examples
457
+ *
458
+ * ```gleam
459
+ * let decoder = decode.string |> decode.collapse_errors("MyThing")
460
+ * let result = decode.run(dynamic.int(1000), decoder)
461
+ * assert result == Error([DecodeError("MyThing", "Int", [])])
462
+ * ```
463
+ */
464
+ export function collapse_errors(decoder, name) {
465
+ return new Decoder(
466
+ (dynamic_data) => {
467
+ let $ = decoder.function(dynamic_data);
468
+ let layer;
469
+ let data;
470
+ let errors;
471
+ layer = $;
472
+ data = $[0];
473
+ errors = $[1];
474
+ if (errors instanceof $Empty) {
475
+ return layer;
476
+ } else {
477
+ return [data, decode_error(name, dynamic_data)];
478
+ }
479
+ },
480
+ );
481
+ }
482
+
483
+ /**
484
+ * Define a decoder that always fails.
485
+ *
486
+ * The first parameter is a "placeholder" value, which is some default value that the
487
+ * decoder uses internally in place of the value that would have been produced
488
+ * if the decoder was successful. It doesn't matter what this value is, it is
489
+ * never returned by the decoder or shown to the user, so pick some arbitrary
490
+ * value. If it is an int you might pick `0`, if it is a list you might pick
491
+ * `[]`.
492
+ *
493
+ * The second parameter is the name of the type that has failed to decode.
494
+ *
495
+ * ```gleam
496
+ * decode.failure(User(name: "", score: 0, tags: []), expected: "User")
497
+ * ```
498
+ */
499
+ export function failure(placeholder, name) {
500
+ return new Decoder((d) => { return [placeholder, decode_error(name, d)]; });
501
+ }
502
+
503
+ /**
504
+ * Create a decoder for a new data type from a decoding function.
505
+ *
506
+ * This function is used for new primitive types. For example, you might
507
+ * define a decoder for Erlang's pid type.
508
+ *
509
+ * A default "placeholder" value is also required to make a decoder. When this
510
+ * decoder is used as part of a larger decoder this placeholder value is used
511
+ * so that the rest of the decoder can continue to run and
512
+ * collect all decoding errors. It doesn't matter what this value is, it is
513
+ * never returned by the decoder or shown to the user, so pick some arbitrary
514
+ * value. If it is an int you might pick `0`, if it is a list you might pick
515
+ * `[]`.
516
+ *
517
+ * If you were to make a decoder for the `Int` type (rather than using the
518
+ * build-in `Int` decoder) you would define it like so:
519
+ *
520
+ * ```gleam
521
+ * pub fn int_decoder() -> decode.Decoder(Int) {
522
+ * let default = ""
523
+ * decode.new_primitive_decoder("Int", int_from_dynamic)
524
+ * }
525
+ *
526
+ * @external(erlang, "my_module", "int_from_dynamic")
527
+ * fn int_from_dynamic(data: Int) -> Result(Int, Int)
528
+ * ```
529
+ *
530
+ * ```erlang
531
+ * -module(my_module).
532
+ * -export([int_from_dynamic/1]).
533
+ *
534
+ * int_from_dynamic(Data) ->
535
+ * case is_integer(Data) of
536
+ * true -> {ok, Data};
537
+ * false -> {error, 0}
538
+ * end.
539
+ * ```
540
+ */
541
+ export function new_primitive_decoder(name, decoding_function) {
542
+ return new Decoder(
543
+ (d) => {
544
+ let $ = decoding_function(d);
545
+ if ($ instanceof Ok) {
546
+ let t = $[0];
547
+ return [t, toList([])];
548
+ } else {
549
+ let placeholder = $[0];
550
+ return [
551
+ placeholder,
552
+ toList([new DecodeError(name, $dynamic.classify(d), toList([]))]),
553
+ ];
554
+ }
555
+ },
556
+ );
557
+ }
558
+
559
+ function decode_string(data) {
560
+ return run_dynamic_function(data, "String", dynamic_string);
561
+ }
562
+
563
+ function path_segment_to_string(key) {
564
+ let decoder = one_of(
565
+ string,
566
+ toList([
567
+ (() => {
568
+ let _pipe = int;
569
+ return map(_pipe, $int.to_string);
570
+ })(),
571
+ (() => {
572
+ let _pipe = float;
573
+ return map(_pipe, $float.to_string);
574
+ })(),
575
+ ]),
576
+ );
577
+ let $ = run(key, decoder);
578
+ if ($ instanceof Ok) {
579
+ let key$1 = $[0];
580
+ return key$1;
581
+ } else {
582
+ return ("<" + $dynamic.classify(key)) + ">";
583
+ }
584
+ }
585
+
586
+ function fold_dict(acc, key, value, key_decoder, value_decoder) {
587
+ let $ = key_decoder(key);
588
+ let $1 = $[1];
589
+ if ($1 instanceof $Empty) {
590
+ let key_decoded = $[0];
591
+ let $2 = value_decoder(value);
592
+ let $3 = $2[1];
593
+ if ($3 instanceof $Empty) {
594
+ let value$1 = $2[0];
595
+ let dict$1 = $dict.insert(acc[0], key_decoded, value$1);
596
+ return [dict$1, acc[1]];
597
+ } else {
598
+ let errors = $3;
599
+ let key_identifier = path_segment_to_string(key);
600
+ return push_path([$dict.new$(), errors], toList([key_identifier]));
601
+ }
602
+ } else {
603
+ let errors = $1;
604
+ return push_path([$dict.new$(), errors], toList(["keys"]));
605
+ }
606
+ }
607
+
608
+ /**
609
+ * A decoder that decodes dicts where all keys and values are decoded with
610
+ * given decoders.
611
+ *
612
+ * ## Examples
613
+ *
614
+ * ```gleam
615
+ * let values = dynamic.properties([
616
+ * #(dynamic.string("one"), dynamic.int(1)),
617
+ * #(dynamic.string("two"), dynamic.int(2)),
618
+ * ])
619
+ *
620
+ * let result =
621
+ * decode.run(values, decode.dict(decode.string, decode.int))
622
+ * assert result == Ok(values)
623
+ * ```
624
+ */
625
+ export function dict(key, value) {
626
+ return new Decoder(
627
+ (data) => {
628
+ let $ = decode_dict(data);
629
+ if ($ instanceof Ok) {
630
+ let dict$1 = $[0];
631
+ return $dict.fold(
632
+ dict$1,
633
+ [$dict.new$(), toList([])],
634
+ (a, k, v) => {
635
+ let $1 = a[1];
636
+ if ($1 instanceof $Empty) {
637
+ return fold_dict(a, k, v, key.function, value.function);
638
+ } else {
639
+ return a;
640
+ }
641
+ },
642
+ );
643
+ } else {
644
+ return [$dict.new$(), decode_error("Dict", data)];
645
+ }
646
+ },
647
+ );
648
+ }
649
+
650
+ /**
651
+ * A decoder that decodes lists where all elements are decoded with a given
652
+ * decoder.
653
+ *
654
+ * ## Examples
655
+ *
656
+ * ```gleam
657
+ * let result =
658
+ * [1, 2, 3]
659
+ * |> list.map(dynamic.int)
660
+ * |> dynamic.list
661
+ * |> decode.run(decode.list(of: decode.int))
662
+ * assert result == Ok([1, 2, 3])
663
+ * ```
664
+ */
665
+ export function list(inner) {
666
+ return new Decoder(
667
+ (data) => {
668
+ return decode_list(
669
+ data,
670
+ inner.function,
671
+ (p, k) => { return push_path(p, toList([k])); },
672
+ 0,
673
+ toList([]),
674
+ );
675
+ },
676
+ );
677
+ }
678
+
679
+ function push_path(layer, path) {
680
+ let path$1 = $list.map(
681
+ path,
682
+ (key) => {
683
+ let _pipe = key;
684
+ let _pipe$1 = cast(_pipe);
685
+ return path_segment_to_string(_pipe$1);
686
+ },
687
+ );
688
+ let errors = $list.map(
689
+ layer[1],
690
+ (error) => {
691
+ return new DecodeError(
692
+ error.expected,
693
+ error.found,
694
+ $list.append(path$1, error.path),
695
+ );
696
+ },
697
+ );
698
+ return [layer[0], errors];
699
+ }
700
+
701
+ function index(
702
+ loop$path,
703
+ loop$position,
704
+ loop$inner,
705
+ loop$data,
706
+ loop$handle_miss
707
+ ) {
708
+ while (true) {
709
+ let path = loop$path;
710
+ let position = loop$position;
711
+ let inner = loop$inner;
712
+ let data = loop$data;
713
+ let handle_miss = loop$handle_miss;
714
+ if (path instanceof $Empty) {
715
+ let _pipe = data;
716
+ let _pipe$1 = inner(_pipe);
717
+ return push_path(_pipe$1, $list.reverse(position));
718
+ } else {
719
+ let key = path.head;
720
+ let path$1 = path.tail;
721
+ let $ = bare_index(data, key);
722
+ if ($ instanceof Ok) {
723
+ let $1 = $[0];
724
+ if ($1 instanceof Some) {
725
+ let data$1 = $1[0];
726
+ loop$path = path$1;
727
+ loop$position = listPrepend(key, position);
728
+ loop$inner = inner;
729
+ loop$data = data$1;
730
+ loop$handle_miss = handle_miss;
731
+ } else {
732
+ return handle_miss(data, listPrepend(key, position));
733
+ }
734
+ } else {
735
+ let kind = $[0];
736
+ let $1 = inner(data);
737
+ let default$;
738
+ default$ = $1[0];
739
+ let _pipe = [
740
+ default$,
741
+ toList([new DecodeError(kind, $dynamic.classify(data), toList([]))]),
742
+ ];
743
+ return push_path(_pipe, $list.reverse(position));
744
+ }
745
+ }
746
+ }
747
+ }
748
+
749
+ /**
750
+ * The same as [`field`](#field), except taking a path to the value rather
751
+ * than a field name.
752
+ *
753
+ * This function will index into dictionaries with any key type, and if the key is
754
+ * an int then it'll also index into Erlang tuples and JavaScript arrays, and
755
+ * the first eight elements of Gleam lists.
756
+ *
757
+ * ## Examples
758
+ *
759
+ * ```gleam
760
+ * let data = dynamic.properties([
761
+ * #(dynamic.string("data"), dynamic.properties([
762
+ * #(dynamic.string("email"), dynamic.string("lucy@example.com")),
763
+ * #(dynamic.string("name"), dynamic.string("Lucy")),
764
+ * ])
765
+ * ])
766
+ *
767
+ * let decoder = {
768
+ * use name <- decode.subfield(["data", "name"], decode.string)
769
+ * use email <- decode.subfield(["data", "email"], decode.string)
770
+ * decode.success(SignUp(name: name, email: email))
771
+ * }
772
+ * let result = decode.run(data, decoder)
773
+ * assert result == Ok(SignUp(name: "Lucy", email: "lucy@example.com"))
774
+ * ```
775
+ */
776
+ export function subfield(field_path, field_decoder, next) {
777
+ return new Decoder(
778
+ (data) => {
779
+ let $ = index(
780
+ field_path,
781
+ toList([]),
782
+ field_decoder.function,
783
+ data,
784
+ (data, position) => {
785
+ let $1 = field_decoder.function(data);
786
+ let default$;
787
+ default$ = $1[0];
788
+ let _pipe = [
789
+ default$,
790
+ toList([new DecodeError("Field", "Nothing", toList([]))]),
791
+ ];
792
+ return push_path(_pipe, $list.reverse(position));
793
+ },
794
+ );
795
+ let out;
796
+ let errors1;
797
+ out = $[0];
798
+ errors1 = $[1];
799
+ let $1 = next(out).function(data);
800
+ let out$1;
801
+ let errors2;
802
+ out$1 = $1[0];
803
+ errors2 = $1[1];
804
+ return [out$1, $list.append(errors1, errors2)];
805
+ },
806
+ );
807
+ }
808
+
809
+ /**
810
+ * A decoder that decodes a value that is nested within other values. For
811
+ * example, decoding a value that is within some deeply nested JSON objects.
812
+ *
813
+ * This function will index into dictionaries with any key type, and if the key is
814
+ * an int then it'll also index into Erlang tuples and JavaScript arrays, and
815
+ * the first eight elements of Gleam lists.
816
+ *
817
+ * ## Examples
818
+ *
819
+ * ```gleam
820
+ * let decoder = decode.at(["one", "two"], decode.int)
821
+ *
822
+ * let data = dynamic.properties([
823
+ * #(dynamic.string("one"), dynamic.properties([
824
+ * #(dynamic.string("two"), dynamic.int(1000)),
825
+ * ]),
826
+ * ])
827
+ *
828
+ * assert decode.run(data, decoder) == Ok(1000)
829
+ * ```
830
+ *
831
+ * ```gleam
832
+ * assert dynamic.nil()
833
+ * |> decode.run(decode.optional(decode.int))
834
+ * == Ok(option.None)
835
+ * ```
836
+ */
837
+ export function at(path, inner) {
838
+ return new Decoder(
839
+ (data) => {
840
+ return index(
841
+ path,
842
+ toList([]),
843
+ inner.function,
844
+ data,
845
+ (data, position) => {
846
+ let $ = inner.function(data);
847
+ let default$;
848
+ default$ = $[0];
849
+ let _pipe = [
850
+ default$,
851
+ toList([new DecodeError("Field", "Nothing", toList([]))]),
852
+ ];
853
+ return push_path(_pipe, $list.reverse(position));
854
+ },
855
+ );
856
+ },
857
+ );
858
+ }
859
+
860
+ /**
861
+ * Run a decoder on a field of a `Dynamic` value, decoding the value if it is
862
+ * of the desired type, or returning errors. An error is returned if there is
863
+ * no field for the specified key.
864
+ *
865
+ * This function will index into dictionaries with any key type, and if the key is
866
+ * an int then it'll also index into Erlang tuples and JavaScript arrays, and
867
+ * the first eight elements of Gleam lists.
868
+ *
869
+ * ## Examples
870
+ *
871
+ * ```gleam
872
+ * let data = dynamic.properties([
873
+ * #(dynamic.string("email"), dynamic.string("lucy@example.com")),
874
+ * #(dynamic.string("name"), dynamic.string("Lucy")),
875
+ * ])
876
+ *
877
+ * let decoder = {
878
+ * use name <- decode.field("name", string)
879
+ * use email <- decode.field("email", string)
880
+ * decode.success(SignUp(name: name, email: email))
881
+ * }
882
+ *
883
+ * let result = decode.run(data, decoder)
884
+ * assert result == Ok(SignUp(name: "Lucy", email: "lucy@example.com"))
885
+ * ```
886
+ *
887
+ * If you wish to decode a value that is more deeply nested within the dynamic
888
+ * data, see [`subfield`](#subfield) and [`at`](#at).
889
+ *
890
+ * If you wish to return a default in the event that a field is not present,
891
+ * see [`optional_field`](#optional_field) and / [`optionally_at`](#optionally_at).
892
+ */
893
+ export function field(field_name, field_decoder, next) {
894
+ return subfield(toList([field_name]), field_decoder, next);
895
+ }
896
+
897
+ /**
898
+ * Run a decoder on a field of a `Dynamic` value, decoding the value if it is
899
+ * of the desired type, or returning errors. The given default value is
900
+ * returned if there is no field for the specified key.
901
+ *
902
+ * This function will index into dictionaries with any key type, and if the key is
903
+ * an int then it'll also index into Erlang tuples and JavaScript arrays, and
904
+ * the first eight elements of Gleam lists.
905
+ *
906
+ * ## Examples
907
+ *
908
+ * ```gleam
909
+ * let data = dynamic.properties([
910
+ * #(dynamic.string("name"), dynamic.string("Lucy")),
911
+ * ])
912
+ *
913
+ * let decoder = {
914
+ * use name <- decode.field("name", string)
915
+ * use email <- decode.optional_field("email", "n/a", string)
916
+ * decode.success(SignUp(name: name, email: email))
917
+ * }
918
+ *
919
+ * let result = decode.run(data, decoder)
920
+ * assert result == Ok(SignUp(name: "Lucy", email: "n/a"))
921
+ * ```
922
+ */
923
+ export function optional_field(key, default$, field_decoder, next) {
924
+ return new Decoder(
925
+ (data) => {
926
+ let _block;
927
+ let _block$1;
928
+ let $1 = bare_index(data, key);
929
+ if ($1 instanceof Ok) {
930
+ let $2 = $1[0];
931
+ if ($2 instanceof Some) {
932
+ let data$1 = $2[0];
933
+ _block$1 = field_decoder.function(data$1);
934
+ } else {
935
+ _block$1 = [default$, toList([])];
936
+ }
937
+ } else {
938
+ let kind = $1[0];
939
+ _block$1 = [
940
+ default$,
941
+ toList([new DecodeError(kind, $dynamic.classify(data), toList([]))]),
942
+ ];
943
+ }
944
+ let _pipe = _block$1;
945
+ _block = push_path(_pipe, toList([key]));
946
+ let $ = _block;
947
+ let out;
948
+ let errors1;
949
+ out = $[0];
950
+ errors1 = $[1];
951
+ let $2 = next(out).function(data);
952
+ let out$1;
953
+ let errors2;
954
+ out$1 = $2[0];
955
+ errors2 = $2[1];
956
+ return [out$1, $list.append(errors1, errors2)];
957
+ },
958
+ );
959
+ }
960
+
961
+ /**
962
+ * A decoder that decodes a value that is nested within other values. For
963
+ * example, decoding a value that is within some deeply nested JSON objects.
964
+ *
965
+ * This function will index into dictionaries with any key type, and if the key is
966
+ * an int then it'll also index into Erlang tuples and JavaScript arrays, and
967
+ * the first eight elements of Gleam lists.
968
+ *
969
+ * ## Examples
970
+ *
971
+ * ```gleam
972
+ * let decoder = decode.optionally_at(["one", "two"], 100, decode.int)
973
+ *
974
+ * let data = dynamic.properties([
975
+ * #(dynamic.string("one"), dynamic.properties([])),
976
+ * ])
977
+ *
978
+ * assert decode.run(data, decoder) == Ok(100)
979
+ * ```
980
+ */
981
+ export function optionally_at(path, default$, inner) {
982
+ return new Decoder(
983
+ (data) => {
984
+ return index(
985
+ path,
986
+ toList([]),
987
+ inner.function,
988
+ data,
989
+ (_, _1) => { return [default$, toList([])]; },
990
+ );
991
+ },
992
+ );
993
+ }