plantr 2.0.0 → 2.2.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/dist/index.d.ts +31 -25
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1050 -251
- package/dist/src/cli.d.ts +13 -3
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/create-seeder-instance.d.ts +64 -78
- 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 +2 -1
- package/dist/src/dependency-resolver.d.ts.map +1 -0
- package/dist/src/expect.d.ts +41 -0
- package/dist/src/expect.d.ts.map +1 -0
- package/dist/src/formatting.d.ts +36 -14
- 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 +46 -26
- package/dist/src/run-seeders.d.ts.map +1 -0
- package/dist/src/seeding-state.d.ts +15 -4
- package/dist/src/seeding-state.d.ts.map +1 -0
- package/dist/src/step.d.ts +79 -22
- package/dist/src/step.d.ts.map +1 -0
- package/dist/src/types.d.ts +121 -38
- package/dist/src/types.d.ts.map +1 -0
- package/dist/state.d.ts +2 -1
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +10 -2
- package/index.ts +70 -28
- package/package.json +5 -2
- package/readme.md +102 -52
- package/src/cli.ts +155 -22
- package/src/create-seeder-instance.ts +252 -111
- package/src/define-seeder.ts +14 -7
- package/src/dependency-resolver.ts +17 -28
- package/src/expect.ts +502 -0
- package/src/formatting.ts +142 -37
- package/src/lazy-faker.ts +46 -0
- package/src/run-seeders.ts +352 -122
- package/src/seeding-state.ts +27 -5
- package/src/step.ts +208 -64
- package/src/types.ts +173 -41
- package/state.ts +1 -1
package/dist/src/cli.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import type { RunSeedersOptions, SeederAny } from './types';
|
|
2
|
-
|
|
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:
|
|
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,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { Faker } from '@faker-js/faker';
|
|
2
|
+
import { type RunSeedersCliOptions } from './cli.js';
|
|
3
|
+
import { type AnyExpectFn, type ExpectFn } from './expect.js';
|
|
4
|
+
import { type SeederCache } from './step.js';
|
|
5
|
+
import type { BaseSeederContext, MaybePromise, Prettify, RunSeedersOptions, RunSeedersResult, Seeder, SeederConfig, SeederName, ValidateSeeders } from './types.js';
|
|
6
|
+
/** Resolve the effective `expect` type from an optional `config.expect` type parameter */
|
|
7
|
+
export type ResolvedExpect<TExpect> = [Exclude<TExpect, undefined>] extends [never] ? ExpectFn : [AnyExpectFn] extends [Exclude<TExpect, undefined>] ? ExpectFn : undefined extends TExpect ? Exclude<TExpect, undefined> | ExpectFn : TExpect;
|
|
8
|
+
/**
|
|
9
|
+
* Full context type resolved from `BaseSeederContext` plus the extra properties
|
|
10
|
+
* returned by `config.context`. Any base key returned by `context` overrides the default.
|
|
11
|
+
*/
|
|
12
|
+
export type ResolvedContext<TExtra extends object = Record<never, never>, TExpect = ExpectFn> = Prettify<Omit<BaseSeederContext<ResolvedExpect<TExpect>>, keyof TExtra> & TExtra>;
|
|
3
13
|
/**
|
|
4
14
|
* Configuration for creating a seeder instance.
|
|
5
|
-
*
|
|
15
|
+
* `context` is optional and its returned properties are automatically merged onto `BaseSeederContext`.
|
|
6
16
|
*/
|
|
7
|
-
export type SeederInstanceConfig<
|
|
17
|
+
export type SeederInstanceConfig<TExtra extends object = Record<never, never>, TExpect extends AnyExpectFn | undefined = ExpectFn> = {
|
|
8
18
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
19
|
+
* Optional factory function that extends the base context (`faker`, `step`, `expect`).
|
|
20
|
+
* Returned properties are merged onto `base` automatically — no need to spread `...base`,
|
|
21
|
+
* though spreading or overriding keys (such as `faker`) also works.
|
|
22
|
+
* Called once per run, after `onBeforeAll`.
|
|
11
23
|
*
|
|
12
24
|
* @example
|
|
13
25
|
* ```typescript
|
|
14
|
-
* context: (
|
|
15
|
-
* ...base,
|
|
16
|
-
* prisma,
|
|
17
|
-
* myHelper: () => { ... }
|
|
18
|
-
* })
|
|
26
|
+
* context: () => ({ prisma })
|
|
19
27
|
* ```
|
|
20
28
|
*/
|
|
21
|
-
context
|
|
29
|
+
context?: ((base: NoInfer<BaseSeederContext<ResolvedExpect<TExpect>>>) => MaybePromise<TExtra>) | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Optional: custom `expect` assertion function (for example Vitest's `expect`).
|
|
32
|
+
* Defaults to `bun:test`'s `expect` on Bun and a zero-dependency `node:assert/strict`
|
|
33
|
+
* implementation on Node.js.
|
|
34
|
+
*/
|
|
35
|
+
expect?: TExpect | undefined;
|
|
22
36
|
/**
|
|
23
37
|
* Optional cache for step caching.
|
|
24
|
-
* Provide get/set
|
|
38
|
+
* Provide `get` / `set` (and optionally `getAll` for single-query preloading).
|
|
25
39
|
*
|
|
26
40
|
* @example
|
|
27
41
|
* ```typescript
|
|
28
42
|
* cache: {
|
|
29
|
-
* get: async (key) => {
|
|
30
|
-
* const cached = await prisma.seedCache.findUnique({ where: { key } })
|
|
31
|
-
* return cached?.output as T | undefined
|
|
32
|
-
* },
|
|
43
|
+
* get: async (key) => (await prisma.seedCache.findUnique({ where: { key } }))?.output,
|
|
33
44
|
* set: async (key, value) => {
|
|
34
45
|
* const output = value as Prisma.InputJsonValue
|
|
35
46
|
* await prisma.seedCache.upsert({ where: { key }, create: { key, output }, update: { output } })
|
|
36
|
-
* }
|
|
47
|
+
* },
|
|
37
48
|
* }
|
|
38
49
|
* ```
|
|
39
50
|
*/
|
|
40
|
-
cache?: SeederCache;
|
|
51
|
+
cache?: SeederCache | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Optional: default maximum number of independent seeders to run concurrently (default: 1).
|
|
54
|
+
* Applies to both `runSeeders` and `runSeedersCli` unless overridden per run or via `--concurrency`.
|
|
55
|
+
* Set to a positive integer (e.g. `4`) or `Infinity` to run independent DAG branches in parallel.
|
|
56
|
+
*/
|
|
57
|
+
concurrency?: number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Optional: custom `Faker` instance (e.g. a non-English locale like `fakerDE` or `fakerNB_NO`).
|
|
60
|
+
* Defaults to the lazy-loaded English locale (`@faker-js/faker/locale/en`).
|
|
61
|
+
*/
|
|
62
|
+
faker?: Faker | undefined;
|
|
41
63
|
/**
|
|
42
64
|
* Optional: the database URL this instance writes to, e.g. `() => process.env.DATABASE_URL`.
|
|
43
65
|
* The banner prints its host and database (never credentials), and a run refuses a
|
|
44
66
|
* host that is not local unless it passes `allowRemote` (CLI: `--allow-remote`).
|
|
45
67
|
* Return undefined to skip the check.
|
|
46
68
|
*/
|
|
47
|
-
target?: () => string | undefined;
|
|
69
|
+
target?: (() => string | undefined) | undefined;
|
|
48
70
|
/**
|
|
49
71
|
* Optional: seed faker before each seeder with this number plus a hash of the
|
|
50
72
|
* seeder's name, so every run generates the same data and adding a seeder does
|
|
51
|
-
* not shift the others'.
|
|
73
|
+
* not shift the others'. Works safely with parallel `concurrency` via isolated Faker instances.
|
|
52
74
|
*/
|
|
53
|
-
fakerSeed?: number;
|
|
75
|
+
fakerSeed?: number | undefined;
|
|
54
76
|
/**
|
|
55
77
|
* Called before all seeders run, before the context factory.
|
|
56
78
|
* Use for setup like connecting to databases, or to refuse a run.
|
|
@@ -62,10 +84,10 @@ export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
|
|
|
62
84
|
* }
|
|
63
85
|
* ```
|
|
64
86
|
*/
|
|
65
|
-
onBeforeAll?: () => void |
|
|
87
|
+
onBeforeAll?: (() => MaybePromise<void>) | undefined;
|
|
66
88
|
/**
|
|
67
89
|
* Called after all seeders complete (success or failure), also when the context
|
|
68
|
-
* factory throws.
|
|
90
|
+
* factory throws. Receives the created context (or `undefined` if the context factory threw).
|
|
69
91
|
* Use for cleanup like disconnecting from databases.
|
|
70
92
|
*
|
|
71
93
|
* @example
|
|
@@ -75,14 +97,15 @@ export type SeederInstanceConfig<TContext extends BaseSeederContext> = {
|
|
|
75
97
|
* }
|
|
76
98
|
* ```
|
|
77
99
|
*/
|
|
78
|
-
onAfterAll?: () => void |
|
|
100
|
+
onAfterAll?: ((ctx: NoInfer<ResolvedContext<TExtra, TExpect>> | undefined) => MaybePromise<void>) | undefined;
|
|
79
101
|
};
|
|
80
102
|
/**
|
|
81
103
|
* Result type for the seeder instance
|
|
82
104
|
*/
|
|
83
|
-
export type SeederInstance<TContext extends BaseSeederContext> = {
|
|
105
|
+
export type SeederInstance<TContext extends object = BaseSeederContext> = {
|
|
84
106
|
/**
|
|
85
|
-
* Define a new seeder with typed dependencies
|
|
107
|
+
* Define a new seeder with typed dependencies.
|
|
108
|
+
* `dependsOn` only accepts seeders whose context is compatible with this instance.
|
|
86
109
|
*
|
|
87
110
|
* @example
|
|
88
111
|
* ```typescript
|
|
@@ -97,26 +120,28 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
|
|
|
97
120
|
* })
|
|
98
121
|
* ```
|
|
99
122
|
*/
|
|
100
|
-
defineSeeder: <TName extends string, TOutput, const TDeps extends readonly
|
|
123
|
+
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
124
|
/**
|
|
102
125
|
* Run an array of seeders in dependency order.
|
|
103
126
|
* Automatically sets seeding state to active during execution.
|
|
104
127
|
*
|
|
128
|
+
* - Enforces context compatibility across seeders at compile time
|
|
129
|
+
* - Flags missing dependencies at compile time when passing known seeders
|
|
130
|
+
* - Autocompletes and checks `only` and `fresh` against the registered seeder names
|
|
131
|
+
* - Returns strongly typed `outputs` and discriminated-union `results`
|
|
132
|
+
*
|
|
105
133
|
* @param seeders - Array of seeders to run
|
|
106
134
|
* @param options - Optional runner options
|
|
107
|
-
* @returns Object containing results and
|
|
135
|
+
* @returns Object containing `success`, typed `results`, and typed `outputs`
|
|
108
136
|
* @throws Before anything runs, on an invalid registry (duplicate name, missing
|
|
109
|
-
* dependency, cycle), an unknown name in `only`/`fresh`, or a refused `target`
|
|
137
|
+
* dependency, cycle), an unknown name in `only`/`fresh`, invalid `concurrency`, or a refused `target`
|
|
110
138
|
*/
|
|
111
|
-
runSeeders:
|
|
112
|
-
results: SeederResult[];
|
|
113
|
-
success: boolean;
|
|
114
|
-
}>;
|
|
139
|
+
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
140
|
/**
|
|
116
141
|
* Run seeders as a CLI command: parses the arguments, runs, and exits with 0 or 1.
|
|
117
142
|
* Seeder names (positional or `--only a,b`) select seeders plus their dependencies;
|
|
118
|
-
* `--fresh`, `--continue-on-failure`, `--allow-remote`, `--
|
|
119
|
-
* to the runner options. Unknown flags and names exit 1.
|
|
143
|
+
* `--fresh`, `--concurrency`, `--continue-on-failure`, `--allow-remote`, `--quiet`,
|
|
144
|
+
* `--dry-run`, `--list`, and `--help` map to the runner options. Unknown flags and names exit 1.
|
|
120
145
|
*
|
|
121
146
|
* @example
|
|
122
147
|
* ```typescript
|
|
@@ -126,11 +151,7 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
|
|
|
126
151
|
* }
|
|
127
152
|
* ```
|
|
128
153
|
*/
|
|
129
|
-
runSeedersCli:
|
|
130
|
-
name?: string;
|
|
131
|
-
/** Arguments to parse (default: `process.argv.slice(2)`) */
|
|
132
|
-
argv?: readonly string[];
|
|
133
|
-
}) => Promise<void>;
|
|
154
|
+
runSeedersCli: <const TSeeders extends readonly Seeder<TContext, string, unknown, string>[]>(seeders: TSeeders & ValidateSeeders<TSeeders>, options?: RunSeedersCliOptions) => Promise<void>;
|
|
134
155
|
/**
|
|
135
156
|
* Check if seeding is currently active.
|
|
136
157
|
* Use this in your application to skip side effects during seeding.
|
|
@@ -145,40 +166,5 @@ export type SeederInstance<TContext extends BaseSeederContext> = {
|
|
|
145
166
|
*/
|
|
146
167
|
isSeedingActive: () => boolean;
|
|
147
168
|
};
|
|
148
|
-
|
|
149
|
-
|
|
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>;
|
|
169
|
+
export declare function createSeederInstance<TExtra extends object = Record<never, never>, TExpect extends AnyExpectFn | undefined = ExpectFn>(config?: SeederInstanceConfig<TExtra, TExpect>): SeederInstance<ResolvedContext<TExtra, TExpect>>;
|
|
170
|
+
//# sourceMappingURL=create-seeder-instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-seeder-instance.d.ts","sourceRoot":"","sources":["../../src/create-seeder-instance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,KAAK,oBAAoB,EAAU,MAAM,UAAU,CAAA;AAE5D,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAoB,MAAM,aAAa,CAAA;AAI/E,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,KAAK,EACX,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,UAAU,EACV,eAAe,EACf,MAAM,YAAY,CAAA;AAEnB,0FAA0F;AAC1F,MAAM,MAAM,cAAc,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,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CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IAElD;;;;;;;;;;;;;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,CACnC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC5C,OAAO,SAAS,WAAW,GAAG,SAAS,GAAG,QAAQ,EAElD,MAAM,CAAC,EAAE,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5C,cAAc,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA2IlD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Seeder,
|
|
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
|
|
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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Constructor type accepted by `toThrow(...)` */
|
|
2
|
+
export type ErrorConstructor = abstract new (...args: any[]) => unknown;
|
|
3
|
+
/** Any callable assertion function accepted by `createSeederInstance({ expect })` */
|
|
4
|
+
export type AnyExpectFn = Function;
|
|
5
|
+
/**
|
|
6
|
+
* Portable assertion matchers supported across Bun (`bun:test`) and Node.js (built-in fallback).
|
|
7
|
+
* Compatible with `bun:test`, Vitest, and Jest `expect` implementations.
|
|
8
|
+
*/
|
|
9
|
+
export interface ExpectMatchers<T = unknown> {
|
|
10
|
+
readonly not: ExpectMatchers<unknown>;
|
|
11
|
+
toBe<E = T>(expected: E): void;
|
|
12
|
+
toEqual<E = T>(expected: E): void;
|
|
13
|
+
toStrictEqual<E = T>(expected: E): void;
|
|
14
|
+
toBeDefined(): void;
|
|
15
|
+
toBeUndefined(): void;
|
|
16
|
+
toBeNull(): void;
|
|
17
|
+
toBeTruthy(): void;
|
|
18
|
+
toBeFalsy(): void;
|
|
19
|
+
toContain(expected: unknown): void;
|
|
20
|
+
toHaveLength(length: number): void;
|
|
21
|
+
toMatch(expected: string | RegExp): void;
|
|
22
|
+
toBeGreaterThan(expected: number | bigint): void;
|
|
23
|
+
toBeGreaterThanOrEqual(expected: number | bigint): void;
|
|
24
|
+
toBeLessThan(expected: number | bigint): void;
|
|
25
|
+
toBeLessThanOrEqual(expected: number | bigint): void;
|
|
26
|
+
toThrow(expected?: string | RegExp | Error | ErrorConstructor): void;
|
|
27
|
+
}
|
|
28
|
+
/** Portable `expect` function signature available in `BaseSeederContext` */
|
|
29
|
+
export type ExpectFn = <T = unknown>(actual: T, message?: string) => ExpectMatchers<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a zero-dependency `expect` implementation backed by `node:assert/strict`.
|
|
32
|
+
* Used automatically on Node.js when no custom `expect` is passed to `createSeederInstance`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createNodeExpect(): ExpectFn;
|
|
35
|
+
/**
|
|
36
|
+
* Synchronously resolve the default `expect` function for the active runtime:
|
|
37
|
+
* `bun:test`'s `expect` on Bun, or the built-in `node:assert/strict` implementation on Node.js.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getDefaultExpect(): ExpectFn;
|
|
40
|
+
export declare const expect: ExpectFn;
|
|
41
|
+
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAIA,kDAAkD;AAElD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAA;AAEvE,qFAAqF;AAErF,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAA;AAElC;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IAC1C,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IACrC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ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/src/formatting.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
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';
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
3
|
+
* Runtime-safe value inspection: uses `Bun.inspect` on Bun and falls back to
|
|
4
|
+
* `node:util`'s `inspect` on Node.js.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inspectValue(value: unknown, options?: {
|
|
7
|
+
colors?: boolean;
|
|
8
|
+
}): string;
|
|
9
|
+
export type ColorName = 'red' | 'green' | 'yellow' | 'cyan' | 'white' | 'gray' | 'dim';
|
|
10
|
+
export type StyleName = 'bold' | 'dim';
|
|
11
|
+
/**
|
|
12
|
+
* Simple colorize function for terminal output.
|
|
13
|
+
* Respects `NO_COLOR`, `FORCE_COLOR`, and stdout TTY state.
|
|
6
14
|
*/
|
|
7
15
|
export declare function colorize(text: string, color: ColorName, style?: StyleName): string;
|
|
8
16
|
/**
|
|
@@ -12,34 +20,48 @@ export declare function formatDuration(ms: number): string;
|
|
|
12
20
|
/**
|
|
13
21
|
* Print a formatted table of seeder results
|
|
14
22
|
*/
|
|
15
|
-
export declare function printResultsTable(results: SeederResult[]): void;
|
|
23
|
+
export declare function printResultsTable(results: readonly SeederResult[]): void;
|
|
16
24
|
/**
|
|
17
25
|
* Print error details for failed seeders: the failing step, the full error (message,
|
|
18
|
-
* stack, cause and own fields via Bun.inspect
|
|
26
|
+
* stack, cause and own fields via Bun.inspect on Bun or util.inspect on Node.js) and
|
|
27
|
+
* a hint when cached steps ran first.
|
|
19
28
|
* Under GitHub Actions, also prints one `::error` annotation per failed seeder.
|
|
20
29
|
*/
|
|
21
|
-
export declare function printErrors(results: SeederResult[]): void;
|
|
30
|
+
export declare function printErrors(results: readonly SeederResult[]): void;
|
|
22
31
|
/**
|
|
23
32
|
* Print seeder header before execution
|
|
24
33
|
*/
|
|
25
34
|
export declare function printSeederHeader(name: string, index: number, total: number, description?: string): void;
|
|
26
35
|
/**
|
|
27
|
-
* Print completion status after a seeder runs
|
|
36
|
+
* Print completion status after a seeder runs (sequential mode)
|
|
28
37
|
*/
|
|
29
38
|
export declare function printSeederComplete(durationMs: number, success: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Print compact prefixed completion status (concurrent mode)
|
|
41
|
+
*/
|
|
42
|
+
export declare function printConcurrentComplete(seederName: string, durationMs: number, success: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Print compact prefixed skip status (concurrent mode)
|
|
45
|
+
*/
|
|
46
|
+
export declare function printConcurrentSkipped(seederName: string, failedDeps: readonly string[]): void;
|
|
30
47
|
/**
|
|
31
48
|
* Print the initial banner when seeding starts
|
|
32
49
|
*/
|
|
33
|
-
export declare function printStartBanner(
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
export declare function printStartBanner(options?: {
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
count?: number | undefined;
|
|
53
|
+
target?: {
|
|
54
|
+
label: string;
|
|
55
|
+
local: boolean;
|
|
56
|
+
} | undefined;
|
|
57
|
+
concurrency?: number | undefined;
|
|
36
58
|
}): void;
|
|
37
59
|
/**
|
|
38
60
|
* Print message when a seeder is skipped due to failed dependencies
|
|
39
61
|
*/
|
|
40
|
-
export declare function printSeederSkipped(failedDeps: string[]): void;
|
|
62
|
+
export declare function printSeederSkipped(failedDeps: readonly string[]): void;
|
|
41
63
|
/**
|
|
42
64
|
* Print the final summary after all seeders complete
|
|
43
65
|
*/
|
|
44
|
-
export declare function printSummary(results: SeederResult[]): void;
|
|
45
|
-
|
|
66
|
+
export declare function printSummary(results: readonly SeederResult[], totalDurationMs?: number, concurrency?: number): void;
|
|
67
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.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MAAM,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAK9F;AAED;;GAEG;AACH,wBAAgB,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,22 +1,44 @@
|
|
|
1
|
-
import type { StepRecord } from './step';
|
|
2
|
-
import type { RunSeedersOptions,
|
|
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: () =>
|
|
10
|
-
/** Called
|
|
11
|
-
|
|
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 |
|
|
39
|
+
onBeforeAll?: (() => MaybePromise<void>) | undefined;
|
|
18
40
|
/** Called after all seeders complete, also when a seeder or the context factory throws */
|
|
19
|
-
onAfterAll?: () => 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
|
|
@@ -26,25 +48,23 @@ export declare class SeedTargetError extends Error {
|
|
|
26
48
|
}
|
|
27
49
|
/**
|
|
28
50
|
* Describe a database URL without its credentials and say whether every host it names
|
|
29
|
-
* is local: loopback
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* (
|
|
51
|
+
* is local: loopback (`localhost`, `127.*`, `::1`, `0.0.0.0`), `*.localhost`,
|
|
52
|
+
* `host.docker.internal`, a socket or `file:` path, or a single-label hostname with an
|
|
53
|
+
* explicit port (such as a compose service like `postgres:5432`). A bare name without a
|
|
54
|
+
* port (such as a cloud project URL like `firestore://my-prod-project`) is treated as
|
|
55
|
+
* remote. A `host=` parameter overrides the URL's host, as libpq does. Hand-parsed so
|
|
56
|
+
* driver formats `URL` rejects still work (several hosts, `sqlserver://host;key=value`,
|
|
57
|
+
* sockets with credentials).
|
|
33
58
|
*/
|
|
34
|
-
export declare function describeTarget(target: string):
|
|
35
|
-
label: string;
|
|
36
|
-
local: boolean;
|
|
37
|
-
};
|
|
59
|
+
export declare function describeTarget(target: string): TargetDescription;
|
|
38
60
|
/**
|
|
39
|
-
* Core seeder runner - executes seeders in dependency order
|
|
61
|
+
* Core seeder runner - executes seeders in dependency order (sequentially or in parallel)
|
|
40
62
|
*
|
|
41
63
|
* @param seeders - Array of seeders to run
|
|
42
64
|
* @param config - Instance configuration (context factory, lifecycle hooks)
|
|
43
|
-
* @param options - Runner options (verbose output, etc.)
|
|
44
|
-
* @returns Object containing results and
|
|
45
|
-
* @throws Dependency errors, `UnknownSeederError
|
|
65
|
+
* @param options - Runner options (verbose output, concurrency, etc.)
|
|
66
|
+
* @returns Object containing `success`, `results`, and `outputs`
|
|
67
|
+
* @throws Dependency errors, `UnknownSeederError`, `SeedTargetError`, or `RangeError` (invalid concurrency), before any hook runs
|
|
46
68
|
*/
|
|
47
|
-
export declare function runSeedersCore<TContext
|
|
48
|
-
|
|
49
|
-
success: boolean;
|
|
50
|
-
}>;
|
|
69
|
+
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>>;
|
|
70
|
+
//# 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,iBAAi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AAY,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;CAC5E,CAAA;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC7B,KAAK,EAAE,MAAM;CAMzB;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CA4BhE;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"}
|
|
@@ -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.
|
|
12
|
-
*
|
|
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
|
-
*
|
|
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"}
|