envio 2.26.0-rc.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "v2.26.0-rc.1",
3
+ "version": "v2.26.0-rc.2",
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.1",
29
- "envio-linux-arm64": "v2.26.0-rc.1",
30
- "envio-darwin-x64": "v2.26.0-rc.1",
31
- "envio-darwin-arm64": "v2.26.0-rc.1"
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"
32
32
  },
33
33
  "dependencies": {
34
34
  "@envio-dev/hypersync-client": "0.6.5",
package/src/Envio.res CHANGED
@@ -42,6 +42,8 @@ let experimental_createEffect = (
42
42
  handler: effectArgs<'input> => promise<'output>,
43
43
  ) => {
44
44
  Prometheus.EffectCallsCount.set(~callsCount=0, ~effectName=options.name)
45
+ let outputSchema =
46
+ S.schema(_ => options.output)->(Utils.magic: S.t<S.t<'output>> => S.t<Internal.effectOutput>)
45
47
  {
46
48
  name: options.name,
47
49
  handler: handler->(
@@ -57,9 +59,21 @@ let experimental_createEffect = (
57
59
  input: S.schema(_ => options.input)->(
58
60
  Utils.magic: S.t<S.t<'input>> => S.t<Internal.effectInput>
59
61
  ),
60
- output: S.schema(_ => options.output)->(
61
- Utils.magic: S.t<S.t<'output>> => S.t<Internal.effectOutput>
62
- ),
63
- cache: options.cache->Belt.Option.getWithDefault(false),
62
+ output: outputSchema,
63
+ cache: switch options.cache {
64
+ | Some(true) =>
65
+ let itemSchema = S.schema((s): Internal.effectCacheItem => {
66
+ id: s.matches(S.string),
67
+ output: s.matches(outputSchema),
68
+ })
69
+ Some({
70
+ table: Internal.makeCacheTable(~effectName=options.name),
71
+ rowsSchema: S.array(itemSchema),
72
+ itemSchema,
73
+ })
74
+ | None
75
+ | Some(false) =>
76
+ None
77
+ },
64
78
  }->(Utils.magic: Internal.effect => effect<'input, 'output>)
65
79
  }
package/src/Envio.res.js CHANGED
@@ -1,19 +1,37 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
+ var Internal = require("./Internal.res.js");
4
5
  var Prometheus = require("./Prometheus.res.js");
5
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
6
6
  var S$RescriptSchema = require("rescript-schema/src/S.res.js");
7
7
 
8
8
  function experimental_createEffect(options, handler) {
9
9
  Prometheus.EffectCallsCount.set(0, options.name);
10
+ var outputSchema = S$RescriptSchema.schema(function (param) {
11
+ return options.output;
12
+ });
13
+ var match = options.cache;
14
+ var tmp;
15
+ if (match !== undefined && match) {
16
+ var itemSchema = S$RescriptSchema.schema(function (s) {
17
+ return {
18
+ id: s.m(S$RescriptSchema.string),
19
+ output: s.m(outputSchema)
20
+ };
21
+ });
22
+ tmp = {
23
+ itemSchema: itemSchema,
24
+ rowsSchema: S$RescriptSchema.array(itemSchema),
25
+ table: Internal.makeCacheTable(options.name)
26
+ };
27
+ } else {
28
+ tmp = undefined;
29
+ }
10
30
  return {
11
31
  name: options.name,
12
32
  handler: handler,
13
- cache: Belt_Option.getWithDefault(options.cache, false),
14
- output: S$RescriptSchema.schema(function (param) {
15
- return options.output;
16
- }),
33
+ cache: tmp,
34
+ output: outputSchema,
17
35
  input: S$RescriptSchema.schema(function (param) {
18
36
  return options.input;
19
37
  }),
@@ -22,4 +40,4 @@ function experimental_createEffect(options, handler) {
22
40
  }
23
41
 
24
42
  exports.experimental_createEffect = experimental_createEffect;
25
- /* Prometheus Not a pure module */
43
+ /* Internal Not a pure module */
package/src/Internal.res CHANGED
@@ -194,14 +194,31 @@ type effectArgs = {
194
194
  context: effectContext,
195
195
  cacheKey: string,
196
196
  }
197
+ type effectCacheItem = {id: string, output: effectOutput}
198
+ type effectCacheMeta = {
199
+ itemSchema: S.t<effectCacheItem>,
200
+ rowsSchema: S.t<array<effectCacheItem>>,
201
+ table: Table.table,
202
+ }
197
203
  type effect = {
198
204
  name: string,
199
205
  handler: effectArgs => promise<effectOutput>,
200
- cache: bool,
206
+ cache: option<effectCacheMeta>,
201
207
  output: S.t<effectOutput>,
202
208
  input: S.t<effectInput>,
203
209
  mutable callsCount: int,
204
210
  }
211
+ let cacheTablePrefix = "envio_effect_"
212
+ let makeCacheTable = (~effectName) => {
213
+ Table.mkTable(
214
+ cacheTablePrefix ++ effectName,
215
+ ~fields=[
216
+ Table.mkField("id", Text, ~fieldSchema=S.string, ~isPrimaryKey=true),
217
+ Table.mkField("output", JsonB, ~fieldSchema=S.json(~validate=false)),
218
+ ],
219
+ ~compositeIndices=[],
220
+ )
221
+ }
205
222
 
206
223
  @genType.import(("./Types.ts", "Invalid"))
207
224
  type noEventFilters
@@ -1,6 +1,7 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
+ var Table = require("./db/Table.res.js");
4
5
  var $$BigInt = require("./bindings/BigInt.res.js");
5
6
  var Js_exn = require("rescript/lib/js/js_exn.js");
6
7
  var Address = require("./Address.res.js");
@@ -34,6 +35,15 @@ function makeEnumConfig(name, variants) {
34
35
  };
35
36
  }
36
37
 
38
+ var cacheTablePrefix = "envio_effect_";
39
+
40
+ function makeCacheTable(effectName) {
41
+ return Table.mkTable(cacheTablePrefix + effectName, [], [
42
+ Table.mkField("id", "TEXT", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
43
+ Table.mkField("output", "JSONB", S$RescriptSchema.json(false), undefined, undefined, undefined, undefined, undefined, undefined)
44
+ ]);
45
+ }
46
+
37
47
  function prettifyExn(exn) {
38
48
  var e = Caml_js_exceptions.internalToOCamlException(exn);
39
49
  if (e.RE_EXN_ID === Js_exn.$$Error) {
@@ -46,5 +56,7 @@ function prettifyExn(exn) {
46
56
  exports.fuelSupplyParamsSchema = fuelSupplyParamsSchema;
47
57
  exports.fuelTransferParamsSchema = fuelTransferParamsSchema;
48
58
  exports.makeEnumConfig = makeEnumConfig;
59
+ exports.cacheTablePrefix = cacheTablePrefix;
60
+ exports.makeCacheTable = makeCacheTable;
49
61
  exports.prettifyExn = prettifyExn;
50
62
  /* fuelSupplyParamsSchema Not a pure module */
@@ -49,10 +49,8 @@ type storage = {
49
49
  ) => promise<unit>,
50
50
  @raises("StorageError")
51
51
  setEffectCacheOrThrow: (
52
- ~effectName: string,
53
- ~ids: array<string>,
54
- ~outputs: array<Internal.effectOutput>,
55
- ~outputSchema: S.t<Internal.effectOutput>,
52
+ ~effect: Internal.effect,
53
+ ~items: array<Internal.effectCacheItem>,
56
54
  ~initialize: bool,
57
55
  ) => promise<unit>,
58
56
  dumpEffectCache: unit => promise<unit>,
@@ -176,13 +174,14 @@ let getInitializedStorageOrThrow = persistence => {
176
174
  }
177
175
  }
178
176
 
179
- let setEffectCacheOrThrow = async (persistence, ~effectName, ~ids, ~outputs, ~outputSchema) => {
177
+ let setEffectCacheOrThrow = async (persistence, ~effect: Internal.effect, ~items) => {
180
178
  switch persistence.storageStatus {
181
179
  | Unknown
182
180
  | Initializing(_) =>
183
181
  Js.Exn.raiseError(`Failed to access the indexer storage. The Persistence layer is not initialized.`)
184
182
  | Ready({cache}) => {
185
183
  let storage = persistence.storage
184
+ let effectName = effect.name
186
185
  let effectCacheRecord = switch cache->Utils.Dict.dangerouslyGetNonOption(effectName) {
187
186
  | Some(c) => c
188
187
  | None => {
@@ -192,8 +191,8 @@ let setEffectCacheOrThrow = async (persistence, ~effectName, ~ids, ~outputs, ~ou
192
191
  }
193
192
  }
194
193
  let initialize = effectCacheRecord.count === 0
195
- await storage.setEffectCacheOrThrow(~effectName, ~ids, ~outputs, ~outputSchema, ~initialize)
196
- effectCacheRecord.count = effectCacheRecord.count + ids->Js.Array2.length
194
+ await storage.setEffectCacheOrThrow(~effect, ~items, ~initialize)
195
+ effectCacheRecord.count = effectCacheRecord.count + items->Js.Array2.length
197
196
  Prometheus.EffectCacheCount.set(~count=effectCacheRecord.count, ~effectName)
198
197
  }
199
198
  }
@@ -113,7 +113,7 @@ function getInitializedStorageOrThrow(persistence) {
113
113
  }
114
114
  }
115
115
 
116
- async function setEffectCacheOrThrow(persistence, effectName, ids, outputs, outputSchema) {
116
+ async function setEffectCacheOrThrow(persistence, effect, items) {
117
117
  var match = persistence.storageStatus;
118
118
  if (typeof match !== "object") {
119
119
  return Js_exn.raiseError("Failed to access the indexer storage. The Persistence layer is not initialized.");
@@ -123,6 +123,7 @@ async function setEffectCacheOrThrow(persistence, effectName, ids, outputs, outp
123
123
  }
124
124
  var cache = match.cache;
125
125
  var storage = persistence.storage;
126
+ var effectName = effect.name;
126
127
  var c = cache[effectName];
127
128
  var effectCacheRecord;
128
129
  if (c !== undefined) {
@@ -136,8 +137,8 @@ async function setEffectCacheOrThrow(persistence, effectName, ids, outputs, outp
136
137
  effectCacheRecord = c$1;
137
138
  }
138
139
  var initialize = effectCacheRecord.count === 0;
139
- await storage.setEffectCacheOrThrow(effectName, ids, outputs, outputSchema, initialize);
140
- effectCacheRecord.count = effectCacheRecord.count + ids.length | 0;
140
+ await storage.setEffectCacheOrThrow(effect, items, initialize);
141
+ effectCacheRecord.count = effectCacheRecord.count + items.length | 0;
141
142
  return Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
142
143
  }
143
144
 
package/src/PgStorage.res CHANGED
@@ -433,8 +433,7 @@ let makeSchemaTableNamesQuery = (~pgSchema) => {
433
433
  `SELECT table_name FROM information_schema.tables WHERE table_schema = '${pgSchema}';`
434
434
  }
435
435
 
436
- let cacheTablePrefix = "envio_effect_"
437
- let cacheTablePrefixLength = cacheTablePrefix->String.length
436
+ let cacheTablePrefixLength = Internal.cacheTablePrefix->String.length
438
437
 
439
438
  type schemaCacheTableInfo = {
440
439
  @as("table_name")
@@ -449,7 +448,7 @@ let makeSchemaCacheTableInfoQuery = (~pgSchema) => {
449
448
  get_cache_row_count(t.table_name) as count
450
449
  FROM information_schema.tables t
451
450
  WHERE t.table_schema = '${pgSchema}'
452
- AND t.table_name LIKE '${cacheTablePrefix}%';`
451
+ AND t.table_name LIKE '${Internal.cacheTablePrefix}%';`
453
452
  }
454
453
 
455
454
  type psqlExecState =
@@ -681,20 +680,17 @@ let make = (
681
680
  }
682
681
 
683
682
  let setEffectCacheOrThrow = async (
684
- ~effectName: string,
685
- ~ids: array<string>,
686
- ~outputs: array<Internal.effectOutput>,
687
- ~outputSchema: S.t<Internal.effectOutput>,
683
+ ~effect: Internal.effect,
684
+ ~items: array<Internal.effectCacheItem>,
688
685
  ~initialize: bool,
689
686
  ) => {
690
- let table = Table.mkTable(
691
- cacheTablePrefix ++ effectName,
692
- ~fields=[
693
- Table.mkField("id", Text, ~fieldSchema=S.string, ~isPrimaryKey=true),
694
- Table.mkField("output", JsonB, ~fieldSchema=S.json(~validate=false)),
695
- ],
696
- ~compositeIndices=[],
697
- )
687
+ let {table, itemSchema} = switch effect.cache {
688
+ | Some(cacheMeta) => cacheMeta
689
+ | None =>
690
+ Js.Exn.raiseError(
691
+ `Failed to set effect cache for "${effect.name}". Effect has no cache enabled.`,
692
+ )
693
+ }
698
694
 
699
695
  if initialize {
700
696
  let _ = await sql->Postgres.unsafe(makeCreateTableQuery(table, ~pgSchema))
@@ -704,26 +700,7 @@ let make = (
704
700
  }
705
701
  }
706
702
 
707
- let items = []
708
- for idx in 0 to outputs->Array.length - 1 {
709
- items
710
- ->Js.Array2.push({
711
- "id": ids[idx],
712
- "output": outputs[idx],
713
- })
714
- ->ignore
715
- }
716
-
717
- await setOrThrow(
718
- ~items,
719
- ~table,
720
- ~itemSchema=S.schema(s =>
721
- {
722
- "id": s.matches(S.string),
723
- "output": s.matches(outputSchema),
724
- }
725
- ),
726
- )
703
+ await setOrThrow(~items, ~table, ~itemSchema)
727
704
  }
728
705
 
729
706
  let dumpEffectCache = async () => {
@@ -807,23 +784,15 @@ let make = (
807
784
  let _ =
808
785
  await cacheFiles
809
786
  ->Js.Array2.map(entry => {
810
- let cacheName = entry->Js.String2.slice(~from=0, ~to_=-4) // Remove .tsv extension
811
- let tableName = cacheTablePrefix ++ cacheName
812
- let table = Table.mkTable(
813
- tableName,
814
- ~fields=[
815
- Table.mkField("id", Text, ~fieldSchema=S.string, ~isPrimaryKey=true),
816
- Table.mkField("output", JsonB, ~fieldSchema=S.json(~validate=false)),
817
- ],
818
- ~compositeIndices=[],
819
- )
787
+ let effectName = entry->Js.String2.slice(~from=0, ~to_=-4) // Remove .tsv extension
788
+ let table = Internal.makeCacheTable(~effectName)
820
789
 
821
790
  sql
822
791
  ->Postgres.unsafe(makeCreateTableQuery(table, ~pgSchema))
823
792
  ->Promise.then(() => {
824
793
  let inputFile = NodeJs.Path.join(cacheDirPath, entry)->NodeJs.Path.toString
825
794
 
826
- let command = `${psqlExec} -c 'COPY "${pgSchema}"."${tableName}" FROM STDIN WITH (FORMAT text, HEADER);' < ${inputFile}`
795
+ let command = `${psqlExec} -c 'COPY "${pgSchema}"."${table.tableName}" FROM STDIN WITH (FORMAT text, HEADER);' < ${inputFile}`
827
796
 
828
797
  Promise.make(
829
798
  (resolve, reject) => {
@@ -13,7 +13,6 @@ var Logging = require("./Logging.res.js");
13
13
  var $$Promise = require("./bindings/Promise.res.js");
14
14
  var Internal = require("./Internal.res.js");
15
15
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
16
- var Caml_array = require("rescript/lib/js/caml_array.js");
17
16
  var Belt_Option = require("rescript/lib/js/belt_Option.js");
18
17
  var Caml_option = require("rescript/lib/js/caml_option.js");
19
18
  var Persistence = require("./Persistence.res.js");
@@ -297,12 +296,10 @@ function makeSchemaTableNamesQuery(pgSchema) {
297
296
  return "SELECT table_name FROM information_schema.tables WHERE table_schema = '" + pgSchema + "';";
298
297
  }
299
298
 
300
- var cacheTablePrefix = "envio_effect_";
301
-
302
- var cacheTablePrefixLength = cacheTablePrefix.length;
299
+ var cacheTablePrefixLength = Internal.cacheTablePrefix.length;
303
300
 
304
301
  function makeSchemaCacheTableInfoQuery(pgSchema) {
305
- 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 '" + cacheTablePrefix + "%';";
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 + "%';";
306
303
  }
307
304
 
308
305
  var psqlExecState = {
@@ -467,11 +464,10 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onI
467
464
  var setOrThrow$1 = function (items, table, itemSchema) {
468
465
  return setOrThrow(sql, items, table, itemSchema, pgSchema);
469
466
  };
470
- var setEffectCacheOrThrow = async function (effectName, ids, outputs, outputSchema, initialize) {
471
- var table = Table.mkTable(cacheTablePrefix + effectName, [], [
472
- Table.mkField("id", "TEXT", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
473
- Table.mkField("output", "JSONB", S$RescriptSchema.json(false), undefined, undefined, undefined, undefined, undefined, undefined)
474
- ]);
467
+ var setEffectCacheOrThrow = async function (effect, items, initialize) {
468
+ var cacheMeta = effect.cache;
469
+ var match = cacheMeta !== undefined ? cacheMeta : Js_exn.raiseError("Failed to set effect cache for \"" + effect.name + "\". Effect has no cache enabled.");
470
+ var table = match.table;
475
471
  if (initialize) {
476
472
  await sql.unsafe(makeCreateTableQuery(table, pgSchema));
477
473
  if (onNewTables !== undefined) {
@@ -479,19 +475,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onI
479
475
  }
480
476
 
481
477
  }
482
- var items = [];
483
- for(var idx = 0 ,idx_finish = outputs.length; idx < idx_finish; ++idx){
484
- items.push({
485
- id: Caml_array.get(ids, idx),
486
- output: Caml_array.get(outputs, idx)
487
- });
488
- }
489
- return await setOrThrow$1(items, table, S$RescriptSchema.schema(function (s) {
490
- return {
491
- id: s.m(S$RescriptSchema.string),
492
- output: s.m(outputSchema)
493
- };
494
- }));
478
+ return await setOrThrow$1(items, table, match.itemSchema);
495
479
  };
496
480
  var dumpEffectCache = async function () {
497
481
  try {
@@ -568,15 +552,11 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onI
568
552
  return entry.endsWith(".tsv");
569
553
  });
570
554
  await Promise.all(cacheFiles.map(function (entry) {
571
- var cacheName = entry.slice(0, -4);
572
- var tableName = cacheTablePrefix + cacheName;
573
- var table = Table.mkTable(tableName, [], [
574
- Table.mkField("id", "TEXT", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
575
- Table.mkField("output", "JSONB", S$RescriptSchema.json(false), undefined, undefined, undefined, undefined, undefined, undefined)
576
- ]);
555
+ var effectName = entry.slice(0, -4);
556
+ var table = Internal.makeCacheTable(effectName);
577
557
  return sql.unsafe(makeCreateTableQuery(table, pgSchema)).then(function () {
578
558
  var inputFile = Path.join(cacheDirPath, entry);
579
- var command = psqlExec$1 + " -c 'COPY \"" + pgSchema + "\".\"" + tableName + "\" FROM STDIN WITH (FORMAT text, HEADER);' < " + inputFile;
559
+ var command = psqlExec$1 + " -c 'COPY \"" + pgSchema + "\".\"" + table.tableName + "\" FROM STDIN WITH (FORMAT text, HEADER);' < " + inputFile;
580
560
  return new Promise((function (resolve, reject) {
581
561
  Child_process.exec(command, psqlExecOptions, (function (error, stdout, param) {
582
562
  if (error === null) {
@@ -654,7 +634,6 @@ exports.setQueryCache = setQueryCache;
654
634
  exports.setOrThrow = setOrThrow;
655
635
  exports.setEntityHistoryOrThrow = setEntityHistoryOrThrow;
656
636
  exports.makeSchemaTableNamesQuery = makeSchemaTableNamesQuery;
657
- exports.cacheTablePrefix = cacheTablePrefix;
658
637
  exports.cacheTablePrefixLength = cacheTablePrefixLength;
659
638
  exports.makeSchemaCacheTableInfoQuery = makeSchemaCacheTableInfoQuery;
660
639
  exports.getConnectedPsqlExec = getConnectedPsqlExec;