schema-seed 0.1.4 → 0.1.5

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/bin.js CHANGED
@@ -19,15 +19,29 @@ import { existsSync } from "fs";
19
19
  import { resolve } from "path";
20
20
  async function loadConfig(configPath) {
21
21
  const jiti = createJiti(import.meta.url);
22
- const paths = configPath ? [resolve(process.cwd(), configPath)] : [
22
+ if (configPath) {
23
+ const fullPath = resolve(process.cwd(), configPath);
24
+ if (!existsSync(fullPath)) {
25
+ throw new Error(`Config file not found at ${fullPath}`);
26
+ }
27
+ const module = await jiti.import(fullPath);
28
+ console.log(`\u2705 Loaded config from ${configPath}`);
29
+ return module.default || module;
30
+ }
31
+ const defaultPaths = [
23
32
  resolve(process.cwd(), "seed.config.ts"),
24
33
  resolve(process.cwd(), "seed.config.js"),
25
34
  resolve(process.cwd(), "seed.config.mjs")
26
35
  ];
27
- for (const path of paths) {
36
+ for (const path of defaultPaths) {
28
37
  if (existsSync(path)) {
29
- const module = await jiti.import(path);
30
- return module.default || module;
38
+ try {
39
+ const module = await jiti.import(path);
40
+ console.log(`\u2705 Loaded config from ${path}`);
41
+ return module.default || module;
42
+ } catch (err) {
43
+ throw new Error(`Failed to load config file ${path}: ${err.message}`);
44
+ }
31
45
  }
32
46
  }
33
47
  return {};
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bin.ts","../src/config.mts"],"sourcesContent":["import 'dotenv/config'\nimport { Command } from 'commander'\nimport {\n version as coreVersion,\n runSeedSql,\n runSeedMongo,\n createSeedPlan,\n reportToConsole,\n reportToJson\n} from 'schema-seed-core'\nimport { generators, inferGenerator } from 'schema-seed-generators'\nimport { loadConfig } from './config.mjs'\nimport { writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { createInterface } from 'node:readline/promises'\n\nconst program = new Command()\n\nprogram\n .name('schema-seed')\n .description('CLI to seed your database with realistic data')\n .version(coreVersion)\n\nasync function getAdapter(dbType: string, dbUrl: string) {\n const packageName = `schema-seed-adapter-${dbType}`\n try {\n const module = await import(packageName)\n const adapterName = dbType.charAt(0).toUpperCase() + dbType.slice(1) + 'Adapter'\n const AdapterClass = module[adapterName] || module.Adapter || module.default\n\n if (!AdapterClass) {\n // Try factory function\n const factoryMethod = `create${dbType.charAt(0).toUpperCase() + dbType.slice(1)}Adapter`\n if (typeof module[factoryMethod] === 'function') {\n return module[factoryMethod](dbUrl)\n }\n throw new Error(`Could not find adapter class or factory in ${packageName}`)\n }\n\n return new AdapterClass(dbUrl)\n } catch (err: any) {\n if (err.code === 'ERR_MODULE_NOT_FOUND' || err.message.includes('Cannot find module')) {\n throw new Error(`Adapter not installed. Run: pnpm add ${packageName}`)\n }\n throw new Error(`Failed to load adapter ${packageName}: ${err.message}`)\n }\n}\n\nfunction inferDbType(dbUrl: string): string {\n if (dbUrl.startsWith('postgres://') || dbUrl.startsWith('postgresql://')) return 'postgres'\n if (dbUrl.startsWith('mysql://')) return 'mysql'\n if (dbUrl.startsWith('sqlite://') || dbUrl.endsWith('.db')) return 'sqlite'\n if (dbUrl.startsWith('mongodb://')) return 'mongodb'\n if (dbUrl.startsWith('sqlserver://')) return 'mssql'\n return 'postgres' // Default\n}\n\nasync function confirmAction(expected: string): Promise<boolean> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout\n })\n const answer = await rl.question(`⚠️ Type \"${expected}\" to confirm: `)\n rl.close()\n return answer === expected\n}\n\nconst commonOptions = (cmd: Command) => {\n return cmd\n .option('--db <url>', 'Database connection string')\n .option('--dbType <type>', 'Database type (postgres, mysql, sqlite, mssql, oracle, mongodb)')\n .option('--config <path>', 'Path to config file')\n .option('--table <names...>', 'Specific tables to seed')\n .option('--all', 'Seed all tables', true)\n .option('--rows <number>', 'Number of rows per table', (v) => parseInt(v), 10)\n .option('--rows-per-table <json>', 'JSON mapping of table names to row counts', (v) => JSON.parse(v))\n .option('--seed <string>', 'Random seed')\n .option('--dry-run', 'Do not execute any writes')\n .option('--truncate', 'Truncate tables before seeding')\n .option('--allow-production', 'Allow running against production databases')\n .option('--confirm <string>', 'Require typed confirmation string to proceed')\n .option('--with-parents', 'Include parent tables for foreign keys')\n .option('--out <path>', 'Output report to JSON file')\n}\n\ncommonOptions(program.command('seed'))\n .description('Seed the database')\n .action(async (options) => {\n const config = await loadConfig(options.config)\n const mergedOptions = { ...config, ...options }\n\n if (options.rowsPerTable) {\n mergedOptions.rows = options.rowsPerTable\n }\n\n if (mergedOptions.confirm && !mergedOptions.dryRun) {\n const confirmed = await confirmAction(mergedOptions.confirm)\n if (!confirmed) {\n console.error('❌ Confirmation failed. Aborting.')\n process.exit(1)\n }\n }\n\n let dbUrl = mergedOptions.db\n if (mergedOptions.dbType === 'mongodb' && mergedOptions.mongodb?.uri) {\n dbUrl = mergedOptions.mongodb.uri\n }\n\n if (!dbUrl) {\n console.error('Error: Database connection string (--db) is required')\n process.exit(1)\n }\n\n const dbType = mergedOptions.dbType || inferDbType(dbUrl)\n\n try {\n const adapter = await getAdapter(dbType, dbUrl)\n\n let report;\n if (dbType === 'mongodb') {\n // For MongoDB, we use the new config-based seeding\n report = await runSeedMongo(adapter as any, mergedOptions as any, {\n dryRun: mergedOptions.dryRun,\n allowProduction: mergedOptions.allowProduction\n }, { generators, inferGenerator })\n } else {\n await adapter.connect()\n const schema = await (adapter as any).introspectSchema()\n const plan = createSeedPlan(schema, mergedOptions, (adapter as any).capabilities?.deferrableConstraints)\n\n report = await runSeedSql(adapter as any, schema, plan, mergedOptions, {\n generators,\n inferGenerator,\n overrides: mergedOptions.overrides\n })\n }\n\n reportToConsole(report)\n\n if (options.out) {\n writeFileSync(resolve(process.cwd(), options.out), reportToJson(report))\n }\n } catch (err: any) {\n console.error(`\\n❌ Error: ${err.message}`)\n process.exit(1)\n }\n })\n\nprogram.command('preview')\n .description('Preview the seeding plan without executing')\n .action(async (options) => {\n // Same as seed --dry-run\n const seedCmd = program.commands.find(c => c.name() === 'seed')\n await seedCmd?.parseAsync(['--dry-run', ...process.argv.slice(3)], { from: 'user' })\n })\n\nprogram.command('reset')\n .description('Truncate all tables')\n .option('--db <url>', 'Database connection string')\n .option('--allow-production', 'Allow running against production databases')\n .action(async (options) => {\n console.log('Resetting database...')\n // Implementation would call adapter.truncateTables()\n })\n\nprogram.command('introspect')\n .description('Introspect the database schema and print as JSON')\n .option('--db <url>', 'Database connection string')\n .action(async (options) => {\n console.log('Introspecting database...')\n // Implementation would call adapter.introspectSchema()\n })\n\nprogram.parse()\n","import { createJiti } from 'jiti'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { type SeedOptions } from 'schema-seed-core'\nimport { type MongoSeedConfig } from 'schema-seed-core/mongo'\n\nexport type Config = (SeedOptions & {\n db?: string\n dbType?: string\n overrides?: Record<string, any>\n}) | MongoSeedConfig\n\nexport async function loadConfig(configPath?: string): Promise<Config> {\n const jiti = createJiti(import.meta.url)\n const paths = configPath\n ? [resolve(process.cwd(), configPath)]\n : [\n resolve(process.cwd(), 'seed.config.ts'),\n resolve(process.cwd(), 'seed.config.js'),\n resolve(process.cwd(), 'seed.config.mjs'),\n ]\n\n for (const path of paths) {\n if (existsSync(path)) {\n const module = await jiti.import(path) as any\n return module.default || module\n }\n }\n\n return {}\n}\n"],"mappings":";;;AAAA,OAAO;AACP,SAAS,eAAe;AACxB;AAAA,EACI,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,YAAY,sBAAsB;;;ACV3C,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAUxB,eAAsB,WAAW,YAAsC;AACnE,QAAM,OAAO,WAAW,YAAY,GAAG;AACvC,QAAM,QAAQ,aACR,CAAC,QAAQ,QAAQ,IAAI,GAAG,UAAU,CAAC,IACnC;AAAA,IACE,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,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AAY,4CAA4C,EACxD,OAAO,OAAO,YAAY;AAEvB,QAAM,UAAU,QAAQ,SAAS,KAAK,OAAK,EAAE,KAAK,MAAM,MAAM;AAC9D,QAAM,SAAS,WAAW,CAAC,aAAa,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,OAAO,CAAC;AACvF,CAAC;AAEL,QAAQ,QAAQ,OAAO,EAClB,YAAY,qBAAqB,EACjC,OAAO,cAAc,4BAA4B,EACjD,OAAO,sBAAsB,4CAA4C,EACzE,OAAO,OAAO,YAAY;AACvB,UAAQ,IAAI,uBAAuB;AAEvC,CAAC;AAEL,QAAQ,QAAQ,YAAY,EACvB,YAAY,kDAAkD,EAC9D,OAAO,cAAc,4BAA4B,EACjD,OAAO,OAAO,YAAY;AACvB,UAAQ,IAAI,2BAA2B;AAE3C,CAAC;AAEL,QAAQ,MAAM;","names":["resolve"]}
1
+ {"version":3,"sources":["../src/bin.ts","../src/config.mts"],"sourcesContent":["import 'dotenv/config'\nimport { Command } from 'commander'\nimport {\n version as coreVersion,\n runSeedSql,\n runSeedMongo,\n createSeedPlan,\n reportToConsole,\n reportToJson\n} from 'schema-seed-core'\nimport { generators, inferGenerator } from 'schema-seed-generators'\nimport { loadConfig } from './config.mjs'\nimport { writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { createInterface } from 'node:readline/promises'\n\nconst program = new Command()\n\nprogram\n .name('schema-seed')\n .description('CLI to seed your database with realistic data')\n .version(coreVersion)\n\nasync function getAdapter(dbType: string, dbUrl: string) {\n const packageName = `schema-seed-adapter-${dbType}`\n try {\n const module = await import(packageName)\n const adapterName = dbType.charAt(0).toUpperCase() + dbType.slice(1) + 'Adapter'\n const AdapterClass = module[adapterName] || module.Adapter || module.default\n\n if (!AdapterClass) {\n // Try factory function\n const factoryMethod = `create${dbType.charAt(0).toUpperCase() + dbType.slice(1)}Adapter`\n if (typeof module[factoryMethod] === 'function') {\n return module[factoryMethod](dbUrl)\n }\n throw new Error(`Could not find adapter class or factory in ${packageName}`)\n }\n\n return new AdapterClass(dbUrl)\n } catch (err: any) {\n if (err.code === 'ERR_MODULE_NOT_FOUND' || err.message.includes('Cannot find module')) {\n throw new Error(`Adapter not installed. Run: pnpm add ${packageName}`)\n }\n throw new Error(`Failed to load adapter ${packageName}: ${err.message}`)\n }\n}\n\nfunction inferDbType(dbUrl: string): string {\n if (dbUrl.startsWith('postgres://') || dbUrl.startsWith('postgresql://')) return 'postgres'\n if (dbUrl.startsWith('mysql://')) return 'mysql'\n if (dbUrl.startsWith('sqlite://') || dbUrl.endsWith('.db')) return 'sqlite'\n if (dbUrl.startsWith('mongodb://')) return 'mongodb'\n if (dbUrl.startsWith('sqlserver://')) return 'mssql'\n return 'postgres' // Default\n}\n\nasync function confirmAction(expected: string): Promise<boolean> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout\n })\n const answer = await rl.question(`⚠️ Type \"${expected}\" to confirm: `)\n rl.close()\n return answer === expected\n}\n\nconst commonOptions = (cmd: Command) => {\n return cmd\n .option('--db <url>', 'Database connection string')\n .option('--dbType <type>', 'Database type (postgres, mysql, sqlite, mssql, oracle, mongodb)')\n .option('--config <path>', 'Path to config file')\n .option('--table <names...>', 'Specific tables to seed')\n .option('--all', 'Seed all tables', true)\n .option('--rows <number>', 'Number of rows per table', (v) => parseInt(v), 10)\n .option('--rows-per-table <json>', 'JSON mapping of table names to row counts', (v) => JSON.parse(v))\n .option('--seed <string>', 'Random seed')\n .option('--dry-run', 'Do not execute any writes')\n .option('--truncate', 'Truncate tables before seeding')\n .option('--allow-production', 'Allow running against production databases')\n .option('--confirm <string>', 'Require typed confirmation string to proceed')\n .option('--with-parents', 'Include parent tables for foreign keys')\n .option('--out <path>', 'Output report to JSON file')\n}\n\ncommonOptions(program.command('seed'))\n .description('Seed the database')\n .action(async (options) => {\n const config = await loadConfig(options.config)\n const mergedOptions = { ...config, ...options }\n\n if (options.rowsPerTable) {\n mergedOptions.rows = options.rowsPerTable\n }\n\n if (mergedOptions.confirm && !mergedOptions.dryRun) {\n const confirmed = await confirmAction(mergedOptions.confirm)\n if (!confirmed) {\n console.error('❌ Confirmation failed. Aborting.')\n process.exit(1)\n }\n }\n\n let dbUrl = mergedOptions.db\n if (mergedOptions.dbType === 'mongodb' && mergedOptions.mongodb?.uri) {\n dbUrl = mergedOptions.mongodb.uri\n }\n\n if (!dbUrl) {\n console.error('Error: Database connection string (--db) is required')\n process.exit(1)\n }\n\n const dbType = mergedOptions.dbType || inferDbType(dbUrl)\n\n try {\n const adapter = await getAdapter(dbType, dbUrl)\n\n let report;\n if (dbType === 'mongodb') {\n // For MongoDB, we use the new config-based seeding\n report = await runSeedMongo(adapter as any, mergedOptions as any, {\n dryRun: mergedOptions.dryRun,\n allowProduction: mergedOptions.allowProduction\n }, { generators, inferGenerator })\n } else {\n await adapter.connect()\n const schema = await (adapter as any).introspectSchema()\n const plan = createSeedPlan(schema, mergedOptions, (adapter as any).capabilities?.deferrableConstraints)\n\n report = await runSeedSql(adapter as any, schema, plan, mergedOptions, {\n generators,\n inferGenerator,\n overrides: mergedOptions.overrides\n })\n }\n\n reportToConsole(report)\n\n if (options.out) {\n writeFileSync(resolve(process.cwd(), options.out), reportToJson(report))\n }\n } catch (err: any) {\n console.error(`\\n❌ Error: ${err.message}`)\n process.exit(1)\n }\n })\n\nprogram.command('preview')\n .description('Preview the seeding plan without executing')\n .action(async (options) => {\n // Same as seed --dry-run\n const seedCmd = program.commands.find(c => c.name() === 'seed')\n await seedCmd?.parseAsync(['--dry-run', ...process.argv.slice(3)], { from: 'user' })\n })\n\nprogram.command('reset')\n .description('Truncate all tables')\n .option('--db <url>', 'Database connection string')\n .option('--allow-production', 'Allow running against production databases')\n .action(async (options) => {\n console.log('Resetting database...')\n // Implementation would call adapter.truncateTables()\n })\n\nprogram.command('introspect')\n .description('Introspect the database schema and print as JSON')\n .option('--db <url>', 'Database connection string')\n .action(async (options) => {\n console.log('Introspecting database...')\n // Implementation would call adapter.introspectSchema()\n })\n\nprogram.parse()\n","import { createJiti } from 'jiti'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { type SeedOptions } from 'schema-seed-core'\nimport { type MongoSeedConfig } from 'schema-seed-core/mongo'\n\nexport type Config = (SeedOptions & {\n db?: string\n dbType?: string\n overrides?: Record<string, any>\n}) | MongoSeedConfig\n\nexport async function loadConfig(configPath?: string): Promise<Config> {\n const jiti = createJiti(import.meta.url)\n\n if (configPath) {\n const fullPath = resolve(process.cwd(), configPath)\n if (!existsSync(fullPath)) {\n throw new Error(`Config file not found at ${fullPath}`)\n }\n const module = await jiti.import(fullPath) as any\n console.log(`✅ Loaded config from ${configPath}`)\n return module.default || module\n }\n\n const defaultPaths = [\n resolve(process.cwd(), 'seed.config.ts'),\n resolve(process.cwd(), 'seed.config.js'),\n resolve(process.cwd(), 'seed.config.mjs'),\n ]\n\n for (const path of defaultPaths) {\n if (existsSync(path)) {\n try {\n const module = await jiti.import(path) as any\n console.log(`✅ Loaded config from ${path}`)\n return module.default || module\n } catch (err: any) {\n throw new Error(`Failed to load config file ${path}: ${err.message}`)\n }\n }\n }\n\n return {}\n}\n"],"mappings":";;;AAAA,OAAO;AACP,SAAS,eAAe;AACxB;AAAA,EACI,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,YAAY,sBAAsB;;;ACV3C,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAUxB,eAAsB,WAAW,YAAsC;AACnE,QAAM,OAAO,WAAW,YAAY,GAAG;AAEvC,MAAI,YAAY;AACZ,UAAM,WAAW,QAAQ,QAAQ,IAAI,GAAG,UAAU;AAClD,QAAI,CAAC,WAAW,QAAQ,GAAG;AACvB,YAAM,IAAI,MAAM,4BAA4B,QAAQ,EAAE;AAAA,IAC1D;AACA,UAAM,SAAS,MAAM,KAAK,OAAO,QAAQ;AACzC,YAAQ,IAAI,6BAA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;AAEA,oBAAgB,MAAM;AAEtB,QAAI,QAAQ,KAAK;AACb,oBAAcA,SAAQ,QAAQ,IAAI,GAAG,QAAQ,GAAG,GAAG,aAAa,MAAM,CAAC;AAAA,IAC3E;AAAA,EACJ,SAAS,KAAU;AACf,YAAQ,MAAM;AAAA,gBAAc,IAAI,OAAO,EAAE;AACzC,YAAQ,KAAK,CAAC;AAAA,EAClB;AACJ,CAAC;AAEL,QAAQ,QAAQ,SAAS,EACpB,YAAY,4CAA4C,EACxD,OAAO,OAAO,YAAY;AAEvB,QAAM,UAAU,QAAQ,SAAS,KAAK,OAAK,EAAE,KAAK,MAAM,MAAM;AAC9D,QAAM,SAAS,WAAW,CAAC,aAAa,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,OAAO,CAAC;AACvF,CAAC;AAEL,QAAQ,QAAQ,OAAO,EAClB,YAAY,qBAAqB,EACjC,OAAO,cAAc,4BAA4B,EACjD,OAAO,sBAAsB,4CAA4C,EACzE,OAAO,OAAO,YAAY;AACvB,UAAQ,IAAI,uBAAuB;AAEvC,CAAC;AAEL,QAAQ,QAAQ,YAAY,EACvB,YAAY,kDAAkD,EAC9D,OAAO,cAAc,4BAA4B,EACjD,OAAO,OAAO,YAAY;AACvB,UAAQ,IAAI,2BAA2B;AAE3C,CAAC;AAEL,QAAQ,MAAM;","names":["resolve"]}
package/dist/index.js CHANGED
@@ -6,15 +6,29 @@ import { existsSync } from "fs";
6
6
  import { resolve } from "path";
7
7
  async function loadConfig(configPath) {
8
8
  const jiti = createJiti(import.meta.url);
9
- const paths = configPath ? [resolve(process.cwd(), configPath)] : [
9
+ if (configPath) {
10
+ const fullPath = resolve(process.cwd(), configPath);
11
+ if (!existsSync(fullPath)) {
12
+ throw new Error(`Config file not found at ${fullPath}`);
13
+ }
14
+ const module = await jiti.import(fullPath);
15
+ console.log(`\u2705 Loaded config from ${configPath}`);
16
+ return module.default || module;
17
+ }
18
+ const defaultPaths = [
10
19
  resolve(process.cwd(), "seed.config.ts"),
11
20
  resolve(process.cwd(), "seed.config.js"),
12
21
  resolve(process.cwd(), "seed.config.mjs")
13
22
  ];
14
- for (const path of paths) {
23
+ for (const path of defaultPaths) {
15
24
  if (existsSync(path)) {
16
- const module = await jiti.import(path);
17
- return module.default || module;
25
+ try {
26
+ const module = await jiti.import(path);
27
+ console.log(`\u2705 Loaded config from ${path}`);
28
+ return module.default || module;
29
+ } catch (err) {
30
+ throw new Error(`Failed to load config file ${path}: ${err.message}`);
31
+ }
18
32
  }
19
33
  }
20
34
  return {};
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.mts","../src/index.ts"],"sourcesContent":["import { createJiti } from 'jiti'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { type SeedOptions } from 'schema-seed-core'\nimport { type MongoSeedConfig } from 'schema-seed-core/mongo'\n\nexport type Config = (SeedOptions & {\n db?: string\n dbType?: string\n overrides?: Record<string, any>\n}) | MongoSeedConfig\n\nexport async function loadConfig(configPath?: string): Promise<Config> {\n const jiti = createJiti(import.meta.url)\n const paths = configPath\n ? [resolve(process.cwd(), configPath)]\n : [\n resolve(process.cwd(), 'seed.config.ts'),\n resolve(process.cwd(), 'seed.config.js'),\n resolve(process.cwd(), 'seed.config.mjs'),\n ]\n\n for (const path of paths) {\n if (existsSync(path)) {\n const module = await jiti.import(path) as any\n return module.default || module\n }\n }\n\n return {}\n}\n","import { Config } from './config.mjs'\nexport { Config } from './config.mjs'\n\nexport function defineConfig(config: Config): Config {\n return config\n}\n\nexport { loadConfig } from './config.mjs'\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAUxB,eAAsB,WAAW,YAAsC;AACnE,QAAM,OAAO,WAAW,YAAY,GAAG;AACvC,QAAM,QAAQ,aACR,CAAC,QAAQ,QAAQ,IAAI,GAAG,UAAU,CAAC,IACnC;AAAA,IACE,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,IAAI,GAAG,iBAAiB;AAAA,EAC5C;AAEJ,aAAW,QAAQ,OAAO;AACtB,QAAI,WAAW,IAAI,GAAG;AAClB,YAAM,SAAS,MAAM,KAAK,OAAO,IAAI;AACrC,aAAO,OAAO,WAAW;AAAA,IAC7B;AAAA,EACJ;AAEA,SAAO,CAAC;AACZ;;;AC3BO,SAAS,aAAa,QAAwB;AACjD,SAAO;AACX;","names":[]}
1
+ {"version":3,"sources":["../src/config.mts","../src/index.ts"],"sourcesContent":["import { createJiti } from 'jiti'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { type SeedOptions } from 'schema-seed-core'\nimport { type MongoSeedConfig } from 'schema-seed-core/mongo'\n\nexport type Config = (SeedOptions & {\n db?: string\n dbType?: string\n overrides?: Record<string, any>\n}) | MongoSeedConfig\n\nexport async function loadConfig(configPath?: string): Promise<Config> {\n const jiti = createJiti(import.meta.url)\n\n if (configPath) {\n const fullPath = resolve(process.cwd(), configPath)\n if (!existsSync(fullPath)) {\n throw new Error(`Config file not found at ${fullPath}`)\n }\n const module = await jiti.import(fullPath) as any\n console.log(`✅ Loaded config from ${configPath}`)\n return module.default || module\n }\n\n const defaultPaths = [\n resolve(process.cwd(), 'seed.config.ts'),\n resolve(process.cwd(), 'seed.config.js'),\n resolve(process.cwd(), 'seed.config.mjs'),\n ]\n\n for (const path of defaultPaths) {\n if (existsSync(path)) {\n try {\n const module = await jiti.import(path) as any\n console.log(`✅ Loaded config from ${path}`)\n return module.default || module\n } catch (err: any) {\n throw new Error(`Failed to load config file ${path}: ${err.message}`)\n }\n }\n }\n\n return {}\n}\n","import { Config } from './config.mjs'\nexport { Config } from './config.mjs'\n\nexport function defineConfig(config: Config): Config {\n return config\n}\n\nexport { loadConfig } from './config.mjs'\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAUxB,eAAsB,WAAW,YAAsC;AACnE,QAAM,OAAO,WAAW,YAAY,GAAG;AAEvC,MAAI,YAAY;AACZ,UAAM,WAAW,QAAQ,QAAQ,IAAI,GAAG,UAAU;AAClD,QAAI,CAAC,WAAW,QAAQ,GAAG;AACvB,YAAM,IAAI,MAAM,4BAA4B,QAAQ,EAAE;AAAA,IAC1D;AACA,UAAM,SAAS,MAAM,KAAK,OAAO,QAAQ;AACzC,YAAQ,IAAI,6BAAwB,UAAU,EAAE;AAChD,WAAO,OAAO,WAAW;AAAA,EAC7B;AAEA,QAAM,eAAe;AAAA,IACjB,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,IAAI,GAAG,iBAAiB;AAAA,EAC5C;AAEA,aAAW,QAAQ,cAAc;AAC7B,QAAI,WAAW,IAAI,GAAG;AAClB,UAAI;AACA,cAAM,SAAS,MAAM,KAAK,OAAO,IAAI;AACrC,gBAAQ,IAAI,6BAAwB,IAAI,EAAE;AAC1C,eAAO,OAAO,WAAW;AAAA,MAC7B,SAAS,KAAU;AACf,cAAM,IAAI,MAAM,8BAA8B,IAAI,KAAK,IAAI,OAAO,EAAE;AAAA,MACxE;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,CAAC;AACZ;;;ACzCO,SAAS,aAAa,QAAwB;AACjD,SAAO;AACX;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-seed",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "CLI for schema-seed",
6
6
  "author": "Ali Nazar",
@@ -40,20 +40,20 @@
40
40
  "commander": "^12.1.0",
41
41
  "dotenv": "^17.2.3",
42
42
  "jiti": "^2.6.1",
43
- "schema-seed-core": "0.1.4",
44
- "schema-seed-generators": "0.1.4"
43
+ "schema-seed-core": "0.1.5",
44
+ "schema-seed-generators": "0.1.5"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^20.19.27",
48
48
  "tsup": "^8.3.5",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^2.1.8",
51
- "schema-seed-adapter-mongodb": "0.1.4",
52
- "schema-seed-adapter-mysql": "0.1.4",
53
- "schema-seed-adapter-postgres": "0.1.4",
54
- "schema-seed-adapter-sqlite": "0.1.4",
55
- "schema-seed-adapter-mssql": "0.1.4",
56
- "schema-seed-adapter-oracle": "0.1.4"
51
+ "schema-seed-adapter-mongodb": "0.1.5",
52
+ "schema-seed-adapter-mysql": "0.1.5",
53
+ "schema-seed-adapter-postgres": "0.1.5",
54
+ "schema-seed-adapter-sqlite": "0.1.5",
55
+ "schema-seed-adapter-mssql": "0.1.5",
56
+ "schema-seed-adapter-oracle": "0.1.5"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",