envio 2.26.0-rc.0 → 2.26.0-rc.2
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/evm.schema.json +7 -0
- package/fuel.schema.json +7 -0
- package/index.d.ts +6 -22
- package/index.js +2 -1
- package/package.json +5 -5
- package/src/Envio.gen.ts +3 -1
- package/src/Envio.res +27 -0
- package/src/Envio.res.js +28 -1
- package/src/FetchState.res +1 -4
- package/src/Internal.res +20 -0
- package/src/Internal.res.js +12 -0
- package/src/Logging.res +8 -0
- package/src/Logging.res.js +29 -0
- package/src/Persistence.res +109 -47
- package/src/Persistence.res.js +62 -17
- package/src/PgStorage.res +488 -86
- package/src/PgStorage.res.js +365 -57
- package/src/Prometheus.res +12 -0
- package/src/Prometheus.res.js +12 -0
- package/src/Utils.res +39 -9
- package/src/Utils.res.js +17 -6
- package/src/bindings/BigInt.gen.ts +10 -0
- package/src/bindings/BigInt.res +1 -0
- package/src/bindings/NodeJs.res +27 -26
- package/src/bindings/NodeJs.res.js +5 -13
- package/src/db/EntityHistory.res +5 -28
- package/src/db/EntityHistory.res.js +4 -23
- package/src/db/Table.res +3 -61
- package/src/db/Table.res.js +3 -42
package/src/Persistence.res.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
5
|
+
var Logging = require("./Logging.res.js");
|
|
6
|
+
var Prometheus = require("./Prometheus.res.js");
|
|
5
7
|
var EntityHistory = require("./db/EntityHistory.res.js");
|
|
6
8
|
var ErrorHandling = require("./ErrorHandling.res.js");
|
|
7
9
|
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
@@ -22,7 +24,7 @@ var entityHistoryActionEnumConfig = {
|
|
|
22
24
|
default: "SET"
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, storage
|
|
27
|
+
function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, storage) {
|
|
26
28
|
var allEntities = userEntities.concat([dcRegistryEntityConfig]);
|
|
27
29
|
var allEnums$1 = allEnums.concat([entityHistoryActionEnumConfig]);
|
|
28
30
|
return {
|
|
@@ -31,14 +33,21 @@ function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, stor
|
|
|
31
33
|
allEntities: allEntities,
|
|
32
34
|
allEnums: allEnums$1,
|
|
33
35
|
storageStatus: "Unknown",
|
|
34
|
-
storage: storage
|
|
35
|
-
onStorageInitialize: onStorageInitialize,
|
|
36
|
-
cacheStorage: cacheStorage
|
|
36
|
+
storage: storage
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async function
|
|
41
|
-
var
|
|
40
|
+
async function loadInitialCache(persistence, withUpload) {
|
|
41
|
+
var effectCacheRecords = await persistence.storage.restoreEffectCache(withUpload);
|
|
42
|
+
var cache = {};
|
|
43
|
+
effectCacheRecords.forEach(function (record) {
|
|
44
|
+
Prometheus.EffectCacheCount.set(record.count, record.effectName);
|
|
45
|
+
cache[record.effectName] = record;
|
|
46
|
+
});
|
|
47
|
+
return cache;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function init(persistence, resetOpt) {
|
|
42
51
|
var reset = resetOpt !== undefined ? resetOpt : false;
|
|
43
52
|
try {
|
|
44
53
|
var promise = persistence.storageStatus;
|
|
@@ -64,20 +73,26 @@ async function init(persistence, skipIsInitializedCheckOpt, resetOpt) {
|
|
|
64
73
|
TAG: "Initializing",
|
|
65
74
|
_0: promise$1
|
|
66
75
|
};
|
|
67
|
-
if (
|
|
76
|
+
if (reset || !await persistence.storage.isInitialized()) {
|
|
77
|
+
Logging.info("Initializing the indexer storage...");
|
|
78
|
+
await persistence.storage.initialize(persistence.allEntities, persistence.staticTables, persistence.allEnums);
|
|
79
|
+
Logging.info("The indexer storage is ready. Uploading cache...");
|
|
68
80
|
persistence.storageStatus = {
|
|
69
81
|
TAG: "Ready",
|
|
70
|
-
cleanRun:
|
|
82
|
+
cleanRun: true,
|
|
83
|
+
cache: await loadInitialCache(persistence, true)
|
|
71
84
|
};
|
|
72
85
|
} else {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
var match = persistence.storageStatus;
|
|
87
|
+
var tmp;
|
|
88
|
+
tmp = typeof match !== "object" || match.TAG !== "Initializing" ? false : true;
|
|
89
|
+
if (tmp) {
|
|
90
|
+
Logging.info("The indexer storage is ready.");
|
|
91
|
+
persistence.storageStatus = {
|
|
92
|
+
TAG: "Ready",
|
|
93
|
+
cleanRun: false,
|
|
94
|
+
cache: await loadInitialCache(persistence, false)
|
|
95
|
+
};
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
}
|
|
@@ -98,9 +113,39 @@ function getInitializedStorageOrThrow(persistence) {
|
|
|
98
113
|
}
|
|
99
114
|
}
|
|
100
115
|
|
|
116
|
+
async function setEffectCacheOrThrow(persistence, effect, items) {
|
|
117
|
+
var match = persistence.storageStatus;
|
|
118
|
+
if (typeof match !== "object") {
|
|
119
|
+
return Js_exn.raiseError("Failed to access the indexer storage. The Persistence layer is not initialized.");
|
|
120
|
+
}
|
|
121
|
+
if (match.TAG === "Initializing") {
|
|
122
|
+
return Js_exn.raiseError("Failed to access the indexer storage. The Persistence layer is not initialized.");
|
|
123
|
+
}
|
|
124
|
+
var cache = match.cache;
|
|
125
|
+
var storage = persistence.storage;
|
|
126
|
+
var effectName = effect.name;
|
|
127
|
+
var c = cache[effectName];
|
|
128
|
+
var effectCacheRecord;
|
|
129
|
+
if (c !== undefined) {
|
|
130
|
+
effectCacheRecord = c;
|
|
131
|
+
} else {
|
|
132
|
+
var c$1 = {
|
|
133
|
+
effectName: effectName,
|
|
134
|
+
count: 0
|
|
135
|
+
};
|
|
136
|
+
cache[effectName] = c$1;
|
|
137
|
+
effectCacheRecord = c$1;
|
|
138
|
+
}
|
|
139
|
+
var initialize = effectCacheRecord.count === 0;
|
|
140
|
+
await storage.setEffectCacheOrThrow(effect, items, initialize);
|
|
141
|
+
effectCacheRecord.count = effectCacheRecord.count + items.length | 0;
|
|
142
|
+
return Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
|
|
143
|
+
}
|
|
144
|
+
|
|
101
145
|
exports.StorageError = StorageError;
|
|
102
146
|
exports.entityHistoryActionEnumConfig = entityHistoryActionEnumConfig;
|
|
103
147
|
exports.make = make;
|
|
104
148
|
exports.init = init;
|
|
105
149
|
exports.getInitializedStorageOrThrow = getInitializedStorageOrThrow;
|
|
106
|
-
|
|
150
|
+
exports.setEffectCacheOrThrow = setEffectCacheOrThrow;
|
|
151
|
+
/* Logging Not a pure module */
|