@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.command-Chb6x9mF.js","names":[],"sources":["../src/dependencies/installed-package.ts","../src/commands/doctor.command.ts","../src/commands/admin.command.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\nimport { readObject } from \"../init/project-detector.js\";\nexport async function installedPackage(\n root: string,\n name: string,\n): Promise<Record<string, unknown> | undefined> {\n let directory: string;\n try {\n directory = dirname(createRequire(join(root, \"package.json\")).resolve(name));\n } catch {\n return undefined;\n }\n for (let depth = 0; depth < 12; depth++) {\n try {\n const manifest = await readObject(join(directory, \"package.json\"));\n if (manifest.name === name) return manifest;\n } catch (error) {\n if (!(error instanceof Error && \"code\" in error && error.code === \"ENOENT\")) throw error;\n }\n if (dirname(directory) === directory) break;\n directory = dirname(directory);\n }\n return undefined;\n}\n","import { satisfies } from \"../dependencies/version-compatibility.js\";\nimport { existsSync } from \"node:fs\";\nimport { join, delimiter } from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { exists, record, stringMap, type ProjectContext } from \"../init/project-detector.js\";\nimport type { ManagedProject } from \"../init/managed-project.js\";\nimport { requiredPackages } from \"../init/initialization-planner.js\";\nimport { installedPackage } from \"../dependencies/installed-package.js\";\ninterface Diagnostic {\n level: \"PASS\" | \"WARN\" | \"FAIL\" | \"SKIP\";\n check: string;\n message: string;\n}\nexport function available(project: ProjectContext, name: string): boolean {\n if (\n !project.dependencies[name] &&\n !project.devDependencies[name] &&\n !existsSync(join(project.root, \"node_modules\", name))\n )\n return false;\n try {\n createRequire(join(project.root, \"package.json\")).resolve(name);\n return true;\n } catch {\n return false;\n }\n}\nexport async function diagnostics(\n project: ProjectContext,\n managed?: ManagedProject,\n selected = \"default\",\n): Promise<Diagnostic[]> {\n const checks: Diagnostic[] = [];\n const add = (level: Diagnostic[\"level\"], check: string, message: string) =>\n checks.push({ level, check, message });\n add(\n satisfies(process.versions.node, \">=24.15.0\") ? \"PASS\" : \"FAIL\",\n \"runtime\",\n `Node.js ${process.versions.node}; requires >=24.15.0 (Bun is a package manager only)`,\n );\n add(\n project.hasManifest ? \"PASS\" : \"FAIL\",\n \"manifest\",\n project.hasManifest ? project.root : \"Create package.json with duraxis init --yes\",\n );\n add(\n project.managerConflict ? \"FAIL\" : \"PASS\",\n \"package-manager\",\n project.managerConflict\n ? \"Conflicting lockfiles; choose --package-manager explicitly\"\n : (project.manager ?? \"npm default (no lockfile detected)\"),\n );\n add(\n \"PASS\",\n \"workspace\",\n project.workspace\n ? `Application ${project.root}; workspace ${project.workspace}; installations use the application directory`\n : \"Standalone package\",\n );\n const manager = project.manager ?? \"npm\";\n const suffixes = process.platform === \"win32\" ? [\".cmd\", \".exe\", \"\"] : [\"\"];\n const managerAvailable = (process.env.PATH ?? \"\")\n .split(delimiter)\n .slice(0, 512)\n .some((directory) => suffixes.some((suffix) => existsSync(join(directory, manager + suffix))));\n add(\n managerAvailable ? \"PASS\" : \"WARN\",\n \"package-manager-availability\",\n managerAvailable\n ? `${manager} executable found on PATH (not executed)`\n : `Install ${manager} or add it to PATH`,\n );\n add(\"PASS\", \"module-format\", project.moduleFormat);\n if (await exists(join(project.root, \"tsconfig.json\"))) {\n const ts = (await import(\"typescript\")).default;\n const parsed = ts.readConfigFile(join(project.root, \"tsconfig.json\"), ts.sys.readFile);\n if (parsed.error) add(\"FAIL\", \"typescript\", \"Cannot parse tsconfig.json\");\n else {\n const config = ts.parseJsonConfigFileContent(parsed.config, ts.sys, project.root);\n const compiler = config.options;\n add(\n compiler.experimentalDecorators &&\n compiler.emitDecoratorMetadata &&\n compiler.useDefineForClassFields === false\n ? \"PASS\"\n : \"WARN\",\n \"typescript\",\n \"Legacy ORM entities require experimentalDecorators:true, emitDecoratorMetadata:true, useDefineForClassFields:false; generated .mts/.cts modules require NodeNext\",\n );\n }\n } else\n add(\n project.language === \"typescript\" ? \"WARN\" : \"SKIP\",\n \"typescript\",\n \"No tsconfig.json; use explicit fields with JavaScript decorator functions\",\n );\n if (!managed) {\n add(\n project.configFiles.length ? \"WARN\" : \"FAIL\",\n \"configuration\",\n project.configFiles.length\n ? \"Executable configuration detected, not evaluated. Use config:validate --evaluate only for trusted code.\"\n : \"Run duraxis init\",\n );\n return checks;\n }\n add(\n \"PASS\",\n \"project-files\",\n `Source ${project.sourceDir}; module candidates: ${project.nestModules.join(\", \") || \"none\"}; entry points: ${project.entryPoints.join(\", \") || \"none\"}; existing migration directories: ${project.migrationDirectories.join(\", \") || \"none\"}; .gitignore: ${project.hasGitignore ? \"present\" : \"absent\"}. Inspection is bounded and does not execute source.`,\n );\n const options = managed.connections[selected];\n if (!options) {\n add(\"FAIL\", \"connection\", \"Unknown named connection\");\n return checks;\n }\n add(\n \"PASS\",\n \"configuration\",\n `Managed version 1; connections: ${Object.keys(managed.connections).join(\", \")}`,\n );\n for (const name of [...requiredPackages(options), \"@duraxis/cli\"])\n add(\n available(project, name) ? \"PASS\" : \"FAIL\",\n `package:${name}`,\n available(project, name)\n ? \"Resolvable without executing package code\"\n : `Install ${name} in ${project.root}`,\n );\n for (const name of requiredPackages(options)) {\n const manifest = await installedPackage(project.root, name);\n if (!manifest) continue;\n try {\n if (record(manifest.engines) && typeof manifest.engines.node === \"string\")\n add(\n satisfies(process.versions.node, manifest.engines.node) ? \"PASS\" : \"FAIL\",\n `engines:${name}`,\n `Installed ${name} Node.js engine compatibility`,\n );\n for (const [peer, range] of Object.entries(stringMap(manifest.peerDependencies))) {\n const installed = await installedPackage(project.root, peer);\n const peerMeta = record(manifest.peerDependenciesMeta)\n ? manifest.peerDependenciesMeta[peer]\n : undefined;\n if (!installed && record(peerMeta) && peerMeta.optional === true) continue;\n add(\n installed && typeof installed.version === \"string\" && satisfies(installed.version, range)\n ? \"PASS\"\n : \"FAIL\",\n `peer:${name}:${peer}`,\n `Requires ${peer} ${range}; install compatible peer dependencies`,\n );\n }\n } catch {\n add(\n \"WARN\",\n `compatibility:${name}`,\n \"Installed metadata uses unsupported version range syntax; verify compatibility manually\",\n );\n }\n }\n add(\n options.framework !== \"nestjs\" || options.orm ? \"PASS\" : \"FAIL\",\n \"framework\",\n `${options.framework}${options.framework === \"nestjs\" ? \"; import generated module and enableShutdownHooks()\" : \"\"}`,\n );\n if (options.cursorKeyEnv)\n add(\n /^[a-fA-F0-9]{64}$/.test(process.env[options.cursorKeyEnv] ?? \"\") ? \"PASS\" : \"FAIL\",\n \"cursor-key\",\n `Provision ${options.cursorKeyEnv} securely as 32 bytes in hex (value redacted)`,\n );\n if (options.driver === \"s3\")\n add(\n options.bucket || process.env.DURAXIS_S3_BUCKET ? \"PASS\" : \"FAIL\",\n \"storage\",\n \"S3 configuration only; credentials use the default AWS chain, connectivity not tested\",\n );\n else\n add(\n \"PASS\",\n \"storage\",\n options.driver === \"memory\"\n ? \"Volatile storage; independent CLI processes do not share data\"\n : options.driver === \"disk\"\n ? \"Exclusive directory ownership required; no automatic lock recovery\"\n : \"Custom implementation must enforce conditional operations and bounded reads\",\n );\n if (options.migrations) {\n const base = selected === \"default\" ? \"duraxis\" : `duraxis/${selected}`;\n add(\n (await exists(join(project.root, base, \"snapshots/baseline.json\"))) ? \"PASS\" : \"FAIL\",\n \"migrations\",\n \"Baseline and directories checked statically; use migrate:check --offline for artifact validation (executes trusted migration modules)\",\n );\n } else add(\"SKIP\", \"migrations\", \"Disabled\");\n add(\n \"SKIP\",\n \"connectivity\",\n \"No database opened; use storage:check --live explicitly where supported\",\n );\n return checks;\n}\n","import { compare, satisfies } from \"../dependencies/version-compatibility.js\";\nimport { diagnostics, available } from \"./doctor.command.js\";\nimport { installedPackage } from \"../dependencies/installed-package.js\";\nimport { configuredRegistry } from \"../dependencies/configured-registry.js\";\nimport { resolve, join, dirname, basename } from \"node:path\";\nimport { readFile } from \"node:fs/promises\";\nimport type { CLIIO } from \"../cli.js\";\nimport type { ParsedCommand } from \"../registry/argument-parser.js\";\nimport { detectProject, exists } from \"../init/project-detector.js\";\nimport { findManagedRoot, readManaged, connectionName } from \"../init/managed-project.js\";\nimport { initializationOptions, assertStorageDirectory } from \"../init/initialization-options.js\";\nimport { planInitialization, requiredPackages } from \"../init/initialization-planner.js\";\nimport { addFile, executeFiles, describePlan, type FilePlan } from \"../filesystem/file-plan.js\";\nimport { extensions, entitySource } from \"../templates/project.js\";\nimport { resolveDependencies } from \"../dependencies/dependency-resolver.js\";\nimport { RegistryClient } from \"../dependencies/registry-client.js\";\nimport { installCommands, runProcess } from \"../dependencies/package-manager.js\";\nfunction plan(root: string): FilePlan {\n return {\n root,\n files: [],\n directories: [],\n warnings: [],\n dependencies: {},\n devDependencies: {},\n commands: [],\n };\n}\nfunction redact(value: unknown, seen = new WeakSet<object>(), depth = 0): unknown {\n if (depth > 16) return \"[unresolved: inspection depth limit]\";\n if (value && typeof value === \"object\") {\n if (seen.has(value)) return \"[circular/shared reference]\";\n seen.add(value);\n if (Array.isArray(value)) return value.map((item) => redact(item, seen, depth + 1));\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [\n key,\n /secret|password|token|credential|signingkey|encryption|access[_-]?key|private[_-]?key|api[_-]?key|^keys?$/i.test(\n key,\n )\n ? \"[REDACTED]\"\n : redact(item, seen, depth + 1),\n ]),\n );\n }\n if (typeof value === \"function\") return \"[trusted function; not evaluated]\";\n if (typeof value === \"string\" && /^https?:/.test(value)) {\n try {\n const url = new URL(value);\n if (url.username || url.password || url.search) return \"[REDACTED URL]\";\n } catch {}\n }\n return value;\n}\nexport async function administer(parsed: ParsedCommand, io: CLIIO): Promise<unknown> {\n const { values, definition, positionals } = parsed;\n const cwd = values.directory\n ? resolve(io.cwd ?? process.cwd(), values.directory)\n : (io.cwd ?? process.cwd());\n const explicit = values.config ? resolve(cwd, values.config) : undefined;\n if (explicit && !(await exists(explicit)))\n throw new Error(\"Explicit configuration file does not exist\");\n const explicitManaged =\n explicit &&\n /^duraxis\\.config\\.[cm]?[jt]s$/.test(basename(explicit)) &&\n (await exists(join(dirname(explicit), \"duraxis.project.json\")));\n const managedRoot = explicit\n ? explicitManaged\n ? dirname(explicit)\n : undefined\n : values.directory\n ? (await exists(join(cwd, \"duraxis.project.json\")))\n ? cwd\n : undefined\n : await findManagedRoot(cwd);\n if (values.directory && !managedRoot)\n throw new Error(\"The selected directory has no managed Duraxis project; run init there first\");\n const project = await detectProject(managedRoot ?? (explicit ? dirname(explicit) : cwd));\n if (explicit) project.configFiles = [basename(explicit)];\n const root = managedRoot ?? project.root;\n const managed = managedRoot ? await readManaged(root) : undefined;\n const selected = values.database ?? managed?.defaultConnection ?? \"default\";\n const selectedOptions = managed?.connections[selected];\n const execute = async (files: FilePlan, after: () => Promise<void> = async () => {}) => {\n if (values[\"dry-run\"]) return { status: \"planned\", ...describePlan(files) };\n await executeFiles(files, after);\n return { status: \"updated\", files: files.files.map((f) => f.path), warnings: files.warnings };\n };\n if (definition.name === \"storage:list\")\n return [\n {\n driver: \"memory\",\n persistent: false,\n limitation: \"Process-local volatile data\",\n package: \"@duraxis/storage-memory\",\n },\n {\n driver: \"disk\",\n persistent: true,\n limitation: \"Single-owner local directory; recovery requires operator action\",\n package: \"@duraxis/storage-disk\",\n },\n {\n driver: \"s3\",\n persistent: true,\n limitation:\n \"Conditional-request-compatible provider required; destructive distributed GC unsupported\",\n package: \"@duraxis/storage-s3\",\n },\n {\n driver: \"custom\",\n persistent: \"implementation-dependent\",\n limitation: \"Conditional semantics and bounded reads required\",\n package: \"@duraxis/storage\",\n },\n ].map((driver) => ({\n ...driver,\n available: true,\n installed: available(project, driver.package),\n configured: selectedOptions?.driver === driver.driver,\n }));\n if (definition.name === \"doctor\") {\n const checks = await diagnostics(project, managed, selected);\n return { failed: checks.some((c) => c.level === \"FAIL\"), diagnostics: checks };\n }\n if (definition.name === \"upgrade\") {\n const installed = Object.fromEntries(\n Object.entries({ ...project.dependencies, ...project.devDependencies }).filter(([name]) =>\n name.startsWith(\"@duraxis/\"),\n ),\n );\n if (!Object.keys(installed).length)\n throw new Error(\"No Duraxis dependencies found in the selected project\");\n for (const [name, specification] of Object.entries(installed)) {\n try {\n satisfies(\"0.0.0\", specification);\n } catch {\n throw new Error(\n `Cannot upgrade unsupported dependency specification for ${name}; update workspace-owned versions with workspace release tooling, or use a supported registry version range`,\n );\n }\n }\n const resolved = await resolveDependencies(\n Object.keys(installed),\n { ...project.dependencies, ...project.devDependencies },\n new RegistryClient(await configuredRegistry(project, values.registry), io.fetch, io.signal),\n values.prerelease,\n process.versions.node,\n false,\n );\n const packages = await Promise.all(\n Object.keys(installed).map(async (name) => {\n const actual = (await installedPackage(root, name))?.version ?? installed[name];\n const downgradeBlocked =\n typeof actual === \"string\" &&\n /^v?\\d+\\.\\d+\\.\\d+(?:[-+]|$)/.test(actual) &&\n compare(resolved[name]!, actual) < 0;\n return {\n package: name,\n installed: actual,\n declaration: installed[name],\n target: resolved[name],\n downgradeBlocked,\n status: downgradeBlocked\n ? \"downgrade blocked\"\n : actual === resolved[name]\n ? \"up to date\"\n : \"update available\",\n };\n }),\n );\n if (!values.apply)\n return {\n packages,\n warning:\n \"Pre-1.0 minor updates may break compatibility. Review changelogs. No data format migration is performed.\",\n };\n if (packages.some((item) => item.downgradeBlocked))\n throw new Error(\n \"Automatic downgrades are unsupported; no dependencies were changed. Review the proposed versions and workspace release state manually.\",\n );\n const production = Object.fromEntries(\n packages\n .filter((p) => project.dependencies[p.package] && p.target !== p.installed)\n .map((p) => [p.package, p.target!]),\n );\n const development = Object.fromEntries(\n packages\n .filter((p) => project.devDependencies[p.package] && p.target !== p.installed)\n .map((p) => [p.package, p.target!]),\n );\n const update = plan(root);\n update.commands = installCommands(\n (await import(\"../init/project-detector.js\")).selectManager(\n project,\n values[\"package-manager\"],\n ),\n production,\n development,\n );\n io.signal?.throwIfAborted();\n await executeFiles(update, async () => {\n for (const [command, ...args] of update.commands)\n await (io.runProcess ?? runProcess)({\n command: command!,\n args,\n cwd: root,\n signal: io.signal,\n });\n io.signal?.throwIfAborted();\n });\n return {\n status: \"updated\",\n packages,\n warning: \"Review pre-1.0 changes before deployment. Database formats were not migrated.\",\n };\n }\n if (values.evaluate || (definition.name === \"storage:check\" && values.live)) {\n const { config } = await (\n await import(\"../config.js\")\n ).loadConfig(cwd, values.config, values.database);\n if (definition.name === \"config:show\")\n return { trustedCodeEvaluated: true, configuration: redact(config) };\n if (definition.name === \"config:validate\")\n return { valid: true, trustedCodeEvaluated: true, databaseOpened: false };\n if (definition.name === \"storage:check\") {\n if (\n selectedOptions?.driver === \"disk\" &&\n !(await exists(\n resolve(\n root,\n process.env[\n (selected === \"default\"\n ? \"DURAXIS\"\n : \"DURAXIS_\" + selected.toUpperCase().replace(/-/g, \"_\")) + \"_STORAGE_DIRECTORY\"\n ] ?? selectedOptions.storageDirectory,\n \"journal.log\",\n ),\n ))\n )\n throw new Error(\n \"Live Disk check requires an existing initialized directory; refusing to create database files\",\n );\n const database = await config.createDatabase();\n try {\n await database.getCollectionDefinitions();\n return {\n valid: true,\n live: true,\n warning:\n \"Trusted factory executed. Disk ownership was temporarily acquired; normal driver recovery may occur. No test objects were written.\",\n };\n } finally {\n await database.close({ closeStorage: true });\n }\n }\n }\n if (!managed)\n return (() => {\n if (definition.name === \"config:show\" || definition.name === \"config:validate\") {\n if (!project.configFiles.length && !values.config)\n throw new Error(\"No configuration found; run duraxis init\");\n return {\n unresolved: true,\n files: values.config ? [resolve(cwd, values.config)] : project.configFiles,\n message:\n \"Executable configuration was not evaluated. Use --evaluate explicitly for trusted application code.\",\n };\n }\n throw new Error(\n \"This operation requires duraxis.project.json managed settings; preserve executable configurations and integrate manually.\",\n );\n })();\n if (!selectedOptions) throw new Error(\"Unknown named database\");\n if (definition.name === \"connection:list\")\n return {\n default: managed.defaultConnection,\n connections: Object.entries(managed.connections).map(([name, connection]) => ({\n name,\n driver: connection.driver,\n namespace: connection.namespace,\n migrations: connection.migrations,\n })),\n };\n if (definition.name === \"config:show\")\n return {\n configuration: redact(selectedOptions),\n connection: selected,\n environment: \"Values are not read or displayed\",\n databaseOpened: false,\n };\n if (definition.name === \"config:validate\" || definition.name === \"storage:check\") {\n const checks = await diagnostics(project, managed, selected);\n return {\n failed: checks.some((c) => c.level === \"FAIL\"),\n diagnostics: checks,\n databaseOpened: false,\n };\n }\n if (definition.name === \"config:set\") {\n const [key, value] = positionals;\n if (!key || value === undefined) throw new Error(\"Usage: config:set <key> <value>\");\n if (\n !new Set([\n \"namespace\",\n \"storageDirectory\",\n \"bucket\",\n \"prefix\",\n \"region\",\n \"endpoint\",\n \"schemaMode\",\n ]).has(key)\n )\n throw new Error(\n \"Unsupported managed key; edit application factories and settings manually. Secrets must use environment references.\",\n );\n if (key === \"storageDirectory\" && selectedOptions.driver === \"disk\")\n assertStorageDirectory(root, value, selectedOptions.sourceDir, selectedOptions.migrations);\n if (\n key === \"namespace\" &&\n (!/^[A-Za-z0-9_/-]{1,128}$/.test(value) ||\n value.split(\"/\").some((part) => !part || part === \"..\"))\n )\n throw new Error(\"Invalid namespace\");\n if (key === \"schemaMode\" && ![\"create\", \"validate\", \"validate-managed\"].includes(value))\n throw new Error(\"Invalid schemaMode\");\n if (key === \"schemaMode\" && selectedOptions.migrations && value === \"create\")\n throw new Error(\"Migrations require validation schema mode\");\n if (key === \"endpoint\") {\n const url = new URL(value);\n if (\n ![\"https:\", \"http:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new Error(\"Endpoint must not contain secrets\");\n }\n if (/[\\r\\n\\0]/.test(value))\n throw new Error(\"Configuration values must not contain control characters\");\n if (key === \"bucket\" && !/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(value))\n throw new Error(\"Invalid bucket\");\n const files = plan(root);\n await addFile(\n files,\n \"duraxis.project.json\",\n JSON.stringify(\n {\n ...managed,\n connections: { ...managed.connections, [selected]: { ...selectedOptions, [key]: value } },\n },\n null,\n 2,\n ) + \"\\n\",\n true,\n );\n return execute(files);\n }\n if (definition.name === \"connection:add\") {\n const name = connectionName(positionals[0] ?? \"\");\n const options = await initializationOptions(project, {\n ...values,\n namespace: values.namespace ?? name,\n language: values.language ?? selectedOptions.language,\n \"module-format\": values[\"module-format\"] ?? selectedOptions.moduleFormat,\n \"source-dir\": values[\"source-dir\"] ?? selectedOptions.sourceDir,\n });\n if (\n options.driver === \"disk\" &&\n Object.values(managed.connections).some(\n (existing) =>\n existing.driver === \"disk\" && existing.storageDirectory === options.storageDirectory,\n )\n )\n throw new Error(\n \"Named Disk connections require a distinct --storage-directory to avoid ownership conflicts\",\n );\n const needed = [...requiredPackages(options), \"@duraxis/cli\"];\n const existing = { ...project.dependencies, ...project.devDependencies };\n const resolved = options.install\n ? await resolveDependencies(\n needed,\n existing,\n new RegistryClient(\n await configuredRegistry(project, values.registry),\n io.fetch,\n io.signal,\n ),\n values.prerelease,\n )\n : Object.fromEntries(needed.map((n) => [n, existing[n] ?? \"latest\"]));\n const dependencies = Object.fromEntries(\n Object.entries(resolved).filter(\n ([n]) => n !== \"@duraxis/cli\" && needed.includes(n) && !existing[n],\n ),\n );\n const dev: Record<string, string> = existing[\"@duraxis/cli\"]\n ? {}\n : { \"@duraxis/cli\": resolved[\"@duraxis/cli\"]! };\n const files = await planInitialization(project, options, dependencies, dev, managed, name);\n files.commands = options.install ? installCommands(options.manager, dependencies, dev) : [];\n if (options.install && !files.commands.length)\n files.commands.push([options.manager, \"install\"]);\n return execute(files, async () => {\n for (const [command, ...args] of files.commands)\n await (io.runProcess ?? runProcess)({\n command: command!,\n args,\n cwd: root,\n signal: io.signal,\n });\n });\n }\n if (definition.name === \"generate:entity\" || definition.name === \"generate:module\") {\n const name = positionals[0];\n if (!name || !/^[A-Z][A-Za-z0-9]{0,63}$/.test(name))\n throw new Error(\"Use a PascalCase identifier (letters and digits only)\");\n const files = plan(root);\n const { source, runtime } = extensions(selectedOptions);\n const base = `${selectedOptions.sourceDir}/duraxis${selected === \"default\" ? \"\" : `/connections/${selected}`}`;\n if (definition.name === \"generate:entity\") {\n if (!selectedOptions.orm) throw new Error(\"Entity generation requires ORM integration\");\n const filename = `${name.replace(/[A-Z]/g, (letter, index: number) => `${index ? \"-\" : \"\"}${letter.toLowerCase()}`)}.entity`;\n await addFile(\n files,\n `${base}/${filename}.${source}`,\n entitySource(\n name,\n name.toLowerCase() + \"s\",\n selectedOptions.language,\n selectedOptions.moduleFormat,\n ),\n );\n const registryPath = `${base}/entities.${source}`;\n const original = await readFile(join(root, registryPath), \"utf8\");\n const ts = (await import(\"typescript\")).default;\n const ast = ts.createSourceFile(registryPath, original, ts.ScriptTarget.Latest, true);\n let array: import(\"typescript\").ArrayLiteralExpression | undefined;\n for (const statement of ast.statements) {\n if (ts.isVariableStatement(statement))\n for (const declaration of statement.declarationList.declarations)\n if (\n ts.isIdentifier(declaration.name) &&\n declaration.name.text === \"entities\" &&\n declaration.initializer &&\n ts.isArrayLiteralExpression(declaration.initializer)\n )\n array = declaration.initializer;\n if (\n ts.isExpressionStatement(statement) &&\n ts.isBinaryExpression(statement.expression) &&\n ts.isPropertyAccessExpression(statement.expression.left) &&\n statement.expression.left.getText(ast) === \"exports.entities\" &&\n ts.isArrayLiteralExpression(statement.expression.right)\n )\n array = statement.expression.right;\n }\n if (\n !original.startsWith(\"// Duraxis managed entity registry\") ||\n !array ||\n array.elements.some((e) => !ts.isIdentifier(e))\n )\n throw new Error(\n \"Entity registry is user-authored or unsupported; add the entity manually. No files were written.\",\n );\n const imported =\n selectedOptions.language === \"typescript\" || selectedOptions.moduleFormat === \"esm\"\n ? `import { ${name} } from \"./${filename}.${runtime}\";\\n`\n : `const { ${name} } = require(\"./${filename}.${runtime}\");\\n`;\n const updated =\n original.slice(0, array.end - 1) +\n (array.elements.length ? \", \" : \"\") +\n name +\n original.slice(array.end - 1);\n await addFile(\n files,\n registryPath,\n \"// Duraxis managed entity registry\\n\" +\n imported +\n updated.slice(\"// Duraxis managed entity registry\\n\".length),\n true,\n );\n } else {\n if (selectedOptions.framework !== \"nestjs\")\n throw new Error(\"Module generation requires NestJS integration\");\n const es =\n selectedOptions.language === \"typescript\" || selectedOptions.moduleFormat === \"esm\";\n const imports = es\n ? `import { Module } from \"@nestjs/common\";\\nimport { DuraxisModule } from \"@duraxis/nestjs\";\\nimport { entities } from \"./entities.${runtime}\";`\n : `const { Module } = require(\"@nestjs/common\");\\nconst { DuraxisModule } = require(\"@duraxis/nestjs\");\\nconst { entities } = require(\"./entities.${runtime}\");`;\n const metadata = `{ imports: [DuraxisModule.forFeature(entities, ${JSON.stringify(selected)})], exports: [DuraxisModule] }`;\n await addFile(\n files,\n `${base}/${name}.module.${source}`,\n `${imports}\\n${selectedOptions.language === \"typescript\" ? `@Module(${metadata})\\nexport class ${name}Module {}` : `${selectedOptions.moduleFormat === \"esm\" ? \"export \" : \"\"}class ${name}Module {}\\nModule(${metadata})(${name}Module);\\n${!es ? `exports.${name}Module = ${name}Module;` : \"\"}`}\\n`,\n );\n }\n return execute(files);\n }\n throw new Error(`No handler for ${definition.name}`);\n}\n"],"mappings":";;;;;;AAGA,eAAsB,iBACpB,MACA,MAC8C;CAC9C,IAAI;CACJ,IAAI;EACF,YAAY,QAAQ,cAAc,KAAK,MAAM,cAAc,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC;CAC7E,QAAQ;EACN;CACF;CACA,KAAK,IAAI,QAAQ,GAAG,QAAQ,IAAI,SAAS;EACvC,IAAI;GACF,MAAM,WAAW,MAAM,WAAW,KAAK,WAAW,cAAc,CAAC;GACjE,IAAI,SAAS,SAAS,MAAM,OAAO;EACrC,SAAS,OAAO;GACd,IAAI,EAAE,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,WAAW,MAAM;EACrF;EACA,IAAI,QAAQ,SAAS,MAAM,WAAW;EACtC,YAAY,QAAQ,SAAS;CAC/B;AAEF;;ACXA,SAAgB,UAAU,SAAyB,MAAuB;CACxE,IACE,CAAC,QAAQ,aAAa,SACtB,CAAC,QAAQ,gBAAgB,SACzB,CAAC,WAAW,KAAK,QAAQ,MAAM,gBAAgB,IAAI,CAAC,GAEpD,OAAO;CACT,IAAI;EACF,cAAc,KAAK,QAAQ,MAAM,cAAc,CAAC,CAAC,CAAC,QAAQ,I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AAK,WAAW,KAAK,WAAW,KAAK,GACrS;EACF;EACA,OAAO,QAAQ,KAAK;CACtB;CACA,MAAM,IAAI,MAAM,kBAAkB,WAAW,MAAM;AACrD"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import type { ProcessRunner } from "./dependencies/package-manager.js";
|
|
2
|
+
import type { Prompt } from "./terminal/prompts.js";
|
|
1
3
|
export interface CLIIO {
|
|
2
4
|
readonly cwd?: string;
|
|
3
5
|
readonly out?: (message: string) => void;
|
|
4
6
|
readonly error?: (message: string) => void;
|
|
7
|
+
readonly fetch?: typeof fetch;
|
|
8
|
+
readonly runProcess?: ProcessRunner;
|
|
9
|
+
readonly prompt?: Prompt;
|
|
10
|
+
readonly interactive?: boolean;
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
5
12
|
}
|
|
6
13
|
export declare function runCLI(args: readonly string[], io?: CLIIO): Promise<number>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProjectContext } from "../init/project-detector.js";
|
|
2
|
+
import type { ManagedProject } from "../init/managed-project.js";
|
|
3
|
+
interface Diagnostic {
|
|
4
|
+
level: "PASS" | "WARN" | "FAIL" | "SKIP";
|
|
5
|
+
check: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function available(project: ProjectContext, name: string): boolean;
|
|
9
|
+
export declare function diagnostics(project: ProjectContext, managed?: ManagedProject, selected?: string): Promise<Diagnostic[]>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { access, readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, extname, resolve } from "node:path";
|
|
4
|
+
import { readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { registerHooks } from "node:module";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
// src/runtime.mjs
|
|
9
|
+
var MINIMUM_NODE_VERSION = "24.15.0";
|
|
10
|
+
/** Reject unsupported runtimes before importing the CLI and its Node.js APIs. */
|
|
11
|
+
function assertSupportedRuntime(version = process.versions.node) {
|
|
12
|
+
const actual = version.split(".").map(Number);
|
|
13
|
+
const minimum = MINIMUM_NODE_VERSION.split(".").map(Number);
|
|
14
|
+
const difference = actual.findIndex((part, index) => part !== minimum[index]);
|
|
15
|
+
if (!(/^\d+\.\d+\.\d+$/.test(version) && (difference === -1 || actual[difference] > minimum[difference]))) throw new Error(`Duraxis requires Node.js ${MINIMUM_NODE_VERSION} or newer.\nCurrent version: ${version}\nPlease upgrade your Node.js installation.`);
|
|
16
|
+
}
|
|
17
|
+
// src/typescript-loader.ts
|
|
18
|
+
var sourceExtensions = {
|
|
19
|
+
".js": ".ts",
|
|
20
|
+
".mjs": ".mts",
|
|
21
|
+
".cjs": ".cts"
|
|
22
|
+
};
|
|
23
|
+
var hooks;
|
|
24
|
+
var modules = /* @__PURE__ */ new Set();
|
|
25
|
+
function localFile(value) {
|
|
26
|
+
if (!value.startsWith("file:")) return;
|
|
27
|
+
const url = new URL(value);
|
|
28
|
+
if (fileURLToPath(url).split(/[\\/]/).includes("node_modules")) return;
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
function exists(url) {
|
|
32
|
+
try {
|
|
33
|
+
return statSync(url).isFile();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code ?? "")) return false;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function remember(url) {
|
|
40
|
+
if (localFile(url)) modules.add(url);
|
|
41
|
+
}
|
|
42
|
+
/** One hook pair per library instance, limited to explicitly loaded local module graphs. */
|
|
43
|
+
function initializeTypeScriptLoader(entry) {
|
|
44
|
+
assertSupportedRuntime();
|
|
45
|
+
remember(entry.href);
|
|
46
|
+
if (hooks) return;
|
|
47
|
+
hooks = registerHooks({
|
|
48
|
+
resolve(specifier, context, nextResolve) {
|
|
49
|
+
const managed = /^(?:\.{1,2}[\\/]|\/|file:)/.test(specifier) && (modules.has(specifier) || context.parentURL !== void 0 && modules.has(context.parentURL));
|
|
50
|
+
try {
|
|
51
|
+
const resolved = nextResolve(specifier, context);
|
|
52
|
+
if (managed) remember(resolved.url);
|
|
53
|
+
return resolved;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (!managed || !["ERR_MODULE_NOT_FOUND", "MODULE_NOT_FOUND"].includes(error.code ?? "")) throw error;
|
|
56
|
+
const requested = localFile(new URL(specifier, context.parentURL).href);
|
|
57
|
+
if (!requested || exists(requested)) throw error;
|
|
58
|
+
const path = fileURLToPath(requested);
|
|
59
|
+
const extension = extname(path);
|
|
60
|
+
const mapped = sourceExtensions[extension];
|
|
61
|
+
if (!mapped) throw error;
|
|
62
|
+
const candidate = pathToFileURL(path.slice(0, -extension.length) + mapped);
|
|
63
|
+
candidate.search = requested.search;
|
|
64
|
+
candidate.hash = requested.hash;
|
|
65
|
+
if (!exists(candidate)) throw error;
|
|
66
|
+
const resolved = nextResolve(context.conditions.includes("require") ? fileURLToPath(candidate) : candidate.href, context);
|
|
67
|
+
remember(resolved.url);
|
|
68
|
+
return resolved;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
load(url, context, nextLoad) {
|
|
72
|
+
if (!modules.has(url)) return nextLoad(url, context);
|
|
73
|
+
const file = localFile(url);
|
|
74
|
+
if (!file) return nextLoad(url, context);
|
|
75
|
+
const path = fileURLToPath(file);
|
|
76
|
+
if (!/\.(?:ts|mts|cts)$/.test(path) || /\.d\.(?:ts|mts|cts)$/.test(path)) return nextLoad(url, context);
|
|
77
|
+
const commonjs = path.endsWith(".cts");
|
|
78
|
+
const result = ts.transpileModule(readFileSync(file, "utf8"), {
|
|
79
|
+
fileName: path,
|
|
80
|
+
reportDiagnostics: true,
|
|
81
|
+
compilerOptions: {
|
|
82
|
+
target: ts.ScriptTarget.ES2022,
|
|
83
|
+
module: commonjs ? ts.ModuleKind.NodeNext : ts.ModuleKind.ESNext,
|
|
84
|
+
...commonjs ? { moduleResolution: ts.ModuleResolutionKind.NodeNext } : {},
|
|
85
|
+
experimentalDecorators: true,
|
|
86
|
+
emitDecoratorMetadata: true,
|
|
87
|
+
useDefineForClassFields: false,
|
|
88
|
+
sourceMap: false
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const errors = (result.diagnostics ?? []).filter((item) => item.category == ts.DiagnosticCategory.Error);
|
|
92
|
+
if (errors.length) throw new Error(ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
93
|
+
getCurrentDirectory: () => process.cwd(),
|
|
94
|
+
getCanonicalFileName: (file) => file,
|
|
95
|
+
getNewLine: () => "\n"
|
|
96
|
+
}));
|
|
97
|
+
return {
|
|
98
|
+
format: commonjs ? "commonjs" : "module",
|
|
99
|
+
source: (commonjs ? "\"use strict\";\nrequire = require(\"node:module\").createRequire(__filename);\n" : "") + result.outputText,
|
|
100
|
+
shortCircuit: true
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Call only when no config/entity/migration callbacks need further dynamic imports. Node's module cache is retained. */
|
|
106
|
+
function disposeTypeScriptLoader() {
|
|
107
|
+
hooks?.deregister();
|
|
108
|
+
hooks = void 0;
|
|
109
|
+
}
|
|
110
|
+
// src/config.ts
|
|
111
|
+
var config_exports = /* @__PURE__ */ __exportAll({ loadConfig: () => loadConfig });
|
|
112
|
+
function defineDuraxisConfig(config) {
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
async function importFile(path) {
|
|
116
|
+
const url = path instanceof URL ? path : pathToFileURL(path);
|
|
117
|
+
initializeTypeScriptLoader(url);
|
|
118
|
+
return import(url.href);
|
|
119
|
+
}
|
|
120
|
+
async function loadConfig(cwd, explicit, database) {
|
|
121
|
+
let path;
|
|
122
|
+
if (explicit) path = resolve(cwd, explicit);
|
|
123
|
+
else {
|
|
124
|
+
let directory = resolve(cwd);
|
|
125
|
+
while (true) {
|
|
126
|
+
for (const name of [
|
|
127
|
+
"duraxis.config.ts",
|
|
128
|
+
"duraxis.config.mts",
|
|
129
|
+
"duraxis.config.js",
|
|
130
|
+
"duraxis.config.mjs",
|
|
131
|
+
"duraxis.config.cts",
|
|
132
|
+
"duraxis.config.cjs"
|
|
133
|
+
]) {
|
|
134
|
+
const candidate = resolve(directory, name);
|
|
135
|
+
try {
|
|
136
|
+
await access(candidate);
|
|
137
|
+
path = candidate;
|
|
138
|
+
break;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error.code != "ENOENT") throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (path || dirname(directory) == directory) break;
|
|
144
|
+
directory = dirname(directory);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!path) throw new Error("No duraxis.config.ts or JavaScript configuration found");
|
|
148
|
+
const base = (await importFile(path)).default;
|
|
149
|
+
const config = database ? base?.databases?.[database] : base;
|
|
150
|
+
if (!config || typeof config.createDatabase != "function" || config.moduleFormat !== void 0 && config.moduleFormat !== "esm" && config.moduleFormat !== "cjs" || config.entities !== void 0 && !Array.isArray(config.entities) && typeof config.entities != "function" || config.migrations !== void 0 && (typeof config.migrations.directory != "string" || typeof config.migrations.snapshots != "string" || config.migrations.format !== void 0 && !["ts", "js"].includes(config.migrations.format))) throw new Error("Invalid Duraxis configuration or unknown named database");
|
|
151
|
+
return {
|
|
152
|
+
config,
|
|
153
|
+
root: dirname(path),
|
|
154
|
+
path
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async function readJSON(path) {
|
|
158
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
159
|
+
}
|
|
160
|
+
function requireMigrationConfig(config) {
|
|
161
|
+
if (!config.migrations) throw new Error("Migrations are disabled for this connection. Enable them before running migration commands.");
|
|
162
|
+
}
|
|
163
|
+
export { readJSON as a, loadConfig as i, defineDuraxisConfig as n, requireMigrationConfig as o, importFile as r, disposeTypeScriptLoader as s, config_exports as t };
|
|
164
|
+
|
|
165
|
+
//# sourceMappingURL=config-CjMUqEhV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-CjMUqEhV.js","names":[],"sources":["../src/runtime.mjs","../src/typescript-loader.ts","../src/config.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 moduleFormat?: \"esm\" | \"cjs\";\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 (config.moduleFormat !== undefined &&\n config.moduleFormat !== \"esm\" &&\n config.moduleFormat !== \"cjs\") ||\n (config.entities !== undefined &&\n !Array.isArray(config.entities) &&\n typeof config.entities != \"function\") ||\n (config.migrations !== undefined &&\n (typeof config.migrations.directory != \"string\" ||\n typeof config.migrations.snapshots != \"string\" ||\n (config.migrations.format !== undefined &&\n ![\"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\nexport function requireMigrationConfig(\n config: DuraxisConnectionConfig,\n): asserts config is DuraxisConnectionConfig & {\n migrations: NonNullable<DuraxisConnectionConfig[\"migrations\"]>;\n} {\n if (!config.migrations)\n throw new Error(\n \"Migrations are disabled for this connection. Enable them before running migration commands.\",\n );\n}\n"],"mappings":";;;;;;;;AAAA,IAAa,uBAAuB;;AAGpC,SAA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AI,MAAM,wDAAwD;CAInF,MAAM,QAAO,MAFS,WAAW,IAAI,EAAA,CAEjB;CAEpB,MAAM,SAAS,WAAW,MAAM,YAAY,YAAY;CAExD,IACE,CAAC,UACD,OAAO,OAAO,kBAAkB,cAC/B,OAAO,iBAAiB,KAAA,KACvB,OAAO,iBAAiB,SACxB,OAAO,iBAAiB,SACzB,OAAO,aAAa,KAAA,KACnB,CAAC,MAAM,QAAQ,OAAO,QAAQ,KAC9B,OAAO,OAAO,YAAY,cAC3B,OAAO,eAAe,KAAA,MACpB,OAAO,OAAO,WAAW,aAAa,YACrC,OAAO,OAAO,WAAW,aAAa,YACrC,OAAO,WAAW,WAAW,KAAA,KAC5B,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,SAAS,OAAO,WAAW,MAAM,IAErD,MAAM,IAAI,MAAM,yDAAyD;CAE3E,OAAO;EAAE;EAAQ,MAAM,QAAQ,IAAI;EAAG;CAAK;AAC7C;AAEA,eAAsB,SAAY,MAA0B;CAC1D,OAAO,KAAK,MAAM,MAAM,SAAS,MAAM,MAAM,CAAC;AAChD;AAEA,SAAgB,uBACd,QAGA;CACA,IAAI,CAAC,OAAO,YACV,MAAM,IAAI,MACR,6FACF;AACJ"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DuraxisDatabase } from "@duraxis/core";
|
|
2
2
|
import type { EntityClass } from "@duraxis/orm";
|
|
3
3
|
export interface DuraxisConnectionConfig {
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
4
|
+
readonly moduleFormat?: "esm" | "cjs";
|
|
5
|
+
readonly entities?: readonly EntityClass[] | (() => readonly EntityClass[] | Promise<readonly EntityClass[]>);
|
|
6
|
+
readonly migrations?: {
|
|
6
7
|
readonly directory: string;
|
|
7
8
|
readonly snapshots: string;
|
|
8
9
|
readonly format?: "ts" | "js";
|
|
@@ -20,3 +21,6 @@ export declare function loadConfig(cwd: string, explicit?: string, database?: st
|
|
|
20
21
|
path: string;
|
|
21
22
|
}>;
|
|
22
23
|
export declare function readJSON<T>(path: string): Promise<T>;
|
|
24
|
+
export declare function requireMigrationConfig(config: DuraxisConnectionConfig): asserts config is DuraxisConnectionConfig & {
|
|
25
|
+
migrations: NonNullable<DuraxisConnectionConfig["migrations"]>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { RegistryClient } from "./registry-client.js";
|
|
2
|
+
export declare function resolveDependencies(names: readonly string[], existing: Record<string, string>, registry: RegistryClient, prerelease?: boolean, node?: string, preserveExisting?: boolean): Promise<Record<string, string>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function installedPackage(root: string, name: string): Promise<Record<string, unknown> | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type PackageManager } from "../init/project-detector.js";
|
|
2
|
+
export interface ProcessRequest {
|
|
3
|
+
command: string;
|
|
4
|
+
args: readonly string[];
|
|
5
|
+
cwd: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export type ProcessRunner = (request: ProcessRequest) => Promise<void>;
|
|
9
|
+
export declare const runProcess: ProcessRunner;
|
|
10
|
+
export declare function installCommands(manager: PackageManager, dependencies: Record<string, string>, development: Record<string, string>): string[][];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface PublishedVersion {
|
|
2
|
+
version: string;
|
|
3
|
+
dependencies: Record<string, string>;
|
|
4
|
+
peers: Record<string, string>;
|
|
5
|
+
optionalPeers: Set<string>;
|
|
6
|
+
node?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PackageMetadata {
|
|
9
|
+
name: string;
|
|
10
|
+
versions: PublishedVersion[];
|
|
11
|
+
tags: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare class RegistryClient {
|
|
14
|
+
private readonly registry;
|
|
15
|
+
private readonly request;
|
|
16
|
+
private readonly signal?;
|
|
17
|
+
private readonly cache;
|
|
18
|
+
constructor(registry?: string, request?: typeof fetch, signal?: AbortSignal | undefined);
|
|
19
|
+
get(name: string): Promise<PackageMetadata>;
|
|
20
|
+
private load;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Version {
|
|
2
|
+
major: number;
|
|
3
|
+
minor: number;
|
|
4
|
+
patch: number;
|
|
5
|
+
prerelease: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function version(value: string): Version;
|
|
8
|
+
export declare function compare(a: string, b: string): number;
|
|
9
|
+
export declare function satisfies(actual: string, range: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface FileChange {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string;
|
|
4
|
+
before?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FilePlan {
|
|
7
|
+
root: string;
|
|
8
|
+
files: FileChange[];
|
|
9
|
+
directories: string[];
|
|
10
|
+
warnings: string[];
|
|
11
|
+
dependencies: Record<string, string>;
|
|
12
|
+
devDependencies: Record<string, string>;
|
|
13
|
+
commands: string[][];
|
|
14
|
+
}
|
|
15
|
+
export declare function safeRelative(path: string): string;
|
|
16
|
+
export declare function assertNoSymlinks(path: string): Promise<void>;
|
|
17
|
+
export declare function addFile(plan: FilePlan, path: string, content: string, update?: boolean): Promise<void>;
|
|
18
|
+
export declare function executeFiles<T>(plan: FilePlan, after: () => Promise<T>): Promise<T>;
|
|
19
|
+
/** Public plans describe changes without echoing secrets in existing file contents. */
|
|
20
|
+
export declare function describePlan(plan: FilePlan): {
|
|
21
|
+
root: string;
|
|
22
|
+
files: {
|
|
23
|
+
path: string;
|
|
24
|
+
action: string;
|
|
25
|
+
bytes: number;
|
|
26
|
+
}[];
|
|
27
|
+
directories: string[];
|
|
28
|
+
dependencies: Record<string, string>;
|
|
29
|
+
devDependencies: Record<string, string>;
|
|
30
|
+
commands: string[][];
|
|
31
|
+
warnings: string[];
|
|
32
|
+
};
|