@reventlessdev/reventless-seed 1.0.0-alpha.1 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/ReventlessSeed.cmi +0 -0
- package/lib/bs/ReventlessSeed.cmt +0 -0
- package/lib/bs/ReventlessSeed.mlmap +2 -0
- package/lib/bs/compiler-info.json +1 -1
- 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 +17 -0
- package/lib/bs/src/Seed.res.mjs +6 -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 +22 -11
- package/lib/bs/src/Seed_Client.res.mjs +23 -5
- 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 +84 -0
- package/lib/bs/src/Seed_Connect.res.mjs +62 -0
- 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 +188 -0
- package/lib/bs/src/Seed_Prompt.res.mjs +172 -0
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
- 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 +86 -1
- package/lib/bs/src/Seed_Runner.res.mjs +69 -1
- package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -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 +2 -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 +17 -0
- 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 +22 -11
- 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 +84 -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 +188 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -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 +86 -1
- package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/package.json +1 -1
- package/src/Seed.res +17 -0
- package/src/Seed.res.mjs +6 -0
- package/src/Seed_Client.res +22 -11
- package/src/Seed_Client.res.mjs +23 -5
- package/src/Seed_Connect.res +84 -0
- package/src/Seed_Connect.res.mjs +62 -0
- package/src/Seed_Prompt.res +188 -0
- package/src/Seed_Prompt.res.mjs +172 -0
- package/src/Seed_Runner.res +86 -1
- package/src/Seed_Runner.res.mjs +69 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
4
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
import * as Nodereadline from "node:readline";
|
|
6
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
7
|
+
import * as Seed_Types$ReventlessSeed from "./Seed_Types.res.mjs";
|
|
8
|
+
|
|
9
|
+
let rlRef = {
|
|
10
|
+
contents: undefined
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let muted = {
|
|
14
|
+
contents: false
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function iface() {
|
|
18
|
+
let rl = rlRef.contents;
|
|
19
|
+
if (rl !== undefined) {
|
|
20
|
+
return Primitive_option.valFromOption(rl);
|
|
21
|
+
}
|
|
22
|
+
let rl$1 = Nodereadline.createInterface({
|
|
23
|
+
input: process.stdin,
|
|
24
|
+
output: process.stdout,
|
|
25
|
+
terminal: true
|
|
26
|
+
});
|
|
27
|
+
rl$1._writeToOutput = s => {
|
|
28
|
+
if (!muted.contents) {
|
|
29
|
+
process.stdout.write(s);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
rlRef.contents = Primitive_option.some(rl$1);
|
|
34
|
+
return rl$1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function close() {
|
|
38
|
+
let rl = rlRef.contents;
|
|
39
|
+
if (rl !== undefined) {
|
|
40
|
+
Primitive_option.valFromOption(rl).close();
|
|
41
|
+
rlRef.contents = undefined;
|
|
42
|
+
process.stdin.pause();
|
|
43
|
+
process.stdin.unref();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function envValue(key) {
|
|
49
|
+
let v = process.env[key];
|
|
50
|
+
if (v !== undefined && v.trim() !== "") {
|
|
51
|
+
return v.trim();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function requireTty() {
|
|
56
|
+
if (process.stdin.isTTY) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
throw {
|
|
60
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
61
|
+
_1: "no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* env vars to run non-interactively.",
|
|
62
|
+
Error: new Error()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function ask(query) {
|
|
67
|
+
return new Promise((resolve, param) => {
|
|
68
|
+
let rl = iface();
|
|
69
|
+
rl.question(query, answer => resolve(answer.trim()));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function askHidden(query) {
|
|
74
|
+
return new Promise((resolve, param) => {
|
|
75
|
+
let rl = iface();
|
|
76
|
+
rl.question(query, answer => {
|
|
77
|
+
muted.contents = false;
|
|
78
|
+
process.stdout.write("\n");
|
|
79
|
+
resolve(answer);
|
|
80
|
+
});
|
|
81
|
+
muted.contents = true;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function select(title, options, env) {
|
|
86
|
+
if (options.length === 1) {
|
|
87
|
+
return options[0][1];
|
|
88
|
+
}
|
|
89
|
+
let fromEnv = Stdlib_Option.flatMap(Stdlib_Option.flatMap(env, envValue), v => {
|
|
90
|
+
let i = options.findIndex(param => param[0] === v);
|
|
91
|
+
if (i !== -1) {
|
|
92
|
+
return options[i];
|
|
93
|
+
}
|
|
94
|
+
let n = Stdlib_Int.fromString(v, undefined);
|
|
95
|
+
if (n !== undefined && n >= 1 && n <= options.length) {
|
|
96
|
+
return options[n - 1 | 0];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (fromEnv !== undefined) {
|
|
100
|
+
return fromEnv[1];
|
|
101
|
+
}
|
|
102
|
+
requireTty();
|
|
103
|
+
console.log("");
|
|
104
|
+
console.log(title);
|
|
105
|
+
console.log("");
|
|
106
|
+
options.forEach((param, i) => {
|
|
107
|
+
console.log(` ` + (i + 1 | 0).toString() + `) ` + param[0]);
|
|
108
|
+
});
|
|
109
|
+
let pick = async () => {
|
|
110
|
+
let answer = await ask(`\nSelect [1-` + options.length.toString() + `]: `);
|
|
111
|
+
let n = Stdlib_Int.fromString(answer, undefined);
|
|
112
|
+
if (n !== undefined) {
|
|
113
|
+
if (n >= 1 && n <= options.length) {
|
|
114
|
+
return options[n - 1 | 0][1];
|
|
115
|
+
} else {
|
|
116
|
+
console.log(" Not a valid choice.");
|
|
117
|
+
return await pick();
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
console.log(" Not a valid choice.");
|
|
121
|
+
return await pick();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return await pick();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function credentials(localDefaultsOpt) {
|
|
128
|
+
let localDefaults = localDefaultsOpt !== undefined ? localDefaultsOpt : false;
|
|
129
|
+
let u = envValue("REVENTLESS_DEMO_USER");
|
|
130
|
+
let username;
|
|
131
|
+
if (u !== undefined) {
|
|
132
|
+
username = u;
|
|
133
|
+
} else {
|
|
134
|
+
requireTty();
|
|
135
|
+
let entered = await ask(localDefaults ? "Username [admin]: " : "Username: ");
|
|
136
|
+
username = entered === "" && localDefaults ? "admin" : entered;
|
|
137
|
+
}
|
|
138
|
+
let p = envValue("REVENTLESS_DEMO_PASSWORD");
|
|
139
|
+
let password;
|
|
140
|
+
if (p !== undefined) {
|
|
141
|
+
password = p;
|
|
142
|
+
} else {
|
|
143
|
+
requireTty();
|
|
144
|
+
let entered$1 = await askHidden(localDefaults ? "Password [admin]: " : "Password: ");
|
|
145
|
+
password = entered$1 === "" && localDefaults ? "admin" : entered$1;
|
|
146
|
+
}
|
|
147
|
+
if (username === "" || password === "") {
|
|
148
|
+
throw {
|
|
149
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
150
|
+
_1: "username and password are required.",
|
|
151
|
+
Error: new Error()
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return [
|
|
155
|
+
username,
|
|
156
|
+
password
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export {
|
|
161
|
+
rlRef,
|
|
162
|
+
muted,
|
|
163
|
+
iface,
|
|
164
|
+
close,
|
|
165
|
+
envValue,
|
|
166
|
+
requireTty,
|
|
167
|
+
ask,
|
|
168
|
+
askHidden,
|
|
169
|
+
select,
|
|
170
|
+
credentials,
|
|
171
|
+
}
|
|
172
|
+
/* node:readline Not a pure module */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -95,7 +95,13 @@ let warn = (warnings: array<string>): unit =>
|
|
|
95
95
|
* plainly that the store is now half-seeded — recovery is a reset, not a re-run.
|
|
96
96
|
*/
|
|
97
97
|
let run = async (main: unit => promise<unit>): unit =>
|
|
98
|
-
try
|
|
98
|
+
try {
|
|
99
|
+
await main()
|
|
100
|
+
// Exit cleanly: HTTP keep-alive sockets (and, on the interactive path, the
|
|
101
|
+
// readline/stdin handle) can otherwise keep the event loop alive so the CLI
|
|
102
|
+
// appears to hang after a successful run.
|
|
103
|
+
exit(0)
|
|
104
|
+
} catch {
|
|
99
105
|
| Failed(message) =>
|
|
100
106
|
Console.error("")
|
|
101
107
|
Console.error("Seeding aborted — the store is now half-seeded; re-run against a")
|
|
@@ -112,3 +118,82 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
112
118
|
)
|
|
113
119
|
exit(1)
|
|
114
120
|
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A named, seedable data set. `seed` owns everything domain-specific — the
|
|
124
|
+
* phases, `verifyViews`, the summary board — so the generic runner never sees
|
|
125
|
+
* domain detail. `label` is what the selection menu shows.
|
|
126
|
+
*/
|
|
127
|
+
type dataSet = {
|
|
128
|
+
name: string,
|
|
129
|
+
label: string,
|
|
130
|
+
seed: Seed_Connect.connection => promise<unit>,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A failure before any command is sent — bad data-set selection, an
|
|
135
|
+
* unreachable/undeployed target, a login failure. Nothing was written, so this
|
|
136
|
+
* says so plainly rather than warning about a half-seeded store (which would
|
|
137
|
+
* send the user resetting a store the run never touched).
|
|
138
|
+
*/
|
|
139
|
+
let abortStartup = (message: string): unit => {
|
|
140
|
+
Seed_Prompt.close()
|
|
141
|
+
Console.error("")
|
|
142
|
+
Console.error("Seeding did not start — nothing was written. Fix the cause below and re-run.")
|
|
143
|
+
Console.error("")
|
|
144
|
+
Console.error(message)
|
|
145
|
+
exit(1)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Top-level seed entry: choose a data set (auto when there is one, `SEED_SET`
|
|
150
|
+
* or a menu otherwise), connect, then hand the connection to the chosen set.
|
|
151
|
+
* Prompts are closed before seeding so the shared readline never lingers.
|
|
152
|
+
*
|
|
153
|
+
* Selection and connect run before any command is sent, so a failure there is
|
|
154
|
+
* reported as "did not start"; only failures inside the data set's own `seed`
|
|
155
|
+
* carry the half-seeded warning (via `run`).
|
|
156
|
+
*/
|
|
157
|
+
let seed = (~sets: array<dataSet>, ~connect: unit => promise<Seed_Connect.connection>): unit => {
|
|
158
|
+
let go = async () => {
|
|
159
|
+
let started = try {
|
|
160
|
+
let chosen = switch sets {
|
|
161
|
+
| [only] => only
|
|
162
|
+
| _ =>
|
|
163
|
+
switch Seed_Prompt.envValue("SEED_SET") {
|
|
164
|
+
| Some(wanted) =>
|
|
165
|
+
switch sets->Array.find(s => s.name == wanted) {
|
|
166
|
+
| Some(s) => s
|
|
167
|
+
| None =>
|
|
168
|
+
throw(
|
|
169
|
+
Failed(
|
|
170
|
+
`SEED_SET="${wanted}" matches no data set (have: ${sets
|
|
171
|
+
->Array.map(s => s.name)
|
|
172
|
+
->Array.join(", ")})`,
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
| None =>
|
|
177
|
+
await Seed_Prompt.select(~title="Data set:", ~options=sets->Array.map(s => (s.label, s)))
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
let connection = await connect()
|
|
181
|
+
Seed_Prompt.close()
|
|
182
|
+
Some((chosen, connection))
|
|
183
|
+
} catch {
|
|
184
|
+
| Failed(message) =>
|
|
185
|
+
abortStartup(message)
|
|
186
|
+
None
|
|
187
|
+
| exn =>
|
|
188
|
+
abortStartup(exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown"))
|
|
189
|
+
None
|
|
190
|
+
}
|
|
191
|
+
switch started {
|
|
192
|
+
| None => () // unreachable: abortStartup has already exited
|
|
193
|
+
| Some((chosen, connection)) =>
|
|
194
|
+
heading(`Seeding "${chosen.label}" into ${connection.label}`)
|
|
195
|
+
await run(() => chosen.seed(connection))
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
go()->ignore
|
|
199
|
+
}
|
|
@@ -6,6 +6,7 @@ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
|
6
6
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
7
7
|
import * as Seed_Types$ReventlessSeed from "./Seed_Types.res.mjs";
|
|
8
8
|
import * as Seed_Client$ReventlessSeed from "./Seed_Client.res.mjs";
|
|
9
|
+
import * as Seed_Prompt$ReventlessSeed from "./Seed_Prompt.res.mjs";
|
|
9
10
|
|
|
10
11
|
function envOr(key, fallback) {
|
|
11
12
|
return Stdlib_Option.getOr(process.env[key], fallback);
|
|
@@ -84,7 +85,9 @@ function warn(warnings) {
|
|
|
84
85
|
|
|
85
86
|
async function run(main) {
|
|
86
87
|
try {
|
|
87
|
-
|
|
88
|
+
await main();
|
|
89
|
+
process.exit(0);
|
|
90
|
+
return;
|
|
88
91
|
} catch (raw_message) {
|
|
89
92
|
let message = Primitive_exceptions.internalToException(raw_message);
|
|
90
93
|
if (message.RE_EXN_ID === Seed_Types$ReventlessSeed.Failed) {
|
|
@@ -105,6 +108,69 @@ async function run(main) {
|
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
|
|
111
|
+
function abortStartup(message) {
|
|
112
|
+
Seed_Prompt$ReventlessSeed.close();
|
|
113
|
+
console.error("");
|
|
114
|
+
console.error("Seeding did not start — nothing was written. Fix the cause below and re-run.");
|
|
115
|
+
console.error("");
|
|
116
|
+
console.error(message);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function seed(sets, connect) {
|
|
121
|
+
let go = async () => {
|
|
122
|
+
let started;
|
|
123
|
+
try {
|
|
124
|
+
let chosen;
|
|
125
|
+
if (sets.length !== 1) {
|
|
126
|
+
let wanted = Seed_Prompt$ReventlessSeed.envValue("SEED_SET");
|
|
127
|
+
if (wanted !== undefined) {
|
|
128
|
+
let s = sets.find(s => s.name === wanted);
|
|
129
|
+
if (s !== undefined) {
|
|
130
|
+
chosen = s;
|
|
131
|
+
} else {
|
|
132
|
+
throw {
|
|
133
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
134
|
+
_1: `SEED_SET="` + wanted + `" matches no data set (have: ` + sets.map(s => s.name).join(", ") + `)`,
|
|
135
|
+
Error: new Error()
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
chosen = await Seed_Prompt$ReventlessSeed.select("Data set:", sets.map(s => [
|
|
140
|
+
s.label,
|
|
141
|
+
s
|
|
142
|
+
]), undefined);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
chosen = sets[0];
|
|
146
|
+
}
|
|
147
|
+
let connection = await connect();
|
|
148
|
+
Seed_Prompt$ReventlessSeed.close();
|
|
149
|
+
started = [
|
|
150
|
+
chosen,
|
|
151
|
+
connection
|
|
152
|
+
];
|
|
153
|
+
} catch (raw_message) {
|
|
154
|
+
let message = Primitive_exceptions.internalToException(raw_message);
|
|
155
|
+
if (message.RE_EXN_ID === Seed_Types$ReventlessSeed.Failed) {
|
|
156
|
+
abortStartup(message._1);
|
|
157
|
+
started = undefined;
|
|
158
|
+
} else {
|
|
159
|
+
abortStartup(Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(message), Stdlib_JsExn.message), "unknown"));
|
|
160
|
+
started = undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (started === undefined) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
let connection$1 = started[1];
|
|
167
|
+
let chosen$1 = started[0];
|
|
168
|
+
heading(`Seeding "` + chosen$1.label + `" into ` + connection$1.label);
|
|
169
|
+
return await run(() => chosen$1.seed(connection$1));
|
|
170
|
+
};
|
|
171
|
+
go();
|
|
172
|
+
}
|
|
173
|
+
|
|
108
174
|
export {
|
|
109
175
|
envOr,
|
|
110
176
|
report,
|
|
@@ -114,5 +180,7 @@ export {
|
|
|
114
180
|
unfillableWarnings,
|
|
115
181
|
warn,
|
|
116
182
|
run,
|
|
183
|
+
abortStartup,
|
|
184
|
+
seed,
|
|
117
185
|
}
|
|
118
186
|
/* Stdlib_JsExn Not a pure module */
|
|
Binary file
|
|
Binary file
|
package/lib/ocaml/.compiler.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#Start(
|
|
2
|
-
#Done(
|
|
1
|
+
#Start(1785092483117)
|
|
2
|
+
#Done(1785092488019)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/ocaml/Seed.ast
CHANGED
|
Binary file
|
package/lib/ocaml/Seed.res
CHANGED
|
@@ -9,9 +9,26 @@ 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, the upload
|
|
18
|
+
// endpoint (empty when the deployment serves no uploads), and a label.
|
|
19
|
+
type connection = Seed_Connect.connection = {
|
|
20
|
+
client: Seed_Client.t,
|
|
21
|
+
uploadEndpoint: string,
|
|
22
|
+
label: string,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A named, seedable data set. `seed` owns everything domain-specific.
|
|
26
|
+
type dataSet = Seed_Runner.dataSet = {
|
|
27
|
+
name: string,
|
|
28
|
+
label: string,
|
|
29
|
+
seed: connection => promise<unit>,
|
|
30
|
+
}
|
|
31
|
+
|
|
15
32
|
type rec value = Seed_Types.value =
|
|
16
33
|
| String(string)
|
|
17
34
|
| Id(string)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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,11 @@ 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
|
+
/** Injects a bearer obtained out-of-band (e.g. a Cognito id token), instead of
|
|
47
|
+
minting one via `login`. Provider-agnostic: the harness only cares that the
|
|
48
|
+
token is a valid bearer for `endpoint`. */
|
|
49
|
+
let useToken = (t: t, token: string): unit => t.token = Some(token)
|
|
50
|
+
|
|
43
51
|
// ── JSON helpers ────────────────────────────────────────────────────────────
|
|
44
52
|
|
|
45
53
|
let field = (json: JSON.t, key: string): option<JSON.t> =>
|
|
@@ -61,28 +69,31 @@ let nodeString = (node: JSON.t, key: string): option<string> =>
|
|
|
61
69
|
// ── Requests ────────────────────────────────────────────────────────────────
|
|
62
70
|
|
|
63
71
|
let login = async (t: t): unit => {
|
|
72
|
+
let loginEndpoint = switch t.config.loginEndpoint {
|
|
73
|
+
| Some(e) => e
|
|
74
|
+
| None => throw(Failed("login: no loginEndpoint configured — supply one or call useToken"))
|
|
75
|
+
}
|
|
76
|
+
let username = t.config.username->Option.getOr("")
|
|
77
|
+
let password = t.config.password->Option.getOr("")
|
|
64
78
|
let body = JSON.stringify(
|
|
65
79
|
JSON.Encode.object(
|
|
66
80
|
Dict.fromArray([
|
|
67
|
-
("username", JSON.Encode.string(
|
|
68
|
-
("password", JSON.Encode.string(
|
|
81
|
+
("username", JSON.Encode.string(username)),
|
|
82
|
+
("password", JSON.Encode.string(password)),
|
|
69
83
|
]),
|
|
70
84
|
),
|
|
71
85
|
)
|
|
72
86
|
let res = try await fetch(
|
|
73
|
-
|
|
87
|
+
loginEndpoint,
|
|
74
88
|
{method: "POST", headers: Dict.fromArray([("content-type", "application/json")]), body},
|
|
75
89
|
) catch {
|
|
76
|
-
| _ =>
|
|
77
|
-
throw(
|
|
78
|
-
Failed(`login: cannot reach ${t.config.loginEndpoint} — is the platform running?`),
|
|
79
|
-
)
|
|
90
|
+
| _ => throw(Failed(`login: cannot reach ${loginEndpoint} — is the platform running?`))
|
|
80
91
|
}
|
|
81
92
|
if !(res->responseOk) {
|
|
82
93
|
let detail = await res->responseText
|
|
83
94
|
throw(
|
|
84
95
|
Failed(
|
|
85
|
-
`login as "${
|
|
96
|
+
`login as "${username}" failed with HTTP ${(res->responseStatus)
|
|
86
97
|
->Int.toString}: ${detail}`,
|
|
87
98
|
),
|
|
88
99
|
)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,84 @@
|
|
|
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 upload endpoint (empty when the deployment serves no uploads), and
|
|
5
|
+
// 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
|
+
type connection = {client: Seed_Client.t, uploadEndpoint: string, label: string}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prompts for credentials, calls `login` to mint a bearer, and returns a
|
|
16
|
+
* connection with that bearer already applied. `login` returns the bearer so a
|
|
17
|
+
* single `useToken` path serves every provider.
|
|
18
|
+
*/
|
|
19
|
+
let make = async (
|
|
20
|
+
~label: string,
|
|
21
|
+
~endpoint: string,
|
|
22
|
+
~uploadEndpoint: string,
|
|
23
|
+
~login: (~username: string, ~password: string) => promise<string>,
|
|
24
|
+
~localDefaults: bool=false,
|
|
25
|
+
): connection => {
|
|
26
|
+
// `SEED_SKIP_UPLOADS` forces the connection to carry no upload endpoint, so a
|
|
27
|
+
// data set's upload phase no-ops the same way it does when a deployment serves
|
|
28
|
+
// none. Use it to seed domain data fast, or to skip a broken/absent upload path
|
|
29
|
+
// without editing the data set. It is the single knob: an empty
|
|
30
|
+
// `REVENTLESS_UPLOAD_ENDPOINT` env reads as "unset" (falls back to discovery),
|
|
31
|
+
// so this is the reliable way to disable uploads.
|
|
32
|
+
let uploadEndpoint = Seed_Prompt.envValue("SEED_SKIP_UPLOADS")->Option.isSome ? "" : uploadEndpoint
|
|
33
|
+
let (username, password) = await Seed_Prompt.credentials(~localDefaults)
|
|
34
|
+
let token = await login(~username, ~password)
|
|
35
|
+
let client = Seed_Client.make(~config={endpoint: endpoint})
|
|
36
|
+
client->Seed_Client.useToken(token)
|
|
37
|
+
{client, uploadEndpoint, label}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A login function backed by an HTTP login endpoint (the local dev
|
|
42
|
+
* `/__inmemory/login` shape: POST `{username, password}` → `{token}`). Reuses
|
|
43
|
+
* `Seed_Client.login` but hands the token back for `useToken`.
|
|
44
|
+
*/
|
|
45
|
+
let viaLoginEndpoint = (~loginEndpoint: string) => async (
|
|
46
|
+
~username: string,
|
|
47
|
+
~password: string,
|
|
48
|
+
): string => {
|
|
49
|
+
let client = Seed_Client.make(
|
|
50
|
+
~config={endpoint: loginEndpoint, loginEndpoint, username, password},
|
|
51
|
+
)
|
|
52
|
+
await Seed_Client.login(client)
|
|
53
|
+
switch Seed_Client.currentToken(client) {
|
|
54
|
+
| Some(token) => token
|
|
55
|
+
| None => throw(Failed(`login at ${loginEndpoint} returned no token`))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let envOr = (key: string, fallback: string): string =>
|
|
60
|
+
Seed_Prompt.envValue(key)->Option.getOr(fallback)
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A ready `connect` thunk for the local dev platform, with the localhost
|
|
64
|
+
* defaults baked in and overridable per endpoint (arg, then env var, then
|
|
65
|
+
* default). Empty input at the credential prompt falls back to `admin`/`admin`.
|
|
66
|
+
*/
|
|
67
|
+
let local = (~graphql=?, ~upload=?, ~login=?, ()): (unit => promise<connection>) => {
|
|
68
|
+
let endpoint =
|
|
69
|
+
graphql->Option.getOr(envOr("REVENTLESS_GRAPHQL_ENDPOINT", "http://localhost:4000/graphql"))
|
|
70
|
+
let uploadEndpoint =
|
|
71
|
+
upload->Option.getOr(
|
|
72
|
+
envOr("REVENTLESS_UPLOAD_ENDPOINT", "http://localhost:4000/__inmemory/upload"),
|
|
73
|
+
)
|
|
74
|
+
let loginEndpoint =
|
|
75
|
+
login->Option.getOr(envOr("REVENTLESS_LOGIN_ENDPOINT", "http://localhost:4000/__inmemory/login"))
|
|
76
|
+
() =>
|
|
77
|
+
make(
|
|
78
|
+
~label="local",
|
|
79
|
+
~endpoint,
|
|
80
|
+
~uploadEndpoint,
|
|
81
|
+
~login=viaLoginEndpoint(~loginEndpoint),
|
|
82
|
+
~localDefaults=true,
|
|
83
|
+
)
|
|
84
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|