@proseql/cli 0.2.4
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/LICENSE +21 -0
- package/README.md +333 -0
- package/dist/commands/collections.d.ts +53 -0
- package/dist/commands/collections.d.ts.map +1 -0
- package/dist/commands/collections.js +145 -0
- package/dist/commands/collections.js.map +1 -0
- package/dist/commands/convert.d.ts +72 -0
- package/dist/commands/convert.d.ts.map +1 -0
- package/dist/commands/convert.js +340 -0
- package/dist/commands/convert.js.map +1 -0
- package/dist/commands/create.d.ts +48 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +141 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/delete.d.ts +51 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +122 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/commands/describe.d.ts +74 -0
- package/dist/commands/describe.d.ts.map +1 -0
- package/dist/commands/describe.js +206 -0
- package/dist/commands/describe.js.map +1 -0
- package/dist/commands/init.d.ts +37 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +340 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/migrate.d.ts +65 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +483 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/query.d.ts +56 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +159 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/stats.d.ts +55 -0
- package/dist/commands/stats.d.ts.map +1 -0
- package/dist/commands/stats.js +188 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/commands/update.d.ts +50 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +121 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/config/discovery.d.ts +37 -0
- package/dist/config/discovery.d.ts.map +1 -0
- package/dist/config/discovery.js +171 -0
- package/dist/config/discovery.js.map +1 -0
- package/dist/config/loader.d.ts +49 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +195 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +66 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +621 -0
- package/dist/main.js.map +1 -0
- package/dist/output/csv.d.ts +14 -0
- package/dist/output/csv.d.ts.map +1 -0
- package/dist/output/csv.js +54 -0
- package/dist/output/csv.js.map +1 -0
- package/dist/output/formatter.d.ts +18 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +29 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/json.d.ts +13 -0
- package/dist/output/json.d.ts.map +1 -0
- package/dist/output/json.js +15 -0
- package/dist/output/json.js.map +1 -0
- package/dist/output/table.d.ts +18 -0
- package/dist/output/table.d.ts.map +1 -0
- package/dist/output/table.js +115 -0
- package/dist/output/table.js.map +1 -0
- package/dist/output/yaml.d.ts +13 -0
- package/dist/output/yaml.d.ts.map +1 -0
- package/dist/output/yaml.js +16 -0
- package/dist/output/yaml.js.map +1 -0
- package/dist/parsers/filter-parser.d.ts +65 -0
- package/dist/parsers/filter-parser.d.ts.map +1 -0
- package/dist/parsers/filter-parser.js +198 -0
- package/dist/parsers/filter-parser.js.map +1 -0
- package/dist/parsers/set-parser.d.ts +55 -0
- package/dist/parsers/set-parser.d.ts.map +1 -0
- package/dist/parsers/set-parser.js +198 -0
- package/dist/parsers/set-parser.js.map +1 -0
- package/dist/prompt.d.ts +58 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +121 -0
- package/dist/prompt.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - Init Command
|
|
3
|
+
*
|
|
4
|
+
* Scaffolds a new proseql project with config and data files.
|
|
5
|
+
* Checks for existing config and aborts with warning if found.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
// Config file names in priority order (same as discovery.ts)
|
|
10
|
+
const CONFIG_FILE_NAMES = [
|
|
11
|
+
"proseql.config.ts",
|
|
12
|
+
"proseql.config.js",
|
|
13
|
+
"proseql.config.json",
|
|
14
|
+
];
|
|
15
|
+
// Default config file name to create
|
|
16
|
+
const DEFAULT_CONFIG_FILE = "proseql.config.ts";
|
|
17
|
+
// Map format to file extension
|
|
18
|
+
const FORMAT_EXTENSIONS = {
|
|
19
|
+
json: "json",
|
|
20
|
+
yaml: "yaml",
|
|
21
|
+
toml: "toml",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Generate example note data for initial setup.
|
|
25
|
+
* Creates a realistic sample to help users understand the data structure.
|
|
26
|
+
*/
|
|
27
|
+
function generateExampleData() {
|
|
28
|
+
const now = new Date().toISOString();
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
id: "note_001",
|
|
32
|
+
title: "Welcome to ProseQL",
|
|
33
|
+
content: "This is your first note. ProseQL stores your data in plain text files that you can read, edit, and version control.",
|
|
34
|
+
createdAt: now,
|
|
35
|
+
updatedAt: now,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "note_002",
|
|
39
|
+
title: "Getting Started",
|
|
40
|
+
content: "Try running 'proseql query notes' to see your data, or 'proseql create notes --data '{...}'' to add new entries.",
|
|
41
|
+
createdAt: now,
|
|
42
|
+
updatedAt: now,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Serialize data to JSON format.
|
|
48
|
+
*/
|
|
49
|
+
function serializeJson(data) {
|
|
50
|
+
return JSON.stringify(data, null, 2);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serialize data to YAML format.
|
|
54
|
+
* Simple implementation without external dependencies for the CLI.
|
|
55
|
+
*/
|
|
56
|
+
function serializeYaml(data) {
|
|
57
|
+
const lines = [];
|
|
58
|
+
for (const item of data) {
|
|
59
|
+
lines.push("-");
|
|
60
|
+
for (const [key, value] of Object.entries(item)) {
|
|
61
|
+
const stringValue = typeof value === "string"
|
|
62
|
+
? `"${value.replace(/"/g, '\\"')}"`
|
|
63
|
+
: String(value);
|
|
64
|
+
lines.push(` ${key}: ${stringValue}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return `${lines.join("\n")}\n`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Serialize data to TOML format.
|
|
71
|
+
* TOML uses [[array]] syntax for arrays of tables.
|
|
72
|
+
*/
|
|
73
|
+
function serializeToml(data) {
|
|
74
|
+
const lines = [];
|
|
75
|
+
for (const item of data) {
|
|
76
|
+
lines.push("[[notes]]");
|
|
77
|
+
for (const [key, value] of Object.entries(item)) {
|
|
78
|
+
const stringValue = typeof value === "string"
|
|
79
|
+
? `"${value.replace(/"/g, '\\"')}"`
|
|
80
|
+
: String(value);
|
|
81
|
+
lines.push(`${key} = ${stringValue}`);
|
|
82
|
+
}
|
|
83
|
+
lines.push("");
|
|
84
|
+
}
|
|
85
|
+
return lines.join("\n");
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Serialize example data to the specified format.
|
|
89
|
+
*/
|
|
90
|
+
function serializeExampleData(data, format) {
|
|
91
|
+
switch (format) {
|
|
92
|
+
case "json":
|
|
93
|
+
return serializeJson(data);
|
|
94
|
+
case "yaml":
|
|
95
|
+
return serializeYaml(data);
|
|
96
|
+
case "toml":
|
|
97
|
+
return serializeToml(data);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate the content for proseql.config.ts with an example collection.
|
|
102
|
+
* The generated config includes a "notes" collection as a simple starting point.
|
|
103
|
+
*
|
|
104
|
+
* @param format - The data file format (json, yaml, toml)
|
|
105
|
+
*/
|
|
106
|
+
function generateConfigContent(format) {
|
|
107
|
+
const extension = format === "yaml" ? "yaml" : format === "toml" ? "toml" : "json";
|
|
108
|
+
return `import { Schema } from "effect"
|
|
109
|
+
import type { DatabaseConfig } from "@proseql/core"
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Example schema for a notes collection.
|
|
113
|
+
* Customize this schema to match your data structure.
|
|
114
|
+
*/
|
|
115
|
+
const NoteSchema = Schema.Struct({
|
|
116
|
+
id: Schema.String,
|
|
117
|
+
title: Schema.String,
|
|
118
|
+
content: Schema.String,
|
|
119
|
+
createdAt: Schema.String,
|
|
120
|
+
updatedAt: Schema.String,
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* ProseQL database configuration.
|
|
125
|
+
* Add your collections here. Each collection needs:
|
|
126
|
+
* - schema: An Effect Schema for validation
|
|
127
|
+
* - file: Path to the data file (optional for in-memory only)
|
|
128
|
+
* - relationships: Related collections (empty object if none)
|
|
129
|
+
*/
|
|
130
|
+
const config = {
|
|
131
|
+
notes: {
|
|
132
|
+
schema: NoteSchema,
|
|
133
|
+
file: "./data/notes.${extension}",
|
|
134
|
+
relationships: {},
|
|
135
|
+
},
|
|
136
|
+
} as const satisfies DatabaseConfig
|
|
137
|
+
|
|
138
|
+
export default config
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if a config file already exists in the current directory.
|
|
143
|
+
* Returns the name of the found config file, or null if none found.
|
|
144
|
+
*/
|
|
145
|
+
function findExistingConfig(cwd) {
|
|
146
|
+
for (const configName of CONFIG_FILE_NAMES) {
|
|
147
|
+
const configPath = path.join(cwd, configName);
|
|
148
|
+
if (fs.existsSync(configPath)) {
|
|
149
|
+
return configName;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check if the current directory is inside a git repository.
|
|
156
|
+
* Returns true if a .git directory exists.
|
|
157
|
+
*/
|
|
158
|
+
function isGitRepository(cwd) {
|
|
159
|
+
const gitPath = path.join(cwd, ".git");
|
|
160
|
+
return fs.existsSync(gitPath);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check if a pattern is already in .gitignore.
|
|
164
|
+
* Handles various formats: exact match, with leading slash, with trailing slash.
|
|
165
|
+
*/
|
|
166
|
+
function isPatternInGitignore(gitignoreContent, pattern) {
|
|
167
|
+
const lines = gitignoreContent.split("\n").map((line) => line.trim());
|
|
168
|
+
const normalizedPattern = pattern.replace(/^\//, "").replace(/\/$/, "");
|
|
169
|
+
for (const line of lines) {
|
|
170
|
+
// Skip comments and empty lines
|
|
171
|
+
if (line.startsWith("#") || line === "") {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const normalizedLine = line.replace(/^\//, "").replace(/\/$/, "");
|
|
175
|
+
if (normalizedLine === normalizedPattern) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Update .gitignore to include the data directory.
|
|
183
|
+
* Creates .gitignore if it doesn't exist.
|
|
184
|
+
* Returns true if the file was modified, false if pattern was already present.
|
|
185
|
+
*/
|
|
186
|
+
function updateGitignore(cwd, dataDir) {
|
|
187
|
+
const gitignorePath = path.join(cwd, ".gitignore");
|
|
188
|
+
const pattern = `${dataDir}/`;
|
|
189
|
+
let gitignoreContent = "";
|
|
190
|
+
let fileExists = false;
|
|
191
|
+
if (fs.existsSync(gitignorePath)) {
|
|
192
|
+
fileExists = true;
|
|
193
|
+
gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
194
|
+
// Check if pattern is already present
|
|
195
|
+
if (isPatternInGitignore(gitignoreContent, dataDir)) {
|
|
196
|
+
return { updated: false, created: false };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Append the pattern to .gitignore
|
|
200
|
+
const newContent = fileExists
|
|
201
|
+
? gitignoreContent.endsWith("\n")
|
|
202
|
+
? `${gitignoreContent}# ProseQL data directory\n${pattern}\n`
|
|
203
|
+
: `${gitignoreContent}\n\n# ProseQL data directory\n${pattern}\n`
|
|
204
|
+
: `# ProseQL data directory\n${pattern}\n`;
|
|
205
|
+
fs.writeFileSync(gitignorePath, newContent, "utf-8");
|
|
206
|
+
return { updated: true, created: !fileExists };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Execute the init command.
|
|
210
|
+
*
|
|
211
|
+
* Checks for existing config files and aborts if found.
|
|
212
|
+
* Creates proseql.config.ts with an example collection definition.
|
|
213
|
+
*
|
|
214
|
+
* @param options - Init command options
|
|
215
|
+
* @returns Result indicating success or failure
|
|
216
|
+
*/
|
|
217
|
+
export function runInit(options = {}) {
|
|
218
|
+
const cwd = options.cwd ?? process.cwd();
|
|
219
|
+
const format = options.format ?? "json";
|
|
220
|
+
// Validate format
|
|
221
|
+
const validFormats = ["json", "yaml", "toml"];
|
|
222
|
+
if (!validFormats.includes(format)) {
|
|
223
|
+
return {
|
|
224
|
+
success: false,
|
|
225
|
+
message: `Invalid format: ${format}. Valid formats are: ${validFormats.join(", ")}`,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
// Check for existing config file
|
|
229
|
+
const existingConfig = findExistingConfig(cwd);
|
|
230
|
+
if (existingConfig !== null) {
|
|
231
|
+
return {
|
|
232
|
+
success: false,
|
|
233
|
+
message: `A proseql config file already exists: ${existingConfig}\nTo reinitialize, remove the existing config first.`,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const createdFiles = [];
|
|
237
|
+
// Task 3.2: Scaffold proseql.config.ts with example collection
|
|
238
|
+
const configPath = path.join(cwd, DEFAULT_CONFIG_FILE);
|
|
239
|
+
const configContent = generateConfigContent(format);
|
|
240
|
+
try {
|
|
241
|
+
fs.writeFileSync(configPath, configContent, "utf-8");
|
|
242
|
+
createdFiles.push(DEFAULT_CONFIG_FILE);
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
246
|
+
return {
|
|
247
|
+
success: false,
|
|
248
|
+
message: `Failed to create config file: ${message}`,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// Task 3.3: Create data/ directory with example data file
|
|
252
|
+
const dataDir = path.join(cwd, "data");
|
|
253
|
+
const extension = FORMAT_EXTENSIONS[format];
|
|
254
|
+
const dataFilePath = path.join(dataDir, `notes.${extension}`);
|
|
255
|
+
try {
|
|
256
|
+
// Create data directory if it doesn't exist
|
|
257
|
+
if (!fs.existsSync(dataDir)) {
|
|
258
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
259
|
+
}
|
|
260
|
+
createdFiles.push("data/");
|
|
261
|
+
// Generate and write example data file
|
|
262
|
+
const exampleData = generateExampleData();
|
|
263
|
+
const dataContent = serializeExampleData(exampleData, format);
|
|
264
|
+
fs.writeFileSync(dataFilePath, dataContent, "utf-8");
|
|
265
|
+
createdFiles.push(`data/notes.${extension}`);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
message: `Failed to create data directory or file: ${message}`,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// Task 3.4: Detect .git directory and update .gitignore
|
|
275
|
+
if (isGitRepository(cwd)) {
|
|
276
|
+
try {
|
|
277
|
+
const gitignoreResult = updateGitignore(cwd, "data");
|
|
278
|
+
if (gitignoreResult.created) {
|
|
279
|
+
createdFiles.push(".gitignore");
|
|
280
|
+
}
|
|
281
|
+
else if (gitignoreResult.updated) {
|
|
282
|
+
createdFiles.push(".gitignore (updated)");
|
|
283
|
+
}
|
|
284
|
+
// If neither created nor updated, the pattern was already present - nothing to report
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
// Non-fatal: warn but don't fail the init
|
|
288
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
289
|
+
console.warn(`Warning: Could not update .gitignore: ${message}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
success: true,
|
|
294
|
+
message: "ProseQL project initialized successfully!",
|
|
295
|
+
createdFiles,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Print a formatted summary of the init operation to stdout.
|
|
300
|
+
* Displays the created files in a clear, user-friendly format.
|
|
301
|
+
*/
|
|
302
|
+
function printInitSummary(result) {
|
|
303
|
+
console.log("");
|
|
304
|
+
console.log(result.message);
|
|
305
|
+
console.log("");
|
|
306
|
+
if (result.createdFiles && result.createdFiles.length > 0) {
|
|
307
|
+
console.log("Created files:");
|
|
308
|
+
for (const file of result.createdFiles) {
|
|
309
|
+
// Use different indicators for different file types
|
|
310
|
+
if (file.endsWith("/")) {
|
|
311
|
+
console.log(` + ${file.slice(0, -1)}/ (directory)`);
|
|
312
|
+
}
|
|
313
|
+
else if (file.includes("(updated)")) {
|
|
314
|
+
console.log(` ~ ${file.replace(" (updated)", "")} (updated)`);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
console.log(` + ${file}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
console.log("");
|
|
321
|
+
}
|
|
322
|
+
console.log("Next steps:");
|
|
323
|
+
console.log(" 1. Edit proseql.config.ts to define your collections");
|
|
324
|
+
console.log(" 2. Run 'proseql query notes' to see example data");
|
|
325
|
+
console.log(" 3. Run 'proseql --help' for available commands");
|
|
326
|
+
console.log("");
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Handle the init command from CLI main.ts
|
|
330
|
+
* This is the entry point called by the command dispatcher.
|
|
331
|
+
*/
|
|
332
|
+
export async function handleInit(options = {}) {
|
|
333
|
+
const result = runInit(options);
|
|
334
|
+
if (!result.success) {
|
|
335
|
+
console.error(`Error: ${result.message}`);
|
|
336
|
+
process.exit(1);
|
|
337
|
+
}
|
|
338
|
+
printInitSummary(result);
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,6DAA6D;AAC7D,MAAM,iBAAiB,GAAG;IACzB,mBAAmB;IACnB,mBAAmB;IACnB,qBAAqB;CACZ,CAAC;AAEX,qCAAqC;AACrC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAKhD,+BAA+B;AAC/B,MAAM,iBAAiB,GAA+B;IACrD,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;CACZ,CAAC;AAEF;;;GAGG;AACH,SAAS,mBAAmB;IAC3B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO;QACN;YACC,EAAE,EAAE,UAAU;YACd,KAAK,EAAE,oBAAoB;YAC3B,OAAO,EACN,qHAAqH;YACtH,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACd;QACD;YACC,EAAE,EAAE,UAAU;YACd,KAAK,EAAE,iBAAiB;YACxB,OAAO,EACN,kHAAkH;YACnH,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACd;KACQ,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,IAAwC;IAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,IAAwC;IAC9D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,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CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - Migrate Command
|
|
3
|
+
*
|
|
4
|
+
* Manages schema migrations: shows status, performs dry runs, and executes migrations.
|
|
5
|
+
* Supports subcommands: `migrate status`, `migrate --dry-run`, `migrate` (run).
|
|
6
|
+
*/
|
|
7
|
+
import { type DatabaseConfig, type DryRunResult } from "@proseql/node";
|
|
8
|
+
import { Effect } from "effect";
|
|
9
|
+
/**
|
|
10
|
+
* Subcommand for the migrate command.
|
|
11
|
+
* - "status": Display migration status for all collections
|
|
12
|
+
* - "dry-run": Show what migrations would run without executing
|
|
13
|
+
* - "run": Execute pending migrations
|
|
14
|
+
*/
|
|
15
|
+
export type MigrateSubcommand = "status" | "dry-run" | "run";
|
|
16
|
+
/**
|
|
17
|
+
* Options for the migrate command.
|
|
18
|
+
*/
|
|
19
|
+
export interface MigrateOptions {
|
|
20
|
+
/** The database configuration */
|
|
21
|
+
readonly config: DatabaseConfig;
|
|
22
|
+
/** The path to the config file (used for resolving relative file paths) */
|
|
23
|
+
readonly configPath: string;
|
|
24
|
+
/** Subcommand to execute */
|
|
25
|
+
readonly subcommand: MigrateSubcommand;
|
|
26
|
+
/** Skip confirmation prompt if true (for run subcommand) */
|
|
27
|
+
readonly force?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Result of the migrate command.
|
|
31
|
+
*/
|
|
32
|
+
export interface MigrateResult {
|
|
33
|
+
readonly success: boolean;
|
|
34
|
+
readonly message?: string;
|
|
35
|
+
/** Whether the operation was aborted by the user */
|
|
36
|
+
readonly aborted?: boolean;
|
|
37
|
+
/** Dry-run or status result data */
|
|
38
|
+
readonly data?: DryRunResult;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Detect which subcommand is being requested based on positional args and flags.
|
|
42
|
+
*
|
|
43
|
+
* @param positionalArgs - Positional arguments after "migrate"
|
|
44
|
+
* @param dryRun - Whether --dry-run flag was passed
|
|
45
|
+
* @returns The detected subcommand
|
|
46
|
+
*/
|
|
47
|
+
export declare function detectSubcommand(positionalArgs: readonly string[], dryRun: boolean): MigrateSubcommand;
|
|
48
|
+
/**
|
|
49
|
+
* Execute the migrate command.
|
|
50
|
+
*
|
|
51
|
+
* Routes to the appropriate subcommand handler based on options.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Migrate command options
|
|
54
|
+
* @returns Effect that resolves to the migrate result
|
|
55
|
+
*/
|
|
56
|
+
export declare function runMigrateCommand(options: MigrateOptions): Effect.Effect<MigrateResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Handle the migrate command from CLI main.ts.
|
|
59
|
+
* This is the entry point called by the command dispatcher.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Migrate command options
|
|
62
|
+
* @returns Promise that resolves to the migrate result
|
|
63
|
+
*/
|
|
64
|
+
export declare function handleMigrate(options: MigrateOptions): Promise<MigrateResult>;
|
|
65
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACN,KAAK,cAAc,EAGnB,KAAK,YAAY,EAUjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAS,MAAM,QAAQ,CAAC;AAGvC;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4BAA4B;IAC5B,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAC;IACvC,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,CAAC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