envio 2.26.0-alpha.7 → 2.26.0-alpha.9

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.
@@ -1,23 +1,15 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
- var Fs = require("fs");
5
- var Path = require("path");
6
4
  var $$Array = require("rescript/lib/js/array.js");
7
5
  var Table = require("./db/Table.res.js");
8
6
  var Utils = require("./Utils.res.js");
9
7
  var Js_exn = require("rescript/lib/js/js_exn.js");
10
8
  var Schema = require("./db/Schema.res.js");
11
- var Js_dict = require("rescript/lib/js/js_dict.js");
12
- var Logging = require("./Logging.res.js");
13
- var $$Promise = require("./bindings/Promise.res.js");
14
- var Internal = require("./Internal.res.js");
15
9
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
16
- var Caml_array = require("rescript/lib/js/caml_array.js");
17
10
  var Belt_Option = require("rescript/lib/js/belt_Option.js");
18
11
  var Caml_option = require("rescript/lib/js/caml_option.js");
19
12
  var Persistence = require("./Persistence.res.js");
20
- var Child_process = require("child_process");
21
13
  var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
22
14
  var S$RescriptSchema = require("rescript-schema/src/S.res.js");
23
15
  var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
@@ -67,11 +59,11 @@ function makeCreateTableQuery(table, pgSchema) {
67
59
  ) + ");";
68
60
  }
69
61
 
70
- function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesOpt, enumsOpt, isEmptyPgSchemaOpt) {
62
+ function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesOpt, enumsOpt, reuseExistingPgSchemaOpt) {
71
63
  var generalTables = generalTablesOpt !== undefined ? generalTablesOpt : [];
72
64
  var entities = entitiesOpt !== undefined ? entitiesOpt : [];
73
65
  var enums = enumsOpt !== undefined ? enumsOpt : [];
74
- var isEmptyPgSchema = isEmptyPgSchemaOpt !== undefined ? isEmptyPgSchemaOpt : false;
66
+ var reuseExistingPgSchema = reuseExistingPgSchemaOpt !== undefined ? reuseExistingPgSchemaOpt : false;
75
67
  var allTables = $$Array.copy(generalTables);
76
68
  var allEntityTables = [];
77
69
  entities.forEach(function (entity) {
@@ -82,7 +74,7 @@ function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesO
82
74
  var derivedSchema = Schema.make(allEntityTables);
83
75
  var query = {
84
76
  contents: (
85
- isEmptyPgSchema && pgSchema === "public" ? "" : "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";\n"
77
+ reuseExistingPgSchema ? "" : "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";\n"
86
78
  ) + ("GRANT ALL ON SCHEMA \"" + pgSchema + "\" TO \"" + pgUser + "\";\nGRANT ALL ON SCHEMA \"" + pgSchema + "\" TO public;")
87
79
  };
88
80
  enums.forEach(function (enumConfig) {
@@ -112,7 +104,6 @@ function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesO
112
104
  query.contents = query.contents + "\n" + makeCreateIndexQuery(derivedFromField.derivedFromEntity, [indexField], pgSchema);
113
105
  });
114
106
  });
115
- functionsQuery.contents = functionsQuery.contents + "\n" + ("CREATE OR REPLACE FUNCTION get_cache_row_count(table_name text) \n RETURNS integer AS $$\n DECLARE\n result integer;\n BEGIN\n EXECUTE format('SELECT COUNT(*) FROM \"" + pgSchema + "\".%I', table_name) INTO result;\n RETURN result;\n END;\n $$ LANGUAGE plpgsql;");
116
107
  return [query.contents].concat(functionsQuery.contents !== "" ? [functionsQuery.contents] : []);
117
108
  }
118
109
 
@@ -276,7 +267,7 @@ async function setOrThrow(sql, items, table, itemSchema, pgSchema) {
276
267
  throw {
277
268
  RE_EXN_ID: Persistence.StorageError,
278
269
  message: "Failed to insert items into table \"" + table.tableName + "\"",
279
- reason: Internal.prettifyExn(exn),
270
+ reason: exn,
280
271
  Error: new Error()
281
272
  };
282
273
  }
@@ -297,79 +288,7 @@ function makeSchemaTableNamesQuery(pgSchema) {
297
288
  return "SELECT table_name FROM information_schema.tables WHERE table_schema = '" + pgSchema + "';";
298
289
  }
299
290
 
300
- var cacheTablePrefix = "envio_effect_";
301
-
302
- var cacheTablePrefixLength = cacheTablePrefix.length;
303
-
304
- function makeSchemaCacheTableInfoQuery(pgSchema) {
305
- return "SELECT \n t.table_name,\n get_cache_row_count(t.table_name) as count\n FROM information_schema.tables t\n WHERE t.table_schema = '" + pgSchema + "' \n AND t.table_name LIKE '" + cacheTablePrefix + "%';";
306
- }
307
-
308
- var psqlExecState = {
309
- contents: "Unknown"
310
- };
311
-
312
- async function getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort) {
313
- var promise = psqlExecState.contents;
314
- if (typeof promise === "object") {
315
- if (promise.TAG === "Pending") {
316
- return await promise._0;
317
- } else {
318
- return promise._0;
319
- }
320
- }
321
- var promise$1 = new Promise((function (resolve, _reject) {
322
- var binary = "psql";
323
- Child_process.exec(binary + " --version", (function (error, param, param$1) {
324
- if (error === null) {
325
- return resolve({
326
- TAG: "Ok",
327
- _0: binary + " -h " + pgHost + " -p " + pgPort.toString() + " -U " + pgUser + " -d " + pgDatabase
328
- });
329
- }
330
- var binary$1 = "docker-compose exec -T -u " + pgUser + " envio-postgres psql";
331
- Child_process.exec(binary$1 + " --version", (function (error, param, param$1) {
332
- if (error === null) {
333
- return resolve({
334
- TAG: "Ok",
335
- _0: binary$1 + " -h " + pgHost + " -p " + (5432).toString() + " -U " + pgUser + " -d " + pgDatabase
336
- });
337
- } else {
338
- return resolve({
339
- TAG: "Error",
340
- _0: "Please check if \"psql\" binary is installed or docker-compose is running for the local indexer."
341
- });
342
- }
343
- }));
344
- }));
345
- }));
346
- psqlExecState.contents = {
347
- TAG: "Pending",
348
- _0: promise$1
349
- };
350
- var result = await promise$1;
351
- psqlExecState.contents = {
352
- TAG: "Resolved",
353
- _0: result
354
- };
355
- return result;
356
- }
357
-
358
- function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onInitialize, onNewTables) {
359
- var psqlExecOptions_env = Js_dict.fromArray([
360
- [
361
- "PGPASSWORD",
362
- pgPassword
363
- ],
364
- [
365
- "PATH",
366
- process.env.PATH
367
- ]
368
- ]);
369
- var psqlExecOptions = {
370
- env: psqlExecOptions_env
371
- };
372
- var cacheDirPath = Path.resolve("..", ".envio", "cache");
291
+ function make(sql, pgSchema, pgUser) {
373
292
  var isInitialized = async function () {
374
293
  var envioTables = await sql.unsafe("SELECT table_schema FROM information_schema.tables WHERE table_schema = '" + pgSchema + "' AND table_name = '" + eventSyncStateTableName + "';");
375
294
  return Utils.$$Array.notEmpty(envioTables);
@@ -390,10 +309,19 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onI
390
309
  return sql.unsafe(query);
391
310
  });
392
311
  });
393
- if (onInitialize !== undefined) {
394
- return await onInitialize();
395
- }
396
-
312
+ };
313
+ var loadEffectCaches = async function () {
314
+ var schemaTableNames = await sql.unsafe(makeSchemaTableNamesQuery(pgSchema));
315
+ return Belt_Array.keepMapU(schemaTableNames, (function (schemaTableName) {
316
+ if (schemaTableName.table_name.startsWith("effect_cache_")) {
317
+ return {
318
+ name: schemaTableName.table_name,
319
+ size: 0,
320
+ table: undefined
321
+ };
322
+ }
323
+
324
+ }));
397
325
  };
398
326
  var loadByIdsOrThrow = async function (ids, table, rowsSchema) {
399
327
  var rows;
@@ -467,167 +395,13 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, onI
467
395
  var setOrThrow$1 = function (items, table, itemSchema) {
468
396
  return setOrThrow(sql, items, table, itemSchema, pgSchema);
469
397
  };
470
- var setEffectCacheOrThrow = async function (effectName, ids, outputs, outputSchema, initialize) {
471
- var table = Table.mkTable(cacheTablePrefix + effectName, [], [
472
- Table.mkField("id", "TEXT", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
473
- Table.mkField("output", "JSONB", S$RescriptSchema.json(false), undefined, undefined, undefined, undefined, undefined, undefined)
474
- ]);
475
- if (initialize) {
476
- await sql.unsafe(makeCreateTableQuery(table, pgSchema));
477
- if (onNewTables !== undefined) {
478
- await onNewTables([table.tableName]);
479
- }
480
-
481
- }
482
- var items = [];
483
- for(var idx = 0 ,idx_finish = outputs.length; idx < idx_finish; ++idx){
484
- items.push({
485
- id: Caml_array.get(ids, idx),
486
- output: Caml_array.get(outputs, idx)
487
- });
488
- }
489
- return await setOrThrow$1(items, table, S$RescriptSchema.schema(function (s) {
490
- return {
491
- id: s.m(S$RescriptSchema.string),
492
- output: s.m(outputSchema)
493
- };
494
- }));
495
- };
496
- var dumpEffectCache = async function () {
497
- try {
498
- var cacheTableInfo = (await sql.unsafe(makeSchemaCacheTableInfoQuery(pgSchema))).filter(function (i) {
499
- return i.count > 0;
500
- });
501
- if (!Utils.$$Array.notEmpty(cacheTableInfo)) {
502
- return ;
503
- }
504
- try {
505
- await Fs.promises.access(cacheDirPath);
506
- }
507
- catch (exn){
508
- await Fs.promises.mkdir(cacheDirPath, {
509
- recursive: true
510
- });
511
- }
512
- var psqlExec = await getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort);
513
- if (psqlExec.TAG !== "Ok") {
514
- return Logging.error("Failed to dump cache. " + psqlExec._0);
515
- }
516
- var psqlExec$1 = psqlExec._0;
517
- Logging.info("Dumping cache: " + cacheTableInfo.map(function (param) {
518
- return param.table_name + " (" + String(param.count) + " rows)";
519
- }).join(", "));
520
- var promises = cacheTableInfo.map(async function (param) {
521
- var tableName = param.table_name;
522
- var cacheName = tableName.slice(cacheTablePrefixLength);
523
- var outputFile = Path.join(cacheDirPath, cacheName + ".tsv");
524
- var command = psqlExec$1 + " -c 'COPY \"" + pgSchema + "\".\"" + tableName + "\" TO STDOUT WITH (FORMAT text, HEADER);' > " + outputFile;
525
- return new Promise((function (resolve, reject) {
526
- Child_process.exec(command, psqlExecOptions, (function (error, stdout, param) {
527
- if (error === null) {
528
- return resolve(stdout);
529
- } else {
530
- return reject(error);
531
- }
532
- }));
533
- }));
534
- });
535
- await Promise.all(promises);
536
- return Logging.info("Successfully dumped cache to " + cacheDirPath);
537
- }
538
- catch (raw_exn){
539
- var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn);
540
- return Logging.errorWithExn(Internal.prettifyExn(exn$1), "Failed to dump cache.");
541
- }
542
- };
543
- var restoreEffectCache = async function (withUpload) {
544
- if (withUpload) {
545
- var nothingToUploadErrorMessage = "Nothing to upload.";
546
- var match = await Promise.all([
547
- $$Promise.$$catch(Fs.promises.readdir(cacheDirPath).then(function (e) {
548
- return {
549
- TAG: "Ok",
550
- _0: e
551
- };
552
- }), (function (param) {
553
- return Promise.resolve({
554
- TAG: "Error",
555
- _0: nothingToUploadErrorMessage
556
- });
557
- })),
558
- getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort)
559
- ]);
560
- var exit = 0;
561
- var message;
562
- var entries = match[0];
563
- if (entries.TAG === "Ok") {
564
- var psqlExec = match[1];
565
- if (psqlExec.TAG === "Ok") {
566
- var psqlExec$1 = psqlExec._0;
567
- var cacheFiles = entries._0.filter(function (entry) {
568
- return entry.endsWith(".tsv");
569
- });
570
- await Promise.all(cacheFiles.map(function (entry) {
571
- var cacheName = entry.slice(0, -4);
572
- var tableName = cacheTablePrefix + cacheName;
573
- var table = Table.mkTable(tableName, [], [
574
- Table.mkField("id", "TEXT", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
575
- Table.mkField("output", "JSONB", S$RescriptSchema.json(false), undefined, undefined, undefined, undefined, undefined, undefined)
576
- ]);
577
- return sql.unsafe(makeCreateTableQuery(table, pgSchema)).then(function () {
578
- var inputFile = Path.join(cacheDirPath, entry);
579
- var command = psqlExec$1 + " -c 'COPY \"" + pgSchema + "\".\"" + tableName + "\" FROM STDIN WITH (FORMAT text, HEADER);' < " + inputFile;
580
- return new Promise((function (resolve, reject) {
581
- Child_process.exec(command, psqlExecOptions, (function (error, stdout, param) {
582
- if (error === null) {
583
- return resolve(stdout);
584
- } else {
585
- return reject(error);
586
- }
587
- }));
588
- }));
589
- });
590
- }));
591
- Logging.info("Successfully uploaded cache.");
592
- } else {
593
- message = match[1]._0;
594
- exit = 1;
595
- }
596
- } else {
597
- message = entries._0;
598
- exit = 1;
599
- }
600
- if (exit === 1) {
601
- if (message === nothingToUploadErrorMessage) {
602
- Logging.info("No cache found to upload.");
603
- } else {
604
- Logging.error("Failed to upload cache, continuing without it. " + message);
605
- }
606
- }
607
-
608
- }
609
- var cacheTableInfo = await sql.unsafe(makeSchemaCacheTableInfoQuery(pgSchema));
610
- if (withUpload && Utils.$$Array.notEmpty(cacheTableInfo) && onNewTables !== undefined) {
611
- await onNewTables(cacheTableInfo.map(function (info) {
612
- return info.table_name;
613
- }));
614
- }
615
- return cacheTableInfo.map(function (info) {
616
- return {
617
- effectName: info.table_name.slice(cacheTablePrefixLength),
618
- count: info.count
619
- };
620
- });
621
- };
622
398
  return {
623
399
  isInitialized: isInitialized,
624
400
  initialize: initialize,
401
+ loadEffectCaches: loadEffectCaches,
625
402
  loadByIdsOrThrow: loadByIdsOrThrow,
626
403
  loadByFieldOrThrow: loadByFieldOrThrow,
627
- setOrThrow: setOrThrow$1,
628
- setEffectCacheOrThrow: setEffectCacheOrThrow,
629
- dumpEffectCache: dumpEffectCache,
630
- restoreEffectCache: restoreEffectCache
404
+ setOrThrow: setOrThrow$1
631
405
  };
632
406
  }
633
407
 
@@ -654,9 +428,5 @@ exports.setQueryCache = setQueryCache;
654
428
  exports.setOrThrow = setOrThrow;
655
429
  exports.setEntityHistoryOrThrow = setEntityHistoryOrThrow;
656
430
  exports.makeSchemaTableNamesQuery = makeSchemaTableNamesQuery;
657
- exports.cacheTablePrefix = cacheTablePrefix;
658
- exports.cacheTablePrefixLength = cacheTablePrefixLength;
659
- exports.makeSchemaCacheTableInfoQuery = makeSchemaCacheTableInfoQuery;
660
- exports.getConnectedPsqlExec = getConnectedPsqlExec;
661
431
  exports.make = make;
662
432
  /* pgEncodingErrorSchema Not a pure module */
@@ -590,15 +590,3 @@ module EffectCallsCount = {
590
590
  gauge->SafeGauge.handleInt(~labels=effectName, ~value=callsCount)
591
591
  }
592
592
  }
593
-
594
- module EffectCacheCount = {
595
- let gauge = SafeGauge.makeOrThrow(
596
- ~name="envio_effect_cache_count",
597
- ~help="The number of items in the effect cache.",
598
- ~labelSchema=effectLabelsSchema,
599
- )
600
-
601
- let set = (~count, ~effectName) => {
602
- gauge->SafeGauge.handleInt(~labels=effectName, ~value=count)
603
- }
604
- }
@@ -700,17 +700,6 @@ var EffectCallsCount = {
700
700
  set: set$21
701
701
  };
702
702
 
703
- var gauge$22 = makeOrThrow$1("envio_effect_cache_count", "The number of items in the effect cache.", effectLabelsSchema);
704
-
705
- function set$22(count, effectName) {
706
- handleInt$1(gauge$22, effectName, count);
707
- }
708
-
709
- var EffectCacheCount = {
710
- gauge: gauge$22,
711
- set: set$22
712
- };
713
-
714
703
  exports.loadEntitiesDurationCounter = loadEntitiesDurationCounter;
715
704
  exports.eventRouterDurationCounter = eventRouterDurationCounter;
716
705
  exports.executeBatchDurationCounter = executeBatchDurationCounter;
@@ -758,5 +747,4 @@ exports.ProgressBlockNumber = ProgressBlockNumber;
758
747
  exports.ProgressEventsCount = ProgressEventsCount;
759
748
  exports.effectLabelsSchema = effectLabelsSchema;
760
749
  exports.EffectCallsCount = EffectCallsCount;
761
- exports.EffectCacheCount = EffectCacheCount;
762
750
  /* loadEntitiesDurationCounter Not a pure module */
package/src/Utils.res CHANGED
@@ -516,17 +516,13 @@ module Proxy = {
516
516
  }
517
517
 
518
518
  module Hash = {
519
- // Hash to JSON string. No specific reason for this,
520
- // just to stick to at least some sort of spec.
521
- // After Sury v11 is out we'll be able to do it with schema
522
519
  let rec makeOrThrow = (any: 'a): string => {
523
520
  switch any->Js.typeof {
524
- | "string" => `"${any->magic}"` // Ideally should escape here,
525
- // but since we don't parse it back, it's fine to keep it super simple
521
+ | "string" => any->magic
526
522
  | "number" => any->magic->Js.Int.toString
527
- | "bigint" => `"${any->magic->BigInt.toString}"`
523
+ | "bigint" => any->magic->BigInt.toString
528
524
  | "boolean" => any->magic ? "true" : "false"
529
- | "undefined" => "null"
525
+ | "undefined" => "undefined"
530
526
  | "object" =>
531
527
  if any === %raw(`null`) {
532
528
  "null"
@@ -534,10 +530,7 @@ module Hash = {
534
530
  let any: array<'a> = any->magic
535
531
  let hash = ref("[")
536
532
  for i in 0 to any->Js.Array2.length - 1 {
537
- if i !== 0 {
538
- hash := hash.contents ++ ","
539
- }
540
- hash := hash.contents ++ any->Js.Array2.unsafe_get(i)->makeOrThrow
533
+ hash := hash.contents ++ any->Js.Array2.unsafe_get(i)->makeOrThrow ++ ","
541
534
  }
542
535
  hash.contents ++ "]"
543
536
  } else {
@@ -548,20 +541,14 @@ module Hash = {
548
541
  let keys = any->Js.Dict.keys->Js.Array2.sortInPlace
549
542
  for i in 0 to keys->Js.Array2.length - 1 {
550
543
  let key = keys->Js.Array2.unsafe_get(i)
551
- let value = any->Js.Dict.unsafeGet(key)
552
- if i !== 0 {
553
- hash := hash.contents ++ ","
554
- }
555
- if value !== %raw(`undefined`) {
556
- // Ideally should escape and wrap the key in double quotes
557
- // but since we don't need to decode the hash,
558
- // it's fine to keep it super simple
559
- hash := hash.contents ++ `"${key}":${any->Js.Dict.unsafeGet(key)->makeOrThrow}`
560
- }
544
+ // Ideally should escape and wrap the key in double quotes
545
+ // but since we don't need to decode the hash,
546
+ // it's fine to keep it super simple
547
+ hash := hash.contents ++ key ++ ":" ++ any->Js.Dict.unsafeGet(key)->makeOrThrow ++ ","
561
548
  }
562
549
  hash.contents ++ "}"
563
550
  } else if constructor["name"] === "BigNumber" {
564
- `"${(any->magic)["toString"]()}"`
551
+ (any->magic)["toString"]()
565
552
  } else {
566
553
  Js.Exn.raiseError(`Don't know how to serialize ${(constructor->magic)["name"]}`)
567
554
  }
package/src/Utils.res.js CHANGED
@@ -455,14 +455,13 @@ var $$Proxy = {};
455
455
  function makeOrThrow(any) {
456
456
  var $$typeof = typeof any;
457
457
  switch ($$typeof) {
458
- case "bigint" :
459
- return "\"" + any.toString() + "\"";
460
458
  case "boolean" :
461
459
  if (any) {
462
460
  return "true";
463
461
  } else {
464
462
  return "false";
465
463
  }
464
+ case "bigint" :
466
465
  case "number" :
467
466
  return any.toString();
468
467
  case "object" :
@@ -472,17 +471,14 @@ function makeOrThrow(any) {
472
471
  if (Array.isArray(any)) {
473
472
  var hash = "[";
474
473
  for(var i = 0 ,i_finish = any.length; i < i_finish; ++i){
475
- if (i !== 0) {
476
- hash = hash + ",";
477
- }
478
- hash = hash + makeOrThrow(any[i]);
474
+ hash = hash + makeOrThrow(any[i]) + ",";
479
475
  }
480
476
  return hash + "]";
481
477
  }
482
478
  var constructor = any["constructor"];
483
479
  if (constructor !== Object) {
484
480
  if (constructor.name === "BigNumber") {
485
- return "\"" + any.toString() + "\"";
481
+ return any.toString();
486
482
  } else {
487
483
  return Js_exn.raiseError("Don't know how to serialize " + constructor.name);
488
484
  }
@@ -491,23 +487,16 @@ function makeOrThrow(any) {
491
487
  var keys = Object.keys(any).sort();
492
488
  for(var i$1 = 0 ,i_finish$1 = keys.length; i$1 < i_finish$1; ++i$1){
493
489
  var key = keys[i$1];
494
- var value = any[key];
495
- if (i$1 !== 0) {
496
- hash$1 = hash$1 + ",";
497
- }
498
- if (value !== undefined) {
499
- hash$1 = hash$1 + ("\"" + key + "\":" + makeOrThrow(any[key]));
500
- }
501
-
490
+ hash$1 = hash$1 + key + ":" + makeOrThrow(any[key]) + ",";
502
491
  }
503
492
  return hash$1 + "}";
504
493
  case "string" :
505
- return "\"" + any + "\"";
494
+ return any;
506
495
  case "function" :
507
496
  case "symbol" :
508
497
  return any.toString();
509
498
  case "undefined" :
510
- return "null";
499
+ return "undefined";
511
500
  default:
512
501
  return Js_exn.raiseError("Don't know how to serialize " + $$typeof);
513
502
  }
@@ -27,7 +27,7 @@ type middleware = (req, res, unit => unit) => unit
27
27
 
28
28
  type server
29
29
 
30
- @send external listen: (app, ~port: int, ~host: string) => server = "listen"
30
+ @send external listen: (app, int) => server = "listen"
31
31
 
32
32
  // res methods
33
33
  @send external sendStatus: (res, int) => unit = "sendStatus"
@@ -4,25 +4,35 @@ type t
4
4
  type exitCode = | @as(0) Success | @as(1) Failure
5
5
  @send external exitWithCode: (t, exitCode) => unit = "exit"
6
6
 
7
- module Process = {
8
- type t = {env: Js.Dict.t<string>}
9
- @module external process: t = "process"
10
- }
11
-
12
- module ChildProcess = {
13
- type execOptions = {
14
- cwd?: string,
15
- env?: dict<string>,
16
- shell?: string,
7
+ module Util = {
8
+ @unboxed
9
+ type depth = Int(int) | @as(null) Null
10
+ @unboxed
11
+ type compact = Bool(bool) | Int(int)
12
+ @unboxed
13
+ type sorted = Bool(bool) | Fn((string, string) => int)
14
+ @unboxed
15
+ type getters = | @as(true) True | @as(false) False | @as("get") Get | @as("set") Set
16
+
17
+ @unbox
18
+ type inspectOptions = {
19
+ showHidden?: bool,
20
+ depth?: depth,
21
+ colors?: bool,
22
+ customInspect?: bool,
23
+ showProxy?: bool,
24
+ maxArrayLength?: int,
25
+ maxStringLength?: int,
26
+ breakLength?: int,
27
+ @as("compact") compact?: compact,
28
+ sorted?: sorted,
29
+ getters?: string,
30
+ numericSeparator?: bool,
17
31
  }
18
32
 
19
- type callback = (~error: Js.null<exn>, ~stdout: string, ~stderr: string) => unit
20
-
21
- @module("child_process")
22
- external exec: (string, callback) => unit = "exec"
33
+ @module("util") external inspect: ('a, inspectOptions) => string = "inspect"
23
34
 
24
- @module("child_process")
25
- external execWithOptions: (string, execOptions, callback) => unit = "exec"
35
+ let inspectObj = a => inspect(a, {showHidden: false, depth: Null, colors: true})
26
36
  }
27
37
 
28
38
  module Path = {
@@ -45,11 +55,6 @@ module Fs = {
45
55
  encoding?: string,
46
56
  }
47
57
 
48
- type mkdirOptions = {
49
- recursive?: bool,
50
- mode?: int,
51
- }
52
-
53
58
  module Promises = {
54
59
  @module("fs") @scope("promises")
55
60
  external writeFile: (
@@ -72,11 +77,5 @@ module Fs = {
72
77
 
73
78
  @module("fs") @scope("promises")
74
79
  external readFile: (~filepath: Path.t, ~encoding: encoding) => promise<string> = "readFile"
75
-
76
- @module("fs") @scope("promises")
77
- external mkdir: (~path: Path.t, ~options: mkdirOptions=?) => Js.Promise.t<unit> = "mkdir"
78
-
79
- @module("fs") @scope("promises")
80
- external readdir: Path.t => Js.Promise.t<array<string>> = "readdir"
81
80
  }
82
81
  }
@@ -1,10 +1,19 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
+ var Util = require("util");
4
5
 
5
- var Process = {};
6
+ function inspectObj(a) {
7
+ return Util.inspect(a, {
8
+ showHidden: false,
9
+ depth: null,
10
+ colors: true
11
+ });
12
+ }
6
13
 
7
- var ChildProcess = {};
14
+ var Util$1 = {
15
+ inspectObj: inspectObj
16
+ };
8
17
 
9
18
  var Path = {};
10
19
 
@@ -14,8 +23,7 @@ var Fs = {
14
23
  Promises: Promises
15
24
  };
16
25
 
17
- exports.Process = Process;
18
- exports.ChildProcess = ChildProcess;
26
+ exports.Util = Util$1;
19
27
  exports.Path = Path;
20
28
  exports.Fs = Fs;
21
- /* No side effect */
29
+ /* util Not a pure module */