patram 0.7.0 → 0.9.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/bin/patram.js +2 -2
- package/lib/{parse-cli-color-options.js → cli/color-options.js} +2 -2
- package/lib/cli/command-helpers.js +35 -0
- package/lib/cli/commands/check.js +73 -0
- package/lib/cli/commands/fields.js +57 -0
- package/lib/cli/commands/queries.js +41 -0
- package/lib/cli/commands/query.js +239 -0
- package/lib/cli/commands/refs.js +72 -0
- package/lib/cli/commands/show.js +58 -0
- package/lib/{cli-help-metadata.js → cli/help-metadata.js} +54 -15
- package/lib/cli/main.js +76 -0
- package/lib/{parse-cli-arguments-helpers.js → cli/parse-arguments-helpers.js} +18 -11
- package/lib/{parse-cli-arguments.js → cli/parse-arguments.js} +12 -12
- package/lib/{parse-cli-query-pagination.js → cli/query-pagination.js} +2 -2
- package/lib/{render-cli-help.js → cli/render-help.js} +4 -4
- package/lib/{resolve-output-mode.js → cli/resolve-output-mode.js} +2 -2
- package/lib/cli/test-helpers.js +30 -0
- package/lib/config/defaults.d.ts +10 -0
- package/lib/config/defaults.js +80 -0
- package/lib/config/load-patram-config.d.ts +76 -0
- package/lib/config/load-patram-config.js +315 -0
- package/lib/config/load-patram-config.types.d.ts +45 -0
- package/lib/{patram-config.d.ts → config/patram-config.d.ts} +31 -31
- package/lib/{patram-config.js → config/patram-config.js} +3 -3
- package/lib/{patram-config.types.d.ts → config/patram-config.types.d.ts} +1 -1
- package/lib/{resolve-patram-graph-config.d.ts → config/resolve-patram-graph-config.d.ts} +2 -2
- package/lib/{resolve-patram-graph-config.js → config/resolve-patram-graph-config.js} +3 -3
- package/lib/{load-patram-config.d.ts → config/schema.d.ts} +147 -191
- package/lib/config/schema.js +324 -0
- package/lib/{source-file-defaults.d.ts → config/source-file-defaults.d.ts} +0 -1
- package/lib/{source-file-defaults.js → config/source-file-defaults.js} +1 -1
- package/lib/config/validation.d.ts +27 -0
- package/lib/config/validation.js +615 -0
- package/lib/directive-validation-test-helpers.js +1 -1
- package/lib/{build-graph-identity.d.ts → graph/build-graph-identity.d.ts} +2 -2
- package/lib/{build-graph-identity.js → graph/build-graph-identity.js} +1 -1
- package/lib/{build-graph.d.ts → graph/build-graph.d.ts} +3 -3
- package/lib/{build-graph.js → graph/build-graph.js} +17 -13
- package/lib/{build-graph.types.d.ts → graph/build-graph.types.d.ts} +1 -1
- package/lib/graph/check-directive-metadata.d.ts +23 -0
- package/lib/{check-directive-metadata.js → graph/check-directive-metadata.js} +7 -7
- package/lib/graph/check-directive-path-target.d.ts +32 -0
- package/lib/{check-directive-path-target.js → graph/check-directive-path-target.js} +4 -4
- package/lib/graph/check-directive-value.d.ts +19 -0
- package/lib/{check-directive-value.js → graph/check-directive-value.js} +3 -3
- package/lib/graph/check-graph.d.ts +29 -0
- package/lib/{check-graph.js → graph/check-graph.js} +6 -6
- package/lib/graph/directive-diagnostics.d.ts +20 -0
- package/lib/{directive-diagnostics.js → graph/directive-diagnostics.js} +2 -2
- package/lib/graph/directive-type-rules.d.ts +18 -0
- package/lib/{directive-type-rules.js → graph/directive-type-rules.js} +3 -3
- package/lib/{document-node-identity.d.ts → graph/document-node-identity.d.ts} +2 -2
- package/lib/{document-node-identity.js → graph/document-node-identity.js} +2 -2
- package/lib/graph/inspect-reverse-references.d.ts +22 -0
- package/lib/graph/inspect-reverse-references.js +184 -0
- package/lib/{load-project-graph.d.ts → graph/load-project-graph.d.ts} +10 -10
- package/lib/{load-project-graph.js → graph/load-project-graph.js} +12 -12
- package/lib/{parse-where-clause.types.d.ts → graph/parse-where-clause.types.d.ts} +1 -1
- package/lib/{query-graph.d.ts → graph/query/execute.d.ts} +11 -11
- package/lib/{query-graph.js → graph/query/execute.js} +12 -12
- package/lib/{query-inspection.d.ts → graph/query/inspect.d.ts} +10 -8
- package/lib/{query-inspection.js → graph/query/inspect.js} +16 -17
- package/lib/{parse-where-clause.d.ts → graph/query/parse.d.ts} +6 -6
- package/lib/{parse-where-clause.js → graph/query/parse.js} +2 -2
- package/lib/graph/query/resolve.d.ts +30 -0
- package/lib/{resolve-where-clause.js → graph/query/resolve.js} +1 -1
- package/lib/graph/reverse-reference-test-helpers.d.ts +55 -0
- package/lib/graph/reverse-reference-test-helpers.js +76 -0
- package/lib/{command-output.js → output/command-output.js} +6 -5
- package/lib/{derived-summary.js → output/derived-summary.js} +7 -7
- package/lib/output/layout-incoming-references.js +105 -0
- package/lib/output/layout-incoming-summary-lines.js +16 -0
- package/lib/{layout-stored-queries.js → output/layout-stored-queries.js} +9 -9
- package/lib/{list-queries.js → output/list-queries.js} +1 -1
- package/lib/{render-check-output.js → output/render-check-output.js} +1 -1
- package/lib/{render-field-discovery.js → output/render-field-discovery.js} +3 -3
- package/lib/output/render-output-view.js +56 -0
- package/lib/{render-json-output.js → output/renderers/json.js} +92 -63
- package/lib/{render-plain-output.js → output/renderers/plain.js} +62 -7
- package/lib/{render-rich-output.js → output/renderers/rich.js} +69 -8
- package/lib/{resolve-check-target.js → output/resolve-check-target.js} +1 -1
- package/lib/{render-rich-source.js → output/rich-source/render.js} +6 -6
- package/lib/{show-document.js → output/show-document.js} +54 -16
- package/lib/{render-output-view.js → output/view-model/index.js} +56 -47
- package/lib/{write-paged-output.js → output/write-paged-output.js} +9 -5
- package/lib/{claim-helpers.d.ts → parse/claim-helpers.d.ts} +2 -2
- package/lib/{parse-jsdoc-claims.d.ts → parse/jsdoc/parse-jsdoc-claims.d.ts} +2 -2
- package/lib/{parse-jsdoc-claims.js → parse/jsdoc/parse-jsdoc-claims.js} +9 -9
- package/lib/{parse-jsdoc-prose.d.ts → parse/jsdoc/parse-jsdoc-prose.d.ts} +1 -1
- package/lib/{parse-jsdoc-prose.js → parse/jsdoc/parse-jsdoc-prose.js} +1 -1
- package/lib/{parse-markdown-claims.d.ts → parse/markdown/parse-markdown-claims.d.ts} +3 -3
- package/lib/{parse-markdown-claims.js → parse/markdown/parse-markdown-claims.js} +8 -8
- package/lib/{parse-markdown-directives.d.ts → parse/markdown/parse-markdown-directives.d.ts} +2 -2
- package/lib/{parse-markdown-directives.js → parse/markdown/parse-markdown-directives.js} +3 -3
- package/lib/{parse-claims.d.ts → parse/parse-claims.d.ts} +4 -13
- package/lib/{parse-claims.js → parse/parse-claims.js} +18 -26
- package/lib/{parse-claims.types.d.ts → parse/parse-claims.types.d.ts} +1 -1
- package/lib/{tagged-fenced-block-error.d.ts → parse/tagged-fenced/tagged-fenced-block-error.d.ts} +2 -2
- package/lib/{tagged-fenced-block-parser.d.ts → parse/tagged-fenced/tagged-fenced-block-parser.d.ts} +3 -3
- package/lib/{tagged-fenced-blocks.d.ts → parse/tagged-fenced/tagged-fenced-blocks.d.ts} +7 -7
- package/lib/{tagged-fenced-blocks.js → parse/tagged-fenced/tagged-fenced-blocks.js} +3 -3
- package/lib/{parse-yaml-claims.d.ts → parse/yaml/parse-yaml-claims.d.ts} +4 -4
- package/lib/{parse-yaml-claims.js → parse/yaml/parse-yaml-claims.js} +22 -13
- package/lib/patram.d.ts +29 -28
- package/lib/patram.js +5 -6
- package/lib/{discover-fields.js → scan/discover-fields.js} +9 -8
- package/lib/scan/list-repo-files.d.ts +16 -0
- package/lib/{list-source-files.js → scan/list-repo-files.js} +2 -35
- package/lib/{list-source-files.d.ts → scan/list-source-files.d.ts} +4 -11
- package/lib/scan/list-source-files.js +45 -0
- package/package.json +8 -7
- package/lib/build-graph.types.ts +0 -27
- package/lib/discover-fields.types.ts +0 -52
- package/lib/load-patram-config.js +0 -1215
- package/lib/load-patram-config.types.d.ts +0 -45
- package/lib/load-patram-config.types.ts +0 -56
- package/lib/output-view.types.d.ts +0 -80
- package/lib/output-view.types.ts +0 -96
- package/lib/overlay-graph.d.ts +0 -43
- package/lib/overlay-graph.js +0 -191
- package/lib/parse-claims.types.ts +0 -41
- package/lib/parse-cli-arguments.types.ts +0 -69
- package/lib/parse-where-clause.types.ts +0 -87
- package/lib/patram-cli.js +0 -528
- package/lib/patram-config.types.ts +0 -22
- package/lib/tagged-fenced-blocks.types.ts +0 -38
- /package/lib/{format-derived-summary-row.js → output/format-derived-summary-row.js} +0 -0
- /package/lib/{format-node-header.js → output/format-node-header.js} +0 -0
- /package/lib/{format-output-item-block.js → output/format-output-item-block.js} +0 -0
- /package/lib/{format-output-metadata.js → output/format-output-metadata.js} +0 -0
- /package/lib/{claim-helpers.js → parse/claim-helpers.js} +0 -0
- /package/lib/{parse-jsdoc-blocks.d.ts → parse/jsdoc/parse-jsdoc-blocks.d.ts} +0 -0
- /package/lib/{parse-jsdoc-blocks.js → parse/jsdoc/parse-jsdoc-blocks.js} +0 -0
- /package/lib/{tagged-fenced-block-error.js → parse/tagged-fenced/tagged-fenced-block-error.js} +0 -0
- /package/lib/{tagged-fenced-block-markdown.d.ts → parse/tagged-fenced/tagged-fenced-block-markdown.d.ts} +0 -0
- /package/lib/{tagged-fenced-block-markdown.js → parse/tagged-fenced/tagged-fenced-block-markdown.js} +0 -0
- /package/lib/{tagged-fenced-block-metadata.d.ts → parse/tagged-fenced/tagged-fenced-block-metadata.d.ts} +0 -0
- /package/lib/{tagged-fenced-block-metadata.js → parse/tagged-fenced/tagged-fenced-block-metadata.js} +0 -0
- /package/lib/{tagged-fenced-block-parser.js → parse/tagged-fenced/tagged-fenced-block-parser.js} +0 -0
- /package/lib/{tagged-fenced-blocks.types.d.ts → parse/tagged-fenced/tagged-fenced-blocks.types.d.ts} +0 -0
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { PatramDiagnostic } from './load-patram-config.types.ts';
|
|
2
|
-
|
|
3
|
-
export type ParsedFieldName = string;
|
|
4
|
-
|
|
5
|
-
export interface ParsedFieldTerm {
|
|
6
|
-
column: number;
|
|
7
|
-
field_name: ParsedFieldName;
|
|
8
|
-
kind: 'field';
|
|
9
|
-
operator: '!=' | '<' | '<=' | '=' | '>' | '>=' | '^=' | '~';
|
|
10
|
-
value: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ParsedFieldSetTerm {
|
|
14
|
-
column: number;
|
|
15
|
-
field_name: ParsedFieldName;
|
|
16
|
-
kind: 'field_set';
|
|
17
|
-
operator: 'in' | 'not in';
|
|
18
|
-
values: string[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ParsedTraversalTerm {
|
|
22
|
-
column: number;
|
|
23
|
-
direction: 'in' | 'out';
|
|
24
|
-
relation_name: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ParsedRelationTerm {
|
|
28
|
-
column: number;
|
|
29
|
-
kind: 'relation';
|
|
30
|
-
relation_name: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ParsedRelationTargetTerm {
|
|
34
|
-
column: number;
|
|
35
|
-
kind: 'relation_target';
|
|
36
|
-
relation_name: string;
|
|
37
|
-
target_id: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type ParsedAggregateComparison = '!=' | '<' | '<=' | '=' | '>' | '>=';
|
|
41
|
-
export type ParsedAggregateName = 'any' | 'count' | 'none';
|
|
42
|
-
|
|
43
|
-
export interface ParsedAggregateTerm {
|
|
44
|
-
aggregate_name: ParsedAggregateName;
|
|
45
|
-
comparison?: ParsedAggregateComparison;
|
|
46
|
-
expression: ParsedExpression;
|
|
47
|
-
kind: 'aggregate';
|
|
48
|
-
traversal: ParsedTraversalTerm;
|
|
49
|
-
value?: number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface ParsedTermExpression {
|
|
53
|
-
kind: 'term';
|
|
54
|
-
term: ParsedTerm;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface ParsedNotExpression {
|
|
58
|
-
expression: ParsedExpression;
|
|
59
|
-
kind: 'not';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ParsedBooleanExpression {
|
|
63
|
-
expressions: ParsedExpression[];
|
|
64
|
-
kind: 'and' | 'or';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type ParsedTerm =
|
|
68
|
-
| ParsedAggregateTerm
|
|
69
|
-
| ParsedFieldSetTerm
|
|
70
|
-
| ParsedFieldTerm
|
|
71
|
-
| ParsedRelationTargetTerm
|
|
72
|
-
| ParsedRelationTerm;
|
|
73
|
-
|
|
74
|
-
export type ParsedExpression =
|
|
75
|
-
| ParsedBooleanExpression
|
|
76
|
-
| ParsedNotExpression
|
|
77
|
-
| ParsedTermExpression;
|
|
78
|
-
|
|
79
|
-
export type ParseWhereClauseResult =
|
|
80
|
-
| {
|
|
81
|
-
expression: ParsedExpression;
|
|
82
|
-
success: true;
|
|
83
|
-
}
|
|
84
|
-
| {
|
|
85
|
-
diagnostic: PatramDiagnostic;
|
|
86
|
-
success: false;
|
|
87
|
-
};
|
package/lib/patram-cli.js
DELETED
|
@@ -1,528 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
/**
|
|
3
|
-
* @import { ParsedCliCommandRequest } from './parse-cli-arguments.types.ts';
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import process from 'node:process';
|
|
7
|
-
|
|
8
|
-
import { checkGraph } from './check-graph.js';
|
|
9
|
-
import {
|
|
10
|
-
shouldPageCommandOutput,
|
|
11
|
-
writeCommandOutput,
|
|
12
|
-
writeRenderedCommandOutput,
|
|
13
|
-
} from './command-output.js';
|
|
14
|
-
import { discoverFields } from './discover-fields.js';
|
|
15
|
-
import { listRepoFiles } from './list-source-files.js';
|
|
16
|
-
import { listQueries } from './list-queries.js';
|
|
17
|
-
import { loadPatramConfig } from './load-patram-config.js';
|
|
18
|
-
import { loadProjectGraph } from './load-project-graph.js';
|
|
19
|
-
import { parseCliArguments } from './parse-cli-arguments.js';
|
|
20
|
-
import { DEFAULT_QUERY_LIMIT, queryGraph } from './query-graph.js';
|
|
21
|
-
import { inspectQuery, renderQueryInspection } from './query-inspection.js';
|
|
22
|
-
import { createDerivedSummaryEvaluator } from './derived-summary.js';
|
|
23
|
-
import {
|
|
24
|
-
renderCheckDiagnostics,
|
|
25
|
-
renderCheckSuccess,
|
|
26
|
-
} from './render-check-output.js';
|
|
27
|
-
import {
|
|
28
|
-
renderCliParseError,
|
|
29
|
-
renderHelpRequest,
|
|
30
|
-
renderInvalidWhereDiagnostic,
|
|
31
|
-
} from './render-cli-help.js';
|
|
32
|
-
import {
|
|
33
|
-
resolveCheckTarget,
|
|
34
|
-
selectCheckTargetDiagnostics,
|
|
35
|
-
selectCheckTargetSourceFiles,
|
|
36
|
-
} from './resolve-check-target.js';
|
|
37
|
-
import {
|
|
38
|
-
createOutputView,
|
|
39
|
-
createShowOutputView,
|
|
40
|
-
} from './render-output-view.js';
|
|
41
|
-
import { renderFieldDiscovery } from './render-field-discovery.js';
|
|
42
|
-
import { resolveWhereClause } from './resolve-where-clause.js';
|
|
43
|
-
import { resolveOutputMode } from './resolve-output-mode.js';
|
|
44
|
-
import { loadShowOutput } from './show-document.js';
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Patram command execution flow.
|
|
48
|
-
*
|
|
49
|
-
* Loads repo state and routes `check`, `fields`, `query`, `queries`, and
|
|
50
|
-
* `show` through the shared output pipeline.
|
|
51
|
-
*
|
|
52
|
-
* Kind: cli
|
|
53
|
-
* Status: active
|
|
54
|
-
* Implements Command: ../docs/reference/commands/check.md
|
|
55
|
-
* Implements Command: ../docs/reference/commands/query.md
|
|
56
|
-
* Implements Command: ../docs/reference/commands/queries.md
|
|
57
|
-
* Implements Command: ../docs/reference/commands/show.md
|
|
58
|
-
* Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
|
|
59
|
-
* Decided by: ../docs/decisions/cli-output-architecture.md
|
|
60
|
-
* Decided by: ../docs/decisions/cli-argument-parser.md
|
|
61
|
-
* @patram
|
|
62
|
-
* @see {@link ./parse-cli-arguments.js}
|
|
63
|
-
* @see {@link ./render-output-view.js}
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Run the Patram CLI.
|
|
68
|
-
*
|
|
69
|
-
* @param {string[]} cli_arguments
|
|
70
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean }, write_paged_output?: (output_text: string) => Promise<void> }} io_context
|
|
71
|
-
* @returns {Promise<number>}
|
|
72
|
-
*/
|
|
73
|
-
export async function main(cli_arguments, io_context) {
|
|
74
|
-
const parsed_arguments = parseCliArguments(cli_arguments);
|
|
75
|
-
|
|
76
|
-
if (!parsed_arguments.success) {
|
|
77
|
-
io_context.stderr.write(renderCliParseError(parsed_arguments.error));
|
|
78
|
-
|
|
79
|
-
return 1;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (parsed_arguments.value.kind === 'help') {
|
|
83
|
-
io_context.stdout.write(renderHelpRequest(parsed_arguments.value));
|
|
84
|
-
|
|
85
|
-
return 0;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const parsed_command = /** @type {ParsedCliCommandRequest} */ (
|
|
89
|
-
parsed_arguments.value
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
if (parsed_command.command_name === 'check') {
|
|
93
|
-
return runCheckCommand(parsed_command, io_context);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (parsed_command.command_name === 'query') {
|
|
97
|
-
return runQueryCommand(parsed_command, io_context);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (parsed_command.command_name === 'fields') {
|
|
101
|
-
return runFieldsCommand(parsed_command, io_context);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (parsed_command.command_name === 'queries') {
|
|
105
|
-
return runQueriesCommand(parsed_command, io_context);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (parsed_command.command_name === 'show') {
|
|
109
|
-
return runShowCommand(parsed_command, io_context);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
io_context.stderr.write('Unknown command.\n');
|
|
113
|
-
|
|
114
|
-
return 1;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
119
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean }, write_paged_output?: (output_text: string) => Promise<void> }} io_context
|
|
120
|
-
* @returns {Promise<number>}
|
|
121
|
-
*/
|
|
122
|
-
async function runCheckCommand(parsed_command, io_context) {
|
|
123
|
-
const output_mode = resolveOutputMode(parsed_command, {
|
|
124
|
-
is_tty: io_context.stdout.isTTY === true,
|
|
125
|
-
no_color: process.env.NO_COLOR !== undefined,
|
|
126
|
-
term: process.env.TERM,
|
|
127
|
-
});
|
|
128
|
-
const resolved_target = await resolveCheckTarget(
|
|
129
|
-
parsed_command.command_arguments[0],
|
|
130
|
-
);
|
|
131
|
-
const project_graph_result = await loadProjectGraph(
|
|
132
|
-
resolved_target.project_directory,
|
|
133
|
-
);
|
|
134
|
-
const repo_file_paths = await listRepoFiles(
|
|
135
|
-
resolved_target.project_directory,
|
|
136
|
-
);
|
|
137
|
-
const selected_source_file_paths = selectCheckTargetSourceFiles(
|
|
138
|
-
project_graph_result.source_file_paths,
|
|
139
|
-
resolved_target,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (project_graph_result.diagnostics.length > 0) {
|
|
143
|
-
io_context.stderr.write(
|
|
144
|
-
renderCheckDiagnostics(project_graph_result.diagnostics, output_mode),
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
return 1;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const diagnostics = checkGraph(
|
|
151
|
-
project_graph_result.graph,
|
|
152
|
-
repo_file_paths,
|
|
153
|
-
project_graph_result.config,
|
|
154
|
-
project_graph_result.claims,
|
|
155
|
-
);
|
|
156
|
-
const selected_diagnostics = selectCheckTargetDiagnostics(
|
|
157
|
-
diagnostics,
|
|
158
|
-
resolved_target,
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
if (selected_diagnostics.length > 0) {
|
|
162
|
-
io_context.stderr.write(
|
|
163
|
-
renderCheckDiagnostics(selected_diagnostics, output_mode),
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
return 1;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
io_context.stdout.write(
|
|
170
|
-
renderCheckSuccess(selected_source_file_paths.length, output_mode),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
return 0;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
178
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean }, write_paged_output?: (output_text: string) => Promise<void> }} io_context
|
|
179
|
-
* @returns {Promise<number>}
|
|
180
|
-
*/
|
|
181
|
-
async function runQueryCommand(parsed_command, io_context) {
|
|
182
|
-
const use_pager = shouldPageCommandOutput(parsed_command, io_context.stdout);
|
|
183
|
-
const output_mode = resolveOutputMode(parsed_command, {
|
|
184
|
-
is_tty: io_context.stdout.isTTY === true,
|
|
185
|
-
no_color: process.env.NO_COLOR !== undefined,
|
|
186
|
-
term: process.env.TERM,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
if (parsed_command.query_inspection_mode) {
|
|
190
|
-
return runQueryInspectionCommand(
|
|
191
|
-
parsed_command,
|
|
192
|
-
io_context,
|
|
193
|
-
output_mode,
|
|
194
|
-
use_pager,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const project_graph_result = await loadProjectGraph(process.cwd());
|
|
199
|
-
|
|
200
|
-
if (project_graph_result.diagnostics.length > 0) {
|
|
201
|
-
writeDiagnostics(io_context.stderr, project_graph_result.diagnostics);
|
|
202
|
-
|
|
203
|
-
return 1;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const where_clause = resolveWhereClause(
|
|
207
|
-
project_graph_result.config,
|
|
208
|
-
parsed_command.command_arguments,
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
if (!where_clause.success) {
|
|
212
|
-
io_context.stderr.write(`${where_clause.message}\n`);
|
|
213
|
-
|
|
214
|
-
return 1;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const query_result = queryGraph(
|
|
218
|
-
project_graph_result.graph,
|
|
219
|
-
where_clause.value.where_clause,
|
|
220
|
-
project_graph_result.config,
|
|
221
|
-
createQueryPaginationOptions(parsed_command, use_pager),
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
if (query_result.diagnostics.length > 0) {
|
|
225
|
-
io_context.stderr.write(
|
|
226
|
-
renderInvalidWhereDiagnostic(query_result.diagnostics[0]),
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
return 1;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const derived_summary_evaluator = createDerivedSummaryEvaluator(
|
|
233
|
-
project_graph_result.config,
|
|
234
|
-
project_graph_result.graph,
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
await writeCommandOutput(
|
|
238
|
-
io_context,
|
|
239
|
-
parsed_command,
|
|
240
|
-
createOutputView('query', query_result.nodes, {
|
|
241
|
-
derived_summary_evaluator,
|
|
242
|
-
...createQueryOutputOptions(parsed_command, query_result, use_pager),
|
|
243
|
-
repo_config: project_graph_result.config,
|
|
244
|
-
}),
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
return 0;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
252
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean } }} io_context
|
|
253
|
-
* @returns {Promise<number>}
|
|
254
|
-
*/
|
|
255
|
-
async function runFieldsCommand(parsed_command, io_context) {
|
|
256
|
-
const output_mode = resolveOutputMode(parsed_command, {
|
|
257
|
-
is_tty: io_context.stdout.isTTY === true,
|
|
258
|
-
no_color: process.env.NO_COLOR !== undefined,
|
|
259
|
-
term: process.env.TERM,
|
|
260
|
-
});
|
|
261
|
-
const load_result = await loadPatramConfig(process.cwd());
|
|
262
|
-
const defined_field_names =
|
|
263
|
-
load_result.diagnostics.length === 0
|
|
264
|
-
? collectDefinedDiscoveryNames(load_result.config)
|
|
265
|
-
: new Set();
|
|
266
|
-
const discovery_result = await discoverFields(process.cwd(), {
|
|
267
|
-
defined_field_names,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
await writeRenderedCommandOutput(
|
|
271
|
-
io_context,
|
|
272
|
-
parsed_command,
|
|
273
|
-
renderFieldDiscovery(discovery_result, output_mode),
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
return 0;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
281
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean } }} io_context
|
|
282
|
-
* @param {import('./output-view.types.ts').ResolvedOutputMode} output_mode
|
|
283
|
-
* @param {boolean} use_pager
|
|
284
|
-
* @returns {Promise<number>}
|
|
285
|
-
*/
|
|
286
|
-
async function runQueryInspectionCommand(
|
|
287
|
-
parsed_command,
|
|
288
|
-
io_context,
|
|
289
|
-
output_mode,
|
|
290
|
-
use_pager,
|
|
291
|
-
) {
|
|
292
|
-
const query_inspection_mode = parsed_command.query_inspection_mode;
|
|
293
|
-
|
|
294
|
-
if (!query_inspection_mode) {
|
|
295
|
-
throw new Error('Expected a query inspection mode.');
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const load_result = await loadPatramConfig(process.cwd());
|
|
299
|
-
|
|
300
|
-
if (load_result.diagnostics.length > 0) {
|
|
301
|
-
io_context.stderr.write(
|
|
302
|
-
renderCheckDiagnostics(load_result.diagnostics, output_mode),
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
return 1;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const repo_config = load_result.config;
|
|
309
|
-
|
|
310
|
-
if (!repo_config) {
|
|
311
|
-
throw new Error('Expected a valid Patram repo config.');
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const where_clause = resolveWhereClause(
|
|
315
|
-
repo_config,
|
|
316
|
-
parsed_command.command_arguments,
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
if (!where_clause.success) {
|
|
320
|
-
io_context.stderr.write(`${where_clause.message}\n`);
|
|
321
|
-
|
|
322
|
-
return 1;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const query_inspection = inspectQuery(repo_config, where_clause.value, {
|
|
326
|
-
inspection_mode: query_inspection_mode,
|
|
327
|
-
...createQueryExecutionOptions(parsed_command, use_pager),
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
if (!query_inspection.success) {
|
|
331
|
-
io_context.stderr.write(
|
|
332
|
-
renderCheckDiagnostics(query_inspection.diagnostics, output_mode),
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
return 1;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
io_context.stdout.write(
|
|
339
|
-
renderQueryInspection(query_inspection.value, output_mode),
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
return 0;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
347
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean }, write_paged_output?: (output_text: string) => Promise<void> }} io_context
|
|
348
|
-
* @returns {Promise<number>}
|
|
349
|
-
*/
|
|
350
|
-
async function runQueriesCommand(parsed_command, io_context) {
|
|
351
|
-
const load_result = await loadPatramConfig(process.cwd());
|
|
352
|
-
|
|
353
|
-
if (load_result.diagnostics.length > 0) {
|
|
354
|
-
writeDiagnostics(io_context.stderr, load_result.diagnostics);
|
|
355
|
-
|
|
356
|
-
return 1;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const repo_config = load_result.config;
|
|
360
|
-
|
|
361
|
-
if (!repo_config) {
|
|
362
|
-
throw new Error('Expected a valid Patram repo config.');
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
await writeCommandOutput(
|
|
366
|
-
io_context,
|
|
367
|
-
parsed_command,
|
|
368
|
-
createOutputView('queries', listQueries(repo_config.queries)),
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
return 0;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
376
|
-
* @param {{ stderr: { write(chunk: string): boolean }, stdout: { isTTY?: boolean, write(chunk: string): boolean }, write_paged_output?: (output_text: string) => Promise<void> }} io_context
|
|
377
|
-
* @returns {Promise<number>}
|
|
378
|
-
*/
|
|
379
|
-
async function runShowCommand(parsed_command, io_context) {
|
|
380
|
-
const project_graph_result = await loadProjectGraph(process.cwd());
|
|
381
|
-
|
|
382
|
-
if (project_graph_result.diagnostics.length > 0) {
|
|
383
|
-
writeDiagnostics(io_context.stderr, project_graph_result.diagnostics);
|
|
384
|
-
|
|
385
|
-
return 1;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const show_output = await loadShowOutput(
|
|
389
|
-
parsed_command.command_arguments[0],
|
|
390
|
-
process.cwd(),
|
|
391
|
-
project_graph_result.graph,
|
|
392
|
-
);
|
|
393
|
-
|
|
394
|
-
if (!show_output.success) {
|
|
395
|
-
writeDiagnostics(io_context.stderr, [show_output.diagnostic]);
|
|
396
|
-
|
|
397
|
-
return 1;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const derived_summary_evaluator = createDerivedSummaryEvaluator(
|
|
401
|
-
project_graph_result.config,
|
|
402
|
-
project_graph_result.graph,
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
await writeCommandOutput(
|
|
406
|
-
io_context,
|
|
407
|
-
parsed_command,
|
|
408
|
-
createShowOutputView(show_output.value, {
|
|
409
|
-
derived_summary_evaluator,
|
|
410
|
-
document_node_ids: project_graph_result.graph.document_node_ids,
|
|
411
|
-
graph_nodes: project_graph_result.graph.nodes,
|
|
412
|
-
repo_config: project_graph_result.config,
|
|
413
|
-
}),
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
return 0;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* @param {{ write(chunk: string): boolean }} output_stream
|
|
421
|
-
* @param {import('./load-patram-config.types.ts').PatramDiagnostic[]} diagnostics
|
|
422
|
-
*/
|
|
423
|
-
function writeDiagnostics(output_stream, diagnostics) {
|
|
424
|
-
for (const diagnostic of diagnostics) {
|
|
425
|
-
output_stream.write(formatDiagnostic(diagnostic));
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
431
|
-
* @param {{ total_count: number, nodes: import('./build-graph.types.ts').GraphNode[] }} query_result
|
|
432
|
-
* @param {boolean} use_pager
|
|
433
|
-
* @returns {{ hints: string[], limit: number, offset: number, total_count: number }}
|
|
434
|
-
*/
|
|
435
|
-
function createQueryOutputOptions(parsed_command, query_result, use_pager) {
|
|
436
|
-
/** @type {string[]} */
|
|
437
|
-
const hints = [];
|
|
438
|
-
const limit =
|
|
439
|
-
parsed_command.query_limit ??
|
|
440
|
-
(use_pager ? query_result.nodes.length : DEFAULT_QUERY_LIMIT);
|
|
441
|
-
const offset = parsed_command.query_offset ?? 0;
|
|
442
|
-
|
|
443
|
-
if (query_result.total_count === 0) {
|
|
444
|
-
hints.push('Try: patram query --where "$class=task"');
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (
|
|
448
|
-
!use_pager &&
|
|
449
|
-
parsed_command.query_limit === undefined &&
|
|
450
|
-
parsed_command.query_offset === undefined &&
|
|
451
|
-
query_result.total_count > DEFAULT_QUERY_LIMIT
|
|
452
|
-
) {
|
|
453
|
-
hints.push(
|
|
454
|
-
'Hint: use --offset <n> or --limit <n> to page through more matches.',
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return {
|
|
459
|
-
hints,
|
|
460
|
-
limit,
|
|
461
|
-
offset,
|
|
462
|
-
total_count: query_result.total_count,
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
468
|
-
* @param {boolean} use_pager
|
|
469
|
-
* @returns {{ limit?: number, offset: number }}
|
|
470
|
-
*/
|
|
471
|
-
function createQueryPaginationOptions(parsed_command, use_pager) {
|
|
472
|
-
/** @type {{ limit?: number, offset: number }} */
|
|
473
|
-
const pagination_options = {
|
|
474
|
-
offset: parsed_command.query_offset ?? 0,
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
if (parsed_command.query_limit !== undefined) {
|
|
478
|
-
pagination_options.limit = parsed_command.query_limit;
|
|
479
|
-
} else if (!use_pager) {
|
|
480
|
-
pagination_options.limit = DEFAULT_QUERY_LIMIT;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
return pagination_options;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* @param {ParsedCliCommandRequest} parsed_command
|
|
488
|
-
* @param {boolean} use_pager
|
|
489
|
-
* @returns {{ limit: number | null, offset: number }}
|
|
490
|
-
*/
|
|
491
|
-
function createQueryExecutionOptions(parsed_command, use_pager) {
|
|
492
|
-
const pagination_options = createQueryPaginationOptions(
|
|
493
|
-
parsed_command,
|
|
494
|
-
use_pager,
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
return {
|
|
498
|
-
limit: pagination_options.limit ?? null,
|
|
499
|
-
offset: pagination_options.offset,
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* @param {import('./load-patram-config.types.ts').PatramDiagnostic} diagnostic
|
|
505
|
-
* @returns {string}
|
|
506
|
-
*/
|
|
507
|
-
function formatDiagnostic(diagnostic) {
|
|
508
|
-
return `${diagnostic.path}:${diagnostic.line}:${diagnostic.column} ${diagnostic.level} ${diagnostic.code} ${diagnostic.message}\n`;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* @param {import('./load-patram-config.types.ts').PatramRepoConfig | null} repo_config
|
|
513
|
-
* @returns {Set<string>}
|
|
514
|
-
*/
|
|
515
|
-
function collectDefinedDiscoveryNames(repo_config) {
|
|
516
|
-
/** @type {Set<string>} */
|
|
517
|
-
const defined_field_names = new Set();
|
|
518
|
-
|
|
519
|
-
for (const field_name of Object.keys(repo_config?.fields ?? {})) {
|
|
520
|
-
defined_field_names.add(field_name);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
for (const relation_name of Object.keys(repo_config?.relations ?? {})) {
|
|
524
|
-
defined_field_names.add(relation_name);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return defined_field_names;
|
|
528
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ClassSchemaConfig,
|
|
3
|
-
MetadataFieldConfig,
|
|
4
|
-
} from './load-patram-config.types.ts';
|
|
5
|
-
|
|
6
|
-
export type ClassDefinition = import('./patram-config.js').ClassDefinition;
|
|
7
|
-
export type RelationDefinition =
|
|
8
|
-
import('./patram-config.js').RelationDefinition;
|
|
9
|
-
export type MappingNodeDefinition =
|
|
10
|
-
import('./patram-config.js').MappingNodeDefinition;
|
|
11
|
-
export type MappingEmitDefinition =
|
|
12
|
-
import('./patram-config.js').MappingEmitDefinition;
|
|
13
|
-
export type MappingDefinition = import('./patram-config.js').MappingDefinition;
|
|
14
|
-
export type PatramGraphConfig = import('./patram-config.js').PatramGraphConfig;
|
|
15
|
-
export type PatramClassConfig = ClassDefinition & {
|
|
16
|
-
schema?: ClassSchemaConfig;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type PatramConfig = Omit<PatramGraphConfig, 'classes'> & {
|
|
20
|
-
classes: Record<string, PatramClassConfig>;
|
|
21
|
-
fields?: Record<string, MetadataFieldConfig>;
|
|
22
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export interface TaggedFencedBlocksInput {
|
|
2
|
-
file_path: string;
|
|
3
|
-
source_text: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface TaggedFencedBlockCriteria {
|
|
7
|
-
[key: string]: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface TaggedFencedBlockOrigin {
|
|
11
|
-
path: string;
|
|
12
|
-
line_start: number;
|
|
13
|
-
line_end: number;
|
|
14
|
-
tag_lines: number[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface TaggedFencedBlockContext {
|
|
18
|
-
heading_path: string[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface TaggedFencedBlock {
|
|
22
|
-
id: string;
|
|
23
|
-
lang: string;
|
|
24
|
-
value: string;
|
|
25
|
-
metadata: Record<string, string>;
|
|
26
|
-
origin: TaggedFencedBlockOrigin;
|
|
27
|
-
context: TaggedFencedBlockContext;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface TaggedFencedBlockFile {
|
|
31
|
-
path: string;
|
|
32
|
-
title: string;
|
|
33
|
-
blocks: TaggedFencedBlock[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface TaggedFencedBlockError extends Error {
|
|
37
|
-
code: string;
|
|
38
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib/{tagged-fenced-block-error.js → parse/tagged-fenced/tagged-fenced-block-error.js}
RENAMED
|
File without changes
|
|
File without changes
|
/package/lib/{tagged-fenced-block-markdown.js → parse/tagged-fenced/tagged-fenced-block-markdown.js}
RENAMED
|
File without changes
|
|
File without changes
|
/package/lib/{tagged-fenced-block-metadata.js → parse/tagged-fenced/tagged-fenced-block-metadata.js}
RENAMED
|
File without changes
|
/package/lib/{tagged-fenced-block-parser.js → parse/tagged-fenced/tagged-fenced-block-parser.js}
RENAMED
|
File without changes
|