envio 2.32.0-alpha.0 → 2.32.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.
@@ -16,7 +16,7 @@ function reorgDetectedToLogParams(reorgDetected, shouldRollbackOnReorg) {
16
16
  };
17
17
  }
18
18
 
19
- function make(chainReorgCheckpoints, maxReorgDepth, shouldRollbackOnReorg, detectedReorgBlock) {
19
+ function make(chainReorgCheckpoints, maxReorgDepth, shouldRollbackOnReorg) {
20
20
  var dataByBlockNumber = {};
21
21
  Belt_Array.forEach(chainReorgCheckpoints, (function (block) {
22
22
  dataByBlockNumber[block.block_number] = {
@@ -27,8 +27,7 @@ function make(chainReorgCheckpoints, maxReorgDepth, shouldRollbackOnReorg, detec
27
27
  return {
28
28
  shouldRollbackOnReorg: shouldRollbackOnReorg,
29
29
  maxReorgDepth: maxReorgDepth,
30
- dataByBlockNumber: dataByBlockNumber,
31
- detectedReorgBlock: detectedReorgBlock
30
+ dataByBlockNumber: dataByBlockNumber
32
31
  };
33
32
  }
34
33
 
@@ -79,12 +78,7 @@ function registerReorgGuard(self, reorgGuard, currentBlockHeight) {
79
78
  }
80
79
  if (maybeReorgDetected !== undefined) {
81
80
  return [
82
- shouldRollbackOnReorg ? ({
83
- shouldRollbackOnReorg: self.shouldRollbackOnReorg,
84
- maxReorgDepth: self.maxReorgDepth,
85
- dataByBlockNumber: self.dataByBlockNumber,
86
- detectedReorgBlock: maybeReorgDetected.scannedBlock
87
- }) : make([], maxReorgDepth, shouldRollbackOnReorg, undefined),
81
+ shouldRollbackOnReorg ? self : make([], maxReorgDepth, shouldRollbackOnReorg),
88
82
  {
89
83
  TAG: "ReorgDetected",
90
84
  _0: maybeReorgDetected
@@ -99,8 +93,7 @@ function registerReorgGuard(self, reorgGuard, currentBlockHeight) {
99
93
  {
100
94
  shouldRollbackOnReorg: shouldRollbackOnReorg,
101
95
  maxReorgDepth: maxReorgDepth,
102
- dataByBlockNumber: dataByBlockNumberCopyInThreshold,
103
- detectedReorgBlock: undefined
96
+ dataByBlockNumber: dataByBlockNumberCopyInThreshold
104
97
  },
105
98
  "NoReorg"
106
99
  ];
@@ -115,12 +108,8 @@ function getLatestValidScannedBlock(reorgDetection, blockNumbersAndHashes) {
115
108
  }
116
109
  var ascBlockNumberKeys = Object.keys(verifiedDataByBlockNumber);
117
110
  var getPrevScannedBlockNumber = function (idx) {
118
- return Belt_Option.flatMap(Belt_Array.get(ascBlockNumberKeys, idx - 1 | 0), (function (key) {
119
- var v = verifiedDataByBlockNumber[key];
120
- if (v !== undefined) {
121
- return v.blockNumber;
122
- }
123
-
111
+ return Belt_Option.map(Belt_Array.get(ascBlockNumberKeys, idx - 1 | 0), (function (key) {
112
+ return verifiedDataByBlockNumber[key].blockNumber;
124
113
  }));
125
114
  };
126
115
  var _idx = 0;
@@ -131,8 +120,10 @@ function getLatestValidScannedBlock(reorgDetection, blockNumbersAndHashes) {
131
120
  return getPrevScannedBlockNumber(idx$1);
132
121
  }
133
122
  var scannedBlock = reorgDetection.dataByBlockNumber[blockNumberKey];
134
- var verifiedBlockData = verifiedDataByBlockNumber[blockNumberKey];
135
- if (verifiedBlockData.blockHash !== scannedBlock.blockHash) {
123
+ if (scannedBlock === undefined) {
124
+ return getPrevScannedBlockNumber(idx$1);
125
+ }
126
+ if (verifiedDataByBlockNumber[blockNumberKey].blockHash !== scannedBlock.blockHash) {
136
127
  return getPrevScannedBlockNumber(idx$1);
137
128
  }
138
129
  _idx = idx$1 + 1 | 0;
@@ -165,8 +156,7 @@ function rollbackToValidBlockNumber(param, blockNumber) {
165
156
  return {
166
157
  shouldRollbackOnReorg: param.shouldRollbackOnReorg,
167
158
  maxReorgDepth: param.maxReorgDepth,
168
- dataByBlockNumber: newDataByBlockNumber,
169
- detectedReorgBlock: undefined
159
+ dataByBlockNumber: newDataByBlockNumber
170
160
  };
171
161
  }
172
162
 
@@ -0,0 +1,110 @@
1
+ module FieldValue = {
2
+ open Belt
3
+ @unboxed
4
+ type rec tNonOptional =
5
+ | String(string)
6
+ | BigInt(bigint)
7
+ | Int(int)
8
+ | BigDecimal(BigDecimal.t)
9
+ | Bool(bool)
10
+ | Array(array<tNonOptional>)
11
+
12
+ let rec toString = tNonOptional =>
13
+ switch tNonOptional {
14
+ | String(v) => v
15
+ | BigInt(v) => v->BigInt.toString
16
+ | Int(v) => v->Int.toString
17
+ | BigDecimal(v) => v->BigDecimal.toString
18
+ | Bool(v) => v ? "true" : "false"
19
+ | Array(v) => `[${v->Array.joinWith(",", toString)}]`
20
+ }
21
+
22
+ //This needs to be a castable type from any type that we
23
+ //support in entities so that we can create evaluations
24
+ //and serialize the types without parsing/wrapping them
25
+ type t = option<tNonOptional>
26
+
27
+ let toString = (value: t) =>
28
+ switch value {
29
+ | Some(v) => v->toString
30
+ | None => "undefined"
31
+ }
32
+
33
+ external castFrom: 'a => t = "%identity"
34
+ external castTo: t => 'a = "%identity"
35
+
36
+ let eq = (a, b) =>
37
+ switch (a, b) {
38
+ //For big decimal use custom equals operator otherwise let Caml_obj.equal do its magic
39
+ | (Some(BigDecimal(bdA)), Some(BigDecimal(bdB))) => BigDecimal.equals(bdA, bdB)
40
+ | (a, b) => a == b
41
+ }
42
+
43
+ let gt = (a, b) =>
44
+ switch (a, b) {
45
+ //For big decimal use custom equals operator otherwise let Caml_obj.equal do its magic
46
+ | (Some(BigDecimal(bdA)), Some(BigDecimal(bdB))) => BigDecimal.gt(bdA, bdB)
47
+ | (a, b) => a > b
48
+ }
49
+
50
+ let lt = (a, b) =>
51
+ switch (a, b) {
52
+ //For big decimal use custom equals operator otherwise let Caml_obj.equal do its magic
53
+ | (Some(BigDecimal(bdA)), Some(BigDecimal(bdB))) => BigDecimal.lt(bdA, bdB)
54
+ | (a, b) => a < b
55
+ }
56
+ }
57
+
58
+ module Operator = {
59
+ type t = Eq | Gt | Lt
60
+
61
+ let values = [Eq, Gt, Lt]
62
+ }
63
+
64
+ module SingleIndex = {
65
+ type t = {fieldName: string, fieldValue: FieldValue.t, operator: Operator.t}
66
+
67
+ let make = (~fieldName, ~fieldValue: 'a, ~operator) => {
68
+ fieldName,
69
+ fieldValue: FieldValue.castFrom(fieldValue),
70
+ operator,
71
+ }
72
+
73
+ // Should much hashing logic in InMemoryTable
74
+ let toString = ({fieldName, fieldValue, operator}) =>
75
+ `${fieldName}:${(operator :> string)}:${fieldValue->FieldValue.toString}`
76
+
77
+ let evaluate = (self: t, ~fieldName, ~fieldValue) =>
78
+ self.fieldName === fieldName &&
79
+ switch self.operator {
80
+ | Eq => fieldValue->FieldValue.eq(self.fieldValue)
81
+ | Gt => fieldValue->FieldValue.gt(self.fieldValue)
82
+ | Lt => fieldValue->FieldValue.lt(self.fieldValue)
83
+ }
84
+ }
85
+
86
+ module Index = {
87
+ //Next step is to support composite indexes
88
+ @unboxed
89
+ type t = Single(SingleIndex.t) //| Composite(array<SingleIndex.t>)
90
+
91
+ let makeSingle = (~fieldName, ~fieldValue, ~operator) => Single(
92
+ SingleIndex.make(~fieldName, ~fieldValue, ~operator),
93
+ )
94
+
95
+ let getFieldName = index =>
96
+ switch index {
97
+ | Single(index) => index.fieldName
98
+ }
99
+
100
+ let toString = index =>
101
+ switch index {
102
+ | Single(index) => index->SingleIndex.toString
103
+ }
104
+
105
+ let evaluate = (index: t, ~fieldName, ~fieldValue) =>
106
+ switch index {
107
+ | Single(index) => SingleIndex.evaluate(index, ~fieldName, ~fieldValue)
108
+ }
109
+ }
110
+
@@ -0,0 +1,143 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+ 'use strict';
3
+
4
+ var Caml_obj = require("rescript/lib/js/caml_obj.js");
5
+ var Belt_Array = require("rescript/lib/js/belt_Array.js");
6
+
7
+ function toString(tNonOptional) {
8
+ if (Array.isArray(tNonOptional)) {
9
+ return "[" + Belt_Array.joinWith(tNonOptional, ",", toString) + "]";
10
+ }
11
+ switch (typeof tNonOptional) {
12
+ case "string" :
13
+ return tNonOptional;
14
+ case "number" :
15
+ return String(tNonOptional);
16
+ case "bigint" :
17
+ case "object" :
18
+ return tNonOptional.toString();
19
+ case "boolean" :
20
+ if (tNonOptional) {
21
+ return "true";
22
+ } else {
23
+ return "false";
24
+ }
25
+
26
+ }
27
+ }
28
+
29
+ function toString$1(value) {
30
+ if (value !== undefined) {
31
+ return toString(value);
32
+ } else {
33
+ return "undefined";
34
+ }
35
+ }
36
+
37
+ function eq(a, b) {
38
+ if (a !== undefined && typeof a === "object" && !Array.isArray(a) && b !== undefined && typeof b === "object" && !Array.isArray(b)) {
39
+ return a.isEqualTo(b);
40
+ } else {
41
+ return Caml_obj.equal(a, b);
42
+ }
43
+ }
44
+
45
+ function gt(a, b) {
46
+ if (a !== undefined && typeof a === "object" && !Array.isArray(a) && b !== undefined && typeof b === "object" && !Array.isArray(b)) {
47
+ return a.isGreaterThan(b);
48
+ } else {
49
+ return Caml_obj.greaterthan(a, b);
50
+ }
51
+ }
52
+
53
+ function lt(a, b) {
54
+ if (a !== undefined && typeof a === "object" && !Array.isArray(a) && b !== undefined && typeof b === "object" && !Array.isArray(b)) {
55
+ return a.isLessThan(b);
56
+ } else {
57
+ return Caml_obj.lessthan(a, b);
58
+ }
59
+ }
60
+
61
+ var FieldValue = {
62
+ toString: toString$1,
63
+ eq: eq,
64
+ gt: gt,
65
+ lt: lt
66
+ };
67
+
68
+ var values = [
69
+ "Eq",
70
+ "Gt",
71
+ "Lt"
72
+ ];
73
+
74
+ var Operator = {
75
+ values: values
76
+ };
77
+
78
+ function make(fieldName, fieldValue, operator) {
79
+ return {
80
+ fieldName: fieldName,
81
+ fieldValue: fieldValue,
82
+ operator: operator
83
+ };
84
+ }
85
+
86
+ function toString$2(param) {
87
+ return param.fieldName + ":" + param.operator + ":" + toString$1(param.fieldValue);
88
+ }
89
+
90
+ function evaluate(self, fieldName, fieldValue) {
91
+ if (self.fieldName !== fieldName) {
92
+ return false;
93
+ }
94
+ var match = self.operator;
95
+ switch (match) {
96
+ case "Eq" :
97
+ return eq(fieldValue, self.fieldValue);
98
+ case "Gt" :
99
+ return gt(fieldValue, self.fieldValue);
100
+ case "Lt" :
101
+ return lt(fieldValue, self.fieldValue);
102
+
103
+ }
104
+ }
105
+
106
+ var SingleIndex = {
107
+ make: make,
108
+ toString: toString$2,
109
+ evaluate: evaluate
110
+ };
111
+
112
+ function makeSingle(fieldName, fieldValue, operator) {
113
+ return {
114
+ fieldName: fieldName,
115
+ fieldValue: fieldValue,
116
+ operator: operator
117
+ };
118
+ }
119
+
120
+ function getFieldName(index) {
121
+ return index.fieldName;
122
+ }
123
+
124
+ function toString$3(index) {
125
+ return toString$2(index);
126
+ }
127
+
128
+ function evaluate$1(index, fieldName, fieldValue) {
129
+ return evaluate(index, fieldName, fieldValue);
130
+ }
131
+
132
+ var Index = {
133
+ makeSingle: makeSingle,
134
+ getFieldName: getFieldName,
135
+ toString: toString$3,
136
+ evaluate: evaluate$1
137
+ };
138
+
139
+ exports.FieldValue = FieldValue;
140
+ exports.Operator = Operator;
141
+ exports.SingleIndex = SingleIndex;
142
+ exports.Index = Index;
143
+ /* No side effect */
package/src/Types.ts CHANGED
@@ -44,6 +44,11 @@ export type EffectContext = {
44
44
  * Define a new Effect using createEffect outside of the handler.
45
45
  */
46
46
  readonly effect: EffectCaller;
47
+ /**
48
+ * Whether to cache the result of the effect. Defaults to the effect's cache configuration.
49
+ * Set to false to disable caching for this specific call.
50
+ */
51
+ cache: boolean;
47
52
  };
48
53
 
49
54
  export type GenericContractRegister<Args> = (
@@ -39,3 +39,7 @@ let intFromMillis = toInt
39
39
  let intFromNanos = toInt
40
40
  let intFromSeconds = toInt
41
41
  let floatFromMillis = Utils.magic
42
+
43
+ let millisBetween = (~from: timeRef, ~to: timeRef): int => {
44
+ to->toMillis->intFromMillis - from->toMillis->intFromMillis
45
+ }
@@ -39,6 +39,10 @@ function floatFromMillis(prim) {
39
39
  return prim;
40
40
  }
41
41
 
42
+ function millisBetween(from, to) {
43
+ return (toMillis(to) | 0) - (toMillis(from) | 0) | 0;
44
+ }
45
+
42
46
  function makeTimer(prim) {
43
47
  return process.hrtime();
44
48
  }
@@ -63,4 +67,5 @@ exports.intFromMillis = intFromMillis;
63
67
  exports.intFromNanos = intFromNanos;
64
68
  exports.intFromSeconds = intFromSeconds;
65
69
  exports.floatFromMillis = floatFromMillis;
70
+ exports.millisBetween = millisBetween;
66
71
  /* No side effect */
@@ -22,3 +22,5 @@ let intFromMillis: milliseconds => int
22
22
  let intFromNanos: nanoseconds => int
23
23
  let intFromSeconds: seconds => int
24
24
  let floatFromMillis: milliseconds => float
25
+
26
+ let millisBetween: (~from: timeRef, ~to: timeRef) => int
@@ -0,0 +1,3 @@
1
+ // TODO: Remove this file once we have our own impl of cloneDeep or it is no longer needed
2
+ @module("./vendored-lodash-fns.js") external cloneDeep: 'a => 'a = "cloneDeep"
3
+
@@ -0,0 +1,11 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+ 'use strict';
3
+
4
+ var VendoredLodashFnsJs = require("./vendored-lodash-fns.js");
5
+
6
+ function cloneDeep(prim) {
7
+ return VendoredLodashFnsJs.cloneDeep(prim);
8
+ }
9
+
10
+ exports.cloneDeep = cloneDeep;
11
+ /* ./vendored-lodash-fns.js Not a pure module */