envio 3.0.0-alpha.2 → 3.0.0-alpha.20

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.
Files changed (175) hide show
  1. package/README.md +164 -30
  2. package/bin.mjs +49 -0
  3. package/evm.schema.json +79 -169
  4. package/fuel.schema.json +50 -21
  5. package/index.d.ts +497 -1
  6. package/index.js +4 -0
  7. package/package.json +42 -31
  8. package/rescript.json +4 -1
  9. package/src/Batch.res +11 -8
  10. package/src/Batch.res.mjs +11 -9
  11. package/src/ChainFetcher.res +531 -0
  12. package/src/ChainFetcher.res.mjs +339 -0
  13. package/src/ChainManager.res +190 -0
  14. package/src/ChainManager.res.mjs +166 -0
  15. package/src/Change.res +3 -3
  16. package/src/Config.gen.ts +19 -0
  17. package/src/Config.res +737 -22
  18. package/src/Config.res.mjs +703 -26
  19. package/src/{Indexer.res → Ctx.res} +1 -1
  20. package/src/Ecosystem.res +9 -124
  21. package/src/Ecosystem.res.mjs +19 -160
  22. package/src/Env.res +30 -74
  23. package/src/Env.res.mjs +25 -87
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +20 -9
  26. package/src/EventProcessing.res +469 -0
  27. package/src/EventProcessing.res.mjs +337 -0
  28. package/src/EvmTypes.gen.ts +6 -0
  29. package/src/EvmTypes.res +1 -0
  30. package/src/FetchState.res +1256 -639
  31. package/src/FetchState.res.mjs +1135 -612
  32. package/src/GlobalState.res +1190 -0
  33. package/src/GlobalState.res.mjs +1183 -0
  34. package/src/GlobalStateManager.res +68 -0
  35. package/src/GlobalStateManager.res.mjs +75 -0
  36. package/src/GlobalStateManager.resi +7 -0
  37. package/src/HandlerLoader.res +89 -0
  38. package/src/HandlerLoader.res.mjs +79 -0
  39. package/src/HandlerRegister.res +357 -0
  40. package/src/HandlerRegister.res.mjs +299 -0
  41. package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
  42. package/src/Hasura.res +111 -175
  43. package/src/Hasura.res.mjs +88 -150
  44. package/src/InMemoryStore.res +1 -1
  45. package/src/InMemoryStore.res.mjs +3 -3
  46. package/src/InMemoryTable.res +1 -1
  47. package/src/InMemoryTable.res.mjs +1 -1
  48. package/src/Internal.gen.ts +4 -0
  49. package/src/Internal.res +230 -12
  50. package/src/Internal.res.mjs +115 -1
  51. package/src/LoadLayer.res +444 -0
  52. package/src/LoadLayer.res.mjs +296 -0
  53. package/src/LoadLayer.resi +32 -0
  54. package/src/LogSelection.res +33 -27
  55. package/src/LogSelection.res.mjs +6 -0
  56. package/src/Logging.res +21 -7
  57. package/src/Logging.res.mjs +16 -8
  58. package/src/Main.res +377 -0
  59. package/src/Main.res.mjs +339 -0
  60. package/src/Persistence.res +7 -21
  61. package/src/Persistence.res.mjs +3 -3
  62. package/src/PgStorage.gen.ts +10 -0
  63. package/src/PgStorage.res +116 -69
  64. package/src/PgStorage.res.d.mts +5 -0
  65. package/src/PgStorage.res.mjs +93 -50
  66. package/src/Prometheus.res +294 -224
  67. package/src/Prometheus.res.mjs +353 -340
  68. package/src/ReorgDetection.res +6 -10
  69. package/src/ReorgDetection.res.mjs +6 -6
  70. package/src/SafeCheckpointTracking.res +4 -4
  71. package/src/SafeCheckpointTracking.res.mjs +2 -2
  72. package/src/Sink.res +4 -2
  73. package/src/Sink.res.mjs +2 -1
  74. package/src/TableIndices.res +0 -1
  75. package/src/TestIndexer.res +692 -0
  76. package/src/TestIndexer.res.mjs +527 -0
  77. package/src/TestIndexerProxyStorage.res +205 -0
  78. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  79. package/src/TopicFilter.res +1 -1
  80. package/src/Types.ts +1 -1
  81. package/src/UserContext.res +424 -0
  82. package/src/UserContext.res.mjs +279 -0
  83. package/src/Utils.res +97 -26
  84. package/src/Utils.res.mjs +91 -44
  85. package/src/bindings/BigInt.res +10 -0
  86. package/src/bindings/BigInt.res.mjs +15 -0
  87. package/src/bindings/ClickHouse.res +120 -23
  88. package/src/bindings/ClickHouse.res.mjs +118 -28
  89. package/src/bindings/DateFns.res +74 -0
  90. package/src/bindings/DateFns.res.mjs +22 -0
  91. package/src/bindings/EventSource.res +8 -1
  92. package/src/bindings/EventSource.res.mjs +8 -1
  93. package/src/bindings/Express.res +1 -0
  94. package/src/bindings/Hrtime.res +14 -1
  95. package/src/bindings/Hrtime.res.mjs +22 -2
  96. package/src/bindings/Hrtime.resi +4 -0
  97. package/src/bindings/Lodash.res +0 -1
  98. package/src/bindings/NodeJs.res +49 -3
  99. package/src/bindings/NodeJs.res.mjs +11 -3
  100. package/src/bindings/Pino.res +24 -10
  101. package/src/bindings/Pino.res.mjs +14 -8
  102. package/src/bindings/Postgres.gen.ts +8 -0
  103. package/src/bindings/Postgres.res +5 -1
  104. package/src/bindings/Postgres.res.d.mts +5 -0
  105. package/src/bindings/PromClient.res +0 -10
  106. package/src/bindings/PromClient.res.mjs +0 -3
  107. package/src/bindings/Vitest.res +142 -0
  108. package/src/bindings/Vitest.res.mjs +9 -0
  109. package/src/bindings/WebSocket.res +27 -0
  110. package/src/bindings/WebSocket.res.mjs +2 -0
  111. package/src/bindings/Yargs.res +8 -0
  112. package/src/bindings/Yargs.res.mjs +2 -0
  113. package/src/db/EntityHistory.res +7 -7
  114. package/src/db/EntityHistory.res.mjs +9 -9
  115. package/src/db/InternalTable.res +59 -111
  116. package/src/db/InternalTable.res.mjs +73 -104
  117. package/src/db/Table.res +27 -8
  118. package/src/db/Table.res.mjs +25 -14
  119. package/src/sources/Evm.res +84 -0
  120. package/src/sources/Evm.res.mjs +105 -0
  121. package/src/sources/EvmChain.res +94 -0
  122. package/src/sources/EvmChain.res.mjs +60 -0
  123. package/src/sources/Fuel.res +19 -34
  124. package/src/sources/Fuel.res.mjs +34 -16
  125. package/src/sources/FuelSDK.res +38 -0
  126. package/src/sources/FuelSDK.res.mjs +29 -0
  127. package/src/sources/HyperFuel.res +2 -2
  128. package/src/sources/HyperFuel.resi +1 -1
  129. package/src/sources/HyperFuelClient.res +2 -2
  130. package/src/sources/HyperFuelSource.res +33 -13
  131. package/src/sources/HyperFuelSource.res.mjs +24 -16
  132. package/src/sources/HyperSync.res +36 -6
  133. package/src/sources/HyperSync.res.mjs +9 -7
  134. package/src/sources/HyperSync.resi +4 -0
  135. package/src/sources/HyperSyncClient.res +1 -1
  136. package/src/sources/HyperSyncHeightStream.res +47 -116
  137. package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
  138. package/src/sources/HyperSyncSource.res +118 -139
  139. package/src/sources/HyperSyncSource.res.mjs +104 -121
  140. package/src/sources/Rpc.res +86 -14
  141. package/src/sources/Rpc.res.mjs +101 -9
  142. package/src/sources/RpcSource.res +621 -364
  143. package/src/sources/RpcSource.res.mjs +843 -410
  144. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  145. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  146. package/src/sources/Source.res +7 -5
  147. package/src/sources/SourceManager.res +325 -225
  148. package/src/sources/SourceManager.res.mjs +314 -171
  149. package/src/sources/SourceManager.resi +17 -6
  150. package/src/sources/Svm.res +81 -0
  151. package/src/sources/Svm.res.mjs +90 -0
  152. package/src/tui/Tui.res +247 -0
  153. package/src/tui/Tui.res.mjs +337 -0
  154. package/src/tui/bindings/Ink.res +371 -0
  155. package/src/tui/bindings/Ink.res.mjs +72 -0
  156. package/src/tui/bindings/Style.res +123 -0
  157. package/src/tui/bindings/Style.res.mjs +2 -0
  158. package/src/tui/components/BufferedProgressBar.res +40 -0
  159. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  160. package/src/tui/components/CustomHooks.res +122 -0
  161. package/src/tui/components/CustomHooks.res.mjs +179 -0
  162. package/src/tui/components/Messages.res +41 -0
  163. package/src/tui/components/Messages.res.mjs +75 -0
  164. package/src/tui/components/SyncETA.res +174 -0
  165. package/src/tui/components/SyncETA.res.mjs +263 -0
  166. package/src/tui/components/TuiData.res +47 -0
  167. package/src/tui/components/TuiData.res.mjs +34 -0
  168. package/svm.schema.json +112 -0
  169. package/bin.js +0 -48
  170. package/src/EventRegister.res +0 -241
  171. package/src/EventRegister.res.mjs +0 -240
  172. package/src/bindings/Ethers.gen.ts +0 -14
  173. package/src/bindings/Ethers.res +0 -204
  174. package/src/bindings/Ethers.res.mjs +0 -130
  175. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/src/Hasura.res CHANGED
@@ -46,19 +46,6 @@ let trackTablesRoute = Rest.route(() => {
46
46
  responses,
47
47
  })
48
48
 
49
- let createSelectPermissionRoute = Rest.route(() => {
50
- method: Post,
51
- path: "",
52
- input: s => {
53
- let _ = s.field("type", S.literal("pg_create_select_permission"))
54
- {
55
- "args": s.field("args", S.json(~validate=false)),
56
- "auth": s->auth,
57
- }
58
- },
59
- responses,
60
- })
61
-
62
49
  let rawBodyRoute = Rest.route(() => {
63
50
  method: Post,
64
51
  path: "",
@@ -71,36 +58,33 @@ let rawBodyRoute = Rest.route(() => {
71
58
  responses,
72
59
  })
73
60
 
74
- let bulkKeepGoingRoute = Rest.route(() => {
75
- method: Post,
76
- path: "",
77
- input: s => {
78
- let _ = s.field("type", S.literal("bulk_keep_going"))
79
- {
80
- "args": s.field("args", S.json(~validate=false)),
81
- "auth": s->auth,
61
+ let sendOperation = async (~endpoint, ~auth, ~operation: Js.Json.t) => {
62
+ let maxRetries = 3
63
+ let rec retry = async (~attempt) => {
64
+ try {
65
+ let _ = await rawBodyRoute->Rest.fetch(
66
+ {
67
+ "bodyString": operation->Js.Json.stringify,
68
+ "auth": auth,
69
+ },
70
+ ~client=Rest.client(endpoint),
71
+ )
72
+ } catch {
73
+ | exn =>
74
+ if attempt < maxRetries {
75
+ let backoffMs = Js.Math.pow_float(~base=2.0, ~exp=attempt->Belt.Int.toFloat)->Belt.Float.toInt * 1000
76
+ await Time.resolvePromiseAfterDelay(~delayMilliseconds=backoffMs)
77
+ await retry(~attempt=attempt + 1)
78
+ } else {
79
+ Logging.warn({
80
+ "msg": "Hasura configuration request failed. Indexing will still work - but you may have issues querying data via GraphQL.",
81
+ "err": exn->Utils.prettifyExn,
82
+ })
83
+ }
82
84
  }
83
- },
84
- responses: [
85
- (s: Rest.Response.s) => {
86
- s.status(200)
87
- s.data(S.json(~validate=false))
88
- },
89
- ],
90
- })
91
- let bulkKeepGoingErrorsSchema = S.array(
92
- S.union([
93
- S.object(s => {
94
- s.tag("message", "success")
95
- None
96
- }),
97
- S.object(s => {
98
- Some(s.field("error", S.string))
99
- }),
100
- ]),
101
- )->S.transform(_ => {
102
- parser: a => Belt.Array.keepMapU(a, a => a),
103
- })
85
+ }
86
+ await retry(~attempt=0)
87
+ }
104
88
 
105
89
  let clearHasuraMetadata = async (~endpoint, ~auth) => {
106
90
  try {
@@ -113,7 +97,7 @@ let clearHasuraMetadata = async (~endpoint, ~auth) => {
113
97
  } catch {
114
98
  | exn =>
115
99
  Logging.error({
116
- "msg": `EE806: There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
100
+ "msg": `There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
117
101
  "err": exn->Utils.prettifyExn,
118
102
  })
119
103
  }
@@ -154,44 +138,47 @@ let trackTables = async (~endpoint, ~auth, ~pgSchema, ~tableNames: array<string>
154
138
  } catch {
155
139
  | exn =>
156
140
  Logging.error({
157
- "msg": `EE807: There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
141
+ "msg": `There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
158
142
  "tableNames": tableNames,
159
143
  "err": exn->Utils.prettifyExn,
160
144
  })
161
145
  }
162
146
  }
163
147
 
164
- type bulkOperation = {
165
- \"type": string,
166
- args: Js.Json.t,
167
- }
168
-
169
- let createSelectPermissionOperation = (
148
+ let createSelectPermission = async (
149
+ ~endpoint,
150
+ ~auth,
170
151
  ~tableName: string,
171
152
  ~pgSchema,
172
153
  ~responseLimit,
173
154
  ~aggregateEntities,
174
- ): bulkOperation => {
175
- {
176
- \"type": "pg_create_select_permission",
177
- args: {
178
- "table": {
179
- "schema": pgSchema,
180
- "name": tableName,
181
- },
182
- "role": "public",
183
- "source": "default",
184
- "permission": {
185
- "columns": "*",
186
- "filter": Js.Obj.empty(),
187
- "limit": responseLimit,
188
- "allow_aggregations": aggregateEntities->Js.Array2.includes(tableName),
155
+ ) => {
156
+ await sendOperation(
157
+ ~endpoint,
158
+ ~auth,
159
+ ~operation={
160
+ "type": "pg_create_select_permission",
161
+ "args": {
162
+ "table": {
163
+ "schema": pgSchema,
164
+ "name": tableName,
165
+ },
166
+ "role": "public",
167
+ "source": "default",
168
+ "permission": {
169
+ "columns": "*",
170
+ "filter": Js.Obj.empty(),
171
+ "limit": responseLimit,
172
+ "allow_aggregations": aggregateEntities->Js.Array2.includes(tableName),
173
+ },
189
174
  },
190
175
  }->(Utils.magic: 'a => Js.Json.t),
191
- }
176
+ )
192
177
  }
193
178
 
194
- let createEntityRelationshipOperation = (
179
+ let createEntityRelationship = async (
180
+ ~endpoint,
181
+ ~auth,
195
182
  ~pgSchema,
196
183
  ~tableName: string,
197
184
  ~relationshipType: string,
@@ -199,73 +186,33 @@ let createEntityRelationshipOperation = (
199
186
  ~objectName: string,
200
187
  ~mappedEntity: string,
201
188
  ~isDerivedFrom: bool,
202
- ): bulkOperation => {
189
+ ) => {
203
190
  let derivedFromTo = isDerivedFrom ? `"id": "${relationalKey}"` : `"${relationalKey}_id" : "id"`
204
191
 
205
- {
206
- \"type": `pg_create_${relationshipType}_relationship`,
207
- args: {
208
- "table": {
209
- "schema": pgSchema,
210
- "name": tableName,
211
- },
212
- "name": objectName,
213
- "source": "default",
214
- "using": {
215
- "manual_configuration": {
216
- "remote_table": {
217
- "schema": pgSchema,
218
- "name": mappedEntity,
192
+ await sendOperation(
193
+ ~endpoint,
194
+ ~auth,
195
+ ~operation={
196
+ "type": `pg_create_${relationshipType}_relationship`,
197
+ "args": {
198
+ "table": {
199
+ "schema": pgSchema,
200
+ "name": tableName,
201
+ },
202
+ "name": objectName,
203
+ "source": "default",
204
+ "using": {
205
+ "manual_configuration": {
206
+ "remote_table": {
207
+ "schema": pgSchema,
208
+ "name": mappedEntity,
209
+ },
210
+ "column_mapping": Js.Json.parseExn(`{${derivedFromTo}}`),
219
211
  },
220
- "column_mapping": Js.Json.parseExn(`{${derivedFromTo}}`),
221
212
  },
222
213
  },
223
214
  }->(Utils.magic: 'a => Js.Json.t),
224
- }
225
- }
226
-
227
- let executeBulkKeepGoing = async (~endpoint, ~auth, ~operations: array<bulkOperation>) => {
228
- if operations->Js.Array2.length === 0 {
229
- Logging.trace("No hasura bulk configuration operations to execute")
230
- } else {
231
- try {
232
- let result = await bulkKeepGoingRoute->Rest.fetch(
233
- {
234
- "auth": auth,
235
- "args": operations->(Utils.magic: 'a => Js.Json.t),
236
- },
237
- ~client=Rest.client(endpoint),
238
- )
239
-
240
- let errors = try {
241
- result->S.parseJsonOrThrow(bulkKeepGoingErrorsSchema)
242
- } catch {
243
- | S.Raised(error) => [error->S.Error.message]
244
- | exn => [exn->Utils.prettifyExn->Utils.magic]
245
- }
246
-
247
- switch errors {
248
- | [] =>
249
- Logging.trace({
250
- "msg": "Hasura configuration completed",
251
- "operations": operations->Js.Array2.length,
252
- })
253
- | _ =>
254
- Logging.warn({
255
- "msg": "Hasura configuration completed with errors. Indexing will still work - but you may have issues querying data via GraphQL.",
256
- "errors": errors,
257
- "operations": operations->Js.Array2.length,
258
- })
259
- }
260
- } catch {
261
- | exn =>
262
- Logging.error({
263
- "msg": `EE809: There was an issue executing bulk operations in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
264
- "operations": operations->Js.Array2.length,
265
- "err": exn->Utils.prettifyExn,
266
- })
267
- }
268
- }
215
+ )
269
216
  }
270
217
 
271
218
  let trackDatabase = async (
@@ -291,64 +238,53 @@ let trackDatabase = async (
291
238
 
292
239
  await trackTables(~endpoint, ~auth, ~pgSchema, ~tableNames)
293
240
 
294
- // Collect all operations for bulk execution
295
- let allOperations = []
296
-
297
- // Add select permission operations
298
- tableNames->Js.Array2.forEach(tableName => {
299
- allOperations
300
- ->Js.Array2.push(
301
- createSelectPermissionOperation(~tableName, ~pgSchema, ~responseLimit, ~aggregateEntities),
302
- )
303
- ->ignore
304
- })
241
+ for i in 0 to tableNames->Js.Array2.length - 1 {
242
+ let tableName = tableNames->Js.Array2.unsafe_get(i)
243
+ await createSelectPermission(~endpoint, ~auth, ~tableName, ~pgSchema, ~responseLimit, ~aggregateEntities)
244
+ }
305
245
 
306
- // Add relationship operations
307
- userEntities->Js.Array2.forEach(entityConfig => {
246
+ for i in 0 to userEntities->Js.Array2.length - 1 {
247
+ let entityConfig = userEntities->Js.Array2.unsafe_get(i)
308
248
  let {tableName} = entityConfig.table
309
249
 
310
250
  //Set array relationships
311
- entityConfig.table
312
- ->Table.getDerivedFromFields
313
- ->Js.Array2.forEach(derivedFromField => {
251
+ let derivedFromFields = entityConfig.table->Table.getDerivedFromFields
252
+ for j in 0 to derivedFromFields->Js.Array2.length - 1 {
253
+ let derivedFromField = derivedFromFields->Js.Array2.unsafe_get(j)
314
254
  //determines the actual name of the underlying relational field (if it's an entity mapping then suffixes _id for eg.)
315
255
  let relationalFieldName =
316
256
  schema->Schema.getDerivedFromFieldName(derivedFromField)->Utils.unwrapResultExn
317
257
 
318
- allOperations
319
- ->Js.Array2.push(
320
- createEntityRelationshipOperation(
321
- ~pgSchema,
322
- ~tableName,
323
- ~relationshipType="array",
324
- ~isDerivedFrom=true,
325
- ~objectName=derivedFromField.fieldName,
326
- ~relationalKey=relationalFieldName,
327
- ~mappedEntity=derivedFromField.derivedFromEntity,
328
- ),
258
+ await createEntityRelationship(
259
+ ~endpoint,
260
+ ~auth,
261
+ ~pgSchema,
262
+ ~tableName,
263
+ ~relationshipType="array",
264
+ ~isDerivedFrom=true,
265
+ ~objectName=derivedFromField.fieldName,
266
+ ~relationalKey=relationalFieldName,
267
+ ~mappedEntity=derivedFromField.derivedFromEntity,
329
268
  )
330
- ->ignore
331
- })
269
+ }
332
270
 
333
271
  //Set object relationships
334
- entityConfig.table
335
- ->Table.getLinkedEntityFields
336
- ->Js.Array2.forEach(((field, linkedEntityName)) => {
337
- allOperations
338
- ->Js.Array2.push(
339
- createEntityRelationshipOperation(
340
- ~pgSchema,
341
- ~tableName,
342
- ~relationshipType="object",
343
- ~isDerivedFrom=false,
344
- ~objectName=field.fieldName,
345
- ~relationalKey=field.fieldName,
346
- ~mappedEntity=linkedEntityName,
347
- ),
272
+ let linkedEntityFields = entityConfig.table->Table.getLinkedEntityFields
273
+ for j in 0 to linkedEntityFields->Js.Array2.length - 1 {
274
+ let (field, linkedEntityName) = linkedEntityFields->Js.Array2.unsafe_get(j)
275
+ await createEntityRelationship(
276
+ ~endpoint,
277
+ ~auth,
278
+ ~pgSchema,
279
+ ~tableName,
280
+ ~relationshipType="object",
281
+ ~isDerivedFrom=false,
282
+ ~objectName=field.fieldName,
283
+ ~relationalKey=field.fieldName,
284
+ ~mappedEntity=linkedEntityName,
348
285
  )
349
- ->ignore
350
- })
351
- })
286
+ }
287
+ }
352
288
 
353
- await executeBulkKeepGoing(~endpoint, ~auth, ~operations=allOperations)
289
+ Logging.info("Hasura configuration completed")
354
290
  }
@@ -1,6 +1,7 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Rest from "./vendored/Rest.res.mjs";
4
+ import * as Time from "./Time.res.mjs";
4
5
  import * as Table from "./db/Table.res.mjs";
5
6
  import * as Utils from "./Utils.res.mjs";
6
7
  import * as Schema from "./db/Schema.res.mjs";
@@ -60,21 +61,6 @@ function trackTablesRoute() {
60
61
  };
61
62
  }
62
63
 
63
- function createSelectPermissionRoute() {
64
- return {
65
- method: "POST",
66
- path: "",
67
- input: (function (s) {
68
- s.field("type", S$RescriptSchema.literal("pg_create_select_permission"));
69
- return {
70
- args: s.field("args", S$RescriptSchema.json(false)),
71
- auth: auth(s)
72
- };
73
- }),
74
- responses: responses
75
- };
76
- }
77
-
78
64
  function rawBodyRoute() {
79
65
  return {
80
66
  method: "POST",
@@ -89,41 +75,31 @@ function rawBodyRoute() {
89
75
  };
90
76
  }
91
77
 
92
- function bulkKeepGoingRoute() {
93
- return {
94
- method: "POST",
95
- path: "",
96
- input: (function (s) {
97
- s.field("type", S$RescriptSchema.literal("bulk_keep_going"));
98
- return {
99
- args: s.field("args", S$RescriptSchema.json(false)),
100
- auth: auth(s)
101
- };
102
- }),
103
- responses: [(function (s) {
104
- s.status(200);
105
- return s.data(S$RescriptSchema.json(false));
106
- })]
107
- };
78
+ async function sendOperation(endpoint, auth, operation) {
79
+ var retry = async function (attempt) {
80
+ try {
81
+ await Rest.$$fetch(rawBodyRoute, {
82
+ bodyString: JSON.stringify(operation),
83
+ auth: auth
84
+ }, Rest.client(endpoint, undefined));
85
+ return ;
86
+ }
87
+ catch (raw_exn){
88
+ var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
89
+ if (attempt >= 3) {
90
+ return Logging.warn({
91
+ msg: "Hasura configuration request failed. Indexing will still work - but you may have issues querying data via GraphQL.",
92
+ err: Utils.prettifyExn(exn)
93
+ });
94
+ }
95
+ var backoffMs = Math.imul(Math.pow(2.0, attempt) | 0, 1000);
96
+ await Time.resolvePromiseAfterDelay(backoffMs);
97
+ return await retry(attempt + 1 | 0);
98
+ }
99
+ };
100
+ return await retry(0);
108
101
  }
109
102
 
110
- var bulkKeepGoingErrorsSchema = S$RescriptSchema.transform(S$RescriptSchema.array(S$RescriptSchema.union([
111
- S$RescriptSchema.object(function (s) {
112
- s.tag("message", "success");
113
- }),
114
- S$RescriptSchema.object(function (s) {
115
- return s.f("error", S$RescriptSchema.string);
116
- })
117
- ])), (function (param) {
118
- return {
119
- p: (function (a) {
120
- return Belt_Array.keepMapU(a, (function (a) {
121
- return a;
122
- }));
123
- })
124
- };
125
- }));
126
-
127
103
  async function clearHasuraMetadata(endpoint, auth) {
128
104
  try {
129
105
  var result = await Rest.$$fetch(clearMetadataRoute, auth, Rest.client(endpoint, undefined));
@@ -134,7 +110,7 @@ async function clearHasuraMetadata(endpoint, auth) {
134
110
  catch (raw_exn){
135
111
  var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
136
112
  return Logging.error({
137
- msg: "EE806: There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.",
113
+ msg: "There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.",
138
114
  err: Utils.prettifyExn(exn)
139
115
  });
140
116
  }
@@ -169,95 +145,55 @@ async function trackTables(endpoint, auth, pgSchema, tableNames) {
169
145
  catch (raw_exn){
170
146
  var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
171
147
  return Logging.error({
172
- msg: "EE807: There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.",
148
+ msg: "There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.",
173
149
  tableNames: tableNames,
174
150
  err: Utils.prettifyExn(exn)
175
151
  });
176
152
  }
177
153
  }
178
154
 
179
- function createSelectPermissionOperation(tableName, pgSchema, responseLimit, aggregateEntities) {
180
- return {
181
- type: "pg_create_select_permission",
182
- args: {
183
- table: {
184
- schema: pgSchema,
185
- name: tableName
186
- },
187
- role: "public",
188
- source: "default",
189
- permission: {
190
- columns: "*",
191
- filter: {},
192
- limit: responseLimit,
193
- allow_aggregations: aggregateEntities.includes(tableName)
194
- }
195
- }
196
- };
155
+ async function createSelectPermission(endpoint, auth, tableName, pgSchema, responseLimit, aggregateEntities) {
156
+ return await sendOperation(endpoint, auth, {
157
+ type: "pg_create_select_permission",
158
+ args: {
159
+ table: {
160
+ schema: pgSchema,
161
+ name: tableName
162
+ },
163
+ role: "public",
164
+ source: "default",
165
+ permission: {
166
+ columns: "*",
167
+ filter: {},
168
+ limit: responseLimit,
169
+ allow_aggregations: aggregateEntities.includes(tableName)
170
+ }
171
+ }
172
+ });
197
173
  }
198
174
 
199
- function createEntityRelationshipOperation(pgSchema, tableName, relationshipType, relationalKey, objectName, mappedEntity, isDerivedFrom) {
175
+ async function createEntityRelationship(endpoint, auth, pgSchema, tableName, relationshipType, relationalKey, objectName, mappedEntity, isDerivedFrom) {
200
176
  var derivedFromTo = isDerivedFrom ? "\"id\": \"" + relationalKey + "\"" : "\"" + relationalKey + "_id\" : \"id\"";
201
- return {
202
- type: "pg_create_" + relationshipType + "_relationship",
203
- args: {
204
- table: {
205
- schema: pgSchema,
206
- name: tableName
207
- },
208
- name: objectName,
209
- source: "default",
210
- using: {
211
- manual_configuration: {
212
- remote_table: {
177
+ return await sendOperation(endpoint, auth, {
178
+ type: "pg_create_" + relationshipType + "_relationship",
179
+ args: {
180
+ table: {
213
181
  schema: pgSchema,
214
- name: mappedEntity
182
+ name: tableName
215
183
  },
216
- column_mapping: JSON.parse("{" + derivedFromTo + "}")
184
+ name: objectName,
185
+ source: "default",
186
+ using: {
187
+ manual_configuration: {
188
+ remote_table: {
189
+ schema: pgSchema,
190
+ name: mappedEntity
191
+ },
192
+ column_mapping: JSON.parse("{" + derivedFromTo + "}")
193
+ }
194
+ }
217
195
  }
218
- }
219
- }
220
- };
221
- }
222
-
223
- async function executeBulkKeepGoing(endpoint, auth, operations) {
224
- if (operations.length === 0) {
225
- return Logging.trace("No hasura bulk configuration operations to execute");
226
- }
227
- try {
228
- var result = await Rest.$$fetch(bulkKeepGoingRoute, {
229
- auth: auth,
230
- args: operations
231
- }, Rest.client(endpoint, undefined));
232
- var errors;
233
- try {
234
- errors = S$RescriptSchema.parseJsonOrThrow(result, bulkKeepGoingErrorsSchema);
235
- }
236
- catch (raw_error){
237
- var error = Caml_js_exceptions.internalToOCamlException(raw_error);
238
- errors = error.RE_EXN_ID === S$RescriptSchema.Raised ? [S$RescriptSchema.$$Error.message(error._1)] : [Utils.prettifyExn(error)];
239
- }
240
- if (errors.length !== 0) {
241
- return Logging.warn({
242
- msg: "Hasura configuration completed with errors. Indexing will still work - but you may have issues querying data via GraphQL.",
243
- errors: errors,
244
- operations: operations.length
245
- });
246
- } else {
247
- return Logging.trace({
248
- msg: "Hasura configuration completed",
249
- operations: operations.length
250
- });
251
- }
252
- }
253
- catch (raw_exn){
254
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
255
- return Logging.error({
256
- msg: "EE809: There was an issue executing bulk operations in hasura - indexing may still work - but you may have issues querying the data in hasura.",
257
- operations: operations.length,
258
- err: Utils.prettifyExn(exn)
259
- });
260
- }
196
+ });
261
197
  }
262
198
 
263
199
  async function trackDatabase(endpoint, auth, pgSchema, userEntities, aggregateEntities, responseLimit, schema) {
@@ -276,23 +212,28 @@ async function trackDatabase(endpoint, auth, pgSchema, userEntities, aggregateEn
276
212
  Logging.info("Tracking tables in Hasura");
277
213
  await clearHasuraMetadata(endpoint, auth);
278
214
  await trackTables(endpoint, auth, pgSchema, tableNames);
279
- var allOperations = [];
280
- tableNames.forEach(function (tableName) {
281
- allOperations.push(createSelectPermissionOperation(tableName, pgSchema, responseLimit, aggregateEntities));
282
- });
283
- userEntities.forEach(function (entityConfig) {
284
- var match = entityConfig.table;
285
- var tableName = match.tableName;
286
- Table.getDerivedFromFields(entityConfig.table).forEach(function (derivedFromField) {
287
- var relationalFieldName = Utils.unwrapResultExn(Schema.getDerivedFromFieldName(schema, derivedFromField));
288
- allOperations.push(createEntityRelationshipOperation(pgSchema, tableName, "array", relationalFieldName, derivedFromField.fieldName, derivedFromField.derivedFromEntity, true));
289
- });
290
- Table.getLinkedEntityFields(entityConfig.table).forEach(function (param) {
291
- var field = param[0];
292
- allOperations.push(createEntityRelationshipOperation(pgSchema, tableName, "object", field.fieldName, field.fieldName, param[1], false));
293
- });
294
- });
295
- return await executeBulkKeepGoing(endpoint, auth, allOperations);
215
+ for(var i = 0 ,i_finish = tableNames.length; i < i_finish; ++i){
216
+ var tableName = tableNames[i];
217
+ await createSelectPermission(endpoint, auth, tableName, pgSchema, responseLimit, aggregateEntities);
218
+ }
219
+ for(var i$1 = 0 ,i_finish$1 = userEntities.length; i$1 < i_finish$1; ++i$1){
220
+ var entityConfig = userEntities[i$1];
221
+ var match = entityConfig.table;
222
+ var tableName$1 = match.tableName;
223
+ var derivedFromFields = Table.getDerivedFromFields(entityConfig.table);
224
+ for(var j = 0 ,j_finish = derivedFromFields.length; j < j_finish; ++j){
225
+ var derivedFromField = derivedFromFields[j];
226
+ var relationalFieldName = Utils.unwrapResultExn(Schema.getDerivedFromFieldName(schema, derivedFromField));
227
+ await createEntityRelationship(endpoint, auth, pgSchema, tableName$1, "array", relationalFieldName, derivedFromField.fieldName, derivedFromField.derivedFromEntity, true);
228
+ }
229
+ var linkedEntityFields = Table.getLinkedEntityFields(entityConfig.table);
230
+ for(var j$1 = 0 ,j_finish$1 = linkedEntityFields.length; j$1 < j_finish$1; ++j$1){
231
+ var match$1 = linkedEntityFields[j$1];
232
+ var field = match$1[0];
233
+ await createEntityRelationship(endpoint, auth, pgSchema, tableName$1, "object", field.fieldName, field.fieldName, match$1[1], false);
234
+ }
235
+ }
236
+ return Logging.info("Hasura configuration completed");
296
237
  }
297
238
 
298
239
  export {
@@ -300,15 +241,12 @@ export {
300
241
  responses ,
301
242
  clearMetadataRoute ,
302
243
  trackTablesRoute ,
303
- createSelectPermissionRoute ,
304
244
  rawBodyRoute ,
305
- bulkKeepGoingRoute ,
306
- bulkKeepGoingErrorsSchema ,
245
+ sendOperation ,
307
246
  clearHasuraMetadata ,
308
247
  trackTables ,
309
- createSelectPermissionOperation ,
310
- createEntityRelationshipOperation ,
311
- executeBulkKeepGoing ,
248
+ createSelectPermission ,
249
+ createEntityRelationship ,
312
250
  trackDatabase ,
313
251
  }
314
- /* bulkKeepGoingErrorsSchema Not a pure module */
252
+ /* Rest Not a pure module */
@@ -100,7 +100,7 @@ let isRollingBack = (inMemoryStore: t) => inMemoryStore.rollbackTargetCheckpoint
100
100
 
101
101
  let setBatchDcs = (inMemoryStore: t, ~batch: Batch.t, ~shouldSaveHistory) => {
102
102
  let inMemTable =
103
- inMemoryStore->getInMemTable(~entityConfig=InternalTable.DynamicContractRegistry.config)
103
+ inMemoryStore->getInMemTable(~entityConfig=InternalTable.DynamicContractRegistry.entityConfig)
104
104
 
105
105
  let itemIdx = ref(0)
106
106