envio 2.21.5 → 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/index.js +2 -2
- package/package.json +11 -8
- package/rescript.json +1 -1
- package/src/Address.res.js +30 -0
- package/src/ChainMap.res.js +77 -0
- package/src/Envio.res +2 -0
- package/src/Envio.res.js +16 -0
- package/src/ErrorHandling.res +0 -26
- 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 +297 -0
- package/src/Hasura.res.js +245 -0
- package/src/Internal.res +26 -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 +31 -31
- package/src/Logging.res.js +247 -0
- package/src/Persistence.res +111 -0
- package/src/Persistence.res.js +90 -0
- package/src/PgStorage.res +165 -0
- package/src/PgStorage.res.js +125 -0
- package/src/Prometheus.res +75 -40
- 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.gen.ts +1 -1
- package/src/bindings/BigDecimal.res.js +41 -0
- package/src/bindings/BigInt.res.js +138 -0
- package/src/bindings/Ethers.gen.ts +1 -1
- 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 +5 -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 +3 -3
- 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
- package/src/Enum.res +0 -22
package/src/Hasura.res
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
type auth = {
|
|
2
|
+
role: string,
|
|
3
|
+
secret: string,
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type validHasuraResponse = QuerySucceeded | AlreadyDone
|
|
7
|
+
|
|
8
|
+
let auth = (s: Rest.s) => {
|
|
9
|
+
role: s.header("X-Hasura-Role", S.string),
|
|
10
|
+
secret: s.header("X-Hasura-Admin-Secret", S.string),
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let responses = [
|
|
14
|
+
(s: Rest.Response.s) => {
|
|
15
|
+
s.status(200)
|
|
16
|
+
let _ = s.data(S.unknown)
|
|
17
|
+
QuerySucceeded
|
|
18
|
+
},
|
|
19
|
+
s => {
|
|
20
|
+
let _ = s.field("code", S.enum(["already-exists", "already-tracked"]))
|
|
21
|
+
AlreadyDone
|
|
22
|
+
},
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
let clearMetadataRoute = Rest.route(() => {
|
|
26
|
+
method: Post,
|
|
27
|
+
path: "",
|
|
28
|
+
input: s => {
|
|
29
|
+
let _ = s.field("type", S.literal("clear_metadata"))
|
|
30
|
+
let _ = s.field("args", S.literal(Js.Obj.empty()))
|
|
31
|
+
s->auth
|
|
32
|
+
},
|
|
33
|
+
responses,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
let trackTablesRoute = Rest.route(() => {
|
|
37
|
+
method: Post,
|
|
38
|
+
path: "",
|
|
39
|
+
input: s => {
|
|
40
|
+
let _ = s.field("type", S.literal("pg_track_tables"))
|
|
41
|
+
{
|
|
42
|
+
"args": s.field("args", S.json(~validate=false)),
|
|
43
|
+
"auth": s->auth,
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
responses,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
let createSelectPermissionRoute = Rest.route(() => {
|
|
50
|
+
method: Post,
|
|
51
|
+
path: "",
|
|
52
|
+
input: s => {
|
|
53
|
+
let _ = s.field("type", S.literal("pg_create_select_permission"))
|
|
54
|
+
{
|
|
55
|
+
"args": s.field("args", S.json(~validate=false)),
|
|
56
|
+
"auth": s->auth,
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
responses,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
let rawBodyRoute = Rest.route(() => {
|
|
63
|
+
method: Post,
|
|
64
|
+
path: "",
|
|
65
|
+
input: s => {
|
|
66
|
+
{
|
|
67
|
+
"bodyString": s.rawBody(S.string),
|
|
68
|
+
"auth": s->auth,
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
responses,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
let clearHasuraMetadata = async (~endpoint, ~auth) => {
|
|
75
|
+
try {
|
|
76
|
+
let result = await clearMetadataRoute->Rest.fetch(auth, ~client=Rest.client(endpoint))
|
|
77
|
+
let msg = switch result {
|
|
78
|
+
| QuerySucceeded => "Metadata Cleared"
|
|
79
|
+
| AlreadyDone => "Metadata Already Cleared"
|
|
80
|
+
}
|
|
81
|
+
Logging.trace(msg)
|
|
82
|
+
} catch {
|
|
83
|
+
| exn =>
|
|
84
|
+
Logging.error({
|
|
85
|
+
"msg": `EE806: There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
|
|
86
|
+
"err": exn->Internal.prettifyExn,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let trackTables = async (~endpoint, ~auth, ~pgSchema, ~tableNames: array<string>) => {
|
|
92
|
+
try {
|
|
93
|
+
let result = await trackTablesRoute->Rest.fetch(
|
|
94
|
+
{
|
|
95
|
+
"auth": auth,
|
|
96
|
+
"args": {
|
|
97
|
+
// If set to false, any warnings will cause the API call to fail and no new tables to be tracked. Otherwise tables that fail to track will be raised as warnings. (default: true)
|
|
98
|
+
"allow_warnings": false,
|
|
99
|
+
"tables": tableNames->Js.Array2.map(tableName =>
|
|
100
|
+
{
|
|
101
|
+
"table": {
|
|
102
|
+
"name": tableName,
|
|
103
|
+
"schema": pgSchema,
|
|
104
|
+
},
|
|
105
|
+
"configuration": {
|
|
106
|
+
// Otherwise the entity in gql will be prefixed with the schema name (when it's not public)
|
|
107
|
+
"custom_name": tableName,
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
}->(Utils.magic: 'a => Js.Json.t),
|
|
112
|
+
},
|
|
113
|
+
~client=Rest.client(endpoint),
|
|
114
|
+
)
|
|
115
|
+
let msg = switch result {
|
|
116
|
+
| QuerySucceeded => "Tables Tracked"
|
|
117
|
+
| AlreadyDone => "Table Already Tracked"
|
|
118
|
+
}
|
|
119
|
+
Logging.trace({
|
|
120
|
+
"msg": msg,
|
|
121
|
+
"tableNames": tableNames,
|
|
122
|
+
})
|
|
123
|
+
} catch {
|
|
124
|
+
| exn =>
|
|
125
|
+
Logging.error({
|
|
126
|
+
"msg": `EE807: There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
|
|
127
|
+
"tableNames": tableNames,
|
|
128
|
+
"err": exn->Internal.prettifyExn,
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let createSelectPermissions = async (
|
|
134
|
+
~auth,
|
|
135
|
+
~endpoint,
|
|
136
|
+
~tableName: string,
|
|
137
|
+
~pgSchema,
|
|
138
|
+
~responseLimit,
|
|
139
|
+
~aggregateEntities,
|
|
140
|
+
) => {
|
|
141
|
+
try {
|
|
142
|
+
let result = await createSelectPermissionRoute->Rest.fetch(
|
|
143
|
+
{
|
|
144
|
+
"auth": auth,
|
|
145
|
+
"args": {
|
|
146
|
+
"table": {
|
|
147
|
+
"schema": pgSchema,
|
|
148
|
+
"name": tableName,
|
|
149
|
+
},
|
|
150
|
+
"role": "public",
|
|
151
|
+
"source": "default",
|
|
152
|
+
"permission": {
|
|
153
|
+
"columns": "*",
|
|
154
|
+
"filter": Js.Obj.empty(),
|
|
155
|
+
"limit": responseLimit,
|
|
156
|
+
"allow_aggregations": aggregateEntities->Js.Array2.includes(tableName),
|
|
157
|
+
},
|
|
158
|
+
}->(Utils.magic: 'a => Js.Json.t),
|
|
159
|
+
},
|
|
160
|
+
~client=Rest.client(endpoint),
|
|
161
|
+
)
|
|
162
|
+
let msg = switch result {
|
|
163
|
+
| QuerySucceeded => "Hasura select permissions created"
|
|
164
|
+
| AlreadyDone => "Hasura select permissions already created"
|
|
165
|
+
}
|
|
166
|
+
Logging.trace({
|
|
167
|
+
"msg": msg,
|
|
168
|
+
"tableName": tableName,
|
|
169
|
+
})
|
|
170
|
+
} catch {
|
|
171
|
+
| exn =>
|
|
172
|
+
Logging.error({
|
|
173
|
+
"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.`,
|
|
174
|
+
"tableName": tableName,
|
|
175
|
+
"err": exn->Internal.prettifyExn,
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let createEntityRelationship = async (
|
|
181
|
+
~pgSchema,
|
|
182
|
+
~endpoint,
|
|
183
|
+
~auth,
|
|
184
|
+
~tableName: string,
|
|
185
|
+
~relationshipType: string,
|
|
186
|
+
~relationalKey: string,
|
|
187
|
+
~objectName: string,
|
|
188
|
+
~mappedEntity: string,
|
|
189
|
+
~isDerivedFrom: bool,
|
|
190
|
+
) => {
|
|
191
|
+
let derivedFromTo = isDerivedFrom ? `"id": "${relationalKey}"` : `"${relationalKey}_id" : "id"`
|
|
192
|
+
|
|
193
|
+
let 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}}}}}}`
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
let result = await rawBodyRoute->Rest.fetch(
|
|
197
|
+
{
|
|
198
|
+
"auth": auth,
|
|
199
|
+
"bodyString": bodyString,
|
|
200
|
+
},
|
|
201
|
+
~client=Rest.client(endpoint),
|
|
202
|
+
)
|
|
203
|
+
let msg = switch result {
|
|
204
|
+
| QuerySucceeded => `Hasura ${relationshipType} relationship created`
|
|
205
|
+
| AlreadyDone => `Hasura ${relationshipType} relationship already created`
|
|
206
|
+
}
|
|
207
|
+
Logging.trace({
|
|
208
|
+
"msg": msg,
|
|
209
|
+
"tableName": tableName,
|
|
210
|
+
})
|
|
211
|
+
} catch {
|
|
212
|
+
| exn =>
|
|
213
|
+
Logging.error({
|
|
214
|
+
"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.`,
|
|
215
|
+
"tableName": tableName,
|
|
216
|
+
"err": exn->Internal.prettifyExn,
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let trackDatabase = async (
|
|
222
|
+
~endpoint,
|
|
223
|
+
~auth,
|
|
224
|
+
~pgSchema,
|
|
225
|
+
~allStaticTables,
|
|
226
|
+
~allEntityTables,
|
|
227
|
+
~aggregateEntities,
|
|
228
|
+
~responseLimit,
|
|
229
|
+
~schema,
|
|
230
|
+
) => {
|
|
231
|
+
Logging.info("Tracking tables in Hasura")
|
|
232
|
+
|
|
233
|
+
let _ = await clearHasuraMetadata(~endpoint, ~auth)
|
|
234
|
+
let tableNames =
|
|
235
|
+
[allStaticTables, allEntityTables]
|
|
236
|
+
->Belt.Array.concatMany
|
|
237
|
+
->Js.Array2.map(({tableName}: Table.table) => tableName)
|
|
238
|
+
|
|
239
|
+
await trackTables(~endpoint, ~auth, ~pgSchema, ~tableNames)
|
|
240
|
+
|
|
241
|
+
let _ =
|
|
242
|
+
await tableNames
|
|
243
|
+
->Js.Array2.map(tableName =>
|
|
244
|
+
createSelectPermissions(
|
|
245
|
+
~endpoint,
|
|
246
|
+
~auth,
|
|
247
|
+
~tableName,
|
|
248
|
+
~pgSchema,
|
|
249
|
+
~responseLimit,
|
|
250
|
+
~aggregateEntities,
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
->Js.Array2.concatMany(
|
|
254
|
+
allEntityTables->Js.Array2.map(table => {
|
|
255
|
+
let {tableName} = table
|
|
256
|
+
[
|
|
257
|
+
//Set array relationships
|
|
258
|
+
table
|
|
259
|
+
->Table.getDerivedFromFields
|
|
260
|
+
->Js.Array2.map(derivedFromField => {
|
|
261
|
+
//determines the actual name of the underlying relational field (if it's an entity mapping then suffixes _id for eg.)
|
|
262
|
+
let relationalFieldName =
|
|
263
|
+
schema->Schema.getDerivedFromFieldName(derivedFromField)->Utils.unwrapResultExn
|
|
264
|
+
|
|
265
|
+
createEntityRelationship(
|
|
266
|
+
~endpoint,
|
|
267
|
+
~auth,
|
|
268
|
+
~pgSchema,
|
|
269
|
+
~tableName,
|
|
270
|
+
~relationshipType="array",
|
|
271
|
+
~isDerivedFrom=true,
|
|
272
|
+
~objectName=derivedFromField.fieldName,
|
|
273
|
+
~relationalKey=relationalFieldName,
|
|
274
|
+
~mappedEntity=derivedFromField.derivedFromEntity,
|
|
275
|
+
)
|
|
276
|
+
}),
|
|
277
|
+
//Set object relationships
|
|
278
|
+
table
|
|
279
|
+
->Table.getLinkedEntityFields
|
|
280
|
+
->Js.Array2.map(((field, linkedEntityName)) => {
|
|
281
|
+
createEntityRelationship(
|
|
282
|
+
~endpoint,
|
|
283
|
+
~auth,
|
|
284
|
+
~pgSchema,
|
|
285
|
+
~tableName,
|
|
286
|
+
~relationshipType="object",
|
|
287
|
+
~isDerivedFrom=false,
|
|
288
|
+
~objectName=field.fieldName,
|
|
289
|
+
~relationalKey=field.fieldName,
|
|
290
|
+
~mappedEntity=linkedEntityName,
|
|
291
|
+
)
|
|
292
|
+
}),
|
|
293
|
+
]->Utils.Array.flatten
|
|
294
|
+
}),
|
|
295
|
+
)
|
|
296
|
+
->Promise.all
|
|
297
|
+
}
|
|
@@ -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 */
|
package/src/Internal.res
CHANGED
|
@@ -160,6 +160,31 @@ let fuelTransferParamsSchema = S.schema(s => {
|
|
|
160
160
|
})
|
|
161
161
|
|
|
162
162
|
type entity = private {id: string}
|
|
163
|
+
type entityConfig = {
|
|
164
|
+
name: string,
|
|
165
|
+
schema: S.t<entity>,
|
|
166
|
+
rowsSchema: S.t<array<entity>>,
|
|
167
|
+
table: Table.table,
|
|
168
|
+
entityHistory: EntityHistory.t<entity>,
|
|
169
|
+
}
|
|
170
|
+
type enum
|
|
171
|
+
type enumConfig<'enum> = {
|
|
172
|
+
name: string,
|
|
173
|
+
variants: array<'enum>,
|
|
174
|
+
schema: S.t<'enum>,
|
|
175
|
+
default: 'enum,
|
|
176
|
+
}
|
|
177
|
+
external fromGenericEnumConfig: enumConfig<'enum> => enumConfig<enum> = "%identity"
|
|
178
|
+
|
|
179
|
+
let makeEnumConfig = (~name, ~variants) => {
|
|
180
|
+
name,
|
|
181
|
+
variants,
|
|
182
|
+
schema: S.enum(variants),
|
|
183
|
+
default: switch variants->Belt.Array.get(0) {
|
|
184
|
+
| Some(v) => v
|
|
185
|
+
| None => Js.Exn.raiseError("No variants defined for enum " ++ name)
|
|
186
|
+
},
|
|
187
|
+
}
|
|
163
188
|
|
|
164
189
|
type effectInput
|
|
165
190
|
type effectOutput
|
|
@@ -172,6 +197,7 @@ type effectArgs = {
|
|
|
172
197
|
type effect = {
|
|
173
198
|
name: string,
|
|
174
199
|
handler: effectArgs => promise<effectOutput>,
|
|
200
|
+
mutable callsCount: int,
|
|
175
201
|
}
|
|
176
202
|
|
|
177
203
|
@genType.import(("./Types.ts", "Invalid"))
|
|
@@ -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 */
|