@duraxis/cli 0.3.0 → 0.4.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/CHANGELOG.md +10 -0
- package/README.md +16 -53
- package/dist/admin.command-Chb6x9mF.js +413 -0
- package/dist/admin.command-Chb6x9mF.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/commands/admin.command.d.ts +3 -0
- package/dist/commands/doctor.command.d.ts +10 -0
- package/dist/commands/init.command.d.ts +3 -0
- package/dist/commands/migration.command.d.ts +3 -0
- package/dist/config-CjMUqEhV.js +165 -0
- package/dist/config-CjMUqEhV.js.map +1 -0
- package/dist/config.d.ts +6 -2
- package/dist/dependencies/configured-registry.d.ts +3 -0
- package/dist/dependencies/dependency-resolver.d.ts +2 -0
- package/dist/dependencies/installed-package.d.ts +1 -0
- package/dist/dependencies/package-manager.d.ts +10 -0
- package/dist/dependencies/registry-client.d.ts +21 -0
- package/dist/dependencies/version-compatibility.d.ts +9 -0
- package/dist/filesystem/file-plan.d.ts +32 -0
- package/dist/index.js +365 -550
- package/dist/index.js.map +1 -1
- package/dist/init/initialization-options.d.ts +32 -0
- package/dist/init/initialization-planner.d.ts +7 -0
- package/dist/init/managed-project.d.ts +9 -0
- package/dist/init/project-detector.d.ts +27 -0
- package/dist/init.command-B2kKoyfi.js +172 -0
- package/dist/init.command-B2kKoyfi.js.map +1 -0
- package/dist/migration.command-N7ahyx92.js +361 -0
- package/dist/migration.command-N7ahyx92.js.map +1 -0
- package/dist/package-manager-BBRBhsIe.js +972 -0
- package/dist/package-manager-BBRBhsIe.js.map +1 -0
- package/dist/registry/argument-parser.d.ts +65 -0
- package/dist/registry/command-registry.d.ts +198 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/dist/templates/project.d.ts +8 -0
- package/dist/terminal/prompts.d.ts +2 -0
- package/package.json +8 -3
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/runtime.mjs","../src/typescript-loader.ts","../src/config.ts","../src/artifacts.ts","../src/cli.ts"],"sourcesContent":["export const MINIMUM_NODE_VERSION = \"24.15.0\";\n\n/** Reject unsupported runtimes before importing the CLI and its Node.js APIs. */\nexport function assertSupportedRuntime(version = process.versions.node) {\n const actual = version.split(\".\").map(Number);\n const minimum = MINIMUM_NODE_VERSION.split(\".\").map(Number);\n const difference = actual.findIndex((part, index) => part !== minimum[index]);\n const supported =\n /^\\d+\\.\\d+\\.\\d+$/.test(version) &&\n (difference === -1 || actual[difference] > minimum[difference]);\n if (!supported)\n throw new Error(\n `Duraxis requires Node.js ${MINIMUM_NODE_VERSION} or newer.\\nCurrent version: ${version}\\nPlease upgrade your Node.js installation.`,\n );\n}\n","import { readFileSync, statSync } from \"node:fs\";\nimport { registerHooks, type ModuleHooks } from \"node:module\";\nimport { extname } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport ts from \"typescript\";\nimport { assertSupportedRuntime } from \"./runtime.mjs\";\n\nconst sourceExtensions: Readonly<Record<string, string>> = {\n \".js\": \".ts\",\n \".mjs\": \".mts\",\n \".cjs\": \".cts\",\n};\nlet hooks: ModuleHooks | undefined;\nconst modules = new Set<string>();\n\nfunction localFile(value: string): URL | undefined {\n if (!value.startsWith(\"file:\")) return;\n const url = new URL(value);\n const path = fileURLToPath(url);\n if (path.split(/[\\\\/]/).includes(\"node_modules\")) return;\n return url;\n}\nfunction exists(url: URL): boolean {\n try {\n return statSync(url).isFile();\n } catch (error) {\n if ([\"ENOENT\", \"ENOTDIR\"].includes((error as NodeJS.ErrnoException).code ?? \"\")) return false;\n throw error;\n }\n}\nfunction remember(url: string): void {\n if (localFile(url)) modules.add(url);\n}\n\n/** One hook pair per library instance, limited to explicitly loaded local module graphs. */\nexport function initializeTypeScriptLoader(entry: URL): void {\n assertSupportedRuntime();\n remember(entry.href);\n if (hooks) return;\n hooks = registerHooks({\n resolve(specifier, context, nextResolve) {\n const relative = /^(?:\\.{1,2}[\\\\/]|\\/|file:)/.test(specifier);\n const managed =\n relative &&\n (modules.has(specifier) ||\n (context.parentURL !== undefined && modules.has(context.parentURL)));\n try {\n const resolved = nextResolve(specifier, context);\n if (managed) remember(resolved.url);\n return resolved;\n } catch (error) {\n if (\n !managed ||\n ![\"ERR_MODULE_NOT_FOUND\", \"MODULE_NOT_FOUND\"].includes(\n (error as NodeJS.ErrnoException).code ?? \"\",\n )\n )\n throw error;\n const requested = localFile(new URL(specifier, context.parentURL).href);\n if (!requested || exists(requested)) throw error;\n const path = fileURLToPath(requested);\n const extension = extname(path);\n const mapped = sourceExtensions[extension];\n if (!mapped) throw error;\n const candidate = pathToFileURL(path.slice(0, -extension.length) + mapped);\n candidate.search = requested.search;\n candidate.hash = requested.hash;\n if (!exists(candidate)) throw error;\n const resolved = nextResolve(\n context.conditions.includes(\"require\") ? fileURLToPath(candidate) : candidate.href,\n context,\n );\n remember(resolved.url);\n return resolved;\n }\n },\n load(url, context, nextLoad) {\n if (!modules.has(url)) return nextLoad(url, context);\n const file = localFile(url);\n if (!file) return nextLoad(url, context);\n const path = fileURLToPath(file);\n if (!/\\.(?:ts|mts|cts)$/.test(path) || /\\.d\\.(?:ts|mts|cts)$/.test(path))\n return nextLoad(url, context);\n const commonjs = path.endsWith(\".cts\");\n const result = ts.transpileModule(readFileSync(file, \"utf8\"), {\n fileName: path,\n reportDiagnostics: true,\n compilerOptions: {\n target: ts.ScriptTarget.ES2022,\n module: commonjs ? ts.ModuleKind.NodeNext : ts.ModuleKind.ESNext,\n ...(commonjs ? { moduleResolution: ts.ModuleResolutionKind.NodeNext } : {}),\n experimentalDecorators: true,\n emitDecoratorMetadata: true,\n useDefineForClassFields: false,\n sourceMap: false,\n },\n });\n const errors = (result.diagnostics ?? []).filter(\n (item) => item.category == ts.DiagnosticCategory.Error,\n );\n if (errors.length)\n throw new Error(\n ts.formatDiagnosticsWithColorAndContext(errors, {\n getCurrentDirectory: () => process.cwd(),\n getCanonicalFileName: (file) => file,\n getNewLine: () => \"\\n\",\n }),\n );\n // Imported CommonJS source otherwise receives the ESM translator's synthetic\n // require, which bypasses customization hooks. Use Node's hook-aware require.\n return {\n format: commonjs ? \"commonjs\" : \"module\",\n source:\n (commonjs\n ? '\"use strict\";\\nrequire = require(\"node:module\").createRequire(__filename);\\n'\n : \"\") + result.outputText,\n shortCircuit: true,\n };\n },\n });\n}\n\n/** Call only when no config/entity/migration callbacks need further dynamic imports. Node's module cache is retained. */\nexport function disposeTypeScriptLoader(): void {\n hooks?.deregister();\n hooks = undefined;\n // Retain graph identity alongside Node's module cache so cached callbacks can\n // resolve further imports after a later initialization.\n}\n","import { access, readFile } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\nimport { initializeTypeScriptLoader } from \"./typescript-loader.js\";\nimport { pathToFileURL } from \"node:url\";\nimport type { DuraxisDatabase } from \"@duraxis/core\";\nimport type { EntityClass } from \"@duraxis/orm\";\n\nexport interface DuraxisConnectionConfig {\n readonly entities:\n readonly EntityClass[] | (() => readonly EntityClass[] | Promise<readonly EntityClass[]>);\n readonly migrations: {\n readonly directory: string;\n readonly snapshots: string;\n readonly format?: \"ts\" | \"js\";\n };\n readonly createDatabase: () => DuraxisDatabase | Promise<DuraxisDatabase>;\n}\n\nexport interface DuraxisConfig extends DuraxisConnectionConfig {\n readonly databases?: Readonly<Record<string, DuraxisConnectionConfig>>;\n}\n\nexport function defineDuraxisConfig<const T extends DuraxisConfig>(config: T): T {\n return config;\n}\n\nexport async function importFile(path: string | URL): Promise<unknown> {\n const url = path instanceof URL ? path : pathToFileURL(path);\n initializeTypeScriptLoader(url);\n return import(url.href);\n}\n\nexport async function loadConfig(\n cwd: string,\n explicit?: string,\n database?: string,\n): Promise<{ config: DuraxisConnectionConfig; root: string; path: string }> {\n let path: string | undefined;\n\n if (explicit) path = resolve(cwd, explicit);\n else {\n let directory = resolve(cwd);\n\n while (true) {\n for (const name of [\n \"duraxis.config.ts\",\n \"duraxis.config.mts\",\n \"duraxis.config.js\",\n \"duraxis.config.mjs\",\n \"duraxis.config.cts\",\n \"duraxis.config.cjs\",\n ]) {\n const candidate = resolve(directory, name);\n\n try {\n await access(candidate);\n\n path = candidate;\n\n break;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code != \"ENOENT\") throw error;\n }\n }\n\n if (path || dirname(directory) == directory) break;\n\n directory = dirname(directory);\n }\n }\n\n if (!path) throw new Error(\"No duraxis.config.ts or JavaScript configuration found\");\n\n const module = (await importFile(path)) as { default?: DuraxisConfig };\n\n const base = module.default;\n\n const config = database ? base?.databases?.[database] : base;\n\n if (\n !config ||\n typeof config.createDatabase != \"function\" ||\n (!Array.isArray(config.entities) && typeof config.entities != \"function\") ||\n typeof config.migrations?.directory != \"string\" ||\n typeof config.migrations.snapshots != \"string\" ||\n (config.migrations.format !== undefined && ![\"ts\", \"js\"].includes(config.migrations.format))\n )\n throw new Error(\"Invalid Duraxis configuration or unknown named database\");\n\n return { config, root: dirname(path), path };\n}\n\nexport async function readJSON<T>(path: string): Promise<T> {\n return JSON.parse(await readFile(path, \"utf8\")) as T;\n}\n","import { randomBytes } from \"node:crypto\";\nimport { access, mkdir, readdir, readFile, writeFile, unlink, rename } from \"node:fs/promises\";\nimport { resolve, join } from \"node:path\";\nimport ts from \"typescript\";\nimport {\n checksum,\n canonicalJSON,\n createSnapshot,\n validateSnapshot,\n validateMigrationId,\n validateArtifacts,\n type DuraxisMigration,\n type MigrationArtifact,\n type SchemaSnapshot,\n type SchemaPlan,\n diffSchemas,\n} from \"@duraxis/migrations\";\nimport type { CollectionDefinition } from \"@duraxis/core\";\nimport { importFile, readJSON, type DuraxisConnectionConfig } from \"./config.js\";\n\nexport function artifactChecksum(source: string): string {\n const options: ts.TranspileOptions = {\n compilerOptions: {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.ESNext,\n removeComments: true,\n newLine: ts.NewLineKind.LineFeed,\n experimentalDecorators: true,\n emitDecoratorMetadata: true,\n useDefineForClassFields: false,\n },\n };\n\n const first = ts.transpileModule(source, options).outputText;\n\n return checksum(ts.transpileModule(first, options).outputText);\n}\n\nexport interface LocalArtifacts {\n readonly artifacts: readonly MigrationArtifact[];\n readonly files: readonly string[];\n readonly snapshots: string;\n readonly directory: string;\n}\n\nexport async function loadArtifacts(\n config: DuraxisConnectionConfig,\n root: string,\n ownsLock = false,\n omitLatest = false,\n): Promise<LocalArtifacts> {\n const directory = resolve(root, config.migrations.directory);\n const snapshots = resolve(root, config.migrations.snapshots);\n\n if (!ownsLock)\n try {\n await access(join(directory, \".duraxis-artifacts.lock\"));\n throw new Error(\n \"Artifact update in progress or stale guard; inspect artifacts before removing the guard\",\n );\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code != \"ENOENT\") throw error;\n }\n\n const files = (await readdir(directory))\n .filter((file) => /\\.(ts|mts|js|mjs)$/.test(file) && !/\\.d\\.(?:ts|mts)$/.test(file))\n .sort();\n\n const artifacts: MigrationArtifact[] = [];\n\n const ids = new Set<string>();\n\n for (const file of files) {\n const id = file.replace(/\\.(ts|mts|js|mjs)$/, \"\");\n\n validateMigrationId(id);\n\n if (ids.has(id)) throw new Error(`Duplicate migration filename: ${id}`);\n\n ids.add(id);\n\n if (omitLatest && file == files.at(-1)) continue;\n\n const source = await readFile(join(directory, file), \"utf8\");\n const module = (await importFile(join(directory, file))) as { default: DuraxisMigration };\n\n if (module.default?.id != id) throw new Error(`Migration ID does not match filename: ${file}`);\n\n const snapshot = await readJSON<SchemaSnapshot>(join(snapshots, `${id}.json`));\n\n validateSnapshot(snapshot);\n\n artifacts.push({ migration: module.default, checksum: artifactChecksum(source), snapshot });\n }\n\n const expected = new Set([...ids].map((id) => `${id}.json`));\n\n for (const file of await readdir(snapshots))\n if (file.endsWith(\".json\") && file != \"baseline.json\" && !expected.has(file))\n throw new Error(`Orphaned snapshot: ${file}`);\n\n const initial = await readJSON<SchemaSnapshot>(join(snapshots, \"baseline.json\"));\n\n validateSnapshot(initial);\n\n if (\n initial.migrationId !== null ||\n initial.parentMigrationId !== null ||\n initial.collections.length\n )\n throw new Error(\"Invalid empty baseline snapshot\");\n\n validateArtifacts(artifacts);\n\n return { artifacts, files, snapshots, directory };\n}\nexport function migrationId(name: string, previous?: string): string {\n if (name.includes(\"..\") || /[\\\\/]/.test(name))\n throw new Error(\"Migration names cannot contain paths\");\n\n const slug = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\");\n\n if (!slug || slug.length > 64) throw new Error(\"Invalid migration name\");\n\n const stamp = new Date().toISOString().replace(/\\D/g, \"\");\n\n const previousStamp = previous?.slice(0, 17);\n\n const prefix =\n previousStamp && previousStamp >= stamp\n ? (BigInt(previousStamp) + 1n).toString().padStart(17, \"0\")\n : stamp;\n\n return `${prefix}_${slug}`;\n}\n\nfunction literal(value: unknown): string {\n return JSON.stringify(value, null, 2)\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\n\nexport function renderMigration(id: string, plan?: SchemaPlan): string {\n if (!plan)\n return `import { defineMigration } from \"@duraxis/migrations\";\\n\\nexport default defineMigration({\\n id: ${JSON.stringify(id)},\\n async up(context) {\\n throw new Error(\"Unfinished migration: implement up and provide its expected snapshot\");\\n },\\n});\\n`;\n\n const inverse = diffSchemas(plan.after, plan.before);\n\n const reversible =\n !plan.operations.some(\n (operation) => operation.kind == \"collection\" && operation.after == null,\n ) && inverse.operations.every((operation) => operation.risk != \"requires-data-transformation\");\n\n return `import { defineMigration, applySchemaPlan } from \"@duraxis/migrations\";\\n\\nexport default defineMigration({\\n id: ${JSON.stringify(id)},\\n async up(context) {\\n await applySchemaPlan(context, ${literal(plan)});\\n },\\n${\n reversible\n ? ` async down(context) {\\n${inverse.operations\n .filter((operation) => operation.kind == \"collection\" && operation.after == null)\n .map(\n (operation) =>\n ` for await (const row of context.scan(${JSON.stringify(operation.collection)})) throw new Error(\"Cannot drop a populated collection during generated rollback\");\\n`,\n )\n .join(\"\")} await applySchemaPlan(context, ${literal(inverse)});\\n },\\n`\n : \" // Irreversible automatically: write an explicit data-safe down() if needed.\\n\"\n } });\\n`;\n}\n\nexport async function withArtifactLock<T>(\n directory: string,\n callback: () => Promise<T>,\n): Promise<T> {\n await mkdir(directory, { recursive: true });\n\n const lock = join(directory, \".duraxis-artifacts.lock\");\n\n await writeFile(\n lock,\n canonicalJSON({\n pid: process.pid,\n purpose: \"artifact update; inspect files before removing a stale guard\",\n }),\n { flag: \"wx\" },\n );\n\n try {\n return await callback();\n } finally {\n await unlink(lock);\n }\n}\n\nexport async function writePair(\n migrationPath: string,\n source: string,\n snapshotPath: string,\n snapshot: SchemaSnapshot,\n): Promise<void> {\n await mkdir(resolve(snapshotPath, \"..\"), { recursive: true });\n await writeFile(migrationPath, source, { flag: \"wx\" });\n\n try {\n await writeFile(snapshotPath, JSON.stringify(snapshot, null, 2) + \"\\n\", { flag: \"wx\" });\n } catch (error) {\n await unlink(migrationPath);\n throw error;\n }\n}\n\nexport async function removePair(migrationPath: string, snapshotPath: string): Promise<void> {\n const suffix = `.removing-${randomBytes(6).toString(\"hex\")}`;\n await rename(migrationPath, migrationPath + suffix);\n\n try {\n await rename(snapshotPath, snapshotPath + suffix);\n } catch (error) {\n await rename(migrationPath + suffix, migrationPath);\n throw error;\n }\n\n await unlink(migrationPath + suffix);\n await unlink(snapshotPath + suffix);\n}\n\nexport function snapshotFor(\n id: string,\n parent: string | null,\n schema: readonly CollectionDefinition[],\n): SchemaSnapshot {\n return createSnapshot(id, parent, schema);\n}\n","import { parseArgs } from \"node:util\";\nimport { access, mkdir, writeFile, unlink } from \"node:fs/promises\";\nimport { resolve, join } from \"node:path\";\nimport { exportSchema } from \"@duraxis/orm\";\nimport {\n MigrationRunner,\n validateArtifacts,\n createSnapshot,\n diffSchemas,\n schemaHash,\n type SchemaSnapshot,\n type SchemaPlan,\n} from \"@duraxis/migrations\";\nimport {\n CommitOutcomeUnknownError,\n ResourceExhaustedError,\n OperationCancelledError,\n type CollectionDefinition,\n type DuraxisDatabase,\n} from \"@duraxis/core\";\nimport { loadConfig, readJSON, type DuraxisConnectionConfig } from \"./config.js\";\nimport {\n artifactChecksum,\n loadArtifacts,\n migrationId,\n renderMigration,\n withArtifactLock,\n writePair,\n removePair,\n} from \"./artifacts.js\";\n\nexport interface CLIIO {\n readonly cwd?: string;\n readonly out?: (message: string) => void;\n readonly error?: (message: string) => void;\n}\n\nconst help = `duraxis <command> [options]\n init\n migration:create <name>\n migration:generate <name> [--allow-destructive]\n migration:snapshot --schema <collections.json>\n migration:remove --yes\n migration:baseline <name> --yes\n migrate:up [--steps N | --to ID] [--dry-run] [--allow-destructive]\n migrate:down [--steps N | --to ID] --yes\n migrate:status\n migrate:diff [--persisted]\n migrate:check [--offline]\nOptions: --config PATH --database NAME --json\nRollback --to retains the target version. Dry-run is a static preview only.`;\n\nasync function withDatabase<T>(\n config: DuraxisConnectionConfig,\n callback: (database: DuraxisDatabase) => Promise<T>,\n): Promise<T> {\n const database = await config.createDatabase();\n\n try {\n return await callback(database);\n } finally {\n await database.close({ closeStorage: true });\n }\n}\n\nfunction summary(plan: SchemaPlan): string {\n return plan.operations.length\n ? plan.operations\n .map(\n (operation) =>\n `${operation.before == null ? \"+\" : operation.after == null ? \"-\" : \"~\"} ${operation.kind} ${operation.collection}/${operation.name} (${operation.risk})`,\n )\n .join(\"\\n\")\n : \"No schema differences.\";\n}\n\nasync function init(cwd: string): Promise<void> {\n const configPath = resolve(cwd, \"duraxis.config.ts\");\n const base = resolve(cwd, \"duraxis/snapshots/baseline.json\");\n\n for (const path of [configPath, base])\n try {\n await access(path);\n throw new Error(`Refusing to overwrite ${path}`);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code != \"ENOENT\") throw error;\n }\n\n await mkdir(resolve(cwd, \"duraxis/migrations\"), { recursive: true });\n await mkdir(resolve(cwd, \"duraxis/snapshots\"), { recursive: true });\n\n await writeFile(\n configPath,\n `import { defineDuraxisConfig } from \"@duraxis/cli\";\n\nexport default defineDuraxisConfig({\n entities: [], // Import your decorated entity classes here.\n migrations: { directory: \"./duraxis/migrations\", snapshots: \"./duraxis/snapshots\", format: \"ts\" },\n async createDatabase() {\n // Return a DuraxisDatabase configured with your storage driver.\n // The CLI closes this database and its storage after every command.\n throw new Error(\"Configure createDatabase() before accessing a database\");\n },\n});\n`,\n { flag: \"wx\" },\n );\n\n try {\n await writeFile(base, JSON.stringify(createSnapshot(null, null, []), null, 2) + \"\\n\", {\n flag: \"wx\",\n });\n } catch (error) {\n await unlink(configPath);\n throw error;\n }\n}\n\nexport async function runCLI(args: readonly string[], io: CLIIO = {}): Promise<number> {\n const cwd = io.cwd ?? process.cwd();\n const out = io.out ?? console.log;\n\n const errorOut = io.error ?? console.error;\n\n let jsonErrors = false;\n\n try {\n const { values, positionals } = parseArgs({\n args: [...args],\n allowPositionals: true,\n strict: true,\n options: {\n config: { type: \"string\" },\n database: { type: \"string\" },\n json: { type: \"boolean\" },\n steps: { type: \"string\" },\n to: { type: \"string\" },\n \"dry-run\": { type: \"boolean\" },\n \"allow-destructive\": { type: \"boolean\" },\n yes: { type: \"boolean\" },\n offline: { type: \"boolean\" },\n persisted: { type: \"boolean\" },\n schema: { type: \"string\" },\n help: { type: \"boolean\" },\n },\n });\n\n jsonErrors = values.json ?? false;\n\n const command = positionals[0];\n const name = positionals[1];\n\n if (!command || values.help) {\n out(help);\n return 0;\n }\n\n const commands = [\n \"init\",\n \"migration:create\",\n \"migration:generate\",\n \"migration:snapshot\",\n \"migration:remove\",\n \"migration:baseline\",\n \"migrate:up\",\n \"migrate:down\",\n \"migrate:status\",\n \"migrate:diff\",\n \"migrate:check\",\n ];\n\n if (!commands.includes(command)) throw new Error(`Unknown command: ${command}`);\n\n if (\n positionals.length > 2 ||\n (name && ![\"migration:create\", \"migration:generate\", \"migration:baseline\"].includes(command))\n )\n throw new Error(\"Unexpected positional arguments\");\n\n const allowed: Record<string, readonly string[]> = {\n init: [],\n \"migration:create\": [],\n \"migration:generate\": [\"allow-destructive\"],\n \"migration:snapshot\": [\"schema\"],\n \"migration:remove\": [\"yes\"],\n \"migration:baseline\": [\"yes\"],\n \"migrate:up\": [\"steps\", \"to\", \"dry-run\", \"allow-destructive\"],\n \"migrate:down\": [\"steps\", \"to\", \"yes\"],\n \"migrate:status\": [],\n \"migrate:diff\": [\"persisted\"],\n \"migrate:check\": [\"offline\"],\n };\n\n for (const option of Object.keys(values))\n if (![\"config\", \"database\", \"json\", \"help\", ...allowed[command]].includes(option))\n throw new Error(`Option --${option} is not supported by ${command}`);\n\n if (command == \"init\") {\n await init(cwd);\n out(\n \"Initialized duraxis.config.ts and migration directories. Configure entities and createDatabase().\",\n );\n return 0;\n }\n\n const { config, root } = await loadConfig(cwd, values.config, values.database);\n\n const directory = resolve(root, config.migrations.directory);\n const snapshots = resolve(root, config.migrations.snapshots);\n\n const print = (value: unknown, text: string) =>\n out(values.json ? JSON.stringify(value, null, 2) : text);\n\n const entities = async () =>\n exportSchema(\n typeof config.entities == \"function\" ? await config.entities() : config.entities,\n );\n\n if (command == \"migration:snapshot\") {\n if (!values.schema)\n throw new Error(\"Provide --schema with a JSON array of expected collection definitions\");\n\n await withArtifactLock(directory, async () => {\n const { readdir } = await import(\"node:fs/promises\");\n\n const files = (await readdir(directory))\n .filter((file) => /\\.(ts|mts|js|mjs)$/.test(file) && !/\\.d\\.(?:ts|mts)$/.test(file))\n .sort();\n\n const latest = files.at(-1);\n\n if (!latest) throw new Error(\"No manual migration found\");\n\n const id = latest.replace(/\\.(ts|mts|js|mjs)$/, \"\");\n\n const parent = files.at(-2)?.replace(/\\.(ts|mts|js|mjs)$/, \"\") ?? null;\n\n if (parent) {\n const previous = await readJSON<SchemaSnapshot>(join(snapshots, `${parent}.json`));\n if (previous.migrationId != parent) throw new Error(\"Invalid predecessor snapshot\");\n }\n\n const definitions = await readJSON<readonly CollectionDefinition[]>(\n resolve(cwd, values.schema!),\n );\n\n await writeFile(\n join(snapshots, `${id}.json`),\n JSON.stringify(createSnapshot(id, parent, definitions), null, 2) + \"\\n\",\n { flag: \"wx\" },\n );\n });\n\n out(\"Saved intended manual snapshot. migrate:up verifies the actual result atomically.\");\n\n return 0;\n }\n\n if ([\"migration:create\", \"migration:generate\", \"migration:baseline\"].includes(command)) {\n if (!name) throw new Error(\"A migration name is required\");\n\n if (command == \"migration:baseline\" && !values.yes)\n throw new Error(\"Baseline adoption requires --yes\");\n\n await withArtifactLock(directory, async () => {\n const local = await loadArtifacts(config, root, true);\n const previous = local.artifacts.at(-1);\n\n const id = migrationId(name, previous?.migration.id);\n const migrationPath = join(directory, `${id}.${config.migrations.format ?? \"ts\"}`);\n\n if (command == \"migration:create\") {\n await writeFile(migrationPath, renderMigration(id), { flag: \"wx\" });\n print(\n { id, unfinished: true },\n `Created ${id}. Implement up(), then use migration:snapshot --schema <collections.json>.`,\n );\n return;\n }\n\n const desired = await entities();\n\n const before = previous?.snapshot.collections ?? [];\n const plan = diffSchemas(before, desired);\n\n if (command == \"migration:baseline\" && local.artifacts.length) {\n if (local.artifacts.length != 1)\n throw new Error(\"Baseline requires exactly one initial artifact\");\n\n const initial = local.artifacts[0]!;\n const creation = diffSchemas([], desired);\n\n if (\n initial.snapshot.schemaHash != schemaHash(desired) ||\n initial.checksum != artifactChecksum(renderMigration(initial.migration.id, creation))\n )\n throw new Error(\n \"Existing baseline must be an unmodified generated initial-schema migration matching entities\",\n );\n await withDatabase(config, (database) =>\n new MigrationRunner(database, local.artifacts).baseline(),\n );\n\n out(`Registered existing baseline ${initial.migration.id}`);\n return;\n }\n\n if (!plan.operations.length) {\n print({ operations: [] }, \"No schema differences.\");\n return;\n }\n\n if (plan.operations.some((operation) => operation.risk == \"requires-data-transformation\"))\n throw new Error(\n \"Automatic generation requires a manual data transformation. Use migration:create and provide a snapshot.\",\n );\n\n if (\n plan.operations.some((operation) => operation.risk == \"destructive\") &&\n !values[\"allow-destructive\"]\n )\n throw new Error(\"Destructive generation requires --allow-destructive\");\n\n const snapshot = createSnapshot(id, previous?.migration.id ?? null, desired);\n\n if (command == \"migration:baseline\") {\n await withDatabase(config, async (database) => {\n const actual = await database.getCollectionDefinitions();\n const names = new Set(desired.map((schema) => schema.name));\n\n if (\n schemaHash(actual.filter((schema) => names.has(schema.name))) != snapshot.schemaHash\n )\n throw new Error(\"Persisted managed schema is incompatible with baseline\");\n\n await writePair(\n migrationPath,\n renderMigration(id, plan),\n join(snapshots, `${id}.json`),\n snapshot,\n );\n\n const loaded = await loadArtifacts(config, root, true);\n\n await new MigrationRunner(database, loaded.artifacts).baseline();\n });\n } else\n await writePair(\n migrationPath,\n renderMigration(id, plan),\n join(snapshots, `${id}.json`),\n snapshot,\n );\n\n print({ id, operations: plan.operations }, `Created ${id}\\n${summary(plan)}`);\n });\n\n return 0;\n }\n\n if (command == \"migration:remove\") {\n if (!values.yes)\n throw new Error(\"Removing the latest unpublished local migration requires --yes\");\n\n await withArtifactLock(directory, async () => {\n const local = await loadArtifacts(config, root, true, true);\n\n const latestFile = local.files.at(-1);\n\n const latest = latestFile?.replace(/\\.(ts|mts|js|mjs)$/, \"\");\n\n if (!latest) throw new Error(\"No local migration to remove\");\n\n await withDatabase(config, async (database) => {\n const status = await new MigrationRunner(database, local.artifacts).status();\n\n if (status.applied.some((entry) => entry.id == latest))\n throw new Error(\"Cannot remove an applied migration\");\n\n const snapshotPath = join(snapshots, `${latest}.json`);\n\n try {\n await access(snapshotPath);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code != \"ENOENT\") throw error;\n\n await unlink(join(directory, latestFile!));\n\n return;\n }\n\n await removePair(join(directory, latestFile!), snapshotPath);\n });\n\n out(\n `Removed ${latest}. This checks only the configured database; never remove shared or released migrations.`,\n );\n });\n\n return 0;\n }\n\n const local = await loadArtifacts(config, root);\n\n if (command == \"migrate:diff\" && !values.persisted) {\n const plan = diffSchemas(\n local.artifacts.at(-1)?.snapshot.collections ?? [],\n await entities(),\n );\n\n print(plan, summary(plan));\n\n return 0;\n }\n\n if (command == \"migrate:check\" && values.offline) {\n validateArtifacts(local.artifacts);\n\n const plan = diffSchemas(\n local.artifacts.at(-1)?.snapshot.collections ?? [],\n await entities(),\n );\n\n if (plan.operations.length)\n throw new Error(`Unrepresented entity changes:\\n${summary(plan)}`);\n\n print(\n { valid: true, mode: \"offline\" },\n \"Local files, snapshots, and entity schema are valid. Database history was not checked.\",\n );\n\n return 0;\n }\n\n if (command == \"migrate:up\" && values[\"dry-run\"]) {\n const steps = values.steps === undefined ? undefined : Number(values.steps);\n\n if (steps !== undefined && (!Number.isSafeInteger(steps) || steps < 0))\n throw new Error(\"Invalid steps\");\n\n if (\n values.to &&\n (!local.artifacts.some((artifact) => artifact.migration.id == values.to) ||\n steps !== undefined)\n )\n throw new Error(\"Invalid target or conflicting --steps\");\n\n const candidates = local.artifacts\n .filter((artifact) => !values.to || artifact.migration.id <= values.to)\n .slice(0, steps ?? Infinity)\n .map((artifact) => artifact.migration.id);\n\n print(\n { dryRun: true, appliedStateChecked: false, candidates },\n `Static preview only; database was not opened and applied state was not checked. Migration callbacks were not executed.\\n${candidates.join(\"\\n\")}`,\n );\n\n return 0;\n }\n\n await withDatabase(config, async (database) => {\n const runner = new MigrationRunner(database, local.artifacts);\n\n const options = {\n ...(values.steps === undefined ? {} : { steps: Number(values.steps) }),\n ...(values.to ? { to: values.to } : {}),\n allowDestructive: values[\"allow-destructive\"] ?? false,\n };\n\n if (command == \"migrate:up\") {\n const applied = await runner.up(options);\n\n print({ applied }, `Applied ${applied.length} migration(s).\\n${applied.join(\"\\n\")}`);\n } else if (command == \"migrate:down\") {\n if (!values.yes)\n throw new Error(\"Rollback requires --yes; review backups and down() first\");\n\n const reverted = await runner.down({ ...options, allowDestructive: true });\n\n print({ reverted }, `Reverted ${reverted.length} migration(s).`);\n } else if (command == \"migrate:status\") {\n const status = await runner.status();\n\n print(\n status,\n `Duraxis migration status\\nDatabase: ${values.database ?? \"default\"}\\n\\nApplied:\\n${status.applied.map((entry) => ` ${entry.id}`).join(\"\\n\")}\\nPending:\\n${status.pending.map((id) => ` ${id}`).join(\"\\n\")}\\nSchema drift: none\\n${status.applied.length} applied, ${status.pending.length} pending`,\n );\n } else if (command == \"migrate:diff\") {\n const plan = await runner.drift();\n\n print(plan, summary(plan));\n } else if (command == \"migrate:check\") {\n await runner.status();\n\n const plan = diffSchemas(\n local.artifacts.at(-1)?.snapshot.collections ?? [],\n await entities(),\n );\n\n if (plan.operations.length)\n throw new Error(`Unrepresented entity changes:\\n${summary(plan)}`);\n\n print(\n { valid: true },\n \"Migration files, snapshots, history, schema, and entities are valid.\",\n );\n }\n });\n\n return 0;\n } catch (error) {\n const message =\n error instanceof CommitOutcomeUnknownError\n ? `Commit outcome is unknown for transaction ${error.transactionId}. Reconcile migration status before retrying; do not repeat external side effects.`\n : error instanceof ResourceExhaustedError\n ? error.message\n : error instanceof OperationCancelledError\n ? \"Duraxis operation cancelled or deadline exceeded. Check configured resource deadlines and storage health.\"\n : error instanceof Error\n ? error.message\n : String(error);\n\n errorOut(jsonErrors ? JSON.stringify({ error: message }) : message);\n\n return 1;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,IAAa,uBAAuB;;AAGpC,SAAgB,uBAAuB,UAAU,QAAQ,SAAS,MAAM;CACtE,MAAM,SAAS,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC5C,MAAM,UAAU,qBAAqB,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC1D,MAAM,aAAa,OAAO,WAAW,MAAM,UAAU,SAAS,QAAQ,MAAM;CAI5E,IAAI,EAFF,kBAAkB,KAAK,OAAO,MAC7B,eAAe,MAAM,OAAO,cAAc,QAAQ,eAEnD,MAAM,IAAI,MACR,4BAA4B,qBAAqB,+BAA+B,QAAQ,4CAC1F;AACJ;;ACPA,IAAM,mBAAqD;CACzD,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AACA,IAAI;AACJ,IAAM,0BAAU,IAAI,IAA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AwB,OAAO,QAAQ,OAAO,YAAY,OAAO,QAAQ,OAAO,SAC/R;GACF,OAAO,IAAI,WAAW,gBAAgB;IACpC,MAAM,OAAO,MAAM,OAAO,MAAM;IAEhC,MAAM,MAAM,QAAQ,IAAI,CAAC;GAC3B,OAAO,IAAI,WAAW,iBAAiB;IACrC,MAAM,OAAO,OAAO;IAEpB,MAAM,OAAO,YACX,MAAM,UAAU,GAAG,EAAE,CAAC,EAAE,SAAS,eAAe,CAAC,GACjD,MAAM,SAAS,CACjB;IAEA,IAAI,KAAK,WAAW,QAClB,MAAM,IAAI,MAAM,kCAAkC,QAAQ,IAAI,GAAG;IAEnE,MACE,EAAE,OAAO,KAAK,GACd,sEACF;GACF;EACF,CAAC;EAED,OAAO;CACT,SAAS,OAAO;EACd,MAAM,UACJ,iBAAiB,4BACb,6CAA6C,MAAM,cAAc,sFACjE,iBAAiB,yBACf,MAAM,UACN,iBAAiB,0BACf,8GACA,iBAAiB,QACf,MAAM,UACN,OAAO,KAAK;EAExB,SAAS,aAAa,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC,IAAI,OAAO;EAElE,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/registry/command-registry.ts","../src/registry/argument-parser.ts","../src/cli.ts"],"sourcesContent":["export const options = {\n config: { type: \"string\" },\n database: { type: \"string\" },\n json: { type: \"boolean\" },\n help: { type: \"boolean\", short: \"h\" },\n version: { type: \"boolean\" },\n framework: { type: \"string\" },\n driver: { type: \"string\" },\n orm: { type: \"boolean\" },\n \"no-orm\": { type: \"boolean\" },\n migrations: { type: \"boolean\" },\n \"no-migrations\": { type: \"boolean\" },\n \"package-manager\": { type: \"string\" },\n language: { type: \"string\" },\n \"module-format\": { type: \"string\" },\n namespace: { type: \"string\" },\n directory: { type: \"string\" },\n \"source-dir\": { type: \"string\" },\n \"storage-directory\": { type: \"string\" },\n bucket: { type: \"string\" },\n prefix: { type: \"string\" },\n region: { type: \"string\" },\n endpoint: { type: \"string\" },\n \"force-path-style\": { type: \"boolean\" },\n \"schema-mode\": { type: \"string\" },\n example: { type: \"boolean\" },\n \"no-example\": { type: \"boolean\" },\n install: { type: \"boolean\" },\n \"no-install\": { type: \"boolean\" },\n \"dry-run\": { type: \"boolean\" },\n yes: { type: \"boolean\" },\n steps: { type: \"string\" },\n to: { type: \"string\" },\n \"allow-destructive\": { type: \"boolean\" },\n offline: { type: \"boolean\" },\n persisted: { type: \"boolean\" },\n schema: { type: \"string\" },\n live: { type: \"boolean\" },\n evaluate: { type: \"boolean\" },\n check: { type: \"boolean\" },\n apply: { type: \"boolean\" },\n registry: { type: \"string\" },\n prerelease: { type: \"boolean\" },\n \"custom-module\": { type: \"string\" },\n \"custom-export\": { type: \"string\" },\n \"custom-constructor\": { type: \"boolean\" },\n \"custom-options\": { type: \"string\" },\n \"max-stored-bytes\": { type: \"string\" },\n \"max-object-bytes\": { type: \"string\" },\n \"max-entries\": { type: \"string\" },\n \"max-metadata-bytes\": { type: \"string\" },\n \"max-journal-bytes\": { type: \"string\" },\n \"max-queued-operations\": { type: \"string\" },\n \"max-pending-operations\": { type: \"string\" },\n \"max-attempts\": { type: \"string\" },\n \"ownership-recovery\": { type: \"string\" },\n \"application-id\": { type: \"string\" },\n \"resources-file\": { type: \"string\" },\n \"cursor-key-env\": { type: \"string\" },\n} as const;\nexport type OptionName = keyof typeof options;\nexport interface CommandDefinition {\n readonly name: string;\n readonly aliases: readonly string[];\n readonly category: string;\n readonly description: string;\n readonly positional: readonly string[];\n readonly optionalPositionals?: boolean;\n readonly options: readonly OptionName[];\n readonly required: readonly OptionName[];\n readonly defaults: Readonly<Record<string, string | boolean>>;\n readonly exclusive: readonly (readonly OptionName[])[];\n readonly examples: readonly string[];\n readonly configuration: \"none\" | \"static\" | \"migration\";\n readonly database: boolean | \"conditional\";\n readonly interactive: boolean;\n readonly handler: \"init\" | \"admin\" | \"migration\" | \"help\" | \"version\";\n}\nconst initOptions: readonly OptionName[] = [\n \"framework\",\n \"driver\",\n \"orm\",\n \"no-orm\",\n \"migrations\",\n \"no-migrations\",\n \"package-manager\",\n \"language\",\n \"module-format\",\n \"namespace\",\n \"directory\",\n \"source-dir\",\n \"storage-directory\",\n \"bucket\",\n \"prefix\",\n \"region\",\n \"endpoint\",\n \"force-path-style\",\n \"schema-mode\",\n \"example\",\n \"no-example\",\n \"install\",\n \"no-install\",\n \"dry-run\",\n \"yes\",\n \"registry\",\n \"prerelease\",\n \"custom-module\",\n \"custom-export\",\n \"custom-constructor\",\n \"custom-options\",\n \"max-stored-bytes\",\n \"max-object-bytes\",\n \"max-entries\",\n \"max-metadata-bytes\",\n \"max-journal-bytes\",\n \"max-queued-operations\",\n \"max-pending-operations\",\n \"max-attempts\",\n \"resources-file\",\n \"cursor-key-env\",\n \"ownership-recovery\",\n \"application-id\",\n];\nfunction command(\n name: string,\n category: string,\n description: string,\n handler: CommandDefinition[\"handler\"],\n extra: Partial<CommandDefinition> = {},\n): CommandDefinition {\n return {\n name,\n category,\n description,\n handler,\n aliases: [],\n positional: [],\n options: [],\n required: [],\n defaults: {},\n exclusive: [],\n examples: [`duraxis ${name}`],\n configuration: \"none\",\n database: false,\n interactive: false,\n ...extra,\n };\n}\nexport const commands: readonly CommandDefinition[] = [\n command(\"init\", \"SETUP\", \"Initialize and configure Duraxis\", \"init\", {\n options: initOptions,\n interactive: true,\n defaults: {\n driver: \"disk\",\n framework: \"auto\",\n language: \"auto\",\n \"module-format\": \"auto\",\n namespace: \"default\",\n install: true,\n },\n exclusive: [\n [\"orm\", \"no-orm\"],\n [\"migrations\", \"no-migrations\"],\n [\"install\", \"no-install\"],\n [\"example\", \"no-example\"],\n ],\n examples: [\n \"duraxis init --driver disk --migrations --yes\",\n \"duraxis init --driver memory --no-orm --no-install --yes\",\n ],\n }),\n command(\n \"doctor\",\n \"SETUP\",\n \"Diagnose project and environment without executing configuration\",\n \"admin\",\n ),\n command(\n \"config:show\",\n \"CONFIGURATION\",\n \"Show redacted static configuration (or trusted code with --evaluate)\",\n \"admin\",\n { options: [\"evaluate\"], configuration: \"static\" },\n ),\n command(\n \"config:validate\",\n \"CONFIGURATION\",\n \"Validate configuration without opening storage\",\n \"admin\",\n { options: [\"evaluate\"], configuration: \"static\" },\n ),\n command(\"config:set\", \"CONFIGURATION\", \"Set a supported managed connection value\", \"admin\", {\n positional: [\"key\", \"value\"],\n options: [\"dry-run\"],\n configuration: \"static\",\n }),\n command(\"connection:add\", \"CONFIGURATION\", \"Add a managed named connection\", \"admin\", {\n positional: [\"name\"],\n options: initOptions,\n configuration: \"static\",\n }),\n command(\n \"connection:list\",\n \"CONFIGURATION\",\n \"List connections without opening databases\",\n \"admin\",\n { configuration: \"static\" },\n ),\n command(\"storage:list\", \"STORAGE\", \"List official drivers and operational limits\", \"admin\"),\n command(\n \"storage:check\",\n \"STORAGE\",\n \"Check configuration; --live opens storage read-only\",\n \"admin\",\n { options: [\"live\"], configuration: \"static\" },\n ),\n command(\n \"generate:entity\",\n \"GENERATORS\",\n \"Generate an ORM entity and update a managed registry\",\n \"admin\",\n { positional: [\"name\"], options: [\"dry-run\"], configuration: \"static\" },\n ),\n command(\"generate:module\", \"GENERATORS\", \"Generate a NestJS feature module\", \"admin\", {\n positional: [\"name\"],\n options: [\"dry-run\"],\n configuration: \"static\",\n }),\n ...(\n [\n [\"migration:create\", \"Create a manual migration\", [\"name\"], []],\n [\"migration:generate\", \"Generate a schema migration\", [\"name\"], [\"allow-destructive\"]],\n [\"migration:snapshot\", \"Save expected schema snapshot\", [], [\"schema\"]],\n [\"migration:remove\", \"Remove latest unpublished migration\", [], [\"yes\"]],\n [\"migration:baseline\", \"Adopt existing schema\", [\"name\"], [\"yes\"]],\n [\n \"migrate:up\",\n \"Apply pending migrations\",\n [],\n [\"steps\", \"to\", \"dry-run\", \"allow-destructive\"],\n ],\n [\"migrate:down\", \"Roll back migrations (target retained)\", [], [\"steps\", \"to\", \"yes\"]],\n [\"migrate:status\", \"Display migration history\", [], []],\n [\"migrate:diff\", \"Compare schemas\", [], [\"persisted\"]],\n [\"migrate:check\", \"Validate migration integrity\", [], [\"offline\"]],\n ] satisfies [string, string, string[], OptionName[]][]\n ).map(([name, description, positional, supported]) =>\n command(name, \"MIGRATIONS\", description, \"migration\", {\n positional,\n options: supported,\n configuration: \"migration\",\n required:\n name === \"migration:snapshot\"\n ? [\"schema\"]\n : [\"migration:remove\", \"migration:baseline\", \"migrate:down\"].includes(name)\n ? [\"yes\"]\n : [],\n database: name.startsWith(\"migrate:\")\n ? \"conditional\"\n : [\"migration:baseline\", \"migration:remove\"].includes(name),\n exclusive: [[\"steps\", \"to\"]],\n }),\n ),\n command(\n \"upgrade\",\n \"DEPENDENCIES\",\n \"Check or explicitly apply compatible published updates\",\n \"admin\",\n {\n options: [\"check\", \"apply\", \"package-manager\", \"registry\", \"prerelease\"],\n exclusive: [[\"check\", \"apply\"]],\n defaults: { check: true },\n },\n ),\n command(\"help\", \"INFORMATION\", \"Display command documentation\", \"help\", {\n positional: [\"command\"],\n optionalPositionals: true,\n }),\n command(\"version\", \"INFORMATION\", \"Display the CLI version\", \"version\", {\n aliases: [\"--version\"],\n }),\n];\nexport function findCommand(name: string): CommandDefinition {\n const found = commands.find((c) => c.name === name || c.aliases.includes(name));\n if (!found) throw new Error(`Unknown command: ${name}. Run duraxis help.`);\n return found;\n}\nexport function helpText(definition?: CommandDefinition): string {\n if (!definition)\n return `Duraxis CLI\\n\\nUsage: duraxis <command> [options]\\n\\n${[\n ...new Set(commands.map((c) => c.category)),\n ]\n .map(\n (category) =>\n `${category}\\n${commands\n .filter((c) => c.category === category)\n .map((c) => ` ${c.name.padEnd(22)} ${c.description}`)\n .join(\"\\n\")}`,\n )\n .join(\n \"\\n\\n\",\n )}\\n\\nExamples:\\n duraxis init\\n duraxis doctor\\n duraxis help init\\n duraxis migrate:status\\n duraxis upgrade --check\\n`;\n const supportedOptions: readonly OptionName[] = [\n \"config\",\n \"database\",\n \"json\",\n \"help\",\n ...definition.options,\n ];\n return `${definition.description}\\n\\nUsage: duraxis ${definition.name} ${definition.positional.map((p) => `<${p}>`).join(\" \")} [options]\\n\\n${supportedOptions.map((name) => ` --${name}${options[name].type === \"string\" ? \" <value>\" : \"\"}${definition.defaults[name] !== undefined ? ` (default: ${definition.defaults[name]})` : \"\"}${definition.required.includes(name) ? \" (required)\" : \"\"}`).join(\"\\n\")}\\n\\nConfiguration: ${definition.configuration}; database access: ${definition.database === \"conditional\" ? \"depends on command flags\" : definition.database ? \"required\" : \"not required by default\"}.\\n${definition.exclusive.map((group) => `Mutually exclusive: ${group.map((n) => `--${n}`).join(\", \")}`).join(\"\\n\")}\\n${definition.name === \"storage:check\" ? \"Live Disk checks may acquire exclusive directory ownership. No test objects are written.\" : \"\"}\\nExamples:\\n${definition.examples.map((e) => ` ${e}`).join(\"\\n\")}`;\n}\n","import { parseArgs } from \"node:util\";\nimport { options, findCommand } from \"./command-registry.js\";\nexport function parseCommand(args: readonly string[]) {\n const parsed = parseArgs({ args: [...args], options, allowPositionals: true, strict: true });\n const name = parsed.values.version ? \"version\" : (parsed.positionals[0] ?? \"help\");\n const definition = findCommand(name);\n const positionals = parsed.positionals.slice(parsed.positionals[0] ? 1 : 0);\n if (positionals.length > definition.positional.length)\n throw new Error(\"Unexpected positional arguments\");\n for (const option of Object.keys(parsed.values))\n if (![\"config\", \"database\", \"json\", \"help\", \"version\", ...definition.options].includes(option))\n throw new Error(`Option --${option} is not supported by ${name}`);\n if (!parsed.values.help) {\n if (!definition.optionalPositionals && positionals.length < definition.positional.length)\n throw new Error(`Missing positional arguments: ${definition.positional.join(\", \")}`);\n for (const group of definition.exclusive)\n if (group.filter((n) => parsed.values[n] !== undefined).length > 1)\n throw new Error(`Mutually exclusive options: ${group.map((n) => `--${n}`).join(\", \")}`);\n for (const option of definition.required)\n if (parsed.values[option] === undefined) throw new Error(`Missing required --${option}`);\n }\n return { ...parsed, definition, positionals };\n}\nexport type ParsedCommand = ReturnType<typeof parseCommand>;\n","import { parseCommand } from \"./registry/argument-parser.js\";\nimport { helpText, findCommand } from \"./registry/command-registry.js\";\nimport type { ProcessRunner } from \"./dependencies/package-manager.js\";\nimport type { Prompt } from \"./terminal/prompts.js\";\nexport interface CLIIO {\n readonly cwd?: string;\n readonly out?: (message: string) => void;\n readonly error?: (message: string) => void;\n readonly fetch?: typeof fetch;\n readonly runProcess?: ProcessRunner;\n readonly prompt?: Prompt;\n readonly interactive?: boolean;\n readonly signal?: AbortSignal;\n}\nexport async function runCLI(args: readonly string[], io: CLIIO = {}): Promise<number> {\n const out = io.out ?? console.log;\n const error = io.error ?? console.error;\n let json = args.includes(\"--json\");\n let migrationCommand = false;\n const controller = new AbortController();\n const interrupt = () => controller.abort(new Error(\"Operation cancelled\"));\n process.once(\"SIGINT\", interrupt);\n const context = {\n ...io,\n signal: io.signal ? AbortSignal.any([io.signal, controller.signal]) : controller.signal,\n };\n try {\n const parsed = parseCommand(args);\n json = parsed.values.json ?? false;\n if (parsed.values.help || parsed.definition.handler === \"help\") {\n const target =\n parsed.definition.handler === \"help\" && parsed.positionals[0]\n ? findCommand(parsed.positionals[0])\n : parsed.definition.handler === \"help\"\n ? undefined\n : parsed.definition;\n out(json ? JSON.stringify({ help: helpText(target) }) : helpText(target));\n return 0;\n }\n if (parsed.definition.handler === \"version\") {\n const { readFile } = await import(\"node:fs/promises\");\n const { dirname, join } = await import(\"node:path\");\n let root = import.meta.dirname;\n while (true) {\n try {\n const manifest: unknown = JSON.parse(await readFile(join(root, \"package.json\"), \"utf8\"));\n if (\n manifest &&\n typeof manifest === \"object\" &&\n \"name\" in manifest &&\n manifest.name === \"@duraxis/cli\" &&\n \"version\" in manifest\n ) {\n out(json ? JSON.stringify({ version: manifest.version }) : String(manifest.version));\n return 0;\n }\n } catch (cause) {\n if (!(cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\")) throw cause;\n }\n if (dirname(root) === root) throw new Error(\"CLI package version unavailable\");\n root = dirname(root);\n }\n }\n if (parsed.definition.handler === \"migration\") {\n migrationCommand = true;\n const code = await (\n await import(\"./commands/migration.command.js\")\n ).executeMigration(parsed, context);\n context.signal.throwIfAborted();\n return code;\n }\n const result =\n parsed.definition.handler === \"init\"\n ? await (await import(\"./commands/init.command.js\")).initialize(parsed, context)\n : await (await import(\"./commands/admin.command.js\")).administer(parsed, context);\n out(\n json\n ? JSON.stringify(result)\n : typeof result === \"string\"\n ? result\n : JSON.stringify(result, null, 2),\n );\n return result && typeof result === \"object\" && \"failed\" in result && result.failed === true\n ? 1\n : 0;\n } catch (cause) {\n const cleanupFailed = cause instanceof Error && cause.name === \"DuraxisMigrationCleanupError\";\n const message = cleanupFailed\n ? \"Migration database cleanup failed; inspect storage health and migration status before retrying\"\n : context.signal.aborted\n ? migrationCommand\n ? \"Migration operation cancelled. Inspect local artifacts and migrate:status before retrying; publication may have completed.\"\n : \"Operation cancelled\"\n : cause instanceof Error\n ? cause.message\n : \"Command failed\";\n error(\n json\n ? JSON.stringify({\n error: {\n code: cleanupFailed\n ? \"CLEANUP_FAILED\"\n : context.signal.aborted\n ? \"CANCELLED\"\n : \"COMMAND_FAILED\",\n message,\n },\n })\n : message,\n );\n return 1;\n } finally {\n process.removeListener(\"SIGINT\", interrupt);\n }\n}\n"],"mappings":";;;AAAA,IAAa,UAAU;CACrB,QAAQ,EAAE,MAAM,SAAS;CACzB,UAAU,EAAE,MAAM,SAAS;CAC3B,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM;EAAE,MAAM;EAAW,OAAO;CAAI;CACpC,SAAS,EAAE,MAAM,UAAU;CAC3B,WAAW,EAAE,MAAM,SAAS;CAC5B,QAAQ,EAAE,MAAM,SAAS;CACzB,KAAK,EAAE,MAAM,UAAU;CACvB,UAAU,EAAE,MAAM,UAAU;CAC5B,YAAY,EAAE,MAAM,UAAU;CAC9B,iBAAiB,EAAE,MAAM,UAAU;CACnC,mBAAmB,EAAE,MAAM,SAAS;CACpC,UAAU,EAAE,MAAM,SAAS;CAC3B,iBAAiB,EAAE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SAAS;CAC3C,gBAAgB,EAAE,MAAM,SAAS;CACjC,sBAAsB,EAAE,MAAM,SAAS;CACvC,kBAAkB,EAAE,MAAM,SAAS;CACnC,kBAAkB,EAAE,MAAM,SAAS;CACnC,kBAAkB,EAAE,MAAM,SAAS;AACrC;AAmBA,IAAM,cAAqC;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,SAAS,QACP,MACA,UACA,aACA,SACA,QAAoC,CAAC,GAClB;CACnB,OAAO;EACL;EACA;EACA;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,SAAS,CAAC;EACV,UAAU,CAAC;EACX,UAAU,CAAC;EACX,WAAW,CAAC;EACZ,UAAU,CAAC,WAAW,MAAM;EAC5B,eAAe;EACf,UAAU;EACV,aAAa;EACb,GAAG;CACL;AACF;AACA,IAAa,WAAyC;CACpD,QAAQ,QAAQ,SAAS,oCAAoC,QAAQ;EACnE,SAAS;EACT,aAAa;EACb,UAAU;GACR,QAAQ;GACR,WAAW;GACX,UAAU;GACV,iBAAiB;GACjB,WAAW;GACX,SAAS;EACX;EACA,WAAW;GACT,CAAC,OAAO,QAAQ;GAChB,CAAC,cAAc,eAAe;GAC9B,CAAC,WAAW,YAAY;GACxB,CAAC,WAAW,YAAY;EAC1B;EACA,UAAU,CACR,iDACA,0DACF;CACF,CAAC;CACD,QACE,UACA,SACA,oEACA,OACF;CACA,QACE,eACA,iBACA,wEACA,SACA;EAAE,SAAS,CAAC,UAAU;EAAG,eAAe;CAAS,CACnD;CACA,QACE,mBACA,iBACA,kDACA,SACA;EAAE,SAAS,CAAC,UAAU;EAAG,eAAe;CAAS,CACnD;CACA,QAAQ,cAAc,iBAAiB,4CAA4C,SAA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OACnF,IACA;CACN,SAAS,OAAO;EACd,MAAM,gBAAgB,iBAAiB,SAAS,MAAM,SAAS;EAC/D,MAAM,UAAU,gBACZ,mGACA,QAAQ,OAAO,UACb,mBACE,+HACA,wBACF,iBAAiB,QACf,MAAM,UACN;EACR,MACE,OACI,KAAK,UAAU,EACb,OAAO;GACL,MAAM,gBACF,mBACA,QAAQ,OAAO,UACb,cACA;GACN;EACF,EACF,CAAC,IACD,OACN;EACA,OAAO;CACT,UAAU;EACR,QAAQ,eAAe,UAAU,SAAS;CAC5C;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ParsedCommand } from "../registry/argument-parser.js";
|
|
2
|
+
import { type ProjectContext, type PackageManager } from "./project-detector.js";
|
|
3
|
+
export interface InitializationOptions {
|
|
4
|
+
framework: "standalone" | "nestjs";
|
|
5
|
+
driver: "memory" | "disk" | "s3" | "custom";
|
|
6
|
+
orm: boolean;
|
|
7
|
+
migrations: boolean;
|
|
8
|
+
language: "typescript" | "javascript";
|
|
9
|
+
moduleFormat: "esm" | "cjs";
|
|
10
|
+
namespace: string;
|
|
11
|
+
sourceDir: string;
|
|
12
|
+
storageDirectory: string;
|
|
13
|
+
bucket?: string;
|
|
14
|
+
prefix: string;
|
|
15
|
+
region?: string;
|
|
16
|
+
endpoint?: string;
|
|
17
|
+
forcePathStyle: boolean;
|
|
18
|
+
schemaMode: "create" | "validate" | "validate-managed";
|
|
19
|
+
applicationId?: string;
|
|
20
|
+
example: boolean;
|
|
21
|
+
install: boolean;
|
|
22
|
+
manager: PackageManager;
|
|
23
|
+
customModule?: string;
|
|
24
|
+
customExport: string;
|
|
25
|
+
customConstructor: boolean;
|
|
26
|
+
customOptions?: string;
|
|
27
|
+
resources: Record<string, unknown>;
|
|
28
|
+
storageLimits: Record<string, number>;
|
|
29
|
+
cursorKeyEnv?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function assertStorageDirectory(root: string, value: string, sourceDir: string, migrations: boolean): void;
|
|
32
|
+
export declare function initializationOptions(context: ProjectContext, values: ParsedCommand["values"]): Promise<InitializationOptions>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type FilePlan } from "../filesystem/file-plan.js";
|
|
2
|
+
import { type ProjectContext } from "./project-detector.js";
|
|
3
|
+
import type { InitializationOptions } from "./initialization-options.js";
|
|
4
|
+
import type { ManagedProject } from "./managed-project.js";
|
|
5
|
+
export declare function requiredPackages(options: InitializationOptions): string[];
|
|
6
|
+
export declare function configSource(managed: ManagedProject): string;
|
|
7
|
+
export declare function planInitialization(context: ProjectContext, options: InitializationOptions, dependencies: Record<string, string>, devDependencies: Record<string, string>, existing?: ManagedProject, name?: string): Promise<FilePlan>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InitializationOptions } from "./initialization-options.js";
|
|
2
|
+
export interface ManagedProject {
|
|
3
|
+
version: 1;
|
|
4
|
+
defaultConnection: string;
|
|
5
|
+
connections: Record<string, InitializationOptions>;
|
|
6
|
+
}
|
|
7
|
+
export declare function connectionName(name: string): string;
|
|
8
|
+
export declare function readManaged(root: string): Promise<ManagedProject>;
|
|
9
|
+
export declare function findManagedRoot(cwd: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare function record(value: unknown): value is Record<string, unknown>;
|
|
2
|
+
export declare function stringMap(value: unknown): Record<string, string>;
|
|
3
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
4
|
+
export declare function readObject(path: string): Promise<Record<string, unknown>>;
|
|
5
|
+
export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
6
|
+
export interface ProjectContext {
|
|
7
|
+
root: string;
|
|
8
|
+
manifest: Record<string, unknown>;
|
|
9
|
+
hasManifest: boolean;
|
|
10
|
+
dependencies: Record<string, string>;
|
|
11
|
+
devDependencies: Record<string, string>;
|
|
12
|
+
manager?: PackageManager;
|
|
13
|
+
managerConflict: boolean;
|
|
14
|
+
workspace?: string;
|
|
15
|
+
language: "typescript" | "javascript";
|
|
16
|
+
moduleFormat: "esm" | "cjs";
|
|
17
|
+
nestjs: boolean;
|
|
18
|
+
configFiles: string[];
|
|
19
|
+
environmentFiles: string[];
|
|
20
|
+
sourceDir: string;
|
|
21
|
+
nestModules: string[];
|
|
22
|
+
entryPoints: string[];
|
|
23
|
+
migrationDirectories: string[];
|
|
24
|
+
hasGitignore: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function detectProject(cwd: string, exact?: boolean): Promise<ProjectContext>;
|
|
27
|
+
export declare function selectManager(context: ProjectContext, value?: string): PackageManager;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { _ as executeFiles, d as planInitialization, f as requiredPackages, g as describePlan, i as resolveDependencies, l as readManaged, n as runProcess, o as initializationOptions, r as RegistryClient, t as installCommands, u as configuredRegistry, v as detectProject, y as exists } from "./package-manager-BBRBhsIe.js";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
// src/terminal/prompts.ts
|
|
5
|
+
async function withPrompts(run, signal) {
|
|
6
|
+
const terminal = createInterface({
|
|
7
|
+
input: process.stdin,
|
|
8
|
+
output: process.stderr,
|
|
9
|
+
terminal: false
|
|
10
|
+
});
|
|
11
|
+
const ask = async (question, fallback, choices) => {
|
|
12
|
+
signal?.throwIfAborted();
|
|
13
|
+
const numbered = choices ? `\n${choices.map((choice, index) => ` ${index + 1}. ${choice}`).join("\n")}\n` : "";
|
|
14
|
+
const value = await new Promise((resolve, reject) => {
|
|
15
|
+
const cancel = () => {
|
|
16
|
+
cleanup();
|
|
17
|
+
reject(/* @__PURE__ */ new Error("Initialization cancelled (EOF or Ctrl+C)"));
|
|
18
|
+
};
|
|
19
|
+
const cleanup = () => {
|
|
20
|
+
terminal.removeListener("close", cancel);
|
|
21
|
+
terminal.removeListener("SIGINT", cancel);
|
|
22
|
+
};
|
|
23
|
+
terminal.once("close", cancel);
|
|
24
|
+
terminal.once("SIGINT", cancel);
|
|
25
|
+
terminal.question(`${question}${numbered} [${fallback}]: `, { signal }).then((answer) => {
|
|
26
|
+
cleanup();
|
|
27
|
+
resolve(answer.trim() || fallback);
|
|
28
|
+
}, (error) => {
|
|
29
|
+
cleanup();
|
|
30
|
+
reject(error);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
if (choices && /^\d+$/.test(value)) {
|
|
34
|
+
const selected = choices[Number(value) - 1];
|
|
35
|
+
if (!selected) throw new Error("Invalid numbered selection");
|
|
36
|
+
return selected;
|
|
37
|
+
}
|
|
38
|
+
if (choices && !choices.includes(value)) throw new Error(`Choose one of: ${choices.join(", ")}`);
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
return await run(ask);
|
|
43
|
+
} finally {
|
|
44
|
+
terminal.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// src/commands/init.command.ts
|
|
48
|
+
async function initialize(parsed, io) {
|
|
49
|
+
const values = { ...parsed.values };
|
|
50
|
+
const project = await detectProject(resolve(io.cwd ?? process.cwd(), values.directory ?? "."), !!values.directory);
|
|
51
|
+
if (!values.directory && project.root !== resolve(io.cwd ?? process.cwd()) && (project.manifest.workspaces || await exists(resolve(project.root, "pnpm-workspace.yaml")))) throw new Error("Initialization from a nested directory would target the workspace root. Select the application explicitly with --directory; use --directory . to create a new package here.");
|
|
52
|
+
if (await exists(resolve(project.root, ".duraxis-init.lock"))) throw new Error("Another initialization/update owns .duraxis-init.lock. Wait for it to finish; inspect stale guards before manual removal.");
|
|
53
|
+
if (await exists(resolve(project.root, "duraxis.project.json"))) {
|
|
54
|
+
const settings = await readManaged(project.root);
|
|
55
|
+
return {
|
|
56
|
+
status: "already-initialized",
|
|
57
|
+
root: project.root,
|
|
58
|
+
connections: Object.keys(settings.connections),
|
|
59
|
+
actions: [
|
|
60
|
+
"config:show",
|
|
61
|
+
"config:set",
|
|
62
|
+
"connection:add",
|
|
63
|
+
"doctor"
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const interactive = io.interactive ?? (process.stdin.isTTY && process.stdout.isTTY && !values.json);
|
|
68
|
+
if (values.framework === "auto") values.framework = project.nestjs ? "nestjs" : "standalone";
|
|
69
|
+
const wizard = async (ask) => {
|
|
70
|
+
if (!project.hasManifest && await ask("Create a minimal Node.js project manifest?", "yes", ["yes", "no"]) !== "yes") throw new Error("Initialization cancelled");
|
|
71
|
+
values.framework ??= await ask("Integration", project.nestjs ? "nestjs" : "standalone", ["standalone", "nestjs"]);
|
|
72
|
+
values.driver ??= await ask("Storage driver", "disk", [
|
|
73
|
+
"disk",
|
|
74
|
+
"memory",
|
|
75
|
+
"s3",
|
|
76
|
+
"custom"
|
|
77
|
+
]);
|
|
78
|
+
if (values.framework === "nestjs") {
|
|
79
|
+
if (values["no-orm"]) throw new Error("NestJS requires ORM");
|
|
80
|
+
values.orm = true;
|
|
81
|
+
} else if (values.orm === void 0 && !values["no-orm"]) values.orm = await ask("Enable ORM?", "yes", ["yes", "no"]) === "yes";
|
|
82
|
+
if (values.migrations === void 0 && !values["no-migrations"]) values.migrations = await ask("Enable migrations?", values.driver === "memory" ? "no" : "yes", ["yes", "no"]) === "yes";
|
|
83
|
+
values.namespace ??= await ask("Database namespace (not an authorization boundary)", "default");
|
|
84
|
+
if (values.driver === "s3") {
|
|
85
|
+
values.bucket ??= await ask("S3 bucket", "");
|
|
86
|
+
values.region ??= await ask("AWS region", "us-east-1");
|
|
87
|
+
}
|
|
88
|
+
if (values.driver === "custom") values["custom-module"] ??= await ask("Trusted custom storage module", "./storage.mjs");
|
|
89
|
+
if (project.managerConflict) values["package-manager"] ??= await ask("Package manager", "npm", [
|
|
90
|
+
"npm",
|
|
91
|
+
"pnpm",
|
|
92
|
+
"yarn",
|
|
93
|
+
"bun"
|
|
94
|
+
]);
|
|
95
|
+
if (await ask("Configure advanced settings?", "no", ["yes", "no"]) === "yes") {
|
|
96
|
+
values["source-dir"] ??= await ask("Source directory", "src");
|
|
97
|
+
if (values.driver === "disk") values["storage-directory"] ??= await ask("Storage directory", "./data/duraxis");
|
|
98
|
+
values["schema-mode"] ??= await ask("Schema mode", values.migrations ? "validate-managed" : "create", [
|
|
99
|
+
"create",
|
|
100
|
+
"validate",
|
|
101
|
+
"validate-managed"
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
if (values.orm && values.example === void 0 && !values["no-example"]) values.example = await ask("Generate example entity?", "no", ["yes", "no"]) === "yes";
|
|
105
|
+
if (values.install === void 0 && !values["no-install"]) values.install = await ask("Install required dependencies?", "yes", ["yes", "no"]) === "yes";
|
|
106
|
+
};
|
|
107
|
+
if (!values.yes && !values["dry-run"]) {
|
|
108
|
+
if (!interactive) throw new Error("Non-interactive initialization requires --yes or --dry-run. No files were changed.");
|
|
109
|
+
if (io.prompt) await wizard(io.prompt);
|
|
110
|
+
else await withPrompts(wizard, io.signal);
|
|
111
|
+
}
|
|
112
|
+
const options = await initializationOptions(project, values);
|
|
113
|
+
const requested = [
|
|
114
|
+
...requiredPackages(options),
|
|
115
|
+
"@duraxis/cli",
|
|
116
|
+
...options.language === "typescript" ? ["typescript", "@types/node"] : []
|
|
117
|
+
];
|
|
118
|
+
const existing = {
|
|
119
|
+
...project.dependencies,
|
|
120
|
+
...project.devDependencies
|
|
121
|
+
};
|
|
122
|
+
const resolved = options.install ? await resolveDependencies(requested, existing, new RegistryClient(await configuredRegistry(project, values.registry), io.fetch, io.signal), values.prerelease) : Object.fromEntries(requested.map((name) => [name, existing[name] ?? "latest"]));
|
|
123
|
+
const devNames = /* @__PURE__ */ new Set([
|
|
124
|
+
"@duraxis/cli",
|
|
125
|
+
"typescript",
|
|
126
|
+
"@types/node"
|
|
127
|
+
]);
|
|
128
|
+
const dependencies = Object.fromEntries(Object.entries(resolved).filter(([name]) => (!devNames.has(name) || !!project.dependencies[name]) && (requested.includes(name) || !name.startsWith("@duraxis/")) && (!existing[name] || existing[name] !== resolved[name])));
|
|
129
|
+
const development = Object.fromEntries(Object.entries(resolved).filter(([name]) => devNames.has(name) && !project.dependencies[name] && (!existing[name] || existing[name] !== resolved[name])));
|
|
130
|
+
const plan = await planInitialization(project, options, dependencies, development);
|
|
131
|
+
plan.commands = options.install ? installCommands(options.manager, dependencies, development) : [];
|
|
132
|
+
if (options.install && !plan.commands.length) plan.commands.push([options.manager, "install"]);
|
|
133
|
+
io.signal?.throwIfAborted();
|
|
134
|
+
if (values["dry-run"]) return {
|
|
135
|
+
status: "planned",
|
|
136
|
+
...describePlan(plan)
|
|
137
|
+
};
|
|
138
|
+
await executeFiles(plan, async () => {
|
|
139
|
+
io.signal?.throwIfAborted();
|
|
140
|
+
for (const [command, ...args] of plan.commands) await (io.runProcess ?? runProcess)({
|
|
141
|
+
command,
|
|
142
|
+
args,
|
|
143
|
+
cwd: project.root,
|
|
144
|
+
signal: io.signal
|
|
145
|
+
});
|
|
146
|
+
io.signal?.throwIfAborted();
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
status: options.driver === "custom" ? "configured-custom-driver-not-evaluated" : options.install ? "initialized" : "configured-dependencies-not-installed",
|
|
150
|
+
databaseOpened: false,
|
|
151
|
+
dependenciesInstalled: options.install,
|
|
152
|
+
root: project.root,
|
|
153
|
+
files: plan.files.map((f) => f.path),
|
|
154
|
+
dependencies,
|
|
155
|
+
devDependencies: development,
|
|
156
|
+
warnings: plan.warnings,
|
|
157
|
+
next: options.migrations ? options.orm ? [
|
|
158
|
+
"Review entities",
|
|
159
|
+
"duraxis migration:generate initial",
|
|
160
|
+
"duraxis migrate:up",
|
|
161
|
+
"Start application after migrations"
|
|
162
|
+
] : [
|
|
163
|
+
"duraxis migration:create initial",
|
|
164
|
+
"Implement the manual migration",
|
|
165
|
+
"duraxis migration:snapshot --schema collections.json",
|
|
166
|
+
"duraxis migrate:up"
|
|
167
|
+
] : ["Import createDatabase/createORM from generated shared factory", "Always close resources in finally"]
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export { initialize };
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=init.command-B2kKoyfi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.command-B2kKoyfi.js","names":[],"sources":["../src/terminal/prompts.ts","../src/commands/init.command.ts"],"sourcesContent":["import { createInterface } from \"node:readline/promises\";\nexport type Prompt = (\n question: string,\n fallback: string,\n choices?: readonly string[],\n) => Promise<string>;\nexport async function withPrompts<T>(\n run: (ask: Prompt) => Promise<T>,\n signal?: AbortSignal,\n): Promise<T> {\n const terminal = createInterface({\n input: process.stdin,\n output: process.stderr,\n terminal: false,\n });\n const ask: Prompt = async (question, fallback, choices) => {\n signal?.throwIfAborted();\n const numbered = choices\n ? `\\n${choices.map((choice, index) => ` ${index + 1}. ${choice}`).join(\"\\n\")}\\n`\n : \"\";\n const value = await new Promise<string>((resolve, reject) => {\n const cancel = () => {\n cleanup();\n reject(new Error(\"Initialization cancelled (EOF or Ctrl+C)\"));\n };\n const cleanup = () => {\n terminal.removeListener(\"close\", cancel);\n terminal.removeListener(\"SIGINT\", cancel);\n };\n terminal.once(\"close\", cancel);\n terminal.once(\"SIGINT\", cancel);\n terminal.question(`${question}${numbered} [${fallback}]: `, { signal }).then(\n (answer) => {\n cleanup();\n resolve(answer.trim() || fallback);\n },\n (error) => {\n cleanup();\n reject(error);\n },\n );\n });\n if (choices && /^\\d+$/.test(value)) {\n const selected = choices[Number(value) - 1];\n if (!selected) throw new Error(\"Invalid numbered selection\");\n return selected;\n }\n if (choices && !choices.includes(value))\n throw new Error(`Choose one of: ${choices.join(\", \")}`);\n return value;\n };\n try {\n return await run(ask);\n } finally {\n terminal.close();\n }\n}\n","import { configuredRegistry } from \"../dependencies/configured-registry.js\";\nimport { resolve } from \"node:path\";\nimport type { CLIIO } from \"../cli.js\";\nimport type { ParsedCommand } from \"../registry/argument-parser.js\";\nimport { detectProject, exists } from \"../init/project-detector.js\";\nimport { initializationOptions } from \"../init/initialization-options.js\";\nimport { planInitialization, requiredPackages } from \"../init/initialization-planner.js\";\nimport { executeFiles, describePlan } from \"../filesystem/file-plan.js\";\nimport { RegistryClient } from \"../dependencies/registry-client.js\";\nimport { resolveDependencies } from \"../dependencies/dependency-resolver.js\";\nimport { installCommands, runProcess } from \"../dependencies/package-manager.js\";\nimport { withPrompts, type Prompt } from \"../terminal/prompts.js\";\nimport { readManaged } from \"../init/managed-project.js\";\nexport async function initialize(parsed: ParsedCommand, io: CLIIO): Promise<unknown> {\n const values = { ...parsed.values };\n const project = await detectProject(\n resolve(io.cwd ?? process.cwd(), values.directory ?? \".\"),\n !!values.directory,\n );\n if (\n !values.directory &&\n project.root !== resolve(io.cwd ?? process.cwd()) &&\n (project.manifest.workspaces || (await exists(resolve(project.root, \"pnpm-workspace.yaml\"))))\n )\n throw new Error(\n \"Initialization from a nested directory would target the workspace root. Select the application explicitly with --directory; use --directory . to create a new package here.\",\n );\n if (await exists(resolve(project.root, \".duraxis-init.lock\")))\n throw new Error(\n \"Another initialization/update owns .duraxis-init.lock. Wait for it to finish; inspect stale guards before manual removal.\",\n );\n if (await exists(resolve(project.root, \"duraxis.project.json\"))) {\n const settings = await readManaged(project.root);\n return {\n status: \"already-initialized\",\n root: project.root,\n connections: Object.keys(settings.connections),\n actions: [\"config:show\", \"config:set\", \"connection:add\", \"doctor\"],\n };\n }\n const interactive =\n io.interactive ?? (process.stdin.isTTY && process.stdout.isTTY && !values.json);\n if (values.framework === \"auto\") values.framework = project.nestjs ? \"nestjs\" : \"standalone\";\n const wizard = async (ask: Prompt) => {\n if (\n !project.hasManifest &&\n (await ask(\"Create a minimal Node.js project manifest?\", \"yes\", [\"yes\", \"no\"])) !== \"yes\"\n )\n throw new Error(\"Initialization cancelled\");\n values.framework ??= await ask(\"Integration\", project.nestjs ? \"nestjs\" : \"standalone\", [\n \"standalone\",\n \"nestjs\",\n ]);\n values.driver ??= await ask(\"Storage driver\", \"disk\", [\"disk\", \"memory\", \"s3\", \"custom\"]);\n if (values.framework === \"nestjs\") {\n if (values[\"no-orm\"]) throw new Error(\"NestJS requires ORM\");\n values.orm = true;\n } else if (values.orm === undefined && !values[\"no-orm\"])\n values.orm = (await ask(\"Enable ORM?\", \"yes\", [\"yes\", \"no\"])) === \"yes\";\n if (values.migrations === undefined && !values[\"no-migrations\"])\n values.migrations =\n (await ask(\"Enable migrations?\", values.driver === \"memory\" ? \"no\" : \"yes\", [\n \"yes\",\n \"no\",\n ])) === \"yes\";\n values.namespace ??= await ask(\"Database namespace (not an authorization boundary)\", \"default\");\n if (values.driver === \"s3\") {\n values.bucket ??= await ask(\"S3 bucket\", \"\");\n values.region ??= await ask(\"AWS region\", \"us-east-1\");\n }\n if (values.driver === \"custom\")\n values[\"custom-module\"] ??= await ask(\"Trusted custom storage module\", \"./storage.mjs\");\n if (project.managerConflict)\n values[\"package-manager\"] ??= await ask(\"Package manager\", \"npm\", [\n \"npm\",\n \"pnpm\",\n \"yarn\",\n \"bun\",\n ]);\n if ((await ask(\"Configure advanced settings?\", \"no\", [\"yes\", \"no\"])) === \"yes\") {\n values[\"source-dir\"] ??= await ask(\"Source directory\", \"src\");\n if (values.driver === \"disk\")\n values[\"storage-directory\"] ??= await ask(\"Storage directory\", \"./data/duraxis\");\n values[\"schema-mode\"] ??= await ask(\n \"Schema mode\",\n values.migrations ? \"validate-managed\" : \"create\",\n [\"create\", \"validate\", \"validate-managed\"],\n );\n }\n if (values.orm && values.example === undefined && !values[\"no-example\"])\n values.example = (await ask(\"Generate example entity?\", \"no\", [\"yes\", \"no\"])) === \"yes\";\n if (values.install === undefined && !values[\"no-install\"])\n values.install =\n (await ask(\"Install required dependencies?\", \"yes\", [\"yes\", \"no\"])) === \"yes\";\n };\n if (!values.yes && !values[\"dry-run\"]) {\n if (!interactive)\n throw new Error(\n \"Non-interactive initialization requires --yes or --dry-run. No files were changed.\",\n );\n if (io.prompt) await wizard(io.prompt);\n else await withPrompts(wizard, io.signal);\n }\n const options = await initializationOptions(project, values);\n const requested = [\n ...requiredPackages(options),\n \"@duraxis/cli\",\n ...(options.language === \"typescript\" ? [\"typescript\", \"@types/node\"] : []),\n ];\n const existing = { ...project.dependencies, ...project.devDependencies };\n const resolved = options.install\n ? await resolveDependencies(\n requested,\n existing,\n new RegistryClient(await configuredRegistry(project, values.registry), io.fetch, io.signal),\n values.prerelease,\n )\n : Object.fromEntries(requested.map((name) => [name, existing[name] ?? \"latest\"]));\n const devNames = new Set([\"@duraxis/cli\", \"typescript\", \"@types/node\"]);\n const dependencies = Object.fromEntries(\n Object.entries(resolved).filter(\n ([name]) =>\n (!devNames.has(name) || !!project.dependencies[name]) &&\n (requested.includes(name) || !name.startsWith(\"@duraxis/\")) &&\n (!existing[name] || existing[name] !== resolved[name]),\n ),\n );\n const development = Object.fromEntries(\n Object.entries(resolved).filter(\n ([name]) =>\n devNames.has(name) &&\n !project.dependencies[name] &&\n (!existing[name] || existing[name] !== resolved[name]),\n ),\n );\n const plan = await planInitialization(project, options, dependencies, development);\n plan.commands = options.install\n ? installCommands(options.manager, dependencies, development)\n : [];\n if (options.install && !plan.commands.length) plan.commands.push([options.manager, \"install\"]);\n io.signal?.throwIfAborted();\n if (values[\"dry-run\"]) return { status: \"planned\", ...describePlan(plan) };\n await executeFiles(plan, async () => {\n io.signal?.throwIfAborted();\n for (const [command, ...args] of plan.commands)\n await (io.runProcess ?? runProcess)({\n command: command!,\n args,\n cwd: project.root,\n signal: io.signal,\n });\n io.signal?.throwIfAborted();\n });\n return {\n status:\n options.driver === \"custom\"\n ? \"configured-custom-driver-not-evaluated\"\n : options.install\n ? \"initialized\"\n : \"configured-dependencies-not-installed\",\n databaseOpened: false,\n dependenciesInstalled: options.install,\n root: project.root,\n files: plan.files.map((f) => f.path),\n dependencies,\n devDependencies: development,\n warnings: plan.warnings,\n next: options.migrations\n ? options.orm\n ? [\n \"Review entities\",\n \"duraxis migration:generate initial\",\n \"duraxis migrate:up\",\n \"Start application after migrations\",\n ]\n : [\n \"duraxis migration:create initial\",\n \"Implement the manual migration\",\n \"duraxis migration:snapshot --schema collections.json\",\n \"duraxis migrate:up\",\n ]\n : [\n \"Import createDatabase/createORM from generated shared factory\",\n \"Always close resources in finally\",\n ],\n };\n}\n"],"mappings":";;;;AAMA,eAAsB,YACpB,KACA,QACY;CACZ,MAAM,WAAW,gBAAgB;EAC/B,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,UAAU;CACZ,CAAC;CACD,MAAM,MAAc,OAAO,UAAU,UAAU,YAAY;EACzD,QAAQ,eAAe;EACvB,MAAM,WAAW,UACb,KAAK,QAAQ,KAAK,QAAQ,UAAU,KAAK,QAAQ,EAAE,IAAI,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,MAC5E;EACJ,MAAM,QAAQ,MAAM,IAAI,SAAiB,SAAS,WAAW;GAC3D,MAAM,eAAe;IACnB,QAAQ;IACR,uBAAO,IAAI,MAAM,0CAA0C,CAAC;GAC9D;GACA,MAAM,gBAAgB;IACpB,SAAS,eAAe,SAAS,MAAM;IACvC,SAAS,eAAe,UAAU,MAAM;GAC1C;GACA,SAAS,KAAK,SAAS,MAAM;GAC7B,SAAS,KAAK,UAAU,MAAM;GAC9B,SAAS,SAAS,GAAG,WAAW,SAAS,IAAI,SAAS,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,MACrE,WAAW;IACV,QAAQ;IACR,QAAQ,OAAO,KAAK,KAAK,QAAQ;GACnC,IACC,UAAU;IACT,QAAQ;IACR,OAAO,KAAK;GACd,CACF;EACF,CAAC;EACD,IAAI,WAAW,QAAQ,KAAK,KAAK,GAAG;GAClC,MAAM,WAAW,QAAQ,OAAO,KAAK,IAAI;GACzC,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,4BAA4B;GAC3D,OAAO;EACT;EACA,IAAI,WAAW,CAAC,QAAQ,SAAS,KAAK,GACpC,MAAM,IAAI,MAAM,kBAAkB,QAAQ,KAAK,IAAI,GAAG;EACxD,OAAO;CACT;CACA,IAAI;EACF,OAAO,MAAM,IAAI,GA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