@greenlabs/ppx-spice 0.1.6 → 0.1.7-rc2

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.
@@ -20,13 +20,13 @@ Jest.describe("variants with @spice.as", (function (param) {
20
20
  _0: /* One */0
21
21
  }, Jest.Expect.expect(variantDecoded));
22
22
  }));
23
- return Jest.test("decode 둘", (function (param) {
24
- var variantDecoded = Variants.t_decode("둘");
25
- return Jest.Expect.toEqual({
26
- TAG: /* Ok */0,
27
- _0: /* Two */1
28
- }, Jest.Expect.expect(variantDecoded));
29
- }));
23
+ Jest.test("decode 둘", (function (param) {
24
+ var variantDecoded = Variants.t_decode("둘");
25
+ return Jest.Expect.toEqual({
26
+ TAG: /* Ok */0,
27
+ _0: /* Two */1
28
+ }, Jest.Expect.expect(variantDecoded));
29
+ }));
30
30
  }));
31
31
 
32
32
  Jest.describe("variants without @spice.as", (function (param) {
@@ -45,13 +45,13 @@ Jest.describe("variants without @spice.as", (function (param) {
45
45
  _0: /* One1 */0
46
46
  }, Jest.Expect.expect(variantDecoded));
47
47
  }));
48
- return Jest.test("decode [\"Two1\"]", (function (param) {
49
- var variantDecoded = Variants.t1_decode(["Two1"]);
50
- return Jest.Expect.toEqual({
51
- TAG: /* Ok */0,
52
- _0: /* Two1 */1
53
- }, Jest.Expect.expect(variantDecoded));
54
- }));
48
+ Jest.test("decode [\"Two1\"]", (function (param) {
49
+ var variantDecoded = Variants.t1_decode(["Two1"]);
50
+ return Jest.Expect.toEqual({
51
+ TAG: /* Ok */0,
52
+ _0: /* Two1 */1
53
+ }, Jest.Expect.expect(variantDecoded));
54
+ }));
55
55
  }));
56
56
 
57
57
  Jest.describe("unboxed variants with @spice.as", (function (param) {
@@ -59,13 +59,13 @@ Jest.describe("unboxed variants with @spice.as", (function (param) {
59
59
  var variantEncoded = Variants.t2_encode(0);
60
60
  return Jest.Expect.toEqual(0.0, Jest.Expect.expect(variantEncoded));
61
61
  }));
62
- return Jest.test("decode 하나", (function (param) {
63
- var variantDecoded = Variants.t2_decode(0.0);
64
- return Jest.Expect.toEqual({
65
- TAG: /* Ok */0,
66
- _0: 0
67
- }, Jest.Expect.expect(variantDecoded));
68
- }));
62
+ Jest.test("decode 하나", (function (param) {
63
+ var variantDecoded = Variants.t2_decode(0.0);
64
+ return Jest.Expect.toEqual({
65
+ TAG: /* Ok */0,
66
+ _0: 0
67
+ }, Jest.Expect.expect(variantDecoded));
68
+ }));
69
69
  }));
70
70
 
71
71
  Jest.describe("unboxed variants without @spice.as", (function (param) {
@@ -73,13 +73,13 @@ Jest.describe("unboxed variants without @spice.as", (function (param) {
73
73
  var variantEncoded = Variants.t3_encode(0);
74
74
  return Jest.Expect.toEqual(0.0, Jest.Expect.expect(variantEncoded));
75
75
  }));
76
- return Jest.test("decode 0", (function (param) {
77
- var variantDecoded = Variants.t3_decode(0.0);
78
- return Jest.Expect.toEqual({
79
- TAG: /* Ok */0,
80
- _0: 0
81
- }, Jest.Expect.expect(variantDecoded));
82
- }));
76
+ Jest.test("decode 0", (function (param) {
77
+ var variantDecoded = Variants.t3_decode(0.0);
78
+ return Jest.Expect.toEqual({
79
+ TAG: /* Ok */0,
80
+ _0: 0
81
+ }, Jest.Expect.expect(variantDecoded));
82
+ }));
83
83
  }));
84
84
 
85
85
  /* Not a pure module */
package/test/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "devDependencies": {
7
7
  "@glennsl/bs-jest": "^0.7.0",
8
8
  "jest": "^27.3.1",
9
- "rescript": "^9.1.4"
9
+ "rescript": "^10.0.1"
10
10
  },
11
11
  "scripts": {
12
12
  "res:build": "rescript",
@@ -3,6 +3,7 @@
3
3
 
4
4
  var Spice = require("./Spice.js");
5
5
  var Js_json = require("rescript/lib/js/js_json.js");
6
+ var Js_array = require("rescript/lib/js/js_array.js");
6
7
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
7
8
 
8
9
  function t_encode(v) {
@@ -57,7 +58,7 @@ function t1_decode(v) {
57
58
  if (json_arr$1.length === 0) {
58
59
  return Spice.error(undefined, "Expected polyvariant, found empty array", v);
59
60
  }
60
- var tagged = json_arr$1.map(Js_json.classify);
61
+ var tagged = Js_array.map(Js_json.classify, json_arr$1);
61
62
  var match = Belt_Array.getExn(tagged, 0);
62
63
  if (typeof match !== "number" && match.TAG === /* JSONString */0) {
63
64
  switch (match._0) {
@@ -7,16 +7,18 @@ var Js_json = require("rescript/lib/js/js_json.js");
7
7
  var Belt_Option = require("rescript/lib/js/belt_Option.js");
8
8
 
9
9
  function t_encode(v) {
10
- return Js_dict.fromArray([
11
- [
12
- "spice-label",
13
- Spice.stringToJson(v.label)
14
- ],
15
- [
16
- "spice-value",
17
- Spice.intToJson(v.value)
18
- ]
19
- ]);
10
+ return Js_dict.fromArray(Spice.filterOptional([
11
+ [
12
+ "spice-label",
13
+ false,
14
+ Spice.stringToJson(v.label)
15
+ ],
16
+ [
17
+ "spice-value",
18
+ false,
19
+ Spice.intToJson(v.value)
20
+ ]
21
+ ]));
20
22
  }
21
23
 
22
24
  function t_decode(v) {
@@ -62,16 +64,18 @@ function t_decode(v) {
62
64
  }
63
65
 
64
66
  function t1_encode(v) {
65
- return Js_dict.fromArray([
66
- [
67
- "label",
68
- Spice.stringToJson(v.label)
69
- ],
70
- [
71
- "value",
72
- Spice.intToJson(v.value)
73
- ]
74
- ]);
67
+ return Js_dict.fromArray(Spice.filterOptional([
68
+ [
69
+ "label",
70
+ false,
71
+ Spice.stringToJson(v.label)
72
+ ],
73
+ [
74
+ "value",
75
+ false,
76
+ Spice.intToJson(v.value)
77
+ ]
78
+ ]));
75
79
  }
76
80
 
77
81
  function t1_decode(v) {
@@ -116,8 +120,67 @@ function t1_decode(v) {
116
120
  };
117
121
  }
118
122
 
123
+ function tOp_encode(v) {
124
+ return Js_dict.fromArray(Spice.filterOptional([
125
+ [
126
+ "label",
127
+ false,
128
+ Spice.optionToJson(Spice.stringToJson, v.label)
129
+ ],
130
+ [
131
+ "value",
132
+ true,
133
+ Spice.optionToJson(Spice.intToJson, v.value)
134
+ ]
135
+ ]));
136
+ }
137
+
138
+ function tOp_decode(v) {
139
+ var dict = Js_json.classify(v);
140
+ if (typeof dict === "number") {
141
+ return Spice.error(undefined, "Not an object", v);
142
+ }
143
+ if (dict.TAG !== /* JSONObject */2) {
144
+ return Spice.error(undefined, "Not an object", v);
145
+ }
146
+ var dict$1 = dict._0;
147
+ var label = Spice.optionFromJson(Spice.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "label"), null));
148
+ if (label.TAG === /* Ok */0) {
149
+ var value = Spice.optionFromJson(Spice.intFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "value"), null));
150
+ if (value.TAG === /* Ok */0) {
151
+ return {
152
+ TAG: /* Ok */0,
153
+ _0: {
154
+ label: label._0,
155
+ value: value._0
156
+ }
157
+ };
158
+ }
159
+ var e = value._0;
160
+ return {
161
+ TAG: /* Error */1,
162
+ _0: {
163
+ path: ".value" + e.path,
164
+ message: e.message,
165
+ value: e.value
166
+ }
167
+ };
168
+ }
169
+ var e$1 = label._0;
170
+ return {
171
+ TAG: /* Error */1,
172
+ _0: {
173
+ path: ".label" + e$1.path,
174
+ message: e$1.message,
175
+ value: e$1.value
176
+ }
177
+ };
178
+ }
179
+
119
180
  exports.t_encode = t_encode;
120
181
  exports.t_decode = t_decode;
121
182
  exports.t1_encode = t1_encode;
122
183
  exports.t1_decode = t1_decode;
184
+ exports.tOp_encode = tOp_encode;
185
+ exports.tOp_decode = tOp_decode;
123
186
  /* No side effect */
@@ -9,3 +9,9 @@ type t1 = {
9
9
  label: string,
10
10
  value: int,
11
11
  }
12
+
13
+ @spice
14
+ type tOp = {
15
+ label: option<string>,
16
+ value?: int,
17
+ }
@@ -9,3 +9,9 @@ type t1 = {
9
9
  label: string,
10
10
  value: int,
11
11
  }
12
+
13
+ @spice
14
+ type tOp = {
15
+ label: option<string>,
16
+ value?: int,
17
+ }
package/test/src/Spice.js CHANGED
@@ -6,6 +6,8 @@ var Curry = require("rescript/lib/js/curry.js");
6
6
  var Js_dict = require("rescript/lib/js/js_dict.js");
7
7
  var Js_json = require("rescript/lib/js/js_json.js");
8
8
  var Js_math = require("rescript/lib/js/js_math.js");
9
+ var Caml_obj = require("rescript/lib/js/caml_obj.js");
10
+ var Js_array = require("rescript/lib/js/js_array.js");
9
11
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
10
12
  var Caml_int64 = require("rescript/lib/js/caml_int64.js");
11
13
  var Belt_Result = require("rescript/lib/js/belt_Result.js");
@@ -166,14 +168,12 @@ function unitFromJson(param) {
166
168
  };
167
169
  }
168
170
 
169
- function arrayToJson(encoder, arr) {
170
- return arr.map(Curry.__1(encoder));
171
- }
171
+ var arrayToJson = Js_array.map;
172
172
 
173
173
  function arrayFromJson(decoder, json) {
174
174
  var arr = Js_json.decodeArray(json);
175
175
  if (arr !== undefined) {
176
- return arr.reduce((function (acc, jsonI, i) {
176
+ return Js_array.reducei((function (acc, jsonI, i) {
177
177
  var match = Curry._1(decoder, jsonI);
178
178
  if (acc.TAG !== /* Ok */0) {
179
179
  return acc;
@@ -181,7 +181,7 @@ function arrayFromJson(decoder, json) {
181
181
  if (match.TAG === /* Ok */0) {
182
182
  return {
183
183
  TAG: /* Ok */0,
184
- _0: acc._0.concat([match._0])
184
+ _0: Js_array.concat([match._0], acc._0)
185
185
  };
186
186
  }
187
187
  var error = match._0;
@@ -196,7 +196,7 @@ function arrayFromJson(decoder, json) {
196
196
  }), {
197
197
  TAG: /* Ok */0,
198
198
  _0: []
199
- });
199
+ }, arr);
200
200
  } else {
201
201
  return {
202
202
  TAG: /* Error */1,
@@ -211,7 +211,7 @@ function arrayFromJson(decoder, json) {
211
211
 
212
212
  function listToJson(encoder, list) {
213
213
  var arr = $$Array.of_list(list);
214
- return arr.map(Curry.__1(encoder));
214
+ return Js_array.map(encoder, arr);
215
215
  }
216
216
 
217
217
  function listFromJson(decoder, json) {
@@ -227,6 +227,18 @@ function optionToJson(encoder, opt) {
227
227
  }
228
228
  }
229
229
 
230
+ function filterOptional(arr) {
231
+ var __x = Belt_Array.keep(arr, (function (param) {
232
+ return !(param[1] && Caml_obj.equal(param[2], null));
233
+ }));
234
+ return Belt_Array.map(__x, (function (param) {
235
+ return [
236
+ param[0],
237
+ param[2]
238
+ ];
239
+ }));
240
+ }
241
+
230
242
  function optionFromJson(decoder, json) {
231
243
  var match = Js_json.decodeNull(json);
232
244
  if (match !== undefined) {
@@ -426,6 +438,7 @@ exports.arrayFromJson = arrayFromJson;
426
438
  exports.listToJson = listToJson;
427
439
  exports.listFromJson = listFromJson;
428
440
  exports.optionToJson = optionToJson;
441
+ exports.filterOptional = filterOptional;
429
442
  exports.optionFromJson = optionFromJson;
430
443
  exports.resultToJson = resultToJson;
431
444
  exports.resultFromJson = resultFromJson;
@@ -3,6 +3,7 @@
3
3
 
4
4
  var Spice = require("./Spice.js");
5
5
  var Js_json = require("rescript/lib/js/js_json.js");
6
+ var Js_array = require("rescript/lib/js/js_array.js");
6
7
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
7
8
  var Belt_Result = require("rescript/lib/js/belt_Result.js");
8
9
 
@@ -58,7 +59,7 @@ function t1_decode(v) {
58
59
  if (json_arr$1.length === 0) {
59
60
  return Spice.error(undefined, "Expected variant, found empty array", v);
60
61
  }
61
- var tagged = json_arr$1.map(Js_json.classify);
62
+ var tagged = Js_array.map(Js_json.classify, json_arr$1);
62
63
  var match = Belt_Array.getExn(tagged, 0);
63
64
  if (typeof match !== "number" && match.TAG === /* JSONString */0) {
64
65
  switch (match._0) {
package/test/yarn.lock CHANGED
@@ -3466,10 +3466,10 @@ require-main-filename@^2.0.0:
3466
3466
  resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
3467
3467
  integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
3468
3468
 
3469
- rescript@^9.1.4:
3470
- version "9.1.4"
3471
- resolved "https://registry.yarnpkg.com/rescript/-/rescript-9.1.4.tgz#1eb126f98d6c16942c0bf0df67c050198e580515"
3472
- integrity sha512-aXANK4IqecJzdnDpJUsU6pxMViCR5ogAxzuqS0mOr8TloMnzAjJFu63fjD6LCkWrKAhlMkFFzQvVQYaAaVkFXw==
3469
+ rescript@^10.0.1:
3470
+ version "10.0.1"
3471
+ resolved "https://registry.yarnpkg.com/rescript/-/rescript-10.0.1.tgz#5b2da8a8bcfb994bed1eb24820bf10cfb9d8c440"
3472
+ integrity sha512-XwO1GPDtoEU4H03xQE5bp0/qtSVR6YLaJRPxWKrfFgKc+LI36ODOCie7o9UJfgzQdoMYkkZyiTGZ4N9OQEaiUw==
3473
3473
 
3474
3474
  resolve-cwd@^3.0.0:
3475
3475
  version "3.0.0"
package/src/esy.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "name": "ppx_spice",
3
- "description": "OCaml/ReasonML ppx that generate parse/stringify function",
4
- "scripts": {
5
- "format": "dune build @fmt --auto-promote",
6
- "release-static": "dune build --root . --only-packages '#{self.name}' --ignore-promoted-rules --no-config --profile release-static"
7
- },
8
- "esy": {
9
- "build": "dune build -p #{self.name}",
10
- "buildsInSource": "_build"
11
- },
12
- "dependencies": {
13
- "@opam/dune": "*",
14
- "@opam/ppxlib": "0.23.0",
15
- "ocaml": "4.12.x"
16
- },
17
- "devDependencies": {
18
- "@opam/ocaml-lsp-server": "1.8.3",
19
- "@opam/ocamlformat": "0.19.0"
20
- }
21
- }
@@ -1,43 +0,0 @@
1
- lib: [
2
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/META"
3
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/dune-package"
4
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/opam"
5
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/polyvariants.ml"
6
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.a"
7
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.cma"
8
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.cmi"
9
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.cmt"
10
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.cmx"
11
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.cmxa"
12
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.ml"
13
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__.cmi"
14
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__.cmt"
15
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__.cmx"
16
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__.ml"
17
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Polyvariants.cmi"
18
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Polyvariants.cmt"
19
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Polyvariants.cmx"
20
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Signature.cmi"
21
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Signature.cmt"
22
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Signature.cmx"
23
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Structure.cmi"
24
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Structure.cmt"
25
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Structure.cmx"
26
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Utils.cmi"
27
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Utils.cmt"
28
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Utils.cmx"
29
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Variants.cmi"
30
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Variants.cmt"
31
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice__Variants.cmx"
32
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/signature.ml"
33
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/structure.ml"
34
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/utils.ml"
35
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/variants.ml"
36
- ]
37
- libexec: [
38
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx.exe"
39
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/lib/ppx_spice/ppx_spice.cmxs"
40
- ]
41
- bin: [
42
- "/Users/woonki/Documents/projects/ppx_spice/src/_esy/default/store/b/ppx__spice-dc255e86/install/default/bin/ppx_spice"
43
- ]