@duraxis/cli 0.3.0 → 0.5.1
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 +29 -0
- package/README.md +20 -71
- package/dist/admin.command-Dt5MnwJw.js +299 -0
- package/dist/admin.command-Dt5MnwJw.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 +9 -0
- package/dist/commands/init.command.d.ts +3 -0
- package/dist/commands/migration.command.d.ts +3 -0
- package/dist/commands/minimal-admin.d.ts +4 -0
- package/dist/config-BKscNXeW.js +204 -0
- package/dist/config-BKscNXeW.js.map +1 -0
- package/dist/config.d.ts +10 -8
- 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/file-plan-D-Sj3yv0.js +130 -0
- package/dist/file-plan-D-Sj3yv0.js.map +1 -0
- package/dist/filesystem/file-plan.d.ts +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +366 -551
- package/dist/index.js.map +1 -1
- package/dist/init/initialization-options.d.ts +32 -0
- package/dist/init/initialization-planner.d.ts +10 -0
- package/dist/init/nest-integration.d.ts +2 -0
- package/dist/init/project-detector.d.ts +27 -0
- package/dist/init/static-config.d.ts +16 -0
- package/dist/init.command-DrO29773.js +167 -0
- package/dist/init.command-DrO29773.js.map +1 -0
- package/dist/initialization-planner-B41PNGWc.js +315 -0
- package/dist/initialization-planner-B41PNGWc.js.map +1 -0
- package/dist/migration.command-dhRbN4UI.js +361 -0
- package/dist/migration.command-dhRbN4UI.js.map +1 -0
- package/dist/minimal-admin-B4ur_cON.js +232 -0
- package/dist/minimal-admin-B4ur_cON.js.map +1 -0
- package/dist/nest-integration-KCc7ZaG6.js +93 -0
- package/dist/nest-integration-KCc7ZaG6.js.map +1 -0
- package/dist/package-manager-Ca5ArUf-.js +269 -0
- package/dist/package-manager-Ca5ArUf-.js.map +1 -0
- package/dist/project-detector-BQWeQZ8Q.js +174 -0
- package/dist/project-detector-BQWeQZ8Q.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/static-config-g_7qN12_.js +109 -0
- package/dist/static-config-g_7qN12_.js.map +1 -0
- package/dist/templates/project.d.ts +10 -0
- package/dist/terminal/prompts.d.ts +2 -0
- package/package.json +13 -8
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { s as satisfies } from "./package-manager-Ca5ArUf-.js";
|
|
3
|
+
import { exists, readObject, record, selectManager, stringMap } from "./project-detector-BQWeQZ8Q.js";
|
|
4
|
+
import { addFile, safeRelative } from "./file-plan-D-Sj3yv0.js";
|
|
5
|
+
import { basename, join, posix, resolve, sep } from "node:path";
|
|
6
|
+
// src/init/initialization-options.ts
|
|
7
|
+
var initialization_options_exports = /* @__PURE__ */ __exportAll({ assertStorageDirectory: () => assertStorageDirectory });
|
|
8
|
+
function assertStorageDirectory(root, value, sourceDir, migrations) {
|
|
9
|
+
if (!value.trim() || /[\r\n\0]/.test(value)) throw new Error("Invalid storage directory");
|
|
10
|
+
const directory = resolve(root, value);
|
|
11
|
+
const source = resolve(root, sourceDir);
|
|
12
|
+
const artifacts = resolve(root, "duraxis");
|
|
13
|
+
if (directory === resolve(root) || source === directory || source.startsWith(directory + sep) || migrations && (directory === artifacts || directory.startsWith(artifacts + sep))) throw new Error("Storage directory conflicts with project source or migration artifacts; choose a separate data directory");
|
|
14
|
+
}
|
|
15
|
+
function choice(value, choices, fallback, automatic = false) {
|
|
16
|
+
if (value === void 0 || automatic && value === "auto") return fallback;
|
|
17
|
+
const selected = choices.find((c) => c === value);
|
|
18
|
+
if (!selected) throw new Error(`Expected one of: ${choices.join(", ")}`);
|
|
19
|
+
return selected;
|
|
20
|
+
}
|
|
21
|
+
async function initializationOptions(context, values) {
|
|
22
|
+
if (record(context.manifest.engines) && typeof context.manifest.engines.node === "string" && !satisfies(process.versions.node, context.manifest.engines.node)) throw new Error("Project Node.js engines exclude the current supported runtime; update package.json before initializing Duraxis");
|
|
23
|
+
const framework = choice(values.framework, ["standalone", "nestjs"], context.nestjs ? "nestjs" : "standalone", true);
|
|
24
|
+
const driver = choice(values.driver, [
|
|
25
|
+
"memory",
|
|
26
|
+
"disk",
|
|
27
|
+
"s3",
|
|
28
|
+
"custom"
|
|
29
|
+
], "disk");
|
|
30
|
+
const orm = values.orm ?? (!values["no-orm"] && framework === "nestjs");
|
|
31
|
+
const migrations = values.migrations ?? (!values["no-migrations"] && driver !== "memory");
|
|
32
|
+
if (framework === "nestjs" && !orm) throw new Error("NestJS integration requires ORM; remove --no-orm");
|
|
33
|
+
if (values.example && !orm) throw new Error("Example entity generation requires --orm");
|
|
34
|
+
const language = choice(values.language, ["typescript", "javascript"], context.hasManifest ? context.language : "typescript", true);
|
|
35
|
+
const moduleFormat = choice(values["module-format"], ["esm", "cjs"], context.hasManifest ? context.moduleFormat : "esm", true);
|
|
36
|
+
if (context.hasManifest && moduleFormat !== context.moduleFormat) throw new Error("Selected module format differs from package.json; use the existing format or update the package type before initialization");
|
|
37
|
+
const sourceDir = safeRelative(values["source-dir"] ?? context.sourceDir);
|
|
38
|
+
const namespace = values.namespace ?? "default";
|
|
39
|
+
if (!/^[A-Za-z0-9_/-]{1,128}$/.test(namespace) || namespace.split("/").some((p) => !p || p === "." || p === "..")) throw new Error("Invalid namespace; namespace is not authorization");
|
|
40
|
+
for (const value of [
|
|
41
|
+
values["storage-directory"],
|
|
42
|
+
values.bucket,
|
|
43
|
+
values.prefix,
|
|
44
|
+
values.region
|
|
45
|
+
]) if (value && /[\r\n\0]/.test(value)) throw new Error("Configuration values must not contain control characters");
|
|
46
|
+
if (driver === "disk") assertStorageDirectory(context.root, values["storage-directory"] ?? "./data/duraxis", sourceDir, migrations);
|
|
47
|
+
const bucket = values.bucket;
|
|
48
|
+
if (driver === "s3" && (!bucket || !/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(bucket))) throw new Error("S3 requires --bucket with a valid general-purpose bucket name");
|
|
49
|
+
if (values.endpoint) {
|
|
50
|
+
const url = new URL(values.endpoint);
|
|
51
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error("Endpoint must not contain credentials, query or fragment");
|
|
52
|
+
}
|
|
53
|
+
const customModule = values["custom-module"];
|
|
54
|
+
if (driver === "custom" && (!customModule || !/^(?:\.?\.?\/[A-Za-z0-9_./-]+|(?:@[a-z0-9-]+\/)?[a-z0-9._-]+)$/.test(customModule) || customModule.includes(".."))) throw new Error("Custom storage requires a safe relative module or package reference via --custom-module");
|
|
55
|
+
if (customModule?.startsWith(".") && !await exists(resolve(context.root, customModule))) throw new Error("Custom storage module does not exist; implement the StorageDriver contract first");
|
|
56
|
+
const customExport = values["custom-export"] ?? "createStorage";
|
|
57
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(customExport)) throw new Error("Invalid custom export name");
|
|
58
|
+
if (values["custom-options"]) safeRelative(values["custom-options"].replace(/^\.\//, ""));
|
|
59
|
+
if (values["custom-options"] && !await exists(resolve(context.root, values["custom-options"]))) throw new Error("Custom configuration module does not exist");
|
|
60
|
+
if (values["cursor-key-env"] && !/^[A-Z_][A-Z0-9_]*$/.test(values["cursor-key-env"])) throw new Error("Invalid cursor key environment variable name");
|
|
61
|
+
if (values["ownership-recovery"] && values["ownership-recovery"] !== "manual") throw new Error("CLI-generated Disk integrations require manual ownership recovery; automatic lock recovery is not enabled");
|
|
62
|
+
if (values["application-id"] && (values["application-id"].length > 128 || /[\r\n\0]/.test(values["application-id"]))) throw new Error("Invalid application identity");
|
|
63
|
+
const storageLimits = {};
|
|
64
|
+
const supported = driver === "memory" ? [
|
|
65
|
+
"max-stored-bytes",
|
|
66
|
+
"max-object-bytes",
|
|
67
|
+
"max-entries"
|
|
68
|
+
] : driver === "disk" ? [
|
|
69
|
+
"max-object-bytes",
|
|
70
|
+
"max-metadata-bytes",
|
|
71
|
+
"max-journal-bytes",
|
|
72
|
+
"max-queued-operations"
|
|
73
|
+
] : driver === "s3" ? [
|
|
74
|
+
"max-object-bytes",
|
|
75
|
+
"max-pending-operations",
|
|
76
|
+
"max-attempts"
|
|
77
|
+
] : [];
|
|
78
|
+
for (const name of [
|
|
79
|
+
"max-stored-bytes",
|
|
80
|
+
"max-object-bytes",
|
|
81
|
+
"max-entries",
|
|
82
|
+
"max-metadata-bytes",
|
|
83
|
+
"max-journal-bytes",
|
|
84
|
+
"max-queued-operations",
|
|
85
|
+
"max-pending-operations",
|
|
86
|
+
"max-attempts"
|
|
87
|
+
]) if (values[name] !== void 0) {
|
|
88
|
+
const value = Number(values[name]);
|
|
89
|
+
if (!supported.includes(name) || !Number.isSafeInteger(value) || value < 1 || name === "max-attempts" && value > 10 || name === "max-journal-bytes" && value < 1048576) throw new Error(`Invalid or unsupported --${name}`);
|
|
90
|
+
storageLimits[name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())] = value;
|
|
91
|
+
}
|
|
92
|
+
const resources = values["resources-file"] ? await readObject(resolve(context.root, values["resources-file"])) : {};
|
|
93
|
+
const { resourceLimits } = await import("@duraxis/core");
|
|
94
|
+
const known = Object.keys(resourceLimits());
|
|
95
|
+
if (Object.keys(resources).some((k) => !known.includes(k)) || Object.values(resources).some((v) => typeof v !== "number" || !Number.isSafeInteger(v) || v < 1)) throw new Error("Invalid Core resources JSON");
|
|
96
|
+
const schemaMode = choice(values["schema-mode"], [
|
|
97
|
+
"create",
|
|
98
|
+
"validate",
|
|
99
|
+
"validate-managed"
|
|
100
|
+
], migrations ? "validate-managed" : "create");
|
|
101
|
+
if (migrations && schemaMode === "create") throw new Error("Migrations require validate or validate-managed schema mode");
|
|
102
|
+
return {
|
|
103
|
+
applicationId: values["application-id"],
|
|
104
|
+
framework,
|
|
105
|
+
driver,
|
|
106
|
+
orm,
|
|
107
|
+
migrations,
|
|
108
|
+
language,
|
|
109
|
+
moduleFormat,
|
|
110
|
+
namespace,
|
|
111
|
+
sourceDir,
|
|
112
|
+
storageDirectory: values["storage-directory"] ?? "./data/duraxis",
|
|
113
|
+
bucket,
|
|
114
|
+
prefix: values.prefix ?? "",
|
|
115
|
+
region: values.region,
|
|
116
|
+
endpoint: values.endpoint,
|
|
117
|
+
forcePathStyle: values["force-path-style"] ?? false,
|
|
118
|
+
schemaMode,
|
|
119
|
+
example: values.example ?? false,
|
|
120
|
+
install: values.install ?? !values["no-install"],
|
|
121
|
+
manager: selectManager(context, values["package-manager"]),
|
|
122
|
+
customModule,
|
|
123
|
+
customExport,
|
|
124
|
+
customConstructor: values["custom-constructor"] ?? false,
|
|
125
|
+
customOptions: values["custom-options"],
|
|
126
|
+
resources,
|
|
127
|
+
storageLimits,
|
|
128
|
+
cursorKeyEnv: values["cursor-key-env"]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// src/templates/project.ts
|
|
132
|
+
function extensions(options) {
|
|
133
|
+
return {
|
|
134
|
+
source: options.language === "typescript" ? "ts" : "js",
|
|
135
|
+
runtime: "js"
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function entitySource(name, collection, language, format) {
|
|
139
|
+
if (language === "typescript") return `import { Entity, PrimaryKey, Column } from "@duraxis/orm";\n@Entity(${JSON.stringify(collection)})\nexport class ${name} {\n @PrimaryKey() id!: string;\n @Column({ type: "string", required: true }) name!: string;\n}\n`;
|
|
140
|
+
return `${format === "esm" ? "import { Entity, PrimaryKey, Column } from \"@duraxis/orm\";" : "const { Entity, PrimaryKey, Column } = require(\"@duraxis/orm\");"}\n${format === "esm" ? "export " : ""}class ${name} {}\nPrimaryKey()(${name}.prototype, "id");\nColumn({ type: "string", required: true })(${name}.prototype, "name");\nEntity(${JSON.stringify(collection)})(${name});\n${format === "cjs" ? `exports.${name} = ${name};\n` : ""}`;
|
|
141
|
+
}
|
|
142
|
+
function connectionSource(options, name, alias) {
|
|
143
|
+
const q = JSON.stringify;
|
|
144
|
+
const filteredLimits = Object.fromEntries(Object.entries(options.storageLimits).filter(([key]) => options.driver !== "s3" || key !== "maxAttempts"));
|
|
145
|
+
const limits = Object.keys(filteredLimits).length ? JSON.stringify(filteredLimits).slice(1, -1) + ", " : "";
|
|
146
|
+
const env = (key, fallback) => `env.${key}${fallback === void 0 ? "" : ` ?? ${q(fallback)}`}`;
|
|
147
|
+
const driver = options.driver === "memory" ? `new ${alias}(${Object.keys(options.storageLimits).length ? q(options.storageLimits) : ""})` : options.driver === "disk" ? `${alias}.open({ ${limits}directory: resolvePath(${env("STORAGE_DIRECTORY", options.storageDirectory)}), ownershipRecovery: { mode: "manual"${options.applicationId ? `, applicationId: ${q(options.applicationId)}` : ""} } })` : options.driver === "s3" ? `new ${alias}({ ${limits}bucket: ${env("S3_BUCKET", options.bucket)}, prefix: ${env("S3_PREFIX", options.prefix)}, client: { region: process.env.AWS_REGION${options.region ? ` ?? ${q(options.region)}` : ""}${options.endpoint ? `, endpoint: ${env("S3_ENDPOINT", options.endpoint)}` : ", endpoint: env.S3_ENDPOINT"}${options.forcePathStyle ? ", forcePathStyle: true" : ""}${options.storageLimits.maxAttempts ? `, maxAttempts: ${options.storageLimits.maxAttempts}` : ""} } })` : `${options.customConstructor ? "new " : ""}${alias}(${options.customOptions ? `customOptions_${name.replaceAll("-", "_")}` : ""})`;
|
|
148
|
+
return `{\n ${[
|
|
149
|
+
`location: ${options.moduleFormat === "esm" ? "import.meta.url" : "__filename"}`,
|
|
150
|
+
`driver: (${options.driver === "memory" || options.driver === "custom" ? "" : options.driver === "s3" ? "{ env }" : "{ env, resolvePath }"}) => ${driver}`,
|
|
151
|
+
...options.orm ? [`autoLoadEntities: ${name === "default" ? "true" : `{ directories: [${q(`./features/${name}`)}] }`}`] : [],
|
|
152
|
+
...options.migrations ? ["migrations: true"] : [],
|
|
153
|
+
...!options.migrations && options.orm ? [`schema: { mode: ${q(options.schemaMode)} }`] : [],
|
|
154
|
+
...options.migrations && options.schemaMode !== "validate-managed" ? [`schema: { mode: ${q(options.schemaMode)} }`] : [],
|
|
155
|
+
...options.namespace !== "default" || Object.keys(options.resources).length ? [`database: { ${options.namespace !== "default" ? `namespace: ${q(options.namespace)}, ` : ""}${Object.keys(options.resources).length ? `resources: ${q(options.resources)}` : ""} }`] : [],
|
|
156
|
+
...options.cursorKeyEnv ? [`cursorKeyEnv: ${q(options.cursorKeyEnv)}`] : []
|
|
157
|
+
].join(",\n ")},\n}`;
|
|
158
|
+
}
|
|
159
|
+
function configurationSource(managed, storageAlias) {
|
|
160
|
+
const options = managed.connections[managed.defaultConnection];
|
|
161
|
+
const es = options.language === "typescript" || options.moduleFormat === "esm";
|
|
162
|
+
const imports = [es ? "import { defineDuraxisConfig } from \"@duraxis/core\";" : "const { defineDuraxisConfig } = require(\"@duraxis/core\");"];
|
|
163
|
+
const entries = Object.entries(managed.connections).map(([name, connection], index) => {
|
|
164
|
+
const className = connection.driver === "disk" ? "AsyncDiskStorageDriver" : connection.driver === "s3" ? "S3StorageDriver" : connection.driver === "memory" ? "MemoryStorageDriver" : connection.customExport;
|
|
165
|
+
const alias = storageAlias ? `${storageAlias}${index || ""}` : Object.keys(managed.connections).length === 1 ? className : `Storage${index}`;
|
|
166
|
+
const module = connection.driver === "custom" ? connection.customModule.startsWith(".") ? posix.relative(connection.sourceDir, connection.customModule.replace(/^\.\//, "")) : connection.customModule : `@duraxis/storage-${connection.driver}`;
|
|
167
|
+
const reference = connection.driver === "custom" && connection.customModule.startsWith(".") && !module.startsWith(".") ? `./${module}` : module;
|
|
168
|
+
imports.push(es ? `import { ${className}${alias === className ? "" : ` as ${alias}`} } from ${JSON.stringify(reference)};` : `const { ${className}${alias === className ? "" : `: ${alias}`} } = require(${JSON.stringify(reference)});`);
|
|
169
|
+
if (connection.customOptions) {
|
|
170
|
+
let custom = posix.relative(connection.sourceDir, connection.customOptions.replace(/^\.\//, ""));
|
|
171
|
+
if (!custom.startsWith(".")) custom = `./${custom}`;
|
|
172
|
+
imports.push(es ? `import customOptions_${name.replaceAll("-", "_")} from ${JSON.stringify(custom)};` : `const customOptions_${name.replaceAll("-", "_")} = require(${JSON.stringify(custom)});`);
|
|
173
|
+
}
|
|
174
|
+
return [name, connectionSource(connection, name, alias)];
|
|
175
|
+
});
|
|
176
|
+
const value = entries.length === 1 && entries[0][0] === "default" ? entries[0][1] : `{ defaultConnection: ${JSON.stringify(managed.defaultConnection)}, connections: {\n${entries.map(([name, value]) => `${JSON.stringify(name)}: ${value}`).join(",\n")}\n} }`;
|
|
177
|
+
return `${imports.join("\n")}\n\n${es ? "export default" : "module.exports ="} defineDuraxisConfig(${value});\n`;
|
|
178
|
+
}
|
|
179
|
+
function projectSources(options, connection = "default") {
|
|
180
|
+
const files = {};
|
|
181
|
+
if (options.example && options.orm) files[`${options.sourceDir}/features/${connection}/example.entity.${extensions(options).source}`] = entitySource("Example", "examples", options.language, options.moduleFormat);
|
|
182
|
+
return files;
|
|
183
|
+
}
|
|
184
|
+
// src/init/initialization-planner.ts
|
|
185
|
+
function requiredPackages(options) {
|
|
186
|
+
return [
|
|
187
|
+
"@duraxis/core",
|
|
188
|
+
...options.driver === "custom" ? ["@duraxis/storage", ...options.customModule && !options.customModule.startsWith(".") ? [options.customModule] : []] : [`@duraxis/storage-${options.driver}`],
|
|
189
|
+
...options.orm ? ["@duraxis/orm", "reflect-metadata"] : [],
|
|
190
|
+
...options.framework === "nestjs" ? [
|
|
191
|
+
"@duraxis/nestjs",
|
|
192
|
+
"@nestjs/core",
|
|
193
|
+
"@nestjs/common",
|
|
194
|
+
"rxjs"
|
|
195
|
+
] : [],
|
|
196
|
+
...options.migrations ? ["@duraxis/migrations"] : []
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
async function planInitialization(context, options, dependencies, devDependencies, name = "default") {
|
|
200
|
+
if (context.configFiles.length) throw new Error("Existing Duraxis configuration found; no files were written.");
|
|
201
|
+
const managed = {
|
|
202
|
+
defaultConnection: "default",
|
|
203
|
+
connections: { default: options }
|
|
204
|
+
};
|
|
205
|
+
const plan = {
|
|
206
|
+
root: context.root,
|
|
207
|
+
files: [],
|
|
208
|
+
directories: [],
|
|
209
|
+
warnings: [],
|
|
210
|
+
dependencies,
|
|
211
|
+
devDependencies,
|
|
212
|
+
commands: []
|
|
213
|
+
};
|
|
214
|
+
const sources = projectSources(options, name);
|
|
215
|
+
for (const [path, content] of Object.entries(sources)) await addFile(plan, path, content);
|
|
216
|
+
const configPath = `${options.sourceDir}/duraxis.config.${extensions(options).source}`;
|
|
217
|
+
await addFile(plan, configPath, configurationSource(managed));
|
|
218
|
+
if (options.framework === "nestjs") {
|
|
219
|
+
const { readFile } = await import("node:fs/promises");
|
|
220
|
+
const { integrateNestModule } = await import("./nest-integration-KCc7ZaG6.js");
|
|
221
|
+
const candidates = context.nestModules.filter((path) => /(?:^|\/)app\.module\.[cm]?[jt]s$/.test(path) && path.startsWith(options.sourceDir + "/"));
|
|
222
|
+
if (candidates.length === 0 && !context.hasManifest) {
|
|
223
|
+
const app = `${options.sourceDir}/app.module.${extensions(options).source}`;
|
|
224
|
+
const es = options.language === "typescript" || options.moduleFormat === "esm";
|
|
225
|
+
const imports = es ? `import { Module } from "@nestjs/common";\nimport { DuraxisModule } from "@duraxis/nestjs";\nimport duraxisConfig from "./duraxis.config.js";` : `const { Module } = require("@nestjs/common");\nconst { DuraxisModule } = require("@duraxis/nestjs");\nconst duraxisConfig = require("./duraxis.config.js");`;
|
|
226
|
+
const metadata = "{ imports: [DuraxisModule.forRoot(duraxisConfig)] }";
|
|
227
|
+
await addFile(plan, app, imports + "\n" + (options.language === "typescript" ? `@Module(${metadata})\nexport class AppModule {}\n` : `${es ? "export " : ""}class AppModule {}\nModule(${metadata})(AppModule);\n${es ? "" : "exports.AppModule = AppModule;\n"}`));
|
|
228
|
+
} else {
|
|
229
|
+
if (candidates.length !== 1) throw new Error("Select one NestJS application using --source-dir (and --directory for its package). Expected one existing app.module.ts; no files were written.");
|
|
230
|
+
const app = candidates[0];
|
|
231
|
+
const original = await readFile(join(context.root, app), "utf8");
|
|
232
|
+
await addFile(plan, app, integrateNestModule(original, app, configPath), true);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (options.migrations) {
|
|
236
|
+
const base = name === "default" ? "duraxis" : `duraxis/${name}`;
|
|
237
|
+
plan.directories.push(`${base}/migrations`, `${base}/snapshots`);
|
|
238
|
+
const { createSnapshot } = await import("@duraxis/migrations");
|
|
239
|
+
await addFile(plan, `${base}/snapshots/baseline.json`, JSON.stringify(createSnapshot(null, null, []), null, 2) + "\n");
|
|
240
|
+
}
|
|
241
|
+
if (options.language === "typescript" && !await exists(join(context.root, "tsconfig.json"))) await addFile(plan, "tsconfig.json", JSON.stringify({
|
|
242
|
+
compilerOptions: {
|
|
243
|
+
target: "ES2023",
|
|
244
|
+
module: "NodeNext",
|
|
245
|
+
moduleResolution: "NodeNext",
|
|
246
|
+
experimentalDecorators: true,
|
|
247
|
+
emitDecoratorMetadata: true,
|
|
248
|
+
useDefineForClassFields: false,
|
|
249
|
+
strict: true,
|
|
250
|
+
outDir: "dist",
|
|
251
|
+
rootDir: options.sourceDir,
|
|
252
|
+
skipLibCheck: true
|
|
253
|
+
},
|
|
254
|
+
include: [options.sourceDir]
|
|
255
|
+
}, null, 2) + "\n");
|
|
256
|
+
const read = await import("node:fs/promises");
|
|
257
|
+
const ignorePath = join(context.root, ".gitignore");
|
|
258
|
+
const beforeIgnore = await exists(ignorePath) ? await read.readFile(ignorePath, "utf8") : "";
|
|
259
|
+
const missing = [
|
|
260
|
+
"node_modules/",
|
|
261
|
+
"dist/",
|
|
262
|
+
".env",
|
|
263
|
+
".env.local",
|
|
264
|
+
".duraxis-init.lock",
|
|
265
|
+
...options.driver === "disk" && !options.storageDirectory.startsWith("/") && !options.storageDirectory.includes("..") ? [options.storageDirectory.replace(/^\.\//, "").replace(/\/$/, "") + "/"] : []
|
|
266
|
+
].filter((line) => !beforeIgnore.split(/\r?\n/).includes(line));
|
|
267
|
+
if (missing.length) await addFile(plan, ".gitignore", beforeIgnore + (beforeIgnore && !beforeIgnore.endsWith("\n") ? "\n" : "") + missing.join("\n") + "\n", true);
|
|
268
|
+
const env = [
|
|
269
|
+
`DURAXIS_NAMESPACE=${options.namespace}`,
|
|
270
|
+
...options.driver === "disk" ? [`DURAXIS_STORAGE_DIRECTORY=${options.storageDirectory}`] : [],
|
|
271
|
+
...options.driver === "s3" ? [
|
|
272
|
+
`DURAXIS_S3_BUCKET=${options.bucket}`,
|
|
273
|
+
`DURAXIS_S3_PREFIX=${options.prefix}`,
|
|
274
|
+
`AWS_REGION=${options.region ?? ""}`,
|
|
275
|
+
...options.endpoint ? [`DURAXIS_S3_ENDPOINT=${options.endpoint}`] : []
|
|
276
|
+
] : [],
|
|
277
|
+
...options.cursorKeyEnv ? [`# Secret 32-byte key encoded as hex; provision securely, never commit it`, `${options.cursorKeyEnv}=`] : []
|
|
278
|
+
].join("\n").replace(/DURAXIS_/g, name === "default" ? "DURAXIS_" : `DURAXIS_${name.toUpperCase().replace(/-/g, "_")}_`) + "\n";
|
|
279
|
+
const envPath = join(context.root, ".env.example");
|
|
280
|
+
const beforeEnv = await exists(envPath) ? await read.readFile(envPath, "utf8") : "";
|
|
281
|
+
const declared = new Set(beforeEnv.split(/\r?\n/).map((line) => /^\s*(?:export\s+)?([A-Z_][A-Z0-9_]*)\s*=/.exec(line)?.[1]).filter(Boolean));
|
|
282
|
+
const additions = env.split("\n").filter((line) => line && !line.startsWith("#") && !declared.has(line.split("=")[0]));
|
|
283
|
+
if (additions.length) await addFile(plan, ".env.example", beforeEnv + (beforeEnv && !beforeEnv.endsWith("\n") ? "\n" : "") + additions.join("\n") + "\n", true);
|
|
284
|
+
const scripts = stringMap(context.manifest.scripts);
|
|
285
|
+
if (options.migrations && scripts["duraxis:status"] === void 0) scripts["duraxis:status"] = "duraxis migrate:status";
|
|
286
|
+
if (options.language === "typescript" && scripts.build === void 0 && !await exists(join(context.root, "tsconfig.json"))) scripts.build = "tsc -p tsconfig.json";
|
|
287
|
+
const manifest = {
|
|
288
|
+
...context.manifest,
|
|
289
|
+
...!context.hasManifest ? {
|
|
290
|
+
name: basename(context.root).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "duraxis-application",
|
|
291
|
+
private: true,
|
|
292
|
+
type: options.moduleFormat === "esm" ? "module" : "commonjs",
|
|
293
|
+
engines: { node: ">=24.15.0" }
|
|
294
|
+
} : {},
|
|
295
|
+
scripts,
|
|
296
|
+
...Object.keys(dependencies).length ? { dependencies: {
|
|
297
|
+
...context.dependencies,
|
|
298
|
+
...dependencies
|
|
299
|
+
} } : {},
|
|
300
|
+
...Object.keys(devDependencies).length ? { devDependencies: {
|
|
301
|
+
...context.devDependencies,
|
|
302
|
+
...devDependencies
|
|
303
|
+
} } : {}
|
|
304
|
+
};
|
|
305
|
+
await addFile(plan, "package.json", JSON.stringify(manifest, null, 2) + "\n", context.hasManifest);
|
|
306
|
+
if (options.driver === "memory") plan.warnings.push("Memory data and migration history are volatile and cannot persist across independent CLI processes.");
|
|
307
|
+
if (options.driver === "custom") plan.warnings.push("Custom driver is trusted executable code; it must implement conditional operations and bounded reads. Initialization does not certify persistence correctness.");
|
|
308
|
+
if (options.framework === "nestjs") plan.warnings.push("Duraxis registered directly in AppModule. Enable shutdown hooks in main for operating-system signal cleanup.");
|
|
309
|
+
if (options.migrations) plan.warnings.push("Run migrations before application startup. Core-only configurations use manual migrations; automatic generation requires entities.");
|
|
310
|
+
if (options.language === "typescript" && await exists(join(context.root, "tsconfig.json"))) plan.warnings.push("Existing tsconfig preserved. Verify NodeNext, experimentalDecorators, emitDecoratorMetadata and useDefineForClassFields:false; see duraxis doctor.");
|
|
311
|
+
return plan;
|
|
312
|
+
}
|
|
313
|
+
export { extensions as a, entitySource as i, requiredPackages as n, initializationOptions as o, configurationSource as r, initialization_options_exports as s, planInitialization as t };
|
|
314
|
+
|
|
315
|
+
//# sourceMappingURL=initialization-planner-B41PNGWc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialization-planner-B41PNGWc.js","names":[],"sources":["../src/init/initialization-options.ts","../src/templates/project.ts","../src/init/initialization-planner.ts"],"sourcesContent":["import { satisfies } from \"../dependencies/version-compatibility.js\";\nimport { resolve, sep } from \"node:path\";\nimport type { ParsedCommand } from \"../registry/argument-parser.js\";\nimport {\n selectManager,\n readObject,\n record,\n exists,\n type ProjectContext,\n type PackageManager,\n} from \"./project-detector.js\";\nimport { safeRelative } from \"../filesystem/file-plan.js\";\nexport interface InitializationOptions {\n framework: \"standalone\" | \"nestjs\";\n driver: \"memory\" | \"disk\" | \"s3\" | \"custom\";\n orm: boolean;\n migrations: boolean;\n language: \"typescript\" | \"javascript\";\n moduleFormat: \"esm\" | \"cjs\";\n namespace: string;\n sourceDir: string;\n storageDirectory: string;\n bucket?: string;\n prefix: string;\n region?: string;\n endpoint?: string;\n forcePathStyle: boolean;\n schemaMode: \"create\" | \"validate\" | \"validate-managed\";\n applicationId?: string;\n example: boolean;\n install: boolean;\n manager: PackageManager;\n customModule?: string;\n customExport: string;\n customConstructor: boolean;\n customOptions?: string;\n resources: Record<string, unknown>;\n storageLimits: Record<string, number>;\n cursorKeyEnv?: string;\n}\n\nexport function assertStorageDirectory(\n root: string,\n value: string,\n sourceDir: string,\n migrations: boolean,\n): void {\n if (!value.trim() || /[\\r\\n\\0]/.test(value)) throw new Error(\"Invalid storage directory\");\n const directory = resolve(root, value);\n const source = resolve(root, sourceDir);\n const artifacts = resolve(root, \"duraxis\");\n if (\n directory === resolve(root) ||\n source === directory ||\n source.startsWith(directory + sep) ||\n (migrations && (directory === artifacts || directory.startsWith(artifacts + sep)))\n )\n throw new Error(\n \"Storage directory conflicts with project source or migration artifacts; choose a separate data directory\",\n );\n}\nfunction choice<T extends string>(\n value: string | undefined,\n choices: readonly T[],\n fallback: T,\n automatic = false,\n): T {\n if (value === undefined || (automatic && value === \"auto\")) return fallback;\n const selected = choices.find((c) => c === value);\n if (!selected) throw new Error(`Expected one of: ${choices.join(\", \")}`);\n return selected;\n}\nexport async function initializationOptions(\n context: ProjectContext,\n values: ParsedCommand[\"values\"],\n): Promise<InitializationOptions> {\n if (\n record(context.manifest.engines) &&\n typeof context.manifest.engines.node === \"string\" &&\n !satisfies(process.versions.node, context.manifest.engines.node)\n )\n throw new Error(\n \"Project Node.js engines exclude the current supported runtime; update package.json before initializing Duraxis\",\n );\n const framework = choice(\n values.framework,\n [\"standalone\", \"nestjs\"],\n context.nestjs ? \"nestjs\" : \"standalone\",\n true,\n );\n const driver = choice(values.driver, [\"memory\", \"disk\", \"s3\", \"custom\"], \"disk\");\n const orm = values.orm ?? (!values[\"no-orm\"] && framework === \"nestjs\");\n const migrations = values.migrations ?? (!values[\"no-migrations\"] && driver !== \"memory\");\n if (framework === \"nestjs\" && !orm)\n throw new Error(\"NestJS integration requires ORM; remove --no-orm\");\n if (values.example && !orm) throw new Error(\"Example entity generation requires --orm\");\n const language = choice(\n values.language,\n [\"typescript\", \"javascript\"],\n context.hasManifest ? context.language : \"typescript\",\n true,\n );\n const moduleFormat = choice(\n values[\"module-format\"],\n [\"esm\", \"cjs\"],\n context.hasManifest ? context.moduleFormat : \"esm\",\n true,\n );\n if (context.hasManifest && moduleFormat !== context.moduleFormat)\n throw new Error(\n \"Selected module format differs from package.json; use the existing format or update the package type before initialization\",\n );\n const sourceDir = safeRelative(values[\"source-dir\"] ?? context.sourceDir);\n const namespace = values.namespace ?? \"default\";\n if (\n !/^[A-Za-z0-9_/-]{1,128}$/.test(namespace) ||\n namespace.split(\"/\").some((p) => !p || p === \".\" || p === \"..\")\n )\n throw new Error(\"Invalid namespace; namespace is not authorization\");\n for (const value of [values[\"storage-directory\"], values.bucket, values.prefix, values.region])\n if (value && /[\\r\\n\\0]/.test(value))\n throw new Error(\"Configuration values must not contain control characters\");\n if (driver === \"disk\")\n assertStorageDirectory(\n context.root,\n values[\"storage-directory\"] ?? \"./data/duraxis\",\n sourceDir,\n migrations,\n );\n const bucket = values.bucket;\n if (driver === \"s3\" && (!bucket || !/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(bucket)))\n throw new Error(\"S3 requires --bucket with a valid general-purpose bucket name\");\n if (values.endpoint) {\n const url = new URL(values.endpoint);\n if (\n ![\"http:\", \"https:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new Error(\"Endpoint must not contain credentials, query or fragment\");\n }\n const customModule = values[\"custom-module\"];\n if (\n driver === \"custom\" &&\n (!customModule ||\n !/^(?:\\.?\\.?\\/[A-Za-z0-9_./-]+|(?:@[a-z0-9-]+\\/)?[a-z0-9._-]+)$/.test(customModule) ||\n customModule.includes(\"..\"))\n )\n throw new Error(\n \"Custom storage requires a safe relative module or package reference via --custom-module\",\n );\n if (customModule?.startsWith(\".\") && !(await exists(resolve(context.root, customModule))))\n throw new Error(\n \"Custom storage module does not exist; implement the StorageDriver contract first\",\n );\n const customExport = values[\"custom-export\"] ?? \"createStorage\";\n if (!/^[A-Za-z_$][\\w$]*$/.test(customExport)) throw new Error(\"Invalid custom export name\");\n if (values[\"custom-options\"]) safeRelative(values[\"custom-options\"].replace(/^\\.\\//, \"\"));\n if (values[\"custom-options\"] && !(await exists(resolve(context.root, values[\"custom-options\"]))))\n throw new Error(\"Custom configuration module does not exist\");\n if (values[\"cursor-key-env\"] && !/^[A-Z_][A-Z0-9_]*$/.test(values[\"cursor-key-env\"]))\n throw new Error(\"Invalid cursor key environment variable name\");\n if (values[\"ownership-recovery\"] && values[\"ownership-recovery\"] !== \"manual\")\n throw new Error(\n \"CLI-generated Disk integrations require manual ownership recovery; automatic lock recovery is not enabled\",\n );\n if (\n values[\"application-id\"] &&\n (values[\"application-id\"].length > 128 || /[\\r\\n\\0]/.test(values[\"application-id\"]))\n )\n throw new Error(\"Invalid application identity\");\n const storageLimits: Record<string, number> = {};\n const supported =\n driver === \"memory\"\n ? [\"max-stored-bytes\", \"max-object-bytes\", \"max-entries\"]\n : driver === \"disk\"\n ? [\"max-object-bytes\", \"max-metadata-bytes\", \"max-journal-bytes\", \"max-queued-operations\"]\n : driver === \"s3\"\n ? [\"max-object-bytes\", \"max-pending-operations\", \"max-attempts\"]\n : [];\n for (const name of [\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 ] as const) {\n if (values[name] !== undefined) {\n const value = Number(values[name]);\n if (\n !supported.includes(name) ||\n !Number.isSafeInteger(value) ||\n value < 1 ||\n (name === \"max-attempts\" && value > 10) ||\n (name === \"max-journal-bytes\" && value < 1024 * 1024)\n )\n throw new Error(`Invalid or unsupported --${name}`);\n storageLimits[name.replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase())] = value;\n }\n }\n const resources = values[\"resources-file\"]\n ? await readObject(resolve(context.root, values[\"resources-file\"]))\n : {};\n const { resourceLimits } = await import(\"@duraxis/core\");\n const known = Object.keys(resourceLimits());\n if (\n Object.keys(resources).some((k) => !known.includes(k)) ||\n Object.values(resources).some((v) => typeof v !== \"number\" || !Number.isSafeInteger(v) || v < 1)\n )\n throw new Error(\"Invalid Core resources JSON\");\n const schemaMode = choice(\n values[\"schema-mode\"],\n [\"create\", \"validate\", \"validate-managed\"],\n migrations ? \"validate-managed\" : \"create\",\n );\n if (migrations && schemaMode === \"create\")\n throw new Error(\"Migrations require validate or validate-managed schema mode\");\n return {\n applicationId: values[\"application-id\"],\n framework,\n driver,\n orm,\n migrations,\n language,\n moduleFormat,\n namespace,\n sourceDir,\n storageDirectory: values[\"storage-directory\"] ?? \"./data/duraxis\",\n bucket,\n prefix: values.prefix ?? \"\",\n region: values.region,\n endpoint: values.endpoint,\n forcePathStyle: values[\"force-path-style\"] ?? false,\n schemaMode,\n example: values.example ?? false,\n install: values.install ?? !values[\"no-install\"],\n manager: selectManager(context, values[\"package-manager\"]),\n customModule,\n customExport,\n customConstructor: values[\"custom-constructor\"] ?? false,\n customOptions: values[\"custom-options\"],\n resources,\n storageLimits,\n cursorKeyEnv: values[\"cursor-key-env\"],\n };\n}\n","import { posix } from \"node:path\";\nimport type { InitializationOptions } from \"../init/initialization-options.js\";\nimport type { ProjectConfiguration } from \"../init/initialization-planner.js\";\nexport function extensions(options: Pick<InitializationOptions, \"language\" | \"moduleFormat\">) {\n return { source: options.language === \"typescript\" ? \"ts\" : \"js\", runtime: \"js\" };\n}\nexport function entitySource(\n name: string,\n collection: string,\n language: string,\n format: string,\n): string {\n if (language === \"typescript\")\n return `import { Entity, PrimaryKey, Column } from \"@duraxis/orm\";\\n@Entity(${JSON.stringify(collection)})\\nexport class ${name} {\\n @PrimaryKey() id!: string;\\n @Column({ type: \"string\", required: true }) name!: string;\\n}\\n`;\n return `${format === \"esm\" ? 'import { Entity, PrimaryKey, Column } from \"@duraxis/orm\";' : 'const { Entity, PrimaryKey, Column } = require(\"@duraxis/orm\");'}\\n${format === \"esm\" ? \"export \" : \"\"}class ${name} {}\\nPrimaryKey()(${name}.prototype, \"id\");\\nColumn({ type: \"string\", required: true })(${name}.prototype, \"name\");\\nEntity(${JSON.stringify(collection)})(${name});\\n${format === \"cjs\" ? `exports.${name} = ${name};\\n` : \"\"}`;\n}\n\nexport function connectionSource(\n options: InitializationOptions,\n name: string,\n alias: string,\n): string {\n const q = JSON.stringify;\n const filteredLimits = Object.fromEntries(\n Object.entries(options.storageLimits).filter(\n ([key]) => options.driver !== \"s3\" || key !== \"maxAttempts\",\n ),\n );\n const limits = Object.keys(filteredLimits).length\n ? JSON.stringify(filteredLimits).slice(1, -1) + \", \"\n : \"\";\n const env = (key: string, fallback: string | undefined) =>\n `env.${key}${fallback === undefined ? \"\" : ` ?? ${q(fallback)}`}`;\n const driver =\n options.driver === \"memory\"\n ? `new ${alias}(${Object.keys(options.storageLimits).length ? q(options.storageLimits) : \"\"})`\n : options.driver === \"disk\"\n ? `${alias}.open({ ${limits}directory: resolvePath(${env(\"STORAGE_DIRECTORY\", options.storageDirectory)}), ownershipRecovery: { mode: \"manual\"${options.applicationId ? `, applicationId: ${q(options.applicationId)}` : \"\"} } })`\n : options.driver === \"s3\"\n ? `new ${alias}({ ${limits}bucket: ${env(\"S3_BUCKET\", options.bucket)}, prefix: ${env(\"S3_PREFIX\", options.prefix)}, client: { region: process.env.AWS_REGION${options.region ? ` ?? ${q(options.region)}` : \"\"}${options.endpoint ? `, endpoint: ${env(\"S3_ENDPOINT\", options.endpoint)}` : \", endpoint: env.S3_ENDPOINT\"}${options.forcePathStyle ? \", forcePathStyle: true\" : \"\"}${options.storageLimits.maxAttempts ? `, maxAttempts: ${options.storageLimits.maxAttempts}` : \"\"} } })`\n : `${options.customConstructor ? \"new \" : \"\"}${alias}(${options.customOptions ? `customOptions_${name.replaceAll(\"-\", \"_\")}` : \"\"})`;\n const fields = [\n `location: ${options.moduleFormat === \"esm\" ? \"import.meta.url\" : \"__filename\"}`,\n `driver: (${options.driver === \"memory\" || options.driver === \"custom\" ? \"\" : options.driver === \"s3\" ? \"{ env }\" : \"{ env, resolvePath }\"}) => ${driver}`,\n ...(options.orm\n ? [\n `autoLoadEntities: ${name === \"default\" ? \"true\" : `{ directories: [${q(`./features/${name}`)}] }`}`,\n ]\n : []),\n ...(options.migrations ? [\"migrations: true\"] : []),\n ...(!options.migrations && options.orm ? [`schema: { mode: ${q(options.schemaMode)} }`] : []),\n ...(options.migrations && options.schemaMode !== \"validate-managed\"\n ? [`schema: { mode: ${q(options.schemaMode)} }`]\n : []),\n ...(options.namespace !== \"default\" || Object.keys(options.resources).length\n ? [\n `database: { ${options.namespace !== \"default\" ? `namespace: ${q(options.namespace)}, ` : \"\"}${Object.keys(options.resources).length ? `resources: ${q(options.resources)}` : \"\"} }`,\n ]\n : []),\n ...(options.cursorKeyEnv ? [`cursorKeyEnv: ${q(options.cursorKeyEnv)}`] : []),\n ];\n return `{\\n ${fields.join(\",\\n \")},\\n}`;\n}\nexport function configurationSource(managed: ProjectConfiguration, storageAlias?: string): string {\n const options = managed.connections[managed.defaultConnection]!;\n const es = options.language === \"typescript\" || options.moduleFormat === \"esm\";\n const imports = [\n es\n ? 'import { defineDuraxisConfig } from \"@duraxis/core\";'\n : 'const { defineDuraxisConfig } = require(\"@duraxis/core\");',\n ];\n const entries = Object.entries(managed.connections).map(([name, connection], index) => {\n const className =\n connection.driver === \"disk\"\n ? \"AsyncDiskStorageDriver\"\n : connection.driver === \"s3\"\n ? \"S3StorageDriver\"\n : connection.driver === \"memory\"\n ? \"MemoryStorageDriver\"\n : connection.customExport;\n const alias = storageAlias\n ? `${storageAlias}${index || \"\"}`\n : Object.keys(managed.connections).length === 1\n ? className\n : `Storage${index}`;\n const module =\n connection.driver === \"custom\"\n ? connection.customModule!.startsWith(\".\")\n ? posix.relative(connection.sourceDir, connection.customModule!.replace(/^\\.\\//, \"\"))\n : connection.customModule!\n : `@duraxis/storage-${connection.driver}`;\n const reference =\n connection.driver === \"custom\" &&\n connection.customModule!.startsWith(\".\") &&\n !module.startsWith(\".\")\n ? `./${module}`\n : module;\n imports.push(\n es\n ? `import { ${className}${alias === className ? \"\" : ` as ${alias}`} } from ${JSON.stringify(reference)};`\n : `const { ${className}${alias === className ? \"\" : `: ${alias}`} } = require(${JSON.stringify(reference)});`,\n );\n if (connection.customOptions) {\n let custom = posix.relative(\n connection.sourceDir,\n connection.customOptions.replace(/^\\.\\//, \"\"),\n );\n if (!custom.startsWith(\".\")) custom = `./${custom}`;\n imports.push(\n es\n ? `import customOptions_${name.replaceAll(\"-\", \"_\")} from ${JSON.stringify(custom)};`\n : `const customOptions_${name.replaceAll(\"-\", \"_\")} = require(${JSON.stringify(custom)});`,\n );\n }\n return [name, connectionSource(connection, name, alias)] as const;\n });\n const value =\n entries.length === 1 && entries[0]![0] === \"default\"\n ? entries[0]![1]\n : `{ defaultConnection: ${JSON.stringify(managed.defaultConnection)}, connections: {\\n${entries.map(([name, value]) => `${JSON.stringify(name)}: ${value}`).join(\",\\n\")}\\n} }`;\n return `${imports.join(\"\\n\")}\\n\\n${es ? \"export default\" : \"module.exports =\"} defineDuraxisConfig(${value});\\n`;\n}\nexport function projectSources(\n options: InitializationOptions,\n connection = \"default\",\n): Record<string, string> {\n const files: Record<string, string> = {};\n if (options.example && options.orm)\n files[\n `${options.sourceDir}/features/${connection}/example.entity.${extensions(options).source}`\n ] = entitySource(\"Example\", \"examples\", options.language, options.moduleFormat);\n return files;\n}\n","import { join, basename } from \"node:path\";\nimport { addFile, type FilePlan } from \"../filesystem/file-plan.js\";\nimport { exists, stringMap, type ProjectContext } from \"./project-detector.js\";\nimport type { InitializationOptions } from \"./initialization-options.js\";\nimport { projectSources, extensions, configurationSource } from \"../templates/project.js\";\nexport interface ProjectConfiguration {\n defaultConnection: string;\n connections: Record<string, InitializationOptions>;\n}\nexport function requiredPackages(options: InitializationOptions): string[] {\n return [\n \"@duraxis/core\",\n ...(options.driver === \"custom\"\n ? [\n \"@duraxis/storage\",\n ...(options.customModule && !options.customModule.startsWith(\".\")\n ? [options.customModule]\n : []),\n ]\n : [`@duraxis/storage-${options.driver}`]),\n ...(options.orm ? [\"@duraxis/orm\", \"reflect-metadata\"] : []),\n ...(options.framework === \"nestjs\"\n ? [\"@duraxis/nestjs\", \"@nestjs/core\", \"@nestjs/common\", \"rxjs\"]\n : []),\n ...(options.migrations ? [\"@duraxis/migrations\"] : []),\n ];\n}\nexport { configurationSource as configSource } from \"../templates/project.js\";\nexport async function planInitialization(\n context: ProjectContext,\n options: InitializationOptions,\n dependencies: Record<string, string>,\n devDependencies: Record<string, string>,\n name = \"default\",\n): Promise<FilePlan> {\n if (context.configFiles.length)\n throw new Error(\"Existing Duraxis configuration found; no files were written.\");\n const managed: ProjectConfiguration = {\n defaultConnection: \"default\",\n connections: { default: options },\n };\n const plan: FilePlan = {\n root: context.root,\n files: [],\n directories: [],\n warnings: [],\n dependencies,\n devDependencies,\n commands: [],\n };\n\n const sources = projectSources(options, name);\n for (const [path, content] of Object.entries(sources)) {\n await addFile(plan, path, content);\n }\n const configPath = `${options.sourceDir}/duraxis.config.${extensions(options).source}`;\n await addFile(plan, configPath, configurationSource(managed));\n if (options.framework === \"nestjs\") {\n const { readFile } = await import(\"node:fs/promises\");\n const { integrateNestModule } = await import(\"./nest-integration.js\");\n const candidates = context.nestModules.filter(\n (path) =>\n /(?:^|\\/)app\\.module\\.[cm]?[jt]s$/.test(path) && path.startsWith(options.sourceDir + \"/\"),\n );\n if (candidates.length === 0 && !context.hasManifest) {\n const app = `${options.sourceDir}/app.module.${extensions(options).source}`;\n const es = options.language === \"typescript\" || options.moduleFormat === \"esm\";\n const imports = es\n ? `import { Module } from \"@nestjs/common\";\\nimport { DuraxisModule } from \"@duraxis/nestjs\";\\nimport duraxisConfig from \"./duraxis.config.js\";`\n : `const { Module } = require(\"@nestjs/common\");\\nconst { DuraxisModule } = require(\"@duraxis/nestjs\");\\nconst duraxisConfig = require(\"./duraxis.config.js\");`;\n const metadata = \"{ imports: [DuraxisModule.forRoot(duraxisConfig)] }\";\n await addFile(\n plan,\n app,\n imports +\n \"\\n\" +\n (options.language === \"typescript\"\n ? `@Module(${metadata})\\nexport class AppModule {}\\n`\n : `${es ? \"export \" : \"\"}class AppModule {}\\nModule(${metadata})(AppModule);\\n${es ? \"\" : \"exports.AppModule = AppModule;\\n\"}`),\n );\n } else {\n if (candidates.length !== 1)\n throw new Error(\n \"Select one NestJS application using --source-dir (and --directory for its package). Expected one existing app.module.ts; no files were written.\",\n );\n const app = candidates[0]!;\n const original = await readFile(join(context.root, app), \"utf8\");\n await addFile(plan, app, integrateNestModule(original, app, configPath), true);\n }\n }\n if (options.migrations) {\n const base = name === \"default\" ? \"duraxis\" : `duraxis/${name}`;\n plan.directories.push(`${base}/migrations`, `${base}/snapshots`);\n const { createSnapshot } = await import(\"@duraxis/migrations\");\n await addFile(\n plan,\n `${base}/snapshots/baseline.json`,\n JSON.stringify(createSnapshot(null, null, []), null, 2) + \"\\n\",\n );\n }\n if (options.language === \"typescript\" && !(await exists(join(context.root, \"tsconfig.json\"))))\n await addFile(\n plan,\n \"tsconfig.json\",\n JSON.stringify(\n {\n compilerOptions: {\n target: \"ES2023\",\n module: \"NodeNext\",\n moduleResolution: \"NodeNext\",\n experimentalDecorators: true,\n emitDecoratorMetadata: true,\n useDefineForClassFields: false,\n strict: true,\n outDir: \"dist\",\n rootDir: options.sourceDir,\n skipLibCheck: true,\n },\n include: [options.sourceDir],\n },\n null,\n 2,\n ) + \"\\n\",\n );\n const read = await import(\"node:fs/promises\");\n const ignorePath = join(context.root, \".gitignore\");\n const beforeIgnore = (await exists(ignorePath)) ? await read.readFile(ignorePath, \"utf8\") : \"\";\n const ignored = [\n \"node_modules/\",\n \"dist/\",\n \".env\",\n \".env.local\",\n \".duraxis-init.lock\",\n ...(options.driver === \"disk\" &&\n !options.storageDirectory.startsWith(\"/\") &&\n !options.storageDirectory.includes(\"..\")\n ? [options.storageDirectory.replace(/^\\.\\//, \"\").replace(/\\/$/, \"\") + \"/\"]\n : []),\n ];\n const missing = ignored.filter((line) => !beforeIgnore.split(/\\r?\\n/).includes(line));\n if (missing.length)\n await addFile(\n plan,\n \".gitignore\",\n beforeIgnore +\n (beforeIgnore && !beforeIgnore.endsWith(\"\\n\") ? \"\\n\" : \"\") +\n missing.join(\"\\n\") +\n \"\\n\",\n true,\n );\n const env =\n [\n `DURAXIS_NAMESPACE=${options.namespace}`,\n ...(options.driver === \"disk\"\n ? [`DURAXIS_STORAGE_DIRECTORY=${options.storageDirectory}`]\n : []),\n ...(options.driver === \"s3\"\n ? [\n `DURAXIS_S3_BUCKET=${options.bucket}`,\n `DURAXIS_S3_PREFIX=${options.prefix}`,\n `AWS_REGION=${options.region ?? \"\"}`,\n ...(options.endpoint ? [`DURAXIS_S3_ENDPOINT=${options.endpoint}`] : []),\n ]\n : []),\n ...(options.cursorKeyEnv\n ? [\n `# Secret 32-byte key encoded as hex; provision securely, never commit it`,\n `${options.cursorKeyEnv}=`,\n ]\n : []),\n ]\n .join(\"\\n\")\n .replace(\n /DURAXIS_/g,\n name === \"default\" ? \"DURAXIS_\" : `DURAXIS_${name.toUpperCase().replace(/-/g, \"_\")}_`,\n ) + \"\\n\";\n const envPath = join(context.root, \".env.example\");\n const beforeEnv = (await exists(envPath)) ? await read.readFile(envPath, \"utf8\") : \"\";\n const declared = new Set(\n beforeEnv\n .split(/\\r?\\n/)\n .map((line) => /^\\s*(?:export\\s+)?([A-Z_][A-Z0-9_]*)\\s*=/.exec(line)?.[1])\n .filter(Boolean),\n );\n const additions = env\n .split(\"\\n\")\n .filter((line) => line && !line.startsWith(\"#\") && !declared.has(line.split(\"=\")[0]));\n if (additions.length)\n await addFile(\n plan,\n \".env.example\",\n beforeEnv +\n (beforeEnv && !beforeEnv.endsWith(\"\\n\") ? \"\\n\" : \"\") +\n additions.join(\"\\n\") +\n \"\\n\",\n true,\n );\n const scripts = stringMap(context.manifest.scripts);\n if (options.migrations && scripts[\"duraxis:status\"] === undefined)\n scripts[\"duraxis:status\"] = \"duraxis migrate:status\";\n if (\n options.language === \"typescript\" &&\n scripts.build === undefined &&\n !(await exists(join(context.root, \"tsconfig.json\")))\n )\n scripts.build = \"tsc -p tsconfig.json\";\n const manifest = {\n ...context.manifest,\n ...(!context.hasManifest\n ? {\n name:\n basename(context.root)\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\") || \"duraxis-application\",\n private: true,\n type: options.moduleFormat === \"esm\" ? \"module\" : \"commonjs\",\n engines: { node: \">=24.15.0\" },\n }\n : {}),\n scripts,\n ...(Object.keys(dependencies).length\n ? { dependencies: { ...context.dependencies, ...dependencies } }\n : {}),\n ...(Object.keys(devDependencies).length\n ? { devDependencies: { ...context.devDependencies, ...devDependencies } }\n : {}),\n };\n await addFile(\n plan,\n \"package.json\",\n JSON.stringify(manifest, null, 2) + \"\\n\",\n context.hasManifest,\n );\n if (options.driver === \"memory\")\n plan.warnings.push(\n \"Memory data and migration history are volatile and cannot persist across independent CLI processes.\",\n );\n if (options.driver === \"custom\")\n plan.warnings.push(\n \"Custom driver is trusted executable code; it must implement conditional operations and bounded reads. Initialization does not certify persistence correctness.\",\n );\n if (options.framework === \"nestjs\")\n plan.warnings.push(\n \"Duraxis registered directly in AppModule. Enable shutdown hooks in main for operating-system signal cleanup.\",\n );\n if (options.migrations)\n plan.warnings.push(\n \"Run migrations before application startup. Core-only configurations use manual migrations; automatic generation requires entities.\",\n );\n if (options.language === \"typescript\" && (await exists(join(context.root, \"tsconfig.json\"))))\n plan.warnings.push(\n \"Existing tsconfig preserved. Verify NodeNext, experimentalDecorators, emitDecoratorMetadata and useDefineForClassFields:false; see duraxis doctor.\",\n );\n return plan;\n}\n"],"mappings":";;;;;;;AAyCA,SAAgB,uBACd,MACA,OACA,WACA,YACM;CACN,IAAI,CAAC,MAAM,KAAK,KAAK,WAAW,KAAK,KAAK,GAAG,MAAM,IAAI,MAAM,2BAA2B;CACxF,MAAM,YAAY,QAAQ,MAAM,KAAK;CACrC,MAAM,SAAS,QAAQ,MAAM,SAAS;CACtC,MAAM,YAAY,QAAQ,MAAM,SAAS;CACzC,IACE,cAAc,QAAQ,IAAI,KAC1B,WAAW,aACX,OAAO,WAAW,YAAY,GAAG,KAChC,eAAe,cAAc,aAAa,UAAU,WAAW,YAAY,GAAG,IAE/E,MAAM,IAAI,MACR,0GACF;AACJ;AACA,SAAS,OACP,OACA,SACA,UACA,YAAY,OACT;CACH,IAAI,UAAU,KAAA,KAAc,aAAa,UAAU,QAAS,OAAO;CACnE,MAAM,WAAW,QAAQ,MAAM,MAAM,MAAM,KAAK;CAChD,IAAI,CAAC,UAAU,MAAM,IAAI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