envio 3.1.2 → 3.2.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.
Files changed (134) hide show
  1. package/evm.schema.json +83 -11
  2. package/fuel.schema.json +83 -11
  3. package/index.d.ts +184 -3
  4. package/package.json +6 -6
  5. package/src/Batch.res +2 -2
  6. package/src/ChainFetcher.res +27 -3
  7. package/src/ChainFetcher.res.mjs +17 -3
  8. package/src/ChainManager.res +163 -0
  9. package/src/ChainManager.res.mjs +136 -0
  10. package/src/Config.res +213 -30
  11. package/src/Config.res.mjs +102 -41
  12. package/src/Core.res +16 -10
  13. package/src/Ecosystem.res +0 -3
  14. package/src/Env.res +2 -2
  15. package/src/Env.res.mjs +2 -2
  16. package/src/Envio.res +101 -2
  17. package/src/Envio.res.mjs +2 -3
  18. package/src/EventConfigBuilder.res +52 -0
  19. package/src/EventConfigBuilder.res.mjs +32 -0
  20. package/src/EventUtils.res +2 -2
  21. package/src/FetchState.res +23 -14
  22. package/src/FetchState.res.mjs +21 -15
  23. package/src/GlobalState.res +219 -363
  24. package/src/GlobalState.res.mjs +314 -491
  25. package/src/GlobalStateManager.res +49 -59
  26. package/src/GlobalStateManager.res.mjs +5 -4
  27. package/src/GlobalStateManager.resi +1 -1
  28. package/src/HandlerLoader.res +12 -1
  29. package/src/HandlerLoader.res.mjs +6 -1
  30. package/src/HandlerRegister.res +9 -9
  31. package/src/HandlerRegister.res.mjs +9 -9
  32. package/src/Hasura.res +102 -32
  33. package/src/Hasura.res.mjs +88 -34
  34. package/src/InMemoryStore.res +10 -1
  35. package/src/InMemoryStore.res.mjs +4 -1
  36. package/src/InMemoryTable.res +83 -136
  37. package/src/InMemoryTable.res.mjs +57 -86
  38. package/src/Internal.res +54 -5
  39. package/src/Internal.res.mjs +2 -8
  40. package/src/LazyLoader.res +2 -2
  41. package/src/LazyLoader.res.mjs +3 -3
  42. package/src/LoadLayer.res +47 -60
  43. package/src/LoadLayer.res.mjs +28 -50
  44. package/src/LoadLayer.resi +2 -5
  45. package/src/LogSelection.res +4 -4
  46. package/src/LogSelection.res.mjs +5 -7
  47. package/src/Logging.res +1 -1
  48. package/src/Main.res +61 -2
  49. package/src/Main.res.mjs +37 -1
  50. package/src/Persistence.res +3 -16
  51. package/src/PgStorage.res +125 -114
  52. package/src/PgStorage.res.mjs +112 -95
  53. package/src/Ports.res +5 -0
  54. package/src/Ports.res.mjs +9 -0
  55. package/src/Prometheus.res +3 -3
  56. package/src/Prometheus.res.mjs +4 -4
  57. package/src/ReorgDetection.res +4 -4
  58. package/src/ReorgDetection.res.mjs +4 -5
  59. package/src/SafeCheckpointTracking.res +16 -16
  60. package/src/SafeCheckpointTracking.res.mjs +2 -2
  61. package/src/SimulateItems.res +10 -14
  62. package/src/SimulateItems.res.mjs +5 -2
  63. package/src/Sink.res +1 -1
  64. package/src/Sink.res.mjs +1 -2
  65. package/src/SvmTypes.res +9 -0
  66. package/src/SvmTypes.res.mjs +14 -0
  67. package/src/TestIndexer.res +17 -57
  68. package/src/TestIndexer.res.mjs +14 -48
  69. package/src/TestIndexerProxyStorage.res +23 -23
  70. package/src/TestIndexerProxyStorage.res.mjs +12 -15
  71. package/src/Throttler.res +2 -2
  72. package/src/Time.res +2 -2
  73. package/src/Time.res.mjs +2 -2
  74. package/src/UserContext.res +19 -118
  75. package/src/UserContext.res.mjs +10 -66
  76. package/src/Utils.res +15 -15
  77. package/src/Utils.res.mjs +7 -8
  78. package/src/adapters/MarkBatchProcessedAdapter.res +5 -0
  79. package/src/adapters/MarkBatchProcessedAdapter.res.mjs +14 -0
  80. package/src/bindings/BigDecimal.res +1 -1
  81. package/src/bindings/BigDecimal.res.mjs +2 -2
  82. package/src/bindings/ClickHouse.res +8 -6
  83. package/src/bindings/ClickHouse.res.mjs +5 -5
  84. package/src/bindings/Hrtime.res +1 -1
  85. package/src/bindings/Pino.res +2 -2
  86. package/src/bindings/Pino.res.mjs +3 -4
  87. package/src/db/EntityFilter.res +410 -0
  88. package/src/db/EntityFilter.res.mjs +424 -0
  89. package/src/db/EntityHistory.res +1 -1
  90. package/src/db/EntityHistory.res.mjs +1 -1
  91. package/src/db/InternalTable.res +10 -10
  92. package/src/db/InternalTable.res.mjs +41 -45
  93. package/src/db/Schema.res +2 -2
  94. package/src/db/Schema.res.mjs +3 -3
  95. package/src/db/Table.res +106 -22
  96. package/src/db/Table.res.mjs +84 -35
  97. package/src/sources/EventRouter.res +67 -2
  98. package/src/sources/EventRouter.res.mjs +45 -3
  99. package/src/sources/Evm.res +0 -7
  100. package/src/sources/Evm.res.mjs +0 -15
  101. package/src/sources/EvmChain.res +1 -1
  102. package/src/sources/EvmChain.res.mjs +1 -2
  103. package/src/sources/EvmRpcClient.res +42 -0
  104. package/src/sources/EvmRpcClient.res.mjs +64 -0
  105. package/src/sources/Fuel.res +0 -7
  106. package/src/sources/Fuel.res.mjs +0 -15
  107. package/src/sources/HyperFuelSource.res +5 -4
  108. package/src/sources/HyperFuelSource.res.mjs +2 -2
  109. package/src/sources/HyperSyncClient.res +9 -5
  110. package/src/sources/HyperSyncClient.res.mjs +2 -2
  111. package/src/sources/HyperSyncHeightStream.res +2 -2
  112. package/src/sources/HyperSyncHeightStream.res.mjs +2 -2
  113. package/src/sources/HyperSyncSource.res +10 -9
  114. package/src/sources/HyperSyncSource.res.mjs +4 -4
  115. package/src/sources/Rpc.res +1 -5
  116. package/src/sources/Rpc.res.mjs +1 -9
  117. package/src/sources/RpcSource.res +57 -21
  118. package/src/sources/RpcSource.res.mjs +47 -20
  119. package/src/sources/RpcWebSocketHeightStream.res +1 -1
  120. package/src/sources/SourceManager.res +3 -2
  121. package/src/sources/SourceManager.res.mjs +1 -1
  122. package/src/sources/Svm.res +3 -10
  123. package/src/sources/Svm.res.mjs +4 -18
  124. package/src/sources/SvmHyperSyncClient.res +265 -0
  125. package/src/sources/SvmHyperSyncClient.res.mjs +28 -0
  126. package/src/sources/SvmHyperSyncSource.res +638 -0
  127. package/src/sources/SvmHyperSyncSource.res.mjs +557 -0
  128. package/src/tui/Tui.res +9 -2
  129. package/src/tui/Tui.res.mjs +18 -3
  130. package/src/tui/components/BufferedProgressBar.res +2 -2
  131. package/src/tui/components/TuiData.res +3 -0
  132. package/svm.schema.json +523 -14
  133. package/src/TableIndices.res +0 -115
  134. package/src/TableIndices.res.mjs +0 -144
@@ -1,5 +1,3 @@
1
- let codegenHelpMessage = `Rerun 'pnpm dev' to update generated code after schema.graphql changes.`
2
-
3
1
  type contextParams = {
4
2
  item: Internal.item,
5
3
  checkpointId: Internal.checkpointId,
@@ -77,126 +75,29 @@ type entityContextParams = {
77
75
 
78
76
  let getWhereHandler = (params: entityContextParams, filter: dict<dict<unknown>>) => {
79
77
  let entityConfig = params.entityConfig
80
- let filterKeys = filter->Dict.keysToArray
81
-
82
- if filterKeys->Array.length === 0 {
83
- JsError.throwWithMessage(
84
- `Empty filter passed to context.${entityConfig.name}.getWhere(). Please provide a filter like { fieldName: { _eq: value } }.`,
85
- )
86
- }
87
- if filterKeys->Array.length > 1 {
88
- JsError.throwWithMessage(
89
- `Multiple filter fields passed to context.${entityConfig.name}.getWhere(). Currently only one filter field per call is supported. Received fields: ${filterKeys->Array.joinUnsafe(
90
- ", ",
91
- )}.`,
92
- )
93
- }
94
-
95
- let dbFieldName = filterKeys->Array.getUnsafe(0)
96
- let operatorObj = filter->Dict.getUnsafe(dbFieldName)
97
- let operatorKeys = operatorObj->Dict.keysToArray
98
-
99
- if operatorKeys->Array.length === 0 {
100
- JsError.throwWithMessage(
101
- `Empty operator passed to context.${entityConfig.name}.getWhere({ ${dbFieldName}: {} }). Please provide an operator like { _eq: value }, { _gt: value }, { _lt: value }, { _gte: value }, { _lte: value }, or { _in: [values] }.`,
102
- )
103
- }
104
- if operatorKeys->Array.length > 1 {
105
- JsError.throwWithMessage(
106
- `Multiple operators passed to context.${entityConfig.name}.getWhere({ ${dbFieldName}: ... }). Currently only one operator per filter field is supported. Received operators: ${operatorKeys->Array.joinUnsafe(
107
- ", ",
108
- )}.`,
109
- )
110
- }
111
-
112
- let operatorKey = operatorKeys->Array.getUnsafe(0)
113
-
114
- let fieldSchema = switch entityConfig.table->Table.getFieldByDbName(dbFieldName) {
115
- | None =>
116
- JsError.throwWithMessage(
117
- `Invalid field "${dbFieldName}" in context.${entityConfig.name}.getWhere(). The field doesn't exist. ${codegenHelpMessage}`,
118
- )
119
- | Some(DerivedFrom(_)) =>
120
- JsError.throwWithMessage(
121
- `The field "${dbFieldName}" on entity "${entityConfig.name}" is a derived field and cannot be used in getWhere(). Use the source entity's indexed field instead.`,
122
- )
123
- | Some(Field({isIndex: false, linkedEntity: None})) =>
124
- JsError.throwWithMessage(
125
- `The field "${dbFieldName}" on entity "${entityConfig.name}" does not have an index. To use it in getWhere(), add the @index directive in your schema.graphql:\n\n ${dbFieldName}: ... @index\n\nThen run 'pnpm envio codegen' to regenerate.`,
126
- )
127
- | Some(Field({fieldSchema})) => fieldSchema
128
- }
129
-
130
- if operatorKey === "_in" {
131
- let fieldValues =
132
- operatorObj
133
- ->Dict.getUnsafe(operatorKey)
134
- ->(Utils.magic: unknown => array<unknown>)
135
78
 
136
- fieldValues
137
- ->Array.map(fieldValue =>
138
- LoadLayer.loadByField(
139
- ~loadManager=params.loadManager,
140
- ~persistence=params.persistence,
141
- ~operator=Eq,
142
- ~entityConfig,
143
- ~fieldName=dbFieldName,
144
- ~fieldValueSchema=fieldSchema,
145
- ~inMemoryStore=params.inMemoryStore,
146
- ~shouldGroup=params.isPreload,
147
- ~item=params.item,
148
- ~fieldValue,
149
- )
150
- )
151
- ->Promise.all
152
- ->Promise.thenResolve(results => results->Belt.Array.concatMany)
153
- } else if operatorKey === "_gte" || operatorKey === "_lte" {
154
- // _gte and _lte are composed from Eq + Gt/Lt
155
- let rangeOperator: TableIndices.Operator.t = operatorKey === "_gte" ? Gt : Lt
156
- let fieldValue = operatorObj->Dict.getUnsafe(operatorKey)
157
-
158
- let loadWithOperator = operator =>
159
- LoadLayer.loadByField(
160
- ~loadManager=params.loadManager,
161
- ~persistence=params.persistence,
162
- ~operator,
163
- ~entityConfig,
164
- ~fieldName=dbFieldName,
165
- ~fieldValueSchema=fieldSchema,
166
- ~inMemoryStore=params.inMemoryStore,
167
- ~shouldGroup=params.isPreload,
168
- ~item=params.item,
169
- ~fieldValue,
170
- )
171
-
172
- [loadWithOperator(Eq), loadWithOperator(rangeOperator)]
173
- ->Promise.all
174
- ->Promise.thenResolve(results => results->Belt.Array.concatMany)
175
- } else {
176
- let operator: TableIndices.Operator.t = switch operatorKey {
177
- | "_eq" => Eq
178
- | "_gt" => Gt
179
- | "_lt" => Lt
180
- | _ =>
181
- JsError.throwWithMessage(
182
- `Invalid operator "${operatorKey}" in context.${entityConfig.name}.getWhere({ ${dbFieldName}: { ${operatorKey}: ... } }). Valid operators are _eq, _gt, _lt, _gte, _lte, _in.`,
183
- )
184
- }
185
-
186
- let fieldValue = operatorObj->Dict.getUnsafe(operatorKey)
187
-
188
- LoadLayer.loadByField(
79
+ @inline
80
+ let loadWithFilter = filter =>
81
+ LoadLayer.loadByFilter(
189
82
  ~loadManager=params.loadManager,
190
83
  ~persistence=params.persistence,
191
- ~operator,
192
84
  ~entityConfig,
193
- ~fieldName=dbFieldName,
194
- ~fieldValueSchema=fieldSchema,
195
85
  ~inMemoryStore=params.inMemoryStore,
196
86
  ~shouldGroup=params.isPreload,
197
87
  ~item=params.item,
198
- ~fieldValue,
88
+ ~filter,
199
89
  )
90
+
91
+ switch filter->EntityFilter.parseGetWhereOrThrow(
92
+ ~entityName=entityConfig.name,
93
+ ~table=entityConfig.table,
94
+ ) {
95
+ | [single] => loadWithFilter(single)
96
+ | filters =>
97
+ filters
98
+ ->Array.map(filter => loadWithFilter(filter))
99
+ ->Promise.all
100
+ ->Promise.thenResolve(results => results->Array.flat)
200
101
  }
201
102
  }
202
103
 
@@ -285,7 +186,7 @@ let entityTraps: Utils.Proxy.traps<entityContextParams> = {
285
186
  | Some(entity) => entity
286
187
  | None =>
287
188
  JsError.throwWithMessage(
288
- message->Belt.Option.getWithDefault(
189
+ message->Option.getOr(
289
190
  `Entity '${params.entityConfig.name}' with ID '${entityId}' is expected to exist.`,
290
191
  ),
291
192
  )
@@ -389,7 +290,7 @@ let handlerTraps: Utils.Proxy.traps<contextParams> = {
389
290
  ->(Utils.magic: entityContextParams => unknown)
390
291
  | None =>
391
292
  JsError.throwWithMessage(
392
- `Invalid context access by '${prop}' property. ${codegenHelpMessage}`,
293
+ `Invalid context access by '${prop}' property. ${EntityFilter.codegenHelpMessage}`,
393
294
  )
394
295
  }
395
296
  }
@@ -458,7 +359,7 @@ let contractRegisterChainTraps: Utils.Proxy.traps<contractRegisterParams> = {
458
359
  {"add": addFn}->(Utils.magic: {"add": Address.t => unit} => unknown)
459
360
  } else {
460
361
  JsError.throwWithMessage(
461
- `Invalid contract name '${prop}' on context.chain. ${codegenHelpMessage}`,
362
+ `Invalid contract name '${prop}' on context.chain. ${EntityFilter.codegenHelpMessage}`,
462
363
  )
463
364
  }
464
365
  }
@@ -481,7 +382,7 @@ let contractRegisterTraps: Utils.Proxy.traps<contractRegisterParams> = {
481
382
  ->(Utils.magic: contractRegisterParams => unknown)
482
383
  | _ =>
483
384
  JsError.throwWithMessage(
484
- `Invalid context access by '${prop}' property. Use context.chain.ContractName.add(address) to register contracts. ${codegenHelpMessage}`,
385
+ `Invalid context access by '${prop}' property. Use context.chain.ContractName.add(address) to register contracts. ${EntityFilter.codegenHelpMessage}`,
485
386
  )
486
387
  }
487
388
  },
@@ -1,22 +1,19 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Table from "./db/Table.res.mjs";
4
3
  import * as Utils from "./Utils.res.mjs";
5
4
  import * as Address from "./Address.res.mjs";
6
5
  import * as Logging from "./Logging.res.mjs";
7
6
  import * as ChainMap from "./ChainMap.res.mjs";
8
7
  import * as Internal from "./Internal.res.mjs";
9
8
  import * as LoadLayer from "./LoadLayer.res.mjs";
10
- import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
11
- import * as Belt_Option from "@rescript/runtime/lib/es6/Belt_Option.js";
9
+ import * as EntityFilter from "./db/EntityFilter.res.mjs";
12
10
  import * as ErrorHandling from "./ErrorHandling.res.mjs";
13
11
  import * as InMemoryStore from "./InMemoryStore.res.mjs";
14
12
  import * as InMemoryTable from "./InMemoryTable.res.mjs";
13
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
15
14
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
16
15
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
17
16
 
18
- let codegenHelpMessage = `Rerun 'pnpm dev' to update generated code after schema.graphql changes.`;
19
-
20
17
  let paramsByThis = new WeakMap();
21
18
 
22
19
  let effectContextPrototype = (Object.create(null));
@@ -53,64 +50,12 @@ function initEffect(params) {
53
50
 
54
51
  function getWhereHandler(params, filter) {
55
52
  let entityConfig = params.entityConfig;
56
- let filterKeys = Object.keys(filter);
57
- if (filterKeys.length === 0) {
58
- Stdlib_JsError.throwWithMessage(`Empty filter passed to context.` + entityConfig.name + `.getWhere(). Please provide a filter like { fieldName: { _eq: value } }.`);
59
- }
60
- if (filterKeys.length > 1) {
61
- Stdlib_JsError.throwWithMessage(`Multiple filter fields passed to context.` + entityConfig.name + `.getWhere(). Currently only one filter field per call is supported. Received fields: ` + filterKeys.join(", ") + `.`);
62
- }
63
- let dbFieldName = filterKeys[0];
64
- let operatorObj = filter[dbFieldName];
65
- let operatorKeys = Object.keys(operatorObj);
66
- if (operatorKeys.length === 0) {
67
- Stdlib_JsError.throwWithMessage(`Empty operator passed to context.` + entityConfig.name + `.getWhere({ ` + dbFieldName + `: {} }). Please provide an operator like { _eq: value }, { _gt: value }, { _lt: value }, { _gte: value }, { _lte: value }, or { _in: [values] }.`);
68
- }
69
- if (operatorKeys.length > 1) {
70
- Stdlib_JsError.throwWithMessage(`Multiple operators passed to context.` + entityConfig.name + `.getWhere({ ` + dbFieldName + `: ... }). Currently only one operator per filter field is supported. Received operators: ` + operatorKeys.join(", ") + `.`);
71
- }
72
- let operatorKey = operatorKeys[0];
73
- let match = Table.getFieldByDbName(entityConfig.table, dbFieldName);
74
- let fieldSchema;
75
- if (match !== undefined) {
76
- if (match.TAG === "Field") {
77
- let match$1 = match._0;
78
- fieldSchema = match$1.isIndex || match$1.linkedEntity !== undefined ? match$1.fieldSchema : Stdlib_JsError.throwWithMessage(`The field "` + dbFieldName + `" on entity "` + entityConfig.name + `" does not have an index. To use it in getWhere(), add the @index directive in your schema.graphql:\n\n ` + dbFieldName + `: ... @index\n\nThen run 'pnpm envio codegen' to regenerate.`);
79
- } else {
80
- fieldSchema = Stdlib_JsError.throwWithMessage(`The field "` + dbFieldName + `" on entity "` + entityConfig.name + `" is a derived field and cannot be used in getWhere(). Use the source entity's indexed field instead.`);
81
- }
53
+ let filters = EntityFilter.parseGetWhereOrThrow(filter, entityConfig.name, entityConfig.table);
54
+ if (filters.length !== 1) {
55
+ return Promise.all(filters.map(filter => LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, params.inMemoryStore, params.isPreload, params.item, filter))).then(results => results.flat());
82
56
  } else {
83
- fieldSchema = Stdlib_JsError.throwWithMessage(`Invalid field "` + dbFieldName + `" in context.` + entityConfig.name + `.getWhere(). The field doesn't exist. ` + codegenHelpMessage);
84
- }
85
- if (operatorKey === "_in") {
86
- let fieldValues = operatorObj[operatorKey];
87
- return Promise.all(fieldValues.map(fieldValue => LoadLayer.loadByField(params.loadManager, params.persistence, "Eq", entityConfig, params.inMemoryStore, dbFieldName, fieldSchema, params.isPreload, params.item, fieldValue))).then(Belt_Array.concatMany);
88
- }
89
- if (operatorKey === "_gte" || operatorKey === "_lte") {
90
- let rangeOperator = operatorKey === "_gte" ? "Gt" : "Lt";
91
- let fieldValue = operatorObj[operatorKey];
92
- let loadWithOperator = operator => LoadLayer.loadByField(params.loadManager, params.persistence, operator, entityConfig, params.inMemoryStore, dbFieldName, fieldSchema, params.isPreload, params.item, fieldValue);
93
- return Promise.all([
94
- loadWithOperator("Eq"),
95
- loadWithOperator(rangeOperator)
96
- ]).then(Belt_Array.concatMany);
97
- }
98
- let operator;
99
- switch (operatorKey) {
100
- case "_eq" :
101
- operator = "Eq";
102
- break;
103
- case "_gt" :
104
- operator = "Gt";
105
- break;
106
- case "_lt" :
107
- operator = "Lt";
108
- break;
109
- default:
110
- operator = Stdlib_JsError.throwWithMessage(`Invalid operator "` + operatorKey + `" in context.` + entityConfig.name + `.getWhere({ ` + dbFieldName + `: { ` + operatorKey + `: ... } }). Valid operators are _eq, _gt, _lt, _gte, _lte, _in.`);
57
+ return LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, params.inMemoryStore, params.isPreload, params.item, filters[0]);
111
58
  }
112
- let fieldValue$1 = operatorObj[operatorKey];
113
- return LoadLayer.loadByField(params.loadManager, params.persistence, operator, entityConfig, params.inMemoryStore, dbFieldName, fieldSchema, params.isPreload, params.item, fieldValue$1);
114
59
  }
115
60
 
116
61
  function noopSet(_entity) {
@@ -171,7 +116,7 @@ let entityTraps_get = (params, prop) => {
171
116
  if (entity !== undefined) {
172
117
  return entity;
173
118
  } else {
174
- return Stdlib_JsError.throwWithMessage(Belt_Option.getWithDefault(message, `Entity '` + params.entityConfig.name + `' with ID '` + entityId + `' is expected to exist.`));
119
+ return Stdlib_JsError.throwWithMessage(Stdlib_Option.getOr(message, `Entity '` + params.entityConfig.name + `' with ID '` + entityId + `' is expected to exist.`));
175
120
  }
176
121
  });
177
122
  }
@@ -226,7 +171,7 @@ let handlerTraps_get = (params, prop) => {
226
171
  entityConfig: entityConfig
227
172
  }, entityTraps);
228
173
  } else {
229
- return Stdlib_JsError.throwWithMessage(`Invalid context access by '` + prop + `' property. ` + codegenHelpMessage);
174
+ return Stdlib_JsError.throwWithMessage(`Invalid context access by '` + prop + `' property. ` + EntityFilter.codegenHelpMessage);
230
175
  }
231
176
  }
232
177
  };
@@ -261,7 +206,7 @@ let contractRegisterChainTraps_get = (params, prop) => {
261
206
  add: makeAddFunction(params, prop)
262
207
  };
263
208
  } else {
264
- return Stdlib_JsError.throwWithMessage(`Invalid contract name '` + prop + `' on context.chain. ` + codegenHelpMessage);
209
+ return Stdlib_JsError.throwWithMessage(`Invalid contract name '` + prop + `' on context.chain. ` + EntityFilter.codegenHelpMessage);
265
210
  }
266
211
  };
267
212
 
@@ -279,7 +224,7 @@ let contractRegisterTraps_get = (params, prop) => {
279
224
  case "log" :
280
225
  return Logging.getUserLogger(params.item);
281
226
  default:
282
- return Stdlib_JsError.throwWithMessage(`Invalid context access by '` + prop + `' property. Use context.chain.ContractName.add(address) to register contracts. ` + codegenHelpMessage);
227
+ return Stdlib_JsError.throwWithMessage(`Invalid context access by '` + prop + `' property. Use context.chain.ContractName.add(address) to register contracts. ` + EntityFilter.codegenHelpMessage);
283
228
  }
284
229
  };
285
230
 
@@ -299,7 +244,6 @@ function getContractRegisterArgs(params) {
299
244
  }
300
245
 
301
246
  export {
302
- codegenHelpMessage,
303
247
  paramsByThis,
304
248
  effectContextPrototype,
305
249
  initEffect,
package/src/Utils.res CHANGED
@@ -267,18 +267,18 @@ module Array = {
267
267
 
268
268
  let rec loop = (i, j, k) => {
269
269
  if i < Array.length(xs) && j < Array.length(ys) {
270
- if f(xs->Belt.Array.getUnsafe(i), ys->Belt.Array.getUnsafe(j)) {
271
- result->Belt.Array.setUnsafe(k, xs->Belt.Array.getUnsafe(i))
270
+ if f(xs->Array.getUnsafe(i), ys->Array.getUnsafe(j)) {
271
+ result->Array.setUnsafe(k, xs->Array.getUnsafe(i))
272
272
  loop(i + 1, j, k + 1)
273
273
  } else {
274
- result->Belt.Array.setUnsafe(k, ys->Belt.Array.getUnsafe(j))
274
+ result->Array.setUnsafe(k, ys->Array.getUnsafe(j))
275
275
  loop(i, j + 1, k + 1)
276
276
  }
277
277
  } else if i < Array.length(xs) {
278
- result->Belt.Array.setUnsafe(k, xs->Belt.Array.getUnsafe(i))
278
+ result->Array.setUnsafe(k, xs->Array.getUnsafe(i))
279
279
  loop(i + 1, j, k + 1)
280
280
  } else if j < Array.length(ys) {
281
- result->Belt.Array.setUnsafe(k, ys->Belt.Array.getUnsafe(j))
281
+ result->Array.setUnsafe(k, ys->Array.getUnsafe(j))
282
282
  loop(i, j + 1, k + 1)
283
283
  }
284
284
  }
@@ -296,7 +296,7 @@ module Array = {
296
296
  Creates a shallow copy of the array and sets the value at the given index
297
297
  */
298
298
  let setIndexImmutable = (arr: array<'a>, index: int, value: 'a): array<'a> => {
299
- let shallowCopy = arr->Belt.Array.copy
299
+ let shallowCopy = arr->Array.copy
300
300
  shallowCopy->Array.setUnsafe(index, value)
301
301
  shallowCopy
302
302
  }
@@ -308,7 +308,7 @@ module Array = {
308
308
  } else {
309
309
  switch results->Array.getUnsafe(index) {
310
310
  | Ok(value) => {
311
- output->Belt.Array.setUnsafe(index, value)
311
+ output->Array.setUnsafe(index, value)
312
312
  loop(index + 1, output)
313
313
  }
314
314
  | Error(_) as err => err->(magic: result<'a, 'b> => result<array<'a>, 'b>)
@@ -316,14 +316,14 @@ module Array = {
316
316
  }
317
317
  }
318
318
 
319
- loop(0, Belt.Array.makeUninitializedUnsafe(results->Array.length))
319
+ loop(0, jsArrayCreate(results->Array.length))
320
320
  }
321
321
 
322
322
  /**
323
323
  Helper to check if a value exists in an array
324
324
  */
325
325
  let includes = (arr: array<'a>, val: 'a) =>
326
- arr->Array.find(item => item == val)->Belt.Option.isSome
326
+ arr->Array.find(item => item == val)->Stdlib.Option.isSome
327
327
 
328
328
  let isEmpty = (arr: array<_>) =>
329
329
  switch arr {
@@ -339,7 +339,7 @@ Helper to check if a value exists in an array
339
339
 
340
340
  let awaitEach = async (arr: array<'a>, fn: 'a => promise<unit>) => {
341
341
  for i in 0 to arr->Array.length - 1 {
342
- let item = arr->Belt.Array.getUnsafe(i)
342
+ let item = arr->Array.getUnsafe(i)
343
343
  await item->fn
344
344
  }
345
345
  }
@@ -357,10 +357,10 @@ Helper to check if a value exists in an array
357
357
  }
358
358
  }
359
359
 
360
- let last = (arr: array<'a>): option<'a> => arr->Belt.Array.get(arr->Array.length - 1)
361
- let first = (arr: array<'a>): option<'a> => arr->Belt.Array.get(0)
360
+ let last = (arr: array<'a>): option<'a> => arr->Array.get(arr->Array.length - 1)
361
+ let first = (arr: array<'a>): option<'a> => arr->Array.get(0)
362
362
 
363
- let lastUnsafe = (arr: array<'a>): 'a => arr->Belt.Array.getUnsafe(arr->Array.length - 1)
363
+ let lastUnsafe = (arr: array<'a>): 'a => arr->Array.getUnsafe(arr->Array.length - 1)
364
364
  let firstUnsafe = (arr: array<'a>): 'a => arr->Array.getUnsafe(0)
365
365
 
366
366
  let findReverseWithIndex = (arr: array<'a>, fn: 'a => bool): option<('a, int)> => {
@@ -368,7 +368,7 @@ Helper to check if a value exists in an array
368
368
  if index < 0 {
369
369
  None
370
370
  } else {
371
- let item = arr->Belt.Array.getUnsafe(index)
371
+ let item = arr->Array.getUnsafe(index)
372
372
  if fn(item) {
373
373
  Some((item, index))
374
374
  } else {
@@ -455,7 +455,7 @@ module Url = {
455
455
  let regex = /https?:\/\/([^\/?]+).*/
456
456
  switch RegExp.exec(regex, url) {
457
457
  | Some(result) =>
458
- switch RegExp.Result.matches(result)->Belt.Array.get(0) {
458
+ switch RegExp.Result.matches(result)->Array.get(0) {
459
459
  | Some(Some(host)) => Some(host)
460
460
  | Some(None) | None => None
461
461
  }
package/src/Utils.res.mjs CHANGED
@@ -1,11 +1,10 @@
1
1
  import packageJson from '../package.json' with { type: 'json' }
2
2
  // Generated by ReScript, PLEASE EDIT WITH CARE
3
3
 
4
- import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
5
- import * as Belt_Option from "@rescript/runtime/lib/es6/Belt_Option.js";
6
4
  import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
7
5
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
8
6
  import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.js";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
9
8
  import * as Stdlib_String from "@rescript/runtime/lib/es6/Stdlib_String.js";
10
9
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
11
10
  import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
@@ -260,14 +259,14 @@ let clearInPlace = ((arr) => {
260
259
  });
261
260
 
262
261
  function setIndexImmutable(arr, index, value) {
263
- let shallowCopy = arr.slice(0);
262
+ let shallowCopy = arr.slice();
264
263
  shallowCopy[index] = value;
265
264
  return shallowCopy;
266
265
  }
267
266
 
268
267
  function transposeResults(results) {
269
268
  let _index = 0;
270
- let output = new Array(results.length);
269
+ let output = Array(results.length);
271
270
  while (true) {
272
271
  let index = _index;
273
272
  if (index >= results.length) {
@@ -287,7 +286,7 @@ function transposeResults(results) {
287
286
  }
288
287
 
289
288
  function includes(arr, val) {
290
- return Belt_Option.isSome(arr.find(item => Primitive_object.equal(item, val)));
289
+ return Stdlib_Option.isSome(arr.find(item => Primitive_object.equal(item, val)));
291
290
  }
292
291
 
293
292
  function isEmpty$1(arr) {
@@ -314,11 +313,11 @@ function removeAtIndex(array, index) {
314
313
  }
315
314
 
316
315
  function last(arr) {
317
- return Belt_Array.get(arr, arr.length - 1 | 0);
316
+ return arr[arr.length - 1 | 0];
318
317
  }
319
318
 
320
319
  function first(arr) {
321
- return Belt_Array.get(arr, 0);
320
+ return arr[0];
322
321
  }
323
322
 
324
323
  function lastUnsafe(arr) {
@@ -429,7 +428,7 @@ function getHostFromUrl(url) {
429
428
  if (result == null) {
430
429
  return;
431
430
  }
432
- let match = Belt_Array.get(result.slice(1), 0);
431
+ let match = result.slice(1)[0];
433
432
  if (match === undefined) {
434
433
  return;
435
434
  }
@@ -0,0 +1,5 @@
1
+ let make = (~inMemoryStore: InMemoryStore.t): Ports.MarkBatchProcessed.t =>
2
+ () => {
3
+ inMemoryStore.isProcessing = false
4
+ inMemoryStore.processedBatchesCount = inMemoryStore.processedBatchesCount + 1
5
+ }
@@ -0,0 +1,14 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+
4
+ function make(inMemoryStore) {
5
+ return () => {
6
+ inMemoryStore.isProcessing = false;
7
+ inMemoryStore.processedBatchesCount = inMemoryStore.processedBatchesCount + 1 | 0;
8
+ };
9
+ }
10
+
11
+ export {
12
+ make,
13
+ }
14
+ /* No side effect */
@@ -22,7 +22,7 @@ type rec t = {
22
22
  // Methods
23
23
  @send external toString: t => string = "toString"
24
24
  @send external toFixed: t => string = "toFixed"
25
- let toInt = (b: t): option<int> => b->toString->Belt.Int.fromString
25
+ let toInt = (b: t): option<int> => b->toString->Int.fromString
26
26
  @send external toNumber: t => float = "toNumber"
27
27
 
28
28
  // Arithmetic Operations
@@ -1,11 +1,11 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Belt_Int from "@rescript/runtime/lib/es6/Belt_Int.js";
3
+ import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
4
4
  import BignumberJs from "bignumber.js";
5
5
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
6
6
 
7
7
  function toInt(b) {
8
- return Belt_Int.fromString(b.toString());
8
+ return Stdlib_Int.fromString(b.toString(), undefined);
9
9
  }
10
10
 
11
11
  function notEquals(a, b) {
@@ -103,14 +103,16 @@ let getClickHouseFieldType = (
103
103
  isNullable ? `Nullable(${baseType})` : baseType
104
104
  }
105
105
 
106
- // Creates an entity schema from table definition, using clickHouseDate for Date fields
106
+ // Creates an entity schema from table definition, using clickHouseDate for Date fields.
107
+ // Serialized keys are the db column names, while the entity values are keyed
108
+ // by API field names (they only differ when column renaming is configured).
107
109
  let makeClickHouseEntitySchema = (table: Table.table): S.t<Internal.entity> => {
108
- S.schema(s => {
110
+ S.object(s => {
109
111
  let dict = Dict.make()
110
112
  table.fields->Array.forEach(field => {
111
113
  switch field {
112
114
  | Field(f) => {
113
- let fieldName = f->Table.getDbFieldName
115
+ let fieldName = f->Table.getClickHouseDbFieldName
114
116
  let fieldSchema = switch f.fieldType {
115
117
  | Date => {
116
118
  let dateSchema = Utils.Schema.clickHouseDate->S.toUnknown
@@ -142,7 +144,7 @@ let makeClickHouseEntitySchema = (table: Table.table): S.t<Internal.entity> => {
142
144
  }
143
145
  | _ => f.fieldSchema
144
146
  }
145
- dict->Dict.set(fieldName, s.matches(fieldSchema))
147
+ dict->Dict.set(f->Table.getApiFieldName, s.field(fieldName, fieldSchema))
146
148
  }
147
149
  | DerivedFrom(_) => () // Skip derived fields
148
150
  }
@@ -316,7 +318,7 @@ let makeCreateHistoryTableQuery = (
316
318
  switch field {
317
319
  | Field(field) =>
318
320
  Some({
319
- let fieldName = field->Table.getDbFieldName
321
+ let fieldName = field->Table.getClickHouseDbFieldName
320
322
  let clickHouseType = getClickHouseFieldType(
321
323
  ~fieldType=field.fieldType,
322
324
  ~isNullable=field.isNullable,
@@ -399,7 +401,7 @@ let makeCreateViewQuery = (~entityConfig: Internal.entityConfig, ~database: stri
399
401
  ->Array.filterMap(field => {
400
402
  switch field {
401
403
  | Field(field) => {
402
- let fieldName = field->Table.getDbFieldName
404
+ let fieldName = field->Table.getClickHouseDbFieldName
403
405
  Some(`\`${fieldName}\``)
404
406
  }
405
407
  | DerivedFrom(_) => None
@@ -82,14 +82,14 @@ function getClickHouseFieldType(fieldType, isNullable, isArray) {
82
82
  }
83
83
 
84
84
  function makeClickHouseEntitySchema(table) {
85
- return S$RescriptSchema.schema(s => {
85
+ return S$RescriptSchema.object(s => {
86
86
  let dict = {};
87
87
  table.fields.forEach(field => {
88
88
  if (field.TAG !== "Field") {
89
89
  return;
90
90
  }
91
91
  let f = field._0;
92
- let fieldName = Table.getDbFieldName(f);
92
+ let fieldName = Table.getClickHouseDbFieldName(f);
93
93
  let match = f.fieldType;
94
94
  let fieldSchema;
95
95
  if (typeof match !== "object") {
@@ -114,7 +114,7 @@ function makeClickHouseEntitySchema(table) {
114
114
  } else {
115
115
  fieldSchema = f.fieldSchema;
116
116
  }
117
- dict[fieldName] = s.m(fieldSchema);
117
+ dict[Table.getApiFieldName(f)] = s.f(fieldName, fieldSchema);
118
118
  });
119
119
  return dict;
120
120
  });
@@ -243,7 +243,7 @@ function makeCreateHistoryTableQuery(entityConfig, database, replicatedOpt) {
243
243
  return;
244
244
  }
245
245
  let field$1 = field._0;
246
- let fieldName = Table.getDbFieldName(field$1);
246
+ let fieldName = Table.getClickHouseDbFieldName(field$1);
247
247
  let clickHouseType = getClickHouseFieldType(field$1.fieldType, field$1.isNullable, field$1.isArray);
248
248
  return `\`` + fieldName + `\` ` + clickHouseType;
249
249
  });
@@ -280,7 +280,7 @@ function makeCreateViewQuery(entityConfig, database) {
280
280
  if (field.TAG !== "Field") {
281
281
  return;
282
282
  }
283
- let fieldName = Table.getDbFieldName(field._0);
283
+ let fieldName = Table.getClickHouseDbFieldName(field._0);
284
284
  return `\`` + fieldName + `\``;
285
285
  }).join(", ");
286
286
  return `CREATE VIEW IF NOT EXISTS ` + database + `.\`` + entityConfig.name + `\` AS
@@ -42,7 +42,7 @@ let toSecondsFloat = (elapsed: timeElapsed): float => {
42
42
  elapsed->toSeconds->(Utils.magic: seconds => float)
43
43
  }
44
44
 
45
- let toInt = float => float->Belt.Int.fromFloat
45
+ let toInt = float => float->Int.fromFloat
46
46
  let intFromMillis = toInt
47
47
  let intFromNanos = toInt
48
48
  let intFromSeconds = toInt
@@ -160,13 +160,13 @@ module MultiStreamLogger = {
160
160
  stream: {write: v => formatter(v)->Console.log},
161
161
  level: userLogLevel,
162
162
  }
163
- let maybeFileStream = logFile->Belt.Option.mapWithDefault([], dest => [
163
+ let maybeFileStream = logFile->Option.mapOr([], dest => [
164
164
  {
165
165
  level: defaultFileLogLevel,
166
166
  stream: destination({dest, sync: false, mkdir: true}),
167
167
  },
168
168
  ])
169
- [stream]->Belt.Array.concat(maybeFileStream)
169
+ [stream]->Array.concat(maybeFileStream)
170
170
  }
171
171
 
172
172
  let make = (