@reventlessdev/reventless-seed 1.0.0-alpha.2 → 1.0.0-alpha.21
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.
- package/CHANGELOG.md +149 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.sourcedirs.json +1 -0
- package/lib/bs/ReventlessSeed.cmi +0 -0
- package/lib/bs/ReventlessSeed.cmt +0 -0
- package/lib/bs/ReventlessSeed.mlmap +6 -0
- package/lib/bs/compiler-info.json +2 -2
- package/lib/bs/src/Seed-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed.ast +0 -0
- package/lib/bs/src/Seed.res +12 -3
- package/lib/bs/src/Seed.res.mjs +3 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Client.ast +0 -0
- package/lib/bs/src/Seed_Client.res +382 -21
- package/lib/bs/src/Seed_Client.res.mjs +332 -24
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Connect.ast +0 -0
- package/lib/bs/src/Seed_Connect.res +281 -33
- package/lib/bs/src/Seed_Connect.res.mjs +162 -8
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Prompt.ast +0 -0
- package/lib/bs/src/Seed_Prompt.res +140 -41
- package/lib/bs/src/Seed_Prompt.res.mjs +88 -13
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Random.ast +0 -0
- package/lib/bs/src/Seed_Random.res +4 -2
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Runner.ast +0 -0
- package/lib/bs/src/Seed_Runner.res +45 -19
- package/lib/bs/src/Seed_Runner.res.mjs +19 -1
- package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload.ast +0 -0
- package/lib/bs/src/Seed_Upload.res +43 -43
- package/lib/bs/src/Seed_Upload.res.mjs +65 -69
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Users.ast +0 -0
- package/lib/bs/src/Seed_Users.res +92 -0
- package/lib/bs/src/Seed_Users.res.mjs +91 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_ClientTest.ast +0 -0
- package/lib/bs/tests/Seed_ClientTest.res +287 -0
- package/lib/bs/tests/Seed_ClientTest.res.mjs +268 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_ConnectTest.ast +0 -0
- package/lib/bs/tests/Seed_ConnectTest.res +64 -0
- package/lib/bs/tests/Seed_ConnectTest.res.mjs +56 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_PromptTest.ast +0 -0
- package/lib/bs/tests/Seed_PromptTest.res +55 -0
- package/lib/bs/tests/Seed_PromptTest.res.mjs +63 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_RandomTest.ast +0 -0
- package/lib/bs/tests/Seed_RandomTest.res +200 -0
- package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_UsersTest.ast +0 -0
- package/lib/bs/tests/Seed_UsersTest.res +129 -0
- package/lib/bs/tests/Seed_UsersTest.res.mjs +113 -0
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/ReventlessSeed.cmi +0 -0
- package/lib/ocaml/ReventlessSeed.cmt +0 -0
- package/lib/ocaml/ReventlessSeed.mlmap +6 -0
- package/lib/ocaml/Seed-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed.ast +0 -0
- package/lib/ocaml/Seed.res +12 -3
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Client.ast +0 -0
- package/lib/ocaml/Seed_Client.res +382 -21
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_ClientTest.ast +0 -0
- package/lib/ocaml/Seed_ClientTest.res +287 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Connect.ast +0 -0
- package/lib/ocaml/Seed_Connect.res +281 -33
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_ConnectTest.ast +0 -0
- package/lib/ocaml/Seed_ConnectTest.res +64 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Prompt.ast +0 -0
- package/lib/ocaml/Seed_Prompt.res +140 -41
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_PromptTest.ast +0 -0
- package/lib/ocaml/Seed_PromptTest.res +55 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Random.ast +0 -0
- package/lib/ocaml/Seed_Random.res +4 -2
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_RandomTest.ast +0 -0
- package/lib/ocaml/Seed_RandomTest.res +200 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Runner.ast +0 -0
- package/lib/ocaml/Seed_Runner.res +45 -19
- package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload.ast +0 -0
- package/lib/ocaml/Seed_Upload.res +43 -43
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Users.ast +0 -0
- package/lib/ocaml/Seed_Users.res +92 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_UsersTest.ast +0 -0
- package/lib/ocaml/Seed_UsersTest.res +129 -0
- package/package.json +7 -2
- package/rescript.json +9 -1
- package/src/Seed.res +12 -3
- package/src/Seed.res.mjs +3 -0
- package/src/Seed_Client.res +382 -21
- package/src/Seed_Client.res.mjs +332 -24
- package/src/Seed_Connect.res +281 -33
- package/src/Seed_Connect.res.mjs +162 -8
- package/src/Seed_Prompt.res +140 -41
- package/src/Seed_Prompt.res.mjs +88 -13
- package/src/Seed_Random.res +4 -2
- package/src/Seed_Runner.res +45 -19
- package/src/Seed_Runner.res.mjs +19 -1
- package/src/Seed_Upload.res +43 -43
- package/src/Seed_Upload.res.mjs +65 -69
- package/src/Seed_Users.res +92 -0
- package/src/Seed_Users.res.mjs +91 -0
- package/tests/Seed_ClientTest.res +287 -0
- package/tests/Seed_ClientTest.res.mjs +268 -0
- package/tests/Seed_ConnectTest.res +64 -0
- package/tests/Seed_ConnectTest.res.mjs +56 -0
- package/tests/Seed_PromptTest.res +55 -0
- package/tests/Seed_PromptTest.res.mjs +63 -0
- package/tests/Seed_RandomTest.res +200 -0
- package/tests/Seed_RandomTest.res.mjs +208 -0
- package/tests/Seed_UsersTest.res +129 -0
- package/tests/Seed_UsersTest.res.mjs +113 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// One shared readline interface for every interactive prompt in a seed run.
|
|
2
2
|
//
|
|
3
3
|
// The reason this module exists: creating and closing a fresh `readline`
|
|
4
|
-
// interface per prompt leaves stdin paused after the first `close`, so the
|
|
4
|
+
// interface per prompt leaves NodeProcess.stdin paused after the first `close`, so the
|
|
5
5
|
// second prompt (password after username) never fires and the run hangs. A
|
|
6
6
|
// single interface, created lazily and closed exactly once, avoids that — and a
|
|
7
7
|
// `muted` gate on its output lets password entry reuse the same interface
|
|
@@ -14,18 +14,8 @@ open Seed_Types
|
|
|
14
14
|
|
|
15
15
|
// ── Node bindings ─────────────────────────────────────────────────────────────
|
|
16
16
|
|
|
17
|
-
type stream
|
|
18
|
-
@val @scope("process") external stdin: stream = "stdin"
|
|
19
|
-
@val @scope("process") external stdout: stream = "stdout"
|
|
20
|
-
@send external writeStream: (stream, string) => unit = "write"
|
|
21
|
-
@get external isTTY: stream => bool = "isTTY"
|
|
22
|
-
@send external pauseStream: stream => unit = "pause"
|
|
23
|
-
@send external unrefStream: stream => unit = "unref"
|
|
24
|
-
|
|
25
|
-
@scope("process") @val external processEnv: dict<string> = "env"
|
|
26
|
-
|
|
27
17
|
type rl
|
|
28
|
-
type rlOptions = {input: stream, output: stream, terminal?: bool}
|
|
18
|
+
type rlOptions = {input: NodeProcess.stream, output: NodeProcess.stream, terminal?: bool}
|
|
29
19
|
@module("node:readline") external createInterface: rlOptions => rl = "createInterface"
|
|
30
20
|
@send external question: (rl, string, string => unit) => unit = "question"
|
|
31
21
|
@send external closeRl: rl => unit = "close"
|
|
@@ -42,10 +32,10 @@ let iface = (): rl =>
|
|
|
42
32
|
switch rlRef.contents {
|
|
43
33
|
| Some(rl) => rl
|
|
44
34
|
| None =>
|
|
45
|
-
let rl = createInterface({input: stdin, output: stdout, terminal: true})
|
|
35
|
+
let rl = createInterface({input: NodeProcess.stdin, output: NodeProcess.stdout, terminal: true})
|
|
46
36
|
rl->setWriteToOutput(s =>
|
|
47
37
|
if !muted.contents {
|
|
48
|
-
stdout->
|
|
38
|
+
NodeProcess.stdout->NodeProcess.write(s)
|
|
49
39
|
}
|
|
50
40
|
)
|
|
51
41
|
rlRef := Some(rl)
|
|
@@ -58,27 +48,31 @@ let close = (): unit =>
|
|
|
58
48
|
rl->closeRl
|
|
59
49
|
rlRef := None
|
|
60
50
|
// Closing the interface is not enough: a terminal-mode readline leaves
|
|
61
|
-
// stdin resumed and reffed, which keeps the event loop alive so the CLI
|
|
51
|
+
// NodeProcess.stdin resumed and reffed, which keeps the event loop alive so the CLI
|
|
62
52
|
// never exits after seeding. Release it explicitly.
|
|
63
|
-
stdin->
|
|
64
|
-
stdin->
|
|
53
|
+
NodeProcess.stdin->NodeProcess.pause
|
|
54
|
+
NodeProcess.stdin->NodeProcess.unref
|
|
65
55
|
| None => ()
|
|
66
56
|
}
|
|
67
57
|
|
|
68
58
|
// ── Env + TTY ─────────────────────────────────────────────────────────────────
|
|
69
59
|
|
|
70
60
|
let envValue = (key: string): option<string> =>
|
|
71
|
-
switch
|
|
61
|
+
switch NodeProcess.env->Dict.get(key) {
|
|
72
62
|
| Some(v) if v->String.trim != "" => Some(v->String.trim)
|
|
73
63
|
| _ => None
|
|
74
64
|
}
|
|
75
65
|
|
|
66
|
+
/** Whether an interactive prompt is possible at all. Callers that can carry on
|
|
67
|
+
without an answer ask this first; a prompt nobody can answer is worse than a
|
|
68
|
+
default, because it turns a workable run into a hang or a throw. */
|
|
69
|
+
let hasTty = (): bool => NodeProcess.stdin->NodeProcess.isTTY->Option.getOr(false)
|
|
70
|
+
|
|
76
71
|
let requireTty = (): unit =>
|
|
77
|
-
if !(
|
|
72
|
+
if !hasTty() {
|
|
78
73
|
throw(
|
|
79
74
|
Failed(
|
|
80
|
-
"no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* " ++
|
|
81
|
-
"env vars to run non-interactively.",
|
|
75
|
+
"no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* " ++ "env vars to run non-interactively.",
|
|
82
76
|
),
|
|
83
77
|
)
|
|
84
78
|
}
|
|
@@ -101,24 +95,41 @@ let askHidden = (query: string): promise<string> =>
|
|
|
101
95
|
let rl = iface()
|
|
102
96
|
rl->question(query, answer => {
|
|
103
97
|
muted := false
|
|
104
|
-
stdout->
|
|
98
|
+
NodeProcess.stdout->NodeProcess.write("\n")
|
|
105
99
|
resolve(answer)
|
|
106
100
|
})
|
|
107
101
|
muted := true
|
|
108
102
|
})
|
|
109
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Whether an answer means yes — the one vocabulary, for the typed reply and the
|
|
106
|
+
* env var that stands in for it alike.
|
|
107
|
+
*
|
|
108
|
+
* It exists because those two drifted: a `[y/N]` prompt took `y`, and the env
|
|
109
|
+
* var beside it took only `1` or `yes`, so the obvious `SEED_RESET_CONFIRM=y`
|
|
110
|
+
* silently fell through to the interactive branch — which, on the CI runs the
|
|
111
|
+
* variable exists for, has no TTY and throws. Two spellings of one question are
|
|
112
|
+
* one spelling too many; callers ask this instead of comparing strings.
|
|
113
|
+
*
|
|
114
|
+
* Trimmed and case-folded, so `Yes`/` y ` answer the same as `y`.
|
|
115
|
+
*/
|
|
116
|
+
let isAffirmative = (answer: string): bool =>
|
|
117
|
+
switch answer->String.trim->String.toLowerCase {
|
|
118
|
+
| "y" | "yes" | "1" => true
|
|
119
|
+
| _ => false
|
|
120
|
+
}
|
|
121
|
+
|
|
110
122
|
/**
|
|
111
123
|
* Chooses one of `options` (a label paired with the value it selects).
|
|
112
124
|
*
|
|
113
125
|
* Auto-returns when there is a single option, so a lone data set or stack needs
|
|
114
126
|
* no keypress. `env` (e.g. `SEED_SET`) preselects by matching label or 1-based
|
|
115
127
|
* index, so CI runs without a TTY. Otherwise it prints a numbered menu.
|
|
128
|
+
*
|
|
129
|
+
* `defaultIndex` makes Enter a valid answer, selecting that 0-based option;
|
|
130
|
+
* without one every reply must name a choice.
|
|
116
131
|
*/
|
|
117
|
-
let select = async (
|
|
118
|
-
~title: string,
|
|
119
|
-
~options: array<(string, 'a)>,
|
|
120
|
-
~env=?,
|
|
121
|
-
): 'a =>
|
|
132
|
+
let select = async (~title: string, ~options: array<(string, 'a)>, ~env=?, ~defaultIndex=?): 'a =>
|
|
122
133
|
switch options {
|
|
123
134
|
| [(_, only)] => only
|
|
124
135
|
| _ =>
|
|
@@ -145,15 +156,24 @@ let select = async (
|
|
|
145
156
|
options->Array.forEachWithIndex(((label, _), i) =>
|
|
146
157
|
Console.log(` ${(i + 1)->Int.toString}) ${label}`)
|
|
147
158
|
)
|
|
159
|
+
let fallback = defaultIndex->Option.flatMap(i => options->Array.get(i))
|
|
160
|
+
let hint = switch (defaultIndex, fallback) {
|
|
161
|
+
| (Some(i), Some(_)) => ` (default ${(i + 1)->Int.toString})`
|
|
162
|
+
| _ => ""
|
|
163
|
+
}
|
|
148
164
|
let rec pick = async (): 'a => {
|
|
149
|
-
let answer = await ask(`\nSelect [1-${
|
|
150
|
-
switch
|
|
151
|
-
| Some(
|
|
152
|
-
let (_, value) = options->Array.getUnsafe(n - 1)
|
|
153
|
-
value
|
|
165
|
+
let answer = await ask(`\nSelect [1-${options->Array.length->Int.toString}]${hint}: `)
|
|
166
|
+
switch (answer, fallback) {
|
|
167
|
+
| ("", Some((_, value))) => value
|
|
154
168
|
| _ =>
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
switch Int.fromString(answer) {
|
|
170
|
+
| Some(n) if n >= 1 && n <= options->Array.length =>
|
|
171
|
+
let (_, value) = options->Array.getUnsafe(n - 1)
|
|
172
|
+
value
|
|
173
|
+
| _ =>
|
|
174
|
+
Console.log(" Not a valid choice.")
|
|
175
|
+
await pick()
|
|
176
|
+
}
|
|
157
177
|
}
|
|
158
178
|
}
|
|
159
179
|
await pick()
|
|
@@ -161,13 +181,30 @@ let select = async (
|
|
|
161
181
|
}
|
|
162
182
|
|
|
163
183
|
/**
|
|
164
|
-
*
|
|
184
|
+
* The account a run authenticated as, alongside every account the platform's
|
|
185
|
+
* accounts file declares.
|
|
165
186
|
*
|
|
166
|
-
* `
|
|
167
|
-
* `
|
|
187
|
+
* `accounts` is `[]` whenever no file was read — the
|
|
188
|
+
* `REVENTLESS_DEMO_USER`/`REVENTLESS_DEMO_PASSWORD` path bypasses it entirely,
|
|
189
|
+
* and so does typing both halves — so a consumer must handle empty rather than
|
|
190
|
+
* assume the file was there. `caller` is always populated, but carries no
|
|
191
|
+
* `groups` and no `userId` on those paths: nothing read them off a file.
|
|
168
192
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
193
|
+
type resolved = {caller: Seed_Users.user, accounts: array<Seed_Users.user>}
|
|
194
|
+
|
|
195
|
+
let typedUser = (~username: string, ~password: string): Seed_Users.user => {
|
|
196
|
+
username,
|
|
197
|
+
password,
|
|
198
|
+
groups: [],
|
|
199
|
+
userId: None,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Typing both halves is the fallback, not the first offer: it is what happens
|
|
203
|
+
// when the platform keeps no accounts file. `envUser` is threaded in so a
|
|
204
|
+
// `REVENTLESS_DEMO_USER` that named nobody in the file still skips the username
|
|
205
|
+
// prompt rather than asking for a name that was already given.
|
|
206
|
+
let askCredentials = async (~localDefaults: bool, ~envUser: option<string>): Seed_Users.user => {
|
|
207
|
+
let username = switch envUser {
|
|
171
208
|
| Some(u) => u
|
|
172
209
|
| None =>
|
|
173
210
|
requireTty()
|
|
@@ -181,8 +218,70 @@ let credentials = async (~localDefaults: bool=false): (string, string) => {
|
|
|
181
218
|
let entered = await askHidden(localDefaults ? "Password [admin]: " : "Password: ")
|
|
182
219
|
entered == "" && localDefaults ? "admin" : entered
|
|
183
220
|
}
|
|
184
|
-
|
|
221
|
+
typedUser(~username, ~password)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// The accounts file the platform already keeps (`.reventless/users.yaml`, or
|
|
225
|
+
// `SEED_USERS_FILE`). It records the password beside the username, so choosing
|
|
226
|
+
// an account is the whole credential step — nothing is typed.
|
|
227
|
+
//
|
|
228
|
+
// A named `REVENTLESS_DEMO_USER` picks its entry directly; otherwise the file's
|
|
229
|
+
// accounts are offered in the order it defines them, first as the default.
|
|
230
|
+
// `None` means the file has nothing to offer and the caller should ask.
|
|
231
|
+
//
|
|
232
|
+
// The whole list travels back with the chosen account, not just the credentials
|
|
233
|
+
// it supplied: the file is also the only place a demo owner's id can be looked
|
|
234
|
+
// up, and reading it once to pick a login and never again is what let a data set
|
|
235
|
+
// seed rows under ids nobody on the platform holds.
|
|
236
|
+
let fromUsersFile = async (~envUser: option<string>): option<resolved> =>
|
|
237
|
+
switch Seed_Users.load(~path=?envValue("SEED_USERS_FILE")) {
|
|
238
|
+
| None => None
|
|
239
|
+
| Some((path, users)) =>
|
|
240
|
+
let chosen = switch envUser {
|
|
241
|
+
| Some(name) => users->Array.find(u => u.username == name)
|
|
242
|
+
| None =>
|
|
243
|
+
Some(
|
|
244
|
+
await select(
|
|
245
|
+
~title=`User (${path}):`,
|
|
246
|
+
~options=users->Array.map(u => (Seed_Users.label(u), u)),
|
|
247
|
+
~env="SEED_USER",
|
|
248
|
+
~defaultIndex=0,
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
// Logged for every arm, including the single-account file that selects
|
|
253
|
+
// itself without a keypress: which identity seeded the data is the thing an
|
|
254
|
+
// operator checks when owner-scoped rows turn up under the wrong account.
|
|
255
|
+
chosen->Option.map(u => {
|
|
256
|
+
Console.log(`Logging in as ${u.username} (from ${path})`)
|
|
257
|
+
{caller: u, accounts: users}
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Resolves the credentials a seed run logs in with.
|
|
263
|
+
*
|
|
264
|
+
* `REVENTLESS_DEMO_USER` + `REVENTLESS_DEMO_PASSWORD` together are the
|
|
265
|
+
* non-interactive path and skip everything below. Otherwise the platform's
|
|
266
|
+
* `.reventless/users.yaml` supplies the accounts to choose from, and only a
|
|
267
|
+
* platform without one falls back to typing both halves — where, with
|
|
268
|
+
* `localDefaults`, empty input means `admin`/`admin`.
|
|
269
|
+
*
|
|
270
|
+
* Returns the resolved account rather than a pair, and the accounts file
|
|
271
|
+
* alongside it when there was one — see `resolved`.
|
|
272
|
+
*/
|
|
273
|
+
let credentials = async (~localDefaults: bool=false): resolved => {
|
|
274
|
+
let envUser = envValue("REVENTLESS_DEMO_USER")
|
|
275
|
+
let resolved = switch (envUser, envValue("REVENTLESS_DEMO_PASSWORD")) {
|
|
276
|
+
| (Some(username), Some(password)) => {caller: typedUser(~username, ~password), accounts: []}
|
|
277
|
+
| _ =>
|
|
278
|
+
switch await fromUsersFile(~envUser) {
|
|
279
|
+
| Some(resolved) => resolved
|
|
280
|
+
| None => {caller: await askCredentials(~localDefaults, ~envUser), accounts: []}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if resolved.caller.username == "" || resolved.caller.password == "" {
|
|
185
284
|
throw(Failed("username and password are required."))
|
|
186
285
|
}
|
|
187
|
-
|
|
286
|
+
resolved
|
|
188
287
|
}
|
|
@@ -5,6 +5,7 @@ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
|
5
5
|
import * as Nodereadline from "node:readline";
|
|
6
6
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
7
7
|
import * as Seed_Types$ReventlessSeed from "./Seed_Types.res.mjs";
|
|
8
|
+
import * as Seed_Users$ReventlessSeed from "./Seed_Users.res.mjs";
|
|
8
9
|
|
|
9
10
|
let rlRef = {
|
|
10
11
|
contents: undefined
|
|
@@ -52,8 +53,12 @@ function envValue(key) {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
function hasTty() {
|
|
57
|
+
return Stdlib_Option.getOr(process.stdin.isTTY, false);
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
function requireTty() {
|
|
56
|
-
if (process.stdin.isTTY) {
|
|
61
|
+
if (Stdlib_Option.getOr(process.stdin.isTTY, false)) {
|
|
57
62
|
return;
|
|
58
63
|
}
|
|
59
64
|
throw {
|
|
@@ -82,7 +87,19 @@ function askHidden(query) {
|
|
|
82
87
|
});
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
|
|
90
|
+
function isAffirmative(answer) {
|
|
91
|
+
let match = answer.trim().toLowerCase();
|
|
92
|
+
switch (match) {
|
|
93
|
+
case "1" :
|
|
94
|
+
case "y" :
|
|
95
|
+
case "yes" :
|
|
96
|
+
return true;
|
|
97
|
+
default:
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function select(title, options, env, defaultIndex) {
|
|
86
103
|
if (options.length === 1) {
|
|
87
104
|
return options[0][1];
|
|
88
105
|
}
|
|
@@ -106,8 +123,13 @@ async function select(title, options, env) {
|
|
|
106
123
|
options.forEach((param, i) => {
|
|
107
124
|
console.log(` ` + (i + 1 | 0).toString() + `) ` + param[0]);
|
|
108
125
|
});
|
|
126
|
+
let fallback = Stdlib_Option.flatMap(defaultIndex, i => options[i]);
|
|
127
|
+
let hint = defaultIndex !== undefined && fallback !== undefined ? ` (default ` + (defaultIndex + 1 | 0).toString() + `)` : "";
|
|
109
128
|
let pick = async () => {
|
|
110
|
-
let answer = await ask(`\nSelect [1-` + options.length.toString() + `]
|
|
129
|
+
let answer = await ask(`\nSelect [1-` + options.length.toString() + `]` + hint + `: `);
|
|
130
|
+
if (answer === "" && fallback !== undefined) {
|
|
131
|
+
return fallback[1];
|
|
132
|
+
}
|
|
111
133
|
let n = Stdlib_Int.fromString(answer, undefined);
|
|
112
134
|
if (n !== undefined) {
|
|
113
135
|
if (n >= 1 && n <= options.length) {
|
|
@@ -124,12 +146,19 @@ async function select(title, options, env) {
|
|
|
124
146
|
return await pick();
|
|
125
147
|
}
|
|
126
148
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
function typedUser(username, password) {
|
|
150
|
+
return {
|
|
151
|
+
username: username,
|
|
152
|
+
password: password,
|
|
153
|
+
groups: [],
|
|
154
|
+
userId: undefined
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function askCredentials(localDefaults, envUser) {
|
|
130
159
|
let username;
|
|
131
|
-
if (
|
|
132
|
-
username =
|
|
160
|
+
if (envUser !== undefined) {
|
|
161
|
+
username = envUser;
|
|
133
162
|
} else {
|
|
134
163
|
requireTty();
|
|
135
164
|
let entered = await ask(localDefaults ? "Username [admin]: " : "Username: ");
|
|
@@ -144,17 +173,58 @@ async function credentials(localDefaultsOpt) {
|
|
|
144
173
|
let entered$1 = await askHidden(localDefaults ? "Password [admin]: " : "Password: ");
|
|
145
174
|
password = entered$1 === "" && localDefaults ? "admin" : entered$1;
|
|
146
175
|
}
|
|
147
|
-
|
|
176
|
+
return typedUser(username, password);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function fromUsersFile(envUser) {
|
|
180
|
+
let match = Seed_Users$ReventlessSeed.load(envValue("SEED_USERS_FILE"));
|
|
181
|
+
if (match === undefined) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
let users = match[1];
|
|
185
|
+
let path = match[0];
|
|
186
|
+
let chosen = envUser !== undefined ? users.find(u => u.username === envUser) : await select(`User (` + path + `):`, users.map(u => [
|
|
187
|
+
Seed_Users$ReventlessSeed.label(u),
|
|
188
|
+
u
|
|
189
|
+
]), "SEED_USER", 0);
|
|
190
|
+
return Stdlib_Option.map(chosen, u => {
|
|
191
|
+
console.log(`Logging in as ` + u.username + ` (from ` + path + `)`);
|
|
192
|
+
return {
|
|
193
|
+
caller: u,
|
|
194
|
+
accounts: users
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function credentials(localDefaultsOpt) {
|
|
200
|
+
let localDefaults = localDefaultsOpt !== undefined ? localDefaultsOpt : false;
|
|
201
|
+
let envUser = envValue("REVENTLESS_DEMO_USER");
|
|
202
|
+
let match = envValue("REVENTLESS_DEMO_PASSWORD");
|
|
203
|
+
let resolved;
|
|
204
|
+
let exit = 0;
|
|
205
|
+
if (envUser !== undefined && match !== undefined) {
|
|
206
|
+
resolved = {
|
|
207
|
+
caller: typedUser(envUser, match),
|
|
208
|
+
accounts: []
|
|
209
|
+
};
|
|
210
|
+
} else {
|
|
211
|
+
exit = 1;
|
|
212
|
+
}
|
|
213
|
+
if (exit === 1) {
|
|
214
|
+
let resolved$1 = await fromUsersFile(envUser);
|
|
215
|
+
resolved = resolved$1 !== undefined ? resolved$1 : ({
|
|
216
|
+
caller: await askCredentials(localDefaults, envUser),
|
|
217
|
+
accounts: []
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (resolved.caller.username === "" || resolved.caller.password === "") {
|
|
148
221
|
throw {
|
|
149
222
|
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
150
223
|
_1: "username and password are required.",
|
|
151
224
|
Error: new Error()
|
|
152
225
|
};
|
|
153
226
|
}
|
|
154
|
-
return
|
|
155
|
-
username,
|
|
156
|
-
password
|
|
157
|
-
];
|
|
227
|
+
return resolved;
|
|
158
228
|
}
|
|
159
229
|
|
|
160
230
|
export {
|
|
@@ -163,10 +233,15 @@ export {
|
|
|
163
233
|
iface,
|
|
164
234
|
close,
|
|
165
235
|
envValue,
|
|
236
|
+
hasTty,
|
|
166
237
|
requireTty,
|
|
167
238
|
ask,
|
|
168
239
|
askHidden,
|
|
240
|
+
isAffirmative,
|
|
169
241
|
select,
|
|
242
|
+
typedUser,
|
|
243
|
+
askCredentials,
|
|
244
|
+
fromUsersFile,
|
|
170
245
|
credentials,
|
|
171
246
|
}
|
|
172
247
|
/* node:readline Not a pure module */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -10,13 +10,15 @@ type t = {mutable state: int}
|
|
|
10
10
|
|
|
11
11
|
let make = (~seed: int): t => {state: seed}
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
/** mulberry32 — small, fast, and stable across JS engines and Node versions. */
|
|
15
14
|
let float = (r: t): float => {
|
|
16
15
|
r.state = (r.state + 0x6d2b79f5)->Int.bitwiseOr(0)
|
|
17
16
|
let a = r.state
|
|
18
17
|
let b = imul(a->Int.bitwiseXor(a->Int.shiftRightUnsigned(15)), a->Int.bitwiseOr(1))
|
|
19
|
-
let c =
|
|
18
|
+
let c =
|
|
19
|
+
b->Int.bitwiseXor(
|
|
20
|
+
b + imul(b->Int.bitwiseXor(b->Int.shiftRightUnsigned(7)), b->Int.bitwiseOr(61)),
|
|
21
|
+
)
|
|
20
22
|
let bits = c->Int.bitwiseXor(c->Int.shiftRightUnsigned(14))
|
|
21
23
|
// `bits` is a signed 32-bit result; fold the sign bit back in to get the
|
|
22
24
|
// unsigned value a `>>> 0` would produce.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
open Seed_Types
|
|
4
4
|
|
|
5
|
-
@scope("process") @val external exit: int => unit = "exit"
|
|
6
|
-
@scope("process") @val external env: dict<string> = "env"
|
|
7
|
-
|
|
8
5
|
let envOr = (key: string, fallback: string): string =>
|
|
9
|
-
env->Dict.get(key)->Option.getOr(fallback)
|
|
6
|
+
NodeProcess.env->Dict.get(key)->Option.getOr(fallback)
|
|
10
7
|
|
|
11
8
|
/** One line of progress per phase, so a slow run never looks hung. */
|
|
12
9
|
let report = (line: string): unit => Console.log(` ${line}`)
|
|
@@ -60,14 +57,12 @@ let verifyViews = async (client: Seed_Client.t, ~views: array<view>): dict<int>
|
|
|
60
57
|
Console.log(` ${count->Int.toString->String.padStart(4, " ")} ${name}${note}`)
|
|
61
58
|
})
|
|
62
59
|
|
|
63
|
-
let empty =
|
|
64
|
-
|
|
65
|
-
->
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
)
|
|
60
|
+
let empty = views->Array.filterMap(v =>
|
|
61
|
+
switch v {
|
|
62
|
+
| Seeded(name) if counts->Dict.get(name)->Option.getOr(0) == 0 => Some(name)
|
|
63
|
+
| _ => None
|
|
64
|
+
}
|
|
65
|
+
)
|
|
71
66
|
if empty->Array.length > 0 {
|
|
72
67
|
throw(Failed(`these views are still empty after seeding: ${empty->Array.join(", ")}`))
|
|
73
68
|
}
|
|
@@ -90,6 +85,33 @@ let warn = (warnings: array<string>): unit =>
|
|
|
90
85
|
warnings->Array.forEach(w => Console.log(` - ${w}`))
|
|
91
86
|
}
|
|
92
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Pre-flight: refuse to seed onto a store that already holds data.
|
|
90
|
+
*
|
|
91
|
+
* The harness is a one-shot against a fresh store — a re-run would hit the
|
|
92
|
+
* domain's own duplicate rejections (`CategoryAlreadyExists`, …) and abort
|
|
93
|
+
* mid-phase. Catching it here, before any command is sent, turns that into an
|
|
94
|
+
* honest "nothing was written" startup abort instead of a misleading
|
|
95
|
+
* half-seeded one. It is the inverse of `verifyViews`: seeding refuses to start
|
|
96
|
+
* unless the store reads empty. Stops at the first non-empty probe view, so a
|
|
97
|
+
* populated store aborts after a single query.
|
|
98
|
+
*/
|
|
99
|
+
let assertStoreEmpty = async (client: Seed_Client.t, ~probeViews: array<string>): unit =>
|
|
100
|
+
for i in 0 to probeViews->Array.length - 1 {
|
|
101
|
+
switch probeViews->Array.get(i) {
|
|
102
|
+
| Some(name) =>
|
|
103
|
+
let count = await Seed_Client.countNodes(client, ~field=name)
|
|
104
|
+
if count > 0 {
|
|
105
|
+
throw(
|
|
106
|
+
Failed(
|
|
107
|
+
`the target store is not empty — "${name}" already holds ${count->Int.toString} row(s). Seeding is a one-shot against a fresh store; reset the store before re-running.`,
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
| None => ()
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
93
115
|
/**
|
|
94
116
|
* Wraps a seed run. On failure it prints the cause and exits non-zero, saying
|
|
95
117
|
* plainly that the store is now half-seeded — recovery is a reset, not a re-run.
|
|
@@ -100,7 +122,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
100
122
|
// Exit cleanly: HTTP keep-alive sockets (and, on the interactive path, the
|
|
101
123
|
// readline/stdin handle) can otherwise keep the event loop alive so the CLI
|
|
102
124
|
// appears to hang after a successful run.
|
|
103
|
-
exit(0)
|
|
125
|
+
NodeProcess.exit(0)
|
|
104
126
|
} catch {
|
|
105
127
|
| Failed(message) =>
|
|
106
128
|
Console.error("")
|
|
@@ -108,15 +130,13 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
108
130
|
Console.error("fresh store once the cause below is fixed.")
|
|
109
131
|
Console.error("")
|
|
110
132
|
Console.error(message)
|
|
111
|
-
exit(1)
|
|
133
|
+
NodeProcess.exit(1)
|
|
112
134
|
| exn =>
|
|
113
135
|
Console.error("")
|
|
114
136
|
Console.error("Seeding aborted with an unexpected error:")
|
|
115
137
|
Console.error("")
|
|
116
|
-
Console.error(
|
|
117
|
-
|
|
118
|
-
)
|
|
119
|
-
exit(1)
|
|
138
|
+
Console.error(exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown"))
|
|
139
|
+
NodeProcess.exit(1)
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
/**
|
|
@@ -128,6 +148,9 @@ type dataSet = {
|
|
|
128
148
|
name: string,
|
|
129
149
|
label: string,
|
|
130
150
|
seed: Seed_Connect.connection => promise<unit>,
|
|
151
|
+
// View names probed by the fresh-store guard before any command is sent; a
|
|
152
|
+
// non-empty one aborts the run at startup. Omit to skip the guard.
|
|
153
|
+
probeViews?: array<string>,
|
|
131
154
|
}
|
|
132
155
|
|
|
133
156
|
/**
|
|
@@ -142,7 +165,7 @@ let abortStartup = (message: string): unit => {
|
|
|
142
165
|
Console.error("Seeding did not start — nothing was written. Fix the cause below and re-run.")
|
|
143
166
|
Console.error("")
|
|
144
167
|
Console.error(message)
|
|
145
|
-
exit(1)
|
|
168
|
+
NodeProcess.exit(1)
|
|
146
169
|
}
|
|
147
170
|
|
|
148
171
|
/**
|
|
@@ -179,6 +202,9 @@ let seed = (~sets: array<dataSet>, ~connect: unit => promise<Seed_Connect.connec
|
|
|
179
202
|
}
|
|
180
203
|
let connection = await connect()
|
|
181
204
|
Seed_Prompt.close()
|
|
205
|
+
// Runs inside this pre-seed `try`, so refusing a non-empty store (or a
|
|
206
|
+
// failed probe query) is reported as "did not start", not "half-seeded".
|
|
207
|
+
await assertStoreEmpty(connection.client, ~probeViews=chosen.probeViews->Option.getOr([]))
|
|
182
208
|
Some((chosen, connection))
|
|
183
209
|
} catch {
|
|
184
210
|
| Failed(message) =>
|
|
@@ -83,6 +83,22 @@ function warn(warnings) {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
async function assertStoreEmpty(client, probeViews) {
|
|
87
|
+
for (let i = 0, i_finish = probeViews.length; i < i_finish; ++i) {
|
|
88
|
+
let name = probeViews[i];
|
|
89
|
+
if (name !== undefined) {
|
|
90
|
+
let count = await Seed_Client$ReventlessSeed.countNodes(client, name);
|
|
91
|
+
if (count > 0) {
|
|
92
|
+
throw {
|
|
93
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
94
|
+
_1: `the target store is not empty — "` + name + `" already holds ` + count.toString() + ` row(s). Seeding is a one-shot against a fresh store; reset the store before re-running.`,
|
|
95
|
+
Error: new Error()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
86
102
|
async function run(main) {
|
|
87
103
|
try {
|
|
88
104
|
await main();
|
|
@@ -139,13 +155,14 @@ function seed(sets, connect) {
|
|
|
139
155
|
chosen = await Seed_Prompt$ReventlessSeed.select("Data set:", sets.map(s => [
|
|
140
156
|
s.label,
|
|
141
157
|
s
|
|
142
|
-
]), undefined);
|
|
158
|
+
]), undefined, undefined);
|
|
143
159
|
}
|
|
144
160
|
} else {
|
|
145
161
|
chosen = sets[0];
|
|
146
162
|
}
|
|
147
163
|
let connection = await connect();
|
|
148
164
|
Seed_Prompt$ReventlessSeed.close();
|
|
165
|
+
await assertStoreEmpty(connection.client, Stdlib_Option.getOr(chosen.probeViews, []));
|
|
149
166
|
started = [
|
|
150
167
|
chosen,
|
|
151
168
|
connection
|
|
@@ -179,6 +196,7 @@ export {
|
|
|
179
196
|
verifyViews,
|
|
180
197
|
unfillableWarnings,
|
|
181
198
|
warn,
|
|
199
|
+
assertStoreEmpty,
|
|
182
200
|
run,
|
|
183
201
|
abortStartup,
|
|
184
202
|
seed,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|