envio 3.7.0 → 3.9.0-resolvers.0

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 (118) hide show
  1. package/README.md +2 -2
  2. package/evm.schema.json +7 -0
  3. package/fuel.schema.json +7 -0
  4. package/index.d.ts +674 -161
  5. package/index.js +10 -0
  6. package/package.json +6 -7
  7. package/src/AddressRows.res +121 -0
  8. package/src/AddressRows.res.mjs +143 -0
  9. package/src/Batch.res +11 -0
  10. package/src/Batch.res.mjs +2 -1
  11. package/src/Bin.res +47 -0
  12. package/src/Bin.res.mjs +34 -1
  13. package/src/ChainState.res +108 -98
  14. package/src/ChainState.res.mjs +86 -67
  15. package/src/ChainState.resi +28 -15
  16. package/src/Config.res +61 -131
  17. package/src/Config.res.mjs +47 -79
  18. package/src/ContractMapping.res +66 -0
  19. package/src/ContractMapping.res.mjs +73 -0
  20. package/src/Core.res +24 -0
  21. package/src/Core.res.mjs +4 -0
  22. package/src/Ecosystem.res +7 -2
  23. package/src/Env.res +128 -1
  24. package/src/Env.res.mjs +123 -1
  25. package/src/Envio.res +54 -76
  26. package/src/EventConfigBuilder.res +316 -46
  27. package/src/EventConfigBuilder.res.mjs +231 -28
  28. package/src/FetchState.res +59 -67
  29. package/src/FetchState.res.mjs +34 -44
  30. package/src/HandlerRegister.res +26 -15
  31. package/src/HandlerRegister.res.mjs +27 -7
  32. package/src/Hasura.res +30 -22
  33. package/src/Hasura.res.mjs +11 -5
  34. package/src/InMemoryStore.res +23 -38
  35. package/src/InMemoryStore.res.mjs +13 -27
  36. package/src/IndexerState.res +40 -3
  37. package/src/IndexerState.res.mjs +30 -4
  38. package/src/IndexerState.resi +4 -1
  39. package/src/Internal.res +49 -30
  40. package/src/Internal.res.mjs +12 -16
  41. package/src/Main.res +27 -20
  42. package/src/Main.res.mjs +19 -14
  43. package/src/Metrics.res +15 -1
  44. package/src/Metrics.res.mjs +5 -1
  45. package/src/Persistence.res +46 -21
  46. package/src/Persistence.res.mjs +8 -5
  47. package/src/PgStorage.res +238 -79
  48. package/src/PgStorage.res.mjs +115 -73
  49. package/src/PruneStaleHistory.res +1 -1
  50. package/src/PruneStaleHistory.res.mjs +1 -1
  51. package/src/Rollback.res +62 -41
  52. package/src/Rollback.res.mjs +61 -19
  53. package/src/RollbackCommit.res +7 -9
  54. package/src/RollbackCommit.res.mjs +5 -6
  55. package/src/SimulateItems.res +254 -9
  56. package/src/SimulateItems.res.mjs +214 -47
  57. package/src/Sink.res +35 -26
  58. package/src/Sink.res.mjs +20 -16
  59. package/src/TestIndexer.res +121 -123
  60. package/src/TestIndexer.res.mjs +97 -102
  61. package/src/Utils.res +38 -0
  62. package/src/Utils.res.mjs +39 -2
  63. package/src/Writing.res +4 -2
  64. package/src/Writing.res.mjs +3 -2
  65. package/src/bindings/ClickHouse.res +311 -656
  66. package/src/bindings/ClickHouse.res.mjs +294 -395
  67. package/src/bindings/ClickHouseSink.res +303 -0
  68. package/src/bindings/ClickHouseSink.res.mjs +216 -0
  69. package/src/bindings/NodeJs.res +9 -0
  70. package/src/bindings/NodeJs.res.mjs +8 -1
  71. package/src/bindings/Postgres.res +9 -0
  72. package/src/bindings/Postgres.res.mjs +3 -0
  73. package/src/db/EntityHistory.res +29 -24
  74. package/src/db/EntityHistory.res.mjs +11 -19
  75. package/src/db/InternalTable.res +258 -83
  76. package/src/db/InternalTable.res.mjs +223 -85
  77. package/src/db/RollbackScope.res +29 -0
  78. package/src/db/RollbackScope.res.mjs +31 -0
  79. package/src/db/Table.res +28 -1
  80. package/src/db/Table.res.mjs +26 -2
  81. package/src/resolvers/ResolverProcess.res +809 -0
  82. package/src/resolvers/ResolverProcess.res.mjs +667 -0
  83. package/src/resolvers/ResolverQuery.res +317 -0
  84. package/src/resolvers/ResolverQuery.res.mjs +220 -0
  85. package/src/resolvers/collisions.js +108 -0
  86. package/src/resolvers/db.js +363 -0
  87. package/src/resolvers/dispatch.js +165 -0
  88. package/src/resolvers/errors.js +30 -0
  89. package/src/resolvers/graphqlSelection.js +292 -0
  90. package/src/resolvers/hasuraAction.js +84 -0
  91. package/src/resolvers/hasuraApply.js +323 -0
  92. package/src/resolvers/hasuraMetadata.js +119 -0
  93. package/src/resolvers/index.js +95 -0
  94. package/src/resolvers/manifest.js +370 -0
  95. package/src/resolvers/server.js +270 -0
  96. package/src/sources/AddressSet.res +0 -22
  97. package/src/sources/AddressStore.res +48 -88
  98. package/src/sources/AddressStore.res.mjs +11 -22
  99. package/src/sources/Evm.res +2 -0
  100. package/src/sources/Evm.res.mjs +2 -0
  101. package/src/sources/EvmHyperSyncSource.res +3 -2
  102. package/src/sources/Fuel.res +2 -0
  103. package/src/sources/Fuel.res.mjs +2 -0
  104. package/src/sources/SimulateSource.res +8 -4
  105. package/src/sources/SimulateSource.res.mjs +7 -3
  106. package/src/sources/Svm.res +36 -7
  107. package/src/sources/Svm.res.mjs +34 -4
  108. package/src/sources/SvmHyperSyncClient.res +20 -116
  109. package/src/sources/SvmHyperSyncClient.res.mjs +5 -7
  110. package/src/sources/SvmHyperSyncSource.res +89 -37
  111. package/src/sources/SvmHyperSyncSource.res.mjs +71 -39
  112. package/src/sources/TransactionStore.res +38 -0
  113. package/src/sources/TransactionStore.res.mjs +5 -0
  114. package/src/tui/Tui.res +1 -1
  115. package/src/tui/Tui.res.mjs +1 -1
  116. package/svm.schema.json +44 -156
  117. package/src/MemoryStorage.res +0 -724
  118. package/src/MemoryStorage.res.mjs +0 -601
package/index.js CHANGED
@@ -9,6 +9,16 @@ import { schema as bigDecimalSchema } from "./src/bindings/BigDecimal.res.mjs";
9
9
 
10
10
  export * from "./src/Envio.res.mjs";
11
11
  export { indexer, createTestIndexer } from "./src/Api.res.mjs";
12
+ export {
13
+ createResolver,
14
+ defineType,
15
+ defineInput,
16
+ defineEnum,
17
+ defineScalar,
18
+ getRegisteredResolvers,
19
+ buildRegisteredManifest,
20
+ ResolverError,
21
+ } from "./src/resolvers/index.js";
12
22
  export { default as BigDecimal } from "bignumber.js";
13
23
 
14
24
  // Important! Should match the index.d.ts file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "3.7.0",
3
+ "version": "3.9.0-resolvers.0",
4
4
  "type": "module",
5
5
  "description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
6
6
  "bin": "./bin.mjs",
@@ -41,7 +41,6 @@
41
41
  "licenses"
42
42
  ],
43
43
  "dependencies": {
44
- "@clickhouse/client": "1.17.0",
45
44
  "@elastic/ecs-pino-format": "1.4.0",
46
45
  "@fuel-ts/crypto": "0.96.1",
47
46
  "@fuel-ts/errors": "0.96.1",
@@ -69,10 +68,10 @@
69
68
  "tsx": "4.21.0"
70
69
  },
71
70
  "optionalDependencies": {
72
- "envio-linux-x64": "3.7.0",
73
- "envio-linux-x64-musl": "3.7.0",
74
- "envio-linux-arm64": "3.7.0",
75
- "envio-darwin-x64": "3.7.0",
76
- "envio-darwin-arm64": "3.7.0"
71
+ "envio-linux-x64": "3.9.0-resolvers.0",
72
+ "envio-linux-x64-musl": "3.9.0-resolvers.0",
73
+ "envio-linux-arm64": "3.9.0-resolvers.0",
74
+ "envio-darwin-x64": "3.9.0-resolvers.0",
75
+ "envio-darwin-arm64": "3.9.0-resolvers.0"
77
76
  }
78
77
  }
@@ -0,0 +1,121 @@
1
+ type key = {
2
+ chainId: ChainId.t,
3
+ address: NodeJs.Buffer.t,
4
+ contractId: int,
5
+ }
6
+
7
+ type row = {
8
+ chainId: ChainId.t,
9
+ address: NodeJs.Buffer.t,
10
+ contractId: int,
11
+ registrationBlock: int,
12
+ }
13
+
14
+ type staged = {
15
+ row: row,
16
+ checkpointId: Internal.checkpointId,
17
+ }
18
+
19
+ type seedRows = {
20
+ addresses: array<NodeJs.Buffer.t>,
21
+ contractIds: array<int>,
22
+ registrationBlocks: array<int>,
23
+ }
24
+
25
+ let emptySeedRows = (): seedRows => {
26
+ addresses: [],
27
+ contractIds: [],
28
+ registrationBlocks: [],
29
+ }
30
+
31
+ // Config addresses are registered by no event. Rollback never reaches them.
32
+ let configRegistrationBlock = -1
33
+
34
+ let keyOf = (row: row): key => {
35
+ chainId: row.chainId,
36
+ address: row.address,
37
+ contractId: row.contractId,
38
+ }
39
+
40
+ let packBuffers = (addresses: array<NodeJs.Buffer.t>) => (
41
+ NodeJs.Buffer.concat(addresses),
42
+ addresses->Array.map(address => address->NodeJs.Buffer.length),
43
+ )
44
+
45
+ let packKeys = (rows: array<row>) => packBuffers(rows->Array.map(row => row.address))
46
+
47
+ let seedRowsOf = (rows: array<row>): seedRows => {
48
+ let addresses = []
49
+ let contractIds = []
50
+ let registrationBlocks = []
51
+ rows->Array.forEach(row => {
52
+ addresses->Array.push(row.address)->ignore
53
+ contractIds->Array.push(row.contractId)->ignore
54
+ registrationBlocks->Array.push(row.registrationBlock)->ignore
55
+ })
56
+ {addresses, contractIds, registrationBlocks}
57
+ }
58
+
59
+ // Rows arrive clustered per chain. Normalizing a chain id is a schema parse.
60
+ let group = (rows: array<row>): dict<seedRows> => {
61
+ let rowsByChain: dict<array<row>> = Dict.make()
62
+ let runChainId = ref(None)
63
+ let runKey = ref("")
64
+ rows->Array.forEach(row => {
65
+ if runChainId.contents !== Some(row.chainId) {
66
+ runChainId := Some(row.chainId)
67
+ runKey := row.chainId->ChainId.normalizeOrThrow->ChainId.toString
68
+ }
69
+ rowsByChain->Utils.Dict.push(runKey.contents, row)
70
+ })
71
+ rowsByChain->Utils.Dict.mapValues(seedRowsOf)
72
+ }
73
+
74
+ module Table = {
75
+ type t = dict<row>
76
+
77
+ let dictKey = (key: key) =>
78
+ `${key.chainId->ChainId.toString}|${key.contractId->Int.toString}|${key.address->NodeJs.Buffer.toBase64}`
79
+
80
+ let make = (): t => Dict.make()
81
+
82
+ let clear = (table: t) => table->Utils.Dict.clearInPlace
83
+
84
+ let insert = (table: t, row: row) => {
85
+ let key = row->keyOf->dictKey
86
+ switch table->Utils.Dict.dangerouslyGetNonOption(key) {
87
+ | Some(_) => ()
88
+ | None => table->Dict.set(key, row)
89
+ }
90
+ }
91
+
92
+ let insertMany = (table: t, rows: array<row>) => rows->Array.forEach(row => table->insert(row))
93
+
94
+ let delete = (table: t, key: key) => table->Utils.Dict.deleteInPlace(key->dictKey)
95
+
96
+ let rows = (table: t): array<row> => table->Dict.valuesToArray
97
+
98
+ let groupByChain = (table: t) => table->rows->group
99
+ }
100
+
101
+ let render = (rows: array<row>, ~ecosystem: string, ~shouldChecksum: bool) => {
102
+ let (bytes, lengths) = rows->packKeys
103
+ Core.getAddon().renderAddresses(~ecosystem, ~shouldChecksum, ~bytes, ~lengths)
104
+ }
105
+
106
+ let renderOfContract = (
107
+ rows: seedRows,
108
+ ~ecosystem: string,
109
+ ~shouldChecksum: bool,
110
+ ~contractId: int,
111
+ ) => {
112
+ let (bytes, lengths) = packBuffers(rows.addresses)
113
+ Core.getAddon().renderContractAddresses(
114
+ ~ecosystem,
115
+ ~shouldChecksum,
116
+ ~bytes,
117
+ ~lengths,
118
+ ~contractIds=rows.contractIds,
119
+ ~contractId,
120
+ )
121
+ }
@@ -0,0 +1,143 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Core from "./Core.res.mjs";
4
+ import * as Utils from "./Utils.res.mjs";
5
+ import * as ChainId from "./ChainId.res.mjs";
6
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
7
+
8
+ function emptySeedRows() {
9
+ return {
10
+ addresses: [],
11
+ contractIds: [],
12
+ registrationBlocks: []
13
+ };
14
+ }
15
+
16
+ function keyOf(row) {
17
+ return {
18
+ chainId: row.chainId,
19
+ address: row.address,
20
+ contractId: row.contractId
21
+ };
22
+ }
23
+
24
+ function packBuffers(addresses) {
25
+ return [
26
+ Buffer.concat(addresses),
27
+ addresses.map(address => address.length)
28
+ ];
29
+ }
30
+
31
+ function packKeys(rows) {
32
+ return packBuffers(rows.map(row => row.address));
33
+ }
34
+
35
+ function seedRowsOf(rows) {
36
+ let addresses = [];
37
+ let contractIds = [];
38
+ let registrationBlocks = [];
39
+ rows.forEach(row => {
40
+ addresses.push(row.address);
41
+ contractIds.push(row.contractId);
42
+ registrationBlocks.push(row.registrationBlock);
43
+ });
44
+ return {
45
+ addresses: addresses,
46
+ contractIds: contractIds,
47
+ registrationBlocks: registrationBlocks
48
+ };
49
+ }
50
+
51
+ function group(rows) {
52
+ let rowsByChain = {};
53
+ let runChainId = {
54
+ contents: undefined
55
+ };
56
+ let runKey = {
57
+ contents: ""
58
+ };
59
+ rows.forEach(row => {
60
+ if (runChainId.contents !== Primitive_option.some(row.chainId)) {
61
+ runChainId.contents = Primitive_option.some(row.chainId);
62
+ runKey.contents = ChainId.toString(ChainId.normalizeOrThrow(row.chainId));
63
+ }
64
+ Utils.Dict.push(rowsByChain, runKey.contents, row);
65
+ });
66
+ return Utils.Dict.mapValues(rowsByChain, seedRowsOf);
67
+ }
68
+
69
+ function dictKey(key) {
70
+ return ChainId.toString(key.chainId) + `|` + key.contractId.toString() + `|` + key.address.toString("base64");
71
+ }
72
+
73
+ function make() {
74
+ return {};
75
+ }
76
+
77
+ function clear(table) {
78
+ Utils.Dict.clearInPlace(table);
79
+ }
80
+
81
+ function insert(table, row) {
82
+ let key = dictKey(keyOf(row));
83
+ let match = table[key];
84
+ if (match !== undefined) {
85
+ return;
86
+ } else {
87
+ table[key] = row;
88
+ return;
89
+ }
90
+ }
91
+
92
+ function insertMany(table, rows) {
93
+ rows.forEach(row => insert(table, row));
94
+ }
95
+
96
+ function $$delete(table, key) {
97
+ Utils.Dict.deleteInPlace(table, dictKey(key));
98
+ }
99
+
100
+ function rows(table) {
101
+ return Object.values(table);
102
+ }
103
+
104
+ function groupByChain(table) {
105
+ return group(Object.values(table));
106
+ }
107
+
108
+ let Table = {
109
+ dictKey: dictKey,
110
+ make: make,
111
+ clear: clear,
112
+ insert: insert,
113
+ insertMany: insertMany,
114
+ $$delete: $$delete,
115
+ rows: rows,
116
+ groupByChain: groupByChain
117
+ };
118
+
119
+ function render(rows, ecosystem, shouldChecksum) {
120
+ let match = packKeys(rows);
121
+ return Core.getAddon().renderAddresses(ecosystem, shouldChecksum, match[0], match[1]);
122
+ }
123
+
124
+ function renderOfContract(rows, ecosystem, shouldChecksum, contractId) {
125
+ let match = packBuffers(rows.addresses);
126
+ return Core.getAddon().renderContractAddresses(ecosystem, shouldChecksum, match[0], match[1], rows.contractIds, contractId);
127
+ }
128
+
129
+ let configRegistrationBlock = -1;
130
+
131
+ export {
132
+ emptySeedRows,
133
+ configRegistrationBlock,
134
+ keyOf,
135
+ packBuffers,
136
+ packKeys,
137
+ seedRowsOf,
138
+ group,
139
+ Table,
140
+ render,
141
+ renderOfContract,
142
+ }
143
+ /* Core Not a pure module */
package/src/Batch.res CHANGED
@@ -43,6 +43,7 @@ type t = {
43
43
  checkpointBlockNumbers: array<int>,
44
44
  checkpointBlockHashes: array<Null.t<string>>,
45
45
  checkpointEventsProcessed: array<int>,
46
+ registeredAddresses: array<AddressRows.staged>,
46
47
  }
47
48
 
48
49
  let getProgressedChainsById = {
@@ -188,6 +189,15 @@ let addReorgCheckpoints = (
188
189
  }
189
190
  }
190
191
 
192
+ // Checkpoint ids are handed out in ascending order as each chain's items are
193
+ // walked in block order, so within a chain a higher id always means a later
194
+ // block. Rollback preserves that: it deletes the chain's ids above its target
195
+ // before any higher one is allocated, so the ids the re-indexed blocks get are
196
+ // above everything the chain still holds. An isolated rollback leans on the
197
+ // invariant — it deletes by `chain_id = c AND id > target`, which is only the
198
+ // chain's stale suffix if ids and blocks agree on order within the chain. Ids
199
+ // interleave freely *across* chains, which is exactly why that predicate can't
200
+ // be the id bound alone.
191
201
  let prepareBatch = (
192
202
  ~checkpointIdBeforeBatch,
193
203
  ~chainsBeforeBatch: dict<chainBeforeBatch>,
@@ -326,6 +336,7 @@ let prepareBatch = (
326
336
  checkpointBlockNumbers,
327
337
  checkpointBlockHashes,
328
338
  checkpointEventsProcessed,
339
+ registeredAddresses: [],
329
340
  }
330
341
  }
331
342
 
package/src/Batch.res.mjs CHANGED
@@ -185,7 +185,8 @@ function prepareBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSizeTarge
185
185
  checkpointChainIds: checkpointChainIds,
186
186
  checkpointBlockNumbers: checkpointBlockNumbers,
187
187
  checkpointBlockHashes: checkpointBlockHashes,
188
- checkpointEventsProcessed: checkpointEventsProcessed
188
+ checkpointEventsProcessed: checkpointEventsProcessed,
189
+ registeredAddresses: []
189
190
  };
190
191
  }
191
192
 
package/src/Bin.res CHANGED
@@ -18,11 +18,13 @@ type startCmd = {
18
18
  }
19
19
  type migrateCmd = {reset: bool, config: JSON.t}
20
20
  type dropSchemaCmd = {config: JSON.t}
21
+ type resolversCmd = {mode: string, cwd: string, env: dict<JSON.t>, config: JSON.t}
21
22
 
22
23
  type command =
23
24
  | Start(startCmd)
24
25
  | Migrate(migrateCmd)
25
26
  | DropSchema(dropSchemaCmd)
27
+ | Resolvers(resolversCmd)
26
28
 
27
29
  let decodeCommand = (json: JSON.t): command => {
28
30
  let obj = switch json->JSON.Decode.object {
@@ -37,6 +39,7 @@ let decodeCommand = (json: JSON.t): command => {
37
39
  | "start" => Start(json->(Utils.magic: JSON.t => startCmd))
38
40
  | "migrate" => Migrate(json->(Utils.magic: JSON.t => migrateCmd))
39
41
  | "drop-schema" => DropSchema(json->(Utils.magic: JSON.t => dropSchemaCmd))
42
+ | "resolvers" => Resolvers(json->(Utils.magic: JSON.t => resolversCmd))
40
43
  | other => JsError.throwWithMessage(`Unknown command kind: ${other}`)
41
44
  }
42
45
  }
@@ -61,6 +64,12 @@ let run = async args => {
61
64
  Config.prime(config)
62
65
  processChdir(cwd)
63
66
  applyEnv(env)
67
+ // `envio dev` only — see ResolverProcess.startForDev. A deployment
68
+ // runs the resolvers as their own Deployment, never from here.
69
+ let loaded = Config.load()
70
+ if loaded.isDev {
71
+ let _ = await ResolverProcess.startForDev(~config=loaded, ~projectRoot=cwd)
72
+ }
64
73
  await Main.start(~reset)
65
74
  | Migrate({reset, config}) =>
66
75
  Config.prime(config)
@@ -68,6 +77,44 @@ let run = async args => {
68
77
  | DropSchema({config}) =>
69
78
  Config.prime(config)
70
79
  await Main.dropSchema()
80
+ | Resolvers({mode, cwd, env, config}) =>
81
+ Config.prime(config)
82
+ processChdir(cwd)
83
+ applyEnv(env)
84
+ switch mode {
85
+ | "manifest" => await ResolverProcess.writeManifest(~config=Config.load(), ~projectRoot=cwd)
86
+ | "metadata" =>
87
+ let handlerUrl = switch Env.Resolvers.publicUrl() {
88
+ | Some(url) => url
89
+ | None =>
90
+ JsError.throwWithMessage(
91
+ "ENVIO_RESOLVERS_PUBLIC_URL is not set. It is the URL Hasura posts to and is baked into every action, so the metadata cannot be printed without it.",
92
+ )
93
+ }
94
+ let metadata = await ResolverProcess.metadataJson(
95
+ ~config=Config.load(),
96
+ ~projectRoot=cwd,
97
+ ~handlerUrl,
98
+ )
99
+ // stdout, so it pipes into `hasura metadata apply` or `jq` rather
100
+ // than being buried in the log stream.
101
+ Console.log(JSON.stringify(metadata, ~space=2))
102
+ | "migrate" =>
103
+ let {applied, reasons} = await ResolverProcess.migrate(
104
+ ~config=Config.load(),
105
+ ~projectRoot=cwd,
106
+ )
107
+ Logging.info(
108
+ applied
109
+ ? `Updated Hasura to match these resolvers: ${reasons->Array.join("; ")}`
110
+ : "Hasura already matches these resolvers; nothing to update",
111
+ )
112
+ // Serving keeps the event loop alive on its own, so returning here
113
+ // leaves the process running rather than exiting.
114
+ | _ =>
115
+ let running = await ResolverProcess.serve(~config=Config.load(), ~projectRoot=cwd)
116
+ running->ResolverProcess.handleSignals
117
+ }
71
118
  }
72
119
  }
73
120
  } catch {
package/src/Bin.res.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Env from "./Env.res.mjs";
3
4
  import * as Core from "./Core.res.mjs";
4
5
  import * as Main from "./Main.res.mjs";
5
6
  import * as Utils from "./Utils.res.mjs";
@@ -11,6 +12,7 @@ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
11
12
  import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
12
13
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
13
14
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
15
+ import * as ResolverProcess from "./resolvers/ResolverProcess.res.mjs";
14
16
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
15
17
 
16
18
  let setEnvVar = ((k, v) => { process.env[k] = v; });
@@ -36,6 +38,11 @@ function decodeCommand(json) {
36
38
  TAG: "Migrate",
37
39
  _0: json
38
40
  };
41
+ case "resolvers" :
42
+ return {
43
+ TAG: "Resolvers",
44
+ _0: json
45
+ };
39
46
  case "start" :
40
47
  return {
41
48
  TAG: "Start",
@@ -65,9 +72,14 @@ async function run(args) {
65
72
  switch (match.TAG) {
66
73
  case "Start" :
67
74
  let match$1 = match._0;
75
+ let cwd = match$1.cwd;
68
76
  Config.prime(match$1.config);
69
- process.chdir(match$1.cwd);
77
+ process.chdir(cwd);
70
78
  applyEnv(match$1.env);
79
+ let loaded = Config.load();
80
+ if (loaded.isDev) {
81
+ await ResolverProcess.startForDev(loaded, cwd);
82
+ }
71
83
  return await Main.start(undefined, match$1.reset, undefined, undefined, undefined);
72
84
  case "Migrate" :
73
85
  let match$2 = match._0;
@@ -76,6 +88,27 @@ async function run(args) {
76
88
  case "DropSchema" :
77
89
  Config.prime(match._0.config);
78
90
  return await Main.dropSchema();
91
+ case "Resolvers" :
92
+ let match$3 = match._0;
93
+ let cwd$1 = match$3.cwd;
94
+ Config.prime(match$3.config);
95
+ process.chdir(cwd$1);
96
+ applyEnv(match$3.env);
97
+ switch (match$3.mode) {
98
+ case "manifest" :
99
+ return await ResolverProcess.writeManifest(Config.load(), cwd$1);
100
+ case "metadata" :
101
+ let url = Env.Resolvers.publicUrl();
102
+ let handlerUrl = url !== undefined ? url : Stdlib_JsError.throwWithMessage("ENVIO_RESOLVERS_PUBLIC_URL is not set. It is the URL Hasura posts to and is baked into every action, so the metadata cannot be printed without it.");
103
+ let metadata = await ResolverProcess.metadataJson(Config.load(), cwd$1, handlerUrl);
104
+ console.log(JSON.stringify(metadata, undefined, 2));
105
+ return;
106
+ case "migrate" :
107
+ let match$4 = await ResolverProcess.migrate(Config.load(), cwd$1);
108
+ return Logging.info(match$4.applied ? `Updated Hasura to match these resolvers: ` + match$4.reasons.join("; ") : "Hasura already matches these resolvers; nothing to update");
109
+ default:
110
+ return ResolverProcess.handleSignals(await ResolverProcess.serve(Config.load(), cwd$1, undefined, undefined, undefined, undefined));
111
+ }
79
112
  }
80
113
  } catch (raw_exn) {
81
114
  let exn = Primitive_exceptions.internalToException(raw_exn);