envio 2.7.0 → 2.7.1

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 (2) hide show
  1. package/package.json +8 -5
  2. package/src/ChainMap.res +42 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "v2.7.0",
3
+ "version": "v2.7.1",
4
4
  "description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
5
5
  "bin": "./bin.js",
6
6
  "repository": {
@@ -23,10 +23,13 @@
23
23
  },
24
24
  "homepage": "https://envio.dev",
25
25
  "optionalDependencies": {
26
- "envio-linux-x64": "v2.7.0",
27
- "envio-linux-arm64": "v2.7.0",
28
- "envio-darwin-x64": "v2.7.0",
29
- "envio-darwin-arm64": "v2.7.0"
26
+ "envio-linux-x64": "v2.7.1",
27
+ "envio-linux-arm64": "v2.7.1",
28
+ "envio-darwin-x64": "v2.7.1",
29
+ "envio-darwin-arm64": "v2.7.1"
30
+ },
31
+ "dependencies": {
32
+ "rescript": "11.1.3"
30
33
  },
31
34
  "files": [
32
35
  "bin.js",
@@ -0,0 +1,42 @@
1
+ open Belt
2
+
3
+ module Chain = {
4
+ type t = int
5
+
6
+ external toChainId: t => int = "%identity"
7
+
8
+ let toString = chainId => chainId->Int.toString
9
+
10
+ let makeUnsafe = (~chainId) => chainId
11
+ }
12
+
13
+ module ChainIdCmp = Belt.Id.MakeComparableU({
14
+ type t = Chain.t
15
+ let cmp = (a, b) => Pervasives.compare(a->Chain.toChainId, b->Chain.toChainId)
16
+ })
17
+
18
+ type t<'a> = Belt.Map.t<ChainIdCmp.t, 'a, ChainIdCmp.identity>
19
+
20
+ let fromArrayUnsafe: array<(Chain.t, 'a)> => t<'a> = arr => {
21
+ arr->Map.fromArray(~id=module(ChainIdCmp))
22
+ }
23
+
24
+ let get: (t<'a>, Chain.t) => 'a = (self, chain) =>
25
+ switch Map.get(self, chain) {
26
+ | Some(v) => v
27
+ | None =>
28
+ // Should be unreachable, since we validate on Chain.t creation
29
+ // Still throw just in case something went wrong
30
+ Js.Exn.raiseError("No chain with id " ++ chain->Chain.toString ++ " found in chain map")
31
+ }
32
+
33
+ let set: (t<'a>, Chain.t, 'a) => t<'a> = (map, chain, v) => Map.set(map, chain, v)
34
+ let values: t<'a> => array<'a> = map => Map.valuesToArray(map)
35
+ let keys: t<'a> => array<Chain.t> = map => Map.keysToArray(map)
36
+ let entries: t<'a> => array<(Chain.t, 'a)> = map => Map.toArray(map)
37
+ let has: (t<'a>, Chain.t) => bool = (map, chain) => Map.has(map, chain)
38
+ let map: (t<'a>, 'a => 'b) => t<'b> = (map, fn) => Map.map(map, fn)
39
+ let mapWithKey: (t<'a>, (Chain.t, 'a) => 'b) => t<'b> = (map, fn) => Map.mapWithKey(map, fn)
40
+ let size: t<'a> => int = map => Map.size(map)
41
+ let update: (t<'a>, Chain.t, 'a => 'a) => t<'a> = (map, chain, updateFn) =>
42
+ Map.update(map, chain, opt => opt->Option.map(updateFn))