envio 2.26.0-alpha.8 → 2.26.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/evm.schema.json +0 -7
- package/fuel.schema.json +0 -7
- package/index.d.ts +22 -6
- package/index.js +1 -2
- package/package.json +5 -5
- package/src/Envio.gen.ts +1 -3
- package/src/Envio.res +0 -13
- package/src/Envio.res.js +0 -9
- package/src/FetchState.res +4 -1
- package/src/Internal.res +0 -3
- package/src/Logging.res +0 -8
- package/src/Logging.res.js +0 -29
- package/src/Persistence.res +47 -110
- package/src/Persistence.res.js +17 -61
- package/src/PgStorage.res +86 -519
- package/src/PgStorage.res.js +57 -386
- package/src/Prometheus.res +0 -12
- package/src/Prometheus.res.js +0 -12
- package/src/Utils.res +9 -39
- package/src/Utils.res.js +6 -17
- package/src/bindings/BigInt.res +0 -1
- package/src/bindings/NodeJs.res +26 -27
- package/src/bindings/NodeJs.res.js +13 -5
- package/src/db/EntityHistory.res +28 -5
- package/src/db/EntityHistory.res.js +23 -4
- package/src/db/Table.res +61 -3
- package/src/db/Table.res.js +42 -3
- package/src/bindings/BigInt.gen.ts +0 -10
package/evm.schema.json
CHANGED
|
@@ -33,13 +33,6 @@
|
|
|
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
|
-
},
|
|
43
36
|
"contracts": {
|
|
44
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.",
|
|
45
38
|
"type": [
|
package/fuel.schema.json
CHANGED
|
@@ -26,13 +26,6 @@
|
|
|
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
|
-
},
|
|
36
29
|
"contracts": {
|
|
37
30
|
"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
31
|
"type": [
|
package/index.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ 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";
|
|
17
16
|
import * as Sury from "rescript-schema";
|
|
18
17
|
|
|
19
18
|
type UnknownToOutput<T> = T extends Sury.Schema<unknown>
|
|
@@ -36,6 +35,26 @@ type UnknownToOutput<T> = T extends Sury.Schema<unknown>
|
|
|
36
35
|
>
|
|
37
36
|
: T;
|
|
38
37
|
|
|
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
|
+
|
|
39
58
|
type HasUndefined<T> = [T] extends [undefined]
|
|
40
59
|
? true
|
|
41
60
|
: undefined extends T
|
|
@@ -73,7 +92,7 @@ type Flatten<T> = T extends object
|
|
|
73
92
|
export function experimental_createEffect<
|
|
74
93
|
IS,
|
|
75
94
|
OS,
|
|
76
|
-
I =
|
|
95
|
+
I = UnknownToInput<IS>,
|
|
77
96
|
O = UnknownToOutput<OS>,
|
|
78
97
|
// A hack to enforce that the inferred return type
|
|
79
98
|
// matches the output schema type
|
|
@@ -86,8 +105,6 @@ export function experimental_createEffect<
|
|
|
86
105
|
readonly input: IS;
|
|
87
106
|
/** The output schema of the effect. */
|
|
88
107
|
readonly output: OS;
|
|
89
|
-
/** Whether the effect should be cached. */
|
|
90
|
-
readonly cache?: boolean;
|
|
91
108
|
},
|
|
92
109
|
handler: (args: EffectArgs<I>) => Promise<R>
|
|
93
110
|
): Effect<I, O>;
|
|
@@ -102,7 +119,7 @@ export declare namespace S {
|
|
|
102
119
|
export const boolean: typeof Sury.boolean;
|
|
103
120
|
export const int32: typeof Sury.int32;
|
|
104
121
|
export const number: typeof Sury.number;
|
|
105
|
-
export const bigint: typeof
|
|
122
|
+
export const bigint: typeof Sury.bigint;
|
|
106
123
|
export const never: typeof Sury.never;
|
|
107
124
|
export const union: typeof Sury.union;
|
|
108
125
|
export const object: typeof Sury.object;
|
|
@@ -111,7 +128,6 @@ export declare namespace S {
|
|
|
111
128
|
// Don't expose recursive for now, since it's too advanced
|
|
112
129
|
// export const recursive: typeof Sury.recursive;
|
|
113
130
|
export const transform: typeof Sury.transform;
|
|
114
|
-
export const shape: typeof Sury.shape;
|
|
115
131
|
export const refine: typeof Sury.refine;
|
|
116
132
|
export const schema: typeof Sury.schema;
|
|
117
133
|
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:
|
|
16
|
+
bigint: Sury.bigint,
|
|
17
17
|
never: Sury.never,
|
|
18
18
|
union: Sury.union,
|
|
19
19
|
object: Sury.object,
|
|
@@ -22,7 +22,6 @@ 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,
|
|
26
25
|
refine: Sury.refine,
|
|
27
26
|
schema: Sury.schema,
|
|
28
27
|
record: Sury.record,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "v2.26.0-
|
|
3
|
+
"version": "v2.26.0-rc.0",
|
|
4
4
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
5
5
|
"bin": "./bin.js",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://envio.dev",
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"envio-linux-x64": "v2.26.0-
|
|
29
|
-
"envio-linux-arm64": "v2.26.0-
|
|
30
|
-
"envio-darwin-x64": "v2.26.0-
|
|
31
|
-
"envio-darwin-arm64": "v2.26.0-
|
|
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"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@envio-dev/hypersync-client": "0.6.5",
|
package/src/Envio.gen.ts
CHANGED
|
@@ -21,9 +21,7 @@ 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
|
|
25
|
-
/** Whether the effect should be cached. */
|
|
26
|
-
readonly cache?: boolean
|
|
24
|
+
readonly output: RescriptSchema_S_t<output>
|
|
27
25
|
};
|
|
28
26
|
|
|
29
27
|
export type effectContext = $$effectContext;
|
package/src/Envio.res
CHANGED
|
@@ -22,8 +22,6 @@ 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,
|
|
27
25
|
}
|
|
28
26
|
@genType.import(("./Types.ts", "EffectContext"))
|
|
29
27
|
and effectContext = {
|
|
@@ -50,16 +48,5 @@ let experimental_createEffect = (
|
|
|
50
48
|
>
|
|
51
49
|
),
|
|
52
50
|
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),
|
|
64
51
|
}->(Utils.magic: Internal.effect => effect<'input, 'output>)
|
|
65
52
|
}
|
package/src/Envio.res.js
CHANGED
|
@@ -2,21 +2,12 @@
|
|
|
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");
|
|
7
5
|
|
|
8
6
|
function experimental_createEffect(options, handler) {
|
|
9
7
|
Prometheus.EffectCallsCount.set(0, options.name);
|
|
10
8
|
return {
|
|
11
9
|
name: options.name,
|
|
12
10
|
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
|
-
}),
|
|
20
11
|
callsCount: 0
|
|
21
12
|
};
|
|
22
13
|
}
|
package/src/FetchState.res
CHANGED
|
@@ -901,7 +901,10 @@ let queueItemIsInReorgThreshold = (
|
|
|
901
901
|
if currentBlockHeight === 0 {
|
|
902
902
|
false
|
|
903
903
|
} else {
|
|
904
|
-
queueItem
|
|
904
|
+
switch queueItem {
|
|
905
|
+
| Item(_) => queueItem->queueItemBlockNumber > highestBlockBelowThreshold
|
|
906
|
+
| NoItem(_) => queueItem->queueItemBlockNumber > highestBlockBelowThreshold
|
|
907
|
+
}
|
|
905
908
|
}
|
|
906
909
|
}
|
|
907
910
|
|
package/src/Internal.res
CHANGED
package/src/Logging.res
CHANGED
|
@@ -168,14 +168,6 @@ 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
|
-
|
|
179
171
|
let getUserLogger = (eventItem): Envio.logger => {
|
|
180
172
|
info: (message: string, ~params=?) => eventItem->logForItem(#uinfo, message, ~params?),
|
|
181
173
|
debug: (message: string, ~params=?) => eventItem->logForItem(#udebug, message, ~params?),
|
package/src/Logging.res.js
CHANGED
|
@@ -197,34 +197,6 @@ 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
|
-
|
|
228
200
|
function getUserLogger(eventItem) {
|
|
229
201
|
return {
|
|
230
202
|
debug: (function (message, params) {
|
|
@@ -271,6 +243,5 @@ exports.createChild = createChild;
|
|
|
271
243
|
exports.createChildFrom = createChildFrom;
|
|
272
244
|
exports.getEventLogger = getEventLogger;
|
|
273
245
|
exports.logForItem = logForItem;
|
|
274
|
-
exports.noopLogger = noopLogger;
|
|
275
246
|
exports.getUserLogger = getUserLogger;
|
|
276
247
|
/* logLevels Not a pure module */
|
package/src/Persistence.res
CHANGED
|
@@ -5,16 +5,6 @@
|
|
|
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
|
-
|
|
18
8
|
type storage = {
|
|
19
9
|
// Should return true if we already have persisted data
|
|
20
10
|
// and we can skip initialization
|
|
@@ -25,6 +15,8 @@ type storage = {
|
|
|
25
15
|
~entities: array<Internal.entityConfig>=?,
|
|
26
16
|
~generalTables: array<Table.table>=?,
|
|
27
17
|
~enums: array<Internal.enumConfig<Internal.enum>>=?,
|
|
18
|
+
// If true, the storage should clear existing data
|
|
19
|
+
~cleanRun: bool=?,
|
|
28
20
|
) => promise<unit>,
|
|
29
21
|
@raises("StorageError")
|
|
30
22
|
loadByIdsOrThrow: 'item. (
|
|
@@ -33,30 +25,11 @@ type storage = {
|
|
|
33
25
|
~rowsSchema: S.t<array<'item>>,
|
|
34
26
|
) => promise<array<'item>>,
|
|
35
27
|
@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")
|
|
45
28
|
setOrThrow: 'item. (
|
|
46
29
|
~items: array<'item>,
|
|
47
30
|
~table: Table.table,
|
|
48
31
|
~itemSchema: S.t<'item>,
|
|
49
32
|
) => 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>>,
|
|
60
33
|
}
|
|
61
34
|
|
|
62
35
|
exception StorageError({message: string, reason: exn})
|
|
@@ -64,7 +37,7 @@ exception StorageError({message: string, reason: exn})
|
|
|
64
37
|
type storageStatus =
|
|
65
38
|
| Unknown
|
|
66
39
|
| Initializing(promise<unit>)
|
|
67
|
-
| Ready({cleanRun: bool
|
|
40
|
+
| Ready({cleanRun: bool})
|
|
68
41
|
|
|
69
42
|
type t = {
|
|
70
43
|
userEntities: array<Internal.entityConfig>,
|
|
@@ -73,6 +46,8 @@ type t = {
|
|
|
73
46
|
allEnums: array<Internal.enumConfig<Internal.enum>>,
|
|
74
47
|
mutable storageStatus: storageStatus,
|
|
75
48
|
storage: storage,
|
|
49
|
+
onStorageInitialize: option<unit => promise<unit>>,
|
|
50
|
+
cacheStorage: storage,
|
|
76
51
|
}
|
|
77
52
|
|
|
78
53
|
let entityHistoryActionEnumConfig: Internal.enumConfig<EntityHistory.RowAction.t> = {
|
|
@@ -89,6 +64,8 @@ let make = (
|
|
|
89
64
|
~allEnums,
|
|
90
65
|
~staticTables,
|
|
91
66
|
~storage,
|
|
67
|
+
~cacheStorage,
|
|
68
|
+
~onStorageInitialize=?,
|
|
92
69
|
) => {
|
|
93
70
|
let allEntities = userEntities->Js.Array2.concat([dcRegistryEntityConfig])
|
|
94
71
|
let allEnums =
|
|
@@ -100,70 +77,53 @@ let make = (
|
|
|
100
77
|
allEnums,
|
|
101
78
|
storageStatus: Unknown,
|
|
102
79
|
storage,
|
|
80
|
+
onStorageInitialize,
|
|
81
|
+
cacheStorage,
|
|
103
82
|
}
|
|
104
83
|
}
|
|
105
84
|
|
|
106
|
-
let init =
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
| Unknown => true
|
|
121
|
-
| Initializing(promise) => {
|
|
122
|
-
await promise
|
|
123
|
-
reset
|
|
124
|
-
}
|
|
125
|
-
| Ready(_) => reset
|
|
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
|
|
126
99
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
})
|
|
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 => ()
|
|
160
121
|
}
|
|
161
|
-
resolveRef.contents()
|
|
162
122
|
}
|
|
163
|
-
|
|
164
|
-
| exn =>
|
|
165
|
-
exn->ErrorHandling.mkLogAndRaise(~msg=`EE800: Failed to initialize the indexer storage.`)
|
|
123
|
+
resolveRef.contents()
|
|
166
124
|
}
|
|
125
|
+
} catch {
|
|
126
|
+
| exn => exn->ErrorHandling.mkLogAndRaise(~msg=`EE800: Failed to initialize the indexer storage.`)
|
|
167
127
|
}
|
|
168
128
|
}
|
|
169
129
|
|
|
@@ -175,26 +135,3 @@ let getInitializedStorageOrThrow = persistence => {
|
|
|
175
135
|
| Ready(_) => persistence.storage
|
|
176
136
|
}
|
|
177
137
|
}
|
|
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
|
-
}
|
package/src/Persistence.res.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
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");
|
|
7
5
|
var EntityHistory = require("./db/EntityHistory.res.js");
|
|
8
6
|
var ErrorHandling = require("./ErrorHandling.res.js");
|
|
9
7
|
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
@@ -24,7 +22,7 @@ var entityHistoryActionEnumConfig = {
|
|
|
24
22
|
default: "SET"
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, storage) {
|
|
25
|
+
function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, storage, cacheStorage, onStorageInitialize) {
|
|
28
26
|
var allEntities = userEntities.concat([dcRegistryEntityConfig]);
|
|
29
27
|
var allEnums$1 = allEnums.concat([entityHistoryActionEnumConfig]);
|
|
30
28
|
return {
|
|
@@ -33,21 +31,14 @@ function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, stor
|
|
|
33
31
|
allEntities: allEntities,
|
|
34
32
|
allEnums: allEnums$1,
|
|
35
33
|
storageStatus: "Unknown",
|
|
36
|
-
storage: storage
|
|
34
|
+
storage: storage,
|
|
35
|
+
onStorageInitialize: onStorageInitialize,
|
|
36
|
+
cacheStorage: cacheStorage
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async function
|
|
41
|
-
var
|
|
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) {
|
|
40
|
+
async function init(persistence, skipIsInitializedCheckOpt, resetOpt) {
|
|
41
|
+
var skipIsInitializedCheck = skipIsInitializedCheckOpt !== undefined ? skipIsInitializedCheckOpt : false;
|
|
51
42
|
var reset = resetOpt !== undefined ? resetOpt : false;
|
|
52
43
|
try {
|
|
53
44
|
var promise = persistence.storageStatus;
|
|
@@ -73,26 +64,20 @@ async function init(persistence, resetOpt) {
|
|
|
73
64
|
TAG: "Initializing",
|
|
74
65
|
_0: promise$1
|
|
75
66
|
};
|
|
76
|
-
if (reset ||
|
|
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...");
|
|
67
|
+
if (!(reset || skipIsInitializedCheck) && await persistence.storage.isInitialized()) {
|
|
80
68
|
persistence.storageStatus = {
|
|
81
69
|
TAG: "Ready",
|
|
82
|
-
cleanRun:
|
|
83
|
-
cache: await loadInitialCache(persistence, true)
|
|
70
|
+
cleanRun: false
|
|
84
71
|
};
|
|
85
72
|
} else {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
cache: await loadInitialCache(persistence, false)
|
|
95
|
-
};
|
|
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();
|
|
96
81
|
}
|
|
97
82
|
|
|
98
83
|
}
|
|
@@ -113,38 +98,9 @@ function getInitializedStorageOrThrow(persistence) {
|
|
|
113
98
|
}
|
|
114
99
|
}
|
|
115
100
|
|
|
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
|
-
|
|
144
101
|
exports.StorageError = StorageError;
|
|
145
102
|
exports.entityHistoryActionEnumConfig = entityHistoryActionEnumConfig;
|
|
146
103
|
exports.make = make;
|
|
147
104
|
exports.init = init;
|
|
148
105
|
exports.getInitializedStorageOrThrow = getInitializedStorageOrThrow;
|
|
149
|
-
|
|
150
|
-
/* Logging Not a pure module */
|
|
106
|
+
/* EntityHistory Not a pure module */
|