@reventlessdev/reventless-seed 1.0.0-alpha.1 → 1.0.0-alpha.11

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 (106) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/lib/bs/.compiler.log +2 -2
  3. package/lib/bs/.sourcedirs.json +1 -0
  4. package/lib/bs/ReventlessSeed.cmi +0 -0
  5. package/lib/bs/ReventlessSeed.cmt +0 -0
  6. package/lib/bs/ReventlessSeed.mlmap +3 -0
  7. package/lib/bs/compiler-info.json +2 -2
  8. package/lib/bs/src/Seed-ReventlessSeed.cmi +0 -0
  9. package/lib/bs/src/Seed-ReventlessSeed.cmt +0 -0
  10. package/lib/bs/src/Seed.ast +0 -0
  11. package/lib/bs/src/Seed.res +19 -0
  12. package/lib/bs/src/Seed.res.mjs +6 -0
  13. package/lib/bs/src/Seed_Client-ReventlessSeed.cmi +0 -0
  14. package/lib/bs/src/Seed_Client-ReventlessSeed.cmj +0 -0
  15. package/lib/bs/src/Seed_Client-ReventlessSeed.cmt +0 -0
  16. package/lib/bs/src/Seed_Client.ast +0 -0
  17. package/lib/bs/src/Seed_Client.res +62 -11
  18. package/lib/bs/src/Seed_Client.res.mjs +51 -5
  19. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmi +0 -0
  20. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmj +0 -0
  21. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmt +0 -0
  22. package/lib/bs/src/Seed_Connect.ast +0 -0
  23. package/lib/bs/src/Seed_Connect.res +86 -0
  24. package/lib/bs/src/Seed_Connect.res.mjs +62 -0
  25. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
  26. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmj +0 -0
  27. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmt +0 -0
  28. package/lib/bs/src/Seed_Prompt.ast +0 -0
  29. package/lib/bs/src/Seed_Prompt.res +178 -0
  30. package/lib/bs/src/Seed_Prompt.res.mjs +172 -0
  31. package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
  32. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
  33. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmj +0 -0
  34. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmt +0 -0
  35. package/lib/bs/src/Seed_Runner.ast +0 -0
  36. package/lib/bs/src/Seed_Runner.res +122 -6
  37. package/lib/bs/src/Seed_Runner.res.mjs +87 -1
  38. package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
  39. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmi +0 -0
  40. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmj +0 -0
  41. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -0
  42. package/lib/bs/src/Seed_Upload.ast +0 -0
  43. package/lib/bs/src/Seed_Upload.res +40 -42
  44. package/lib/bs/src/Seed_Upload.res.mjs +65 -69
  45. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmi +0 -0
  46. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmj +0 -0
  47. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmt +0 -0
  48. package/lib/bs/tests/Seed_RandomTest.ast +0 -0
  49. package/lib/bs/tests/Seed_RandomTest.res +160 -0
  50. package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
  51. package/lib/ocaml/.compiler.log +2 -2
  52. package/lib/ocaml/ReventlessSeed.cmi +0 -0
  53. package/lib/ocaml/ReventlessSeed.cmt +0 -0
  54. package/lib/ocaml/ReventlessSeed.mlmap +3 -0
  55. package/lib/ocaml/Seed-ReventlessSeed.cmi +0 -0
  56. package/lib/ocaml/Seed-ReventlessSeed.cmt +0 -0
  57. package/lib/ocaml/Seed.ast +0 -0
  58. package/lib/ocaml/Seed.res +19 -0
  59. package/lib/ocaml/Seed_Client-ReventlessSeed.cmi +0 -0
  60. package/lib/ocaml/Seed_Client-ReventlessSeed.cmj +0 -0
  61. package/lib/ocaml/Seed_Client-ReventlessSeed.cmt +0 -0
  62. package/lib/ocaml/Seed_Client.ast +0 -0
  63. package/lib/ocaml/Seed_Client.res +62 -11
  64. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmi +0 -0
  65. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmj +0 -0
  66. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmt +0 -0
  67. package/lib/ocaml/Seed_Connect.ast +0 -0
  68. package/lib/ocaml/Seed_Connect.res +86 -0
  69. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
  70. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmj +0 -0
  71. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmt +0 -0
  72. package/lib/ocaml/Seed_Prompt.ast +0 -0
  73. package/lib/ocaml/Seed_Prompt.res +178 -0
  74. package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
  75. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmi +0 -0
  76. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmj +0 -0
  77. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmt +0 -0
  78. package/lib/ocaml/Seed_RandomTest.ast +0 -0
  79. package/lib/ocaml/Seed_RandomTest.res +160 -0
  80. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
  81. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmj +0 -0
  82. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmt +0 -0
  83. package/lib/ocaml/Seed_Runner.ast +0 -0
  84. package/lib/ocaml/Seed_Runner.res +122 -6
  85. package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
  86. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmi +0 -0
  87. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmj +0 -0
  88. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
  89. package/lib/ocaml/Seed_Upload.ast +0 -0
  90. package/lib/ocaml/Seed_Upload.res +40 -42
  91. package/package.json +6 -2
  92. package/rescript.json +9 -1
  93. package/src/Seed.res +19 -0
  94. package/src/Seed.res.mjs +6 -0
  95. package/src/Seed_Client.res +62 -11
  96. package/src/Seed_Client.res.mjs +51 -5
  97. package/src/Seed_Connect.res +86 -0
  98. package/src/Seed_Connect.res.mjs +62 -0
  99. package/src/Seed_Prompt.res +178 -0
  100. package/src/Seed_Prompt.res.mjs +172 -0
  101. package/src/Seed_Runner.res +122 -6
  102. package/src/Seed_Runner.res.mjs +87 -1
  103. package/src/Seed_Upload.res +40 -42
  104. package/src/Seed_Upload.res.mjs +65 -69
  105. package/tests/Seed_RandomTest.res +160 -0
  106. package/tests/Seed_RandomTest.res.mjs +208 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,81 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 1.0.0-alpha.11 (2026-08-11)
7
+
8
+ **Note:** Version bump only for package @reventlessdev/reventless-seed
9
+
10
+
11
+
12
+
13
+
14
+ # 1.0.0-alpha.10 (2026-08-09)
15
+
16
+ **Note:** Version bump only for package @reventlessdev/reventless-seed
17
+
18
+
19
+
20
+
21
+
22
+ # 1.0.0-alpha.9 (2026-08-05)
23
+
24
+ **Note:** Version bump only for package @reventlessdev/reventless-seed
25
+
26
+
27
+
28
+
29
+
30
+ # 1.0.0-alpha.8 (2026-08-02)
31
+
32
+ **Note:** Version bump only for package @reventlessdev/reventless-seed
33
+
34
+
35
+
36
+
37
+
38
+ # 1.0.0-alpha.7 (2026-08-01)
39
+
40
+ ### Features
41
+
42
+ * **upload:** add the release half of the upload contract via the domain API ([448f887](https://github.com/ReventlessDev/reventless-core/commit/448f88714a5875be420f794a08d482fcf4ba8404))
43
+
44
+
45
+ # 1.0.0-alpha.6 (2026-07-31)
46
+
47
+ **Note:** Version bump only for package @reventlessdev/reventless-seed
48
+
49
+
50
+
51
+
52
+
53
+ # 1.0.0-alpha.5 (2026-07-31)
54
+
55
+ ### Bug Fixes
56
+
57
+ * **seed:** address a deployment's per-store upload endpoints ([45b226e](https://github.com/ReventlessDev/reventless-core/commit/45b226e00604af9fd28b6fb0b75ba7d3414791f2))
58
+
59
+
60
+ # 1.0.0-alpha.4 (2026-07-27)
61
+
62
+ ### Features
63
+
64
+ * **seed:** guarded AWS store reset (seed:reset) with per-project scope selection ([8446172](https://github.com/ReventlessDev/reventless-core/commit/8446172cbb53776a58f53220d19e96d96ce94508))
65
+
66
+
67
+ # 1.0.0-alpha.3 (2026-07-27)
68
+
69
+ ### Features
70
+
71
+ * **seed:** refuse to seed onto a non-empty store (fresh-store guard) ([987613f](https://github.com/ReventlessDev/reventless-core/commit/987613f0767fc4391297dfeed3a6b19cd76d8157))
72
+
73
+
74
+ # 1.0.0-alpha.2 (2026-07-26)
75
+
76
+ ### Features
77
+
78
+ * **seed:** per-provider seed scripts, shared machinery, exportable data sets ([ba43e9e](https://github.com/ReventlessDev/reventless-core/commit/ba43e9efab84dd2955b6dafd1e187fd4aad699ad))
79
+
80
+
6
81
  # 1.0.0-alpha.1 (2026-07-26)
7
82
 
8
83
  ### Bug Fixes
@@ -1,2 +1,2 @@
1
- #Start(1785055307106)
2
- #Done(1785055311634)
1
+ #Start(1786453304385)
2
+ #Done(1786453304425)
@@ -0,0 +1 @@
1
+ {"cmt_scan":[{"also_scan_build_root":true,"build_root":"lib/bs","scan_dirs":["src","tests"]}],"dirs":["src","tests"],"generated":[],"pkgs":[["@reventlessdev/rescript-jest","/home/runner/work/reventless-core/reventless-core/rescript/jest"],["@reventlessdev/rescript-node","/home/runner/work/reventless-core/reventless-core/rescript/node"]],"version":2}
Binary file
Binary file
@@ -1,7 +1,10 @@
1
1
  randjbuildsystem
2
2
  Seed
3
3
  Seed_Client
4
+ Seed_Connect
5
+ Seed_Prompt
4
6
  Seed_Random
7
+ Seed_RandomTest
5
8
  Seed_Runner
6
9
  Seed_Types
7
10
  Seed_Upload
@@ -2,7 +2,7 @@
2
2
  "version": "12.3.0",
3
3
  "bsc_path": "/home/runner/work/reventless-core/reventless-core/node_modules/@rescript/linux-x64/bin/bsc.exe",
4
4
  "bsc_hash": "75e3a59c95cc953608fd3dd6ea6ed68141bba4414a20a52f114261b8a48385fa",
5
- "rescript_config_hash": "ad3a9d479584c1d6e4fe10cd993d9e290f74732e9b0cb3dd5d7429e88b4bba38",
5
+ "rescript_config_hash": "25cfff836d200084949fdfdfec2f6875901bfee1f04d84634eca252ef1ca1ef1",
6
6
  "runtime_path": "/home/runner/work/reventless-core/reventless-core/node_modules/@rescript/runtime",
7
- "generated_at": "1785055311640"
7
+ "generated_at": "1786453304428"
8
8
  }
Binary file
Binary file
Binary file
@@ -9,9 +9,28 @@ module Random = Seed_Random
9
9
  module Client = Seed_Client
10
10
  module Runner = Seed_Runner
11
11
  module Upload = Seed_Upload
12
+ module Prompt = Seed_Prompt
13
+ module Connect = Seed_Connect
12
14
 
13
15
  exception Failed = Seed_Types.Failed
14
16
 
17
+ // A live target a data set seeds against: an authenticated client, whether uploads
18
+ // are skipped this run, and a label. Uploads mint through the domain API's
19
+ // `Upload_Presign` mutation on the client (route B), so no upload endpoint is carried.
20
+ type connection = Seed_Connect.connection = {
21
+ client: Seed_Client.t,
22
+ uploadsSkipped: bool,
23
+ label: string,
24
+ }
25
+
26
+ // A named, seedable data set. `seed` owns everything domain-specific.
27
+ type dataSet = Seed_Runner.dataSet = {
28
+ name: string,
29
+ label: string,
30
+ seed: connection => promise<unit>,
31
+ probeViews?: array<string>,
32
+ }
33
+
15
34
  type rec value = Seed_Types.value =
16
35
  | String(string)
17
36
  | Id(string)
@@ -10,6 +10,10 @@ let Runner;
10
10
 
11
11
  let Upload;
12
12
 
13
+ let Prompt;
14
+
15
+ let Connect;
16
+
13
17
  let Failed = Seed_Types$ReventlessSeed.Failed;
14
18
 
15
19
  let mutation = Seed_Types$ReventlessSeed.mutation;
@@ -25,6 +29,8 @@ export {
25
29
  Client,
26
30
  Runner,
27
31
  Upload,
32
+ Prompt,
33
+ Connect,
28
34
  Failed,
29
35
  mutation,
30
36
  ids,
Binary file
@@ -27,9 +27,12 @@ let sleep = (ms: int): promise<unit> => Promise.make((resolve, _) => setTimeout(
27
27
 
28
28
  type config = {
29
29
  endpoint: string,
30
- loginEndpoint: string,
31
- username: string,
32
- password: string,
30
+ // Present only for the `login` flow (a platform that mints tokens over HTTP,
31
+ // e.g. the local dev `/__inmemory/login`). Omit when the bearer is supplied
32
+ // out-of-band via `useToken` (e.g. a Cognito id token minted by the caller).
33
+ loginEndpoint?: string,
34
+ username?: string,
35
+ password?: string,
33
36
  }
34
37
 
35
38
  type t = {config: config, mutable token: option<string>}
@@ -40,6 +43,15 @@ let make = (~config: config): t => {config, token: None}
40
43
  Seed.Upload) can authenticate side-channel requests with the same identity. */
41
44
  let currentToken = (t: t): option<string> => t.token
42
45
 
46
+ /** The GraphQL endpoint this client targets — so `Seed.Upload` can resolve a
47
+ relative presigned `uploadUrl` against the same origin. */
48
+ let endpoint = (t: t): string => t.config.endpoint
49
+
50
+ /** Injects a bearer obtained out-of-band (e.g. a Cognito id token), instead of
51
+ minting one via `login`. Provider-agnostic: the harness only cares that the
52
+ token is a valid bearer for `endpoint`. */
53
+ let useToken = (t: t, token: string): unit => t.token = Some(token)
54
+
43
55
  // ── JSON helpers ────────────────────────────────────────────────────────────
44
56
 
45
57
  let field = (json: JSON.t, key: string): option<JSON.t> =>
@@ -61,28 +73,31 @@ let nodeString = (node: JSON.t, key: string): option<string> =>
61
73
  // ── Requests ────────────────────────────────────────────────────────────────
62
74
 
63
75
  let login = async (t: t): unit => {
76
+ let loginEndpoint = switch t.config.loginEndpoint {
77
+ | Some(e) => e
78
+ | None => throw(Failed("login: no loginEndpoint configured — supply one or call useToken"))
79
+ }
80
+ let username = t.config.username->Option.getOr("")
81
+ let password = t.config.password->Option.getOr("")
64
82
  let body = JSON.stringify(
65
83
  JSON.Encode.object(
66
84
  Dict.fromArray([
67
- ("username", JSON.Encode.string(t.config.username)),
68
- ("password", JSON.Encode.string(t.config.password)),
85
+ ("username", JSON.Encode.string(username)),
86
+ ("password", JSON.Encode.string(password)),
69
87
  ]),
70
88
  ),
71
89
  )
72
90
  let res = try await fetch(
73
- t.config.loginEndpoint,
91
+ loginEndpoint,
74
92
  {method: "POST", headers: Dict.fromArray([("content-type", "application/json")]), body},
75
93
  ) catch {
76
- | _ =>
77
- throw(
78
- Failed(`login: cannot reach ${t.config.loginEndpoint} — is the platform running?`),
79
- )
94
+ | _ => throw(Failed(`login: cannot reach ${loginEndpoint} — is the platform running?`))
80
95
  }
81
96
  if !(res->responseOk) {
82
97
  let detail = await res->responseText
83
98
  throw(
84
99
  Failed(
85
- `login as "${t.config.username}" failed with HTTP ${(res->responseStatus)
100
+ `login as "${username}" failed with HTTP ${(res->responseStatus)
86
101
  ->Int.toString}: ${detail}`,
87
102
  ),
88
103
  )
@@ -205,6 +220,42 @@ let queryAllNodes = async (t: t, ~field as fieldName: string, ~selection: string
205
220
  let countNodes = async (t: t, ~field: string): int =>
206
221
  (await queryAllNodes(t, ~field, ~selection="id"))->Array.length
207
222
 
223
+ /**
224
+ * Polls a connection field until the collected nodes satisfy `satisfied`, or the
225
+ * timeout elapses. Read models are eventually consistent: a view queried the
226
+ * instant after the writes that feed it can still read empty or partial (a
227
+ * DynamoDB connection scan is eventually consistent by default, and the write and
228
+ * read-back can land on different replicas), so a cross-check that asserts on a
229
+ * single immediate read races the projection. Same rationale as `waitForIds`,
230
+ * for the "observe the whole connection" case rather than a fixed id set.
231
+ *
232
+ * On timeout, throws `Failed(onTimeout(finalNodes))` so the caller can report
233
+ * what the view actually settled on — distinguishing a still-empty view from a
234
+ * genuine count mismatch — instead of a bare assertion.
235
+ */
236
+ let queryAllNodesUntil = async (
237
+ t: t,
238
+ ~field: string,
239
+ ~selection: string,
240
+ ~satisfied: array<JSON.t> => bool,
241
+ ~onTimeout: array<JSON.t> => string,
242
+ ~timeoutMs: int=60000,
243
+ ): array<JSON.t> => {
244
+ let deadline = nowMs() +. Int.toFloat(timeoutMs)
245
+ let result = ref(None)
246
+ while result.contents == None {
247
+ let nodes = await queryAllNodes(t, ~field, ~selection)
248
+ if satisfied(nodes) {
249
+ result := Some(nodes)
250
+ } else if nowMs() > deadline {
251
+ throw(Failed(onTimeout(nodes)))
252
+ } else {
253
+ await sleep(500)
254
+ }
255
+ }
256
+ result.contents->Option.getOr([])
257
+ }
258
+
208
259
  /**
209
260
  * Polls a `<View>ByIds` field until every id is present.
210
261
  *
@@ -21,6 +21,14 @@ function currentToken(t) {
21
21
  return t.token;
22
22
  }
23
23
 
24
+ function endpoint(t) {
25
+ return t.config.endpoint;
26
+ }
27
+
28
+ function useToken(t, token) {
29
+ t.token = token;
30
+ }
31
+
24
32
  function field(json, key) {
25
33
  if (typeof json === "object" && json !== null && !Array.isArray(json)) {
26
34
  return json[key];
@@ -38,19 +46,32 @@ function nodeString(node, key) {
38
46
  }
39
47
 
40
48
  async function login(t) {
49
+ let e = t.config.loginEndpoint;
50
+ let loginEndpoint;
51
+ if (e !== undefined) {
52
+ loginEndpoint = e;
53
+ } else {
54
+ throw {
55
+ RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
56
+ _1: "login: no loginEndpoint configured — supply one or call useToken",
57
+ Error: new Error()
58
+ };
59
+ }
60
+ let username = Stdlib_Option.getOr(t.config.username, "");
61
+ let password = Stdlib_Option.getOr(t.config.password, "");
41
62
  let body = JSON.stringify(Object.fromEntries([
42
63
  [
43
64
  "username",
44
- t.config.username
65
+ username
45
66
  ],
46
67
  [
47
68
  "password",
48
- t.config.password
69
+ password
49
70
  ]
50
71
  ]));
51
72
  let res;
52
73
  try {
53
- res = await fetch(t.config.loginEndpoint, {
74
+ res = await fetch(loginEndpoint, {
54
75
  method: "POST",
55
76
  headers: Object.fromEntries([[
56
77
  "content-type",
@@ -61,7 +82,7 @@ async function login(t) {
61
82
  } catch (exn) {
62
83
  throw {
63
84
  RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
64
- _1: `login: cannot reach ` + t.config.loginEndpoint + ` — is the platform running?`,
85
+ _1: `login: cannot reach ` + loginEndpoint + ` — is the platform running?`,
65
86
  Error: new Error()
66
87
  };
67
88
  }
@@ -69,7 +90,7 @@ async function login(t) {
69
90
  let detail = await res.text();
70
91
  throw {
71
92
  RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
72
- _1: `login as "` + t.config.username + `" failed with HTTP ` + res.status.toString() + `: ` + detail,
93
+ _1: `login as "` + username + `" failed with HTTP ` + res.status.toString() + `: ` + detail,
73
94
  Error: new Error()
74
95
  };
75
96
  }
@@ -191,6 +212,28 @@ async function countNodes(t, field) {
191
212
  return (await queryAllNodes(t, field, "id")).length;
192
213
  }
193
214
 
215
+ async function queryAllNodesUntil(t, field, selection, satisfied, onTimeout, timeoutMsOpt) {
216
+ let timeoutMs = timeoutMsOpt !== undefined ? timeoutMsOpt : 60000;
217
+ let deadline = Date.now() + timeoutMs;
218
+ let result;
219
+ while (result === undefined) {
220
+ let nodes = await queryAllNodes(t, field, selection);
221
+ if (satisfied(nodes)) {
222
+ result = nodes;
223
+ } else {
224
+ if (Date.now() > deadline) {
225
+ throw {
226
+ RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
227
+ _1: onTimeout(nodes),
228
+ Error: new Error()
229
+ };
230
+ }
231
+ await sleep(500);
232
+ }
233
+ };
234
+ return Stdlib_Option.getOr(result, []);
235
+ }
236
+
194
237
  async function waitForIds(t, fieldName, ids, timeoutMsOpt) {
195
238
  let timeoutMs = timeoutMsOpt !== undefined ? timeoutMsOpt : 60000;
196
239
  let deadline = Date.now() + timeoutMs;
@@ -227,6 +270,8 @@ export {
227
270
  sleep,
228
271
  make,
229
272
  currentToken,
273
+ endpoint,
274
+ useToken,
230
275
  field,
231
276
  asString,
232
277
  nodeString,
@@ -237,6 +282,7 @@ export {
237
282
  sendAll,
238
283
  queryAllNodes,
239
284
  countNodes,
285
+ queryAllNodesUntil,
240
286
  waitForIds,
241
287
  }
242
288
  /* No side effect */
Binary file
@@ -0,0 +1,86 @@
1
+ // Turns endpoints plus a login function into a ready `connection`.
2
+ //
3
+ // A connection is what a data set seeds against: an authenticated GraphQL
4
+ // client, the deployment's upload endpoints (empty when it serves no uploads),
5
+ // and a human label for the target. `make` is provider-agnostic — it prompts for
6
+ // credentials, calls the supplied `login` to obtain a bearer, and wires it onto
7
+ // the client via `useToken`. Where the bearer comes from (a local `/login`
8
+ // round-trip, a Cognito id token) is the caller's concern.
9
+
10
+ open Seed_Types
11
+
12
+ // Under route B the client mints uploads through the domain API's `Upload_Presign`
13
+ // mutation (authenticated by the same bearer as commands), so a connection needs no
14
+ // upload endpoint — just the authenticated client and whether uploads are skipped this
15
+ // run (`SEED_SKIP_UPLOADS`). Which store an asset uploads into is the caller's `~store`.
16
+ type connection = {
17
+ client: Seed_Client.t,
18
+ uploadsSkipped: bool,
19
+ label: string,
20
+ }
21
+
22
+ /**
23
+ * Prompts for credentials, calls `login` to mint a bearer, and returns a
24
+ * connection with that bearer already applied. `login` returns the bearer so a
25
+ * single `useToken` path serves every provider.
26
+ */
27
+ let make = async (
28
+ ~label: string,
29
+ ~endpoint: string,
30
+ ~login: (~username: string, ~password: string) => promise<string>,
31
+ ~localDefaults: bool=false,
32
+ ): connection => {
33
+ // `SEED_SKIP_UPLOADS` forces the upload phase to no-op — seed domain data fast, or
34
+ // skip a broken/absent upload path without editing the data set. The data set reads
35
+ // `connection.uploadsSkipped` and reports the skip.
36
+ let uploadsSkipped = Seed_Upload.uploadsSkipped()
37
+ let (username, password) = await Seed_Prompt.credentials(~localDefaults)
38
+ let token = await login(~username, ~password)
39
+ let client = Seed_Client.make(~config={endpoint: endpoint})
40
+ client->Seed_Client.useToken(token)
41
+ {client, uploadsSkipped, label}
42
+ }
43
+
44
+ /**
45
+ * A login function backed by an HTTP login endpoint (the local dev
46
+ * `/__inmemory/login` shape: POST `{username, password}` → `{token}`). Reuses
47
+ * `Seed_Client.login` but hands the token back for `useToken`.
48
+ */
49
+ let viaLoginEndpoint = (~loginEndpoint: string) => async (
50
+ ~username: string,
51
+ ~password: string,
52
+ ): string => {
53
+ let client = Seed_Client.make(
54
+ ~config={endpoint: loginEndpoint, loginEndpoint, username, password},
55
+ )
56
+ await Seed_Client.login(client)
57
+ switch Seed_Client.currentToken(client) {
58
+ | Some(token) => token
59
+ | None => throw(Failed(`login at ${loginEndpoint} returned no token`))
60
+ }
61
+ }
62
+
63
+ let envOr = (key: string, fallback: string): string =>
64
+ Seed_Prompt.envValue(key)->Option.getOr(fallback)
65
+
66
+ /**
67
+ * A ready `connect` thunk for the local dev platform, with the localhost
68
+ * defaults baked in and overridable per endpoint (arg, then env var, then
69
+ * default). Empty input at the credential prompt falls back to `admin`/`admin`.
70
+ *
71
+ * No upload endpoint: uploads mint through the domain API's `Upload_Presign` mutation
72
+ * on the same `graphql` endpoint, with the store passed per asset.
73
+ */
74
+ let local = (~graphql=?, ~login=?, ()): (unit => promise<connection>) => {
75
+ let endpoint =
76
+ graphql->Option.getOr(envOr("REVENTLESS_GRAPHQL_ENDPOINT", "http://localhost:4000/graphql"))
77
+ let loginEndpoint =
78
+ login->Option.getOr(envOr("REVENTLESS_LOGIN_ENDPOINT", "http://localhost:4000/__inmemory/login"))
79
+ () =>
80
+ make(
81
+ ~label="local",
82
+ ~endpoint,
83
+ ~login=viaLoginEndpoint(~loginEndpoint),
84
+ ~localDefaults=true,
85
+ )
86
+ }
@@ -0,0 +1,62 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
4
+ import * as Seed_Types$ReventlessSeed from "./Seed_Types.res.mjs";
5
+ import * as Seed_Client$ReventlessSeed from "./Seed_Client.res.mjs";
6
+ import * as Seed_Prompt$ReventlessSeed from "./Seed_Prompt.res.mjs";
7
+ import * as Seed_Upload$ReventlessSeed from "./Seed_Upload.res.mjs";
8
+
9
+ async function make(label, endpoint, login, localDefaultsOpt) {
10
+ let localDefaults = localDefaultsOpt !== undefined ? localDefaultsOpt : false;
11
+ let uploadsSkipped = Seed_Upload$ReventlessSeed.uploadsSkipped();
12
+ let match = await Seed_Prompt$ReventlessSeed.credentials(localDefaults);
13
+ let token = await login(match[0], match[1]);
14
+ let client = Seed_Client$ReventlessSeed.make({
15
+ endpoint: endpoint
16
+ });
17
+ Seed_Client$ReventlessSeed.useToken(client, token);
18
+ return {
19
+ client: client,
20
+ uploadsSkipped: uploadsSkipped,
21
+ label: label
22
+ };
23
+ }
24
+
25
+ function viaLoginEndpoint(loginEndpoint) {
26
+ return async (username, password) => {
27
+ let client = Seed_Client$ReventlessSeed.make({
28
+ endpoint: loginEndpoint,
29
+ loginEndpoint: loginEndpoint,
30
+ username: username,
31
+ password: password
32
+ });
33
+ await Seed_Client$ReventlessSeed.login(client);
34
+ let token = Seed_Client$ReventlessSeed.currentToken(client);
35
+ if (token !== undefined) {
36
+ return token;
37
+ }
38
+ throw {
39
+ RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
40
+ _1: `login at ` + loginEndpoint + ` returned no token`,
41
+ Error: new Error()
42
+ };
43
+ };
44
+ }
45
+
46
+ function envOr(key, fallback) {
47
+ return Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue(key), fallback);
48
+ }
49
+
50
+ function local(graphql, login, param) {
51
+ let endpoint = Stdlib_Option.getOr(graphql, Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue("REVENTLESS_GRAPHQL_ENDPOINT"), "http://localhost:4000/graphql"));
52
+ let loginEndpoint = Stdlib_Option.getOr(login, Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue("REVENTLESS_LOGIN_ENDPOINT"), "http://localhost:4000/__inmemory/login"));
53
+ return () => make("local", endpoint, viaLoginEndpoint(loginEndpoint), true);
54
+ }
55
+
56
+ export {
57
+ make,
58
+ viaLoginEndpoint,
59
+ envOr,
60
+ local,
61
+ }
62
+ /* Seed_Prompt-ReventlessSeed Not a pure module */
Binary file