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
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
5
|
+
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
6
|
+
|
|
7
|
+
async function $$default(args) {
|
|
8
|
+
var result = await fetch(args.path, args);
|
|
9
|
+
var contentType = result.headers.get("content-type");
|
|
10
|
+
if (contentType && contentType.includes("application/") && contentType.includes("json")) {
|
|
11
|
+
return {
|
|
12
|
+
data: await result.json(),
|
|
13
|
+
status: result.status,
|
|
14
|
+
headers: result.headers
|
|
15
|
+
};
|
|
16
|
+
} else if (contentType && contentType.includes("text/")) {
|
|
17
|
+
return {
|
|
18
|
+
data: await result.text(),
|
|
19
|
+
status: result.status,
|
|
20
|
+
headers: result.headers
|
|
21
|
+
};
|
|
22
|
+
} else {
|
|
23
|
+
return {
|
|
24
|
+
data: await result.blob(),
|
|
25
|
+
status: result.status,
|
|
26
|
+
headers: result.headers
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var ApiFetcher = {
|
|
32
|
+
$$default: $$default
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function register(map, status, builder) {
|
|
36
|
+
if (map[status]) {
|
|
37
|
+
throw new Error("[rescript-rest] " + ("Response for the \"" + status + "\" status registered multiple times"));
|
|
38
|
+
}
|
|
39
|
+
map[status] = builder;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parsePath(_path, pathItems, pathParams) {
|
|
43
|
+
while(true) {
|
|
44
|
+
var path = _path;
|
|
45
|
+
if (path === "") {
|
|
46
|
+
return ;
|
|
47
|
+
}
|
|
48
|
+
var paramStartIdx = path.indexOf("{");
|
|
49
|
+
if (paramStartIdx !== -1) {
|
|
50
|
+
var paramEndIdx = path.indexOf("}");
|
|
51
|
+
if (paramEndIdx !== -1) {
|
|
52
|
+
if (paramStartIdx > paramEndIdx) {
|
|
53
|
+
throw new Error("[rescript-rest] Path parameter is not enclosed in curly braces");
|
|
54
|
+
}
|
|
55
|
+
var paramName = path.slice(paramStartIdx + 1 | 0, paramEndIdx);
|
|
56
|
+
if (paramName === "") {
|
|
57
|
+
throw new Error("[rescript-rest] Path parameter name cannot be empty");
|
|
58
|
+
}
|
|
59
|
+
var param = {
|
|
60
|
+
name: paramName
|
|
61
|
+
};
|
|
62
|
+
pathItems.push(path.slice(0, paramStartIdx));
|
|
63
|
+
pathItems.push(param);
|
|
64
|
+
pathParams[paramName] = param;
|
|
65
|
+
_path = path.slice(paramEndIdx + 1 | 0);
|
|
66
|
+
continue ;
|
|
67
|
+
}
|
|
68
|
+
throw new Error("[rescript-rest] Path contains an unclosed parameter");
|
|
69
|
+
}
|
|
70
|
+
pathItems.push(path);
|
|
71
|
+
return ;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function coerceSchema(schema) {
|
|
76
|
+
return S$RescriptSchema.preprocess(schema, (function (s) {
|
|
77
|
+
var optionalSchema = s.schema.t;
|
|
78
|
+
var tagged;
|
|
79
|
+
tagged = typeof optionalSchema !== "object" || optionalSchema.TAG !== "option" ? optionalSchema : optionalSchema._0.t;
|
|
80
|
+
var exit = 0;
|
|
81
|
+
if (typeof tagged !== "object") {
|
|
82
|
+
switch (tagged) {
|
|
83
|
+
case "int32" :
|
|
84
|
+
case "number" :
|
|
85
|
+
exit = 2;
|
|
86
|
+
break;
|
|
87
|
+
case "boolean" :
|
|
88
|
+
exit = 1;
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
switch (tagged.TAG) {
|
|
95
|
+
case "literal" :
|
|
96
|
+
switch (tagged._0.kind) {
|
|
97
|
+
case "Number" :
|
|
98
|
+
exit = 2;
|
|
99
|
+
break;
|
|
100
|
+
case "Boolean" :
|
|
101
|
+
exit = 1;
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
switch (exit) {
|
|
112
|
+
case 1 :
|
|
113
|
+
return {
|
|
114
|
+
p: (function (unknown) {
|
|
115
|
+
switch (unknown) {
|
|
116
|
+
case "false" :
|
|
117
|
+
return false;
|
|
118
|
+
case "true" :
|
|
119
|
+
return true;
|
|
120
|
+
default:
|
|
121
|
+
return unknown;
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
case 2 :
|
|
126
|
+
return {
|
|
127
|
+
p: (function (unknown) {
|
|
128
|
+
var $$float = (+unknown);
|
|
129
|
+
if (Number.isNaN($$float)) {
|
|
130
|
+
return unknown;
|
|
131
|
+
} else {
|
|
132
|
+
return $$float;
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function stripInPlace(schema) {
|
|
142
|
+
schema.t.unknownKeys = "Strip";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getSchemaField(schema, fieldName) {
|
|
146
|
+
return schema.t.fields[fieldName];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isNestedFlattenSupported(schema) {
|
|
150
|
+
var match = schema.t;
|
|
151
|
+
if (typeof match !== "object") {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (match.TAG !== "object") {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
if (match.advanced) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
var match$1 = S$RescriptSchema.reverse(schema).t;
|
|
161
|
+
if (typeof match$1 !== "object" || !(match$1.TAG === "object" && !match$1.advanced)) {
|
|
162
|
+
return false;
|
|
163
|
+
} else {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var bearerAuthSchema = S$RescriptSchema.transform(S$RescriptSchema.string, (function (s) {
|
|
169
|
+
return {
|
|
170
|
+
p: (function (string) {
|
|
171
|
+
var match = string.split(" ");
|
|
172
|
+
if (match.length !== 2) {
|
|
173
|
+
return s.fail("Invalid Bearer token", undefined);
|
|
174
|
+
}
|
|
175
|
+
var match$1 = match[0];
|
|
176
|
+
if (match$1 === "Bearer") {
|
|
177
|
+
return match[1];
|
|
178
|
+
} else {
|
|
179
|
+
return s.fail("Invalid Bearer token", undefined);
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
s: (function (token) {
|
|
183
|
+
return "Bearer " + token;
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
}));
|
|
187
|
+
|
|
188
|
+
var basicAuthSchema = S$RescriptSchema.transform(S$RescriptSchema.string, (function (s) {
|
|
189
|
+
return {
|
|
190
|
+
p: (function (string) {
|
|
191
|
+
var match = string.split(" ");
|
|
192
|
+
if (match.length !== 2) {
|
|
193
|
+
return s.fail("Invalid Basic token", undefined);
|
|
194
|
+
}
|
|
195
|
+
var match$1 = match[0];
|
|
196
|
+
if (match$1 === "Basic") {
|
|
197
|
+
return match[1];
|
|
198
|
+
} else {
|
|
199
|
+
return s.fail("Invalid Basic token", undefined);
|
|
200
|
+
}
|
|
201
|
+
}),
|
|
202
|
+
s: (function (token) {
|
|
203
|
+
return "Basic " + token;
|
|
204
|
+
})
|
|
205
|
+
};
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
function params(route) {
|
|
209
|
+
var params$1 = route._rest;
|
|
210
|
+
if (params$1 !== undefined) {
|
|
211
|
+
return params$1;
|
|
212
|
+
}
|
|
213
|
+
var definition = route();
|
|
214
|
+
var params$2;
|
|
215
|
+
if (definition.output) {
|
|
216
|
+
var p = definition.operationId;
|
|
217
|
+
var path = "/" + (
|
|
218
|
+
p !== undefined ? p : route.name
|
|
219
|
+
);
|
|
220
|
+
var inputSchema = S$RescriptSchema.object(function (s) {
|
|
221
|
+
return s.f("body", definition.input);
|
|
222
|
+
});
|
|
223
|
+
stripInPlace(inputSchema);
|
|
224
|
+
inputSchema.f = undefined;
|
|
225
|
+
var outputSchema = S$RescriptSchema.object(function (s) {
|
|
226
|
+
return s.f("data", definition.output);
|
|
227
|
+
});
|
|
228
|
+
stripInPlace(outputSchema);
|
|
229
|
+
outputSchema.f = undefined;
|
|
230
|
+
var response_status = 200;
|
|
231
|
+
var response_dataSchema = definition.input;
|
|
232
|
+
var response = {
|
|
233
|
+
status: response_status,
|
|
234
|
+
description: undefined,
|
|
235
|
+
dataSchema: response_dataSchema,
|
|
236
|
+
emptyData: false,
|
|
237
|
+
schema: outputSchema
|
|
238
|
+
};
|
|
239
|
+
var responsesMap = {};
|
|
240
|
+
responsesMap["200"] = response;
|
|
241
|
+
params$2 = {
|
|
242
|
+
method: "POST",
|
|
243
|
+
path: path,
|
|
244
|
+
pathItems: [path],
|
|
245
|
+
inputSchema: inputSchema,
|
|
246
|
+
outputSchema: outputSchema,
|
|
247
|
+
responses: [response],
|
|
248
|
+
responsesMap: responsesMap,
|
|
249
|
+
isRawBody: false,
|
|
250
|
+
summary: definition.summary,
|
|
251
|
+
description: definition.description,
|
|
252
|
+
deprecated: definition.deprecated,
|
|
253
|
+
operationId: definition.operationId,
|
|
254
|
+
tags: definition.tags
|
|
255
|
+
};
|
|
256
|
+
} else {
|
|
257
|
+
var pathItems = [];
|
|
258
|
+
var pathParams = {};
|
|
259
|
+
parsePath(definition.path, pathItems, pathParams);
|
|
260
|
+
var isRawBody = false;
|
|
261
|
+
var inputSchema$1 = S$RescriptSchema.object(function (s) {
|
|
262
|
+
return definition.input({
|
|
263
|
+
field: (function (fieldName, schema) {
|
|
264
|
+
return s.nested("body").f(fieldName, schema);
|
|
265
|
+
}),
|
|
266
|
+
body: (function (schema) {
|
|
267
|
+
if (isNestedFlattenSupported(schema)) {
|
|
268
|
+
return s.nested("body").flatten(schema);
|
|
269
|
+
} else {
|
|
270
|
+
return s.f("body", schema);
|
|
271
|
+
}
|
|
272
|
+
}),
|
|
273
|
+
rawBody: (function (schema) {
|
|
274
|
+
var match = schema.t;
|
|
275
|
+
var isNonStringBased;
|
|
276
|
+
isNonStringBased = typeof match !== "object" ? (
|
|
277
|
+
match === "string" ? false : true
|
|
278
|
+
) : (
|
|
279
|
+
match.TAG === "literal" && match._0.kind === "String" ? false : true
|
|
280
|
+
);
|
|
281
|
+
if (isNonStringBased) {
|
|
282
|
+
throw new Error("[rescript-rest] Only string-based schemas are allowed in rawBody");
|
|
283
|
+
}
|
|
284
|
+
((isRawBody = true));
|
|
285
|
+
return s.f("body", schema);
|
|
286
|
+
}),
|
|
287
|
+
header: (function (fieldName, schema) {
|
|
288
|
+
return s.nested("headers").f(fieldName.toLowerCase(), coerceSchema(schema));
|
|
289
|
+
}),
|
|
290
|
+
query: (function (fieldName, schema) {
|
|
291
|
+
return s.nested("query").f(fieldName, coerceSchema(schema));
|
|
292
|
+
}),
|
|
293
|
+
param: (function (fieldName, schema) {
|
|
294
|
+
if (!pathParams[fieldName]) {
|
|
295
|
+
throw new Error("[rescript-rest] " + ("Path parameter \"" + fieldName + "\" is not defined in the path"));
|
|
296
|
+
}
|
|
297
|
+
return s.nested("params").f(fieldName, coerceSchema(schema));
|
|
298
|
+
}),
|
|
299
|
+
auth: (function (auth) {
|
|
300
|
+
var tmp;
|
|
301
|
+
tmp = auth === "Bearer" ? bearerAuthSchema : basicAuthSchema;
|
|
302
|
+
return s.nested("headers").f("authorization", tmp);
|
|
303
|
+
})
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
stripInPlace(inputSchema$1);
|
|
307
|
+
inputSchema$1.f = undefined;
|
|
308
|
+
var match = getSchemaField(inputSchema$1, "headers");
|
|
309
|
+
if (match !== undefined) {
|
|
310
|
+
var schema = match.schema;
|
|
311
|
+
stripInPlace(schema);
|
|
312
|
+
schema.f = undefined;
|
|
313
|
+
}
|
|
314
|
+
var match$1 = getSchemaField(inputSchema$1, "params");
|
|
315
|
+
if (match$1 !== undefined) {
|
|
316
|
+
match$1.schema.f = undefined;
|
|
317
|
+
}
|
|
318
|
+
var match$2 = getSchemaField(inputSchema$1, "query");
|
|
319
|
+
if (match$2 !== undefined) {
|
|
320
|
+
match$2.schema.f = undefined;
|
|
321
|
+
}
|
|
322
|
+
var responsesMap$1 = {};
|
|
323
|
+
var responses = [];
|
|
324
|
+
definition.responses.forEach(function (r) {
|
|
325
|
+
var builder = {
|
|
326
|
+
emptyData: true
|
|
327
|
+
};
|
|
328
|
+
var schema = S$RescriptSchema.object(function (s) {
|
|
329
|
+
var status = function (status$1) {
|
|
330
|
+
builder.status = status$1;
|
|
331
|
+
register(responsesMap$1, status$1, builder);
|
|
332
|
+
s.tag("status", status$1);
|
|
333
|
+
};
|
|
334
|
+
var header = function (fieldName, schema) {
|
|
335
|
+
return s.nested("headers").f(fieldName.toLowerCase(), coerceSchema(schema));
|
|
336
|
+
};
|
|
337
|
+
var definition = r({
|
|
338
|
+
status: status,
|
|
339
|
+
description: (function (d) {
|
|
340
|
+
builder.description = d;
|
|
341
|
+
}),
|
|
342
|
+
data: (function (schema) {
|
|
343
|
+
builder.emptyData = false;
|
|
344
|
+
if (isNestedFlattenSupported(schema)) {
|
|
345
|
+
return s.nested("data").flatten(schema);
|
|
346
|
+
} else {
|
|
347
|
+
return s.f("data", schema);
|
|
348
|
+
}
|
|
349
|
+
}),
|
|
350
|
+
field: (function (fieldName, schema) {
|
|
351
|
+
builder.emptyData = false;
|
|
352
|
+
return s.nested("data").f(fieldName, schema);
|
|
353
|
+
}),
|
|
354
|
+
header: header,
|
|
355
|
+
redirect: (function (schema) {
|
|
356
|
+
status(307);
|
|
357
|
+
return header("location", coerceSchema(schema));
|
|
358
|
+
})
|
|
359
|
+
});
|
|
360
|
+
if (builder.emptyData) {
|
|
361
|
+
s.tag("data", null);
|
|
362
|
+
}
|
|
363
|
+
return definition;
|
|
364
|
+
});
|
|
365
|
+
if (builder.status === undefined) {
|
|
366
|
+
register(responsesMap$1, "default", builder);
|
|
367
|
+
}
|
|
368
|
+
stripInPlace(schema);
|
|
369
|
+
schema.f = undefined;
|
|
370
|
+
var dataSchema = getSchemaField(schema, "data").schema;
|
|
371
|
+
builder.dataSchema = dataSchema;
|
|
372
|
+
var match = dataSchema.t;
|
|
373
|
+
if (typeof match === "object" && match.TAG === "literal") {
|
|
374
|
+
var dataTypeValidation = dataSchema.f;
|
|
375
|
+
schema.f = (function (b, inputVar) {
|
|
376
|
+
return dataTypeValidation(b, inputVar + ".data");
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
var match$1 = getSchemaField(schema, "headers");
|
|
380
|
+
if (match$1 !== undefined) {
|
|
381
|
+
var schema$1 = match$1.schema;
|
|
382
|
+
stripInPlace(schema$1);
|
|
383
|
+
schema$1.f = undefined;
|
|
384
|
+
}
|
|
385
|
+
builder.schema = schema;
|
|
386
|
+
responses.push(builder);
|
|
387
|
+
});
|
|
388
|
+
if (responses.length === 0) {
|
|
389
|
+
throw new Error("[rescript-rest] At least single response should be registered");
|
|
390
|
+
}
|
|
391
|
+
params$2 = {
|
|
392
|
+
method: definition.method,
|
|
393
|
+
path: definition.path,
|
|
394
|
+
pathItems: pathItems,
|
|
395
|
+
inputSchema: inputSchema$1,
|
|
396
|
+
outputSchema: S$RescriptSchema.union(responses.map(function (r) {
|
|
397
|
+
return r.schema;
|
|
398
|
+
})),
|
|
399
|
+
responses: responses,
|
|
400
|
+
responsesMap: responsesMap$1,
|
|
401
|
+
isRawBody: isRawBody,
|
|
402
|
+
summary: definition.summary,
|
|
403
|
+
description: definition.description,
|
|
404
|
+
deprecated: definition.deprecated,
|
|
405
|
+
operationId: definition.operationId,
|
|
406
|
+
tags: definition.tags,
|
|
407
|
+
jsonQuery: definition.jsonQuery
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
route._rest = params$2;
|
|
411
|
+
return params$2;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function tokeniseValue(key, value, append) {
|
|
415
|
+
if (Array.isArray(value)) {
|
|
416
|
+
value.forEach(function (v, idx) {
|
|
417
|
+
tokeniseValue(key + "[" + idx.toString() + "]", v, append);
|
|
418
|
+
});
|
|
419
|
+
return ;
|
|
420
|
+
} else if (value === null) {
|
|
421
|
+
return append(key, "");
|
|
422
|
+
} else if (value === (void 0)) {
|
|
423
|
+
return ;
|
|
424
|
+
} else if (typeof value === "object") {
|
|
425
|
+
Object.keys(value).forEach(function (k) {
|
|
426
|
+
tokeniseValue(key + "[" + encodeURIComponent(k) + "]", value[k], append);
|
|
427
|
+
});
|
|
428
|
+
return ;
|
|
429
|
+
} else {
|
|
430
|
+
return append(key, value);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function getCompletePath(baseUrl, pathItems, maybeQuery, maybeParams, jsonQueryOpt) {
|
|
435
|
+
var jsonQuery = jsonQueryOpt !== undefined ? jsonQueryOpt : false;
|
|
436
|
+
var path = baseUrl;
|
|
437
|
+
for(var idx = 0 ,idx_finish = pathItems.length; idx < idx_finish; ++idx){
|
|
438
|
+
var pathItem = pathItems[idx];
|
|
439
|
+
if (typeof pathItem === "string") {
|
|
440
|
+
path = path + pathItem;
|
|
441
|
+
} else {
|
|
442
|
+
var name = pathItem.name;
|
|
443
|
+
var param = maybeParams && maybeParams[name];
|
|
444
|
+
if (param !== undefined) {
|
|
445
|
+
path = path + param;
|
|
446
|
+
} else {
|
|
447
|
+
throw new Error("[rescript-rest] " + ("Path parameter \"" + name + "\" is not defined in input"));
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (maybeQuery !== undefined) {
|
|
452
|
+
var queryItems = [];
|
|
453
|
+
var append = function (key, value) {
|
|
454
|
+
queryItems.push(key + "=" + encodeURIComponent(value));
|
|
455
|
+
};
|
|
456
|
+
var queryNames = Object.keys(maybeQuery);
|
|
457
|
+
for(var idx$1 = 0 ,idx_finish$1 = queryNames.length; idx$1 < idx_finish$1; ++idx$1){
|
|
458
|
+
var queryName = queryNames[idx$1];
|
|
459
|
+
var value = maybeQuery[queryName];
|
|
460
|
+
var key = encodeURIComponent(queryName);
|
|
461
|
+
if (value !== (void 0)) {
|
|
462
|
+
if (jsonQuery) {
|
|
463
|
+
append(key, typeof value === "string" && value !== "true" && value !== "false" && value !== "null" && Number.isNaN(Number(value)) ? value : JSON.stringify(value));
|
|
464
|
+
} else {
|
|
465
|
+
tokeniseValue(key, value, append);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
if (queryItems.length > 0) {
|
|
471
|
+
path = path + "?" + queryItems.join("&");
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
}
|
|
475
|
+
return path;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function url(route, input, baseUrlOpt) {
|
|
479
|
+
var baseUrl = baseUrlOpt !== undefined ? baseUrlOpt : "";
|
|
480
|
+
var match = params(route);
|
|
481
|
+
var data = S$RescriptSchema.reverseConvertOrThrow(input, match.inputSchema);
|
|
482
|
+
return getCompletePath(baseUrl, match.pathItems, data.query, data.params, false);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
var $$global = {
|
|
486
|
+
c: undefined
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
function $$fetch$1(route, input, client) {
|
|
490
|
+
var match = params(route);
|
|
491
|
+
var responsesMap = match.responsesMap;
|
|
492
|
+
var client$1;
|
|
493
|
+
if (client !== undefined) {
|
|
494
|
+
client$1 = client;
|
|
495
|
+
} else {
|
|
496
|
+
var client$2 = $$global.c;
|
|
497
|
+
if (client$2 !== undefined) {
|
|
498
|
+
client$1 = client$2;
|
|
499
|
+
} else {
|
|
500
|
+
throw new Error("[rescript-rest] " + ("Client is not set for the " + match.path + " fetch request. Please, use Rest.setGlobalClient or pass a client explicitly to the Rest.fetch arguments"));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
var data = S$RescriptSchema.reverseConvertOrThrow(input, match.inputSchema);
|
|
504
|
+
if (data.body !== (void 0)) {
|
|
505
|
+
if (!match.isRawBody) {
|
|
506
|
+
data.body = (JSON.stringify(data["body"]));
|
|
507
|
+
}
|
|
508
|
+
if (data.headers === (void 0)) {
|
|
509
|
+
data.headers = {};
|
|
510
|
+
}
|
|
511
|
+
data.headers["content-type"] = "application/json";
|
|
512
|
+
}
|
|
513
|
+
return client$1.fetcher({
|
|
514
|
+
body: data.body,
|
|
515
|
+
headers: data.headers,
|
|
516
|
+
method: match.method,
|
|
517
|
+
path: getCompletePath(client$1.baseUrl, match.pathItems, data.query, data.params, match.jsonQuery)
|
|
518
|
+
}).then(function (fetcherResponse) {
|
|
519
|
+
var responseStatus = fetcherResponse.status;
|
|
520
|
+
var response = responsesMap[responseStatus] || responsesMap[(responseStatus / 100 | 0) + "XX"] || responsesMap["default"];
|
|
521
|
+
if (response !== undefined) {
|
|
522
|
+
try {
|
|
523
|
+
return S$RescriptSchema.parseOrThrow(fetcherResponse, response.schema);
|
|
524
|
+
}
|
|
525
|
+
catch (raw_error){
|
|
526
|
+
var error = Caml_js_exceptions.internalToOCamlException(raw_error);
|
|
527
|
+
if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
|
|
528
|
+
var error$1 = error._1;
|
|
529
|
+
var match = error$1.code;
|
|
530
|
+
if (typeof match === "object" && match.TAG === "InvalidType" && error$1.path === S$RescriptSchema.Path.empty) {
|
|
531
|
+
var message = "Failed parsing response data. Reason: Expected " + getSchemaField(match.expected, "data").schema.n() + ", received " + match.received.data;
|
|
532
|
+
throw new Error("[rescript-rest] " + message);
|
|
533
|
+
}
|
|
534
|
+
var message$1 = "Failed parsing response at " + error$1.path + ". Reason: " + S$RescriptSchema.$$Error.reason(error$1);
|
|
535
|
+
throw new Error("[rescript-rest] " + message$1);
|
|
536
|
+
}
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
} else {
|
|
540
|
+
var error$2 = "Unexpected response status \"" + fetcherResponse.status.toString() + "\"";
|
|
541
|
+
if (fetcherResponse.data && typeof fetcherResponse.data.message === "string") {
|
|
542
|
+
error$2 = error$2 + ". Message: " + fetcherResponse.data.message;
|
|
543
|
+
}
|
|
544
|
+
throw new Error("[rescript-rest] " + error$2);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function client(baseUrl, fetcherOpt) {
|
|
550
|
+
var fetcher = fetcherOpt !== undefined ? fetcherOpt : $$default;
|
|
551
|
+
return {
|
|
552
|
+
baseUrl: baseUrl,
|
|
553
|
+
fetcher: fetcher
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function setGlobalClient(baseUrl, fetcher) {
|
|
558
|
+
var match = $$global.c;
|
|
559
|
+
if (match !== undefined) {
|
|
560
|
+
throw new Error("[rescript-rest] There's already a global client defined. You can have only one global client at a time.");
|
|
561
|
+
}
|
|
562
|
+
$$global.c = client(baseUrl, fetcher);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
var $$Response = {};
|
|
566
|
+
|
|
567
|
+
exports.$$Response = $$Response;
|
|
568
|
+
exports.params = params;
|
|
569
|
+
exports.ApiFetcher = ApiFetcher;
|
|
570
|
+
exports.url = url;
|
|
571
|
+
exports.client = client;
|
|
572
|
+
exports.setGlobalClient = setGlobalClient;
|
|
573
|
+
exports.$$fetch = $$fetch$1;
|
|
574
|
+
/* bearerAuthSchema Not a pure module */
|
package/src/Enum.res
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Graphql Enum Type Variants
|
|
2
|
-
type enum<'a> = {
|
|
3
|
-
name: string,
|
|
4
|
-
variants: array<'a>,
|
|
5
|
-
schema: S.t<'a>,
|
|
6
|
-
default: 'a,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
let make = (~name, ~variants) => {
|
|
10
|
-
name,
|
|
11
|
-
variants,
|
|
12
|
-
schema: S.enum(variants),
|
|
13
|
-
default: switch variants->Belt.Array.get(0) {
|
|
14
|
-
| Some(v) => v
|
|
15
|
-
| None => Js.Exn.raiseError("No variants defined for enum " ++ name)
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module type S = {
|
|
20
|
-
type t
|
|
21
|
-
let enum: enum<t>
|
|
22
|
-
}
|