@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,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - CSV Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as CSV with proper quoting and comma escaping.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Escape a value for CSV output.
|
|
8
|
+
* Values containing commas, quotes, or newlines are wrapped in quotes.
|
|
9
|
+
* Quotes within values are doubled.
|
|
10
|
+
*
|
|
11
|
+
* @param value - Value to escape
|
|
12
|
+
* @returns Escaped CSV value
|
|
13
|
+
*/
|
|
14
|
+
function escapeValue(value) {
|
|
15
|
+
if (value === null || value === undefined) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
const str = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
19
|
+
// Check if the value needs quoting
|
|
20
|
+
if (str.includes(",") ||
|
|
21
|
+
str.includes('"') ||
|
|
22
|
+
str.includes("\n") ||
|
|
23
|
+
str.includes("\r")) {
|
|
24
|
+
// Double any existing quotes and wrap in quotes
|
|
25
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
26
|
+
}
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format records as CSV.
|
|
31
|
+
* Writes header row with all unique field names, then data rows.
|
|
32
|
+
*
|
|
33
|
+
* @param records - Array of records to format
|
|
34
|
+
* @returns CSV string with header and data rows
|
|
35
|
+
*/
|
|
36
|
+
export function formatAsCsv(records) {
|
|
37
|
+
if (records.length === 0) {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
// Collect all unique field names across all records
|
|
41
|
+
const fieldSet = new Set();
|
|
42
|
+
for (const record of records) {
|
|
43
|
+
for (const key of Object.keys(record)) {
|
|
44
|
+
fieldSet.add(key);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const fields = Array.from(fieldSet);
|
|
48
|
+
// Build header row
|
|
49
|
+
const headerRow = fields.map(escapeValue).join(",");
|
|
50
|
+
// Build data rows
|
|
51
|
+
const dataRows = records.map((record) => fields.map((field) => escapeValue(record[field])).join(","));
|
|
52
|
+
return [headerRow, ...dataRows].join("\n");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,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEpC,mBAAmB;IACnB,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEpD,kBAAkB;IAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACvC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAC;IAEF,OAAO,CAAC,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - Output Formatter Dispatcher
|
|
3
|
+
*
|
|
4
|
+
* Accepts a format flag and record array, delegates to the appropriate formatter.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Supported output formats.
|
|
8
|
+
*/
|
|
9
|
+
export type OutputFormat = "table" | "json" | "yaml" | "csv";
|
|
10
|
+
/**
|
|
11
|
+
* Format the given records based on the specified format.
|
|
12
|
+
*
|
|
13
|
+
* @param format - The output format to use
|
|
14
|
+
* @param records - Array of records to format
|
|
15
|
+
* @returns Formatted string output
|
|
16
|
+
*/
|
|
17
|
+
export declare function format(format: OutputFormat, records: ReadonlyArray<Record<string, unknown>>): string;
|
|
18
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/output/formatter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAE7D;;;;;;GAMG;AACH,wBAAgB,MAAM,CACrB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC7C,MAAM,CAWR"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - Output Formatter Dispatcher
|
|
3
|
+
*
|
|
4
|
+
* Accepts a format flag and record array, delegates to the appropriate formatter.
|
|
5
|
+
*/
|
|
6
|
+
import { formatAsCsv } from "./csv.js";
|
|
7
|
+
import { formatAsJson } from "./json.js";
|
|
8
|
+
import { formatAsTable } from "./table.js";
|
|
9
|
+
import { formatAsYaml } from "./yaml.js";
|
|
10
|
+
/**
|
|
11
|
+
* Format the given records based on the specified format.
|
|
12
|
+
*
|
|
13
|
+
* @param format - The output format to use
|
|
14
|
+
* @param records - Array of records to format
|
|
15
|
+
* @returns Formatted string output
|
|
16
|
+
*/
|
|
17
|
+
export function format(format, records) {
|
|
18
|
+
switch (format) {
|
|
19
|
+
case "json":
|
|
20
|
+
return formatAsJson(records);
|
|
21
|
+
case "yaml":
|
|
22
|
+
return formatAsYaml(records);
|
|
23
|
+
case "csv":
|
|
24
|
+
return formatAsCsv(records);
|
|
25
|
+
case "table":
|
|
26
|
+
return formatAsTable(records);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/output/formatter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAOzC;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACrB,MAAoB,EACpB,OAA+C;IAE/C,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,MAAM;YACV,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;QAC9B,KAAK,MAAM;YACV,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;QAC9B,KAAK,KAAK;YACT,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;QAC7B,KAAK,OAAO;YACX,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - JSON Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as JSON with 2-space indentation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Format records as pretty-printed JSON.
|
|
8
|
+
*
|
|
9
|
+
* @param records - Array of records to format
|
|
10
|
+
* @returns JSON string with 2-space indentation
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatAsJson(records: ReadonlyArray<Record<string, unknown>>): string;
|
|
13
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/output/json.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC7C,MAAM,CAER"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - JSON Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as JSON with 2-space indentation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Format records as pretty-printed JSON.
|
|
8
|
+
*
|
|
9
|
+
* @param records - Array of records to format
|
|
10
|
+
* @returns JSON string with 2-space indentation
|
|
11
|
+
*/
|
|
12
|
+
export function formatAsJson(records) {
|
|
13
|
+
return JSON.stringify(records, null, 2);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/output/json.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC3B,OAA+C;IAE/C,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - Table Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as an aligned ASCII table.
|
|
5
|
+
* Calculates column widths from headers and data, truncates values exceeding terminal width.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Format records as an aligned ASCII table.
|
|
9
|
+
*
|
|
10
|
+
* @param records - Array of records to format
|
|
11
|
+
* @param options - Optional configuration
|
|
12
|
+
* @param options.maxColumnWidth - Maximum width for any column (default: 40)
|
|
13
|
+
* @returns Formatted table string
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatAsTable(records: ReadonlyArray<Record<string, unknown>>, options?: {
|
|
16
|
+
readonly maxColumnWidth?: number;
|
|
17
|
+
}): string;
|
|
18
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/output/table.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyDH;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC/C,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,MAAM,CA4DR"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - Table Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as an aligned ASCII table.
|
|
5
|
+
* Calculates column widths from headers and data, truncates values exceeding terminal width.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Default maximum width for a single column before truncation.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_MAX_COLUMN_WIDTH = 40;
|
|
11
|
+
/**
|
|
12
|
+
* Get the display width of a value (handling null, undefined, objects).
|
|
13
|
+
*
|
|
14
|
+
* @param value - Value to measure
|
|
15
|
+
* @returns String representation of the value
|
|
16
|
+
*/
|
|
17
|
+
function stringify(value) {
|
|
18
|
+
if (value === null) {
|
|
19
|
+
return "null";
|
|
20
|
+
}
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "object") {
|
|
25
|
+
return JSON.stringify(value);
|
|
26
|
+
}
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Truncate a string to a maximum length, adding ellipsis if needed.
|
|
31
|
+
*
|
|
32
|
+
* @param str - String to truncate
|
|
33
|
+
* @param maxLen - Maximum length
|
|
34
|
+
* @returns Truncated string with ellipsis if truncated
|
|
35
|
+
*/
|
|
36
|
+
function truncate(str, maxLen) {
|
|
37
|
+
if (str.length <= maxLen) {
|
|
38
|
+
return str;
|
|
39
|
+
}
|
|
40
|
+
if (maxLen <= 3) {
|
|
41
|
+
return str.slice(0, maxLen);
|
|
42
|
+
}
|
|
43
|
+
return `${str.slice(0, maxLen - 3)}...`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Pad a string to a given length with spaces (left-align).
|
|
47
|
+
*
|
|
48
|
+
* @param str - String to pad
|
|
49
|
+
* @param len - Target length
|
|
50
|
+
* @returns Padded string
|
|
51
|
+
*/
|
|
52
|
+
function padRight(str, len) {
|
|
53
|
+
if (str.length >= len) {
|
|
54
|
+
return str;
|
|
55
|
+
}
|
|
56
|
+
return str + " ".repeat(len - str.length);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Format records as an aligned ASCII table.
|
|
60
|
+
*
|
|
61
|
+
* @param records - Array of records to format
|
|
62
|
+
* @param options - Optional configuration
|
|
63
|
+
* @param options.maxColumnWidth - Maximum width for any column (default: 40)
|
|
64
|
+
* @returns Formatted table string
|
|
65
|
+
*/
|
|
66
|
+
export function formatAsTable(records, options) {
|
|
67
|
+
if (records.length === 0) {
|
|
68
|
+
return "(no results)";
|
|
69
|
+
}
|
|
70
|
+
const maxColumnWidth = options?.maxColumnWidth ?? DEFAULT_MAX_COLUMN_WIDTH;
|
|
71
|
+
// Collect all unique field names across all records
|
|
72
|
+
const fieldSet = new Set();
|
|
73
|
+
for (const record of records) {
|
|
74
|
+
for (const key of Object.keys(record)) {
|
|
75
|
+
fieldSet.add(key);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const fields = Array.from(fieldSet);
|
|
79
|
+
// Calculate column widths (min of actual content width and max column width)
|
|
80
|
+
const columnWidths = new Map();
|
|
81
|
+
for (const field of fields) {
|
|
82
|
+
// Start with header width
|
|
83
|
+
let maxWidth = field.length;
|
|
84
|
+
// Check all data values
|
|
85
|
+
for (const record of records) {
|
|
86
|
+
const value = stringify(record[field]);
|
|
87
|
+
maxWidth = Math.max(maxWidth, value.length);
|
|
88
|
+
}
|
|
89
|
+
// Clamp to max column width
|
|
90
|
+
columnWidths.set(field, Math.min(maxWidth, maxColumnWidth));
|
|
91
|
+
}
|
|
92
|
+
// Helper to get column width with fallback (width is always set for fields in the loop above)
|
|
93
|
+
const getWidth = (field) => columnWidths.get(field) ?? 0;
|
|
94
|
+
// Build header row
|
|
95
|
+
const headerRow = fields
|
|
96
|
+
.map((field) => {
|
|
97
|
+
const width = getWidth(field);
|
|
98
|
+
return padRight(truncate(field, width), width);
|
|
99
|
+
})
|
|
100
|
+
.join(" ");
|
|
101
|
+
// Build separator row
|
|
102
|
+
const separatorRow = fields
|
|
103
|
+
.map((field) => "-".repeat(getWidth(field)))
|
|
104
|
+
.join(" ");
|
|
105
|
+
// Build data rows
|
|
106
|
+
const dataRows = records.map((record) => fields
|
|
107
|
+
.map((field) => {
|
|
108
|
+
const value = stringify(record[field]);
|
|
109
|
+
const width = getWidth(field);
|
|
110
|
+
return padRight(truncate(value, width), width);
|
|
111
|
+
})
|
|
112
|
+
.join(" "));
|
|
113
|
+
return [headerRow, separatorRow, ...dataRows].join("\n");
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/output/table.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAc;IAChC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IACf,CAAC;IACD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACX,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,QAAQ,CAAC,GAAW,EAAE,MAAc;IAC5C,IAAI,GAAG,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,GAAG,GAAG,CAAC,KAAK,CA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AAY,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - YAML Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as YAML using the same YAML library as @proseql/core.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Format records as YAML.
|
|
8
|
+
*
|
|
9
|
+
* @param records - Array of records to format
|
|
10
|
+
* @returns YAML string with 2-space indentation
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatAsYaml(records: ReadonlyArray<Record<string, unknown>>): string;
|
|
13
|
+
//# sourceMappingURL=yaml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../src/output/yaml.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;GAKG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC7C,MAAM,CAER"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseQL CLI - YAML Output Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats records as YAML using the same YAML library as @proseql/core.
|
|
5
|
+
*/
|
|
6
|
+
import YAML from "yaml";
|
|
7
|
+
/**
|
|
8
|
+
* Format records as YAML.
|
|
9
|
+
*
|
|
10
|
+
* @param records - Array of records to format
|
|
11
|
+
* @returns YAML string with 2-space indentation
|
|
12
|
+
*/
|
|
13
|
+
export function formatAsYaml(records) {
|
|
14
|
+
return YAML.stringify(records, { indent: 2 });
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=yaml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.js","sourceRoot":"","sources":["../../src/output/yaml.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC3B,OAA+C;IAE/C,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter Parser - Parses CLI --where expressions into proseql where clause objects
|
|
3
|
+
*
|
|
4
|
+
* Supports operators: =, !=, >, <, >=, <=, contains, startsWith, endsWith
|
|
5
|
+
* Auto-detects value types: numbers, booleans, strings
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* "year > 1970" -> { year: { $gt: 1970 } }
|
|
9
|
+
* "status = active" -> { status: { $eq: "active" } }
|
|
10
|
+
* "active = true" -> { active: { $eq: true } }
|
|
11
|
+
* "title contains War" -> { title: { $contains: "War" } }
|
|
12
|
+
*/
|
|
13
|
+
import { Effect } from "effect";
|
|
14
|
+
declare const FilterParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
15
|
+
readonly _tag: "FilterParseError";
|
|
16
|
+
} & Readonly<A>;
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when a filter expression cannot be parsed
|
|
19
|
+
*/
|
|
20
|
+
export declare class FilterParseError extends FilterParseError_base<{
|
|
21
|
+
readonly expression: string;
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
}> {
|
|
24
|
+
get message(): string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Where clause type - record of field to filter operators
|
|
28
|
+
*/
|
|
29
|
+
export type WhereClause = Record<string, {
|
|
30
|
+
$eq?: string | number | boolean;
|
|
31
|
+
} | {
|
|
32
|
+
$ne?: string | number | boolean;
|
|
33
|
+
} | {
|
|
34
|
+
$gt?: string | number;
|
|
35
|
+
} | {
|
|
36
|
+
$lt?: string | number;
|
|
37
|
+
} | {
|
|
38
|
+
$gte?: string | number;
|
|
39
|
+
} | {
|
|
40
|
+
$lte?: string | number;
|
|
41
|
+
} | {
|
|
42
|
+
$contains?: string;
|
|
43
|
+
} | {
|
|
44
|
+
$startsWith?: string;
|
|
45
|
+
} | {
|
|
46
|
+
$endsWith?: string;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Parse a single filter expression into a where clause object
|
|
50
|
+
*
|
|
51
|
+
* @param expression - Filter expression string (e.g., "year > 1970")
|
|
52
|
+
* @returns Effect containing the where clause or a FilterParseError
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseFilter(expression: string): Effect.Effect<WhereClause, FilterParseError>;
|
|
55
|
+
/**
|
|
56
|
+
* Parse multiple filter expressions and combine them into a single where clause
|
|
57
|
+
* Multiple filters on different fields are combined with AND logic
|
|
58
|
+
* Multiple filters on the same field are merged
|
|
59
|
+
*
|
|
60
|
+
* @param expressions - Array of filter expression strings
|
|
61
|
+
* @returns Effect containing the combined where clause or a FilterParseError
|
|
62
|
+
*/
|
|
63
|
+
export declare function parseFilters(expressions: readonly string[]): Effect.Effect<WhereClause, FilterParseError>;
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=filter-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-parser.d.ts","sourceRoot":"","sources":["../../src/parsers/filter-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAEtC;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,sBAAqC;IAC1E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB,CAAC;IACD,IAAI,OAAO,IAAI,MAAM,CAEpB;CACD;AAyLD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAC/B,MAAM,EACJ;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,GACnC;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,GACnC;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GACzB;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GACzB;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAC1B;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAC1B;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACtB;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACxB;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CACxB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAC1B,UAAU,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAW9C;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC3B,WAAW,EAAE,SAAS,MAAM,EAAE,GAC5B,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAuB9C"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter Parser - Parses CLI --where expressions into proseql where clause objects
|
|
3
|
+
*
|
|
4
|
+
* Supports operators: =, !=, >, <, >=, <=, contains, startsWith, endsWith
|
|
5
|
+
* Auto-detects value types: numbers, booleans, strings
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* "year > 1970" -> { year: { $gt: 1970 } }
|
|
9
|
+
* "status = active" -> { status: { $eq: "active" } }
|
|
10
|
+
* "active = true" -> { active: { $eq: true } }
|
|
11
|
+
* "title contains War" -> { title: { $contains: "War" } }
|
|
12
|
+
*/
|
|
13
|
+
import { Data, Effect } from "effect";
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when a filter expression cannot be parsed
|
|
16
|
+
*/
|
|
17
|
+
export class FilterParseError extends Data.TaggedError("FilterParseError") {
|
|
18
|
+
get message() {
|
|
19
|
+
return `Failed to parse filter "${this.expression}": ${this.reason}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Supported comparison operators
|
|
24
|
+
*/
|
|
25
|
+
const COMPARISON_OPERATORS = [">=", "<=", "!=", ">", "<", "="];
|
|
26
|
+
/**
|
|
27
|
+
* Supported word operators (case-insensitive)
|
|
28
|
+
*/
|
|
29
|
+
const WORD_OPERATORS = ["contains", "startswith", "endswith"];
|
|
30
|
+
/**
|
|
31
|
+
* Map CLI operators to proseql filter operators
|
|
32
|
+
*/
|
|
33
|
+
function mapOperator(op) {
|
|
34
|
+
switch (op) {
|
|
35
|
+
case "=":
|
|
36
|
+
return "$eq";
|
|
37
|
+
case "!=":
|
|
38
|
+
return "$ne";
|
|
39
|
+
case ">":
|
|
40
|
+
return "$gt";
|
|
41
|
+
case "<":
|
|
42
|
+
return "$lt";
|
|
43
|
+
case ">=":
|
|
44
|
+
return "$gte";
|
|
45
|
+
case "<=":
|
|
46
|
+
return "$lte";
|
|
47
|
+
case "contains":
|
|
48
|
+
return "$contains";
|
|
49
|
+
case "startswith":
|
|
50
|
+
return "$startsWith";
|
|
51
|
+
case "endswith":
|
|
52
|
+
return "$endsWith";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parse a string value into the appropriate type (number, boolean, or string)
|
|
57
|
+
*/
|
|
58
|
+
function parseValue(value) {
|
|
59
|
+
const trimmed = value.trim();
|
|
60
|
+
// Check for boolean
|
|
61
|
+
if (trimmed.toLowerCase() === "true") {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (trimmed.toLowerCase() === "false") {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// Check for number
|
|
68
|
+
const num = Number(trimmed);
|
|
69
|
+
if (!Number.isNaN(num) && trimmed !== "") {
|
|
70
|
+
return num;
|
|
71
|
+
}
|
|
72
|
+
// Default to string - strip quotes if present
|
|
73
|
+
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
74
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
|
75
|
+
return trimmed.slice(1, -1);
|
|
76
|
+
}
|
|
77
|
+
return trimmed;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Try to parse a filter expression with comparison operators (=, !=, >, <, >=, <=)
|
|
81
|
+
*/
|
|
82
|
+
function tryParseComparisonOperator(expression) {
|
|
83
|
+
// Try each operator in order (longest first to avoid partial matches)
|
|
84
|
+
for (const op of COMPARISON_OPERATORS) {
|
|
85
|
+
const index = expression.indexOf(op);
|
|
86
|
+
if (index > 0) {
|
|
87
|
+
const field = expression.slice(0, index).trim();
|
|
88
|
+
const valueStr = expression.slice(index + op.length).trim();
|
|
89
|
+
if (field && valueStr) {
|
|
90
|
+
return {
|
|
91
|
+
field,
|
|
92
|
+
operator: op,
|
|
93
|
+
value: parseValue(valueStr),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Try to parse a filter expression with word operators (contains, startsWith, endsWith)
|
|
102
|
+
*/
|
|
103
|
+
function tryParseWordOperator(expression) {
|
|
104
|
+
const _lowerExpr = expression.toLowerCase();
|
|
105
|
+
for (const op of WORD_OPERATORS) {
|
|
106
|
+
// Look for the operator as a word boundary (space before and after)
|
|
107
|
+
const pattern = new RegExp(`\\s+${op}\\s+`, "i");
|
|
108
|
+
const match = expression.match(pattern);
|
|
109
|
+
if (match && match.index !== undefined) {
|
|
110
|
+
const field = expression.slice(0, match.index).trim();
|
|
111
|
+
const valueStr = expression.slice(match.index + match[0].length).trim();
|
|
112
|
+
if (field && valueStr) {
|
|
113
|
+
return {
|
|
114
|
+
field,
|
|
115
|
+
operator: op,
|
|
116
|
+
value: parseValue(valueStr),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Parse a single filter expression into a parsed filter object
|
|
125
|
+
*/
|
|
126
|
+
function parseExpression(expression) {
|
|
127
|
+
return Effect.gen(function* () {
|
|
128
|
+
const trimmed = expression.trim();
|
|
129
|
+
if (!trimmed) {
|
|
130
|
+
return yield* Effect.fail(new FilterParseError({
|
|
131
|
+
expression,
|
|
132
|
+
reason: "Empty expression",
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
// Try comparison operators first
|
|
136
|
+
const comparisonResult = tryParseComparisonOperator(trimmed);
|
|
137
|
+
if (comparisonResult) {
|
|
138
|
+
return comparisonResult;
|
|
139
|
+
}
|
|
140
|
+
// Try word operators
|
|
141
|
+
const wordResult = tryParseWordOperator(trimmed);
|
|
142
|
+
if (wordResult) {
|
|
143
|
+
return wordResult;
|
|
144
|
+
}
|
|
145
|
+
return yield* Effect.fail(new FilterParseError({
|
|
146
|
+
expression,
|
|
147
|
+
reason: "No valid operator found. Supported operators: =, !=, >, <, >=, <=, contains, startsWith, endsWith",
|
|
148
|
+
}));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Parse a single filter expression into a where clause object
|
|
153
|
+
*
|
|
154
|
+
* @param expression - Filter expression string (e.g., "year > 1970")
|
|
155
|
+
* @returns Effect containing the where clause or a FilterParseError
|
|
156
|
+
*/
|
|
157
|
+
export function parseFilter(expression) {
|
|
158
|
+
return Effect.gen(function* () {
|
|
159
|
+
const parsed = yield* parseExpression(expression);
|
|
160
|
+
const operator = mapOperator(parsed.operator);
|
|
161
|
+
return {
|
|
162
|
+
[parsed.field]: {
|
|
163
|
+
[operator]: parsed.value,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Parse multiple filter expressions and combine them into a single where clause
|
|
170
|
+
* Multiple filters on different fields are combined with AND logic
|
|
171
|
+
* Multiple filters on the same field are merged
|
|
172
|
+
*
|
|
173
|
+
* @param expressions - Array of filter expression strings
|
|
174
|
+
* @returns Effect containing the combined where clause or a FilterParseError
|
|
175
|
+
*/
|
|
176
|
+
export function parseFilters(expressions) {
|
|
177
|
+
return Effect.gen(function* () {
|
|
178
|
+
if (expressions.length === 0) {
|
|
179
|
+
return {};
|
|
180
|
+
}
|
|
181
|
+
const parsedFilters = yield* Effect.all(expressions.map(parseFilter));
|
|
182
|
+
// Merge all filters into a single where clause
|
|
183
|
+
const combined = {};
|
|
184
|
+
for (const filter of parsedFilters) {
|
|
185
|
+
for (const [field, conditions] of Object.entries(filter)) {
|
|
186
|
+
if (combined[field]) {
|
|
187
|
+
// Merge conditions for the same field
|
|
188
|
+
combined[field] = { ...combined[field], ...conditions };
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
combined[field] = conditions;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return combined;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=filter-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-parser.js","sourceRoot":"","sources":["../../src/parsers/filter-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAGvE;IACD,IAAI,OAAO;QACV,OAAO,2BAA2B,IAAI,CAAC,UAAU,MAAM,IAAI,CAAC,MA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