patram 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build-graph-identity.js +57 -24
- package/lib/build-graph.js +383 -17
- package/lib/build-graph.types.ts +5 -2
- package/lib/check-directive-metadata.js +516 -0
- package/lib/check-directive-value.js +282 -0
- package/lib/check-graph.js +24 -5
- package/lib/cli-help-metadata.js +580 -0
- package/lib/derived-summary.js +280 -0
- package/lib/directive-diagnostics.js +38 -0
- package/lib/directive-type-rules.js +133 -0
- package/lib/discover-fields.js +427 -0
- package/lib/discover-fields.types.ts +52 -0
- package/lib/format-derived-summary-row.js +9 -0
- package/lib/format-node-header.js +21 -0
- package/lib/format-output-item-block.js +22 -0
- package/lib/format-output-metadata.js +54 -0
- package/lib/layout-stored-queries.js +96 -2
- package/lib/load-patram-config.js +754 -18
- package/lib/load-patram-config.types.ts +128 -2
- package/lib/load-project-graph.js +4 -1
- package/lib/output-view.types.ts +29 -6
- package/lib/parse-cli-arguments-helpers.js +263 -90
- package/lib/parse-cli-arguments.js +160 -8
- package/lib/parse-cli-arguments.types.ts +49 -4
- package/lib/parse-where-clause.js +670 -209
- package/lib/parse-where-clause.types.ts +72 -0
- package/lib/patram-cli.js +180 -21
- package/lib/patram-config.js +31 -31
- package/lib/patram-config.types.ts +10 -4
- package/lib/patram.js +6 -0
- package/lib/query-graph.js +444 -113
- package/lib/query-inspection.js +798 -0
- package/lib/render-check-output.js +1 -1
- package/lib/render-cli-help.js +419 -0
- package/lib/render-field-discovery.js +148 -0
- package/lib/render-json-output.js +66 -14
- package/lib/render-output-view.js +272 -22
- package/lib/render-plain-output.js +31 -86
- package/lib/render-rich-output.js +34 -87
- package/lib/resolve-patram-graph-config.js +15 -9
- package/lib/resolve-where-clause.js +18 -3
- package/lib/show-document.js +51 -7
- package/lib/tagged-fenced-block-error.js +17 -0
- package/lib/tagged-fenced-block-markdown.js +111 -0
- package/lib/tagged-fenced-block-metadata.js +97 -0
- package/lib/tagged-fenced-block-parser.js +292 -0
- package/lib/tagged-fenced-blocks.js +100 -0
- package/lib/tagged-fenced-blocks.types.ts +38 -0
- package/package.json +12 -7
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/* eslint-disable max-lines-per-function */
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {import('./parse-cli-arguments-helpers.js').CliOptionValues} CliOptionValues
|
|
3
4
|
* @typedef {import('./parse-cli-arguments-helpers.js').ParsedCommandLine} ParsedCommandLine
|
|
5
|
+
* @typedef {import('./parse-cli-arguments.types.ts').CliParseError} CliParseError
|
|
4
6
|
* @typedef {import('./parse-cli-arguments.types.ts').ParseCliArgumentsResult} ParseCliArgumentsResult
|
|
5
7
|
*/
|
|
6
8
|
|
|
@@ -10,11 +12,19 @@ import {
|
|
|
10
12
|
CLI_OPTIONS,
|
|
11
13
|
buildCommandArguments,
|
|
12
14
|
collectOptionTokens,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
createCommandHelpRequest,
|
|
16
|
+
createMessageParseError,
|
|
17
|
+
createNamedHelpRequest,
|
|
18
|
+
createRootHelpRequest,
|
|
19
|
+
createUnknownCommandError,
|
|
20
|
+
createUnknownHelpTargetError,
|
|
15
21
|
resolveOutputMode,
|
|
22
|
+
validateCommandLineBeforeHelp,
|
|
23
|
+
validateHelpCommandLine,
|
|
16
24
|
validateParsedCommand,
|
|
25
|
+
validateRootCommandLine,
|
|
17
26
|
} from './parse-cli-arguments-helpers.js';
|
|
27
|
+
import { isCommandName } from './cli-help-metadata.js';
|
|
18
28
|
import { resolveColorMode } from './parse-cli-color-options.js';
|
|
19
29
|
import { buildQueryPagination } from './parse-cli-query-pagination.js';
|
|
20
30
|
|
|
@@ -46,19 +56,56 @@ export function parseCliArguments(cli_arguments) {
|
|
|
46
56
|
return command_line;
|
|
47
57
|
}
|
|
48
58
|
|
|
59
|
+
const root_request = resolveRootHelpRequest(command_line.value);
|
|
60
|
+
|
|
61
|
+
if (root_request) {
|
|
62
|
+
return root_request;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const help_request = resolveNamedHelpRequest(command_line.value);
|
|
66
|
+
|
|
67
|
+
if (help_request) {
|
|
68
|
+
return help_request;
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
const command_name = command_line.value.positionals[0];
|
|
50
72
|
|
|
51
73
|
if (!isCommandName(command_name)) {
|
|
52
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
error: createUnknownCommandError(command_name),
|
|
76
|
+
success: false,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const pre_help_error = validateCommandLineBeforeHelp(
|
|
81
|
+
command_name,
|
|
82
|
+
command_line.value,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (pre_help_error) {
|
|
86
|
+
return {
|
|
87
|
+
error: pre_help_error,
|
|
88
|
+
success: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (command_line.value.values.help) {
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
value: createCommandHelpRequest(command_name),
|
|
96
|
+
};
|
|
53
97
|
}
|
|
54
98
|
|
|
55
|
-
const
|
|
99
|
+
const validation_error = validateParsedCommand(
|
|
56
100
|
command_name,
|
|
57
101
|
command_line.value,
|
|
58
102
|
);
|
|
59
103
|
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
104
|
+
if (validation_error) {
|
|
105
|
+
return {
|
|
106
|
+
error: validation_error,
|
|
107
|
+
success: false,
|
|
108
|
+
};
|
|
62
109
|
}
|
|
63
110
|
|
|
64
111
|
const command_positionals = command_line.value.positionals.slice(1);
|
|
@@ -66,6 +113,7 @@ export function parseCliArguments(cli_arguments) {
|
|
|
66
113
|
return {
|
|
67
114
|
success: true,
|
|
68
115
|
value: {
|
|
116
|
+
kind: 'command',
|
|
69
117
|
color_mode: resolveColorMode(command_line.value.option_tokens),
|
|
70
118
|
command_arguments: buildCommandArguments(
|
|
71
119
|
command_name,
|
|
@@ -74,6 +122,7 @@ export function parseCliArguments(cli_arguments) {
|
|
|
74
122
|
),
|
|
75
123
|
command_name,
|
|
76
124
|
output_mode: resolveOutputMode(command_line.value.values),
|
|
125
|
+
...buildQueryInspection(command_line.value),
|
|
77
126
|
...buildQueryPagination(command_line.value.values),
|
|
78
127
|
},
|
|
79
128
|
};
|
|
@@ -81,7 +130,7 @@ export function parseCliArguments(cli_arguments) {
|
|
|
81
130
|
|
|
82
131
|
/**
|
|
83
132
|
* @param {string[]} cli_arguments
|
|
84
|
-
* @returns {{ success: true, value: ParsedCommandLine } | {
|
|
133
|
+
* @returns {{ success: true, value: ParsedCommandLine } | { error: CliParseError, success: false }}
|
|
85
134
|
*/
|
|
86
135
|
function parseCommandLine(cli_arguments) {
|
|
87
136
|
try {
|
|
@@ -106,9 +155,112 @@ function parseCommandLine(cli_arguments) {
|
|
|
106
155
|
};
|
|
107
156
|
} catch (error) {
|
|
108
157
|
if (error instanceof Error) {
|
|
109
|
-
return
|
|
158
|
+
return {
|
|
159
|
+
error: /** @type {CliParseError} */ (
|
|
160
|
+
createMessageParseError(error.message)
|
|
161
|
+
),
|
|
162
|
+
success: false,
|
|
163
|
+
};
|
|
110
164
|
}
|
|
111
165
|
|
|
112
166
|
throw error;
|
|
113
167
|
}
|
|
114
168
|
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {ParsedCommandLine} command_line
|
|
172
|
+
* @returns {ParseCliArgumentsResult | null}
|
|
173
|
+
*/
|
|
174
|
+
function resolveNamedHelpRequest(command_line) {
|
|
175
|
+
if (command_line.positionals[0] !== 'help') {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const validation_error = validateHelpCommandLine(command_line);
|
|
180
|
+
|
|
181
|
+
if (validation_error) {
|
|
182
|
+
return {
|
|
183
|
+
error: validation_error,
|
|
184
|
+
success: false,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const help_target = command_line.positionals[1];
|
|
189
|
+
|
|
190
|
+
if (!help_target) {
|
|
191
|
+
return {
|
|
192
|
+
success: true,
|
|
193
|
+
value: createRootHelpRequest(),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const help_request = createNamedHelpRequest(help_target);
|
|
198
|
+
|
|
199
|
+
if (help_request) {
|
|
200
|
+
return {
|
|
201
|
+
success: true,
|
|
202
|
+
value: help_request,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
error: createUnknownHelpTargetError(help_target),
|
|
208
|
+
success: false,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {ParsedCommandLine} command_line
|
|
214
|
+
* @returns {ParseCliArgumentsResult | null}
|
|
215
|
+
*/
|
|
216
|
+
function resolveRootHelpRequest(command_line) {
|
|
217
|
+
if (command_line.positionals.length > 0) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const validation_error = validateRootCommandLine(command_line);
|
|
222
|
+
|
|
223
|
+
if (validation_error) {
|
|
224
|
+
return {
|
|
225
|
+
error: validation_error,
|
|
226
|
+
success: false,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
success: true,
|
|
232
|
+
value: createRootHelpRequest(),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @param {ParsedCommandLine} command_line
|
|
238
|
+
* @returns {'explain' | 'lint' | undefined}
|
|
239
|
+
*/
|
|
240
|
+
function resolveQueryInspectionMode(command_line) {
|
|
241
|
+
if (command_line.values.explain) {
|
|
242
|
+
return 'explain';
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (command_line.values.lint) {
|
|
246
|
+
return 'lint';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @param {ParsedCommandLine} command_line
|
|
254
|
+
* @returns {{ query_inspection_mode?: 'explain' | 'lint' }}
|
|
255
|
+
*/
|
|
256
|
+
function buildQueryInspection(command_line) {
|
|
257
|
+
const query_inspection_mode = resolveQueryInspectionMode(command_line);
|
|
258
|
+
|
|
259
|
+
if (!query_inspection_mode) {
|
|
260
|
+
return {};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
query_inspection_mode,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
@@ -1,24 +1,69 @@
|
|
|
1
|
-
export type CliCommandName = 'check' | 'query' | 'queries' | 'show';
|
|
1
|
+
export type CliCommandName = 'check' | 'fields' | 'query' | 'queries' | 'show';
|
|
2
|
+
export type CliHelpTopicName = 'query-language';
|
|
3
|
+
export type CliHelpTargetKind = 'root' | 'command' | 'topic';
|
|
2
4
|
|
|
3
5
|
export type CliOutputMode = 'default' | 'plain' | 'json';
|
|
4
6
|
|
|
5
7
|
export type CliColorMode = 'auto' | 'always' | 'never';
|
|
6
8
|
|
|
7
|
-
export interface
|
|
9
|
+
export interface ParsedCliCommandRequest {
|
|
10
|
+
kind?: 'command';
|
|
8
11
|
color_mode: CliColorMode;
|
|
9
12
|
command_arguments: string[];
|
|
10
13
|
command_name: CliCommandName;
|
|
11
14
|
output_mode: CliOutputMode;
|
|
15
|
+
query_inspection_mode?: 'explain' | 'lint';
|
|
12
16
|
query_limit?: number;
|
|
13
17
|
query_offset?: number;
|
|
14
18
|
}
|
|
15
19
|
|
|
20
|
+
export interface ParsedCliHelpRequest {
|
|
21
|
+
kind: 'help';
|
|
22
|
+
target_kind: CliHelpTargetKind;
|
|
23
|
+
target_name?: CliCommandName | CliHelpTopicName;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ParsedCliArguments = ParsedCliCommandRequest;
|
|
27
|
+
export type ParsedCliRequest = ParsedCliCommandRequest | ParsedCliHelpRequest;
|
|
28
|
+
|
|
29
|
+
export type CliParseError =
|
|
30
|
+
| {
|
|
31
|
+
code: 'message';
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
code: 'missing_required_argument';
|
|
36
|
+
argument_label: string;
|
|
37
|
+
command_name: 'query' | 'show';
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
code: 'option_not_valid_for_command';
|
|
41
|
+
command_name: CliCommandName;
|
|
42
|
+
token: string;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
code: 'unknown_command';
|
|
46
|
+
suggestion?: CliCommandName;
|
|
47
|
+
token: string;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
code: 'unknown_help_target';
|
|
51
|
+
suggestion?: CliCommandName | CliHelpTopicName;
|
|
52
|
+
token: string;
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
code: 'unknown_option';
|
|
56
|
+
command_name?: CliCommandName;
|
|
57
|
+
suggestion?: string;
|
|
58
|
+
token: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
16
61
|
export type ParseCliArgumentsResult =
|
|
17
62
|
| {
|
|
18
63
|
success: true;
|
|
19
|
-
value:
|
|
64
|
+
value: ParsedCliRequest;
|
|
20
65
|
}
|
|
21
66
|
| {
|
|
22
|
-
|
|
67
|
+
error: CliParseError;
|
|
23
68
|
success: false;
|
|
24
69
|
};
|