@greenlabs/ppx-spice 0.2.2 → 0.2.3

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,6 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.2.3 (unreleased)
3
+ ## 0.2.4 (unreleased)
4
+
5
+ ## 0.2.3
6
+
7
+ - Support the compiler v12-alpha.4 https://github.com/green-labs/ppx_spice/pull/82
8
+ - Support bigint type https://github.com/green-labs/ppx_spice/pull/83
4
9
 
5
10
  ## 0.2.2
6
11
 
package/README.md CHANGED
@@ -130,6 +130,7 @@ Read our [Guide with examples](docs/GUIDE.md)
130
130
 
131
131
  | Compiler | Ppx_spice |
132
132
  | -------- | -------------- |
133
+ | v12 | >= v0.2.3 |
133
134
  | v11 | >= v0.2.1-rc.1 |
134
135
  | v10 | ~<= v0.1.15 |
135
136
 
@@ -160,7 +161,7 @@ Make sure running the below commands in `/src`.
160
161
  1. Create a sandbox with opam
161
162
 
162
163
  ```
163
- opam switch create spice 4.12.1
164
+ opam switch create spice 4.14.0
164
165
  ```
165
166
 
166
167
  2. Install dependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greenlabs/ppx-spice",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
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
@@ -3,17 +3,20 @@
3
3
  "sources": [
4
4
  {
5
5
  "dir": "src",
6
- "subdirs": ["rescript"]
6
+ "subdirs": [
7
+ "rescript"
8
+ ]
7
9
  },
8
10
  {
9
11
  "dir": "test",
10
12
  "type": "dev"
11
13
  }
12
14
  ],
13
- "refmt": 3,
14
- "ppx-flags": ["./ppx"],
15
+ "ppx-flags": [
16
+ "./ppx"
17
+ ],
15
18
  "warnings": {
16
19
  "number": "+A-9-40-42"
17
20
  },
18
- "bsc-flags": ["-bs-super-errors"]
19
- }
21
+ "bsc-flags": []
22
+ }
@@ -24,30 +24,22 @@ let stringFromJson = j =>
24
24
  | _ => Error({path: "", message: "Not a string", value: j})
25
25
  }
26
26
 
27
- let intToJson = (i): Js.Json.t => Js.Json.Number(float_of_int(i))
27
+ let intToJson = (i): Js.Json.t => Js.Json.Number(Float.fromInt(i))
28
28
  let intFromJson = j =>
29
29
  switch (j: Js.Json.t) {
30
30
  | Js.Json.Number(f) =>
31
- float_of_int(Js.Math.floor(f)) == f
31
+ Float.fromInt(Js.Math.floor(f)) == f
32
32
  ? Ok(Js.Math.floor(f))
33
33
  : Error({path: "", message: "Not an integer", value: j})
34
34
 
35
35
  | _ => Error({path: "", message: "Not a number", value: j})
36
36
  }
37
37
 
38
- let int64ToJson = (i): Js.Json.t => Js.Json.Number(Int64.float_of_bits(i))
38
+ let bigintToJson = (i): Js.Json.t => Js.Json.Number(BigInt.toFloat(i))
39
39
 
40
- let int64FromJson = j =>
40
+ let bigintFromJson = j =>
41
41
  switch (j: Js.Json.t) {
42
- | Js.Json.Number(n) => Ok(Int64.bits_of_float(n))
43
- | _ => error("Not a number", j)
44
- }
45
-
46
- let int64ToJsonUnsafe = (i): Js.Json.t => Js.Json.number(Int64.to_float(i))
47
-
48
- let int64FromJsonUnsafe = j =>
49
- switch (j: Js.Json.t) {
50
- | Js.Json.Number(n) => Ok(Int64.of_float(n))
42
+ | Js.Json.Number(n) => Ok(BigInt.fromFloat(n))
51
43
  | _ => error("Not a number", j)
52
44
  }
53
45
 
@@ -82,7 +74,7 @@ let arrayFromJson = (decoder, json) =>
82
74
  | (Error(_), _) => acc
83
75
 
84
76
  | (_, Error({path} as error)) =>
85
- Error({...error, path: "[" ++ (string_of_int(i) ++ ("]" ++ path))})
77
+ Error({...error, path: "[" ++ (Int.toString(i) ++ ("]" ++ path))})
86
78
 
87
79
  | (Ok(prev), Ok(newVal)) =>
88
80
  Ok(Js.Array.concat([newVal], prev))
@@ -178,7 +170,7 @@ module Codecs = {
178
170
  include Spice_Codecs
179
171
  let string = (stringToJson, stringFromJson)
180
172
  let int = (intToJson, intFromJson)
181
- let int64Unsafe = (int64ToJsonUnsafe, int64FromJsonUnsafe)
173
+ let bigint = (bigintToJson, bigintFromJson)
182
174
  let float = (floatToJson, floatFromJson)
183
175
  let bool = (boolToJson, boolFromJson)
184
176
  let array = (arrayToJson, arrayFromJson)
@@ -1,446 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
-
4
- var Js_dict = require("rescript/lib/js/js_dict.js");
5
- var Js_json = require("rescript/lib/js/js_json.js");
6
- var Js_math = require("rescript/lib/js/js_math.js");
7
- var Caml_obj = require("rescript/lib/js/caml_obj.js");
8
- var Js_array = require("rescript/lib/js/js_array.js");
9
- var Belt_List = require("rescript/lib/js/belt_List.js");
10
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
11
- var Caml_int64 = require("rescript/lib/js/caml_int64.js");
12
- var Belt_Result = require("rescript/lib/js/belt_Result.js");
13
- var Caml_option = require("rescript/lib/js/caml_option.js");
14
- var Spice_Codecs = require("./Spice_Codecs.js");
15
-
16
- function error(path, message, value) {
17
- var path$1 = path !== undefined ? path : "";
18
- return {
19
- TAG: "Error",
20
- _0: {
21
- path: path$1,
22
- message: message,
23
- value: value
24
- }
25
- };
26
- }
27
-
28
- function stringToJson(s) {
29
- return s;
30
- }
31
-
32
- function stringFromJson(j) {
33
- var s = Js_json.decodeString(j);
34
- if (s !== undefined) {
35
- return {
36
- TAG: "Ok",
37
- _0: s
38
- };
39
- } else {
40
- return {
41
- TAG: "Error",
42
- _0: {
43
- path: "",
44
- message: "Not a string",
45
- value: j
46
- }
47
- };
48
- }
49
- }
50
-
51
- function intToJson(i) {
52
- return i;
53
- }
54
-
55
- function intFromJson(j) {
56
- var f = Js_json.decodeNumber(j);
57
- if (f !== undefined) {
58
- if (Js_math.floor(f) === f) {
59
- return {
60
- TAG: "Ok",
61
- _0: Js_math.floor(f)
62
- };
63
- } else {
64
- return {
65
- TAG: "Error",
66
- _0: {
67
- path: "",
68
- message: "Not an integer",
69
- value: j
70
- }
71
- };
72
- }
73
- } else {
74
- return {
75
- TAG: "Error",
76
- _0: {
77
- path: "",
78
- message: "Not a number",
79
- value: j
80
- }
81
- };
82
- }
83
- }
84
-
85
- var int64ToJson = Caml_int64.float_of_bits;
86
-
87
- function int64FromJson(j) {
88
- var n = Js_json.decodeNumber(j);
89
- if (n !== undefined) {
90
- return {
91
- TAG: "Ok",
92
- _0: Caml_int64.bits_of_float(n)
93
- };
94
- } else {
95
- return error(undefined, "Not a number", j);
96
- }
97
- }
98
-
99
- var int64ToJsonUnsafe = Caml_int64.to_float;
100
-
101
- function int64FromJsonUnsafe(j) {
102
- var n = Js_json.decodeNumber(j);
103
- if (n !== undefined) {
104
- return {
105
- TAG: "Ok",
106
- _0: Caml_int64.of_float(n)
107
- };
108
- } else {
109
- return error(undefined, "Not a number", j);
110
- }
111
- }
112
-
113
- function floatToJson(v) {
114
- return v;
115
- }
116
-
117
- function floatFromJson(j) {
118
- var f = Js_json.decodeNumber(j);
119
- if (f !== undefined) {
120
- return {
121
- TAG: "Ok",
122
- _0: f
123
- };
124
- } else {
125
- return {
126
- TAG: "Error",
127
- _0: {
128
- path: "",
129
- message: "Not a number",
130
- value: j
131
- }
132
- };
133
- }
134
- }
135
-
136
- function boolToJson(v) {
137
- return v;
138
- }
139
-
140
- function boolFromJson(j) {
141
- var b = Js_json.decodeBoolean(j);
142
- if (b !== undefined) {
143
- return {
144
- TAG: "Ok",
145
- _0: b
146
- };
147
- } else {
148
- return {
149
- TAG: "Error",
150
- _0: {
151
- path: "",
152
- message: "Not a boolean",
153
- value: j
154
- }
155
- };
156
- }
157
- }
158
-
159
- function unitToJson() {
160
- return 0.0;
161
- }
162
-
163
- function unitFromJson(param) {
164
- return {
165
- TAG: "Ok",
166
- _0: undefined
167
- };
168
- }
169
-
170
- var arrayToJson = Js_array.map;
171
-
172
- function arrayFromJson(decoder, json) {
173
- var arr = Js_json.decodeArray(json);
174
- if (arr !== undefined) {
175
- return Js_array.reducei((function (acc, jsonI, i) {
176
- var match = decoder(jsonI);
177
- if (acc.TAG !== "Ok") {
178
- return acc;
179
- }
180
- if (match.TAG === "Ok") {
181
- return {
182
- TAG: "Ok",
183
- _0: Js_array.concat([match._0], acc._0)
184
- };
185
- }
186
- var error = match._0;
187
- return {
188
- TAG: "Error",
189
- _0: {
190
- path: "[" + (String(i) + ("]" + error.path)),
191
- message: error.message,
192
- value: error.value
193
- }
194
- };
195
- }), {
196
- TAG: "Ok",
197
- _0: []
198
- }, arr);
199
- } else {
200
- return {
201
- TAG: "Error",
202
- _0: {
203
- path: "",
204
- message: "Not an array",
205
- value: json
206
- }
207
- };
208
- }
209
- }
210
-
211
- function listToJson(encoder, list) {
212
- return Js_array.map(encoder, Belt_List.toArray(list));
213
- }
214
-
215
- function listFromJson(decoder, json) {
216
- return Belt_Result.map(arrayFromJson(decoder, json), Belt_List.fromArray);
217
- }
218
-
219
- function filterOptional(arr) {
220
- return Belt_Array.map(Belt_Array.keep(arr, (function (param) {
221
- return !(param[1] && Caml_obj.equal(param[2], null));
222
- })), (function (param) {
223
- return [
224
- param[0],
225
- param[2]
226
- ];
227
- }));
228
- }
229
-
230
- function optionToJson(encoder, opt) {
231
- if (opt !== undefined) {
232
- return encoder(Caml_option.valFromOption(opt));
233
- } else {
234
- return null;
235
- }
236
- }
237
-
238
- function optionFromJson(decoder, json) {
239
- var match = Js_json.decodeNull(json);
240
- if (match !== undefined) {
241
- return {
242
- TAG: "Ok",
243
- _0: undefined
244
- };
245
- } else {
246
- return Belt_Result.map(decoder(json), (function (v) {
247
- return Caml_option.some(v);
248
- }));
249
- }
250
- }
251
-
252
- function resultToJson(okEncoder, errorEncoder, result) {
253
- if (result.TAG === "Ok") {
254
- return [
255
- "Ok",
256
- okEncoder(result._0)
257
- ];
258
- } else {
259
- return [
260
- "Error",
261
- errorEncoder(result._0)
262
- ];
263
- }
264
- }
265
-
266
- function resultFromJson(okDecoder, errorDecoder, json) {
267
- var match = Js_json.decodeArray(json);
268
- if (match === undefined) {
269
- return error(undefined, "Not an array", json);
270
- }
271
- if (match.length !== 2) {
272
- return error(undefined, "Expected exactly 2 values in array", json);
273
- }
274
- var variantConstructorId = match[0];
275
- var payload = match[1];
276
- var match$1 = Js_json.decodeString(variantConstructorId);
277
- if (match$1 === undefined) {
278
- return error(undefined, "Not a string", variantConstructorId);
279
- }
280
- switch (match$1) {
281
- case "Error" :
282
- var v = errorDecoder(payload);
283
- if (v.TAG === "Ok") {
284
- return {
285
- TAG: "Ok",
286
- _0: {
287
- TAG: "Error",
288
- _0: v._0
289
- }
290
- };
291
- } else {
292
- return {
293
- TAG: "Error",
294
- _0: v._0
295
- };
296
- }
297
- case "Ok" :
298
- return Belt_Result.map(okDecoder(payload), (function (v) {
299
- return {
300
- TAG: "Ok",
301
- _0: v
302
- };
303
- }));
304
- default:
305
- return error(undefined, "Expected either \"Ok\" or \"Error\"", variantConstructorId);
306
- }
307
- }
308
-
309
- function dictToJson(encoder, dict) {
310
- return Js_dict.map((function (a) {
311
- return encoder(a);
312
- }), dict);
313
- }
314
-
315
- function dictFromJson(decoder, json) {
316
- var dict = Js_json.decodeObject(json);
317
- if (dict !== undefined) {
318
- return Belt_Array.reduce(Js_dict.entries(Caml_option.valFromOption(dict)), {
319
- TAG: "Ok",
320
- _0: {}
321
- }, (function (acc, param) {
322
- var key = param[0];
323
- var match = decoder(param[1]);
324
- if (acc.TAG !== "Ok") {
325
- return acc;
326
- }
327
- var prev = acc._0;
328
- if (match.TAG === "Ok") {
329
- prev[key] = match._0;
330
- return {
331
- TAG: "Ok",
332
- _0: prev
333
- };
334
- }
335
- var error = match._0;
336
- return {
337
- TAG: "Error",
338
- _0: {
339
- path: "." + (key + error.path),
340
- message: error.message,
341
- value: error.value
342
- }
343
- };
344
- }));
345
- } else {
346
- return {
347
- TAG: "Error",
348
- _0: {
349
- path: "",
350
- message: "Not a dict",
351
- value: json
352
- }
353
- };
354
- }
355
- }
356
-
357
- var string = [
358
- stringToJson,
359
- stringFromJson
360
- ];
361
-
362
- var $$int = [
363
- intToJson,
364
- intFromJson
365
- ];
366
-
367
- var int64Unsafe = [
368
- int64ToJsonUnsafe,
369
- int64FromJsonUnsafe
370
- ];
371
-
372
- var $$float = [
373
- floatToJson,
374
- floatFromJson
375
- ];
376
-
377
- var bool = [
378
- boolToJson,
379
- boolFromJson
380
- ];
381
-
382
- var array = [
383
- arrayToJson,
384
- arrayFromJson
385
- ];
386
-
387
- var list = [
388
- listToJson,
389
- listFromJson
390
- ];
391
-
392
- var option = [
393
- optionToJson,
394
- optionFromJson
395
- ];
396
-
397
- var unit = [
398
- unitToJson,
399
- unitFromJson
400
- ];
401
-
402
- var Codecs = {
403
- falseableEncode: Spice_Codecs.falseableEncode,
404
- falseableDecode: Spice_Codecs.falseableDecode,
405
- falseable: Spice_Codecs.falseable,
406
- magicDecode: Spice_Codecs.magicDecode,
407
- magic: Spice_Codecs.magic,
408
- string: string,
409
- $$int: $$int,
410
- int64Unsafe: int64Unsafe,
411
- $$float: $$float,
412
- bool: bool,
413
- array: array,
414
- list: list,
415
- option: option,
416
- unit: unit
417
- };
418
-
419
- exports.error = error;
420
- exports.stringToJson = stringToJson;
421
- exports.stringFromJson = stringFromJson;
422
- exports.intToJson = intToJson;
423
- exports.intFromJson = intFromJson;
424
- exports.int64ToJson = int64ToJson;
425
- exports.int64FromJson = int64FromJson;
426
- exports.int64ToJsonUnsafe = int64ToJsonUnsafe;
427
- exports.int64FromJsonUnsafe = int64FromJsonUnsafe;
428
- exports.floatToJson = floatToJson;
429
- exports.floatFromJson = floatFromJson;
430
- exports.boolToJson = boolToJson;
431
- exports.boolFromJson = boolFromJson;
432
- exports.unitToJson = unitToJson;
433
- exports.unitFromJson = unitFromJson;
434
- exports.arrayToJson = arrayToJson;
435
- exports.arrayFromJson = arrayFromJson;
436
- exports.listToJson = listToJson;
437
- exports.listFromJson = listFromJson;
438
- exports.filterOptional = filterOptional;
439
- exports.optionToJson = optionToJson;
440
- exports.optionFromJson = optionFromJson;
441
- exports.resultToJson = resultToJson;
442
- exports.resultFromJson = resultFromJson;
443
- exports.dictToJson = dictToJson;
444
- exports.dictFromJson = dictFromJson;
445
- exports.Codecs = Codecs;
446
- /* No side effect */
@@ -1,55 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
-
4
- var Js_json = require("rescript/lib/js/js_json.js");
5
- var Belt_Result = require("rescript/lib/js/belt_Result.js");
6
- var Caml_option = require("rescript/lib/js/caml_option.js");
7
-
8
- function falseableEncode(encoder, opt) {
9
- if (opt !== undefined) {
10
- return encoder(Caml_option.valFromOption(opt));
11
- } else {
12
- return false;
13
- }
14
- }
15
-
16
- function falseableDecode(decoder, json) {
17
- var match = Js_json.decodeBoolean(json);
18
- if (match !== undefined && !match) {
19
- return {
20
- TAG: "Ok",
21
- _0: undefined
22
- };
23
- }
24
- return Belt_Result.map(decoder(json), (function (v) {
25
- return Caml_option.some(v);
26
- }));
27
- }
28
-
29
- var falseable = [
30
- falseableEncode,
31
- falseableDecode
32
- ];
33
-
34
- function magicDecode(j) {
35
- return {
36
- TAG: "Ok",
37
- _0: j
38
- };
39
- }
40
-
41
- function magic_0(prim) {
42
- return prim;
43
- }
44
-
45
- var magic = [
46
- magic_0,
47
- magicDecode
48
- ];
49
-
50
- exports.falseableEncode = falseableEncode;
51
- exports.falseableDecode = falseableDecode;
52
- exports.falseable = falseable;
53
- exports.magicDecode = magicDecode;
54
- exports.magic = magic;
55
- /* No side effect */