envio 2.22.0 → 2.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -6
- package/src/Address.res.js +30 -0
- package/src/ChainMap.res.js +77 -0
- package/src/Envio.res.js +16 -0
- package/src/ErrorHandling.res.js +56 -0
- package/src/EventUtils.res.js +75 -0
- package/src/EvmTypes.res.js +16 -0
- package/src/FetchState.res.js +969 -0
- package/src/Hasura.res.js +245 -0
- package/src/Internal.res.js +50 -0
- package/src/LazyLoader.res.js +117 -0
- package/src/LoadManager.res.js +124 -0
- package/src/LogSelection.res.js +203 -0
- package/src/Logging.res.js +247 -0
- package/src/Persistence.res.js +90 -0
- package/src/PgStorage.res.js +125 -0
- package/src/Prometheus.res.js +750 -0
- package/src/ReorgDetection.res.js +223 -0
- package/src/Throttler.res.js +60 -0
- package/src/Time.res.js +41 -0
- package/src/TopicFilter.res.js +86 -0
- package/src/Utils.res.js +527 -0
- package/src/bindings/BigDecimal.res.js +41 -0
- package/src/bindings/BigInt.res.js +138 -0
- package/src/bindings/Ethers.res.js +109 -0
- package/src/bindings/Express.res.js +2 -0
- package/src/bindings/Hrtime.res.js +66 -0
- package/src/bindings/NodeJs.res.js +29 -0
- package/src/bindings/Pino.res.js +95 -0
- package/src/bindings/Postgres.res.js +16 -0
- package/src/bindings/PromClient.res.js +17 -0
- package/src/bindings/Promise.res.js +25 -0
- package/src/bindings/SDSL.res.js +8 -0
- package/src/bindings/Viem.res.js +45 -0
- package/src/db/EntityHistory.res.js +307 -0
- package/src/db/Schema.res.js +54 -0
- package/src/db/Table.res.js +365 -0
- package/src/sources/Fuel.res.js +28 -0
- package/src/sources/HyperFuel.res.js +193 -0
- package/src/sources/HyperFuelClient.res.js +19 -0
- package/src/sources/HyperSync.res.js +301 -0
- package/src/sources/HyperSyncClient.res.js +99 -0
- package/src/sources/HyperSyncJsonApi.res.js +259 -0
- package/src/sources/Rpc.res.js +198 -0
- package/src/sources/Source.res.js +9 -0
- package/src/sources/SourceManager.res.js +366 -0
- package/src/vendored/Rest.res.js +574 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Rest = require("./vendored/Rest.res.js");
|
|
5
|
+
var Table = require("./db/Table.res.js");
|
|
6
|
+
var Utils = require("./Utils.res.js");
|
|
7
|
+
var Schema = require("./db/Schema.res.js");
|
|
8
|
+
var Logging = require("./Logging.res.js");
|
|
9
|
+
var Internal = require("./Internal.res.js");
|
|
10
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
11
|
+
var Caml_splice_call = require("rescript/lib/js/caml_splice_call.js");
|
|
12
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
13
|
+
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
14
|
+
|
|
15
|
+
function auth(s) {
|
|
16
|
+
return {
|
|
17
|
+
role: s.header("X-Hasura-Role", S$RescriptSchema.string),
|
|
18
|
+
secret: s.header("X-Hasura-Admin-Secret", S$RescriptSchema.string)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var responses = [
|
|
23
|
+
(function (s) {
|
|
24
|
+
s.status(200);
|
|
25
|
+
s.data(S$RescriptSchema.unknown);
|
|
26
|
+
return "QuerySucceeded";
|
|
27
|
+
}),
|
|
28
|
+
(function (s) {
|
|
29
|
+
s.field("code", S$RescriptSchema.$$enum([
|
|
30
|
+
"already-exists",
|
|
31
|
+
"already-tracked"
|
|
32
|
+
]));
|
|
33
|
+
return "AlreadyDone";
|
|
34
|
+
})
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
function clearMetadataRoute() {
|
|
38
|
+
return {
|
|
39
|
+
method: "POST",
|
|
40
|
+
path: "",
|
|
41
|
+
input: (function (s) {
|
|
42
|
+
s.field("type", S$RescriptSchema.literal("clear_metadata"));
|
|
43
|
+
s.field("args", S$RescriptSchema.literal({}));
|
|
44
|
+
return auth(s);
|
|
45
|
+
}),
|
|
46
|
+
responses: responses
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function trackTablesRoute() {
|
|
51
|
+
return {
|
|
52
|
+
method: "POST",
|
|
53
|
+
path: "",
|
|
54
|
+
input: (function (s) {
|
|
55
|
+
s.field("type", S$RescriptSchema.literal("pg_track_tables"));
|
|
56
|
+
return {
|
|
57
|
+
args: s.field("args", S$RescriptSchema.json(false)),
|
|
58
|
+
auth: auth(s)
|
|
59
|
+
};
|
|
60
|
+
}),
|
|
61
|
+
responses: responses
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function createSelectPermissionRoute() {
|
|
66
|
+
return {
|
|
67
|
+
method: "POST",
|
|
68
|
+
path: "",
|
|
69
|
+
input: (function (s) {
|
|
70
|
+
s.field("type", S$RescriptSchema.literal("pg_create_select_permission"));
|
|
71
|
+
return {
|
|
72
|
+
args: s.field("args", S$RescriptSchema.json(false)),
|
|
73
|
+
auth: auth(s)
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
responses: responses
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function rawBodyRoute() {
|
|
81
|
+
return {
|
|
82
|
+
method: "POST",
|
|
83
|
+
path: "",
|
|
84
|
+
input: (function (s) {
|
|
85
|
+
return {
|
|
86
|
+
bodyString: s.rawBody(S$RescriptSchema.string),
|
|
87
|
+
auth: auth(s)
|
|
88
|
+
};
|
|
89
|
+
}),
|
|
90
|
+
responses: responses
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function clearHasuraMetadata(endpoint, auth) {
|
|
95
|
+
try {
|
|
96
|
+
var result = await Rest.$$fetch(clearMetadataRoute, auth, Rest.client(endpoint, undefined));
|
|
97
|
+
var msg;
|
|
98
|
+
msg = result === "QuerySucceeded" ? "Metadata Cleared" : "Metadata Already Cleared";
|
|
99
|
+
return Logging.trace(msg);
|
|
100
|
+
}
|
|
101
|
+
catch (raw_exn){
|
|
102
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
103
|
+
return Logging.error({
|
|
104
|
+
msg: "EE806: There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.",
|
|
105
|
+
err: Internal.prettifyExn(exn)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function trackTables(endpoint, auth, pgSchema, tableNames) {
|
|
111
|
+
try {
|
|
112
|
+
var result = await Rest.$$fetch(trackTablesRoute, {
|
|
113
|
+
auth: auth,
|
|
114
|
+
args: {
|
|
115
|
+
allow_warnings: false,
|
|
116
|
+
tables: tableNames.map(function (tableName) {
|
|
117
|
+
return {
|
|
118
|
+
table: {
|
|
119
|
+
name: tableName,
|
|
120
|
+
schema: pgSchema
|
|
121
|
+
},
|
|
122
|
+
configuration: {
|
|
123
|
+
custom_name: tableName
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
}, Rest.client(endpoint, undefined));
|
|
129
|
+
var msg;
|
|
130
|
+
msg = result === "QuerySucceeded" ? "Tables Tracked" : "Table Already Tracked";
|
|
131
|
+
return Logging.trace({
|
|
132
|
+
msg: msg,
|
|
133
|
+
tableNames: tableNames
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (raw_exn){
|
|
137
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
138
|
+
return Logging.error({
|
|
139
|
+
msg: "EE807: There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.",
|
|
140
|
+
tableNames: tableNames,
|
|
141
|
+
err: Internal.prettifyExn(exn)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function createSelectPermissions(auth, endpoint, tableName, pgSchema, responseLimit, aggregateEntities) {
|
|
147
|
+
try {
|
|
148
|
+
var result = await Rest.$$fetch(createSelectPermissionRoute, {
|
|
149
|
+
auth: auth,
|
|
150
|
+
args: {
|
|
151
|
+
table: {
|
|
152
|
+
schema: pgSchema,
|
|
153
|
+
name: tableName
|
|
154
|
+
},
|
|
155
|
+
role: "public",
|
|
156
|
+
source: "default",
|
|
157
|
+
permission: {
|
|
158
|
+
columns: "*",
|
|
159
|
+
filter: {},
|
|
160
|
+
limit: responseLimit,
|
|
161
|
+
allow_aggregations: aggregateEntities.includes(tableName)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}, Rest.client(endpoint, undefined));
|
|
165
|
+
var msg;
|
|
166
|
+
msg = result === "QuerySucceeded" ? "Hasura select permissions created" : "Hasura select permissions already created";
|
|
167
|
+
return Logging.trace({
|
|
168
|
+
msg: msg,
|
|
169
|
+
tableName: tableName
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (raw_exn){
|
|
173
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
174
|
+
return Logging.error({
|
|
175
|
+
msg: "EE808: There was an issue setting up view permissions for the " + tableName + " table in hasura - indexing may still work - but you may have issues querying the data in hasura.",
|
|
176
|
+
tableName: tableName,
|
|
177
|
+
err: Internal.prettifyExn(exn)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function createEntityRelationship(pgSchema, endpoint, auth, tableName, relationshipType, relationalKey, objectName, mappedEntity, isDerivedFrom) {
|
|
183
|
+
var derivedFromTo = isDerivedFrom ? "\"id\": \"" + relationalKey + "\"" : "\"" + relationalKey + "_id\" : \"id\"";
|
|
184
|
+
var bodyString = "{\"type\": \"pg_create_" + relationshipType + "_relationship\",\"args\": {\"table\": {\"schema\": \"" + pgSchema + "\", \"name\": \"" + tableName + "\"},\"name\": \"" + objectName + "\",\"source\": \"default\",\"using\": {\"manual_configuration\": {\"remote_table\": {\"schema\": \"" + pgSchema + "\", \"name\": \"" + mappedEntity + "\"},\"column_mapping\": {" + derivedFromTo + "}}}}}";
|
|
185
|
+
try {
|
|
186
|
+
var result = await Rest.$$fetch(rawBodyRoute, {
|
|
187
|
+
auth: auth,
|
|
188
|
+
bodyString: bodyString
|
|
189
|
+
}, Rest.client(endpoint, undefined));
|
|
190
|
+
var msg;
|
|
191
|
+
msg = result === "QuerySucceeded" ? "Hasura " + relationshipType + " relationship created" : "Hasura " + relationshipType + " relationship already created";
|
|
192
|
+
return Logging.trace({
|
|
193
|
+
msg: msg,
|
|
194
|
+
tableName: tableName
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch (raw_exn){
|
|
198
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
199
|
+
return Logging.error({
|
|
200
|
+
msg: "EE808: There was an issue setting up " + relationshipType + " relationship for the " + tableName + " table in hasura - indexing may still work - but you may have issues querying the data in hasura.",
|
|
201
|
+
tableName: tableName,
|
|
202
|
+
err: Internal.prettifyExn(exn)
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function trackDatabase(endpoint, auth, pgSchema, allStaticTables, allEntityTables, aggregateEntities, responseLimit, schema) {
|
|
208
|
+
Logging.info("Tracking tables in Hasura");
|
|
209
|
+
await clearHasuraMetadata(endpoint, auth);
|
|
210
|
+
var tableNames = Belt_Array.concatMany([
|
|
211
|
+
allStaticTables,
|
|
212
|
+
allEntityTables
|
|
213
|
+
]).map(function (param) {
|
|
214
|
+
return param.tableName;
|
|
215
|
+
});
|
|
216
|
+
await trackTables(endpoint, auth, pgSchema, tableNames);
|
|
217
|
+
await Promise.all(Caml_splice_call.spliceObjApply(tableNames.map(function (tableName) {
|
|
218
|
+
return createSelectPermissions(auth, endpoint, tableName, pgSchema, responseLimit, aggregateEntities);
|
|
219
|
+
}), "concat", [allEntityTables.map(function (table) {
|
|
220
|
+
var tableName = table.tableName;
|
|
221
|
+
return [
|
|
222
|
+
Table.getDerivedFromFields(table).map(function (derivedFromField) {
|
|
223
|
+
var relationalFieldName = Utils.unwrapResultExn(Schema.getDerivedFromFieldName(schema, derivedFromField));
|
|
224
|
+
return createEntityRelationship(pgSchema, endpoint, auth, tableName, "array", relationalFieldName, derivedFromField.fieldName, derivedFromField.derivedFromEntity, true);
|
|
225
|
+
}),
|
|
226
|
+
Table.getLinkedEntityFields(table).map(function (param) {
|
|
227
|
+
var field = param[0];
|
|
228
|
+
return createEntityRelationship(pgSchema, endpoint, auth, tableName, "object", field.fieldName, field.fieldName, param[1], false);
|
|
229
|
+
})
|
|
230
|
+
].flat(1);
|
|
231
|
+
})]));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
exports.auth = auth;
|
|
235
|
+
exports.responses = responses;
|
|
236
|
+
exports.clearMetadataRoute = clearMetadataRoute;
|
|
237
|
+
exports.trackTablesRoute = trackTablesRoute;
|
|
238
|
+
exports.createSelectPermissionRoute = createSelectPermissionRoute;
|
|
239
|
+
exports.rawBodyRoute = rawBodyRoute;
|
|
240
|
+
exports.clearHasuraMetadata = clearHasuraMetadata;
|
|
241
|
+
exports.trackTables = trackTables;
|
|
242
|
+
exports.createSelectPermissions = createSelectPermissions;
|
|
243
|
+
exports.createEntityRelationship = createEntityRelationship;
|
|
244
|
+
exports.trackDatabase = trackDatabase;
|
|
245
|
+
/* Rest Not a pure module */
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var $$BigInt = require("./bindings/BigInt.res.js");
|
|
5
|
+
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
6
|
+
var Address = require("./Address.res.js");
|
|
7
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
8
|
+
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
9
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
10
|
+
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
11
|
+
|
|
12
|
+
var fuelSupplyParamsSchema = S$RescriptSchema.schema(function (s) {
|
|
13
|
+
return {
|
|
14
|
+
subId: s.m(S$RescriptSchema.string),
|
|
15
|
+
amount: s.m($$BigInt.schema)
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var fuelTransferParamsSchema = S$RescriptSchema.schema(function (s) {
|
|
20
|
+
return {
|
|
21
|
+
to: s.m(Address.schema),
|
|
22
|
+
assetId: s.m(S$RescriptSchema.string),
|
|
23
|
+
amount: s.m($$BigInt.schema)
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function makeEnumConfig(name, variants) {
|
|
28
|
+
var v = Belt_Array.get(variants, 0);
|
|
29
|
+
return {
|
|
30
|
+
name: name,
|
|
31
|
+
variants: variants,
|
|
32
|
+
schema: S$RescriptSchema.$$enum(variants),
|
|
33
|
+
default: v !== undefined ? Caml_option.valFromOption(v) : Js_exn.raiseError("No variants defined for enum " + name)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function prettifyExn(exn) {
|
|
38
|
+
var e = Caml_js_exceptions.internalToOCamlException(exn);
|
|
39
|
+
if (e.RE_EXN_ID === Js_exn.$$Error) {
|
|
40
|
+
return e._1;
|
|
41
|
+
} else {
|
|
42
|
+
return e;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.fuelSupplyParamsSchema = fuelSupplyParamsSchema;
|
|
47
|
+
exports.fuelTransferParamsSchema = fuelTransferParamsSchema;
|
|
48
|
+
exports.makeEnumConfig = makeEnumConfig;
|
|
49
|
+
exports.prettifyExn = prettifyExn;
|
|
50
|
+
/* fuelSupplyParamsSchema Not a pure module */
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Utils = require("./Utils.res.js");
|
|
5
|
+
var JsSdsl = require("js-sdsl");
|
|
6
|
+
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
7
|
+
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
8
|
+
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
9
|
+
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
10
|
+
|
|
11
|
+
var LoaderTimeout = /* @__PURE__ */Caml_exceptions.create("LazyLoader.LoaderTimeout");
|
|
12
|
+
|
|
13
|
+
function make(loaderFn, onError, cacheSizeOpt, loaderPoolSizeOpt, retryDelayMillisOpt, timeoutMillisOpt) {
|
|
14
|
+
var cacheSize = cacheSizeOpt !== undefined ? cacheSizeOpt : 10000;
|
|
15
|
+
var loaderPoolSize = loaderPoolSizeOpt !== undefined ? loaderPoolSizeOpt : 10;
|
|
16
|
+
var retryDelayMillis = retryDelayMillisOpt !== undefined ? retryDelayMillisOpt : 5000;
|
|
17
|
+
var timeoutMillis = timeoutMillisOpt !== undefined ? timeoutMillisOpt : 300000;
|
|
18
|
+
return {
|
|
19
|
+
_cacheSize: cacheSize,
|
|
20
|
+
_loaderPoolSize: loaderPoolSize,
|
|
21
|
+
_retryDelayMillis: retryDelayMillis,
|
|
22
|
+
_timeoutMillis: timeoutMillis,
|
|
23
|
+
externalPromises: new Map(),
|
|
24
|
+
resolvers: new Map(),
|
|
25
|
+
inProgress: new Set(),
|
|
26
|
+
loaderQueue: new JsSdsl.Queue(),
|
|
27
|
+
loadedKeys: new JsSdsl.Queue(),
|
|
28
|
+
loaderFn: loaderFn,
|
|
29
|
+
onError: onError
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function deleteKey(_obj, _k) {
|
|
34
|
+
((delete _obj[_k]));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function timeoutAfter(timeoutMillis) {
|
|
38
|
+
return Utils.delay(timeoutMillis).then(function () {
|
|
39
|
+
return Promise.reject({
|
|
40
|
+
RE_EXN_ID: LoaderTimeout,
|
|
41
|
+
_1: "Query took longer than " + String(timeoutMillis / 1000 | 0) + " seconds"
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function loadNext(am, k) {
|
|
47
|
+
am.inProgress.add(k);
|
|
48
|
+
var awaitTaskPromiseAndLoadNextWithTimeout = async function () {
|
|
49
|
+
var val = await Promise.race([
|
|
50
|
+
am.loaderFn(k),
|
|
51
|
+
timeoutAfter(am._timeoutMillis)
|
|
52
|
+
]);
|
|
53
|
+
Belt_Option.forEach(am.resolvers.get(k), (function (r) {
|
|
54
|
+
am.resolvers.delete(k);
|
|
55
|
+
r(val);
|
|
56
|
+
}));
|
|
57
|
+
am.inProgress.delete(k);
|
|
58
|
+
var loadedKeysNumber = am.loadedKeys.push(k);
|
|
59
|
+
if (loadedKeysNumber > am._cacheSize) {
|
|
60
|
+
var old = am.loadedKeys.pop();
|
|
61
|
+
if (old !== undefined) {
|
|
62
|
+
am.externalPromises.delete(Caml_option.valFromOption(old));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
var next = am.loaderQueue.pop();
|
|
67
|
+
if (next !== undefined) {
|
|
68
|
+
return await loadNext(am, Caml_option.valFromOption(next));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
};
|
|
72
|
+
var tmp;
|
|
73
|
+
var exit = 0;
|
|
74
|
+
var val;
|
|
75
|
+
try {
|
|
76
|
+
val = await awaitTaskPromiseAndLoadNextWithTimeout();
|
|
77
|
+
exit = 1;
|
|
78
|
+
}
|
|
79
|
+
catch (raw_err){
|
|
80
|
+
var err = Caml_js_exceptions.internalToOCamlException(raw_err);
|
|
81
|
+
var onError = am.onError;
|
|
82
|
+
if (onError !== undefined) {
|
|
83
|
+
onError(am, err);
|
|
84
|
+
}
|
|
85
|
+
await Utils.delay(am._retryDelayMillis);
|
|
86
|
+
tmp = awaitTaskPromiseAndLoadNextWithTimeout();
|
|
87
|
+
}
|
|
88
|
+
if (exit === 1) {
|
|
89
|
+
tmp = Promise.resolve();
|
|
90
|
+
}
|
|
91
|
+
return await tmp;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function get(am, k) {
|
|
95
|
+
var x = am.externalPromises.get(k);
|
|
96
|
+
if (x !== undefined) {
|
|
97
|
+
return Caml_option.valFromOption(x);
|
|
98
|
+
}
|
|
99
|
+
var promise = new Promise((function (resolve, param) {
|
|
100
|
+
am.resolvers.set(k, resolve);
|
|
101
|
+
}));
|
|
102
|
+
am.externalPromises.set(k, promise);
|
|
103
|
+
if (am.inProgress.size < am._loaderPoolSize) {
|
|
104
|
+
loadNext(am, k);
|
|
105
|
+
} else {
|
|
106
|
+
am.loaderQueue.push(k);
|
|
107
|
+
}
|
|
108
|
+
return promise;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.LoaderTimeout = LoaderTimeout;
|
|
112
|
+
exports.make = make;
|
|
113
|
+
exports.deleteKey = deleteKey;
|
|
114
|
+
exports.timeoutAfter = timeoutAfter;
|
|
115
|
+
exports.loadNext = loadNext;
|
|
116
|
+
exports.get = get;
|
|
117
|
+
/* Utils Not a pure module */
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Utils = require("./Utils.res.js");
|
|
5
|
+
var Internal = require("./Internal.res.js");
|
|
6
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
7
|
+
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
8
|
+
|
|
9
|
+
var Call = {};
|
|
10
|
+
|
|
11
|
+
var Group = {};
|
|
12
|
+
|
|
13
|
+
function make() {
|
|
14
|
+
return {
|
|
15
|
+
groups: {},
|
|
16
|
+
isCollecting: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function schedule(loadManager) {
|
|
21
|
+
loadManager.isCollecting = true;
|
|
22
|
+
await Promise.resolve();
|
|
23
|
+
loadManager.isCollecting = false;
|
|
24
|
+
var groups = loadManager.groups;
|
|
25
|
+
Object.keys(groups).forEach(async function (key) {
|
|
26
|
+
var group = groups[key];
|
|
27
|
+
var calls = group.calls;
|
|
28
|
+
var inputsToLoad = [];
|
|
29
|
+
var currentInputKeys = [];
|
|
30
|
+
Object.keys(calls).forEach(function (inputKey) {
|
|
31
|
+
var call = calls[inputKey];
|
|
32
|
+
if (!call.isLoading) {
|
|
33
|
+
call.isLoading = true;
|
|
34
|
+
currentInputKeys.push(inputKey);
|
|
35
|
+
if (!group.hasInMemory(inputKey)) {
|
|
36
|
+
inputsToLoad.push(call.input);
|
|
37
|
+
return ;
|
|
38
|
+
} else {
|
|
39
|
+
return ;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
if (!Utils.$$Array.isEmpty(inputsToLoad)) {
|
|
45
|
+
try {
|
|
46
|
+
await group.load(inputsToLoad);
|
|
47
|
+
}
|
|
48
|
+
catch (raw_exn){
|
|
49
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
50
|
+
var exn$1 = Internal.prettifyExn(exn);
|
|
51
|
+
Belt_Array.forEach(currentInputKeys, (function (inputKey) {
|
|
52
|
+
var call = calls[inputKey];
|
|
53
|
+
call.reject(exn$1);
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (Utils.$$Array.isEmpty(currentInputKeys)) {
|
|
58
|
+
return ;
|
|
59
|
+
}
|
|
60
|
+
currentInputKeys.forEach(function (inputKey) {
|
|
61
|
+
var call = calls[inputKey];
|
|
62
|
+
Utils.Dict.deleteInPlace(calls, inputKey);
|
|
63
|
+
call.resolve(group.getUnsafeInMemory(inputKey));
|
|
64
|
+
});
|
|
65
|
+
var latestGroup = groups[key];
|
|
66
|
+
if (Utils.$$Array.isEmpty(Object.keys(latestGroup.calls))) {
|
|
67
|
+
return Utils.Dict.deleteInPlace(groups, key);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function noopHasher(input) {
|
|
74
|
+
return input;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function call(loadManager, input, key, load, hasher, shouldGroup, hasInMemory, getUnsafeInMemory) {
|
|
78
|
+
var inputKey = hasher === noopHasher ? input : hasher(input);
|
|
79
|
+
if (!shouldGroup && hasInMemory(inputKey)) {
|
|
80
|
+
return Promise.resolve(getUnsafeInMemory(inputKey));
|
|
81
|
+
}
|
|
82
|
+
var group = loadManager.groups[key];
|
|
83
|
+
var group$1;
|
|
84
|
+
if (group !== undefined) {
|
|
85
|
+
group$1 = group;
|
|
86
|
+
} else {
|
|
87
|
+
var g_calls = {};
|
|
88
|
+
var g = {
|
|
89
|
+
calls: g_calls,
|
|
90
|
+
load: load,
|
|
91
|
+
getUnsafeInMemory: getUnsafeInMemory,
|
|
92
|
+
hasInMemory: hasInMemory
|
|
93
|
+
};
|
|
94
|
+
loadManager.groups[key] = g;
|
|
95
|
+
group$1 = g;
|
|
96
|
+
}
|
|
97
|
+
var c = group$1.calls[inputKey];
|
|
98
|
+
if (c !== undefined) {
|
|
99
|
+
return c.promise;
|
|
100
|
+
}
|
|
101
|
+
var promise = new Promise((function (resolve, reject) {
|
|
102
|
+
var call = {
|
|
103
|
+
input: input,
|
|
104
|
+
resolve: resolve,
|
|
105
|
+
reject: reject,
|
|
106
|
+
promise: null,
|
|
107
|
+
isLoading: false
|
|
108
|
+
};
|
|
109
|
+
group$1.calls[inputKey] = call;
|
|
110
|
+
}));
|
|
111
|
+
group$1.calls[inputKey].promise = promise;
|
|
112
|
+
if (!loadManager.isCollecting) {
|
|
113
|
+
schedule(loadManager);
|
|
114
|
+
}
|
|
115
|
+
return promise;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
exports.Call = Call;
|
|
119
|
+
exports.Group = Group;
|
|
120
|
+
exports.make = make;
|
|
121
|
+
exports.schedule = schedule;
|
|
122
|
+
exports.noopHasher = noopHasher;
|
|
123
|
+
exports.call = call;
|
|
124
|
+
/* Utils Not a pure module */
|