envio 2.22.0 → 2.22.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/package.json +7 -6
- package/src/Address.res.js +30 -0
- package/src/ChainMap.res.js +77 -0
- package/src/Envio.res.js +16 -0
- package/src/ErrorHandling.res.js +56 -0
- package/src/EventUtils.res.js +75 -0
- package/src/EvmTypes.res.js +16 -0
- package/src/FetchState.res.js +969 -0
- package/src/Hasura.res.js +245 -0
- package/src/Internal.res.js +50 -0
- package/src/LazyLoader.res.js +117 -0
- package/src/LoadManager.res.js +124 -0
- package/src/LogSelection.res.js +203 -0
- package/src/Logging.res.js +247 -0
- package/src/Persistence.res.js +90 -0
- package/src/PgStorage.res +18 -4
- package/src/PgStorage.res.js +125 -0
- package/src/Prometheus.res.js +750 -0
- package/src/ReorgDetection.res.js +223 -0
- package/src/Throttler.res.js +60 -0
- package/src/Time.res.js +41 -0
- package/src/TopicFilter.res.js +86 -0
- package/src/Utils.res.js +527 -0
- package/src/bindings/BigDecimal.res.js +41 -0
- package/src/bindings/BigInt.res.js +138 -0
- package/src/bindings/Ethers.res.js +109 -0
- package/src/bindings/Express.res.js +2 -0
- package/src/bindings/Hrtime.res.js +66 -0
- package/src/bindings/NodeJs.res.js +29 -0
- package/src/bindings/Pino.res.js +95 -0
- package/src/bindings/Postgres.res.js +16 -0
- package/src/bindings/PromClient.res.js +17 -0
- package/src/bindings/Promise.res.js +25 -0
- package/src/bindings/SDSL.res.js +8 -0
- package/src/bindings/Viem.res.js +45 -0
- package/src/db/EntityHistory.res.js +307 -0
- package/src/db/Schema.res.js +54 -0
- package/src/db/Table.res.js +365 -0
- package/src/sources/Fuel.res.js +28 -0
- package/src/sources/HyperFuel.res.js +193 -0
- package/src/sources/HyperFuelClient.res.js +19 -0
- package/src/sources/HyperSync.res.js +301 -0
- package/src/sources/HyperSyncClient.res.js +99 -0
- package/src/sources/HyperSyncJsonApi.res.js +259 -0
- package/src/sources/Rpc.res.js +198 -0
- package/src/sources/Source.res.js +9 -0
- package/src/sources/SourceManager.res.js +366 -0
- package/src/vendored/Rest.res.js +574 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var $$BigInt = require("../bindings/BigInt.res.js");
|
|
5
|
+
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
6
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
7
|
+
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
8
|
+
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
9
|
+
var Belt_SetString = require("rescript/lib/js/belt_SetString.js");
|
|
10
|
+
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
11
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
12
|
+
|
|
13
|
+
function mkField(fieldName, fieldType, fieldSchema, $$default, isArrayOpt, isNullableOpt, isPrimaryKeyOpt, isIndexOpt, linkedEntity) {
|
|
14
|
+
var isArray = isArrayOpt !== undefined ? isArrayOpt : false;
|
|
15
|
+
var isNullable = isNullableOpt !== undefined ? isNullableOpt : false;
|
|
16
|
+
var isPrimaryKey = isPrimaryKeyOpt !== undefined ? isPrimaryKeyOpt : false;
|
|
17
|
+
var isIndex = isIndexOpt !== undefined ? isIndexOpt : false;
|
|
18
|
+
return {
|
|
19
|
+
TAG: "Field",
|
|
20
|
+
_0: {
|
|
21
|
+
fieldName: fieldName,
|
|
22
|
+
fieldType: fieldType,
|
|
23
|
+
fieldSchema: fieldSchema,
|
|
24
|
+
isArray: isArray,
|
|
25
|
+
isNullable: isNullable,
|
|
26
|
+
isPrimaryKey: isPrimaryKey,
|
|
27
|
+
isIndex: isIndex,
|
|
28
|
+
linkedEntity: linkedEntity,
|
|
29
|
+
defaultValue: $$default
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function mkDerivedFromField(fieldName, derivedFromEntity, derivedFromField) {
|
|
35
|
+
return {
|
|
36
|
+
TAG: "DerivedFrom",
|
|
37
|
+
_0: {
|
|
38
|
+
fieldName: fieldName,
|
|
39
|
+
derivedFromEntity: derivedFromEntity,
|
|
40
|
+
derivedFromField: derivedFromField
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getUserDefinedFieldName(fieldOrDerived) {
|
|
46
|
+
return fieldOrDerived._0.fieldName;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isLinkedEntityField(field) {
|
|
50
|
+
return Belt_Option.isSome(field.linkedEntity);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getDbFieldName(field) {
|
|
54
|
+
if (Belt_Option.isSome(field.linkedEntity)) {
|
|
55
|
+
return field.fieldName + "_id";
|
|
56
|
+
} else {
|
|
57
|
+
return field.fieldName;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getFieldName(fieldOrDerived) {
|
|
62
|
+
if (fieldOrDerived.TAG === "Field") {
|
|
63
|
+
return getDbFieldName(fieldOrDerived._0);
|
|
64
|
+
} else {
|
|
65
|
+
return fieldOrDerived._0.fieldName;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getFieldType(field) {
|
|
70
|
+
return field.fieldType + (
|
|
71
|
+
field.isArray ? "[]" : ""
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function mkTable(tableName, schemaName, compositeIndicesOpt, fields) {
|
|
76
|
+
var compositeIndices = compositeIndicesOpt !== undefined ? compositeIndicesOpt : [];
|
|
77
|
+
return {
|
|
78
|
+
tableName: tableName,
|
|
79
|
+
schemaName: schemaName,
|
|
80
|
+
fields: fields,
|
|
81
|
+
compositeIndices: compositeIndices
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getPrimaryKeyFieldNames(table) {
|
|
86
|
+
return Belt_Array.keepMap(table.fields, (function (field) {
|
|
87
|
+
if (field.TAG !== "Field") {
|
|
88
|
+
return ;
|
|
89
|
+
}
|
|
90
|
+
var match = field._0;
|
|
91
|
+
if (match.isPrimaryKey) {
|
|
92
|
+
return match.fieldName;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getFields(table) {
|
|
99
|
+
return Belt_Array.keepMap(table.fields, (function (field) {
|
|
100
|
+
if (field.TAG === "Field") {
|
|
101
|
+
return field._0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getFieldNames(table) {
|
|
108
|
+
return Belt_Array.map(getFields(table), getDbFieldName);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getNonDefaultFields(table) {
|
|
112
|
+
return Belt_Array.keepMap(table.fields, (function (field) {
|
|
113
|
+
if (field.TAG !== "Field") {
|
|
114
|
+
return ;
|
|
115
|
+
}
|
|
116
|
+
var field$1 = field._0;
|
|
117
|
+
if (Belt_Option.isNone(field$1.defaultValue)) {
|
|
118
|
+
return field$1;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getLinkedEntityFields(table) {
|
|
125
|
+
return Belt_Array.keepMap(table.fields, (function (field) {
|
|
126
|
+
if (field.TAG !== "Field") {
|
|
127
|
+
return ;
|
|
128
|
+
}
|
|
129
|
+
var field$1 = field._0;
|
|
130
|
+
var linkedEntityName = field$1.linkedEntity;
|
|
131
|
+
if (linkedEntityName !== undefined) {
|
|
132
|
+
return [
|
|
133
|
+
field$1,
|
|
134
|
+
linkedEntityName
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getDerivedFromFields(table) {
|
|
142
|
+
return Belt_Array.keepMap(table.fields, (function (field) {
|
|
143
|
+
if (field.TAG === "Field") {
|
|
144
|
+
return ;
|
|
145
|
+
} else {
|
|
146
|
+
return field._0;
|
|
147
|
+
}
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getNonDefaultFieldNames(table) {
|
|
152
|
+
return Belt_Array.map(getNonDefaultFields(table), getDbFieldName);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function getFieldByName(table, fieldName) {
|
|
156
|
+
return Caml_option.undefined_to_opt(table.fields.find(function (field) {
|
|
157
|
+
return field._0.fieldName === fieldName;
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function getFieldByDbName(table, dbFieldName) {
|
|
162
|
+
return Caml_option.undefined_to_opt(table.fields.find(function (field) {
|
|
163
|
+
var tmp;
|
|
164
|
+
tmp = field.TAG === "Field" ? getDbFieldName(field._0) : field._0.fieldName;
|
|
165
|
+
return tmp === dbFieldName;
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var NonExistingTableField = /* @__PURE__ */Caml_exceptions.create("Table.NonExistingTableField");
|
|
170
|
+
|
|
171
|
+
function getUnfilteredCompositeIndicesUnsafe(table) {
|
|
172
|
+
return Belt_Array.map(table.compositeIndices, (function (compositeIndex) {
|
|
173
|
+
return Belt_Array.map(compositeIndex, (function (userDefinedFieldName) {
|
|
174
|
+
var field = getFieldByName(table, userDefinedFieldName);
|
|
175
|
+
if (field !== undefined) {
|
|
176
|
+
return getFieldName(field);
|
|
177
|
+
}
|
|
178
|
+
throw {
|
|
179
|
+
RE_EXN_ID: NonExistingTableField,
|
|
180
|
+
_1: userDefinedFieldName,
|
|
181
|
+
Error: new Error()
|
|
182
|
+
};
|
|
183
|
+
}));
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function toSqlParams(table, schema) {
|
|
188
|
+
var quotedFieldNames = [];
|
|
189
|
+
var quotedNonPrimaryFieldNames = [];
|
|
190
|
+
var arrayFieldTypes = [];
|
|
191
|
+
var hasArrayField = {
|
|
192
|
+
contents: false
|
|
193
|
+
};
|
|
194
|
+
var dbSchema = S$RescriptSchema.schema(function (s) {
|
|
195
|
+
var match = schema.t;
|
|
196
|
+
if (typeof match !== "object") {
|
|
197
|
+
return Js_exn.raiseError("Failed creating db schema. Expected an object schema for table");
|
|
198
|
+
}
|
|
199
|
+
if (match.TAG !== "object") {
|
|
200
|
+
return Js_exn.raiseError("Failed creating db schema. Expected an object schema for table");
|
|
201
|
+
}
|
|
202
|
+
var dict = {};
|
|
203
|
+
Belt_Array.forEach(match.items, (function (param) {
|
|
204
|
+
var inlinedLocation = param.inlinedLocation;
|
|
205
|
+
var $$location = param.location;
|
|
206
|
+
var coerceSchema = function (schema) {
|
|
207
|
+
var child = schema.t;
|
|
208
|
+
if (typeof child !== "object") {
|
|
209
|
+
switch (child) {
|
|
210
|
+
case "bigint" :
|
|
211
|
+
return $$BigInt.schema;
|
|
212
|
+
case "boolean" :
|
|
213
|
+
return S$RescriptSchema.union([
|
|
214
|
+
S$RescriptSchema.shape(S$RescriptSchema.literal(1), (function (param) {
|
|
215
|
+
return true;
|
|
216
|
+
})),
|
|
217
|
+
S$RescriptSchema.shape(S$RescriptSchema.literal(0), (function (param) {
|
|
218
|
+
return false;
|
|
219
|
+
}))
|
|
220
|
+
]);
|
|
221
|
+
default:
|
|
222
|
+
return schema;
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
switch (child.TAG) {
|
|
226
|
+
case "option" :
|
|
227
|
+
case "null" :
|
|
228
|
+
return S$RescriptSchema.$$null(coerceSchema(child._0));
|
|
229
|
+
case "array" :
|
|
230
|
+
hasArrayField.contents = true;
|
|
231
|
+
return S$RescriptSchema.array(coerceSchema(child._0));
|
|
232
|
+
case "JSON" :
|
|
233
|
+
hasArrayField.contents = true;
|
|
234
|
+
return schema;
|
|
235
|
+
default:
|
|
236
|
+
return schema;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
var field = getFieldByDbName(table, $$location);
|
|
241
|
+
var field$1;
|
|
242
|
+
if (field !== undefined) {
|
|
243
|
+
field$1 = field;
|
|
244
|
+
} else {
|
|
245
|
+
throw {
|
|
246
|
+
RE_EXN_ID: NonExistingTableField,
|
|
247
|
+
_1: $$location,
|
|
248
|
+
Error: new Error()
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
quotedFieldNames.push(inlinedLocation);
|
|
252
|
+
if (field$1.TAG === "Field") {
|
|
253
|
+
if (field$1._0.isPrimaryKey) {
|
|
254
|
+
|
|
255
|
+
} else {
|
|
256
|
+
quotedNonPrimaryFieldNames.push(inlinedLocation);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
var tmp;
|
|
260
|
+
if (field$1.TAG === "Field") {
|
|
261
|
+
var f = field$1._0;
|
|
262
|
+
var fieldType = f.fieldType;
|
|
263
|
+
tmp = fieldType === "TIMESTAMP" || fieldType === "TIMESTAMP WITH TIME ZONE" || fieldType === "JSONB" || fieldType === "SERIAL" || fieldType === "TEXT" || fieldType === "DOUBLE PRECISION" || fieldType === "NUMERIC" || fieldType === "BOOLEAN" || fieldType === "INTEGER" || fieldType === "TIMESTAMP WITH TIME ZONE NULL" ? (
|
|
264
|
+
fieldType === "BOOLEAN" ? "INTEGER[]::" + f.fieldType : fieldType
|
|
265
|
+
) : "TEXT[]::" + fieldType;
|
|
266
|
+
} else {
|
|
267
|
+
tmp = "TEXT";
|
|
268
|
+
}
|
|
269
|
+
arrayFieldTypes.push(tmp + "[]");
|
|
270
|
+
dict[$$location] = s.m(coerceSchema(param.schema));
|
|
271
|
+
}));
|
|
272
|
+
return dict;
|
|
273
|
+
});
|
|
274
|
+
return {
|
|
275
|
+
dbSchema: dbSchema,
|
|
276
|
+
quotedFieldNames: quotedFieldNames,
|
|
277
|
+
quotedNonPrimaryFieldNames: quotedNonPrimaryFieldNames,
|
|
278
|
+
arrayFieldTypes: arrayFieldTypes,
|
|
279
|
+
hasArrayField: hasArrayField.contents
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function getSingleIndices(table) {
|
|
284
|
+
var indexFields = Belt_Array.keepMap(table.fields, (function (field) {
|
|
285
|
+
if (field.TAG !== "Field") {
|
|
286
|
+
return ;
|
|
287
|
+
}
|
|
288
|
+
var field$1 = field._0;
|
|
289
|
+
if (field$1.isIndex) {
|
|
290
|
+
return getDbFieldName(field$1);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
}));
|
|
294
|
+
return Belt_SetString.toArray(Belt_SetString.fromArray(Belt_Array.concatMany(Belt_Array.concat(Belt_Array.keep(getUnfilteredCompositeIndicesUnsafe(table), (function (cidx) {
|
|
295
|
+
return cidx.length === 1;
|
|
296
|
+
})), [indexFields])))).sort();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function getCompositeIndices(table) {
|
|
300
|
+
return Belt_Array.keep(getUnfilteredCompositeIndicesUnsafe(table), (function (ind) {
|
|
301
|
+
return ind.length > 1;
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function makeBatchSetFnString(table) {
|
|
306
|
+
var fieldNamesInQuotes = Belt_Array.map(getNonDefaultFieldNames(table), (function (fieldName) {
|
|
307
|
+
return "\"" + fieldName + "\"";
|
|
308
|
+
}));
|
|
309
|
+
return "(sql, rows) => {\n return sql\`\n INSERT INTO \"" + table.schemaName + "\".\"" + table.tableName + "\"\n \${sql(rows, " + fieldNamesInQuotes.join(", ") + ")}\n ON CONFLICT(" + getPrimaryKeyFieldNames(table).join(", ") + ") DO UPDATE\n SET\n " + Belt_Array.map(fieldNamesInQuotes, (function (fieldNameInQuotes) {
|
|
310
|
+
return fieldNameInQuotes + " = EXCLUDED." + fieldNameInQuotes;
|
|
311
|
+
})).join(", ") + ";\`\n }";
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function chunkBatchQuery(sql, entityDataArray, queryToExecute, maxItemsPerQueryOpt) {
|
|
315
|
+
var maxItemsPerQuery = maxItemsPerQueryOpt !== undefined ? maxItemsPerQueryOpt : 500;
|
|
316
|
+
var responses = [];
|
|
317
|
+
var i = 0;
|
|
318
|
+
while(i < entityDataArray.length) {
|
|
319
|
+
var chunk = entityDataArray.slice(i, i + maxItemsPerQuery | 0);
|
|
320
|
+
var response = queryToExecute(sql, chunk);
|
|
321
|
+
responses.push(response);
|
|
322
|
+
i = i + maxItemsPerQuery | 0;
|
|
323
|
+
};
|
|
324
|
+
return Promise.all(responses);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function makeBatchSetFn(table, schema) {
|
|
328
|
+
var batchSetFn = eval(makeBatchSetFnString(table));
|
|
329
|
+
var parseOrThrow = S$RescriptSchema.compile(S$RescriptSchema.array(schema), "Output", "Json", "Sync", true);
|
|
330
|
+
return async function (sql, rows) {
|
|
331
|
+
var rowsJson = parseOrThrow(rows);
|
|
332
|
+
await chunkBatchQuery(sql, rowsJson, batchSetFn, undefined);
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
var PostgresInterop = {
|
|
337
|
+
makeBatchSetFnString: makeBatchSetFnString,
|
|
338
|
+
chunkBatchQuery: chunkBatchQuery,
|
|
339
|
+
makeBatchSetFn: makeBatchSetFn
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
exports.mkField = mkField;
|
|
343
|
+
exports.mkDerivedFromField = mkDerivedFromField;
|
|
344
|
+
exports.getUserDefinedFieldName = getUserDefinedFieldName;
|
|
345
|
+
exports.isLinkedEntityField = isLinkedEntityField;
|
|
346
|
+
exports.getDbFieldName = getDbFieldName;
|
|
347
|
+
exports.getFieldName = getFieldName;
|
|
348
|
+
exports.getFieldType = getFieldType;
|
|
349
|
+
exports.mkTable = mkTable;
|
|
350
|
+
exports.getPrimaryKeyFieldNames = getPrimaryKeyFieldNames;
|
|
351
|
+
exports.getFields = getFields;
|
|
352
|
+
exports.getFieldNames = getFieldNames;
|
|
353
|
+
exports.getNonDefaultFields = getNonDefaultFields;
|
|
354
|
+
exports.getLinkedEntityFields = getLinkedEntityFields;
|
|
355
|
+
exports.getDerivedFromFields = getDerivedFromFields;
|
|
356
|
+
exports.getNonDefaultFieldNames = getNonDefaultFieldNames;
|
|
357
|
+
exports.getFieldByName = getFieldByName;
|
|
358
|
+
exports.getFieldByDbName = getFieldByDbName;
|
|
359
|
+
exports.NonExistingTableField = NonExistingTableField;
|
|
360
|
+
exports.getUnfilteredCompositeIndicesUnsafe = getUnfilteredCompositeIndicesUnsafe;
|
|
361
|
+
exports.toSqlParams = toSqlParams;
|
|
362
|
+
exports.getSingleIndices = getSingleIndices;
|
|
363
|
+
exports.getCompositeIndices = getCompositeIndices;
|
|
364
|
+
exports.PostgresInterop = PostgresInterop;
|
|
365
|
+
/* BigInt Not a pure module */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var VendoredFuelAbiCoderJs = require("./vendored-fuel-abi-coder.js");
|
|
5
|
+
|
|
6
|
+
function transpileAbi(prim) {
|
|
7
|
+
return VendoredFuelAbiCoderJs.transpileAbi(prim);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getLogDecoder(prim0, prim1) {
|
|
11
|
+
return VendoredFuelAbiCoderJs.AbiCoder.getLogDecoder(prim0, prim1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getLogDataDecoder(abi, logId) {
|
|
15
|
+
var decode = VendoredFuelAbiCoderJs.AbiCoder.getLogDecoder(abi, logId);
|
|
16
|
+
return function (data) {
|
|
17
|
+
return decode(data);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var Receipt = {
|
|
22
|
+
getLogDataDecoder: getLogDataDecoder
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.transpileAbi = transpileAbi;
|
|
26
|
+
exports.getLogDecoder = getLogDecoder;
|
|
27
|
+
exports.Receipt = Receipt;
|
|
28
|
+
/* ./vendored-fuel-abi-coder.js Not a pure module */
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Time = require("../Time.res.js");
|
|
5
|
+
var Logging = require("../Logging.res.js");
|
|
6
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
7
|
+
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
8
|
+
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
9
|
+
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
10
|
+
var HyperFuelClient = require("./HyperFuelClient.res.js");
|
|
11
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
12
|
+
|
|
13
|
+
var cache = {};
|
|
14
|
+
|
|
15
|
+
function getClient(url) {
|
|
16
|
+
var client = cache[url];
|
|
17
|
+
if (client !== undefined) {
|
|
18
|
+
return Caml_option.valFromOption(client);
|
|
19
|
+
}
|
|
20
|
+
var newClient = HyperFuelClient.make({
|
|
21
|
+
url: url
|
|
22
|
+
});
|
|
23
|
+
cache[url] = newClient;
|
|
24
|
+
return newClient;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function queryErrorToMsq(e) {
|
|
28
|
+
var match = e._0;
|
|
29
|
+
return match.queryName + " query failed due to unexpected missing params on response:\n " + match.missingParams.join(", ");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var $$Error = /* @__PURE__ */Caml_exceptions.create("HyperFuel.GetLogs.Error");
|
|
33
|
+
|
|
34
|
+
function makeRequestBody(fromBlock, toBlockInclusive, recieptsSelection) {
|
|
35
|
+
return {
|
|
36
|
+
fromBlock: fromBlock,
|
|
37
|
+
toBlock: toBlockInclusive !== undefined ? toBlockInclusive + 1 | 0 : undefined,
|
|
38
|
+
receipts: recieptsSelection,
|
|
39
|
+
fieldSelection: {
|
|
40
|
+
block: [
|
|
41
|
+
"id",
|
|
42
|
+
"height",
|
|
43
|
+
"time"
|
|
44
|
+
],
|
|
45
|
+
receipt: [
|
|
46
|
+
"tx_id",
|
|
47
|
+
"block_height",
|
|
48
|
+
"root_contract_id",
|
|
49
|
+
"data",
|
|
50
|
+
"receipt_index",
|
|
51
|
+
"receipt_type",
|
|
52
|
+
"rb",
|
|
53
|
+
"sub_id",
|
|
54
|
+
"val",
|
|
55
|
+
"amount",
|
|
56
|
+
"to_address",
|
|
57
|
+
"asset_id",
|
|
58
|
+
"to"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getParam(param, name) {
|
|
65
|
+
if (param !== undefined) {
|
|
66
|
+
return Caml_option.valFromOption(param);
|
|
67
|
+
}
|
|
68
|
+
throw {
|
|
69
|
+
RE_EXN_ID: $$Error,
|
|
70
|
+
_1: {
|
|
71
|
+
TAG: "UnexpectedMissingParams",
|
|
72
|
+
missingParams: [name]
|
|
73
|
+
},
|
|
74
|
+
Error: new Error()
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function decodeLogQueryPageItems(response_data) {
|
|
79
|
+
var blocksDict = {};
|
|
80
|
+
Belt_Array.forEach(response_data.blocks, (function (block) {
|
|
81
|
+
blocksDict[block.height] = block;
|
|
82
|
+
}));
|
|
83
|
+
var items = [];
|
|
84
|
+
Belt_Array.forEach(response_data.receipts, (function (receipt) {
|
|
85
|
+
var contractId = receipt.rootContractId;
|
|
86
|
+
if (contractId === undefined) {
|
|
87
|
+
return ;
|
|
88
|
+
}
|
|
89
|
+
var block = getParam(blocksDict[receipt.blockHeight], "Failed to find block associated to receipt");
|
|
90
|
+
items.push({
|
|
91
|
+
transactionId: receipt.txId,
|
|
92
|
+
contractId: Caml_option.valFromOption(contractId),
|
|
93
|
+
receipt: receipt,
|
|
94
|
+
receiptIndex: receipt.receiptIndex,
|
|
95
|
+
block: {
|
|
96
|
+
id: block.id,
|
|
97
|
+
time: block.time,
|
|
98
|
+
height: block.height
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}));
|
|
102
|
+
return items;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function query(serverUrl, fromBlock, toBlock, recieptsSelection) {
|
|
106
|
+
var query$1 = makeRequestBody(fromBlock, toBlock, recieptsSelection);
|
|
107
|
+
var hyperFuelClient = getClient(serverUrl);
|
|
108
|
+
var res = await hyperFuelClient.getSelectedData(query$1);
|
|
109
|
+
if (res.nextBlock <= fromBlock) {
|
|
110
|
+
throw {
|
|
111
|
+
RE_EXN_ID: $$Error,
|
|
112
|
+
_1: "WrongInstance",
|
|
113
|
+
Error: new Error()
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
items: decodeLogQueryPageItems(res.data),
|
|
118
|
+
nextBlock: res.nextBlock,
|
|
119
|
+
archiveHeight: Belt_Option.getWithDefault(res.archiveHeight, 0)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function queryBlockData(serverUrl, blockNumber, logger) {
|
|
124
|
+
var query_toBlock = blockNumber + 1 | 0;
|
|
125
|
+
var query_inputs = [{}];
|
|
126
|
+
var query_outputs = [{}];
|
|
127
|
+
var query_includeAllBlocks = true;
|
|
128
|
+
var query_fieldSelection = {
|
|
129
|
+
block: [
|
|
130
|
+
"height",
|
|
131
|
+
"id",
|
|
132
|
+
"time"
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
var query = {
|
|
136
|
+
fromBlock: blockNumber,
|
|
137
|
+
toBlock: query_toBlock,
|
|
138
|
+
inputs: query_inputs,
|
|
139
|
+
outputs: query_outputs,
|
|
140
|
+
includeAllBlocks: query_includeAllBlocks,
|
|
141
|
+
fieldSelection: query_fieldSelection
|
|
142
|
+
};
|
|
143
|
+
var hyperFuelClient = getClient(serverUrl);
|
|
144
|
+
var logger$1 = Logging.createChildFrom(logger, {
|
|
145
|
+
logType: "hypersync get blockhash query",
|
|
146
|
+
blockNumber: blockNumber
|
|
147
|
+
});
|
|
148
|
+
var executeQuery = function () {
|
|
149
|
+
return hyperFuelClient.getSelectedData(query);
|
|
150
|
+
};
|
|
151
|
+
var res = await Time.retryAsyncWithExponentialBackOff(undefined, undefined, undefined, undefined, logger$1, executeQuery);
|
|
152
|
+
if (res.nextBlock > blockNumber) {
|
|
153
|
+
return Belt_Option.flatMap(res.data.blocks, (function (blocks) {
|
|
154
|
+
return Belt_Option.map(Belt_Array.get(blocks, 0), (function (block) {
|
|
155
|
+
return {
|
|
156
|
+
blockHash: block.id,
|
|
157
|
+
blockNumber: block.height,
|
|
158
|
+
blockTimestamp: block.time
|
|
159
|
+
};
|
|
160
|
+
}));
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
var logger$2 = Logging.createChild({
|
|
164
|
+
url: serverUrl
|
|
165
|
+
});
|
|
166
|
+
Logging.childInfo(logger$2, "Block #" + String(blockNumber) + " not found in HyperFuel. HyperFuel has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in " + String(100) + "ms.");
|
|
167
|
+
await Time.resolvePromiseAfterDelay(100);
|
|
168
|
+
return await queryBlockData(serverUrl, blockNumber, logger$2);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function heightRoute() {
|
|
172
|
+
return {
|
|
173
|
+
method: "GET",
|
|
174
|
+
path: "/height",
|
|
175
|
+
input: (function (param) {
|
|
176
|
+
|
|
177
|
+
}),
|
|
178
|
+
responses: [(function (s) {
|
|
179
|
+
return s.field("height", S$RescriptSchema.$$int);
|
|
180
|
+
})]
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
var GetLogs = {
|
|
185
|
+
$$Error: $$Error,
|
|
186
|
+
query: query
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
exports.queryErrorToMsq = queryErrorToMsq;
|
|
190
|
+
exports.GetLogs = GetLogs;
|
|
191
|
+
exports.queryBlockData = queryBlockData;
|
|
192
|
+
exports.heightRoute = heightRoute;
|
|
193
|
+
/* Time Not a pure module */
|
|
@@ -0,0 +1,19 @@
|
|
|
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 HyperfuelClient = require("@envio-dev/hyperfuel-client");
|
|
6
|
+
|
|
7
|
+
var QueryTypes = {};
|
|
8
|
+
|
|
9
|
+
var FuelTypes = {};
|
|
10
|
+
|
|
11
|
+
function make(cfg) {
|
|
12
|
+
var newrecord = Caml_obj.obj_dup(cfg);
|
|
13
|
+
return HyperfuelClient.HyperfuelClient.new((newrecord.bearerToken = "3dc856dd-b0ea-494f-b27e-017b8b6b7e07", newrecord));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.QueryTypes = QueryTypes;
|
|
17
|
+
exports.FuelTypes = FuelTypes;
|
|
18
|
+
exports.make = make;
|
|
19
|
+
/* @envio-dev/hyperfuel-client Not a pure module */
|