envio 2.26.0-alpha.7 → 2.26.0-alpha.9
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/index.d.ts +21 -2
- package/index.js +0 -1
- package/package.json +5 -5
- package/src/Envio.res +0 -10
- package/src/Envio.res.js +0 -7
- package/src/Internal.res +0 -2
- package/src/Persistence.res +58 -94
- package/src/Persistence.res.js +15 -49
- package/src/PgStorage.res +26 -329
- package/src/PgStorage.res.js +20 -250
- package/src/Prometheus.res +0 -12
- package/src/Prometheus.res.js +0 -12
- package/src/Utils.res +9 -22
- package/src/Utils.res.js +6 -17
- package/src/bindings/Express.res +1 -1
- package/src/bindings/NodeJs.res +26 -27
- package/src/bindings/NodeJs.res.js +13 -5
package/index.d.ts
CHANGED
|
@@ -35,6 +35,26 @@ type UnknownToOutput<T> = T extends Sury.Schema<unknown>
|
|
|
35
35
|
>
|
|
36
36
|
: T;
|
|
37
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
|
+
|
|
38
58
|
type HasUndefined<T> = [T] extends [undefined]
|
|
39
59
|
? true
|
|
40
60
|
: undefined extends T
|
|
@@ -72,7 +92,7 @@ type Flatten<T> = T extends object
|
|
|
72
92
|
export function experimental_createEffect<
|
|
73
93
|
IS,
|
|
74
94
|
OS,
|
|
75
|
-
I =
|
|
95
|
+
I = UnknownToInput<IS>,
|
|
76
96
|
O = UnknownToOutput<OS>,
|
|
77
97
|
// A hack to enforce that the inferred return type
|
|
78
98
|
// matches the output schema type
|
|
@@ -110,7 +130,6 @@ export declare namespace S {
|
|
|
110
130
|
// Don't expose recursive for now, since it's too advanced
|
|
111
131
|
// export const recursive: typeof Sury.recursive;
|
|
112
132
|
export const transform: typeof Sury.transform;
|
|
113
|
-
export const shape: typeof Sury.shape;
|
|
114
133
|
export const refine: typeof Sury.refine;
|
|
115
134
|
export const schema: typeof Sury.schema;
|
|
116
135
|
export const record: typeof Sury.record;
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "v2.26.0-alpha.
|
|
3
|
+
"version": "v2.26.0-alpha.9",
|
|
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-alpha.
|
|
29
|
-
"envio-linux-arm64": "v2.26.0-alpha.
|
|
30
|
-
"envio-darwin-x64": "v2.26.0-alpha.
|
|
31
|
-
"envio-darwin-arm64": "v2.26.0-alpha.
|
|
28
|
+
"envio-linux-x64": "v2.26.0-alpha.9",
|
|
29
|
+
"envio-linux-arm64": "v2.26.0-alpha.9",
|
|
30
|
+
"envio-darwin-x64": "v2.26.0-alpha.9",
|
|
31
|
+
"envio-darwin-arm64": "v2.26.0-alpha.9"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@envio-dev/hypersync-client": "0.6.5",
|
package/src/Envio.res
CHANGED
|
@@ -50,16 +50,6 @@ let experimental_createEffect = (
|
|
|
50
50
|
>
|
|
51
51
|
),
|
|
52
52
|
callsCount: 0,
|
|
53
|
-
// This is the way to make the createEffect API
|
|
54
|
-
// work without the need for users to call S.schema themselves,
|
|
55
|
-
// but simply pass the desired object/tuple/etc.
|
|
56
|
-
// If they pass a schem, it'll also work.
|
|
57
|
-
input: S.schema(_ => options.input)->(
|
|
58
|
-
Utils.magic: S.t<S.t<'input>> => S.t<Internal.effectInput>
|
|
59
|
-
),
|
|
60
|
-
output: S.schema(_ => options.output)->(
|
|
61
|
-
Utils.magic: S.t<S.t<'output>> => S.t<Internal.effectOutput>
|
|
62
|
-
),
|
|
63
53
|
cache: options.cache->Belt.Option.getWithDefault(false),
|
|
64
54
|
}->(Utils.magic: Internal.effect => effect<'input, 'output>)
|
|
65
55
|
}
|
package/src/Envio.res.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
var Prometheus = require("./Prometheus.res.js");
|
|
5
5
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
6
|
-
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
7
6
|
|
|
8
7
|
function experimental_createEffect(options, handler) {
|
|
9
8
|
Prometheus.EffectCallsCount.set(0, options.name);
|
|
@@ -11,12 +10,6 @@ function experimental_createEffect(options, handler) {
|
|
|
11
10
|
name: options.name,
|
|
12
11
|
handler: handler,
|
|
13
12
|
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
13
|
callsCount: 0
|
|
21
14
|
};
|
|
22
15
|
}
|
package/src/Internal.res
CHANGED
package/src/Persistence.res
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
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
|
|
8
|
+
// The type reflects an effect cache table in the db
|
|
9
9
|
// It might be present even if the effect is not used in the application
|
|
10
|
-
type
|
|
11
|
-
|
|
10
|
+
type effectCache = {
|
|
11
|
+
name: string,
|
|
12
12
|
// Number of rows in the table
|
|
13
|
-
mutable
|
|
13
|
+
mutable size: int,
|
|
14
|
+
// Lazily attached table definition when effect is used in the application
|
|
15
|
+
mutable table: option<Table.table>,
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
type operator = [#">" | #"="]
|
|
@@ -26,6 +28,7 @@ type storage = {
|
|
|
26
28
|
~generalTables: array<Table.table>=?,
|
|
27
29
|
~enums: array<Internal.enumConfig<Internal.enum>>=?,
|
|
28
30
|
) => promise<unit>,
|
|
31
|
+
loadEffectCaches: unit => promise<array<effectCache>>,
|
|
29
32
|
@raises("StorageError")
|
|
30
33
|
loadByIdsOrThrow: 'item. (
|
|
31
34
|
~ids: array<string>,
|
|
@@ -47,16 +50,6 @@ type storage = {
|
|
|
47
50
|
~table: Table.table,
|
|
48
51
|
~itemSchema: S.t<'item>,
|
|
49
52
|
) => 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
53
|
}
|
|
61
54
|
|
|
62
55
|
exception StorageError({message: string, reason: exn})
|
|
@@ -64,7 +57,7 @@ exception StorageError({message: string, reason: exn})
|
|
|
64
57
|
type storageStatus =
|
|
65
58
|
| Unknown
|
|
66
59
|
| Initializing(promise<unit>)
|
|
67
|
-
| Ready({cleanRun: bool,
|
|
60
|
+
| Ready({cleanRun: bool, effectCaches: dict<effectCache>})
|
|
68
61
|
|
|
69
62
|
type t = {
|
|
70
63
|
userEntities: array<Internal.entityConfig>,
|
|
@@ -73,6 +66,7 @@ type t = {
|
|
|
73
66
|
allEnums: array<Internal.enumConfig<Internal.enum>>,
|
|
74
67
|
mutable storageStatus: storageStatus,
|
|
75
68
|
storage: storage,
|
|
69
|
+
onStorageInitialize: option<unit => promise<unit>>,
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
let entityHistoryActionEnumConfig: Internal.enumConfig<EntityHistory.RowAction.t> = {
|
|
@@ -89,6 +83,7 @@ let make = (
|
|
|
89
83
|
~allEnums,
|
|
90
84
|
~staticTables,
|
|
91
85
|
~storage,
|
|
86
|
+
~onStorageInitialize=?,
|
|
92
87
|
) => {
|
|
93
88
|
let allEntities = userEntities->Js.Array2.concat([dcRegistryEntityConfig])
|
|
94
89
|
let allEnums =
|
|
@@ -100,70 +95,62 @@ let make = (
|
|
|
100
95
|
allEnums,
|
|
101
96
|
storageStatus: Unknown,
|
|
102
97
|
storage,
|
|
98
|
+
onStorageInitialize,
|
|
103
99
|
}
|
|
104
100
|
}
|
|
105
101
|
|
|
106
|
-
let init = {
|
|
107
|
-
|
|
108
|
-
let
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
})
|
|
114
|
-
cache
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async (persistence, ~reset=false) => {
|
|
118
|
-
try {
|
|
119
|
-
let shouldRun = switch persistence.storageStatus {
|
|
120
|
-
| Unknown => true
|
|
121
|
-
| Initializing(promise) => {
|
|
122
|
-
await promise
|
|
123
|
-
reset
|
|
124
|
-
}
|
|
125
|
-
| Ready(_) => reset
|
|
102
|
+
let init = async (persistence, ~reset=false) => {
|
|
103
|
+
try {
|
|
104
|
+
let shouldRun = switch persistence.storageStatus {
|
|
105
|
+
| Unknown => true
|
|
106
|
+
| Initializing(promise) => {
|
|
107
|
+
await promise
|
|
108
|
+
reset
|
|
126
109
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
110
|
+
| Ready(_) => reset
|
|
111
|
+
}
|
|
112
|
+
if shouldRun {
|
|
113
|
+
let resolveRef = ref(%raw(`null`))
|
|
114
|
+
let promise = Promise.make((resolve, _) => {
|
|
115
|
+
resolveRef := resolve
|
|
116
|
+
})
|
|
117
|
+
persistence.storageStatus = Initializing(promise)
|
|
118
|
+
if reset || !(await persistence.storage.isInitialized()) {
|
|
119
|
+
let _ = await persistence.storage.initialize(
|
|
120
|
+
~entities=persistence.allEntities,
|
|
121
|
+
~generalTables=persistence.staticTables,
|
|
122
|
+
~enums=persistence.allEnums,
|
|
123
|
+
)
|
|
141
124
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
persistence.storageStatus = Ready({
|
|
157
|
-
cleanRun: false,
|
|
158
|
-
cache: await loadInitialCache(persistence, ~withUpload=false),
|
|
159
|
-
})
|
|
125
|
+
persistence.storageStatus = Ready({
|
|
126
|
+
cleanRun: true,
|
|
127
|
+
effectCaches: Js.Dict.empty(),
|
|
128
|
+
})
|
|
129
|
+
switch persistence.onStorageInitialize {
|
|
130
|
+
| Some(onStorageInitialize) => await onStorageInitialize()
|
|
131
|
+
| None => ()
|
|
132
|
+
}
|
|
133
|
+
} else if (
|
|
134
|
+
// In case of a race condition,
|
|
135
|
+
// we want to set the initial status to Ready only once.
|
|
136
|
+
switch persistence.storageStatus {
|
|
137
|
+
| Initializing(_) => true
|
|
138
|
+
| _ => false
|
|
160
139
|
}
|
|
161
|
-
|
|
140
|
+
) {
|
|
141
|
+
let effectCaches = Js.Dict.empty()
|
|
142
|
+
(await persistence.storage.loadEffectCaches())->Js.Array2.forEach(effectCache => {
|
|
143
|
+
effectCaches->Js.Dict.set(effectCache.name, effectCache)
|
|
144
|
+
})
|
|
145
|
+
persistence.storageStatus = Ready({
|
|
146
|
+
cleanRun: false,
|
|
147
|
+
effectCaches,
|
|
148
|
+
})
|
|
162
149
|
}
|
|
163
|
-
|
|
164
|
-
| exn =>
|
|
165
|
-
exn->ErrorHandling.mkLogAndRaise(~msg=`EE800: Failed to initialize the indexer storage.`)
|
|
150
|
+
resolveRef.contents()
|
|
166
151
|
}
|
|
152
|
+
} catch {
|
|
153
|
+
| exn => exn->ErrorHandling.mkLogAndRaise(~msg=`EE800: Failed to initialize the indexer storage.`)
|
|
167
154
|
}
|
|
168
155
|
}
|
|
169
156
|
|
|
@@ -175,26 +162,3 @@ let getInitializedStorageOrThrow = persistence => {
|
|
|
175
162
|
| Ready(_) => persistence.storage
|
|
176
163
|
}
|
|
177
164
|
}
|
|
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, onStorageInitialize) {
|
|
28
26
|
var allEntities = userEntities.concat([dcRegistryEntityConfig]);
|
|
29
27
|
var allEnums$1 = allEnums.concat([entityHistoryActionEnumConfig]);
|
|
30
28
|
return {
|
|
@@ -33,20 +31,11 @@ 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
|
|
37
36
|
};
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
async function loadInitialCache(persistence, withUpload) {
|
|
41
|
-
var effectCacheRecords = await persistence.storage.restoreEffectCache(withUpload);
|
|
42
|
-
var cache = {};
|
|
43
|
-
effectCacheRecords.forEach(function (record) {
|
|
44
|
-
Prometheus.EffectCacheCount.set(record.count, record.effectName);
|
|
45
|
-
cache[record.effectName] = record;
|
|
46
|
-
});
|
|
47
|
-
return cache;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
39
|
async function init(persistence, resetOpt) {
|
|
51
40
|
var reset = resetOpt !== undefined ? resetOpt : false;
|
|
52
41
|
try {
|
|
@@ -74,24 +63,30 @@ async function init(persistence, resetOpt) {
|
|
|
74
63
|
_0: promise$1
|
|
75
64
|
};
|
|
76
65
|
if (reset || !await persistence.storage.isInitialized()) {
|
|
77
|
-
Logging.info("Initializing the indexer storage...");
|
|
78
66
|
await persistence.storage.initialize(persistence.allEntities, persistence.staticTables, persistence.allEnums);
|
|
79
|
-
Logging.info("The indexer storage is ready. Uploading cache...");
|
|
80
67
|
persistence.storageStatus = {
|
|
81
68
|
TAG: "Ready",
|
|
82
69
|
cleanRun: true,
|
|
83
|
-
|
|
70
|
+
effectCaches: {}
|
|
84
71
|
};
|
|
72
|
+
var onStorageInitialize = persistence.onStorageInitialize;
|
|
73
|
+
if (onStorageInitialize !== undefined) {
|
|
74
|
+
await onStorageInitialize();
|
|
75
|
+
}
|
|
76
|
+
|
|
85
77
|
} else {
|
|
86
78
|
var match = persistence.storageStatus;
|
|
87
79
|
var tmp;
|
|
88
80
|
tmp = typeof match !== "object" || match.TAG !== "Initializing" ? false : true;
|
|
89
81
|
if (tmp) {
|
|
90
|
-
|
|
82
|
+
var effectCaches = {};
|
|
83
|
+
(await persistence.storage.loadEffectCaches()).forEach(function (effectCache) {
|
|
84
|
+
effectCaches[effectCache.name] = effectCache;
|
|
85
|
+
});
|
|
91
86
|
persistence.storageStatus = {
|
|
92
87
|
TAG: "Ready",
|
|
93
88
|
cleanRun: false,
|
|
94
|
-
|
|
89
|
+
effectCaches: effectCaches
|
|
95
90
|
};
|
|
96
91
|
}
|
|
97
92
|
|
|
@@ -113,38 +108,9 @@ function getInitializedStorageOrThrow(persistence) {
|
|
|
113
108
|
}
|
|
114
109
|
}
|
|
115
110
|
|
|
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
111
|
exports.StorageError = StorageError;
|
|
145
112
|
exports.entityHistoryActionEnumConfig = entityHistoryActionEnumConfig;
|
|
146
113
|
exports.make = make;
|
|
147
114
|
exports.init = init;
|
|
148
115
|
exports.getInitializedStorageOrThrow = getInitializedStorageOrThrow;
|
|
149
|
-
|
|
150
|
-
/* Logging Not a pure module */
|
|
116
|
+
/* EntityHistory Not a pure module */
|