plantr 2.0.0 → 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.
Files changed (40) hide show
  1. package/dist/index.d.ts +23 -20
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +761 -262
  4. package/dist/src/cli.d.ts +13 -3
  5. package/dist/src/cli.d.ts.map +1 -0
  6. package/dist/src/create-seeder-instance.d.ts +55 -78
  7. package/dist/src/create-seeder-instance.d.ts.map +1 -0
  8. package/dist/src/define-seeder.d.ts +4 -3
  9. package/dist/src/define-seeder.d.ts.map +1 -0
  10. package/dist/src/dependency-resolver.d.ts +2 -1
  11. package/dist/src/dependency-resolver.d.ts.map +1 -0
  12. package/dist/src/formatting.d.ts +27 -13
  13. package/dist/src/formatting.d.ts.map +1 -0
  14. package/dist/src/lazy-faker.d.ts +12 -0
  15. package/dist/src/lazy-faker.d.ts.map +1 -0
  16. package/dist/src/run-seeders.d.ts +39 -22
  17. package/dist/src/run-seeders.d.ts.map +1 -0
  18. package/dist/src/seeding-state.d.ts +15 -4
  19. package/dist/src/seeding-state.d.ts.map +1 -0
  20. package/dist/src/step.d.ts +79 -22
  21. package/dist/src/step.d.ts.map +1 -0
  22. package/dist/src/types.d.ts +117 -34
  23. package/dist/src/types.d.ts.map +1 -0
  24. package/dist/state.d.ts +2 -1
  25. package/dist/state.d.ts.map +1 -0
  26. package/dist/state.js +10 -2
  27. package/index.ts +56 -23
  28. package/package.json +2 -1
  29. package/readme.md +89 -48
  30. package/src/cli.ts +154 -21
  31. package/src/create-seeder-instance.ts +225 -110
  32. package/src/define-seeder.ts +14 -7
  33. package/src/dependency-resolver.ts +17 -28
  34. package/src/formatting.ts +121 -36
  35. package/src/lazy-faker.ts +46 -0
  36. package/src/run-seeders.ts +336 -115
  37. package/src/seeding-state.ts +27 -5
  38. package/src/step.ts +208 -64
  39. package/src/types.ts +169 -37
  40. package/state.ts +1 -1
package/dist/src/cli.d.ts CHANGED
@@ -1,13 +1,23 @@
1
- import type { RunSeedersOptions, SeederAny } from './types';
2
- type RunSeeders = (seeders: readonly SeederAny[], options?: RunSeedersOptions) => Promise<{
1
+ import type { RunSeedersOptions, SeederAny } from './types.js';
2
+ /** Options for `runSeedersCli` */
3
+ export type RunSeedersCliOptions = {
4
+ /** Display name shown in the banner (default: `'Seeders'`) */
5
+ name?: string | undefined;
6
+ /** Arguments to parse (default: `process.argv.slice(2)`) */
7
+ argv?: readonly string[] | undefined;
8
+ };
9
+ type CliRunner = (seeders: readonly SeederAny[], options?: RunSeedersOptions) => Promise<{
3
10
  success: boolean;
4
11
  }>;
5
12
  /**
6
13
  * Parse CLI arguments, run the seeders and return the exit code.
7
14
  * Unknown flags and unknown seeder names return 1.
8
15
  */
9
- export declare function runCli(seeders: readonly SeederAny[], runSeeders: RunSeeders, { name, argv }: {
16
+ export declare function runCli(seeders: readonly SeederAny[], runSeeders: CliRunner, { argv, target, defaultConcurrency, }: {
10
17
  name: string;
11
18
  argv: readonly string[];
19
+ target?: (() => string | undefined) | undefined;
20
+ defaultConcurrency?: number | undefined;
12
21
  }): Promise<number>;
13
22
  export {};
23
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE9D,kCAAkC;AAClC,MAAM,MAAM,oBAAoB,GAAG;IAClC,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;CACpC,CAAA;AAED,KAAK,SAAS,GAAG,CAChB,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,OAAO,CAAC,EAAE,iBAAiB,KACvB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AA0ClC;;;GAGG;AACH,wBAAsB,MAAM,CAC3B,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,UAAU,EAAE,SAAS,EACrB,EACC,IAAI,EACJ,MAAM,EACN,kBAAkB,GAClB,EAAE;IACF,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IACvB,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAC/C,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACvC,GACC,OAAO,CAAC,MAAM,CAAC,CA2JjB"}
@@ -1,56 +1,69 @@
1
- import { type SeederCache } from './step';
2
- import type { BaseSeederContext, RunSeedersOptions, Seeder, SeederAny, SeederConfig, SeederResult } from './types';
1
+ import type { Faker } from '@faker-js/faker';
2
+ import { type RunSeedersCliOptions } from './cli.js';
3
+ import { type SeederCache } from './step.js';
4
+ import type { BaseSeederContext, MaybePromise, Prettify, RunSeedersOptions, RunSeedersResult, Seeder, SeederConfig, SeederName, ValidateSeeders } from './types.js';
5
+ /**
6
+ * Full context type resolved from `BaseSeederContext` plus the extra properties
7
+ * returned by `config.context`. Any base key returned by `context` overrides the default.
8
+ */
9
+ export type ResolvedContext<TExtra extends object = Record<never, never>> = Prettify<Omit<BaseSeederContext, keyof TExtra> & TExtra>;
3
10
  /**
4
11
  * Configuration for creating a seeder instance.
5
- * The context factory receives the base context (faker, step, expect) and can extend it.
12
+ * `context` is optional and its returned properties are automatically merged onto `BaseSeederContext`.
6
13
  */
7
- export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
14
+ export type SeederInstanceConfig<TExtra extends object = Record<never, never>> = {
8
15
  /**
9
- * Factory function that creates the context for each seeder.
10
- * Receives the base context (faker, step, expect) and should return the full context.
16
+ * Optional factory function that extends the base context (`faker`, `step`, `expect`).
17
+ * Returned properties are merged onto `base` automatically — no need to spread `...base`,
18
+ * though spreading or overriding keys (such as `faker`) also works.
19
+ * Called once per run, after `onBeforeAll`.
11
20
  *
12
21
  * @example
13
22
  * ```typescript
14
- * context: (base) => ({
15
- * ...base,
16
- * prisma,
17
- * myHelper: () => { ... }
18
- * })
23
+ * context: () => ({ prisma })
19
24
  * ```
20
25
  */
21
- context: (base: BaseSeederContext) => TContext | Promise<TContext>;
26
+ context?: ((base: BaseSeederContext) => MaybePromise<TExtra>) | undefined;
22
27
  /**
23
28
  * Optional cache for step caching.
24
- * Provide get/set functions to enable caching in the step runner.
29
+ * Provide `get` / `set` (and optionally `getAll` for single-query preloading).
25
30
  *
26
31
  * @example
27
32
  * ```typescript
28
33
  * cache: {
29
- * get: async (key) => {
30
- * const cached = await prisma.seedCache.findUnique({ where: { key } })
31
- * return cached?.output as T | undefined
32
- * },
34
+ * get: async (key) => (await prisma.seedCache.findUnique({ where: { key } }))?.output,
33
35
  * set: async (key, value) => {
34
36
  * const output = value as Prisma.InputJsonValue
35
37
  * await prisma.seedCache.upsert({ where: { key }, create: { key, output }, update: { output } })
36
- * }
38
+ * },
37
39
  * }
38
40
  * ```
39
41
  */
40
- cache?: SeederCache;
42
+ cache?: SeederCache | undefined;
43
+ /**
44
+ * Optional: default maximum number of independent seeders to run concurrently (default: 1).
45
+ * Applies to both `runSeeders` and `runSeedersCli` unless overridden per run or via `--concurrency`.
46
+ * Set to a positive integer (e.g. `4`) or `Infinity` to run independent DAG branches in parallel.
47
+ */
48
+ concurrency?: number | undefined;
49
+ /**
50
+ * Optional: custom `Faker` instance (e.g. a non-English locale like `fakerDE` or `fakerNB_NO`).
51
+ * Defaults to the lazy-loaded English locale (`@faker-js/faker/locale/en`).
52
+ */
53
+ faker?: Faker | undefined;
41
54
  /**
42
55
  * Optional: the database URL this instance writes to, e.g. `() => process.env.DATABASE_URL`.
43
56
  * The banner prints its host and database (never credentials), and a run refuses a
44
57
  * host that is not local unless it passes `allowRemote` (CLI: `--allow-remote`).
45
58
  * Return undefined to skip the check.
46
59
  */
47
- target?: () => string | undefined;
60
+ target?: (() => string | undefined) | undefined;
48
61
  /**
49
62
  * Optional: seed faker before each seeder with this number plus a hash of the
50
63
  * seeder's name, so every run generates the same data and adding a seeder does
51
- * not shift the others'.
64
+ * not shift the others'. Works safely with parallel `concurrency` via isolated Faker instances.
52
65
  */
53
- fakerSeed?: number;
66
+ fakerSeed?: number | undefined;
54
67
  /**
55
68
  * Called before all seeders run, before the context factory.
56
69
  * Use for setup like connecting to databases, or to refuse a run.
@@ -62,10 +75,10 @@ export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
62
75
  * }
63
76
  * ```
64
77
  */
65
- onBeforeAll?: () => void | Promise<void>;
78
+ onBeforeAll?: (() => MaybePromise<void>) | undefined;
66
79
  /**
67
80
  * Called after all seeders complete (success or failure), also when the context
68
- * factory throws.
81
+ * factory throws. Receives the created context (or `undefined` if the context factory threw).
69
82
  * Use for cleanup like disconnecting from databases.
70
83
  *
71
84
  * @example
@@ -75,14 +88,15 @@ export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
75
88
  * }
76
89
  * ```
77
90
  */
78
- onAfterAll?: () => void | Promise<void>;
91
+ onAfterAll?: ((ctx: NoInfer<ResolvedContext<TExtra>> | undefined) => MaybePromise<void>) | undefined;
79
92
  };
80
93
  /**
81
94
  * Result type for the seeder instance
82
95
  */
83
- export type SeederInstance<TContext extends BaseSeederContext> = {
96
+ export type SeederInstance<TContext extends object = BaseSeederContext> = {
84
97
  /**
85
- * Define a new seeder with typed dependencies
98
+ * Define a new seeder with typed dependencies.
99
+ * `dependsOn` only accepts seeders whose context is compatible with this instance.
86
100
  *
87
101
  * @example
88
102
  * ```typescript
@@ -97,26 +111,28 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
97
111
  * })
98
112
  * ```
99
113
  */
100
- defineSeeder: <TName extends string, TOutput, const TDeps extends readonly SeederAny[] = readonly []>(config: SeederConfig<TContext, TName, TOutput, TDeps>) => Seeder<TContext, TName, TOutput>;
114
+ defineSeeder: <TName extends string, TOutput, const TDeps extends readonly Seeder<TContext, string, unknown, string>[] = readonly []>(config: SeederConfig<TContext, TName, TOutput, TDeps>) => Seeder<TContext, TName, Awaited<TOutput>, SeederName<TDeps[number]>>;
101
115
  /**
102
116
  * Run an array of seeders in dependency order.
103
117
  * Automatically sets seeding state to active during execution.
104
118
  *
119
+ * - Enforces context compatibility across seeders at compile time
120
+ * - Flags missing dependencies at compile time when passing known seeders
121
+ * - Autocompletes and checks `only` and `fresh` against the registered seeder names
122
+ * - Returns strongly typed `outputs` and discriminated-union `results`
123
+ *
105
124
  * @param seeders - Array of seeders to run
106
125
  * @param options - Optional runner options
107
- * @returns Object containing results and success status; `success` is false when a seeder failed
126
+ * @returns Object containing `success`, typed `results`, and typed `outputs`
108
127
  * @throws Before anything runs, on an invalid registry (duplicate name, missing
109
- * dependency, cycle), an unknown name in `only`/`fresh`, or a refused `target`
128
+ * dependency, cycle), an unknown name in `only`/`fresh`, invalid `concurrency`, or a refused `target`
110
129
  */
111
- runSeeders: (seeders: readonly SeederAny[], options?: RunSeedersOptions) => Promise<{
112
- results: SeederResult[];
113
- success: boolean;
114
- }>;
130
+ runSeeders: <const TSeeders extends readonly Seeder<TContext, string, unknown, string>[], const TOptions extends RunSeedersOptions<SeederName<TSeeders[number]>> | undefined = undefined>(seeders: TSeeders & ValidateSeeders<TSeeders>, options?: TOptions) => Promise<RunSeedersResult<TSeeders, TOptions>>;
115
131
  /**
116
132
  * Run seeders as a CLI command: parses the arguments, runs, and exits with 0 or 1.
117
133
  * Seeder names (positional or `--only a,b`) select seeders plus their dependencies;
118
- * `--fresh`, `--continue-on-failure`, `--allow-remote`, `--dry-run` and `--help` map
119
- * to the runner options. Unknown flags and names exit 1.
134
+ * `--fresh`, `--concurrency`, `--continue-on-failure`, `--allow-remote`, `--quiet`,
135
+ * `--dry-run`, `--list`, and `--help` map to the runner options. Unknown flags and names exit 1.
120
136
  *
121
137
  * @example
122
138
  * ```typescript
@@ -126,11 +142,7 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
126
142
  * }
127
143
  * ```
128
144
  */
129
- runSeedersCli: (seeders: readonly SeederAny[], options?: {
130
- name?: string;
131
- /** Arguments to parse (default: `process.argv.slice(2)`) */
132
- argv?: readonly string[];
133
- }) => Promise<void>;
145
+ runSeedersCli: <const TSeeders extends readonly Seeder<TContext, string, unknown, string>[]>(seeders: TSeeders & ValidateSeeders<TSeeders>, options?: RunSeedersCliOptions) => Promise<void>;
134
146
  /**
135
147
  * Check if seeding is currently active.
136
148
  * Use this in your application to skip side effects during seeding.
@@ -145,40 +157,5 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
145
157
  */
146
158
  isSeedingActive: () => boolean;
147
159
  };
148
- /**
149
- * Create a seeder instance with a custom context
150
- *
151
- * This is the main entry point for the seeder library. The library provides
152
- * a base context with faker, step, and expect. Consumers extend this with
153
- * their own context (e.g. prisma, custom helpers).
154
- *
155
- * The seeding state is automatically managed - set to active when runSeeders
156
- * starts and set to inactive when it completes.
157
- *
158
- * @example
159
- * ```typescript
160
- * import { createSeederInstance } from 'plantr'
161
- *
162
- * type MyContext = BaseSeederContext & { prisma: typeof prisma }
163
- *
164
- * const { defineSeeder, runSeeders, isSeedingActive } = createSeederInstance<MyContext>({
165
- * context: (base) => ({
166
- * ...base,
167
- * prisma,
168
- * }),
169
- * target: () => process.env.DATABASE_URL,
170
- * })
171
- *
172
- * export { defineSeeder, isSeedingActive }
173
- *
174
- * // In your message/queue system:
175
- * if (isSeedingActive()) {
176
- * console.log('Skipping side effect during seeding')
177
- * return
178
- * }
179
- *
180
- * // Later...
181
- * await runSeeders([seeder1, seeder2])
182
- * ```
183
- */
184
- export declare function createSeederInstance<TContext extends BaseSeederContext = BaseSeederContext>(config: SeederInstanceConfig<TContext>): SeederInstance<TContext>;
160
+ export declare function createSeederInstance<TExtra extends object = Record<never, never>>(config?: SeederInstanceConfig<TExtra>): SeederInstance<ResolvedContext<TExtra>>;
161
+ //# sourceMappingURL=create-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D;;;;;;;;;;;;;OAaG;IACH,aAAa,EAAE,CAAC,KAAK,CAAC,QAAQ,SAAS,SAAS,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,EAC1F,OAAO,EAAE,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,EAC7C,OAAO,CAAC,EAAE,oBAAoB,KAC1B,OAAO,CAAC,IAAI,CAAC,CAAA;IAElB;;;;;;;;;;;OAWG;IACH,eAAe,EAAE,MAAM,OAAO,CAAA;CAC9B,CAAA;AAuCD,wBAAgB,oBAAoB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAChF,MAAM,CAAC,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACnC,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CA0IzC"}
@@ -1,6 +1,6 @@
1
- import type { Seeder, SeederAny, SeederConfig } from './types';
1
+ import type { Seeder, SeederConfig, SeederName } from './types.js';
2
2
  /**
3
- * Create a typed seeder definition
3
+ * Create a typed seeder definition factory bound to `TContext`.
4
4
  *
5
5
  * This is the core factory that creates a seeder from a configuration.
6
6
  * The seeder can then be passed to `runSeeders` for execution.
@@ -25,4 +25,5 @@ import type { Seeder, SeederAny, SeederConfig } from './types';
25
25
  * })
26
26
  * ```
27
27
  */
28
- export declare function createDefineSeeder<TContext>(): <TName extends string, TOutput, const TDeps extends readonly SeederAny[] = readonly []>(config: SeederConfig<TContext, TName, TOutput, TDeps>) => Seeder<TContext, TName, TOutput>;
28
+ export declare function createDefineSeeder<TContext>(): <TName extends string, TOutput, const TDeps extends readonly Seeder<TContext, string, unknown, string>[] = readonly []>(config: SeederConfig<TContext, TName, TOutput, TDeps>) => Seeder<TContext, TName, Awaited<TOutput>, SeederName<TDeps[number]>>;
29
+ //# sourceMappingURL=define-seeder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-seeder.d.ts","sourceRoot":"","sources":["../../src/define-seeder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,MAEzC,KAAK,SAAS,MAAM,EACpB,OAAO,EACP,KAAK,CAAC,KAAK,SAAS,SAAS,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,GAAG,SAAS,EAAE,EAEtF,QAAQ,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,KACnD,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAiBvE"}
@@ -1,4 +1,4 @@
1
- import type { SeederAny } from './types';
1
+ import type { SeederAny } from './types.js';
2
2
  /**
3
3
  * Error thrown when circular dependencies are detected in seeders
4
4
  */
@@ -36,3 +36,4 @@ export declare class UnknownSeederError extends Error {
36
36
  * @throws {MissingDependencyError} If a seeder depends on a non-existent seeder
37
37
  */
38
38
  export declare function resolveDependencyOrder(seeders: readonly SeederAny[], only?: readonly string[]): string[];
39
+ //# sourceMappingURL=dependency-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-resolver.d.ts","sourceRoot":"","sources":["../../src/dependency-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,KAAK,EAAE,MAAM,EAAE;CAI3B;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACpC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAI9C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBAClC,IAAI,EAAE,MAAM;CAIxB;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE;CAIlD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GACtB,MAAM,EAAE,CA6EV"}
@@ -1,8 +1,9 @@
1
- import type { SeederResult } from './types';
2
- type ColorName = 'red' | 'green' | 'yellow' | 'cyan' | 'white' | 'gray' | 'dim';
3
- type StyleName = 'bold' | 'dim';
1
+ import type { SeederResult } from './types.js';
2
+ export type ColorName = 'red' | 'green' | 'yellow' | 'cyan' | 'white' | 'gray' | 'dim';
3
+ export type StyleName = 'bold' | 'dim';
4
4
  /**
5
- * Simple colorize function for terminal output
5
+ * Simple colorize function for terminal output.
6
+ * Respects `NO_COLOR`, `FORCE_COLOR`, and stdout TTY state.
6
7
  */
7
8
  export declare function colorize(text: string, color: ColorName, style?: StyleName): string;
8
9
  /**
@@ -12,34 +13,47 @@ export declare function formatDuration(ms: number): string;
12
13
  /**
13
14
  * Print a formatted table of seeder results
14
15
  */
15
- export declare function printResultsTable(results: SeederResult[]): void;
16
+ export declare function printResultsTable(results: readonly SeederResult[]): void;
16
17
  /**
17
18
  * Print error details for failed seeders: the failing step, the full error (message,
18
19
  * stack, cause and own fields via Bun.inspect) and a hint when cached steps ran first.
19
20
  * Under GitHub Actions, also prints one `::error` annotation per failed seeder.
20
21
  */
21
- export declare function printErrors(results: SeederResult[]): void;
22
+ export declare function printErrors(results: readonly SeederResult[]): void;
22
23
  /**
23
24
  * Print seeder header before execution
24
25
  */
25
26
  export declare function printSeederHeader(name: string, index: number, total: number, description?: string): void;
26
27
  /**
27
- * Print completion status after a seeder runs
28
+ * Print completion status after a seeder runs (sequential mode)
28
29
  */
29
30
  export declare function printSeederComplete(durationMs: number, success: boolean): void;
31
+ /**
32
+ * Print compact prefixed completion status (concurrent mode)
33
+ */
34
+ export declare function printConcurrentComplete(seederName: string, durationMs: number, success: boolean): void;
35
+ /**
36
+ * Print compact prefixed skip status (concurrent mode)
37
+ */
38
+ export declare function printConcurrentSkipped(seederName: string, failedDeps: readonly string[]): void;
30
39
  /**
31
40
  * Print the initial banner when seeding starts
32
41
  */
33
- export declare function printStartBanner(target?: {
34
- label: string;
35
- local: boolean;
42
+ export declare function printStartBanner(options?: {
43
+ name?: string | undefined;
44
+ count?: number | undefined;
45
+ target?: {
46
+ label: string;
47
+ local: boolean;
48
+ } | undefined;
49
+ concurrency?: number | undefined;
36
50
  }): void;
37
51
  /**
38
52
  * Print message when a seeder is skipped due to failed dependencies
39
53
  */
40
- export declare function printSeederSkipped(failedDeps: string[]): void;
54
+ export declare function printSeederSkipped(failedDeps: readonly string[]): void;
41
55
  /**
42
56
  * Print the final summary after all seeders complete
43
57
  */
44
- export declare function printSummary(results: SeederResult[]): void;
45
- export {};
58
+ export declare function printSummary(results: readonly SeederResult[], totalDurationMs?: number, concurrency?: number): void;
59
+ //# sourceMappingURL=formatting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAiB9C,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAA;AACtF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,CAAA;AAQtC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,MAAM,CAOlF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,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AI,GACb,IAAI,CAsDN"}
@@ -0,0 +1,12 @@
1
+ import type { Faker } from '@faker-js/faker';
2
+ /**
3
+ * Synchronously load the default English Faker instance on first access.
4
+ * Defers the ~35ms locale initialization cost until a seeder actually uses `faker`.
5
+ */
6
+ export declare function getDefaultFaker(): Faker;
7
+ /**
8
+ * Lazy proxy for the default English Faker instance.
9
+ * Importing `plantr` does not pay the faker load cost until a property is accessed.
10
+ */
11
+ export declare const lazyFaker: Faker;
12
+ //# sourceMappingURL=lazy-faker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-faker.d.ts","sourceRoot":"","sources":["../../src/lazy-faker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAI5C;;;GAGG;AACH,wBAAgB,eAAe,IAAI,KAAK,CAOvC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,KAuBtB,CAAA"}
@@ -1,22 +1,44 @@
1
- import type { StepRecord } from './step';
2
- import type { RunSeedersOptions, SeederAny, SeederResult } from './types';
1
+ import type { StepRecord } from './step.js';
2
+ import type { MaybePromise, RunSeedersOptions, RunSeedersResult, SeederAny } from './types.js';
3
+ /** Parsed description of a database target URL (without credentials) */
4
+ export type TargetDescription = {
5
+ label: string;
6
+ local: boolean;
7
+ };
8
+ /** Per-seeder scope handle returned by `InternalSeederConfig.runSeederScope` */
9
+ export type SeederScopeHandle = {
10
+ record?: StepRecord | undefined;
11
+ run: <T>(fn: () => Promise<T>) => Promise<T>;
12
+ };
3
13
  /**
4
14
  * Internal configuration used by the runner.
5
- * This is created by createSeederInstance and includes the wrapped context factory.
15
+ * This is created by `createSeederInstance` and includes the wrapped context factory.
6
16
  */
7
17
  export type InternalSeederConfig<TContext> = {
8
18
  /** Factory function that creates the full context; called once, after onBeforeAll */
9
- context: () => TContext | Promise<TContext>;
10
- /** Called before each seeder runs (cache scoping); may return the record its steps fill */
11
- beforeSeeder?: (name: string, options: {
19
+ context: () => MaybePromise<TContext>;
20
+ /** Called once after onBeforeAll to preload step cache entries (when cache.getAll is configured) */
21
+ preloadCache?: (() => MaybePromise<void>) | undefined;
22
+ /** Called once before onAfterAll to flush buffered step cache writes (when cache.setMany is configured) */
23
+ flushCache?: (() => MaybePromise<void>) | undefined;
24
+ /** Called before each seeder runs (legacy sequential hook); may return the record its steps fill */
25
+ beforeSeeder?: ((name: string, options: {
12
26
  fresh: boolean;
13
- }) => StepRecord | undefined;
27
+ }) => StepRecord | undefined) | undefined;
28
+ /** Concurrency-safe scope wrapper for running a seeder (used by createSeederInstance) */
29
+ createSeederScope?: ((options: {
30
+ name: string;
31
+ fresh: boolean;
32
+ concurrent: boolean;
33
+ }) => SeederScopeHandle) | undefined;
34
+ /** Banner title (default: `'Seeders'`) */
35
+ bannerName?: string | undefined;
14
36
  /** Database URL the run writes to; non-local hosts are refused unless allowRemote */
15
- target?: () => string | undefined;
37
+ target?: (() => string | undefined) | undefined;
16
38
  /** Called before the context is created */
17
- onBeforeAll?: () => void | Promise<void>;
39
+ onBeforeAll?: (() => MaybePromise<void>) | undefined;
18
40
  /** Called after all seeders complete, also when a seeder or the context factory throws */
19
- onAfterAll?: () => void | Promise<void>;
41
+ onAfterAll?: ((ctx: TContext | undefined) => MaybePromise<void>) | undefined;
20
42
  };
21
43
  /**
22
44
  * Error thrown when a run would write to a database that is not local
@@ -31,20 +53,15 @@ export declare class SeedTargetError extends Error {
31
53
  * URL's host, as libpq does. Hand-parsed so driver formats `URL` rejects still work
32
54
  * (several hosts, `sqlserver://host;key=value`, sockets with credentials).
33
55
  */
34
- export declare function describeTarget(target: string): {
35
- label: string;
36
- local: boolean;
37
- };
56
+ export declare function describeTarget(target: string): TargetDescription;
38
57
  /**
39
- * Core seeder runner - executes seeders in dependency order
58
+ * Core seeder runner - executes seeders in dependency order (sequentially or in parallel)
40
59
  *
41
60
  * @param seeders - Array of seeders to run
42
61
  * @param config - Instance configuration (context factory, lifecycle hooks)
43
- * @param options - Runner options (verbose output, etc.)
44
- * @returns Object containing results and success status
45
- * @throws Dependency errors, `UnknownSeederError` and `SeedTargetError`, before any hook runs
62
+ * @param options - Runner options (verbose output, concurrency, etc.)
63
+ * @returns Object containing `success`, `results`, and `outputs`
64
+ * @throws Dependency errors, `UnknownSeederError`, `SeedTargetError`, or `RangeError` (invalid concurrency), before any hook runs
46
65
  */
47
- export declare function runSeedersCore<TContext>(seeders: readonly SeederAny[], config: InternalSeederConfig<TContext>, options?: RunSeedersOptions): Promise<{
48
- results: SeederResult[];
49
- success: boolean;
50
- }>;
66
+ export declare function runSeedersCore<TContext, const TSeeders extends readonly SeederAny[] = readonly SeederAny[], const TOptions extends RunSeedersOptions = RunSeedersOptions>(seeders: TSeeders, config: InternalSeederConfig<TContext>, options?: TOptions): Promise<RunSeedersResult<TSeeders, TOptions>>;
67
+ //# sourceMappingURL=run-seeders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-seeders.d.ts","sourceRoot":"","sources":["../../src/run-seeders.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EACX,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EAGT,MAAM,YAAY,CAAA;AAEnB,wEAAwE;AACxE,MAAM,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;CACd,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,iBAAiB,GAAG;IAC/B,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;IAC/B,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CAC5C,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,IAAI;IAC5C,qFAAqF;IACrF,OAAO,EAAE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ACR,KAAK,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,GAAG,SAAS,SAAS,EAAE,EAClE,KAAK,CAAC,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB,EAE5D,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EACtC,OAAO,GAAE,QAAyB,GAChC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CA4U/C"}
@@ -8,15 +8,26 @@
8
8
  * - Syncing to external services
9
9
  *
10
10
  * The flag lives on `globalThis`, so `plantr` and `plantr/state` share it even when
11
- * they are loaded as separate bundles. It is one flag per process, shared by every
12
- * seeder instance.
11
+ * they are loaded as separate bundles. Overlapping runs are reference-counted so
12
+ * one finishing run does not clear the flag while another is still active.
13
13
  */
14
14
  /**
15
15
  * Check if seeding is currently active
16
16
  */
17
17
  export declare function isSeedingActive(): boolean;
18
18
  /**
19
- * Set the seeding state.
20
- * Called automatically by `runSeeders` around a run.
19
+ * Set the seeding state directly.
20
+ * Resets the active run count to 1 (true) or 0 (false).
21
21
  */
22
22
  export declare function setSeedingActive(active: boolean): void;
23
+ /**
24
+ * Increment the active seeding run counter and mark seeding active.
25
+ * Called automatically by `runSeeders` when execution begins.
26
+ */
27
+ export declare function enterSeeding(): void;
28
+ /**
29
+ * Decrement the active seeding run counter and clear the flag when no runs remain.
30
+ * Called automatically by `runSeeders` when execution finishes.
31
+ */
32
+ export declare function exitSeeding(): void;
33
+ //# sourceMappingURL=seeding-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeding-state.d.ts","sourceRoot":"","sources":["../../src/seeding-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAGtD;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAInC;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAIlC"}