envio 2.26.0-rc.0 → 2.26.0-rc.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.
package/evm.schema.json CHANGED
@@ -33,6 +33,13 @@
33
33
  "null"
34
34
  ]
35
35
  },
36
+ "output": {
37
+ "description": "Path where the generated directory will be placed. By default it's 'generated' relative to the current working directory. If set, it'll be a path relative to the config file location.",
38
+ "type": [
39
+ "string",
40
+ "null"
41
+ ]
42
+ },
36
43
  "contracts": {
37
44
  "description": "Global contract definitions that must contain all definitions except addresses. You can share a single handler/abi/event definitions for contracts across multiple chains.",
38
45
  "type": [
package/fuel.schema.json CHANGED
@@ -26,6 +26,13 @@
26
26
  "null"
27
27
  ]
28
28
  },
29
+ "output": {
30
+ "description": "Path where the generated directory will be placed. By default it's 'generated' relative to the current working directory. If set, it'll be a path relative to the config file location.",
31
+ "type": [
32
+ "string",
33
+ "null"
34
+ ]
35
+ },
29
36
  "contracts": {
30
37
  "description": "Global contract definitions that must contain all definitions except addresses. You can share a single handler/abi/event definitions for contracts across multiple chains.",
31
38
  "type": [
package/index.d.ts CHANGED
@@ -13,6 +13,7 @@ import type {
13
13
  } from "./src/Envio.gen.ts";
14
14
 
15
15
  import { schema as bigDecimalSchema } from "./src/bindings/BigDecimal.gen.ts";
16
+ import { schema as bigintSchema } from "./src/bindings/BigInt.gen.ts";
16
17
  import * as Sury from "rescript-schema";
17
18
 
18
19
  type UnknownToOutput<T> = T extends Sury.Schema<unknown>
@@ -35,26 +36,6 @@ type UnknownToOutput<T> = T extends Sury.Schema<unknown>
35
36
  >
36
37
  : T;
37
38
 
38
- type UnknownToInput<T> = T extends Sury.Schema<unknown>
39
- ? Sury.Input<T>
40
- : T extends (...args: any[]) => any
41
- ? T
42
- : T extends unknown[]
43
- ? { [K in keyof T]: UnknownToInput<T[K]> }
44
- : T extends { [k in keyof T]: unknown }
45
- ? Flatten<
46
- {
47
- [k in keyof T as HasUndefined<UnknownToInput<T[k]>> extends true
48
- ? k
49
- : never]?: UnknownToInput<T[k]>;
50
- } & {
51
- [k in keyof T as HasUndefined<UnknownToInput<T[k]>> extends true
52
- ? never
53
- : k]: UnknownToInput<T[k]>;
54
- }
55
- >
56
- : T;
57
-
58
39
  type HasUndefined<T> = [T] extends [undefined]
59
40
  ? true
60
41
  : undefined extends T
@@ -92,7 +73,7 @@ type Flatten<T> = T extends object
92
73
  export function experimental_createEffect<
93
74
  IS,
94
75
  OS,
95
- I = UnknownToInput<IS>,
76
+ I = UnknownToOutput<IS>,
96
77
  O = UnknownToOutput<OS>,
97
78
  // A hack to enforce that the inferred return type
98
79
  // matches the output schema type
@@ -105,6 +86,8 @@ export function experimental_createEffect<
105
86
  readonly input: IS;
106
87
  /** The output schema of the effect. */
107
88
  readonly output: OS;
89
+ /** Whether the effect should be cached. */
90
+ readonly cache?: boolean;
108
91
  },
109
92
  handler: (args: EffectArgs<I>) => Promise<R>
110
93
  ): Effect<I, O>;
@@ -119,7 +102,7 @@ export declare namespace S {
119
102
  export const boolean: typeof Sury.boolean;
120
103
  export const int32: typeof Sury.int32;
121
104
  export const number: typeof Sury.number;
122
- export const bigint: typeof Sury.bigint;
105
+ export const bigint: typeof bigintSchema;
123
106
  export const never: typeof Sury.never;
124
107
  export const union: typeof Sury.union;
125
108
  export const object: typeof Sury.object;
@@ -128,6 +111,7 @@ export declare namespace S {
128
111
  // Don't expose recursive for now, since it's too advanced
129
112
  // export const recursive: typeof Sury.recursive;
130
113
  export const transform: typeof Sury.transform;
114
+ export const shape: typeof Sury.shape;
131
115
  export const refine: typeof Sury.refine;
132
116
  export const schema: typeof Sury.schema;
133
117
  export const record: typeof Sury.record;
package/index.js CHANGED
@@ -13,7 +13,7 @@ exports.S = {
13
13
  boolean: Sury.boolean,
14
14
  int32: Sury.int32,
15
15
  number: Sury.number,
16
- bigint: Sury.bigint,
16
+ bigint: require("./src/bindings/BigInt.res.js").schema,
17
17
  never: Sury.never,
18
18
  union: Sury.union,
19
19
  object: Sury.object,
@@ -22,6 +22,7 @@ exports.S = {
22
22
  // Don't expose recursive for now, since it's too advanced
23
23
  // recursive: Sury.recursive,
24
24
  transform: Sury.transform,
25
+ shape: Sury.shape,
25
26
  refine: Sury.refine,
26
27
  schema: Sury.schema,
27
28
  record: Sury.record,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "v2.26.0-rc.0",
3
+ "version": "v2.26.0-rc.1",
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.0",
29
- "envio-linux-arm64": "v2.26.0-rc.0",
30
- "envio-darwin-x64": "v2.26.0-rc.0",
31
- "envio-darwin-arm64": "v2.26.0-rc.0"
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"
32
32
  },
33
33
  "dependencies": {
34
34
  "@envio-dev/hypersync-client": "0.6.5",
package/src/Envio.gen.ts CHANGED
@@ -21,7 +21,9 @@ export type effectOptions<input,output> = {
21
21
  /** The input schema of the effect. */
22
22
  readonly input: RescriptSchema_S_t<input>;
23
23
  /** The output schema of the effect. */
24
- readonly output: RescriptSchema_S_t<output>
24
+ readonly output: RescriptSchema_S_t<output>;
25
+ /** Whether the effect should be cached. */
26
+ readonly cache?: boolean
25
27
  };
26
28
 
27
29
  export type effectContext = $$effectContext;
package/src/Envio.res CHANGED
@@ -22,6 +22,8 @@ and effectOptions<'input, 'output> = {
22
22
  input: S.t<'input>,
23
23
  /** The output schema of the effect. */
24
24
  output: S.t<'output>,
25
+ /** Whether the effect should be cached. */
26
+ cache?: bool,
25
27
  }
26
28
  @genType.import(("./Types.ts", "EffectContext"))
27
29
  and effectContext = {
@@ -48,5 +50,16 @@ let experimental_createEffect = (
48
50
  >
49
51
  ),
50
52
  callsCount: 0,
53
+ // This is the way to make the createEffect API
54
+ // work without the need for users to call S.schema themselves,
55
+ // but simply pass the desired object/tuple/etc.
56
+ // If they pass a schem, it'll also work.
57
+ input: S.schema(_ => options.input)->(
58
+ Utils.magic: S.t<S.t<'input>> => S.t<Internal.effectInput>
59
+ ),
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),
51
64
  }->(Utils.magic: Internal.effect => effect<'input, 'output>)
52
65
  }
package/src/Envio.res.js CHANGED
@@ -2,12 +2,21 @@
2
2
  'use strict';
3
3
 
4
4
  var Prometheus = require("./Prometheus.res.js");
5
+ var Belt_Option = require("rescript/lib/js/belt_Option.js");
6
+ var S$RescriptSchema = require("rescript-schema/src/S.res.js");
5
7
 
6
8
  function experimental_createEffect(options, handler) {
7
9
  Prometheus.EffectCallsCount.set(0, options.name);
8
10
  return {
9
11
  name: options.name,
10
12
  handler: handler,
13
+ cache: Belt_Option.getWithDefault(options.cache, false),
14
+ output: S$RescriptSchema.schema(function (param) {
15
+ return options.output;
16
+ }),
17
+ input: S$RescriptSchema.schema(function (param) {
18
+ return options.input;
19
+ }),
11
20
  callsCount: 0
12
21
  };
13
22
  }
@@ -901,10 +901,7 @@ let queueItemIsInReorgThreshold = (
901
901
  if currentBlockHeight === 0 {
902
902
  false
903
903
  } else {
904
- switch queueItem {
905
- | Item(_) => queueItem->queueItemBlockNumber > highestBlockBelowThreshold
906
- | NoItem(_) => queueItem->queueItemBlockNumber > highestBlockBelowThreshold
907
- }
904
+ queueItem->queueItemBlockNumber > highestBlockBelowThreshold
908
905
  }
909
906
  }
910
907
 
package/src/Internal.res CHANGED
@@ -197,6 +197,9 @@ type effectArgs = {
197
197
  type effect = {
198
198
  name: string,
199
199
  handler: effectArgs => promise<effectOutput>,
200
+ cache: bool,
201
+ output: S.t<effectOutput>,
202
+ input: S.t<effectInput>,
200
203
  mutable callsCount: int,
201
204
  }
202
205
 
package/src/Logging.res CHANGED
@@ -168,6 +168,14 @@ let logForItem = (eventItem, level: Pino.logLevel, message: string, ~params=?) =
168
168
  (eventItem->getEventLogger->Utils.magic->Js.Dict.unsafeGet((level :> string)))(params, message)
169
169
  }
170
170
 
171
+ let noopLogger: Envio.logger = {
172
+ info: (_message: string, ~params as _=?) => (),
173
+ debug: (_message: string, ~params as _=?) => (),
174
+ warn: (_message: string, ~params as _=?) => (),
175
+ error: (_message: string, ~params as _=?) => (),
176
+ errorWithExn: (_message: string, _exn) => (),
177
+ }
178
+
171
179
  let getUserLogger = (eventItem): Envio.logger => {
172
180
  info: (message: string, ~params=?) => eventItem->logForItem(#uinfo, message, ~params?),
173
181
  debug: (message: string, ~params=?) => eventItem->logForItem(#udebug, message, ~params?),
@@ -197,6 +197,34 @@ function logForItem(eventItem, level, message, params) {
197
197
  return getEventLogger(eventItem)[level](params, message);
198
198
  }
199
199
 
200
+ function noopLogger_debug(_message, param) {
201
+
202
+ }
203
+
204
+ function noopLogger_info(_message, param) {
205
+
206
+ }
207
+
208
+ function noopLogger_warn(_message, param) {
209
+
210
+ }
211
+
212
+ function noopLogger_error(_message, param) {
213
+
214
+ }
215
+
216
+ function noopLogger_errorWithExn(_message, _exn) {
217
+
218
+ }
219
+
220
+ var noopLogger = {
221
+ debug: noopLogger_debug,
222
+ info: noopLogger_info,
223
+ warn: noopLogger_warn,
224
+ error: noopLogger_error,
225
+ errorWithExn: noopLogger_errorWithExn
226
+ };
227
+
200
228
  function getUserLogger(eventItem) {
201
229
  return {
202
230
  debug: (function (message, params) {
@@ -243,5 +271,6 @@ exports.createChild = createChild;
243
271
  exports.createChildFrom = createChildFrom;
244
272
  exports.getEventLogger = getEventLogger;
245
273
  exports.logForItem = logForItem;
274
+ exports.noopLogger = noopLogger;
246
275
  exports.getUserLogger = getUserLogger;
247
276
  /* logLevels Not a pure module */
@@ -5,6 +5,16 @@
5
5
  // Currently there are quite many code spread across
6
6
  // DbFunctions, Db, Migrations, InMemoryStore modules which use codegen code directly.
7
7
 
8
+ // The type reflects an cache table in the db
9
+ // It might be present even if the effect is not used in the application
10
+ type effectCacheRecord = {
11
+ effectName: string,
12
+ // Number of rows in the table
13
+ mutable count: int,
14
+ }
15
+
16
+ type operator = [#">" | #"="]
17
+
8
18
  type storage = {
9
19
  // Should return true if we already have persisted data
10
20
  // and we can skip initialization
@@ -15,8 +25,6 @@ type storage = {
15
25
  ~entities: array<Internal.entityConfig>=?,
16
26
  ~generalTables: array<Table.table>=?,
17
27
  ~enums: array<Internal.enumConfig<Internal.enum>>=?,
18
- // If true, the storage should clear existing data
19
- ~cleanRun: bool=?,
20
28
  ) => promise<unit>,
21
29
  @raises("StorageError")
22
30
  loadByIdsOrThrow: 'item. (
@@ -25,11 +33,30 @@ type storage = {
25
33
  ~rowsSchema: S.t<array<'item>>,
26
34
  ) => promise<array<'item>>,
27
35
  @raises("StorageError")
36
+ loadByFieldOrThrow: 'item 'value. (
37
+ ~fieldName: string,
38
+ ~fieldSchema: S.t<'value>,
39
+ ~fieldValue: 'value,
40
+ ~operator: operator,
41
+ ~table: Table.table,
42
+ ~rowsSchema: S.t<array<'item>>,
43
+ ) => promise<array<'item>>,
44
+ @raises("StorageError")
28
45
  setOrThrow: 'item. (
29
46
  ~items: array<'item>,
30
47
  ~table: Table.table,
31
48
  ~itemSchema: S.t<'item>,
32
49
  ) => promise<unit>,
50
+ @raises("StorageError")
51
+ setEffectCacheOrThrow: (
52
+ ~effectName: string,
53
+ ~ids: array<string>,
54
+ ~outputs: array<Internal.effectOutput>,
55
+ ~outputSchema: S.t<Internal.effectOutput>,
56
+ ~initialize: bool,
57
+ ) => promise<unit>,
58
+ dumpEffectCache: unit => promise<unit>,
59
+ restoreEffectCache: (~withUpload: bool) => promise<array<effectCacheRecord>>,
33
60
  }
34
61
 
35
62
  exception StorageError({message: string, reason: exn})
@@ -37,7 +64,7 @@ exception StorageError({message: string, reason: exn})
37
64
  type storageStatus =
38
65
  | Unknown
39
66
  | Initializing(promise<unit>)
40
- | Ready({cleanRun: bool})
67
+ | Ready({cleanRun: bool, cache: dict<effectCacheRecord>})
41
68
 
42
69
  type t = {
43
70
  userEntities: array<Internal.entityConfig>,
@@ -46,8 +73,6 @@ type t = {
46
73
  allEnums: array<Internal.enumConfig<Internal.enum>>,
47
74
  mutable storageStatus: storageStatus,
48
75
  storage: storage,
49
- onStorageInitialize: option<unit => promise<unit>>,
50
- cacheStorage: storage,
51
76
  }
52
77
 
53
78
  let entityHistoryActionEnumConfig: Internal.enumConfig<EntityHistory.RowAction.t> = {
@@ -64,8 +89,6 @@ let make = (
64
89
  ~allEnums,
65
90
  ~staticTables,
66
91
  ~storage,
67
- ~cacheStorage,
68
- ~onStorageInitialize=?,
69
92
  ) => {
70
93
  let allEntities = userEntities->Js.Array2.concat([dcRegistryEntityConfig])
71
94
  let allEnums =
@@ -77,53 +100,70 @@ let make = (
77
100
  allEnums,
78
101
  storageStatus: Unknown,
79
102
  storage,
80
- onStorageInitialize,
81
- cacheStorage,
82
103
  }
83
104
  }
84
105
 
85
- let init = async (
86
- persistence,
87
- // There are not much sense in the option,
88
- // but this is how the runUpMigration used to work
89
- // and we want to keep the upsert behavior without breaking changes.
90
- ~skipIsInitializedCheck=false,
91
- ~reset=false,
92
- ) => {
93
- try {
94
- let shouldRun = switch persistence.storageStatus {
95
- | Unknown => true
96
- | Initializing(promise) => {
97
- await promise
98
- reset
106
+ let init = {
107
+ let loadInitialCache = async (persistence, ~withUpload) => {
108
+ let effectCacheRecords = await persistence.storage.restoreEffectCache(~withUpload)
109
+ let cache = Js.Dict.empty()
110
+ effectCacheRecords->Js.Array2.forEach(record => {
111
+ Prometheus.EffectCacheCount.set(~count=record.count, ~effectName=record.effectName)
112
+ cache->Js.Dict.set(record.effectName, record)
113
+ })
114
+ cache
115
+ }
116
+
117
+ async (persistence, ~reset=false) => {
118
+ try {
119
+ let shouldRun = switch persistence.storageStatus {
120
+ | Unknown => true
121
+ | Initializing(promise) => {
122
+ await promise
123
+ reset
124
+ }
125
+ | Ready(_) => reset
99
126
  }
100
- | Ready(_) => reset
101
- }
102
- if shouldRun {
103
- let resolveRef = ref(%raw(`null`))
104
- let promise = Promise.make((resolve, _) => {
105
- resolveRef := resolve
106
- })
107
- persistence.storageStatus = Initializing(promise)
108
- if !(reset || skipIsInitializedCheck) && (await persistence.storage.isInitialized()) {
109
- persistence.storageStatus = Ready({cleanRun: false})
110
- } else {
111
- let _ = await persistence.storage.initialize(
112
- ~entities=persistence.allEntities,
113
- ~generalTables=persistence.staticTables,
114
- ~enums=persistence.allEnums,
115
- ~cleanRun=reset || !skipIsInitializedCheck,
116
- )
117
- persistence.storageStatus = Ready({cleanRun: true})
118
- switch persistence.onStorageInitialize {
119
- | Some(onStorageInitialize) => await onStorageInitialize()
120
- | None => ()
127
+ if shouldRun {
128
+ let resolveRef = ref(%raw(`null`))
129
+ let promise = Promise.make((resolve, _) => {
130
+ resolveRef := resolve
131
+ })
132
+ persistence.storageStatus = Initializing(promise)
133
+ if reset || !(await persistence.storage.isInitialized()) {
134
+ Logging.info(`Initializing the indexer storage...`)
135
+
136
+ await persistence.storage.initialize(
137
+ ~entities=persistence.allEntities,
138
+ ~generalTables=persistence.staticTables,
139
+ ~enums=persistence.allEnums,
140
+ )
141
+
142
+ Logging.info(`The indexer storage is ready. Uploading cache...`)
143
+ persistence.storageStatus = Ready({
144
+ cleanRun: true,
145
+ cache: await loadInitialCache(persistence, ~withUpload=true),
146
+ })
147
+ } else if (
148
+ // In case of a race condition,
149
+ // we want to set the initial status to Ready only once.
150
+ switch persistence.storageStatus {
151
+ | Initializing(_) => true
152
+ | _ => false
153
+ }
154
+ ) {
155
+ Logging.info(`The indexer storage is ready.`)
156
+ persistence.storageStatus = Ready({
157
+ cleanRun: false,
158
+ cache: await loadInitialCache(persistence, ~withUpload=false),
159
+ })
121
160
  }
161
+ resolveRef.contents()
122
162
  }
123
- resolveRef.contents()
163
+ } catch {
164
+ | exn =>
165
+ exn->ErrorHandling.mkLogAndRaise(~msg=`EE800: Failed to initialize the indexer storage.`)
124
166
  }
125
- } catch {
126
- | exn => exn->ErrorHandling.mkLogAndRaise(~msg=`EE800: Failed to initialize the indexer storage.`)
127
167
  }
128
168
  }
129
169
 
@@ -135,3 +175,26 @@ let getInitializedStorageOrThrow = persistence => {
135
175
  | Ready(_) => persistence.storage
136
176
  }
137
177
  }
178
+
179
+ let setEffectCacheOrThrow = async (persistence, ~effectName, ~ids, ~outputs, ~outputSchema) => {
180
+ switch persistence.storageStatus {
181
+ | Unknown
182
+ | Initializing(_) =>
183
+ Js.Exn.raiseError(`Failed to access the indexer storage. The Persistence layer is not initialized.`)
184
+ | Ready({cache}) => {
185
+ let storage = persistence.storage
186
+ let effectCacheRecord = switch cache->Utils.Dict.dangerouslyGetNonOption(effectName) {
187
+ | Some(c) => c
188
+ | None => {
189
+ let c = {effectName, count: 0}
190
+ cache->Js.Dict.set(effectName, c)
191
+ c
192
+ }
193
+ }
194
+ let initialize = effectCacheRecord.count === 0
195
+ await storage.setEffectCacheOrThrow(~effectName, ~ids, ~outputs, ~outputSchema, ~initialize)
196
+ effectCacheRecord.count = effectCacheRecord.count + ids->Js.Array2.length
197
+ Prometheus.EffectCacheCount.set(~count=effectCacheRecord.count, ~effectName)
198
+ }
199
+ }
200
+ }
@@ -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, cacheStorage, onStorageInitialize) {
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 init(persistence, skipIsInitializedCheckOpt, resetOpt) {
41
- var skipIsInitializedCheck = skipIsInitializedCheckOpt !== undefined ? skipIsInitializedCheckOpt : false;
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 (!(reset || skipIsInitializedCheck) && await persistence.storage.isInitialized()) {
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: false
82
+ cleanRun: true,
83
+ cache: await loadInitialCache(persistence, true)
71
84
  };
72
85
  } else {
73
- await persistence.storage.initialize(persistence.allEntities, persistence.staticTables, persistence.allEnums, reset || !skipIsInitializedCheck);
74
- persistence.storageStatus = {
75
- TAG: "Ready",
76
- cleanRun: true
77
- };
78
- var onStorageInitialize = persistence.onStorageInitialize;
79
- if (onStorageInitialize !== undefined) {
80
- await onStorageInitialize();
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,38 @@ function getInitializedStorageOrThrow(persistence) {
98
113
  }
99
114
  }
100
115
 
116
+ async function setEffectCacheOrThrow(persistence, effectName, ids, outputs, outputSchema) {
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 c = cache[effectName];
127
+ var effectCacheRecord;
128
+ if (c !== undefined) {
129
+ effectCacheRecord = c;
130
+ } else {
131
+ var c$1 = {
132
+ effectName: effectName,
133
+ count: 0
134
+ };
135
+ cache[effectName] = c$1;
136
+ effectCacheRecord = c$1;
137
+ }
138
+ var initialize = effectCacheRecord.count === 0;
139
+ await storage.setEffectCacheOrThrow(effectName, ids, outputs, outputSchema, initialize);
140
+ effectCacheRecord.count = effectCacheRecord.count + ids.length | 0;
141
+ return Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
142
+ }
143
+
101
144
  exports.StorageError = StorageError;
102
145
  exports.entityHistoryActionEnumConfig = entityHistoryActionEnumConfig;
103
146
  exports.make = make;
104
147
  exports.init = init;
105
148
  exports.getInitializedStorageOrThrow = getInitializedStorageOrThrow;
106
- /* EntityHistory Not a pure module */
149
+ exports.setEffectCacheOrThrow = setEffectCacheOrThrow;
150
+ /* Logging Not a pure module */