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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +23 -20
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +906 -235
  5. package/dist/src/cli.d.ts +23 -0
  6. package/dist/src/cli.d.ts.map +1 -0
  7. package/dist/src/create-seeder-instance.d.ts +73 -83
  8. package/dist/src/create-seeder-instance.d.ts.map +1 -0
  9. package/dist/src/define-seeder.d.ts +4 -3
  10. package/dist/src/define-seeder.d.ts.map +1 -0
  11. package/dist/src/dependency-resolver.d.ts +18 -2
  12. package/dist/src/dependency-resolver.d.ts.map +1 -0
  13. package/dist/src/formatting.d.ts +31 -12
  14. package/dist/src/formatting.d.ts.map +1 -0
  15. package/dist/src/lazy-faker.d.ts +12 -0
  16. package/dist/src/lazy-faker.d.ts.map +1 -0
  17. package/dist/src/run-seeders.d.ts +57 -17
  18. package/dist/src/run-seeders.d.ts.map +1 -0
  19. package/dist/src/seeding-state.d.ts +17 -2
  20. package/dist/src/seeding-state.d.ts.map +1 -0
  21. package/dist/src/step.d.ts +97 -15
  22. package/dist/src/step.d.ts.map +1 -0
  23. package/dist/src/types.d.ts +132 -29
  24. package/dist/src/types.d.ts.map +1 -0
  25. package/dist/state.d.ts +12 -0
  26. package/dist/state.d.ts.map +1 -0
  27. package/dist/state.js +20 -0
  28. package/index.ts +60 -24
  29. package/package.json +20 -10
  30. package/readme.md +169 -49
  31. package/src/cli.ts +251 -0
  32. package/src/create-seeder-instance.ts +254 -173
  33. package/src/define-seeder.ts +14 -7
  34. package/src/dependency-resolver.ts +59 -30
  35. package/src/formatting.ts +142 -39
  36. package/src/lazy-faker.ts +46 -0
  37. package/src/run-seeders.ts +413 -123
  38. package/src/seeding-state.ts +32 -5
  39. package/src/step.ts +247 -46
  40. package/src/types.ts +184 -32
  41. package/state.ts +11 -0
  42. package/dist/cli.d.ts +0 -17
  43. package/dist/cli.js +0 -59
  44. package/dist/index-a1s5r901.js +0 -4
@@ -0,0 +1,23 @@
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<{
10
+ success: boolean;
11
+ }>;
12
+ /**
13
+ * Parse CLI arguments, run the seeders and return the exit code.
14
+ * Unknown flags and unknown seeder names return 1.
15
+ */
16
+ export declare function runCli(seeders: readonly SeederAny[], runSeeders: CliRunner, { argv, target, defaultConcurrency, }: {
17
+ name: string;
18
+ argv: readonly string[];
19
+ target?: (() => string | undefined) | undefined;
20
+ defaultConcurrency?: number | undefined;
21
+ }): Promise<number>;
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,45 +1,72 @@
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
- * await prisma.seedCache.create({ data: { key, output: value } })
35
- * }
36
+ * const output = value as Prisma.InputJsonValue
37
+ * await prisma.seedCache.upsert({ where: { key }, create: { key, output }, update: { output } })
38
+ * },
36
39
  * }
37
40
  * ```
38
41
  */
39
- 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;
40
49
  /**
41
- * Called before all seeders run.
42
- * Use for setup like connecting to databases.
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;
54
+ /**
55
+ * Optional: the database URL this instance writes to, e.g. `() => process.env.DATABASE_URL`.
56
+ * The banner prints its host and database (never credentials), and a run refuses a
57
+ * host that is not local unless it passes `allowRemote` (CLI: `--allow-remote`).
58
+ * Return undefined to skip the check.
59
+ */
60
+ target?: (() => string | undefined) | undefined;
61
+ /**
62
+ * Optional: seed faker before each seeder with this number plus a hash of the
63
+ * seeder's name, so every run generates the same data and adding a seeder does
64
+ * not shift the others'. Works safely with parallel `concurrency` via isolated Faker instances.
65
+ */
66
+ fakerSeed?: number | undefined;
67
+ /**
68
+ * Called before all seeders run, before the context factory.
69
+ * Use for setup like connecting to databases, or to refuse a run.
43
70
  *
44
71
  * @example
45
72
  * ```typescript
@@ -48,9 +75,10 @@ export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
48
75
  * }
49
76
  * ```
50
77
  */
51
- onBeforeAll?: () => void | Promise<void>;
78
+ onBeforeAll?: (() => MaybePromise<void>) | undefined;
52
79
  /**
53
- * Called after all seeders complete (success or failure).
80
+ * Called after all seeders complete (success or failure), also when the context
81
+ * factory throws. Receives the created context (or `undefined` if the context factory threw).
54
82
  * Use for cleanup like disconnecting from databases.
55
83
  *
56
84
  * @example
@@ -60,14 +88,15 @@ export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
60
88
  * }
61
89
  * ```
62
90
  */
63
- onAfterAll?: () => void | Promise<void>;
91
+ onAfterAll?: ((ctx: NoInfer<ResolvedContext<TExtra>> | undefined) => MaybePromise<void>) | undefined;
64
92
  };
65
93
  /**
66
94
  * Result type for the seeder instance
67
95
  */
68
- export type SeederInstance<TContext extends BaseSeederContext> = {
96
+ export type SeederInstance<TContext extends object = BaseSeederContext> = {
69
97
  /**
70
- * 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.
71
100
  *
72
101
  * @example
73
102
  * ```typescript
@@ -82,22 +111,28 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
82
111
  * })
83
112
  * ```
84
113
  */
85
- 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]>>;
86
115
  /**
87
116
  * Run an array of seeders in dependency order.
88
117
  * Automatically sets seeding state to active during execution.
89
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
+ *
90
124
  * @param seeders - Array of seeders to run
91
125
  * @param options - Optional runner options
92
- * @returns Object containing results and success status
126
+ * @returns Object containing `success`, typed `results`, and typed `outputs`
127
+ * @throws Before anything runs, on an invalid registry (duplicate name, missing
128
+ * dependency, cycle), an unknown name in `only`/`fresh`, invalid `concurrency`, or a refused `target`
93
129
  */
94
- runSeeders: (seeders: readonly SeederAny[], options?: RunSeedersOptions) => Promise<{
95
- results: SeederResult[];
96
- success: boolean;
97
- }>;
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>>;
98
131
  /**
99
- * Run seeders as a CLI command.
100
- * Handles help flag, prints banner, runs seeders, and exits with proper code.
132
+ * Run seeders as a CLI command: parses the arguments, runs, and exits with 0 or 1.
133
+ * Seeder names (positional or `--only a,b`) select seeders plus their dependencies;
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.
101
136
  *
102
137
  * @example
103
138
  * ```typescript
@@ -107,9 +142,7 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
107
142
  * }
108
143
  * ```
109
144
  */
110
- runSeedersCli: (seeders: readonly SeederAny[], options?: {
111
- name?: string;
112
- }) => Promise<void>;
145
+ runSeedersCli: <const TSeeders extends readonly Seeder<TContext, string, unknown, string>[]>(seeders: TSeeders & ValidateSeeders<TSeeders>, options?: RunSeedersCliOptions) => Promise<void>;
113
146
  /**
114
147
  * Check if seeding is currently active.
115
148
  * Use this in your application to skip side effects during seeding.
@@ -124,48 +157,5 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
124
157
  */
125
158
  isSeedingActive: () => boolean;
126
159
  };
127
- /**
128
- * Create a seeder instance with a custom context
129
- *
130
- * This is the main entry point for the seeder library. The library provides
131
- * a base context with faker, step, and expect. Consumers extend this with
132
- * their own context (e.g. prisma, custom helpers).
133
- *
134
- * The seeding state is automatically managed - set to active when runSeeders
135
- * starts and set to inactive when it completes.
136
- *
137
- * @example
138
- * ```typescript
139
- * import { createSeederInstance } from 'plantr'
140
- *
141
- * type MyContext = BaseSeederContext & { prisma: typeof prisma }
142
- *
143
- * const { defineSeeder, runSeeders, isSeedingActive } = createSeederInstance<MyContext>({
144
- * context: (base) => ({
145
- * ...base,
146
- * prisma,
147
- * }),
148
- * cache: {
149
- * get: async (key) => {
150
- * const cached = await prisma.seedCache.findUnique({ where: { key } })
151
- * return cached?.output
152
- * },
153
- * set: async (key, value) => {
154
- * await prisma.seedCache.create({ data: { key, output: value } })
155
- * }
156
- * },
157
- * })
158
- *
159
- * export { defineSeeder, isSeedingActive }
160
- *
161
- * // In your message/queue system:
162
- * if (isSeedingActive()) {
163
- * console.log('Skipping side effect during seeding')
164
- * return
165
- * }
166
- *
167
- * // Later...
168
- * await runSeeders([seeder1, seeder2])
169
- * ```
170
- */
171
- 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-seeder-instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create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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
  */
@@ -11,13 +11,29 @@ export declare class CircularDependencyError extends Error {
11
11
  export declare class MissingDependencyError extends Error {
12
12
  constructor(seeder: string, missingDep: string);
13
13
  }
14
+ /**
15
+ * Error thrown when two seeders share a name
16
+ */
17
+ export declare class DuplicateSeederError extends Error {
18
+ constructor(name: string);
19
+ }
20
+ /**
21
+ * Error thrown when a seeder is selected by a name that is not registered
22
+ */
23
+ export declare class UnknownSeederError extends Error {
24
+ constructor(name: string, known: readonly string[]);
25
+ }
14
26
  /**
15
27
  * Resolves the execution order of seeders based on their dependencies
16
28
  * using Kahn's algorithm (topological sort)
17
29
  *
18
30
  * @param seeders - Array of seeders to sort
31
+ * @param only - Optional names to select: returns them and everything they depend on
19
32
  * @returns Array of seeder names in execution order
33
+ * @throws {DuplicateSeederError} If two seeders share a name
34
+ * @throws {UnknownSeederError} If a name in `only` is not registered
20
35
  * @throws {CircularDependencyError} If circular dependencies are detected
21
36
  * @throws {MissingDependencyError} If a seeder depends on a non-existent seeder
22
37
  */
23
- export declare function resolveDependencyOrder(seeders: readonly SeederAny[]): string[];
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,29 +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
- * Print error details for failed seeders
18
+ * Print error details for failed seeders: the failing step, the full error (message,
19
+ * stack, cause and own fields via Bun.inspect) and a hint when cached steps ran first.
20
+ * Under GitHub Actions, also prints one `::error` annotation per failed seeder.
18
21
  */
19
- export declare function printErrors(results: SeederResult[]): void;
22
+ export declare function printErrors(results: readonly SeederResult[]): void;
20
23
  /**
21
24
  * Print seeder header before execution
22
25
  */
23
26
  export declare function printSeederHeader(name: string, index: number, total: number, description?: string): void;
24
27
  /**
25
- * Print completion status after a seeder runs
28
+ * Print completion status after a seeder runs (sequential mode)
26
29
  */
27
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;
28
39
  /**
29
40
  * Print the initial banner when seeding starts
30
41
  */
31
- export declare function printStartBanner(label?: string): void;
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;
50
+ }): void;
32
51
  /**
33
52
  * Print message when a seeder is skipped due to failed dependencies
34
53
  */
35
- export declare function printSeederSkipped(failedDeps: string[]): void;
54
+ export declare function printSeederSkipped(failedDeps: readonly string[]): void;
36
55
  /**
37
56
  * Print the final summary after all seeders complete
38
57
  */
39
- export declare function printSummary(results: SeederResult[]): void;
40
- export {};
58
+ export declare function printSummary(results: readonly SeederResult[], totalDurationMs?: number, concurrency?: number): void;
59
+ //# sourceMapp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B,gBAAgB,CAAC,OAAO,CAAC,EAAE;IAC1C,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAA;IACtD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAChC,GAAG,IAAI,CAWP;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAItE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,eAAe,CAAC,EAAE,MAAM,EACxB,WAAW,SAAI,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,27 +1,67 @@
1
- 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
+ };
2
13
  /**
3
14
  * Internal configuration used by the runner.
4
- * This is created by createSeederInstance and includes the wrapped context factory.
15
+ * This is created by `createSeederInstance` and includes the wrapped context factory.
5
16
  */
6
17
  export type InternalSeederConfig<TContext> = {
7
- /** Factory function that creates the full context (already includes base context) */
8
- context: () => TContext | Promise<TContext>;
9
- /** Called before each seeder to set the current seeder name (for cache key scoping) */
10
- setSeederName?: (name: string) => void;
11
- /** Called before all seeders run */
12
- onBeforeAll?: () => void | Promise<void>;
13
- /** Called after all seeders complete */
14
- onAfterAll?: () => void | Promise<void>;
18
+ /** Factory function that creates the full context; called once, after onBeforeAll */
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: {
26
+ fresh: boolean;
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;
36
+ /** Database URL the run writes to; non-local hosts are refused unless allowRemote */
37
+ target?: (() => string | undefined) | undefined;
38
+ /** Called before the context is created */
39
+ onBeforeAll?: (() => MaybePromise<void>) | undefined;
40
+ /** Called after all seeders complete, also when a seeder or the context factory throws */
41
+ onAfterAll?: ((ctx: TContext | undefined) => MaybePromise<void>) | undefined;
15
42
  };
16
43
  /**
17
- * Core seeder runner - executes seeders in dependency order
44
+ * Error thrown when a run would write to a database that is not local
45
+ */
46
+ export declare class SeedTargetError extends Error {
47
+ constructor(label: string);
48
+ }
49
+ /**
50
+ * Describe a database URL without its credentials and say whether every host it names
51
+ * is local: loopback, `*.localhost`, `host.docker.internal`, a socket or `file:` path,
52
+ * or a name without a dot (a compose service). A `host=` parameter overrides the
53
+ * URL's host, as libpq does. Hand-parsed so driver formats `URL` rejects still work
54
+ * (several hosts, `sqlserver://host;key=value`, sockets with credentials).
55
+ */
56
+ export declare function describeTarget(target: string): TargetDescription;
57
+ /**
58
+ * Core seeder runner - executes seeders in dependency order (sequentially or in parallel)
18
59
  *
19
60
  * @param seeders - Array of seeders to run
20
61
  * @param config - Instance configuration (context factory, lifecycle hooks)
21
- * @param options - Runner options (verbose output, etc.)
22
- * @returns Object containing results and success status
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
23
65
  */
24
- export declare function runSeedersCore<TContext>(seeders: readonly SeederAny[], config: InternalSeederConfig<TContext>, options?: RunSeedersOptions): Promise<{
25
- results: SeederResult[];
26
- success: boolean;
27
- }>;
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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;IACrF,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAC/C,2CAA2C;IAC3C,WAAW,CAAC,EAAE,CAAC,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;IACpD,0FAA0F;IAC1F,UAAU,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,GAAG,SAAS,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;CAC5E,CAAA;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC7B,KAAK,EAAE,MAAM;CAMzB;AAiBD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAwBhE;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CACnC,QAAQ,EACR,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"}
@@ -6,13 +6,28 @@
6
6
  * - Sending notifications (email, Slack, push)
7
7
  * - Creating background jobs
8
8
  * - Syncing to external services
9
+ *
10
+ * The flag lives on `globalThis`, so `plantr` and `plantr/state` share it even when
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.
9
13
  */
10
14
  /**
11
15
  * Check if seeding is currently active
12
16
  */
13
17
  export declare function isSeedingActive(): boolean;
14
18
  /**
15
- * Set the seeding state.
16
- * Called automatically by the seeder runner's onBeforeAll/onAfterAll hooks.
19
+ * Set the seeding state directly.
20
+ * Resets the active run count to 1 (true) or 0 (false).
17
21
  */
18
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"}