envio 3.0.0-alpha.21 → 3.0.0-alpha.22

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