plantr 2.1.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 +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +313 -13
- package/dist/src/create-seeder-instance.d.ts +14 -5
- package/dist/src/create-seeder-instance.d.ts.map +1 -1
- package/dist/src/expect.d.ts +41 -0
- package/dist/src/expect.d.ts.map +1 -0
- package/dist/src/formatting.d.ts +9 -1
- package/dist/src/formatting.d.ts.map +1 -1
- package/dist/src/run-seeders.d.ts +7 -4
- package/dist/src/run-seeders.d.ts.map +1 -1
- package/dist/src/types.d.ts +4 -4
- package/dist/src/types.d.ts.map +1 -1
- package/index.ts +15 -6
- package/package.json +4 -2
- package/readme.md +17 -8
- package/src/cli.ts +2 -2
- package/src/create-seeder-instance.ts +39 -13
- package/src/expect.ts +502 -0
- package/src/formatting.ts +22 -2
- package/src/run-seeders.ts +16 -7
- package/src/types.ts +4 -4
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,4EAA4E;AAC5E,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAA;AAEvD,mDAAmD;AACnD,MAAM,MAAM,YAAY,C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AAsE;AACtE,MAAM,MAAM,gBAAgB,CAC3B,QAAQ,SAAS,SAAS,SAAS,EAAE,GAAG,SAAS,SAAS,EAAE,EAC5D,QAAQ,GAAG,SAAS,IAElB;IACA,OAAO,EAAE,IAAI,CAAA;IACb,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAA;IACpC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;CAC5C,GACD;IACA,OAAO,EAAE,KAAK,CAAA;IACd,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAA;IACpC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;CACxC,CAAA"}
|
package/index.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* plantr - Generic seeder library with built-in faker, step, and expect
|
|
3
3
|
*
|
|
4
|
-
* A
|
|
5
|
-
* The library provides a base context with faker,
|
|
6
|
-
* extend this with their own context (e.g. prisma, custom helpers).
|
|
4
|
+
* A TypeScript library for Bun and Node.js (>= 22) for creating type-safe database
|
|
5
|
+
* seeders with dependency resolution. The library provides a base context with faker,
|
|
6
|
+
* step, and expect. Consumers extend this with their own context (e.g. prisma, custom helpers).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* On Bun, `expect` defaults to `bun:test`. On Node.js, `expect` uses a zero-dependency
|
|
9
|
+
* `node:assert/strict` fallback, or you can pass a custom `expect` (e.g. Vitest's) to
|
|
10
|
+
* `createSeederInstance({ expect })`.
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
11
13
|
* ```typescript
|
|
@@ -34,14 +36,14 @@
|
|
|
34
36
|
* ```
|
|
35
37
|
*/
|
|
36
38
|
|
|
37
|
-
// Re-export lazy-loaded English faker (0ms until first access) and expect
|
|
38
|
-
export { expect } from 'bun:test'
|
|
39
|
+
// Re-export lazy-loaded English faker (0ms until first access) and runtime-safe expect
|
|
39
40
|
export type { Faker } from '@faker-js/faker'
|
|
40
41
|
// CLI types
|
|
41
42
|
export type { RunSeedersCliOptions } from './src/cli.js'
|
|
42
43
|
// Main API
|
|
43
44
|
export type {
|
|
44
45
|
ResolvedContext,
|
|
46
|
+
ResolvedExpect,
|
|
45
47
|
SeederInstance,
|
|
46
48
|
SeederInstanceConfig,
|
|
47
49
|
} from './src/create-seeder-instance.js'
|
|
@@ -55,6 +57,13 @@ export {
|
|
|
55
57
|
resolveDependencyOrder,
|
|
56
58
|
UnknownSeederError,
|
|
57
59
|
} from './src/dependency-resolver.js'
|
|
60
|
+
export type {
|
|
61
|
+
AnyExpectFn,
|
|
62
|
+
ErrorConstructor,
|
|
63
|
+
ExpectFn,
|
|
64
|
+
ExpectMatchers,
|
|
65
|
+
} from './src/expect.js'
|
|
66
|
+
export { expect } from './src/expect.js'
|
|
58
67
|
export type { ColorName, StyleName } from './src/formatting.js'
|
|
59
68
|
export { colorize, formatDuration } from './src/formatting.js'
|
|
60
69
|
export { lazyFaker as faker } from './src/lazy-faker.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plantr",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A generic seeder library with built-in faker, step, and expect support for type-safe database seeding",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"author": "Kristoffer Hansen",
|
|
16
16
|
"keywords": [
|
|
17
17
|
"bun",
|
|
18
|
+
"node",
|
|
18
19
|
"seeder",
|
|
19
20
|
"database",
|
|
20
21
|
"faker",
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
"dependency-injection"
|
|
26
27
|
],
|
|
27
28
|
"engines": {
|
|
28
|
-
"bun": ">=1.0.0"
|
|
29
|
+
"bun": ">=1.0.0",
|
|
30
|
+
"node": ">=22.0.0"
|
|
29
31
|
},
|
|
30
32
|
"files": [
|
|
31
33
|
"index.ts",
|
package/readme.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# plantr
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript database seeder library for **Bun and Node.js (>= 22)** with built-in faker, step workflow, parallel DAG execution, and end-to-end TypeScript inference.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
7
|
+
- **Bun & Node.js (>= 22)** - Runs natively on both Bun and Node.js (`node`, `tsx`, `ts-node`, `vitest`) with zero extra dependencies
|
|
8
|
+
- **Built-in utilities** - `faker`, `step`, and `expect` available in every seeder (`faker` is lazy-loaded on first access, English locale only by default; `expect` uses `bun:test` on Bun, a built-in `node:assert/strict` implementation on Node.js, or your own `expect` such as Vitest's)
|
|
8
9
|
- **End-to-end TypeScript** - Zero-boilerplate context inference, context-safe seeder registries, typed dependencies, typed `outputs`, discriminated-union `results`, compile-time missing dependency checks, and autocompleted `only`/`fresh`
|
|
9
10
|
- **Automatic ordering & parallel DAG execution** - Runs in dependency order with critical-path scheduling across independent branches via `concurrency` / `--concurrency`
|
|
10
11
|
- **Run a subset** - Run named seeders plus what they depend on (`--only`, `only`)
|
|
11
12
|
- **Step workflow** - Organize seeders into sequential or `Promise.all` parallel steps with progress logging
|
|
12
13
|
- **Step caching** - Skip steps that already ran, with explicit keys, canonical JSON versions, single-query `getAll` preloading, batched `setMany` writes, and a `--fresh` override
|
|
13
|
-
- **Target guard** - Refuse to seed a database that is not local unless asked to
|
|
14
|
+
- **Target guard** - Refuse to seed a database or emulator target that is not local unless asked to
|
|
14
15
|
- **Lifecycle hooks** - `onBeforeAll` / `onAfterAll(ctx)` for setup and teardown
|
|
15
16
|
- **Continue on failure** - Keep seeding independent data when one seeder fails
|
|
16
17
|
- **Dry run & list modes** - Preview execution order, target, and descriptions without running
|
|
@@ -19,9 +20,11 @@ A Bun-first database seeder library with built-in faker, step workflow, parallel
|
|
|
19
20
|
|
|
20
21
|
```bash
|
|
21
22
|
bun add plantr
|
|
23
|
+
# or with pnpm / npm on Node.js >= 22
|
|
24
|
+
pnpm add plantr
|
|
22
25
|
```
|
|
23
26
|
|
|
24
|
-
> **
|
|
27
|
+
> **Runtime support:** Works on **Bun >= 1.0** and **Node.js >= 22**. On Bun, `expect` delegates to `bun:test`. On Node.js, `expect` uses a zero-dependency fallback backed by `node:assert/strict` (covering `toBe`, `toEqual`, `toStrictEqual`, `toBeDefined`, `toBeUndefined`, `toBeNull`, `toBeTruthy`, `toBeFalsy`, `toContain`, `toHaveLength`, `toMatch`, `toBeGreaterThan`, `toBeGreaterThanOrEqual`, `toBeLessThan`, `toBeLessThanOrEqual`, `toThrow`, and `.not.*`), or pass your own `expect` (for example Vitest's `expect`) via `createSeederInstance({ expect })`.
|
|
25
28
|
|
|
26
29
|
## Quick Start
|
|
27
30
|
|
|
@@ -118,6 +121,8 @@ if (import.meta.main) {
|
|
|
118
121
|
Run with:
|
|
119
122
|
```bash
|
|
120
123
|
bun run src/seed.ts
|
|
124
|
+
# or on Node.js:
|
|
125
|
+
npx tsx src/seed.ts
|
|
121
126
|
```
|
|
122
127
|
|
|
123
128
|
Or programmatically (e.g. in tests) with fully typed `outputs`:
|
|
@@ -173,7 +178,11 @@ createSeederInstance({
|
|
|
173
178
|
// Optional: custom Faker locale instance (default: lazy-loaded @faker-js/faker/locale/en)
|
|
174
179
|
faker: fakerDE,
|
|
175
180
|
|
|
176
|
-
// Optional:
|
|
181
|
+
// Optional: custom `expect` implementation (e.g. Vitest's `expect`).
|
|
182
|
+
// Defaults to `bun:test` on Bun and a built-in `node:assert/strict` fallback on Node.js.
|
|
183
|
+
expect: vitestExpect,
|
|
184
|
+
|
|
185
|
+
// Optional: the database or emulator URL the run writes to (see Target guard)
|
|
177
186
|
target: () => process.env.DATABASE_URL,
|
|
178
187
|
|
|
179
188
|
// Optional: seed faker per seeder (fakerSeed + hash of the seeder name),
|
|
@@ -293,13 +302,13 @@ cache: {
|
|
|
293
302
|
|
|
294
303
|
## Target guard
|
|
295
304
|
|
|
296
|
-
Set `target` to the database URL the instance writes to. The banner then shows its host and
|
|
305
|
+
Set `target` to the database or emulator URL the instance writes to (for example `process.env.DATABASE_URL`, `http://127.0.0.1:8080`, or `firestore://127.0.0.1:8080/demo-app`). The banner then shows its host and path, never credentials (`🌱 Running Seeders (2 seeders) → localhost:5432/app`), and a run refuses with `SeedTargetError` before `onBeforeAll` when the target is not local. Local means every host the URL names (several hosts, or a `host=` parameter, which overrides the URL's host) is loopback (`localhost`, `127.*`, `::1`, `0.0.0.0`), `*.localhost`, `host.docker.internal`, a socket directory or `file:` path, or a single-label hostname with an explicit port such as a compose service (`postgres:5432`). A bare name without a port (such as a cloud project URL like `firestore://my-prod-project`) or a target without a `scheme://` is refused. Seed anything else on purpose with `allowRemote: true` or `--allow-remote`, for example in a staging pre-deploy command.
|
|
297
306
|
|
|
298
307
|
Without `target` there is no check. For other rules (an environment variable, a list of allowed hosts), throw from `onBeforeAll`.
|
|
299
308
|
|
|
300
309
|
## Seeding State
|
|
301
310
|
|
|
302
|
-
Check if seeding is active to skip side effects. Runtime code (job queues, mailers, the API) should import it from `plantr/state`, which does not load faker
|
|
311
|
+
Check if seeding is active to skip side effects. Runtime code (job queues, mailers, the API) should import it from `plantr/state`, which does not load faker, `bun:test`, or assertion helpers:
|
|
303
312
|
|
|
304
313
|
```typescript
|
|
305
314
|
import { isSeedingActive } from 'plantr/state'
|
|
@@ -339,7 +348,7 @@ try {
|
|
|
339
348
|
}
|
|
340
349
|
```
|
|
341
350
|
|
|
342
|
-
When a seeder fails, the summary names the failing step and prints the whole error
|
|
351
|
+
When a seeder fails, the summary names the failing step and prints the whole error (`Bun.inspect` on Bun or `util.inspect` on Node.js: message, stack, `cause` and extra fields). Under GitHub Actions it also prints an `::error` annotation. Terminal colors respect `NO_COLOR`, `FORCE_COLOR`, and stdout TTY state.
|
|
343
352
|
|
|
344
353
|
## License
|
|
345
354
|
|
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util'
|
|
2
2
|
import { resolveDependencyOrder } from './dependency-resolver.js'
|
|
3
|
-
import { colorize } from './formatting.js'
|
|
3
|
+
import { colorize, inspectValue } from './formatting.js'
|
|
4
4
|
import { describeTarget } from './run-seeders.js'
|
|
5
5
|
import type { RunSeedersOptions, SeederAny } from './types.js'
|
|
6
6
|
|
|
@@ -226,7 +226,7 @@ export async function runCli(
|
|
|
226
226
|
return success ? 0 : 1
|
|
227
227
|
} catch (error) {
|
|
228
228
|
const usage = error instanceof Error && USAGE_ERRORS.has(error.name)
|
|
229
|
-
console.error(colorize(usage ? (error as Error).message :
|
|
229
|
+
console.error(colorize(usage ? (error as Error).message : inspectValue(error), 'red'))
|
|
230
230
|
return 1
|
|
231
231
|
}
|
|
232
232
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { expect } from 'bun:test'
|
|
2
1
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
3
2
|
import type { Faker } from '@faker-js/faker'
|
|
4
3
|
import { type RunSeedersCliOptions, runCli } from './cli.js'
|
|
5
4
|
import { createDefineSeeder } from './define-seeder.js'
|
|
5
|
+
import { type AnyExpectFn, type ExpectFn, getDefaultExpect } from './expect.js'
|
|
6
6
|
import { getDefaultFaker, lazyFaker } from './lazy-faker.js'
|
|
7
7
|
import { runSeedersCore } from './run-seeders.js'
|
|
8
8
|
import { isSeedingActive } from './seeding-state.js'
|
|
@@ -19,19 +19,32 @@ import type {
|
|
|
19
19
|
ValidateSeeders,
|
|
20
20
|
} from './types.js'
|
|
21
21
|
|
|
22
|
+
/** Resolve the effective `expect` type from an optional `config.expect` type parameter */
|
|
23
|
+
export type ResolvedExpect<TExpect> = [Exclude<TExpect, undefined>] extends [never]
|
|
24
|
+
? ExpectFn
|
|
25
|
+
: [AnyExpectFn] extends [Exclude<TExpect, undefined>]
|
|
26
|
+
? ExpectFn
|
|
27
|
+
: undefined extends TExpect
|
|
28
|
+
? Exclude<TExpect, undefined> | ExpectFn
|
|
29
|
+
: TExpect
|
|
30
|
+
|
|
22
31
|
/**
|
|
23
32
|
* Full context type resolved from `BaseSeederContext` plus the extra properties
|
|
24
33
|
* returned by `config.context`. Any base key returned by `context` overrides the default.
|
|
25
34
|
*/
|
|
26
|
-
export type ResolvedContext<
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
export type ResolvedContext<
|
|
36
|
+
TExtra extends object = Record<never, never>,
|
|
37
|
+
TExpect = ExpectFn,
|
|
38
|
+
> = Prettify<Omit<BaseSeederContext<ResolvedExpect<TExpect>>, keyof TExtra> & TExtra>
|
|
29
39
|
|
|
30
40
|
/**
|
|
31
41
|
* Configuration for creating a seeder instance.
|
|
32
42
|
* `context` is optional and its returned properties are automatically merged onto `BaseSeederContext`.
|
|
33
43
|
*/
|
|
34
|
-
export type SeederInstanceConfig<
|
|
44
|
+
export type SeederInstanceConfig<
|
|
45
|
+
TExtra extends object = Record<never, never>,
|
|
46
|
+
TExpect extends AnyExpectFn | undefined = ExpectFn,
|
|
47
|
+
> = {
|
|
35
48
|
/**
|
|
36
49
|
* Optional factory function that extends the base context (`faker`, `step`, `expect`).
|
|
37
50
|
* Returned properties are merged onto `base` automatically — no need to spread `...base`,
|
|
@@ -43,7 +56,16 @@ export type SeederInstanceConfig<TExtra extends object = Record<never, never>> =
|
|
|
43
56
|
* context: () => ({ prisma })
|
|
44
57
|
* ```
|
|
45
58
|
*/
|
|
46
|
-
context?:
|
|
59
|
+
context?:
|
|
60
|
+
| ((base: NoInfer<BaseSeederContext<ResolvedExpect<TExpect>>>) => MaybePromise<TExtra>)
|
|
61
|
+
| undefined
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Optional: custom `expect` assertion function (for example Vitest's `expect`).
|
|
65
|
+
* Defaults to `bun:test`'s `expect` on Bun and a zero-dependency `node:assert/strict`
|
|
66
|
+
* implementation on Node.js.
|
|
67
|
+
*/
|
|
68
|
+
expect?: TExpect | undefined
|
|
47
69
|
|
|
48
70
|
/**
|
|
49
71
|
* Optional cache for step caching.
|
|
@@ -116,7 +138,7 @@ export type SeederInstanceConfig<TExtra extends object = Record<never, never>> =
|
|
|
116
138
|
* ```
|
|
117
139
|
*/
|
|
118
140
|
onAfterAll?:
|
|
119
|
-
| ((ctx: NoInfer<ResolvedContext<TExtra>> | undefined) => MaybePromise<void>)
|
|
141
|
+
| ((ctx: NoInfer<ResolvedContext<TExtra, TExpect>> | undefined) => MaybePromise<void>)
|
|
120
142
|
| undefined
|
|
121
143
|
}
|
|
122
144
|
|
|
@@ -243,14 +265,18 @@ type FakerSlot = {
|
|
|
243
265
|
instance?: Faker
|
|
244
266
|
}
|
|
245
267
|
|
|
246
|
-
export function createSeederInstance<
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
268
|
+
export function createSeederInstance<
|
|
269
|
+
TExtra extends object = Record<never, never>,
|
|
270
|
+
TExpect extends AnyExpectFn | undefined = ExpectFn,
|
|
271
|
+
>(
|
|
272
|
+
config?: SeederInstanceConfig<TExtra, TExpect>,
|
|
273
|
+
): SeederInstance<ResolvedContext<TExtra, TExpect>> {
|
|
274
|
+
type TContext = ResolvedContext<TExtra, TExpect>
|
|
250
275
|
|
|
251
276
|
const defineSeeder = createDefineSeeder<TContext>()
|
|
252
277
|
const customFaker = config?.faker && config.faker !== lazyFaker ? config.faker : undefined
|
|
253
278
|
const resolveBaseFaker = (): Faker => customFaker ?? getDefaultFaker()
|
|
279
|
+
const customExpect = config?.expect
|
|
254
280
|
const fakerSeed = config?.fakerSeed
|
|
255
281
|
const defaultConcurrency = config?.concurrency
|
|
256
282
|
|
|
@@ -317,10 +343,10 @@ export function createSeederInstance<TExtra extends object = Record<never, never
|
|
|
317
343
|
seeders,
|
|
318
344
|
{
|
|
319
345
|
context: async () => {
|
|
320
|
-
const base: BaseSeederContext = {
|
|
346
|
+
const base: BaseSeederContext<ResolvedExpect<TExpect>> = {
|
|
321
347
|
faker: scopedFaker,
|
|
322
348
|
step: stepRunner.step,
|
|
323
|
-
expect
|
|
349
|
+
expect: (customExpect ?? getDefaultExpect()) as ResolvedExpect<TExpect>,
|
|
324
350
|
}
|
|
325
351
|
if (!config?.context) return base as unknown as TContext
|
|
326
352
|
const extra = await config.context(base)
|