plantr 1.0.1 → 2.1.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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +23 -20
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +906 -235
- package/dist/src/cli.d.ts +23 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/create-seeder-instance.d.ts +73 -83
- package/dist/src/create-seeder-instance.d.ts.map +1 -0
- package/dist/src/define-seeder.d.ts +4 -3
- package/dist/src/define-seeder.d.ts.map +1 -0
- package/dist/src/dependency-resolver.d.ts +18 -2
- package/dist/src/dependency-resolver.d.ts.map +1 -0
- package/dist/src/formatting.d.ts +31 -12
- package/dist/src/formatting.d.ts.map +1 -0
- package/dist/src/lazy-faker.d.ts +12 -0
- package/dist/src/lazy-faker.d.ts.map +1 -0
- package/dist/src/run-seeders.d.ts +57 -17
- package/dist/src/run-seeders.d.ts.map +1 -0
- package/dist/src/seeding-state.d.ts +17 -2
- package/dist/src/seeding-state.d.ts.map +1 -0
- package/dist/src/step.d.ts +97 -15
- package/dist/src/step.d.ts.map +1 -0
- package/dist/src/types.d.ts +132 -29
- package/dist/src/types.d.ts.map +1 -0
- package/dist/state.d.ts +12 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +20 -0
- package/index.ts +60 -24
- package/package.json +20 -10
- package/readme.md +169 -49
- package/src/cli.ts +251 -0
- package/src/create-seeder-instance.ts +254 -173
- package/src/define-seeder.ts +14 -7
- package/src/dependency-resolver.ts +59 -30
- package/src/formatting.ts +142 -39
- package/src/lazy-faker.ts +46 -0
- package/src/run-seeders.ts +413 -123
- package/src/seeding-state.ts +32 -5
- package/src/step.ts +247 -46
- package/src/types.ts +184 -32
- package/state.ts +11 -0
- package/dist/cli.d.ts +0 -17
- package/dist/cli.js +0 -59
- package/dist/index-a1s5r901.js +0 -4
package/dist/index.js
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
import { expect as expect2 } from "bun:test";
|
|
3
|
-
import { faker as faker2 } from "@faker-js/faker";
|
|
4
3
|
|
|
5
4
|
// src/create-seeder-instance.ts
|
|
6
5
|
import { expect } from "bun:test";
|
|
7
|
-
import {
|
|
6
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
8
7
|
|
|
9
|
-
// src/
|
|
10
|
-
|
|
11
|
-
return function defineSeeder(config) {
|
|
12
|
-
const dependsOnNames = (config.dependsOn ?? []).map((seeder) => seeder.name);
|
|
13
|
-
return {
|
|
14
|
-
name: config.name,
|
|
15
|
-
description: config.description,
|
|
16
|
-
dependsOn: dependsOnNames,
|
|
17
|
-
run: config.run
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
}
|
|
8
|
+
// src/cli.ts
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
21
10
|
|
|
22
11
|
// src/dependency-resolver.ts
|
|
23
12
|
class CircularDependencyError extends Error {
|
|
24
13
|
constructor(cycle) {
|
|
25
|
-
super(`Circular dependency detected in seeders: ${cycle.join(" -> ")} -> ${cycle[0]}`);
|
|
14
|
+
super(`Circular dependency detected in seeders: ${cycle.join(" -> ")} -> ${cycle[0] ?? ""}`);
|
|
26
15
|
this.name = "CircularDependencyError";
|
|
27
16
|
}
|
|
28
17
|
}
|
|
@@ -33,18 +22,27 @@ class MissingDependencyError extends Error {
|
|
|
33
22
|
this.name = "MissingDependencyError";
|
|
34
23
|
}
|
|
35
24
|
}
|
|
36
|
-
|
|
25
|
+
|
|
26
|
+
class DuplicateSeederError extends Error {
|
|
27
|
+
constructor(name) {
|
|
28
|
+
super(`Two seeders are named "${name}"; seeder names must be unique`);
|
|
29
|
+
this.name = "DuplicateSeederError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class UnknownSeederError extends Error {
|
|
34
|
+
constructor(name, known) {
|
|
35
|
+
super(`Unknown seeder "${name}". Registered seeders: ${known.join(", ") || "(none)"}`);
|
|
36
|
+
this.name = "UnknownSeederError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function resolveDependencyOrder(seeders, only) {
|
|
37
40
|
const seederMap = new Map;
|
|
38
41
|
for (const seeder of seeders) {
|
|
42
|
+
if (seederMap.has(seeder.name))
|
|
43
|
+
throw new DuplicateSeederError(seeder.name);
|
|
39
44
|
seederMap.set(seeder.name, seeder);
|
|
40
45
|
}
|
|
41
|
-
for (const seeder of seeders) {
|
|
42
|
-
for (const dep of seeder.dependsOn) {
|
|
43
|
-
if (!seederMap.has(dep)) {
|
|
44
|
-
throw new MissingDependencyError(seeder.name, dep);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
46
|
const inDegree = new Map;
|
|
49
47
|
const dependents = new Map;
|
|
50
48
|
for (const seeder of seeders) {
|
|
@@ -52,12 +50,14 @@ function resolveDependencyOrder(seeders) {
|
|
|
52
50
|
dependents.set(seeder.name, []);
|
|
53
51
|
}
|
|
54
52
|
for (const seeder of seeders) {
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const uniqueDeps = new Set(seeder.dependsOn);
|
|
54
|
+
inDegree.set(seeder.name, uniqueDeps.size);
|
|
55
|
+
for (const dep of uniqueDeps) {
|
|
57
56
|
const deps = dependents.get(dep);
|
|
58
|
-
if (deps) {
|
|
59
|
-
|
|
57
|
+
if (!deps) {
|
|
58
|
+
throw new MissingDependencyError(seeder.name, dep);
|
|
60
59
|
}
|
|
60
|
+
deps.push(seeder.name);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
const queue = [];
|
|
@@ -67,10 +67,13 @@ function resolveDependencyOrder(seeders) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
const result = [];
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
let head = 0;
|
|
71
|
+
while (head < queue.length) {
|
|
72
|
+
const current = queue[head++];
|
|
72
73
|
result.push(current);
|
|
73
|
-
const deps = dependents.get(current)
|
|
74
|
+
const deps = dependents.get(current);
|
|
75
|
+
if (!deps)
|
|
76
|
+
continue;
|
|
74
77
|
for (const dependent of deps) {
|
|
75
78
|
const newDegree = (inDegree.get(dependent) ?? 0) - 1;
|
|
76
79
|
inDegree.set(dependent, newDegree);
|
|
@@ -80,11 +83,27 @@ function resolveDependencyOrder(seeders) {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
if (result.length !== seeders.length) {
|
|
83
|
-
const
|
|
86
|
+
const resolved = new Set(result);
|
|
87
|
+
const remaining = seeders.filter((s) => !resolved.has(s.name));
|
|
84
88
|
const cycle = findCycle(remaining, seederMap);
|
|
85
89
|
throw new CircularDependencyError(cycle);
|
|
86
90
|
}
|
|
87
|
-
|
|
91
|
+
if (!only)
|
|
92
|
+
return result;
|
|
93
|
+
const selected = new Set;
|
|
94
|
+
const visit = (name) => {
|
|
95
|
+
if (selected.has(name))
|
|
96
|
+
return;
|
|
97
|
+
selected.add(name);
|
|
98
|
+
for (const dep of seederMap.get(name)?.dependsOn ?? [])
|
|
99
|
+
visit(dep);
|
|
100
|
+
};
|
|
101
|
+
for (const name of only) {
|
|
102
|
+
if (!seederMap.has(name))
|
|
103
|
+
throw new UnknownSeederError(name, [...seederMap.keys()]);
|
|
104
|
+
visit(name);
|
|
105
|
+
}
|
|
106
|
+
return result.filter((name) => selected.has(name));
|
|
88
107
|
}
|
|
89
108
|
function findCycle(remaining, seederMap) {
|
|
90
109
|
const visited = new Set;
|
|
@@ -134,7 +153,16 @@ var colors = {
|
|
|
134
153
|
white: "\x1B[37m",
|
|
135
154
|
gray: "\x1B[90m"
|
|
136
155
|
};
|
|
156
|
+
function supportsColor() {
|
|
157
|
+
if (process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== "")
|
|
158
|
+
return false;
|
|
159
|
+
if (process.env.FORCE_COLOR !== undefined && process.env.FORCE_COLOR !== "0")
|
|
160
|
+
return true;
|
|
161
|
+
return Boolean(process.stdout.isTTY);
|
|
162
|
+
}
|
|
137
163
|
function colorize(text, color, style) {
|
|
164
|
+
if (!supportsColor())
|
|
165
|
+
return text;
|
|
138
166
|
let result = "";
|
|
139
167
|
if (style === "bold")
|
|
140
168
|
result += colors.bold;
|
|
@@ -145,7 +173,7 @@ function colorize(text, color, style) {
|
|
|
145
173
|
}
|
|
146
174
|
function formatDuration(ms) {
|
|
147
175
|
if (ms < 1000)
|
|
148
|
-
return `${ms}ms`;
|
|
176
|
+
return `${Math.round(ms)}ms`;
|
|
149
177
|
if (ms < 60000)
|
|
150
178
|
return `${(ms / 1000).toFixed(1)}s`;
|
|
151
179
|
return `${(ms / 60000).toFixed(1)}m`;
|
|
@@ -160,7 +188,12 @@ function printResultsTable(results) {
|
|
|
160
188
|
const durationHeader = "Duration";
|
|
161
189
|
const maxNameLen = Math.max(nameHeader.length, ...results.map((r) => r.name.length));
|
|
162
190
|
const maxStatusLen = Math.max(statusHeader.length, 10);
|
|
163
|
-
const maxDurationLen = Math.max(durationHeader.length, ...results.map((r) =>
|
|
191
|
+
const maxDurationLen = Math.max(durationHeader.length, ...results.map((r) => {
|
|
192
|
+
if (r.status === "completed" || r.status === "failed") {
|
|
193
|
+
return formatDuration(r.durationMs).length;
|
|
194
|
+
}
|
|
195
|
+
return 1;
|
|
196
|
+
}));
|
|
164
197
|
const topBorder = `┌${"─".repeat(maxNameLen + 2)}┬${"─".repeat(maxStatusLen + 2)}┬${"─".repeat(maxDurationLen + 2)}┐`;
|
|
165
198
|
const divider = `├${"─".repeat(maxNameLen + 2)}┼${"─".repeat(maxStatusLen + 2)}┼${"─".repeat(maxDurationLen + 2)}┤`;
|
|
166
199
|
const bottomBorder = `└${"─".repeat(maxNameLen + 2)}┴${"─".repeat(maxStatusLen + 2)}┴${"─".repeat(maxDurationLen + 2)}┘`;
|
|
@@ -171,46 +204,48 @@ function printResultsTable(results) {
|
|
|
171
204
|
for (const result of results) {
|
|
172
205
|
let statusDisplay;
|
|
173
206
|
let statusColor;
|
|
207
|
+
let duration = "-";
|
|
174
208
|
switch (result.status) {
|
|
175
209
|
case "completed":
|
|
176
210
|
statusDisplay = "✓ Done";
|
|
177
211
|
statusColor = "green";
|
|
212
|
+
duration = formatDuration(result.durationMs);
|
|
178
213
|
break;
|
|
179
214
|
case "failed":
|
|
180
215
|
statusDisplay = "✗ Failed";
|
|
181
216
|
statusColor = "red";
|
|
217
|
+
duration = formatDuration(result.durationMs);
|
|
182
218
|
break;
|
|
183
219
|
case "skipped":
|
|
184
220
|
statusDisplay = "⊘ Skipped";
|
|
185
221
|
statusColor = "yellow";
|
|
186
222
|
break;
|
|
187
|
-
case "
|
|
188
|
-
statusDisplay = "⟳ Running";
|
|
189
|
-
statusColor = "yellow";
|
|
190
|
-
break;
|
|
191
|
-
default:
|
|
223
|
+
case "pending":
|
|
192
224
|
statusDisplay = "○ Pending";
|
|
193
225
|
statusColor = "gray";
|
|
226
|
+
break;
|
|
194
227
|
}
|
|
195
|
-
const duration = result.durationMs !== undefined ? formatDuration(result.durationMs) : "-";
|
|
196
228
|
console.log(`│ ${result.name.padEnd(maxNameLen)} │ ${colorize(statusDisplay.padEnd(maxStatusLen), statusColor)} │ ${colorize(duration.padEnd(maxDurationLen), "dim")} │`);
|
|
197
229
|
}
|
|
198
230
|
console.log(bottomBorder);
|
|
199
231
|
console.log("");
|
|
200
232
|
}
|
|
233
|
+
var escapeAnnotation = (text) => text.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
201
234
|
function printErrors(results) {
|
|
202
235
|
const failed = results.filter((r) => r.status === "failed");
|
|
203
236
|
for (const result of failed) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
237
|
+
const where = result.failedStep ? ` in step "${result.failedStep}"` : "";
|
|
238
|
+
console.log(colorize(`❌ Seeder "${result.name}" failed${where}:`, "red"));
|
|
239
|
+
const details = Bun.inspect(result.error, { colors: supportsColor() });
|
|
240
|
+
for (const line of details.split(`
|
|
241
|
+
`))
|
|
242
|
+
console.log(` ${line}`);
|
|
243
|
+
if (result.cachedSteps.length > 0) {
|
|
244
|
+
console.log(colorize(` ${result.cachedSteps.length} earlier step(s) came from the cache: ${result.cachedSteps.join(", ")}. If they are stale, run this seeder fresh (CLI: --only ${result.name} --fresh).`, "yellow"));
|
|
245
|
+
}
|
|
246
|
+
if (process.env.GITHUB_ACTIONS === "true") {
|
|
247
|
+
const title = `Seeder ${result.name} failed${where}`.replace(/[:,]/g, " ");
|
|
248
|
+
console.log(`::error title=${escapeAnnotation(title)}::${escapeAnnotation(result.error.message || "failed")}`);
|
|
214
249
|
}
|
|
215
250
|
console.log("");
|
|
216
251
|
}
|
|
@@ -233,10 +268,25 @@ function printSeederComplete(durationMs, success) {
|
|
|
233
268
|
}
|
|
234
269
|
console.log("");
|
|
235
270
|
}
|
|
236
|
-
function
|
|
237
|
-
const
|
|
271
|
+
function printConcurrentComplete(seederName, durationMs, success) {
|
|
272
|
+
const tag = colorize(`[${seederName}]`, "cyan", "bold");
|
|
273
|
+
if (success) {
|
|
274
|
+
console.log(` ${tag} ${colorize(`✓ Completed in ${formatDuration(durationMs)}`, "green")}`);
|
|
275
|
+
} else {
|
|
276
|
+
console.log(` ${tag} ${colorize(`✗ Failed after ${formatDuration(durationMs)}`, "red")}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function printConcurrentSkipped(seederName, failedDeps) {
|
|
280
|
+
const tag = colorize(`[${seederName}]`, "cyan", "bold");
|
|
281
|
+
console.log(` ${tag} ${colorize(`⊘ Skipped (depends on failed: ${failedDeps.join(", ")})`, "yellow")}`);
|
|
282
|
+
}
|
|
283
|
+
function printStartBanner(options) {
|
|
284
|
+
const name = options?.name ?? "Seeders";
|
|
285
|
+
const countText = options?.count !== undefined ? ` ${colorize(`(${options.count} ${options.count === 1 ? "seeder" : "seeders"}${options.concurrency && options.concurrency > 1 ? `, concurrency: ${options.concurrency === Number.POSITIVE_INFINITY ? "∞" : options.concurrency}` : ""})`, "dim")}` : "";
|
|
286
|
+
const target = options?.target;
|
|
287
|
+
const targetText = target ? ` ${colorize(`→ ${target.label}`, "dim")}${target.local ? "" : ` ${colorize("(remote, allowed)", "yellow")}`}` : "";
|
|
238
288
|
console.log(`
|
|
239
|
-
${colorize(
|
|
289
|
+
${colorize(`\uD83C\uDF31 Running ${name}`, "cyan", "bold")}${countText}${targetText}
|
|
240
290
|
`);
|
|
241
291
|
}
|
|
242
292
|
function printSeederSkipped(failedDeps) {
|
|
@@ -244,11 +294,36 @@ function printSeederSkipped(failedDeps) {
|
|
|
244
294
|
console.log(colorize(` ⊘ Skipped (depends on failed: ${failedDeps.join(", ")})`, "yellow"));
|
|
245
295
|
console.log("");
|
|
246
296
|
}
|
|
247
|
-
function printSummary(results) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
297
|
+
function printSummary(results, totalDurationMs, concurrency = 1) {
|
|
298
|
+
let completed = 0;
|
|
299
|
+
let failed = 0;
|
|
300
|
+
let skipped = 0;
|
|
301
|
+
let pending = 0;
|
|
302
|
+
let cachedCount = 0;
|
|
303
|
+
let totalWorkMs = 0;
|
|
304
|
+
for (const r of results) {
|
|
305
|
+
switch (r.status) {
|
|
306
|
+
case "completed":
|
|
307
|
+
completed++;
|
|
308
|
+
cachedCount += r.cachedSteps.length;
|
|
309
|
+
totalWorkMs += r.durationMs;
|
|
310
|
+
break;
|
|
311
|
+
case "failed":
|
|
312
|
+
failed++;
|
|
313
|
+
cachedCount += r.cachedSteps.length;
|
|
314
|
+
totalWorkMs += r.durationMs;
|
|
315
|
+
break;
|
|
316
|
+
case "skipped":
|
|
317
|
+
skipped++;
|
|
318
|
+
break;
|
|
319
|
+
case "pending":
|
|
320
|
+
pending++;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const durationSuffix = totalDurationMs !== undefined ? ` in ${formatDuration(totalDurationMs)}` : "";
|
|
325
|
+
const speedupSuffix = concurrency > 1 && totalDurationMs !== undefined && totalDurationMs > 0 && totalWorkMs > totalDurationMs * 1.1 ? ` ${colorize(`(${formatDuration(totalWorkMs)} work, ${(totalWorkMs / totalDurationMs).toFixed(1)}× faster)`, "dim")}` : "";
|
|
326
|
+
const cacheSuffix = cachedCount > 0 ? ` ${colorize(`(${cachedCount} cached ${cachedCount === 1 ? "step" : "steps"})`, "cyan")}` : "";
|
|
252
327
|
if (failed > 0 || skipped > 0) {
|
|
253
328
|
const parts = [`${completed} completed`];
|
|
254
329
|
if (failed > 0)
|
|
@@ -257,242 +332,826 @@ function printSummary(results) {
|
|
|
257
332
|
parts.push(`${skipped} skipped`);
|
|
258
333
|
if (pending > 0)
|
|
259
334
|
parts.push(`${pending} pending`);
|
|
260
|
-
console.log(colorize(`Seeding failed: ${parts.join(", ")}`, "red"));
|
|
335
|
+
console.log(colorize(`Seeding failed: ${parts.join(", ")}${durationSuffix}`, "red"));
|
|
261
336
|
} else {
|
|
262
|
-
console.log(`${colorize("✓ Seeding complete:", "green")} ${completed} seeders executed successfully
|
|
337
|
+
console.log(`${colorize("✓ Seeding complete:", "green")} ${completed} ${completed === 1 ? "seeder" : "seeders"} executed successfully${durationSuffix}${speedupSuffix}${cacheSuffix}
|
|
263
338
|
`);
|
|
264
339
|
}
|
|
265
340
|
}
|
|
266
341
|
|
|
342
|
+
// src/seeding-state.ts
|
|
343
|
+
var key = Symbol.for("plantr.seedingActive");
|
|
344
|
+
var countKey = Symbol.for("plantr.seedingCount");
|
|
345
|
+
var state = globalThis;
|
|
346
|
+
function isSeedingActive() {
|
|
347
|
+
return state[key] === true;
|
|
348
|
+
}
|
|
349
|
+
function enterSeeding() {
|
|
350
|
+
const next = (state[countKey] ?? 0) + 1;
|
|
351
|
+
state[countKey] = next;
|
|
352
|
+
state[key] = true;
|
|
353
|
+
}
|
|
354
|
+
function exitSeeding() {
|
|
355
|
+
const next = Math.max(0, (state[countKey] ?? 0) - 1);
|
|
356
|
+
state[countKey] = next;
|
|
357
|
+
state[key] = next > 0;
|
|
358
|
+
}
|
|
359
|
+
|
|
267
360
|
// src/run-seeders.ts
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
if (verbose) {
|
|
274
|
-
printStartBanner();
|
|
361
|
+
class SeedTargetError extends Error {
|
|
362
|
+
constructor(label) {
|
|
363
|
+
super(`Refusing to seed ${label}: it is not a local database. Pass allowRemote (CLI: --allow-remote) to seed it on purpose.`);
|
|
364
|
+
this.name = "SeedTargetError";
|
|
275
365
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
366
|
+
}
|
|
367
|
+
var isLocalHost = (hostPort) => {
|
|
368
|
+
if (hostPort.startsWith("/"))
|
|
369
|
+
return true;
|
|
370
|
+
const lower = hostPort.toLowerCase();
|
|
371
|
+
const bracketed = /^\[([^\]]*)\]/.exec(lower);
|
|
372
|
+
const host = bracketed ? bracketed[1] ?? "" : lower.replace(/:\d+$/, "");
|
|
373
|
+
return host === "::1" || host === "0.0.0.0" || host === "host.docker.internal" || host.endsWith(".localhost") || /^127\./.test(host) || !/[.:]/.test(host);
|
|
374
|
+
};
|
|
375
|
+
function describeTarget(target) {
|
|
376
|
+
if (/^file:/i.test(target))
|
|
377
|
+
return { label: target.replace(/[?#].*$/, ""), local: true };
|
|
378
|
+
const scheme = /^[a-z][\w+.-]*:\/\//i.exec(target);
|
|
379
|
+
if (!scheme)
|
|
380
|
+
return { label: "a target that is not a URL", local: false };
|
|
381
|
+
const rest = target.slice(scheme[0].length);
|
|
382
|
+
const queryStart = rest.search(/[?#]/);
|
|
383
|
+
const beforeQuery = queryStart === -1 ? rest : rest.slice(0, queryStart);
|
|
384
|
+
const query = queryStart === -1 ? "" : rest.slice(queryStart);
|
|
385
|
+
const authorityAndPath = beforeQuery.slice(beforeQuery.lastIndexOf("@") + 1);
|
|
386
|
+
const [authority = "", path = ""] = authorityAndPath.split(/(?=[/;])/, 2);
|
|
387
|
+
let hosts = authority.split(",").filter(Boolean);
|
|
388
|
+
const hostParam = /[?&;]host=([^&;#]*)/i.exec(`${query}${path.startsWith(";") ? path : ""}`)?.[1];
|
|
389
|
+
if (hostParam) {
|
|
390
|
+
try {
|
|
391
|
+
hosts = decodeURIComponent(hostParam).split(",").filter(Boolean);
|
|
392
|
+
} catch {
|
|
393
|
+
return { label: "a target with an invalid host parameter", local: false };
|
|
284
394
|
}
|
|
285
|
-
return { results: [], success: false };
|
|
286
395
|
}
|
|
396
|
+
const label = `${hosts.join(",") || "local socket"}${path.startsWith("/") ? path : ""}`;
|
|
397
|
+
return { label, local: hosts.every(isLocalHost) };
|
|
398
|
+
}
|
|
399
|
+
async function runSeedersCore(seeders, config, options = {}) {
|
|
400
|
+
const {
|
|
401
|
+
printResults = true,
|
|
402
|
+
verbose = true,
|
|
403
|
+
continueOnFailure = false,
|
|
404
|
+
only,
|
|
405
|
+
fresh = false,
|
|
406
|
+
allowRemote = false,
|
|
407
|
+
concurrency = 1
|
|
408
|
+
} = options;
|
|
409
|
+
if (Number.isNaN(concurrency) || concurrency < 1 || Number.isFinite(concurrency) && !Number.isInteger(concurrency)) {
|
|
410
|
+
throw new RangeError(`Invalid concurrency (${String(concurrency)}): expected a positive integer or Infinity`);
|
|
411
|
+
}
|
|
412
|
+
const orderedNames = resolveDependencyOrder(seeders, only);
|
|
287
413
|
const seederMap = new Map;
|
|
288
414
|
for (const seeder of seeders) {
|
|
289
415
|
seederMap.set(seeder.name, seeder);
|
|
290
416
|
}
|
|
417
|
+
const freshSet = Array.isArray(fresh) ? new Set(fresh) : undefined;
|
|
418
|
+
if (freshSet) {
|
|
419
|
+
for (const name of freshSet) {
|
|
420
|
+
if (!seederMap.has(name))
|
|
421
|
+
throw new UnknownSeederError(name, [...seederMap.keys()]);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const targetUrl = config.target?.();
|
|
425
|
+
const target = targetUrl ? describeTarget(targetUrl) : undefined;
|
|
426
|
+
if (target && !target.local && !allowRemote) {
|
|
427
|
+
throw new SeedTargetError(target.label);
|
|
428
|
+
}
|
|
429
|
+
const isFresh = (name) => fresh === true || (freshSet?.has(name) ?? false);
|
|
291
430
|
const results = orderedNames.map((name) => ({
|
|
292
431
|
name,
|
|
293
432
|
status: "pending"
|
|
294
433
|
}));
|
|
434
|
+
const resultIndex = new Map;
|
|
435
|
+
for (let i = 0;i < orderedNames.length; i++) {
|
|
436
|
+
resultIndex.set(orderedNames[i], i);
|
|
437
|
+
}
|
|
295
438
|
const outputs = {};
|
|
296
439
|
const failedSeeders = new Set;
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const result = results[i];
|
|
301
|
-
if (!name || !result)
|
|
302
|
-
continue;
|
|
303
|
-
const seeder = seederMap.get(name);
|
|
304
|
-
if (!seeder)
|
|
305
|
-
continue;
|
|
306
|
-
if (continueOnFailure) {
|
|
307
|
-
const hasFailedDep = seeder.dependsOn.some((dep) => failedSeeders.has(dep));
|
|
308
|
-
if (hasFailedDep) {
|
|
309
|
-
result.status = "skipped";
|
|
310
|
-
failedSeeders.add(name);
|
|
311
|
-
if (verbose) {
|
|
312
|
-
printSeederHeader(name, i, orderedNames.length, seeder.description);
|
|
313
|
-
printSeederSkipped(seeder.dependsOn.filter((d) => failedSeeders.has(d)));
|
|
314
|
-
}
|
|
315
|
-
continue;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
440
|
+
const concurrent = concurrency > 1;
|
|
441
|
+
enterSeeding();
|
|
442
|
+
try {
|
|
318
443
|
if (verbose) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
444
|
+
printStartBanner({
|
|
445
|
+
name: config.bannerName,
|
|
446
|
+
count: orderedNames.length,
|
|
447
|
+
target,
|
|
448
|
+
concurrency
|
|
449
|
+
});
|
|
324
450
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
451
|
+
const runStartTime = performance.now();
|
|
452
|
+
if (config.onBeforeAll) {
|
|
453
|
+
await config.onBeforeAll();
|
|
328
454
|
}
|
|
329
|
-
|
|
455
|
+
let ctx;
|
|
330
456
|
try {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
result.status = "completed";
|
|
334
|
-
result.durationMs = Date.now() - startTime;
|
|
335
|
-
result.output = output;
|
|
336
|
-
if (verbose) {
|
|
337
|
-
printSeederComplete(result.durationMs, true);
|
|
457
|
+
if (config.preloadCache) {
|
|
458
|
+
await config.preloadCache();
|
|
338
459
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
460
|
+
ctx = await config.context();
|
|
461
|
+
const activeCtx = ctx;
|
|
462
|
+
const executeSeeder = async (name) => {
|
|
463
|
+
const idx = resultIndex.get(name);
|
|
464
|
+
const seeder = seederMap.get(name);
|
|
465
|
+
if (idx === undefined || !seeder)
|
|
466
|
+
return true;
|
|
467
|
+
const scopeHandle = config.createSeederScope ? config.createSeederScope({ name, fresh: isFresh(name), concurrent }) : {
|
|
468
|
+
record: config.beforeSeeder?.(name, { fresh: isFresh(name) }),
|
|
469
|
+
run: (fn) => fn()
|
|
470
|
+
};
|
|
471
|
+
const deps = {};
|
|
472
|
+
for (const depName of seeder.dependsOn) {
|
|
473
|
+
deps[depName] = outputs[depName];
|
|
474
|
+
}
|
|
475
|
+
const startTime = performance.now();
|
|
476
|
+
try {
|
|
477
|
+
const output = await scopeHandle.run(async () => seeder.run(activeCtx, deps));
|
|
478
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
479
|
+
outputs[name] = output;
|
|
480
|
+
results[idx] = {
|
|
481
|
+
name,
|
|
482
|
+
status: "completed",
|
|
483
|
+
durationMs,
|
|
484
|
+
output,
|
|
485
|
+
cachedSteps: scopeHandle.record?.cachedSteps ?? []
|
|
486
|
+
};
|
|
487
|
+
if (verbose) {
|
|
488
|
+
if (concurrent) {
|
|
489
|
+
printConcurrentComplete(name, durationMs, true);
|
|
490
|
+
} else {
|
|
491
|
+
printSeederComplete(durationMs, true);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return true;
|
|
495
|
+
} catch (error) {
|
|
496
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
497
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
498
|
+
const failedStep = scopeHandle.record?.failed && scopeHandle.record.failed.error === error ? scopeHandle.record.failed.step : undefined;
|
|
499
|
+
results[idx] = {
|
|
500
|
+
name,
|
|
501
|
+
status: "failed",
|
|
502
|
+
durationMs,
|
|
503
|
+
error: err,
|
|
504
|
+
...failedStep !== undefined ? { failedStep } : {},
|
|
505
|
+
cachedSteps: scopeHandle.record?.cachedSteps ?? []
|
|
506
|
+
};
|
|
507
|
+
failedSeeders.add(name);
|
|
508
|
+
if (verbose) {
|
|
509
|
+
if (concurrent) {
|
|
510
|
+
printConcurrentComplete(name, durationMs, false);
|
|
511
|
+
} else {
|
|
512
|
+
printSeederComplete(durationMs, false);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
if (!concurrent) {
|
|
519
|
+
for (let i = 0;i < orderedNames.length; i++) {
|
|
520
|
+
const name = orderedNames[i];
|
|
521
|
+
if (!name)
|
|
522
|
+
continue;
|
|
523
|
+
const seeder = seederMap.get(name);
|
|
524
|
+
if (!seeder)
|
|
525
|
+
continue;
|
|
526
|
+
if (continueOnFailure) {
|
|
527
|
+
const failedDeps = seeder.dependsOn.filter((dep) => failedSeeders.has(dep));
|
|
528
|
+
if (failedDeps.length > 0) {
|
|
529
|
+
results[i] = { name, status: "skipped", failedDeps };
|
|
530
|
+
failedSeeders.add(name);
|
|
531
|
+
if (verbose) {
|
|
532
|
+
printSeederHeader(name, i, orderedNames.length, seeder.description);
|
|
533
|
+
printSeederSkipped(failedDeps);
|
|
534
|
+
}
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (verbose) {
|
|
539
|
+
printSeederHeader(name, i, orderedNames.length, seeder.description);
|
|
540
|
+
}
|
|
541
|
+
const ok = await executeSeeder(name);
|
|
542
|
+
if (!ok && !continueOnFailure) {
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
} else if (orderedNames.length > 0) {
|
|
547
|
+
const remainingDeps = new Map;
|
|
548
|
+
const dependents = new Map;
|
|
549
|
+
for (const name of orderedNames) {
|
|
550
|
+
remainingDeps.set(name, 0);
|
|
551
|
+
dependents.set(name, []);
|
|
552
|
+
}
|
|
553
|
+
for (const name of orderedNames) {
|
|
554
|
+
const seeder = seederMap.get(name);
|
|
555
|
+
if (!seeder)
|
|
556
|
+
continue;
|
|
557
|
+
const uniqueDeps = new Set(seeder.dependsOn);
|
|
558
|
+
remainingDeps.set(name, uniqueDeps.size);
|
|
559
|
+
for (const dep of uniqueDeps) {
|
|
560
|
+
dependents.get(dep)?.push(name);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
const criticalHeight = new Map;
|
|
564
|
+
for (let i = orderedNames.length - 1;i >= 0; i--) {
|
|
565
|
+
const name = orderedNames[i];
|
|
566
|
+
let maxHeight = 0;
|
|
567
|
+
for (const dependent of dependents.get(name) ?? []) {
|
|
568
|
+
const h = (criticalHeight.get(dependent) ?? 0) + 1;
|
|
569
|
+
if (h > maxHeight)
|
|
570
|
+
maxHeight = h;
|
|
571
|
+
}
|
|
572
|
+
criticalHeight.set(name, maxHeight);
|
|
573
|
+
}
|
|
574
|
+
const ready = [];
|
|
575
|
+
for (const name of orderedNames) {
|
|
576
|
+
if (remainingDeps.get(name) === 0) {
|
|
577
|
+
ready.push(name);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
const popHighestPriority = () => {
|
|
581
|
+
let bestIdx = 0;
|
|
582
|
+
let bestHeight = criticalHeight.get(ready[0]) ?? 0;
|
|
583
|
+
let bestOrder = resultIndex.get(ready[0]) ?? 0;
|
|
584
|
+
for (let i = 1;i < ready.length; i++) {
|
|
585
|
+
const candidate = ready[i];
|
|
586
|
+
const h = criticalHeight.get(candidate) ?? 0;
|
|
587
|
+
const order = resultIndex.get(candidate) ?? 0;
|
|
588
|
+
if (h > bestHeight || h === bestHeight && order < bestOrder) {
|
|
589
|
+
bestIdx = i;
|
|
590
|
+
bestHeight = h;
|
|
591
|
+
bestOrder = order;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return ready.splice(bestIdx, 1)[0];
|
|
595
|
+
};
|
|
596
|
+
await new Promise((resolve) => {
|
|
597
|
+
let inFlight = 0;
|
|
598
|
+
let stopped = false;
|
|
599
|
+
const markSettled = (settledName) => {
|
|
600
|
+
const deps = dependents.get(settledName);
|
|
601
|
+
if (!deps)
|
|
602
|
+
return;
|
|
603
|
+
for (const dependent of deps) {
|
|
604
|
+
const next = (remainingDeps.get(dependent) ?? 1) - 1;
|
|
605
|
+
remainingDeps.set(dependent, next);
|
|
606
|
+
if (next !== 0 || stopped)
|
|
607
|
+
continue;
|
|
608
|
+
const seeder = seederMap.get(dependent);
|
|
609
|
+
if (!seeder)
|
|
610
|
+
continue;
|
|
611
|
+
const failedDeps = seeder.dependsOn.filter((d) => failedSeeders.has(d));
|
|
612
|
+
if (failedDeps.length > 0) {
|
|
613
|
+
const idx = resultIndex.get(dependent);
|
|
614
|
+
if (idx !== undefined) {
|
|
615
|
+
results[idx] = { name: dependent, status: "skipped", failedDeps };
|
|
616
|
+
}
|
|
617
|
+
failedSeeders.add(dependent);
|
|
618
|
+
if (verbose) {
|
|
619
|
+
printConcurrentSkipped(dependent, failedDeps);
|
|
620
|
+
}
|
|
621
|
+
markSettled(dependent);
|
|
622
|
+
} else {
|
|
623
|
+
ready.push(dependent);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const schedule = () => {
|
|
628
|
+
while (!stopped && inFlight < concurrency && ready.length > 0) {
|
|
629
|
+
const name = popHighestPriority();
|
|
630
|
+
inFlight++;
|
|
631
|
+
executeSeeder(name).then((ok) => {
|
|
632
|
+
inFlight--;
|
|
633
|
+
if (!ok && !continueOnFailure) {
|
|
634
|
+
stopped = true;
|
|
635
|
+
} else {
|
|
636
|
+
markSettled(name);
|
|
637
|
+
}
|
|
638
|
+
schedule();
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
if (inFlight === 0 && (stopped || ready.length === 0)) {
|
|
642
|
+
resolve();
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
schedule();
|
|
646
|
+
});
|
|
346
647
|
}
|
|
347
|
-
if (
|
|
348
|
-
|
|
648
|
+
if (printResults) {
|
|
649
|
+
printResultsTable(results);
|
|
650
|
+
printErrors(results);
|
|
651
|
+
printSummary(results, performance.now() - runStartTime, concurrency);
|
|
652
|
+
}
|
|
653
|
+
} finally {
|
|
654
|
+
try {
|
|
655
|
+
if (config.flushCache) {
|
|
656
|
+
await config.flushCache();
|
|
657
|
+
}
|
|
658
|
+
} finally {
|
|
659
|
+
if (config.onAfterAll) {
|
|
660
|
+
await config.onAfterAll(ctx);
|
|
661
|
+
}
|
|
349
662
|
}
|
|
350
663
|
}
|
|
664
|
+
} finally {
|
|
665
|
+
exitSeeding();
|
|
666
|
+
}
|
|
667
|
+
const hasFailure = results.some((r) => r.status === "failed");
|
|
668
|
+
if (hasFailure) {
|
|
669
|
+
return {
|
|
670
|
+
success: false,
|
|
671
|
+
results,
|
|
672
|
+
outputs
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
success: true,
|
|
677
|
+
results,
|
|
678
|
+
outputs
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// src/cli.ts
|
|
683
|
+
var USAGE_ERRORS = new Set([
|
|
684
|
+
"CircularDependencyError",
|
|
685
|
+
"MissingDependencyError",
|
|
686
|
+
"DuplicateSeederError",
|
|
687
|
+
"UnknownSeederError",
|
|
688
|
+
"SeedTargetError"
|
|
689
|
+
]);
|
|
690
|
+
function formatSeedersList(seeders) {
|
|
691
|
+
if (seeders.length === 0)
|
|
692
|
+
return "No seeders registered.";
|
|
693
|
+
const maxLen = Math.max(...seeders.map((s) => s.name.length));
|
|
694
|
+
const lines = seeders.map((s) => {
|
|
695
|
+
const desc = s.description ? ` ${colorize(s.description, "dim")}` : "";
|
|
696
|
+
return ` ${s.name.padEnd(maxLen)}${desc}`;
|
|
697
|
+
});
|
|
698
|
+
return `${colorize(`Registered seeders (${seeders.length}):`, "white", "bold")}
|
|
699
|
+
${lines.join(`
|
|
700
|
+
`)}`;
|
|
701
|
+
}
|
|
702
|
+
var helpText = (seeders) => `
|
|
703
|
+
${colorize("Usage:", "cyan", "bold")} bun run seed [seeder...] [options]
|
|
704
|
+
|
|
705
|
+
${colorize("Arguments:", "white", "bold")}
|
|
706
|
+
seeder... Run only these seeders and the seeders they depend on
|
|
707
|
+
|
|
708
|
+
${colorize("Options:", "white", "bold")}
|
|
709
|
+
--only a,b Same as naming the seeders
|
|
710
|
+
--fresh Ignore and overwrite cached steps of the named seeders
|
|
711
|
+
(of every seeder when none are named)
|
|
712
|
+
--concurrency, -c <n> Run up to <n> independent seeders in parallel (default: 1)
|
|
713
|
+
--continue-on-failure Keep running seeders that do not depend on a failed one
|
|
714
|
+
--allow-remote Seed a database that is not local
|
|
715
|
+
--quiet, -q Suppress progress and step output (keep results table)
|
|
716
|
+
--dry-run Show execution order without running seeders
|
|
717
|
+
--list, -l List registered seeders in dependency order and exit
|
|
718
|
+
--help, -h Show this help message
|
|
719
|
+
|
|
720
|
+
${formatSeedersList(seeders)}
|
|
721
|
+
`;
|
|
722
|
+
async function runCli(seeders, runSeeders, {
|
|
723
|
+
argv,
|
|
724
|
+
target,
|
|
725
|
+
defaultConcurrency
|
|
726
|
+
}) {
|
|
727
|
+
let parsed;
|
|
728
|
+
try {
|
|
729
|
+
parsed = parse(argv);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
console.error(colorize(error instanceof Error ? error.message : String(error), "red"));
|
|
732
|
+
console.log(helpText(seeders));
|
|
733
|
+
return 1;
|
|
734
|
+
}
|
|
735
|
+
const { values, positionals } = parsed;
|
|
736
|
+
if (values.help) {
|
|
737
|
+
console.log(helpText(seeders));
|
|
738
|
+
return 0;
|
|
351
739
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
740
|
+
let concurrency;
|
|
741
|
+
if (values.concurrency !== undefined) {
|
|
742
|
+
const parsedConcurrency = values.concurrency.toLowerCase() === "infinity" ? Number.POSITIVE_INFINITY : Number(values.concurrency);
|
|
743
|
+
if (Number.isNaN(parsedConcurrency) || parsedConcurrency < 1 || Number.isFinite(parsedConcurrency) && !Number.isInteger(parsedConcurrency)) {
|
|
744
|
+
console.error(colorize(`Invalid --concurrency value "${values.concurrency}": expected a positive integer`, "red"));
|
|
745
|
+
return 1;
|
|
746
|
+
}
|
|
747
|
+
concurrency = parsedConcurrency;
|
|
356
748
|
}
|
|
357
|
-
|
|
358
|
-
|
|
749
|
+
const names = [...positionals, ...(values.only ?? []).flatMap((value) => value.split(","))].map((value) => value.trim()).filter(Boolean);
|
|
750
|
+
const only = names.length > 0 ? names : undefined;
|
|
751
|
+
try {
|
|
752
|
+
if (values.list) {
|
|
753
|
+
const order = resolveDependencyOrder(seeders, only);
|
|
754
|
+
const seederMap = new Map(seeders.map((s) => [s.name, s]));
|
|
755
|
+
console.log(`
|
|
756
|
+
${colorize("\uD83C\uDF31 Seeders", "cyan", "bold")} ${colorize(`(${order.length})`, "dim")}
|
|
757
|
+
`);
|
|
758
|
+
const maxLen = Math.max(0, ...order.map((n) => n.length));
|
|
759
|
+
for (const seederName of order) {
|
|
760
|
+
const seeder = seederMap.get(seederName);
|
|
761
|
+
const desc = seeder?.description ? ` ${colorize(seeder.description, "dim")}` : "";
|
|
762
|
+
const deps = seeder?.dependsOn ?? [];
|
|
763
|
+
const depsStr = deps.length > 0 ? ` ${colorize(`[depends on: ${deps.join(", ")}]`, "dim")}` : "";
|
|
764
|
+
console.log(` ${seederName.padEnd(maxLen)}${desc}${depsStr}`);
|
|
765
|
+
}
|
|
766
|
+
console.log("");
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
769
|
+
if (values["dry-run"]) {
|
|
770
|
+
const order = resolveDependencyOrder(seeders, only);
|
|
771
|
+
const seederMap = new Map(seeders.map((s) => [s.name, s]));
|
|
772
|
+
const targetUrl = target?.();
|
|
773
|
+
const targetDesc = targetUrl ? describeTarget(targetUrl) : undefined;
|
|
774
|
+
const targetText = targetDesc ? ` ${colorize(`→ ${targetDesc.label}`, "dim")}${targetDesc.local ? "" : ` ${colorize("(remote)", "yellow")}`}` : "";
|
|
775
|
+
const freshSet = values.fresh ? only ? new Set(only) : true : false;
|
|
776
|
+
const effectiveConcurrency = concurrency ?? defaultConcurrency ?? 1;
|
|
777
|
+
const concurrencyText = effectiveConcurrency > 1 ? `, concurrency: ${effectiveConcurrency === Number.POSITIVE_INFINITY ? "∞" : effectiveConcurrency}` : "";
|
|
778
|
+
console.log(`
|
|
779
|
+
${colorize("\uD83C\uDF31 Dry Run", "cyan", "bold")} ${colorize(`(${order.length} ${order.length === 1 ? "seeder" : "seeders"}${concurrencyText})`, "dim")}${targetText}
|
|
780
|
+
`);
|
|
781
|
+
const printItem = (seederName, num, indent) => {
|
|
782
|
+
const seeder = seederMap.get(seederName);
|
|
783
|
+
const deps = seeder?.dependsOn ?? [];
|
|
784
|
+
const depsStr = deps.length > 0 ? ` ${colorize(`(depends on: ${deps.join(", ")})`, "dim")}` : "";
|
|
785
|
+
const freshStr = freshSet === true || freshSet instanceof Set && freshSet.has(seederName) ? ` ${colorize("(fresh)", "yellow")}` : "";
|
|
786
|
+
console.log(`${indent}${num}. ${seederName}${depsStr}${freshStr}`);
|
|
787
|
+
if (seeder?.description) {
|
|
788
|
+
console.log(`${indent} ${colorize(seeder.description, "dim")}`);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
if (effectiveConcurrency > 1 && order.length > 0) {
|
|
792
|
+
const waveOf = new Map;
|
|
793
|
+
const waves = [];
|
|
794
|
+
for (const seederName of order) {
|
|
795
|
+
const deps = seederMap.get(seederName)?.dependsOn ?? [];
|
|
796
|
+
let wave = 0;
|
|
797
|
+
for (const dep of deps) {
|
|
798
|
+
wave = Math.max(wave, (waveOf.get(dep) ?? 0) + 1);
|
|
799
|
+
}
|
|
800
|
+
waveOf.set(seederName, wave);
|
|
801
|
+
let bucket = waves[wave];
|
|
802
|
+
if (!bucket) {
|
|
803
|
+
bucket = [];
|
|
804
|
+
waves[wave] = bucket;
|
|
805
|
+
}
|
|
806
|
+
bucket.push(seederName);
|
|
807
|
+
}
|
|
808
|
+
console.log(colorize(`Execution plan (${waves.length} ${waves.length === 1 ? "wave" : "waves"}):`, "white", "bold"));
|
|
809
|
+
let index = 1;
|
|
810
|
+
waves.forEach((waveSeeders, waveIdx) => {
|
|
811
|
+
const parallelTag = waveSeeders.length > 1 ? ` ${colorize("(parallel)", "cyan")}` : "";
|
|
812
|
+
console.log(` ${colorize(`Wave ${waveIdx + 1}`, "white", "bold")}${parallelTag}`);
|
|
813
|
+
for (const seederName of waveSeeders) {
|
|
814
|
+
printItem(seederName, index++, " ");
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
} else {
|
|
818
|
+
console.log(colorize("Execution order:", "white", "bold"));
|
|
819
|
+
order.forEach((seederName, i) => {
|
|
820
|
+
printItem(seederName, i + 1, " ");
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
console.log("");
|
|
824
|
+
return 0;
|
|
825
|
+
}
|
|
826
|
+
const { success } = await runSeeders(seeders, {
|
|
827
|
+
printResults: true,
|
|
828
|
+
verbose: !values.quiet,
|
|
829
|
+
only,
|
|
830
|
+
fresh: values.fresh ? only ?? true : false,
|
|
831
|
+
continueOnFailure: values["continue-on-failure"],
|
|
832
|
+
allowRemote: values["allow-remote"],
|
|
833
|
+
concurrency
|
|
834
|
+
});
|
|
835
|
+
return success ? 0 : 1;
|
|
836
|
+
} catch (error) {
|
|
837
|
+
const usage = error instanceof Error && USAGE_ERRORS.has(error.name);
|
|
838
|
+
console.error(colorize(usage ? error.message : Bun.inspect(error), "red"));
|
|
839
|
+
return 1;
|
|
359
840
|
}
|
|
360
|
-
|
|
361
|
-
|
|
841
|
+
}
|
|
842
|
+
function parse(argv) {
|
|
843
|
+
return parseArgs({
|
|
844
|
+
args: [...argv],
|
|
845
|
+
allowPositionals: true,
|
|
846
|
+
strict: true,
|
|
847
|
+
options: {
|
|
848
|
+
help: { type: "boolean", short: "h" },
|
|
849
|
+
list: { type: "boolean", short: "l" },
|
|
850
|
+
quiet: { type: "boolean", short: "q" },
|
|
851
|
+
concurrency: { type: "string", short: "c" },
|
|
852
|
+
"dry-run": { type: "boolean" },
|
|
853
|
+
only: { type: "string", multiple: true },
|
|
854
|
+
fresh: { type: "boolean" },
|
|
855
|
+
"continue-on-failure": { type: "boolean" },
|
|
856
|
+
"allow-remote": { type: "boolean" }
|
|
857
|
+
}
|
|
858
|
+
});
|
|
362
859
|
}
|
|
363
860
|
|
|
364
|
-
// src/
|
|
365
|
-
|
|
366
|
-
function
|
|
367
|
-
|
|
861
|
+
// src/define-seeder.ts
|
|
862
|
+
function createDefineSeeder() {
|
|
863
|
+
return function defineSeeder(config) {
|
|
864
|
+
const dependsOnNames = [
|
|
865
|
+
...new Set((config.dependsOn ?? []).map((seeder) => seeder.name))
|
|
866
|
+
];
|
|
867
|
+
return {
|
|
868
|
+
name: config.name,
|
|
869
|
+
description: config.description,
|
|
870
|
+
dependsOn: dependsOnNames,
|
|
871
|
+
run: config.run
|
|
872
|
+
};
|
|
873
|
+
};
|
|
368
874
|
}
|
|
369
|
-
|
|
370
|
-
|
|
875
|
+
|
|
876
|
+
// src/lazy-faker.ts
|
|
877
|
+
import { createRequire } from "node:module";
|
|
878
|
+
var loadedFaker;
|
|
879
|
+
function getDefaultFaker() {
|
|
880
|
+
if (!loadedFaker) {
|
|
881
|
+
const req = createRequire(import.meta.url);
|
|
882
|
+
const mod = req("@faker-js/faker/locale/en");
|
|
883
|
+
loadedFaker = mod.faker;
|
|
884
|
+
}
|
|
885
|
+
return loadedFaker;
|
|
371
886
|
}
|
|
887
|
+
var lazyFaker = new Proxy({}, {
|
|
888
|
+
get(_target, prop) {
|
|
889
|
+
const instance = getDefaultFaker();
|
|
890
|
+
const value = Reflect.get(instance, prop, instance);
|
|
891
|
+
return typeof value === "function" && prop !== "constructor" ? value.bind(instance) : value;
|
|
892
|
+
},
|
|
893
|
+
set(_target, prop, value) {
|
|
894
|
+
const instance = getDefaultFaker();
|
|
895
|
+
return Reflect.set(instance, prop, value, instance);
|
|
896
|
+
},
|
|
897
|
+
has(_target, prop) {
|
|
898
|
+
return Reflect.has(getDefaultFaker(), prop);
|
|
899
|
+
},
|
|
900
|
+
ownKeys() {
|
|
901
|
+
return Reflect.ownKeys(getDefaultFaker());
|
|
902
|
+
},
|
|
903
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
904
|
+
const desc = Reflect.getOwnPropertyDescriptor(getDefaultFaker(), prop);
|
|
905
|
+
return desc ? { ...desc, configurable: true } : undefined;
|
|
906
|
+
},
|
|
907
|
+
getPrototypeOf() {
|
|
908
|
+
return Reflect.getPrototypeOf(getDefaultFaker());
|
|
909
|
+
}
|
|
910
|
+
});
|
|
372
911
|
|
|
373
912
|
// src/step.ts
|
|
913
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
914
|
+
var isCacheEntry = (stored) => typeof stored === "object" && stored !== null && stored.__plantr === 1;
|
|
915
|
+
var slugify = (description) => description.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
916
|
+
function canonicalStringify(value) {
|
|
917
|
+
if (value === null || typeof value !== "object") {
|
|
918
|
+
return JSON.stringify(value);
|
|
919
|
+
}
|
|
920
|
+
if (Array.isArray(value)) {
|
|
921
|
+
return `[${value.map((item) => item === undefined ? "null" : canonicalStringify(item)).join(",")}]`;
|
|
922
|
+
}
|
|
923
|
+
if (typeof value.toJSON === "function") {
|
|
924
|
+
return canonicalStringify(value.toJSON());
|
|
925
|
+
}
|
|
926
|
+
const obj = value;
|
|
927
|
+
const keys = Object.keys(obj).sort();
|
|
928
|
+
const parts = [];
|
|
929
|
+
for (const key of keys) {
|
|
930
|
+
const entryValue = obj[key];
|
|
931
|
+
if (entryValue !== undefined) {
|
|
932
|
+
parts.push(`${JSON.stringify(key)}:${canonicalStringify(entryValue)}`);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return `{${parts.join(",")}}`;
|
|
936
|
+
}
|
|
374
937
|
function createStepRunner(config) {
|
|
375
|
-
const { cache } = config ?? {};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
938
|
+
const { cache, log = true } = config ?? {};
|
|
939
|
+
const scopeStorage = new AsyncLocalStorage;
|
|
940
|
+
let fallbackScope = {
|
|
941
|
+
seederName: config?.seederName ?? "",
|
|
942
|
+
fresh: false,
|
|
943
|
+
record: { cachedSteps: [] }
|
|
379
944
|
};
|
|
945
|
+
const usedKeys = new Set;
|
|
946
|
+
const pendingWrites = new Map;
|
|
947
|
+
let preloaded;
|
|
948
|
+
let warnedNoCache = false;
|
|
949
|
+
const setSeederName = (name, options) => {
|
|
950
|
+
const record = { cachedSteps: [] };
|
|
951
|
+
fallbackScope = {
|
|
952
|
+
seederName: name,
|
|
953
|
+
fresh: options?.fresh ?? false,
|
|
954
|
+
record
|
|
955
|
+
};
|
|
956
|
+
return record;
|
|
957
|
+
};
|
|
958
|
+
const createScope = (options) => ({
|
|
959
|
+
seederName: options.seederName,
|
|
960
|
+
fresh: options.fresh ?? false,
|
|
961
|
+
record: { cachedSteps: [] },
|
|
962
|
+
prefix: options.prefix
|
|
963
|
+
});
|
|
964
|
+
const runWithScope = (scope, fn) => scopeStorage.run(scope, fn);
|
|
965
|
+
const preload = async () => {
|
|
966
|
+
if (!cache?.getAll)
|
|
967
|
+
return;
|
|
968
|
+
const entries = await cache.getAll();
|
|
969
|
+
preloaded = entries instanceof Map ? new Map(entries) : new Map(Object.entries(entries));
|
|
970
|
+
};
|
|
971
|
+
const flush = async () => {
|
|
972
|
+
if (!cache?.setMany || pendingWrites.size === 0)
|
|
973
|
+
return;
|
|
974
|
+
const entries = [...pendingWrites.entries()].map(([key, value]) => ({
|
|
975
|
+
key,
|
|
976
|
+
value
|
|
977
|
+
}));
|
|
978
|
+
pendingWrites.clear();
|
|
979
|
+
await cache.setMany(entries);
|
|
980
|
+
};
|
|
981
|
+
const print = (line) => {
|
|
982
|
+
if (log)
|
|
983
|
+
console.log(line);
|
|
984
|
+
};
|
|
985
|
+
const formatPrefix = (scope) => scope.prefix ? ` ${colorize(`[${scope.prefix}]`, "cyan")} ` : " ";
|
|
380
986
|
const step = async (description, fn, options) => {
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
const
|
|
987
|
+
const scope = scopeStorage.getStore() ?? fallbackScope;
|
|
988
|
+
const useCache = options?.useCache === true;
|
|
989
|
+
const startTime = performance.now();
|
|
990
|
+
const prefix = formatPrefix(scope);
|
|
384
991
|
try {
|
|
385
992
|
let result;
|
|
386
993
|
let wasCached = false;
|
|
387
994
|
if (useCache && cache) {
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
995
|
+
const rawKey = options.key !== undefined ? options.key : slugify(description);
|
|
996
|
+
const cacheKey = scope.seederName ? `${scope.seederName}:${rawKey}` : rawKey;
|
|
997
|
+
if (usedKeys.has(cacheKey)) {
|
|
998
|
+
throw new Error(`Step "${description}" uses cache key "${cacheKey}", which another cached step in this run already used. Give each cached step a unique description or explicit key.`);
|
|
999
|
+
}
|
|
1000
|
+
usedKeys.add(cacheKey);
|
|
1001
|
+
const version = options.version === undefined ? undefined : canonicalStringify(options.version);
|
|
1002
|
+
const stored = scope.fresh ? undefined : preloaded !== undefined ? preloaded.get(cacheKey) : await cache.get(cacheKey);
|
|
1003
|
+
if (isCacheEntry(stored) && stored.version === version) {
|
|
1004
|
+
result = stored.value;
|
|
1005
|
+
wasCached = true;
|
|
1006
|
+
} else if (stored !== undefined && stored !== null && !isCacheEntry(stored) && version === undefined) {
|
|
1007
|
+
result = stored;
|
|
391
1008
|
wasCached = true;
|
|
392
1009
|
} else {
|
|
393
1010
|
result = await fn();
|
|
394
|
-
|
|
1011
|
+
const entry = version === undefined ? { __plantr: 1, value: result } : { __plantr: 1, version, value: result };
|
|
1012
|
+
preloaded?.set(cacheKey, entry);
|
|
1013
|
+
if (cache.setMany) {
|
|
1014
|
+
pendingWrites.set(cacheKey, entry);
|
|
1015
|
+
} else {
|
|
1016
|
+
await cache.set(cacheKey, entry);
|
|
1017
|
+
}
|
|
395
1018
|
}
|
|
396
1019
|
} else if (useCache && !cache) {
|
|
397
|
-
|
|
1020
|
+
if (!warnedNoCache) {
|
|
1021
|
+
warnedNoCache = true;
|
|
1022
|
+
print(`${prefix}${colorize("⚠ Cache not configured, running without cache", "yellow")}`);
|
|
1023
|
+
}
|
|
398
1024
|
result = await fn();
|
|
399
1025
|
} else {
|
|
400
1026
|
result = await fn();
|
|
401
1027
|
}
|
|
402
|
-
|
|
403
|
-
|
|
1028
|
+
if (wasCached)
|
|
1029
|
+
scope.record.cachedSteps.push(description);
|
|
1030
|
+
const suffix = wasCached ? ` ${colorize("(cached)", "cyan")}` : ` ${colorize(formatDuration(performance.now() - startTime), "dim")}`;
|
|
1031
|
+
print(`${prefix}${colorize("✓", "green")} ${description}${suffix}`);
|
|
404
1032
|
return result;
|
|
405
1033
|
} catch (error) {
|
|
406
|
-
|
|
1034
|
+
if (!scope.record.failed || scope.record.failed.error !== error) {
|
|
1035
|
+
scope.record.failed = { step: description, error };
|
|
1036
|
+
}
|
|
1037
|
+
print(`${prefix}${colorize("✗", "red")} ${description}`);
|
|
407
1038
|
if (error instanceof Error) {
|
|
408
|
-
|
|
1039
|
+
print(`${prefix} ${colorize(error.message, "dim")}`);
|
|
409
1040
|
}
|
|
410
1041
|
throw error;
|
|
411
1042
|
}
|
|
412
1043
|
};
|
|
413
|
-
return { step, setSeederName };
|
|
1044
|
+
return { step, setSeederName, createScope, runWithScope, preload, flush };
|
|
414
1045
|
}
|
|
415
1046
|
|
|
416
1047
|
// src/create-seeder-instance.ts
|
|
1048
|
+
function cloneFaker(baseFaker) {
|
|
1049
|
+
const Ctor = baseFaker.constructor;
|
|
1050
|
+
if (typeof Ctor === "function" && "rawDefinitions" in baseFaker && baseFaker.rawDefinitions) {
|
|
1051
|
+
return new Ctor({ locale: baseFaker.rawDefinitions });
|
|
1052
|
+
}
|
|
1053
|
+
return baseFaker;
|
|
1054
|
+
}
|
|
417
1055
|
function createSeederInstance(config) {
|
|
418
1056
|
const defineSeeder = createDefineSeeder();
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
1057
|
+
const customFaker = config?.faker && config.faker !== lazyFaker ? config.faker : undefined;
|
|
1058
|
+
const resolveBaseFaker = () => customFaker ?? getDefaultFaker();
|
|
1059
|
+
const fakerSeed = config?.fakerSeed;
|
|
1060
|
+
const defaultConcurrency = config?.concurrency;
|
|
1061
|
+
const runInternal = async (seeders, options, bannerName) => {
|
|
1062
|
+
const stepRunner = createStepRunner({
|
|
1063
|
+
cache: config?.cache,
|
|
1064
|
+
log: options?.verbose ?? true
|
|
1065
|
+
});
|
|
1066
|
+
const fakerStorage = new AsyncLocalStorage2;
|
|
1067
|
+
const resolveActiveFaker = () => {
|
|
1068
|
+
const slot = fakerStorage.getStore();
|
|
1069
|
+
if (!slot)
|
|
1070
|
+
return resolveBaseFaker();
|
|
1071
|
+
if (slot.instance)
|
|
1072
|
+
return slot.instance;
|
|
1073
|
+
const base = resolveBaseFaker();
|
|
1074
|
+
if (!slot.isolated) {
|
|
1075
|
+
slot.instance = base;
|
|
1076
|
+
return base;
|
|
1077
|
+
}
|
|
1078
|
+
const cloned = cloneFaker(base);
|
|
1079
|
+
if (fakerSeed !== undefined) {
|
|
1080
|
+
cloned.seed(fakerSeed + hashName(slot.name));
|
|
1081
|
+
}
|
|
1082
|
+
slot.instance = cloned;
|
|
1083
|
+
return cloned;
|
|
425
1084
|
};
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
setSeedingActive(true);
|
|
432
|
-
if (config.onBeforeAll) {
|
|
433
|
-
await config.onBeforeAll();
|
|
434
|
-
}
|
|
1085
|
+
const scopedFaker = new Proxy({}, {
|
|
1086
|
+
get(_target, prop) {
|
|
1087
|
+
const active = resolveActiveFaker();
|
|
1088
|
+
const value = Reflect.get(active, prop, active);
|
|
1089
|
+
return typeof value === "function" && prop !== "constructor" ? value.bind(active) : value;
|
|
435
1090
|
},
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
1091
|
+
set(_target, prop, value) {
|
|
1092
|
+
const active = resolveActiveFaker();
|
|
1093
|
+
return Reflect.set(active, prop, value, active);
|
|
1094
|
+
},
|
|
1095
|
+
has(_target, prop) {
|
|
1096
|
+
return Reflect.has(resolveActiveFaker(), prop);
|
|
1097
|
+
},
|
|
1098
|
+
ownKeys() {
|
|
1099
|
+
return Reflect.ownKeys(resolveActiveFaker());
|
|
1100
|
+
},
|
|
1101
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
1102
|
+
const desc = Reflect.getOwnPropertyDescriptor(resolveActiveFaker(), prop);
|
|
1103
|
+
return desc ? { ...desc, configurable: true } : undefined;
|
|
1104
|
+
},
|
|
1105
|
+
getPrototypeOf() {
|
|
1106
|
+
return Reflect.getPrototypeOf(resolveActiveFaker());
|
|
441
1107
|
}
|
|
442
|
-
};
|
|
443
|
-
|
|
1108
|
+
});
|
|
1109
|
+
const mergedOptions = defaultConcurrency !== undefined && options?.concurrency === undefined ? { ...options, concurrency: defaultConcurrency } : options ?? {};
|
|
1110
|
+
return runSeedersCore(seeders, {
|
|
1111
|
+
context: async () => {
|
|
1112
|
+
const base = {
|
|
1113
|
+
faker: scopedFaker,
|
|
1114
|
+
step: stepRunner.step,
|
|
1115
|
+
expect
|
|
1116
|
+
};
|
|
1117
|
+
if (!config?.context)
|
|
1118
|
+
return base;
|
|
1119
|
+
const extra = await config.context(base);
|
|
1120
|
+
return extra === base ? base : { ...base, ...extra };
|
|
1121
|
+
},
|
|
1122
|
+
preloadCache: config?.cache?.getAll ? () => stepRunner.preload() : undefined,
|
|
1123
|
+
flushCache: config?.cache?.setMany ? () => stepRunner.flush() : undefined,
|
|
1124
|
+
createSeederScope: ({ name, fresh, concurrent }) => {
|
|
1125
|
+
const stepScope = stepRunner.createScope({
|
|
1126
|
+
seederName: name,
|
|
1127
|
+
fresh,
|
|
1128
|
+
prefix: concurrent ? name : undefined
|
|
1129
|
+
});
|
|
1130
|
+
const slot = {
|
|
1131
|
+
name,
|
|
1132
|
+
isolated: fakerSeed !== undefined || concurrent
|
|
1133
|
+
};
|
|
1134
|
+
return {
|
|
1135
|
+
record: stepScope.record,
|
|
1136
|
+
run: (fn) => stepRunner.runWithScope(stepScope, () => fakerStorage.run(slot, fn))
|
|
1137
|
+
};
|
|
1138
|
+
},
|
|
1139
|
+
bannerName,
|
|
1140
|
+
target: config?.target,
|
|
1141
|
+
onBeforeAll: config?.onBeforeAll,
|
|
1142
|
+
onAfterAll: config?.onAfterAll
|
|
1143
|
+
}, mergedOptions);
|
|
444
1144
|
};
|
|
1145
|
+
const runSeeders = (seeders, options) => runInternal(seeders, options);
|
|
445
1146
|
const runSeedersCli = async (seeders, options) => {
|
|
446
|
-
const
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
${colorize("Options:", "white", "bold")}
|
|
453
|
-
--help, -h Show this help message
|
|
454
|
-
--dry-run Show execution order without running seeders
|
|
455
|
-
|
|
456
|
-
Runs all ${seeders.length} seeders in dependency order.
|
|
457
|
-
`);
|
|
458
|
-
process.exit(0);
|
|
459
|
-
}
|
|
460
|
-
if (args.includes("--dry-run")) {
|
|
461
|
-
console.log(`
|
|
462
|
-
${colorize("\uD83C\uDF31 Dry Run", "cyan", "bold")} ${colorize(`(${seeders.length} seeders)`, "dim")}
|
|
463
|
-
`);
|
|
464
|
-
const seederMap = new Map;
|
|
465
|
-
for (const seeder of seeders) {
|
|
466
|
-
seederMap.set(seeder.name, seeder);
|
|
467
|
-
}
|
|
468
|
-
try {
|
|
469
|
-
const order = resolveDependencyOrder(seeders);
|
|
470
|
-
console.log(colorize("Execution order:", "white", "bold"));
|
|
471
|
-
for (let i = 0;i < order.length; i++) {
|
|
472
|
-
const seederName = order[i];
|
|
473
|
-
if (!seederName)
|
|
474
|
-
continue;
|
|
475
|
-
const seeder = seederMap.get(seederName);
|
|
476
|
-
const deps = seeder?.dependsOn ?? [];
|
|
477
|
-
const depsStr = deps.length > 0 ? ` ${colorize(`(depends on: ${deps.join(", ")})`, "dim")}` : "";
|
|
478
|
-
console.log(` ${i + 1}. ${seederName}${depsStr}`);
|
|
479
|
-
}
|
|
480
|
-
console.log("");
|
|
481
|
-
process.exit(0);
|
|
482
|
-
} catch (error) {
|
|
483
|
-
console.error(colorize("Failed to resolve dependencies:", "red"));
|
|
484
|
-
console.error(` ${error instanceof Error ? error.message : String(error)}`);
|
|
485
|
-
process.exit(1);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
console.log(`
|
|
489
|
-
${colorize(`\uD83C\uDF31 Running ${name}`, "cyan", "bold")} ${colorize(`(${seeders.length} seeders)`, "dim")}
|
|
490
|
-
`);
|
|
491
|
-
const { success } = await runSeeders(seeders, {
|
|
492
|
-
printResults: true,
|
|
493
|
-
verbose: true
|
|
1147
|
+
const bannerName = options?.name ?? "Seeders";
|
|
1148
|
+
const code = await runCli(seeders, (s, opts) => runInternal(s, opts, bannerName), {
|
|
1149
|
+
name: bannerName,
|
|
1150
|
+
argv: options?.argv ?? process.argv.slice(2),
|
|
1151
|
+
target: config?.target,
|
|
1152
|
+
defaultConcurrency
|
|
494
1153
|
});
|
|
495
|
-
process.exit(
|
|
1154
|
+
process.exit(code);
|
|
496
1155
|
};
|
|
497
1156
|
return {
|
|
498
1157
|
defineSeeder,
|
|
@@ -501,17 +1160,29 @@ ${colorize(`\uD83C\uDF31 Running ${name}`, "cyan", "bold")} ${colorize(`(${seede
|
|
|
501
1160
|
isSeedingActive
|
|
502
1161
|
};
|
|
503
1162
|
}
|
|
1163
|
+
function hashName(name) {
|
|
1164
|
+
let hash = 2166136261;
|
|
1165
|
+
for (let i = 0;i < name.length; i++) {
|
|
1166
|
+
hash ^= name.charCodeAt(i);
|
|
1167
|
+
hash = Math.imul(hash, 16777619);
|
|
1168
|
+
}
|
|
1169
|
+
return hash >>> 0;
|
|
1170
|
+
}
|
|
504
1171
|
export {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
isSeedingActive,
|
|
508
|
-
formatDuration,
|
|
509
|
-
faker2 as faker,
|
|
510
|
-
expect2 as expect,
|
|
511
|
-
createStepRunner,
|
|
512
|
-
createSeederInstance,
|
|
513
|
-
createDefineSeeder,
|
|
514
|
-
colorize,
|
|
1172
|
+
CircularDependencyError,
|
|
1173
|
+
DuplicateSeederError,
|
|
515
1174
|
MissingDependencyError,
|
|
516
|
-
|
|
1175
|
+
SeedTargetError,
|
|
1176
|
+
UnknownSeederError,
|
|
1177
|
+
colorize,
|
|
1178
|
+
createDefineSeeder,
|
|
1179
|
+
createSeederInstance,
|
|
1180
|
+
createStepRunner,
|
|
1181
|
+
describeTarget,
|
|
1182
|
+
expect2 as expect,
|
|
1183
|
+
lazyFaker as faker,
|
|
1184
|
+
formatDuration,
|
|
1185
|
+
isSeedingActive,
|
|
1186
|
+
resolveDependencyOrder,
|
|
1187
|
+
runSeedersCore
|
|
517
1188
|
};
|