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 CHANGED
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * plantr - Generic seeder library with built-in faker, step, and expect
3
3
  *
4
- * A Bun-first library for creating type-safe database seeders with dependency resolution.
5
- * The library provides a base context with faker, step, and expect. Consumers
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
- * Note: This library requires Bun as it uses bun:test for the expect function.
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
@@ -33,13 +35,14 @@
33
35
  * }
34
36
  * ```
35
37
  */
36
- export { expect } from 'bun:test';
37
38
  export type { Faker } from '@faker-js/faker';
38
39
  export type { RunSeedersCliOptions } from './src/cli.js';
39
- export type { ResolvedContext, SeederInstance, SeederInstanceConfig, } from './src/create-seeder-instance.js';
40
+ export type { ResolvedContext, ResolvedExpect, SeederInstance, SeederInstanceConfig, } from './src/create-seeder-instance.js';
40
41
  export { createSeederInstance } from './src/create-seeder-instance.js';
41
42
  export { createDefineSeeder } from './src/define-seeder.js';
42
43
  export { CircularDependencyError, DuplicateSeederError, MissingDependencyError, resolveDependencyOrder, UnknownSeederError, } from './src/dependency-resolver.js';
44
+ export type { AnyExpectFn, ErrorConstructor, ExpectFn, ExpectMatchers, } from './src/expect.js';
45
+ export { expect } from './src/expect.js';
43
46
  export type { ColorName, StyleName } from './src/formatting.js';
44
47
  export { colorize, formatDuration } from './src/formatting.js';
45
48
  export { lazyFaker as faker } from './src/l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,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAItF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAGxD,YAAY,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,SAAS,GACT,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGhD,YAAY,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,EACN,SAAS,EACT,YAAY,EACZ,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,GACf,MAAM,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -1,8 +1,4 @@
1
- // index.ts
2
- import { expect as expect2 } from "bun:test";
3
-
4
1
  // src/create-seeder-instance.ts
5
- import { expect } from "bun:test";
6
2
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
7
3
 
8
4
  // src/cli.ts
@@ -142,6 +138,14 @@ function findCycle(remaining, seederMap) {
142
138
  }
143
139
 
144
140
  // src/formatting.ts
141
+ import { inspect as nodeInspect } from "node:util";
142
+ function inspectValue(value, options) {
143
+ const bunInspect = globalThis.Bun?.inspect;
144
+ if (typeof bunInspect === "function") {
145
+ return options ? bunInspect(value, options) : bunInspect(value);
146
+ }
147
+ return nodeInspect(value, { colors: options?.colors ?? false });
148
+ }
145
149
  var colors = {
146
150
  reset: "\x1B[0m",
147
151
  bold: "\x1B[1m",
@@ -236,7 +240,7 @@ function printErrors(results) {
236
240
  for (const result of failed) {
237
241
  const where = result.failedStep ? ` in step "${result.failedStep}"` : "";
238
242
  console.log(colorize(`❌ Seeder "${result.name}" failed${where}:`, "red"));
239
- const details = Bun.inspect(result.error, { colors: supportsColor() });
243
+ const details = inspectValue(result.error, { colors: supportsColor() });
240
244
  for (const line of details.split(`
241
245
  `))
242
246
  console.log(` ${line}`);
@@ -369,8 +373,9 @@ var isLocalHost = (hostPort) => {
369
373
  return true;
370
374
  const lower = hostPort.toLowerCase();
371
375
  const bracketed = /^\[([^\]]*)\]/.exec(lower);
376
+ const hasPort = bracketed ? /:\d+$/.test(lower.slice(bracketed[0].length)) : /:\d+$/.test(lower);
372
377
  const host = bracketed ? bracketed[1] ?? "" : lower.replace(/:\d+$/, "");
373
- return host === "::1" || host === "0.0.0.0" || host === "host.docker.internal" || host.endsWith(".localhost") || /^127\./.test(host) || !/[.:]/.test(host);
378
+ return host === "localhost" || host === "::1" || host === "0.0.0.0" || host === "host.docker.internal" || host.endsWith(".localhost") || /^127\./.test(host) || hasPort && host.length > 0 && !/[.:]/.test(host);
374
379
  };
375
380
  function describeTarget(target) {
376
381
  if (/^file:/i.test(target))
@@ -383,7 +388,9 @@ function describeTarget(target) {
383
388
  const beforeQuery = queryStart === -1 ? rest : rest.slice(0, queryStart);
384
389
  const query = queryStart === -1 ? "" : rest.slice(queryStart);
385
390
  const authorityAndPath = beforeQuery.slice(beforeQuery.lastIndexOf("@") + 1);
386
- const [authority = "", path = ""] = authorityAndPath.split(/(?=[/;])/, 2);
391
+ const pathStart = authorityAndPath.search(/[/;]/);
392
+ const authority = pathStart === -1 ? authorityAndPath : authorityAndPath.slice(0, pathStart);
393
+ const path = pathStart === -1 ? "" : authorityAndPath.slice(pathStart);
387
394
  let hosts = authority.split(",").filter(Boolean);
388
395
  const hostParam = /[?&;]host=([^&;#]*)/i.exec(`${query}${path.startsWith(";") ? path : ""}`)?.[1];
389
396
  if (hostParam) {
@@ -393,7 +400,9 @@ function describeTarget(target) {
393
400
  return { label: "a target with an invalid host parameter", local: false };
394
401
  }
395
402
  }
396
- const label = `${hosts.join(",") || "local socket"}${path.startsWith("/") ? path : ""}`;
403
+ const pathWithoutParams = path.startsWith("/") ? path.split(";", 1)[0] ?? "" : "";
404
+ const pathLabel = pathWithoutParams.length > 1 ? pathWithoutParams : "";
405
+ const label = `${hosts.join(",") || "local socket"}${pathLabel}`;
397
406
  return { label, local: hosts.every(isLocalHost) };
398
407
  }
399
408
  async function runSeedersCore(seeders, config, options = {}) {
@@ -835,7 +844,7 @@ ${colorize("\uD83C\uDF31 Dry Run", "cyan", "bold")} ${colorize(`(${order.length}
835
844
  return success ? 0 : 1;
836
845
  } catch (error) {
837
846
  const usage = error instanceof Error && USAGE_ERRORS.has(error.name);
838
- console.error(colorize(usage ? error.message : Bun.inspect(error), "red"));
847
+ console.error(colorize(usage ? error.message : inspectValue(error), "red"));
839
848
  return 1;
840
849
  }
841
850
  }
@@ -873,12 +882,302 @@ function createDefineSeeder() {
873
882
  };
874
883
  }
875
884
 
876
- // src/lazy-faker.ts
885
+ // src/expect.ts
886
+ import assert, { AssertionError } from "node:assert/strict";
877
887
  import { createRequire } from "node:module";
888
+ function isPlainObject(value) {
889
+ const proto = Object.getPrototypeOf(value);
890
+ return proto === Object.prototype || proto === null;
891
+ }
892
+ function normalizeForEqual(value, seen = new WeakMap) {
893
+ if (value === null || typeof value !== "object")
894
+ return value;
895
+ if (seen.has(value))
896
+ return seen.get(value);
897
+ if (Array.isArray(value)) {
898
+ const normalized = new Array(value.length);
899
+ seen.set(value, normalized);
900
+ for (let i = 0;i < value.length; i++) {
901
+ normalized[i] = normalizeForEqual(value[i], seen);
902
+ }
903
+ return normalized;
904
+ }
905
+ if (isPlainObject(value)) {
906
+ const normalized = Object.getPrototypeOf(value) === null ? Object.create(null) : {};
907
+ seen.set(value, normalized);
908
+ for (const key of Reflect.ownKeys(value)) {
909
+ const desc = Object.getOwnPropertyDescriptor(value, key);
910
+ if (!desc?.enumerable)
911
+ continue;
912
+ const entryValue = value[key];
913
+ if (entryValue !== undefined) {
914
+ normalized[key] = normalizeForEqual(entryValue, seen);
915
+ }
916
+ }
917
+ return normalized;
918
+ }
919
+ return value;
920
+ }
921
+ function sameValueZero(a, b) {
922
+ return a === b || Number.isNaN(a) && Number.isNaN(b);
923
+ }
924
+ function containsValue(actual, expected) {
925
+ if (typeof actual === "string") {
926
+ return typeof expected === "string" && actual.includes(expected);
927
+ }
928
+ if (Array.isArray(actual)) {
929
+ return actual.includes(expected);
930
+ }
931
+ if (actual instanceof Set) {
932
+ return actual.has(expected);
933
+ }
934
+ if (actual !== null && actual !== undefined && typeof actual[Symbol.iterator] === "function") {
935
+ for (const item of actual) {
936
+ if (sameValueZero(item, expected))
937
+ return true;
938
+ }
939
+ }
940
+ return false;
941
+ }
942
+ function matchesThrown(thrown, expected) {
943
+ if (typeof expected === "string") {
944
+ const errorMessage = thrown instanceof Error ? thrown.message : String(thrown);
945
+ return errorMessage.includes(expected);
946
+ }
947
+ if (expected instanceof RegExp) {
948
+ const errorMessage = thrown instanceof Error ? thrown.message : String(thrown);
949
+ const re = expected.global || expected.sticky ? new RegExp(expected.source, expected.flags) : expected;
950
+ return re.test(errorMessage);
951
+ }
952
+ if (expected instanceof Error) {
953
+ if (!(thrown instanceof Error))
954
+ return false;
955
+ if (expected.constructor !== Error && !(thrown instanceof expected.constructor))
956
+ return false;
957
+ return thrown.message === expected.message;
958
+ }
959
+ if (typeof expected === "function") {
960
+ return thrown instanceof expected;
961
+ }
962
+ return false;
963
+ }
964
+ function failAssertion(defaultMessage, actual, expected, operator, customMessage) {
965
+ throw new AssertionError({
966
+ message: customMessage ?? defaultMessage,
967
+ actual,
968
+ expected,
969
+ operator
970
+ });
971
+ }
972
+ function createMatchers(actual, message, negated) {
973
+ const checkComparison = (expected, operator, label, compare) => {
974
+ if (typeof actual !== "number" && typeof actual !== "bigint") {
975
+ failAssertion(`Expected a number or bigint, received ${typeof actual} (${inspectValue(actual)})`, actual, expected, operator, message);
976
+ }
977
+ const passed = compare(actual, expected);
978
+ if (negated ? passed : !passed) {
979
+ failAssertion(`Expected ${inspectValue(actual)} ${negated ? "not " : ""}${label} ${inspectValue(expected)}`, actual, expected, negated ? `not ${operator}` : operator, message);
980
+ }
981
+ };
982
+ return {
983
+ get not() {
984
+ return createMatchers(actual, message, !negated);
985
+ },
986
+ toBe(expected) {
987
+ if (negated) {
988
+ assert.notStrictEqual(actual, expected, message);
989
+ } else {
990
+ assert.strictEqual(actual, expected, message);
991
+ }
992
+ },
993
+ toEqual(expected) {
994
+ const normActual = normalizeForEqual(actual);
995
+ const normExpected = normalizeForEqual(expected);
996
+ if (negated) {
997
+ try {
998
+ assert.notDeepStrictEqual(normActual, normExpected, message);
999
+ } catch (err) {
1000
+ if (err instanceof AssertionError) {
1001
+ failAssertion(err.message, actual, expected, "not toEqual", message);
1002
+ }
1003
+ throw err;
1004
+ }
1005
+ } else {
1006
+ try {
1007
+ assert.deepStrictEqual(normActual, normExpected, message);
1008
+ } catch (err) {
1009
+ if (err instanceof AssertionError) {
1010
+ failAssertion(err.message, actual, expected, "toEqual", message);
1011
+ }
1012
+ throw err;
1013
+ }
1014
+ }
1015
+ },
1016
+ toStrictEqual(expected) {
1017
+ if (negated) {
1018
+ assert.notDeepStrictEqual(actual, expected, message);
1019
+ } else {
1020
+ assert.deepStrictEqual(actual, expected, message);
1021
+ }
1022
+ },
1023
+ toBeDefined() {
1024
+ const isDefined = actual !== undefined;
1025
+ if (negated ? isDefined : !isDefined) {
1026
+ failAssertion(negated ? `Expected ${inspectValue(actual)} to be undefined` : "Expected value to be defined, received undefined", actual, undefined, negated ? "not toBeDefined" : "toBeDefined", message);
1027
+ }
1028
+ },
1029
+ toBeUndefined() {
1030
+ if (negated) {
1031
+ assert.notStrictEqual(actual, undefined, message);
1032
+ } else {
1033
+ assert.strictEqual(actual, undefined, message);
1034
+ }
1035
+ },
1036
+ toBeNull() {
1037
+ if (negated) {
1038
+ assert.notStrictEqual(actual, null, message);
1039
+ } else {
1040
+ assert.strictEqual(actual, null, message);
1041
+ }
1042
+ },
1043
+ toBeTruthy() {
1044
+ const isTruthy = Boolean(actual);
1045
+ if (negated ? isTruthy : !isTruthy) {
1046
+ failAssertion(`Expected ${inspectValue(actual)} ${negated ? "not " : ""}to be truthy`, actual, !negated, negated ? "not toBeTruthy" : "toBeTruthy", message);
1047
+ }
1048
+ },
1049
+ toBeFalsy() {
1050
+ const isFalsy = !actual;
1051
+ if (negated ? isFalsy : !isFalsy) {
1052
+ failAssertion(`Expected ${inspectValue(actual)} ${negated ? "not " : ""}to be falsy`, actual, negated, negated ? "not toBeFalsy" : "toBeFalsy", message);
1053
+ }
1054
+ },
1055
+ toContain(expected) {
1056
+ const passed = containsValue(actual, expected);
1057
+ if (negated ? passed : !passed) {
1058
+ failAssertion(`Expected ${inspectValue(actual)} ${negated ? "not " : ""}to contain ${inspectValue(expected)}`, actual, expected, negated ? "not toContain" : "toContain", message);
1059
+ }
1060
+ },
1061
+ toHaveLength(length) {
1062
+ const actualLength = actual !== null && actual !== undefined ? actual.length : undefined;
1063
+ if (typeof actualLength !== "number") {
1064
+ failAssertion(`Expected ${inspectValue(actual)} to have a numeric length property`, actual, length, "toHaveLength", message);
1065
+ }
1066
+ if (negated) {
1067
+ if (actualLength === length) {
1068
+ failAssertion(`Expected ${inspectValue(actual)} not to have length ${length}`, actualLength, length, "not toHaveLength", message);
1069
+ }
1070
+ } else {
1071
+ assert.strictEqual(actualLength, length, message ?? `Expected ${inspectValue(actual)} to have length ${length}, received ${actualLength}`);
1072
+ }
1073
+ },
1074
+ toMatch(expected) {
1075
+ if (typeof actual !== "string") {
1076
+ failAssertion(`Expected a string for toMatch, received ${typeof actual} (${inspectValue(actual)})`, actual, expected, "toMatch", message);
1077
+ }
1078
+ const passed = expected instanceof RegExp ? (expected.global || expected.sticky ? new RegExp(expected.source, expected.flags) : expected).test(actual) : actual.includes(expected);
1079
+ if (negated ? passed : !passed) {
1080
+ failAssertion(`Expected ${inspectValue(actual)} ${negated ? "not " : ""}to match ${inspectValue(expected)}`, actual, expected, negated ? "not toMatch" : "toMatch", message);
1081
+ }
1082
+ },
1083
+ toBeGreaterThan(expected) {
1084
+ checkComparison(expected, ">", "to be greater than", (a, b) => a > b);
1085
+ },
1086
+ toBeGreaterThanOrEqual(expected) {
1087
+ checkComparison(expected, ">=", "to be greater than or equal to", (a, b) => a >= b);
1088
+ },
1089
+ toBeLessThan(expected) {
1090
+ checkComparison(expected, "<", "to be less than", (a, b) => a < b);
1091
+ },
1092
+ toBeLessThanOrEqual(expected) {
1093
+ checkComparison(expected, "<=", "to be less than or equal to", (a, b) => a <= b);
1094
+ },
1095
+ toThrow(expected) {
1096
+ if (typeof actual !== "function") {
1097
+ failAssertion(`Expected a function for toThrow, received ${typeof actual} (${inspectValue(actual)})`, actual, expected, "toThrow", message);
1098
+ }
1099
+ let threw = false;
1100
+ let thrown;
1101
+ try {
1102
+ actual();
1103
+ } catch (err) {
1104
+ threw = true;
1105
+ thrown = err;
1106
+ }
1107
+ if (!threw) {
1108
+ if (!negated) {
1109
+ failAssertion(expected === undefined ? "Expected function to throw" : `Expected function to throw ${inspectValue(expected)}, but it did not throw`, undefined, expected, "toThrow", message);
1110
+ }
1111
+ return;
1112
+ }
1113
+ if (expected === undefined) {
1114
+ if (negated) {
1115
+ failAssertion(`Expected function not to throw, but it threw ${inspectValue(thrown)}`, thrown, undefined, "not toThrow", message);
1116
+ }
1117
+ return;
1118
+ }
1119
+ const matched = matchesThrown(thrown, expected);
1120
+ if (negated ? matched : !matched) {
1121
+ failAssertion(negated ? `Expected function not to throw matching ${inspectValue(expected)}, but it threw ${inspectValue(thrown)}` : `Expected function to throw matching ${inspectValue(expected)}, but it threw ${inspectValue(thrown)}`, thrown, expected, negated ? "not toThrow" : "toThrow", message);
1122
+ }
1123
+ }
1124
+ };
1125
+ }
1126
+ function createNodeExpect() {
1127
+ return (actual, message) => createMatchers(actual, message, false);
1128
+ }
1129
+ var cachedDefaultExpect;
1130
+ function loadBunExpect() {
1131
+ if (typeof globalThis.Bun === "undefined")
1132
+ return;
1133
+ try {
1134
+ const req = createRequire(import.meta.url);
1135
+ const specifier = ["bun", "test"].join(":");
1136
+ const mod = req(specifier);
1137
+ if (typeof mod.expect === "function")
1138
+ return mod.expect;
1139
+ } catch {}
1140
+ return;
1141
+ }
1142
+ function getDefaultExpect() {
1143
+ if (!cachedDefaultExpect) {
1144
+ cachedDefaultExpect = loadBunExpect() ?? createNodeExpect();
1145
+ }
1146
+ return cachedDefaultExpect;
1147
+ }
1148
+ var expectTarget = () => {
1149
+ throw new Error("unreachable");
1150
+ };
1151
+ var expect = new Proxy(expectTarget, {
1152
+ apply(_target, thisArg, args) {
1153
+ return Reflect.apply(getDefaultExpect(), thisArg, args);
1154
+ },
1155
+ get(_target, prop) {
1156
+ const impl = getDefaultExpect();
1157
+ const value = Reflect.get(impl, prop, impl);
1158
+ return typeof value === "function" ? value.bind(impl) : value;
1159
+ },
1160
+ has(_target, prop) {
1161
+ return Reflect.has(getDefaultExpect(), prop);
1162
+ },
1163
+ ownKeys() {
1164
+ return Reflect.ownKeys(getDefaultExpect());
1165
+ },
1166
+ getOwnPropertyDescriptor(_target, prop) {
1167
+ const desc = Reflect.getOwnPropertyDescriptor(getDefaultExpect(), prop);
1168
+ return desc ? { ...desc, configurable: true } : undefined;
1169
+ },
1170
+ getPrototypeOf() {
1171
+ return Reflect.getPrototypeOf(getDefaultExpect());
1172
+ }
1173
+ });
1174
+
1175
+ // src/lazy-faker.ts
1176
+ import { createRequire as createRequire2 } from "node:module";
878
1177
  var loadedFaker;
879
1178
  function getDefaultFaker() {
880
1179
  if (!loadedFaker) {
881
- const req = createRequire(import.meta.url);
1180
+ const req = createRequire2(import.meta.url);
882
1181
  const mod = req("@faker-js/faker/locale/en");
883
1182
  loadedFaker = mod.faker;
884
1183
  }
@@ -1056,6 +1355,7 @@ function createSeederInstance(config) {
1056
1355
  const defineSeeder = createDefineSeeder();
1057
1356
  const customFaker = config?.faker && config.faker !== lazyFaker ? config.faker : undefined;
1058
1357
  const resolveBaseFaker = () => customFaker ?? getDefaultFaker();
1358
+ const customExpect = config?.expect;
1059
1359
  const fakerSeed = config?.fakerSeed;
1060
1360
  const defaultConcurrency = config?.concurrency;
1061
1361
  const runInternal = async (seeders, options, bannerName) => {
@@ -1112,7 +1412,7 @@ function createSeederInstance(config) {
1112
1412
  const base = {
1113
1413
  faker: scopedFaker,
1114
1414
  step: stepRunner.step,
1115
- expect
1415
+ expect: customExpect ?? getDefaultExpect()
1116
1416
  };
1117
1417
  if (!config?.context)
1118
1418
  return base;
@@ -1179,7 +1479,7 @@ export {
1179
1479
  createSeederInstance,
1180
1480
  createStepRunner,
1181
1481
  describeTarget,
1182
- expect2 as expect,
1482
+ expect,
1183
1483
  lazyFaker as faker,
1184
1484
  formatDuration,
1185
1485
  isSeedingActive,
@@ -1,17 +1,20 @@
1
1
  import type { Faker } from '@faker-js/faker';
2
2
  import { type RunSeedersCliOptions } from './cli.js';
3
+ import { type AnyExpectFn, type ExpectFn } from './expect.js';
3
4
  import { type SeederCache } from './step.js';
4
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;
5
8
  /**
6
9
  * Full context type resolved from `BaseSeederContext` plus the extra properties
7
10
  * returned by `config.context`. Any base key returned by `context` overrides the default.
8
11
  */
9
- export type ResolvedContext<TExtra extends object = Record<never, never>> = Prettify<Omit<BaseSeederContext, keyof TExtra> & TExtra>;
12
+ export type ResolvedContext<TExtra extends object = Record<never, never>, TExpect = ExpectFn> = Prettify<Omit<BaseSeederContext<ResolvedExpect<TExpect>>, keyof TExtra> & TExtra>;
10
13
  /**
11
14
  * Configuration for creating a seeder instance.
12
15
  * `context` is optional and its returned properties are automatically merged onto `BaseSeederContext`.
13
16
  */
14
- export type SeederInstanceConfig<TExtra extends object = Record<never, never>> = {
17
+ export type SeederInstanceConfig<TExtra extends object = Record<never, never>, TExpect extends AnyExpectFn | undefined = ExpectFn> = {
15
18
  /**
16
19
  * Optional factory function that extends the base context (`faker`, `step`, `expect`).
17
20
  * Returned properties are merged onto `base` automatically — no need to spread `...base`,
@@ -23,7 +26,13 @@ export type SeederInstanceConfig<TExtra extends object = Record<never, never>> =
23
26
  * context: () => ({ prisma })
24
27
  * ```
25
28
  */
26
- context?: ((base: BaseSeederContext) => MaybePromise<TExtra>) | undefined;
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;
27
36
  /**
28
37
  * Optional cache for step caching.
29
38
  * Provide `get` / `set` (and optionally `getAll` for single-query preloading).
@@ -88,7 +97,7 @@ export type SeederInstanceConfig<TExtra extends object = Record<never, never>> =
88
97
  * }
89
98
  * ```
90
99
  */
91
- onAfterAll?: ((ctx: NoInfer<ResolvedContext<TExtra>> | undefined) => MaybePromise<void>) | undefined;
100
+ onAfterAll?: ((ctx: NoInfer<ResolvedContext<TExtra, TExpect>> | undefined) => MaybePromise<void>) | undefined;
92
101
  };
93
102
  /**
94
103
  * Result type for the seeder instance
@@ -157,5 +166,5 @@ export type SeederInstance<TContext extends object = BaseSeederContext> = {
157
166
  */
158
167
  isSeedingActive: () => boolean;
159
168
  };
160
- export declare function createSeederInstance<TExtra extends object = Record<never, never>>(config?: SeederInstanceConfig<TExtra>): SeederInstance<ResolvedContext<TExtra>>;
169
+ export declare function createSeederInstance<TExtra extends object = Record<never, never>, TExpect extends AnyExpectFn | undefined = ExpectFn>(config?: SeederInstanceConfig<TExtra, TExpect>): SeederInstance<ResolvedContext<TExtra, TExpect>>;
161
170
  //# sourceMappingURL=create-seeder-instance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-seeder-instance.d.ts","sourceRoot":"","sources":["../../src/create-seeder-instance.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,KAAK,oBAAoB,EAAU,MAAM,UAAU,CAAA;AAK5D,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;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,QAAQ,CACnF,IAAI,CAAC,iBAAiB,EAAE,MAAM,MAAM,CAAC,GAAG,MAAM,CAC9C,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI;IAChF;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,iBAAiB,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;IAEzE;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;IAE/B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAEhC;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IAEzB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,GAAG,S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C,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"}
@@ -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,EAAE,CAAC,GAAG,IAAI,CAAA;IAC9B,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAA;IACjC,aAAa,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAA;IACvC,WAAW,IAAI,IAAI,CAAA;IACnB,aAAa,IAAI,IAAI,CAAA;IACrB,QAAQ,IAAI,IAAI,CAAA;IAChB,UAAU,IAAI,IAAI,CAAA;IAClB,SAAS,IAAI,IAAI,CAAA;IACjB,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAA;IAClC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACxC,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAChD,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACvD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC7C,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACpD,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,gBAAgB,GAAG,IAAI,CAAA;CACpE;AAED,4EAA4E;AAC5E,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,cAAc,CAAC,CAAC,CAAC,CAAA;AA8YtF;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAG3C;AAkBD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAK3C;AAUD,eAAO,MAAM,MAAM,EAAE,QAsBnB,CAAA"}
@@ -1,4 +1,11 @@
1
1
  import type { SeederResult } from './types.js';
2
+ /**
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;
2
9
  export type ColorName = 'red' | 'green' | 'yellow' | 'cyan' | 'white' | 'gray' | 'dim';
3
10
  export type StyleName = 'bold' | 'dim';
4
11
  /**
@@ -16,7 +23,8 @@ export declare function formatDuration(ms: number): string;
16
23
  export declare function printResultsTable(results: readonly SeederResult[]): void;
17
24
  /**
18
25
  * 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.
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.
20
28
  * Under GitHub Actions, also prints one `::error` annotation per failed seeder.
21
29
  */
22
30
  export declare function printErrors(results: readonly SeederResult[]): void;
@@ -1 +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,MAAM,GAAG,MAAM,CAIjD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,CAqExE;AAKD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,CAwBlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GAClB,IAAI,CAQN;AAED;;GAEG;AACH,wB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ACtD,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"}
@@ -48,10 +48,13 @@ export declare class SeedTargetError extends Error {
48
48
  }
49
49
  /**
50
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).
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).
55
58
  */
56
59
  export declare function describeTarget(target: string): TargetDescription;
57
60
  /**
@@ -1 +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,EAA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AiB,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"}
@@ -4,8 +4,8 @@
4
4
  * The library provides a base context with faker, step, and expect.
5
5
  * Consumers can extend this with their own context (e.g. prisma, custom helpers).
6
6
  */
7
- import type { expect } from 'bun:test';
8
7
  import type { Faker } from '@faker-js/faker';
8
+ import type { ExpectFn } from './expect.js';
9
9
  import type { StepFn } from './step.js';
10
10
  /** Flatten intersections and mapped types for cleaner IDE hover tooltips */
11
11
  export type Prettify<T> = {
@@ -24,13 +24,13 @@ export type JsonValue = JsonPrimitive | readonly JsonValue[] | {
24
24
  * Contains faker for generating test data, step for workflow organization,
25
25
  * and expect for assertions.
26
26
  */
27
- export type BaseSeederContext = {
27
+ export type BaseSeederContext<TExpect = ExpectFn> = {
28
28
  /** Faker instance for generating test data */
29
29
  faker: Faker;
30
30
  /** Step function for organizing seeder workflow */
31
31
  step: StepFn;
32
- /** Assertion function from bun:test for verifying data */
33
- expect: typeof expect;
32
+ /** Assertion function for verifying data (bun:test on Bun, built-in fallback on Node, or custom) */
33
+ expect: TExpect;
34
34
  };
35
35
  /** Extract the output type from a Seeder */
36
36
  export type SeederOutput<T> = T extends Seeder<any, any, infer O, any> ? O : never;