envio 2.26.0-rc.2 → 2.26.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "v2.26.0-rc.2",
3
+ "version": "v2.26.0",
4
4
  "description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
5
5
  "bin": "./bin.js",
6
6
  "main": "./index.js",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "homepage": "https://envio.dev",
27
27
  "optionalDependencies": {
28
- "envio-linux-x64": "v2.26.0-rc.2",
29
- "envio-linux-arm64": "v2.26.0-rc.2",
30
- "envio-darwin-x64": "v2.26.0-rc.2",
31
- "envio-darwin-arm64": "v2.26.0-rc.2"
28
+ "envio-linux-x64": "v2.26.0",
29
+ "envio-linux-arm64": "v2.26.0",
30
+ "envio-darwin-x64": "v2.26.0",
31
+ "envio-darwin-arm64": "v2.26.0"
32
32
  },
33
33
  "dependencies": {
34
34
  "@envio-dev/hypersync-client": "0.6.5",
@@ -53,7 +53,11 @@ type storage = {
53
53
  ~items: array<Internal.effectCacheItem>,
54
54
  ~initialize: bool,
55
55
  ) => promise<unit>,
56
+ // This is to download cache from the database to .envio/cache
56
57
  dumpEffectCache: unit => promise<unit>,
58
+ // This is not good, but the function does two things:
59
+ // - Gets info about existing cache tables
60
+ // - if withUpload is true, it also populates the cache from .envio/cache to the database
57
61
  restoreEffectCache: (~withUpload: bool) => promise<array<effectCacheRecord>>,
58
62
  }
59
63
 
package/src/PgStorage.res CHANGED
@@ -1,3 +1,5 @@
1
+ let getCacheRowCountFnName = "get_cache_row_count"
2
+
1
3
  let makeCreateIndexQuery = (~tableName, ~indexFields, ~pgSchema) => {
2
4
  let indexName = tableName ++ "_" ++ indexFields->Js.Array2.joinWith("_")
3
5
  let index = indexFields->Belt.Array.map(idx => `"${idx}"`)->Js.Array2.joinWith(", ")
@@ -133,15 +135,15 @@ GRANT ALL ON SCHEMA "${pgSchema}" TO public;`,
133
135
  functionsQuery :=
134
136
  functionsQuery.contents ++
135
137
  "\n" ++
136
- `CREATE OR REPLACE FUNCTION get_cache_row_count(table_name text)
137
- RETURNS integer AS $$
138
- DECLARE
139
- result integer;
140
- BEGIN
141
- EXECUTE format('SELECT COUNT(*) FROM "${pgSchema}".%I', table_name) INTO result;
142
- RETURN result;
143
- END;
144
- $$ LANGUAGE plpgsql;`
138
+ `CREATE OR REPLACE FUNCTION ${getCacheRowCountFnName}(table_name text)
139
+ RETURNS integer AS $$
140
+ DECLARE
141
+ result integer;
142
+ BEGIN
143
+ EXECUTE format('SELECT COUNT(*) FROM "${pgSchema}".%I', table_name) INTO result;
144
+ RETURN result;
145
+ END;
146
+ $$ LANGUAGE plpgsql;`
145
147
 
146
148
  [query.contents]->Js.Array2.concat(
147
149
  functionsQuery.contents !== "" ? [functionsQuery.contents] : [],
@@ -445,7 +447,7 @@ type schemaCacheTableInfo = {
445
447
  let makeSchemaCacheTableInfoQuery = (~pgSchema) => {
446
448
  `SELECT
447
449
  t.table_name,
448
- get_cache_row_count(t.table_name) as count
450
+ ${getCacheRowCountFnName}(t.table_name) as count
449
451
  FROM information_schema.tables t
450
452
  WHERE t.table_schema = '${pgSchema}'
451
453
  AND t.table_name LIKE '${Internal.cacheTablePrefix}%';`
@@ -577,6 +579,7 @@ let make = (
577
579
  queries->Js.Array2.map(query => sql->Postgres.unsafe(query))
578
580
  })
579
581
 
582
+ // Integration with other tools like Hasura
580
583
  switch onInitialize {
581
584
  | Some(onInitialize) => await onInitialize()
582
585
  | None => ()
@@ -694,6 +697,7 @@ let make = (
694
697
 
695
698
  if initialize {
696
699
  let _ = await sql->Postgres.unsafe(makeCreateTableQuery(table, ~pgSchema))
700
+ // Integration with other tools like Hasura
697
701
  switch onNewTables {
698
702
  | Some(onNewTables) => await onNewTables(~tableNames=[table.tableName])
699
703
  | None => ()
@@ -828,6 +832,7 @@ let make = (
828
832
  await sql->Postgres.unsafe(makeSchemaCacheTableInfoQuery(~pgSchema))
829
833
 
830
834
  if withUpload && cacheTableInfo->Utils.Array.notEmpty {
835
+ // Integration with other tools like Hasura
831
836
  switch onNewTables {
832
837
  | Some(onNewTables) =>
833
838
  await onNewTables(
@@ -21,6 +21,8 @@ var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
21
21
  var S$RescriptSchema = require("rescript-schema/src/S.res.js");
22
22
  var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
23
23
 
24
+ var getCacheRowCountFnName = "get_cache_row_count";
25
+
24
26
  function makeCreateIndexQuery(tableName, indexFields, pgSchema) {
25
27
  var indexName = tableName + "_" + indexFields.join("_");
26
28
  var index = Belt_Array.map(indexFields, (function (idx) {
@@ -111,7 +113,7 @@ function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesO
111
113
  query.contents = query.contents + "\n" + makeCreateIndexQuery(derivedFromField.derivedFromEntity, [indexField], pgSchema);
112
114
  });
113
115
  });
114
- functionsQuery.contents = functionsQuery.contents + "\n" + ("CREATE OR REPLACE FUNCTION get_cache_row_count(table_name text) \n RETURNS integer AS $$\n DECLARE\n result integer;\n BEGIN\n EXECUTE format('SELECT COUNT(*) FROM \"" + pgSchema + "\".%I', table_name) INTO result;\n RETURN result;\n END;\n $$ LANGUAGE plpgsql;");
116
+ functionsQuery.contents = functionsQuery.contents + "\n" + ("CREATE OR REPLACE FUNCTION " + getCacheRowCountFnName + "(table_name text) \nRETURNS integer AS $$\nDECLARE\n result integer;\nBEGIN\n EXECUTE format('SELECT COUNT(*) FROM \"" + pgSchema + "\".%I', table_name) INTO result;\n RETURN result;\nEND;\n$$ LANGUAGE plpgsql;");
115
117
  return [query.contents].concat(functionsQuery.contents !== "" ? [functionsQuery.contents] : []);
116
118
  }
117
119
 
@@ -299,7 +301,7 @@ function makeSchemaTableNamesQuery(pgSchema) {
299
301
  var cacheTablePrefixLength = Internal.cacheTablePrefix.length;
300
302
 
301
303
  function makeSchemaCacheTableInfoQuery(pgSchema) {
302
- return "SELECT \n t.table_name,\n get_cache_row_count(t.table_name) as count\n FROM information_schema.tables t\n WHERE t.table_schema = '" + pgSchema + "' \n AND t.table_name LIKE '" + Internal.cacheTablePrefix + "%';";
304
+ return "SELECT \n t.table_name,\n " + getCacheRowCountFnName + "(t.table_name) as count\n FROM information_schema.tables t\n WHERE t.table_schema = '" + pgSchema + "' \n AND t.table_name LIKE '" + Internal.cacheTablePrefix + "%';";
303
305
  }
304
306
 
305
307
  var psqlExecState = {
@@ -613,6 +615,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onI
613
615
 
614
616
  var maxItemsPerQuery = 500;
615
617
 
618
+ exports.getCacheRowCountFnName = getCacheRowCountFnName;
616
619
  exports.makeCreateIndexQuery = makeCreateIndexQuery;
617
620
  exports.makeCreateTableIndicesQuery = makeCreateTableIndicesQuery;
618
621
  exports.makeCreateTableQuery = makeCreateTableQuery;
package/src/Utils.res CHANGED
@@ -516,6 +516,12 @@ module Proxy = {
516
516
  }
517
517
 
518
518
  module Hash = {
519
+ let fail = name => {
520
+ Js.Exn.raiseError(
521
+ `Failed to get hash for ${name}. If you're using a custom Sury schema make it based on the string type with a decoder: const myTypeSchema = S.transform(S.string, undefined, (yourType) => yourType.toString())`,
522
+ )
523
+ }
524
+
519
525
  // Hash to JSON string. No specific reason for this,
520
526
  // just to stick to at least some sort of spec.
521
527
  // After Sury v11 is out we'll be able to do it with schema
@@ -546,13 +552,16 @@ module Hash = {
546
552
  if constructor === %raw(`Object`) {
547
553
  let hash = ref("{")
548
554
  let keys = any->Js.Dict.keys->Js.Array2.sortInPlace
555
+ let isFirst = ref(true)
549
556
  for i in 0 to keys->Js.Array2.length - 1 {
550
557
  let key = keys->Js.Array2.unsafe_get(i)
551
558
  let value = any->Js.Dict.unsafeGet(key)
552
- if i !== 0 {
553
- hash := hash.contents ++ ","
554
- }
555
559
  if value !== %raw(`undefined`) {
560
+ if isFirst.contents {
561
+ isFirst := false
562
+ } else {
563
+ hash := hash.contents ++ ","
564
+ }
556
565
  // Ideally should escape and wrap the key in double quotes
557
566
  // but since we don't need to decode the hash,
558
567
  // it's fine to keep it super simple
@@ -563,13 +572,13 @@ module Hash = {
563
572
  } else if constructor["name"] === "BigNumber" {
564
573
  `"${(any->magic)["toString"]()}"`
565
574
  } else {
566
- Js.Exn.raiseError(`Don't know how to serialize ${(constructor->magic)["name"]}`)
575
+ fail((constructor->magic)["name"])
567
576
  }
568
577
  }
569
578
  | "symbol"
570
579
  | "function" =>
571
580
  (any->magic)["toString"]()
572
- | typeof => Js.Exn.raiseError(`Don't know how to serialize ${typeof}`)
581
+ | typeof => fail(typeof)
573
582
  }
574
583
  }
575
584
  }
package/src/Utils.res.js CHANGED
@@ -452,6 +452,10 @@ var $$Map = {};
452
452
 
453
453
  var $$Proxy = {};
454
454
 
455
+ function fail(name) {
456
+ return Js_exn.raiseError("Failed to get hash for " + name + ". If you're using a custom Sury schema make it based on the string type with a decoder: const myTypeSchema = S.transform(S.string, undefined, (yourType) => yourType.toString())");
457
+ }
458
+
455
459
  function makeOrThrow(any) {
456
460
  var $$typeof = typeof any;
457
461
  switch ($$typeof) {
@@ -484,18 +488,21 @@ function makeOrThrow(any) {
484
488
  if (constructor.name === "BigNumber") {
485
489
  return "\"" + any.toString() + "\"";
486
490
  } else {
487
- return Js_exn.raiseError("Don't know how to serialize " + constructor.name);
491
+ return fail(constructor.name);
488
492
  }
489
493
  }
490
494
  var hash$1 = "{";
491
495
  var keys = Object.keys(any).sort();
496
+ var isFirst = true;
492
497
  for(var i$1 = 0 ,i_finish$1 = keys.length; i$1 < i_finish$1; ++i$1){
493
498
  var key = keys[i$1];
494
499
  var value = any[key];
495
- if (i$1 !== 0) {
496
- hash$1 = hash$1 + ",";
497
- }
498
500
  if (value !== undefined) {
501
+ if (isFirst) {
502
+ isFirst = false;
503
+ } else {
504
+ hash$1 = hash$1 + ",";
505
+ }
499
506
  hash$1 = hash$1 + ("\"" + key + "\":" + makeOrThrow(any[key]));
500
507
  }
501
508
 
@@ -509,11 +516,12 @@ function makeOrThrow(any) {
509
516
  case "undefined" :
510
517
  return "null";
511
518
  default:
512
- return Js_exn.raiseError("Don't know how to serialize " + $$typeof);
519
+ return fail($$typeof);
513
520
  }
514
521
  }
515
522
 
516
523
  var Hash = {
524
+ fail: fail,
517
525
  makeOrThrow: makeOrThrow
518
526
  };
519
527
 
@@ -4,6 +4,37 @@ type t
4
4
  type exitCode = | @as(0) Success | @as(1) Failure
5
5
  @send external exitWithCode: (t, exitCode) => unit = "exit"
6
6
 
7
+ module Util = {
8
+ @unboxed
9
+ type depth = Int(int) | @as(null) Null
10
+ @unboxed
11
+ type compact = Bool(bool) | Int(int)
12
+ @unboxed
13
+ type sorted = Bool(bool) | Fn((string, string) => int)
14
+ @unboxed
15
+ type getters = | @as(true) True | @as(false) False | @as("get") Get | @as("set") Set
16
+
17
+ @unbox
18
+ type inspectOptions = {
19
+ showHidden?: bool,
20
+ depth?: depth,
21
+ colors?: bool,
22
+ customInspect?: bool,
23
+ showProxy?: bool,
24
+ maxArrayLength?: int,
25
+ maxStringLength?: int,
26
+ breakLength?: int,
27
+ @as("compact") compact?: compact,
28
+ sorted?: sorted,
29
+ getters?: string,
30
+ numericSeparator?: bool,
31
+ }
32
+
33
+ @module("util") external inspect: ('a, inspectOptions) => string = "inspect"
34
+
35
+ let inspectObj = a => inspect(a, {showHidden: false, depth: Null, colors: true})
36
+ }
37
+
7
38
  module Process = {
8
39
  type t = {env: Js.Dict.t<string>}
9
40
  @module external process: t = "process"
@@ -1,6 +1,19 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
+ var Util = require("util");
5
+
6
+ function inspectObj(a) {
7
+ return Util.inspect(a, {
8
+ showHidden: false,
9
+ depth: null,
10
+ colors: true
11
+ });
12
+ }
13
+
14
+ var Util$1 = {
15
+ inspectObj: inspectObj
16
+ };
4
17
 
5
18
  var Process = {};
6
19
 
@@ -14,8 +27,9 @@ var Fs = {
14
27
  Promises: Promises
15
28
  };
16
29
 
30
+ exports.Util = Util$1;
17
31
  exports.Process = Process;
18
32
  exports.ChildProcess = ChildProcess;
19
33
  exports.Path = Path;
20
34
  exports.Fs = Fs;
21
- /* No side effect */
35
+ /* util Not a pure module */