envio 3.14.0 → 3.14.1-resolvers.2

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 (42) hide show
  1. package/evm.schema.json +8 -1
  2. package/fuel.schema.json +7 -0
  3. package/index.d.ts +258 -5
  4. package/index.js +10 -0
  5. package/package.json +6 -6
  6. package/src/Bin.res +48 -0
  7. package/src/Bin.res.mjs +34 -1
  8. package/src/Config.res +12 -2
  9. package/src/Config.res.mjs +7 -0
  10. package/src/Env.res +141 -1
  11. package/src/Env.res.mjs +133 -1
  12. package/src/HandlerLoader.res +7 -13
  13. package/src/HandlerLoader.res.mjs +7 -14
  14. package/src/HandlerTypeCheck.res +207 -0
  15. package/src/HandlerTypeCheck.res.mjs +262 -0
  16. package/src/bindings/NodeJs.res +31 -0
  17. package/src/bindings/NodeJs.res.mjs +3 -0
  18. package/src/resolvers/ResolverProcess.res +805 -0
  19. package/src/resolvers/ResolverProcess.res.mjs +662 -0
  20. package/src/resolvers/ResolverQuery.res +313 -0
  21. package/src/resolvers/ResolverQuery.res.mjs +220 -0
  22. package/src/resolvers/collisions.js +108 -0
  23. package/src/resolvers/db.js +363 -0
  24. package/src/resolvers/dispatch.js +259 -0
  25. package/src/resolvers/errors.js +30 -0
  26. package/src/resolvers/graphqlSelection.js +292 -0
  27. package/src/resolvers/hasuraAction.js +84 -0
  28. package/src/resolvers/hasuraApply.js +333 -0
  29. package/src/resolvers/hasuraMetadata.js +137 -0
  30. package/src/resolvers/index.js +123 -0
  31. package/src/resolvers/manifest.js +376 -0
  32. package/src/resolvers/server.js +304 -0
  33. package/src/sources/EvmRpcClient.res +2 -0
  34. package/src/sources/RpcSource.res +17 -4
  35. package/src/sources/RpcSource.res.mjs +23 -5
  36. package/src/sources/SourceManager.res +63 -40
  37. package/src/sources/SourceManager.res.mjs +32 -20
  38. package/src/tui/Tui.res +1 -1
  39. package/src/tui/Tui.res.mjs +1 -1
  40. package/svm.schema.json +7 -0
  41. package/src/HandlerTypeCheck.mjs +0 -14
  42. package/src/HandlerTypeCheckWorker.mjs +0 -68
@@ -0,0 +1,262 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Fs from "fs";
4
+ import * as Path from "path";
5
+ import * as Util from "util";
6
+ import * as Module from "module";
7
+ import * as Process from "process";
8
+ import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
9
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
10
+ import * as Child_process from "child_process";
11
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
12
+
13
+ let fileDiagnostic = /^(.+):\d+:\d+ - error TS(\d+): /;
14
+
15
+ let globalDiagnostic = /^error TS(\d+): /;
16
+
17
+ let summary = /^Found \d+ errors?\b/;
18
+
19
+ let thrownError = /^\w*Error: /;
20
+
21
+ function lines(output) {
22
+ return output.replaceAll("\r\n", "\n").split("\n");
23
+ }
24
+
25
+ function findUp(_directory, name) {
26
+ while (true) {
27
+ let directory = _directory;
28
+ let candidate = Path.resolve(directory, name);
29
+ if (Fs.existsSync(candidate)) {
30
+ return candidate;
31
+ }
32
+ let parent = Path.dirname(directory);
33
+ if (parent === directory) {
34
+ return;
35
+ }
36
+ _directory = parent;
37
+ continue;
38
+ };
39
+ }
40
+
41
+ function resolveTsc(cwd) {
42
+ try {
43
+ let manifest = Module.createRequire(Path.resolve(cwd, "package.json")).resolve("typescript/package.json");
44
+ let fields = JSON.parse(Fs.readFileSync(manifest, "utf8"));
45
+ let bin;
46
+ if (typeof fields === "object" && fields !== null && !Array.isArray(fields)) {
47
+ let match = fields["bin"];
48
+ if (match !== undefined && !(match === null || Array.isArray(match))) {
49
+ switch (typeof match) {
50
+ case "string" :
51
+ bin = match;
52
+ break;
53
+ case "object" :
54
+ let match$1 = match["tsc"];
55
+ bin = typeof match$1 === "string" ? match$1 : undefined;
56
+ break;
57
+ default:
58
+ bin = undefined;
59
+ }
60
+ } else {
61
+ bin = undefined;
62
+ }
63
+ } else {
64
+ bin = undefined;
65
+ }
66
+ return Stdlib_Option.map(bin, bin => Path.resolve(Path.dirname(manifest), bin));
67
+ } catch (exn) {
68
+ return;
69
+ }
70
+ }
71
+
72
+ function runTsc(tsc, cwd, args) {
73
+ return new Promise((resolve, param) => {
74
+ Child_process.execFile(Process.execPath, [tsc].concat(args), {
75
+ cwd: cwd,
76
+ timeout: 30000,
77
+ maxBuffer: Number.POSITIVE_INFINITY
78
+ }, (error, stdout, stderr) => resolve({
79
+ error: error === null ? undefined : Primitive_option.some(error),
80
+ output: Util.stripVTControlCharacters(stdout + stderr)
81
+ }));
82
+ });
83
+ }
84
+
85
+ function canStopTypeChecking(param) {
86
+ let code = param.code;
87
+ if (Stdlib_Option.isNone(param.file) || code < 2000) {
88
+ return true;
89
+ } else if (code >= 5000) {
90
+ return code < 7000;
91
+ } else {
92
+ return false;
93
+ }
94
+ }
95
+
96
+ function parse(output, cwd) {
97
+ let relative = file => Path.relative(cwd, Path.resolve(cwd, file));
98
+ let diagnostics = [];
99
+ let programFiles = new Set();
100
+ let current = {
101
+ contents: undefined
102
+ };
103
+ let start = (file, code, line) => {
104
+ let diagnostic_code = Stdlib_Option.getOr(Stdlib_Int.fromString(code, undefined), 0);
105
+ let diagnostic_lines = [line];
106
+ let diagnostic = {
107
+ file: file,
108
+ code: diagnostic_code,
109
+ lines: diagnostic_lines
110
+ };
111
+ diagnostics.push(diagnostic);
112
+ current.contents = diagnostic;
113
+ };
114
+ lines(output).forEach(line => {
115
+ let match = Stdlib_Option.map(Primitive_option.fromNullable(fileDiagnostic.exec(line)), prim => prim.slice(1));
116
+ let match$1 = Stdlib_Option.map(Primitive_option.fromNullable(globalDiagnostic.exec(line)), prim => prim.slice(1));
117
+ let exit = 0;
118
+ if (match !== undefined && match.length === 2) {
119
+ let file = match[0];
120
+ if (file !== undefined) {
121
+ let code = match[1];
122
+ if (code !== undefined) {
123
+ return start(relative(file), code, line);
124
+ }
125
+ exit = 2;
126
+ } else {
127
+ exit = 2;
128
+ }
129
+ } else {
130
+ exit = 2;
131
+ }
132
+ if (exit === 2 && match$1 !== undefined && match$1.length === 1) {
133
+ let code$1 = match$1[0];
134
+ if (code$1 !== undefined) {
135
+ return start(undefined, code$1, line);
136
+ }
137
+ }
138
+ if (Path.isAbsolute(line)) {
139
+ programFiles.add(relative(line));
140
+ current.contents = undefined;
141
+ return;
142
+ } else if (summary.test(line)) {
143
+ current.contents = undefined;
144
+ return;
145
+ } else {
146
+ return Stdlib_Option.forEach(current.contents, diagnostic => {
147
+ diagnostic.lines.push(line);
148
+ });
149
+ }
150
+ });
151
+ return [
152
+ diagnostics,
153
+ programFiles
154
+ ];
155
+ }
156
+
157
+ function failure(param) {
158
+ let output = param.output;
159
+ let error = param.error;
160
+ if (error !== undefined && error.killed) {
161
+ return `Skipped the handler type check: tsc didn't finish within ` + (30).toString() + ` seconds.`;
162
+ }
163
+ let reason = Stdlib_Option.getOr(lines(output).find(line => thrownError.test(line)), output.trim());
164
+ return `Skipped the handler type check: tsc failed to run:\n\n` + reason;
165
+ }
166
+
167
+ async function check(cwd, files) {
168
+ let skip = warning => {
169
+ if (Fs.existsSync(Path.resolve(cwd, "rescript.json"))) {
170
+ return "Passed";
171
+ } else {
172
+ return {
173
+ TAG: "Skipped",
174
+ _0: warning
175
+ };
176
+ }
177
+ };
178
+ let match = resolveTsc(cwd);
179
+ let match$1 = findUp(cwd, "tsconfig.json");
180
+ if (match === undefined) {
181
+ return skip("Skipped the handler type check: typescript isn't installed. Add it to devDependencies to type-check handlers on start.");
182
+ }
183
+ if (match$1 === undefined) {
184
+ return skip("Skipped the handler type check: no tsconfig.json found. Add one, like the one envio init creates, to type-check handlers on start.");
185
+ }
186
+ let run = await runTsc(match, cwd, [
187
+ "--project",
188
+ match$1,
189
+ "--noEmit",
190
+ "--incremental",
191
+ "false",
192
+ "--composite",
193
+ "false",
194
+ "--listFiles",
195
+ "--explainFiles",
196
+ "false",
197
+ "--pretty"
198
+ ]);
199
+ let match$2 = parse(run.output, cwd);
200
+ let programFiles = match$2[1];
201
+ let diagnostics = match$2[0];
202
+ let report = diagnostics => diagnostics.map(param => param.lines.join("\n").trimEnd()).join("\n\n");
203
+ let handlers = files.map(file => Path.relative(cwd, file));
204
+ let isHandler = param => Stdlib_Option.mapOr(param.file, false, file => handlers.includes(file));
205
+ let errors = diagnostics.filter(isHandler);
206
+ let stopping = diagnostics.filter(diagnostic => {
207
+ if (isHandler(diagnostic)) {
208
+ return false;
209
+ } else {
210
+ return canStopTypeChecking(diagnostic);
211
+ }
212
+ });
213
+ let unchecked = handlers.filter(file => !programFiles.has(file));
214
+ if (Stdlib_Option.isSome(run.error) && diagnostics.length === 0) {
215
+ return {
216
+ TAG: "Skipped",
217
+ _0: failure(run)
218
+ };
219
+ }
220
+ if (errors.length !== 0) {
221
+ return {
222
+ TAG: "TypeErrors",
223
+ _0: report(errors)
224
+ };
225
+ }
226
+ if (stopping.length !== 0) {
227
+ let reason = report(stopping);
228
+ return {
229
+ TAG: "Skipped",
230
+ _0: `Skipped the handler type check: tsc can't check the handlers until these errors are fixed:\n\n` + reason
231
+ };
232
+ }
233
+ if (unchecked.length === 0) {
234
+ return "Passed";
235
+ }
236
+ let names = unchecked.join(", ");
237
+ let tsconfig = Path.relative(cwd, match$1);
238
+ let pronoun = unchecked.length === 1 ? "it" : "them";
239
+ return {
240
+ TAG: "Skipped",
241
+ _0: `Skipped the handler type check: ` + tsconfig + ` doesn't include ` + names + `. Add ` + pronoun + ` to "include" to type-check ` + pronoun + ` on start.`
242
+ };
243
+ }
244
+
245
+ let timeoutSeconds = 30;
246
+
247
+ export {
248
+ timeoutSeconds,
249
+ fileDiagnostic,
250
+ globalDiagnostic,
251
+ summary,
252
+ thrownError,
253
+ lines,
254
+ findUp,
255
+ resolveTsc,
256
+ runTsc,
257
+ canStopTypeChecking,
258
+ parse,
259
+ failure,
260
+ check,
261
+ }
262
+ /* fs Not a pure module */
@@ -39,6 +39,15 @@ module Util = {
39
39
  @module("util") external inspect: ('a, inspectOptions) => string = "inspect"
40
40
 
41
41
  let inspectObj = a => inspect(a, {showHidden: false, depth: Null, colors: true})
42
+
43
+ @module("util") external stripVTControlCharacters: string => string = "stripVTControlCharacters"
44
+ }
45
+
46
+ module Module = {
47
+ type require
48
+
49
+ @module("module") external createRequire: string => require = "createRequire"
50
+ @send external resolve: (require, string) => string = "resolve"
42
51
  }
43
52
 
44
53
  module Process = {
@@ -165,6 +174,23 @@ module ChildProcess = {
165
174
  @module("child_process")
166
175
  external execWithOptions: (string, execOptions, callback) => unit = "exec"
167
176
 
177
+ type execFileOptions = {
178
+ cwd?: string,
179
+ timeout?: int,
180
+ maxBuffer?: float,
181
+ }
182
+
183
+ // `killed` is set when the timeout stopped the child.
184
+ type execFileError = {killed: bool}
185
+
186
+ @module("child_process")
187
+ external execFile: (
188
+ string,
189
+ array<string>,
190
+ execFileOptions,
191
+ (Null.t<execFileError>, string, string) => unit,
192
+ ) => unit = "execFile"
193
+
168
194
  // One of a child's stdio slots, present only for a slot the parent asked to
169
195
  // pipe rather than inherit.
170
196
  module Stream = {
@@ -225,6 +251,8 @@ module Path = {
225
251
 
226
252
  @module("path") external join: (t, string) => t = "join"
227
253
  @module("path") external dirname: string => t = "dirname"
254
+ @module("path") external relative: (string, string) => string = "relative"
255
+ @module("path") external isAbsolute: string => bool = "isAbsolute"
228
256
 
229
257
  external toString: t => string = "%identity"
230
258
 
@@ -275,6 +303,9 @@ module Fs = {
275
303
  mode?: int,
276
304
  }
277
305
 
306
+ @module("fs") external existsSync: string => bool = "existsSync"
307
+ @module("fs") external readFileSync: (string, @as("utf8") _) => string = "readFileSync"
308
+
278
309
  module Promises = {
279
310
  @module("fs") @scope("promises")
280
311
  external writeFile: (
@@ -16,6 +16,8 @@ let Util$1 = {
16
16
  inspectObj: inspectObj
17
17
  };
18
18
 
19
+ let Module = {};
20
+
19
21
  let Process = {};
20
22
 
21
23
  let empty = globalThis.Buffer.alloc(0);
@@ -59,6 +61,7 @@ let Fs = {
59
61
 
60
62
  export {
61
63
  Util$1 as Util,
64
+ Module,
62
65
  Process,
63
66
  Buffer,
64
67
  V8,