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.
Files changed (140) hide show
  1. package/bin/patram.js +2 -2
  2. package/lib/{parse-cli-color-options.js → cli/color-options.js} +2 -2
  3. package/lib/cli/command-helpers.js +35 -0
  4. package/lib/cli/commands/check.js +73 -0
  5. package/lib/cli/commands/fields.js +57 -0
  6. package/lib/cli/commands/queries.js +41 -0
  7. package/lib/cli/commands/query.js +239 -0
  8. package/lib/cli/commands/refs.js +72 -0
  9. package/lib/cli/commands/show.js +58 -0
  10. package/lib/{cli-help-metadata.js → cli/help-metadata.js} +54 -15
  11. package/lib/cli/main.js +76 -0
  12. package/lib/{parse-cli-arguments-helpers.js → cli/parse-arguments-helpers.js} +18 -11
  13. package/lib/{parse-cli-arguments.js → cli/parse-arguments.js} +12 -12
  14. package/lib/{parse-cli-query-pagination.js → cli/query-pagination.js} +2 -2
  15. package/lib/{render-cli-help.js → cli/render-help.js} +4 -4
  16. package/lib/{resolve-output-mode.js → cli/resolve-output-mode.js} +2 -2
  17. package/lib/cli/test-helpers.js +30 -0
  18. package/lib/config/defaults.d.ts +10 -0
  19. package/lib/config/defaults.js +80 -0
  20. package/lib/config/load-patram-config.d.ts +76 -0
  21. package/lib/config/load-patram-config.js +315 -0
  22. package/lib/config/load-patram-config.types.d.ts +45 -0
  23. package/lib/{patram-config.d.ts → config/patram-config.d.ts} +31 -31
  24. package/lib/{patram-config.js → config/patram-config.js} +3 -3
  25. package/lib/{patram-config.types.d.ts → config/patram-config.types.d.ts} +1 -1
  26. package/lib/{resolve-patram-graph-config.d.ts → config/resolve-patram-graph-config.d.ts} +2 -2
  27. package/lib/{resolve-patram-graph-config.js → config/resolve-patram-graph-config.js} +3 -3
  28. package/lib/{load-patram-config.d.ts → config/schema.d.ts} +147 -191
  29. package/lib/config/schema.js +324 -0
  30. package/lib/{source-file-defaults.d.ts → config/source-file-defaults.d.ts} +0 -1
  31. package/lib/{source-file-defaults.js → config/source-file-defaults.js} +1 -1
  32. package/lib/config/validation.d.ts +27 -0
  33. package/lib/config/validation.js +615 -0
  34. package/lib/directive-validation-test-helpers.js +1 -1
  35. package/lib/{build-graph-identity.d.ts → graph/build-graph-identity.d.ts} +2 -2
  36. package/lib/{build-graph-identity.js → graph/build-graph-identity.js} +1 -1
  37. package/lib/{build-graph.d.ts → graph/build-graph.d.ts} +3 -3
  38. package/lib/{build-graph.js → graph/build-graph.js} +17 -13
  39. package/lib/{build-graph.types.d.ts → graph/build-graph.types.d.ts} +1 -1
  40. package/lib/graph/check-directive-metadata.d.ts +23 -0
  41. package/lib/{check-directive-metadata.js → graph/check-directive-metadata.js} +7 -7
  42. package/lib/graph/check-directive-path-target.d.ts +32 -0
  43. package/lib/{check-directive-path-target.js → graph/check-directive-path-target.js} +4 -4
  44. package/lib/graph/check-directive-value.d.ts +19 -0
  45. package/lib/{check-directive-value.js → graph/check-directive-value.js} +3 -3
  46. package/lib/graph/check-graph.d.ts +29 -0
  47. package/lib/{check-graph.js → graph/check-graph.js} +6 -6
  48. package/lib/graph/directive-diagnostics.d.ts +20 -0
  49. package/lib/{directive-diagnostics.js → graph/directive-diagnostics.js} +2 -2
  50. package/lib/graph/directive-type-rules.d.ts +18 -0
  51. package/lib/{directive-type-rules.js → graph/directive-type-rules.js} +3 -3
  52. package/lib/{document-node-identity.d.ts → graph/document-node-identity.d.ts} +2 -2
  53. package/lib/{document-node-identity.js → graph/document-node-identity.js} +2 -2
  54. package/lib/graph/inspect-reverse-references.d.ts +22 -0
  55. package/lib/graph/inspect-reverse-references.js +184 -0
  56. package/lib/{load-project-graph.d.ts → graph/load-project-graph.d.ts} +10 -10
  57. package/lib/{load-project-graph.js → graph/load-project-graph.js} +12 -12
  58. package/lib/{parse-where-clause.types.d.ts → graph/parse-where-clause.types.d.ts} +1 -1
  59. package/lib/{query-graph.d.ts → graph/query/execute.d.ts} +11 -11
  60. package/lib/{query-graph.js → graph/query/execute.js} +12 -12
  61. package/lib/{query-inspection.d.ts → graph/query/inspect.d.ts} +10 -8
  62. package/lib/{query-inspection.js → graph/query/inspect.js} +16 -17
  63. package/lib/{parse-where-clause.d.ts → graph/query/parse.d.ts} +6 -6
  64. package/lib/{parse-where-clause.js → graph/query/parse.js} +2 -2
  65. package/lib/graph/query/resolve.d.ts +30 -0
  66. package/lib/{resolve-where-clause.js → graph/query/resolve.js} +1 -1
  67. package/lib/graph/reverse-reference-test-helpers.d.ts +55 -0
  68. package/lib/graph/reverse-reference-test-helpers.js +76 -0
  69. package/lib/{command-output.js → output/command-output.js} +6 -5
  70. package/lib/{derived-summary.js → output/derived-summary.js} +7 -7
  71. package/lib/output/layout-incoming-references.js +105 -0
  72. package/lib/output/layout-incoming-summary-lines.js +16 -0
  73. package/lib/{layout-stored-queries.js → output/layout-stored-queries.js} +9 -9
  74. package/lib/{list-queries.js → output/list-queries.js} +1 -1
  75. package/lib/{render-check-output.js → output/render-check-output.js} +1 -1
  76. package/lib/{render-field-discovery.js → output/render-field-discovery.js} +3 -3
  77. package/lib/output/render-output-view.js +56 -0
  78. package/lib/{render-json-output.js → output/renderers/json.js} +92 -63
  79. package/lib/{render-plain-output.js → output/renderers/plain.js} +62 -7
  80. package/lib/{render-rich-output.js → output/renderers/rich.js} +69 -8
  81. package/lib/{resolve-check-target.js → output/resolve-check-target.js} +1 -1
  82. package/lib/{render-rich-source.js → output/rich-source/render.js} +6 -6
  83. package/lib/{show-document.js → output/show-document.js} +54 -16
  84. package/lib/{render-output-view.js → output/view-model/index.js} +56 -47
  85. package/lib/{write-paged-output.js → output/write-paged-output.js} +9 -5
  86. package/lib/{claim-helpers.d.ts → parse/claim-helpers.d.ts} +2 -2
  87. package/lib/{parse-jsdoc-claims.d.ts → parse/jsdoc/parse-jsdoc-claims.d.ts} +2 -2
  88. package/lib/{parse-jsdoc-claims.js → parse/jsdoc/parse-jsdoc-claims.js} +9 -9
  89. package/lib/{parse-jsdoc-prose.d.ts → parse/jsdoc/parse-jsdoc-prose.d.ts} +1 -1
  90. package/lib/{parse-jsdoc-prose.js → parse/jsdoc/parse-jsdoc-prose.js} +1 -1
  91. package/lib/{parse-markdown-claims.d.ts → parse/markdown/parse-markdown-claims.d.ts} +3 -3
  92. package/lib/{parse-markdown-claims.js → parse/markdown/parse-markdown-claims.js} +8 -8
  93. package/lib/{parse-markdown-directives.d.ts → parse/markdown/parse-markdown-directives.d.ts} +2 -2
  94. package/lib/{parse-markdown-directives.js → parse/markdown/parse-markdown-directives.js} +3 -3
  95. package/lib/{parse-claims.d.ts → parse/parse-claims.d.ts} +4 -13
  96. package/lib/{parse-claims.js → parse/parse-claims.js} +18 -26
  97. package/lib/{parse-claims.types.d.ts → parse/parse-claims.types.d.ts} +1 -1
  98. package/lib/{tagged-fenced-block-error.d.ts → parse/tagged-fenced/tagged-fenced-block-error.d.ts} +2 -2
  99. package/lib/{tagged-fenced-block-parser.d.ts → parse/tagged-fenced/tagged-fenced-block-parser.d.ts} +3 -3
  100. package/lib/{tagged-fenced-blocks.d.ts → parse/tagged-fenced/tagged-fenced-blocks.d.ts} +7 -7
  101. package/lib/{tagged-fenced-blocks.js → parse/tagged-fenced/tagged-fenced-blocks.js} +3 -3
  102. package/lib/{parse-yaml-claims.d.ts → parse/yaml/parse-yaml-claims.d.ts} +4 -4
  103. package/lib/{parse-yaml-claims.js → parse/yaml/parse-yaml-claims.js} +22 -13
  104. package/lib/patram.d.ts +29 -28
  105. package/lib/patram.js +5 -6
  106. package/lib/{discover-fields.js → scan/discover-fields.js} +9 -8
  107. package/lib/scan/list-repo-files.d.ts +16 -0
  108. package/lib/{list-source-files.js → scan/list-repo-files.js} +2 -35
  109. package/lib/{list-source-files.d.ts → scan/list-source-files.d.ts} +4 -11
  110. package/lib/scan/list-source-files.js +45 -0
  111. package/package.json +8 -7
  112. package/lib/build-graph.types.ts +0 -27
  113. package/lib/discover-fields.types.ts +0 -52
  114. package/lib/load-patram-config.js +0 -1215
  115. package/lib/load-patram-config.types.d.ts +0 -45
  116. package/lib/load-patram-config.types.ts +0 -56
  117. package/lib/output-view.types.d.ts +0 -80
  118. package/lib/output-view.types.ts +0 -96
  119. package/lib/overlay-graph.d.ts +0 -43
  120. package/lib/overlay-graph.js +0 -191
  121. package/lib/parse-claims.types.ts +0 -41
  122. package/lib/parse-cli-arguments.types.ts +0 -69
  123. package/lib/parse-where-clause.types.ts +0 -87
  124. package/lib/patram-cli.js +0 -528
  125. package/lib/patram-config.types.ts +0 -22
  126. package/lib/tagged-fenced-blocks.types.ts +0 -38
  127. /package/lib/{format-derived-summary-row.js → output/format-derived-summary-row.js} +0 -0
  128. /package/lib/{format-node-header.js → output/format-node-header.js} +0 -0
  129. /package/lib/{format-output-item-block.js → output/format-output-item-block.js} +0 -0
  130. /package/lib/{format-output-metadata.js → output/format-output-metadata.js} +0 -0
  131. /package/lib/{claim-helpers.js → parse/claim-helpers.js} +0 -0
  132. /package/lib/{parse-jsdoc-blocks.d.ts → parse/jsdoc/parse-jsdoc-blocks.d.ts} +0 -0
  133. /package/lib/{parse-jsdoc-blocks.js → parse/jsdoc/parse-jsdoc-blocks.js} +0 -0
  134. /package/lib/{tagged-fenced-block-error.js → parse/tagged-fenced/tagged-fenced-block-error.js} +0 -0
  135. /package/lib/{tagged-fenced-block-markdown.d.ts → parse/tagged-fenced/tagged-fenced-block-markdown.d.ts} +0 -0
  136. /package/lib/{tagged-fenced-block-markdown.js → parse/tagged-fenced/tagged-fenced-block-markdown.js} +0 -0
  137. /package/lib/{tagged-fenced-block-metadata.d.ts → parse/tagged-fenced/tagged-fenced-block-metadata.d.ts} +0 -0
  138. /package/lib/{tagged-fenced-block-metadata.js → parse/tagged-fenced/tagged-fenced-block-metadata.js} +0 -0
  139. /package/lib/{tagged-fenced-block-parser.js → parse/tagged-fenced/tagged-fenced-block-parser.js} +0 -0
  140. /package/lib/{tagged-fenced-blocks.types.d.ts → parse/tagged-fenced/tagged-fenced-blocks.types.d.ts} +0 -0
@@ -32,7 +32,7 @@ export function parseYamlDirectiveFields(parse_input: {
32
32
  diagnostics: PatramDiagnostic[];
33
33
  directive_fields: PatramClaimFields[];
34
34
  };
35
- import type { ParseClaimsInput } from './parse-claims.types.ts';
36
- import type { ParseSourceFileResult } from './parse-claims.types.ts';
37
- import type { PatramDiagnostic } from './load-patram-config.types.ts';
38
- import type { PatramClaimFields } from './parse-claims.types.ts';
35
+ import type { ParseClaimsInput } from '../parse-claims.types.d.ts';
36
+ import type { ParseSourceFileResult } from '../parse-claims.types.d.ts';
37
+ import type { PatramDiagnostic } from '../../config/load-patram-config.types.d.ts';
38
+ import type { PatramClaimFields } from '../parse-claims.types.d.ts';
@@ -1,14 +1,14 @@
1
1
  /** @import * as yaml from 'yaml'; */
2
2
  /* eslint-disable max-lines */
3
3
  /**
4
- * @import { PatramDiagnostic } from './load-patram-config.types.ts';
5
- * @import { ParseClaimsInput, ParseSourceFileResult, PatramClaimFields } from './parse-claims.types.ts';
4
+ * @import { PatramDiagnostic } from '../../config/load-patram-config.types.ts';
5
+ * @import { ParseClaimsInput, ParseSourceFileResult, PatramClaimFields } from '../parse-claims.types.ts';
6
6
  */
7
7
 
8
8
  import { isMap, isScalar, isSeq, LineCounter, parseAllDocuments } from 'yaml';
9
9
 
10
- import { createClaim, getFileExtension } from './claim-helpers.js';
11
- import { YAML_SOURCE_FILE_EXTENSIONS } from './source-file-defaults.js';
10
+ import { createClaim, getFileExtension } from '../claim-helpers.js';
11
+ import { YAML_SOURCE_FILE_EXTENSIONS } from '../../config/source-file-defaults.js';
12
12
 
13
13
  /**
14
14
  * YAML claim parsing.
@@ -18,11 +18,11 @@ import { YAML_SOURCE_FILE_EXTENSIONS } from './source-file-defaults.js';
18
18
  *
19
19
  * Kind: parse
20
20
  * Status: active
21
- * Tracked in: ../docs/plans/v0/yaml-source-and-front-matter.md
22
- * Decided by: ../docs/decisions/yaml-source-and-front-matter.md
21
+ * Tracked in: ../../../docs/plans/v0/yaml-source-and-front-matter.md
22
+ * Decided by: ../../../docs/decisions/yaml-source-and-front-matter.md
23
23
  * @patram
24
- * @see {@link ./parse-claims.js}
25
- * @see {@link ./parse-markdown-directives.js}
24
+ * @see {@link ../parse-claims.js}
25
+ * @see {@link ../markdown/parse-markdown-directives.js}
26
26
  */
27
27
 
28
28
  const YAML_EXTENSIONS = new Set(YAML_SOURCE_FILE_EXTENSIONS);
@@ -107,7 +107,7 @@ export function parseYamlDirectiveFields(parse_input) {
107
107
  * file_path: string,
108
108
  * start_line: number,
109
109
  * }} parse_input
110
- * @param {any[]} yaml_documents
110
+ * @param {yaml.Document.Parsed[]} yaml_documents
111
111
  * @param {LineCounter} line_counter
112
112
  * @returns {{
113
113
  success: true,
@@ -221,12 +221,13 @@ function collectDirectiveFields(parse_input, yaml_map, line_counter) {
221
221
  * markdown_style?: 'front_matter',
222
222
  * multi_value_directive_names?: ReadonlySet<string>,
223
223
  * }} parse_input
224
- * @param {any} yaml_pair
224
+ * @param {yaml.Pair<unknown, unknown>} yaml_pair
225
225
  * @param {LineCounter} line_counter
226
226
  * @returns {PatramClaimFields[]}
227
227
  */
228
228
  function createPairDirectiveFields(parse_input, yaml_pair, line_counter) {
229
229
  const directive_name = resolveDirectiveName(yaml_pair.key);
230
+ const key_node = isNodeWithOptionalRange(yaml_pair.key) ? yaml_pair.key : {};
230
231
 
231
232
  if (!directive_name || yaml_pair.value === null) {
232
233
  return [];
@@ -236,7 +237,7 @@ function createPairDirectiveFields(parse_input, yaml_pair, line_counter) {
236
237
  return createScalarDirectiveFields(
237
238
  parse_input,
238
239
  directive_name,
239
- yaml_pair.key,
240
+ key_node,
240
241
  yaml_pair.value.value,
241
242
  line_counter,
242
243
  );
@@ -303,7 +304,7 @@ function createScalarDirectiveFields(
303
304
  * }} parse_input
304
305
  * @param {string} directive_name
305
306
  * @param {unknown} yaml_value
306
- * @returns {boolean}
307
+ * @returns {yaml_value is yaml.YAMLSeq<yaml.Scalar<string | boolean | number>>}
307
308
  */
308
309
  function shouldCollectSequence(parse_input, directive_name, yaml_value) {
309
310
  return (
@@ -379,7 +380,15 @@ function normalizeScalarValue(scalar_value) {
379
380
 
380
381
  /**
381
382
  * @param {unknown} yaml_node
382
- * @returns {boolean}
383
+ * @returns {yaml_node is { range?: [number, number, number] }}
384
+ */
385
+ function isNodeWithOptionalRange(yaml_node) {
386
+ return typeof yaml_node === 'object' && yaml_node !== null;
387
+ }
388
+
389
+ /**
390
+ * @param {unknown} yaml_node
391
+ * @returns {yaml_node is yaml.Scalar<string | boolean | number>}
383
392
  */
384
393
  function isNonNullScalarNode(yaml_node) {
385
394
  return isScalar(yaml_node) && normalizeScalarValue(yaml_node.value) !== null;
package/lib/patram.d.ts CHANGED
@@ -3,52 +3,53 @@ export {
3
3
  loadTaggedFencedBlocks,
4
4
  selectTaggedBlock,
5
5
  selectTaggedBlocks,
6
- } from './tagged-fenced-blocks.js';
6
+ } from './parse/tagged-fenced/tagged-fenced-blocks.js';
7
7
 
8
- export { parseWhereClause } from './parse-where-clause.js';
9
- export { getQuerySemanticDiagnostics } from './query-inspection.js';
10
- export { loadProjectGraph } from './load-project-graph.js';
11
- export { overlayGraph } from './overlay-graph.js';
12
- export { queryGraph } from './query-graph.js';
8
+ export { parseWhereClause } from './graph/query/parse.js';
9
+ export { getQuerySemanticDiagnostics } from './graph/query/inspect.js';
10
+ export { loadProjectGraph } from './graph/load-project-graph.js';
11
+ export { queryGraph } from './graph/query/execute.js';
13
12
 
14
- export type PatramGraphNode = import('./build-graph.types.ts').GraphNode;
15
- export type PatramGraphEdge = import('./build-graph.types.ts').GraphEdge;
13
+ export type PatramGraphNode =
14
+ import('./graph/build-graph.types.d.ts').GraphNode;
15
+ export type PatramGraphEdge =
16
+ import('./graph/build-graph.types.d.ts').GraphEdge;
16
17
  export type PatramBuildGraphResult =
17
- import('./build-graph.types.ts').BuildGraphResult;
18
+ import('./graph/build-graph.types.d.ts').BuildGraphResult;
18
19
  export type PatramDiagnostic =
19
- import('./load-patram-config.types.ts').PatramDiagnostic;
20
+ import('./config/load-patram-config.types.d.ts').PatramDiagnostic;
20
21
  export type PatramRepoConfig =
21
- import('./load-patram-config.types.ts').PatramRepoConfig;
22
+ import('./config/load-patram-config.types.d.ts').PatramRepoConfig;
22
23
  export type PatramParsedFieldName =
23
- import('./parse-where-clause.types.ts').ParsedFieldName;
24
+ import('./graph/parse-where-clause.types.d.ts').ParsedFieldName;
24
25
  export type PatramParsedFieldTerm =
25
- import('./parse-where-clause.types.ts').ParsedFieldTerm;
26
+ import('./graph/parse-where-clause.types.d.ts').ParsedFieldTerm;
26
27
  export type PatramParsedFieldSetTerm =
27
- import('./parse-where-clause.types.ts').ParsedFieldSetTerm;
28
+ import('./graph/parse-where-clause.types.d.ts').ParsedFieldSetTerm;
28
29
  export type PatramParsedTraversalTerm =
29
- import('./parse-where-clause.types.ts').ParsedTraversalTerm;
30
+ import('./graph/parse-where-clause.types.d.ts').ParsedTraversalTerm;
30
31
  export type PatramParsedRelationTerm =
31
- import('./parse-where-clause.types.ts').ParsedRelationTerm;
32
+ import('./graph/parse-where-clause.types.d.ts').ParsedRelationTerm;
32
33
  export type PatramParsedRelationTargetTerm =
33
- import('./parse-where-clause.types.ts').ParsedRelationTargetTerm;
34
+ import('./graph/parse-where-clause.types.d.ts').ParsedRelationTargetTerm;
34
35
  export type PatramParsedAggregateComparison =
35
- import('./parse-where-clause.types.ts').ParsedAggregateComparison;
36
+ import('./graph/parse-where-clause.types.d.ts').ParsedAggregateComparison;
36
37
  export type PatramParsedAggregateName =
37
- import('./parse-where-clause.types.ts').ParsedAggregateName;
38
+ import('./graph/parse-where-clause.types.d.ts').ParsedAggregateName;
38
39
  export type PatramParsedAggregateTerm =
39
- import('./parse-where-clause.types.ts').ParsedAggregateTerm;
40
+ import('./graph/parse-where-clause.types.d.ts').ParsedAggregateTerm;
40
41
  export type PatramParsedTermExpression =
41
- import('./parse-where-clause.types.ts').ParsedTermExpression;
42
+ import('./graph/parse-where-clause.types.d.ts').ParsedTermExpression;
42
43
  export type PatramParsedNotExpression =
43
- import('./parse-where-clause.types.ts').ParsedNotExpression;
44
+ import('./graph/parse-where-clause.types.d.ts').ParsedNotExpression;
44
45
  export type PatramParsedBooleanExpression =
45
- import('./parse-where-clause.types.ts').ParsedBooleanExpression;
46
+ import('./graph/parse-where-clause.types.d.ts').ParsedBooleanExpression;
46
47
  export type PatramParsedTerm =
47
- import('./parse-where-clause.types.ts').ParsedTerm;
48
+ import('./graph/parse-where-clause.types.d.ts').ParsedTerm;
48
49
  export type PatramParsedExpression =
49
- import('./parse-where-clause.types.ts').ParsedExpression;
50
+ import('./graph/parse-where-clause.types.d.ts').ParsedExpression;
50
51
  export type PatramParseWhereClauseResult =
51
- import('./parse-where-clause.types.ts').ParseWhereClauseResult;
52
+ import('./graph/parse-where-clause.types.d.ts').ParseWhereClauseResult;
52
53
  export type PatramQuerySource =
53
54
  | {
54
55
  kind: 'ad_hoc';
@@ -59,8 +60,8 @@ export type PatramQuerySource =
59
60
  };
60
61
 
61
62
  export interface PatramProjectGraphResult {
62
- claims: import('./parse-claims.types.ts').PatramClaim[];
63
- config: import('./load-patram-config.types.ts').PatramRepoConfig;
63
+ claims: import('./parse/parse-claims.types.d.ts').PatramClaim[];
64
+ config: import('./config/load-patram-config.types.d.ts').PatramRepoConfig;
64
65
  diagnostics: PatramDiagnostic[];
65
66
  graph: PatramBuildGraphResult;
66
67
  source_file_paths: string[];
package/lib/patram.js CHANGED
@@ -3,10 +3,9 @@ export {
3
3
  loadTaggedFencedBlocks,
4
4
  selectTaggedBlock,
5
5
  selectTaggedBlocks,
6
- } from './tagged-fenced-blocks.js';
6
+ } from './parse/tagged-fenced/tagged-fenced-blocks.js';
7
7
 
8
- export { parseWhereClause } from './parse-where-clause.js';
9
- export { getQuerySemanticDiagnostics } from './query-inspection.js';
10
- export { loadProjectGraph } from './load-project-graph.js';
11
- export { overlayGraph } from './overlay-graph.js';
12
- export { queryGraph } from './query-graph.js';
8
+ export { parseWhereClause } from './graph/query/parse.js';
9
+ export { getQuerySemanticDiagnostics } from './graph/query/inspect.js';
10
+ export { loadProjectGraph } from './graph/load-project-graph.js';
11
+ export { queryGraph } from './graph/query/execute.js';
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-lines, max-lines-per-function */
2
2
  /**
3
- * @import { ClaimOrigin, PatramClaim } from './parse-claims.types.ts';
3
+ * @import { ClaimOrigin, PatramClaim } from '../parse/parse-claims.types.ts';
4
4
  * @import {
5
5
  * DiscoveredFieldMultiplicity,
6
6
  * DiscoveredFieldTypeName,
@@ -17,9 +17,9 @@ import { readFile } from 'node:fs/promises';
17
17
  import process from 'node:process';
18
18
  import { resolve } from 'node:path';
19
19
 
20
- import { DEFAULT_INCLUDE_PATTERNS } from './source-file-defaults.js';
20
+ import { DEFAULT_INCLUDE_PATTERNS } from '../config/source-file-defaults.js';
21
21
  import { listSourceFiles } from './list-source-files.js';
22
- import { parseSourceFile } from './parse-claims.js';
22
+ import { parseSourceFile } from '../parse/parse-claims.js';
23
23
 
24
24
  /**
25
25
  * Field discovery from source claims.
@@ -29,10 +29,10 @@ import { parseSourceFile } from './parse-claims.js';
29
29
  *
30
30
  * Kind: discovery
31
31
  * Status: active
32
- * Tracked in: ../docs/plans/v1/field-model-redesign.md
33
- * Decided by: ../docs/decisions/field-discovery-workflow.md
32
+ * Tracked in: ../../docs/plans/v1/field-model-redesign.md
33
+ * Decided by: ../../docs/decisions/field-discovery-workflow.md
34
34
  * @patram
35
- * @see {@link ./render-field-discovery.js}
35
+ * @see {@link ../output/render-field-discovery.js}
36
36
  */
37
37
 
38
38
  const TYPE_NAME_ORDER = /** @type {const} */ ([
@@ -132,6 +132,7 @@ export async function discoverFields(
132
132
  /** @type {Map<string, FieldBucket>} */
133
133
  const field_buckets = field_observations.reduce(
134
134
  (buckets, field_observation) => {
135
+ /** @type {FieldBucket} */
135
136
  const bucket = buckets.get(field_observation.name) ?? {
136
137
  name: field_observation.name,
137
138
  observations: [],
@@ -141,7 +142,7 @@ export async function discoverFields(
141
142
  buckets.set(field_observation.name, bucket);
142
143
  return buckets;
143
144
  },
144
- new Map(),
145
+ /** @type {Map<string, FieldBucket>} */ (new Map()),
145
146
  );
146
147
  const fields = [...field_buckets.values()]
147
148
  .map(buildFieldSuggestion)
@@ -236,7 +237,7 @@ function inferFieldMultiplicity(observations) {
236
237
  }
237
238
 
238
239
  return values;
239
- }, new Map());
240
+ }, /** @type {Map<string, Set<string>>} */ (new Map()));
240
241
  const repeated_identical_documents = [...values_by_document.values()].reduce(
241
242
  (count, values) => {
242
243
  if (values.size > 1) {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * List repo files available for broken-link validation.
3
+ *
4
+ * @param {string} [project_directory]
5
+ * @returns {Promise<string[]>}
6
+ */
7
+ export function listRepoFiles(project_directory?: string): Promise<string[]>;
8
+ /**
9
+ * @param {string[]} include_patterns
10
+ * @param {string} project_directory
11
+ * @param {{ dot?: boolean }} [options]
12
+ * @returns {Promise<string[]>}
13
+ */
14
+ export function listMatchingFiles(include_patterns: string[], project_directory: string, options?: {
15
+ dot?: boolean;
16
+ }): Promise<string[]>;
@@ -1,39 +1,6 @@
1
- import { globby } from 'globby';
2
1
  import process from 'node:process';
3
2
 
4
- /**
5
- * Source file scanning.
6
- *
7
- * Expands include globs into stable repo-relative file lists for indexing and
8
- * broken-link validation.
9
- *
10
- * Kind: scan
11
- * Status: active
12
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
13
- * Decided by: ../docs/decisions/source-scan.md
14
- * @patram
15
- * @see {@link ./load-project-graph.js}
16
- * @see {@link ../docs/decisions/source-scan.md}
17
- */
18
-
19
- /**
20
- * List source files matched by Patram include globs.
21
- *
22
- * @param {string[]} include_patterns
23
- * @param {string} [project_directory]
24
- * @returns {Promise<string[]>}
25
- */
26
- export async function listSourceFiles(
27
- include_patterns,
28
- project_directory = process.cwd(),
29
- ) {
30
- const source_file_paths = await listMatchingFiles(
31
- include_patterns,
32
- project_directory,
33
- );
34
-
35
- return [...new Set(source_file_paths)].sort(comparePaths);
36
- }
3
+ import { globby } from 'globby';
37
4
 
38
5
  /**
39
6
  * List repo files available for broken-link validation.
@@ -55,7 +22,7 @@ export async function listRepoFiles(project_directory = process.cwd()) {
55
22
  * @param {{ dot?: boolean }} [options]
56
23
  * @returns {Promise<string[]>}
57
24
  */
58
- async function listMatchingFiles(
25
+ export async function listMatchingFiles(
59
26
  include_patterns,
60
27
  project_directory,
61
28
  options = {},
@@ -6,11 +6,11 @@
6
6
  *
7
7
  * Kind: scan
8
8
  * Status: active
9
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
10
- * Decided by: ../docs/decisions/source-scan.md
9
+ * Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
10
+ * Decided by: ../../docs/decisions/source-scan.md
11
11
  * @patram
12
- * @see {@link ./load-project-graph.js}
13
- * @see {@link ../docs/decisions/source-scan.md}
12
+ * @see {@link ../graph/load-project-graph.js}
13
+ * @see {@link ../../docs/decisions/source-scan.md}
14
14
  */
15
15
  /**
16
16
  * List source files matched by Patram include globs.
@@ -20,10 +20,3 @@
20
20
  * @returns {Promise<string[]>}
21
21
  */
22
22
  export function listSourceFiles(include_patterns: string[], project_directory?: string): Promise<string[]>;
23
- /**
24
- * List repo files available for broken-link validation.
25
- *
26
- * @param {string} [project_directory]
27
- * @returns {Promise<string[]>}
28
- */
29
- export function listRepoFiles(project_directory?: string): Promise<string[]>;
@@ -0,0 +1,45 @@
1
+ import process from 'node:process';
2
+
3
+ import { listMatchingFiles } from './list-repo-files.js';
4
+ /**
5
+ * Source file scanning.
6
+ *
7
+ * Expands include globs into stable repo-relative file lists for indexing and
8
+ * broken-link validation.
9
+ *
10
+ * Kind: scan
11
+ * Status: active
12
+ * Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
13
+ * Decided by: ../../docs/decisions/source-scan.md
14
+ * @patram
15
+ * @see {@link ../graph/load-project-graph.js}
16
+ * @see {@link ../../docs/decisions/source-scan.md}
17
+ */
18
+
19
+ /**
20
+ * List source files matched by Patram include globs.
21
+ *
22
+ * @param {string[]} include_patterns
23
+ * @param {string} [project_directory]
24
+ * @returns {Promise<string[]>}
25
+ */
26
+ export async function listSourceFiles(
27
+ include_patterns,
28
+ project_directory = process.cwd(),
29
+ ) {
30
+ const source_file_paths = await listMatchingFiles(
31
+ include_patterns,
32
+ project_directory,
33
+ );
34
+
35
+ return [...new Set(source_file_paths)].sort(comparePaths);
36
+ }
37
+
38
+ /**
39
+ * @param {string} left_path
40
+ * @param {string} right_path
41
+ * @returns {number}
42
+ */
43
+ function comparePaths(left_path, right_path) {
44
+ return left_path.localeCompare(right_path, 'en');
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patram",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "main": "./lib/patram.js",
6
6
  "types": "./lib/patram.d.ts",
@@ -15,7 +15,6 @@
15
15
  "bin/patram.js",
16
16
  "lib/**/*.d.ts",
17
17
  "lib/**/*.js",
18
- "lib/**/*.ts",
19
18
  "!bin/**/*.test.d.ts",
20
19
  "!bin/**/*.test-helpers.d.ts",
21
20
  "!bin/**/*.test.js",
@@ -38,9 +37,11 @@
38
37
  },
39
38
  "license": "MIT",
40
39
  "scripts": {
41
- "all": "npm run check:lint && npm run check:format && npm run check:types && npm run check:patram && npm run test:coverage && npm run check:dupes",
40
+ "all": "npm run check:lint && npm run check:format && npm run check:types && npm run check:patram && npm run check:knip && npm run check:knip:production && npm run test:coverage && npm run check:dupes",
42
41
  "check:dupes": "jscpd --min-tokens 100 --min-lines 6 --mode mild --threshold 0 --reporters console --gitignore .",
43
42
  "check:format": "prettier --check .",
43
+ "check:knip": "knip",
44
+ "check:knip:production": "knip --production --include exports",
44
45
  "check:lint": "eslint .",
45
46
  "check:patram": "./bin/patram.js check",
46
47
  "check:staged": "lint-staged",
@@ -62,7 +63,6 @@
62
63
  ]
63
64
  },
64
65
  "dependencies": {
65
- "@shikijs/cli": "^4.0.2",
66
66
  "@shikijs/vscode-textmate": "^10.0.2",
67
67
  "ansis": "^4.2.0",
68
68
  "beautiful-mermaid": "^1.1.3",
@@ -77,16 +77,17 @@
77
77
  "devDependencies": {
78
78
  "@eslint/js": "^10.0.1",
79
79
  "@types/node": "^24.12.0",
80
- "@vitest/coverage-v8": "^4.1.1",
80
+ "@vitest/coverage-istanbul": "^4.1.2",
81
81
  "eslint": "^10.1.0",
82
82
  "eslint-plugin-jsdoc": "^62.8.0",
83
83
  "globals": "^17.4.0",
84
84
  "husky": "^9.1.7",
85
85
  "jscpd": "^4.0.8",
86
+ "knip": "^6.1.0",
86
87
  "lint-staged": "^16.2.6",
87
88
  "prettier": "^3.5.3",
88
- "slice-ansi": "^8.0.0",
89
- "typescript": "^6.0.2",
89
+ "typescript": "^5.9.3",
90
+ "typescript-eslint": "^8.57.2",
90
91
  "vitest": "^4.1.1"
91
92
  }
92
93
  }
@@ -1,27 +0,0 @@
1
- import type { ClaimOrigin } from './parse-claims.types.ts';
2
-
3
- export interface GraphNode {
4
- $class?: string;
5
- $id?: string;
6
- $path?: string;
7
- id: string;
8
- kind?: string;
9
- key?: string;
10
- path?: string;
11
- title?: string;
12
- [field: string]: string | string[] | undefined;
13
- }
14
-
15
- export interface GraphEdge {
16
- from: string;
17
- id: string;
18
- origin: ClaimOrigin;
19
- relation: string;
20
- to: string;
21
- }
22
-
23
- export interface BuildGraphResult {
24
- document_node_ids?: Record<string, string>;
25
- edges: GraphEdge[];
26
- nodes: Record<string, GraphNode>;
27
- }
@@ -1,52 +0,0 @@
1
- export type DiscoveredFieldTypeName =
2
- | 'date'
3
- | 'date_time'
4
- | 'enum'
5
- | 'glob'
6
- | 'integer'
7
- | 'path'
8
- | 'string';
9
-
10
- export type DiscoveredFieldMultiplicity = 'multiple' | 'single';
11
-
12
- export interface FieldDiscoveryEvidenceReference {
13
- column: number;
14
- line: number;
15
- path: string;
16
- value: string;
17
- }
18
-
19
- export interface FieldDiscoveryClassUsage {
20
- classes: string[];
21
- }
22
-
23
- export interface FieldDiscoveryTypeSuggestion {
24
- confidence: number;
25
- name: DiscoveredFieldTypeName;
26
- }
27
-
28
- export interface FieldDiscoveryMultiplicitySuggestion {
29
- confidence: number;
30
- name: DiscoveredFieldMultiplicity;
31
- }
32
-
33
- export interface FieldDiscoverySuggestion {
34
- confidence: number;
35
- conflicting_evidence: FieldDiscoveryEvidenceReference[];
36
- evidence_references: FieldDiscoveryEvidenceReference[];
37
- likely_class_usage: FieldDiscoveryClassUsage;
38
- likely_multiplicity: FieldDiscoveryMultiplicitySuggestion;
39
- likely_type: FieldDiscoveryTypeSuggestion;
40
- name: string;
41
- }
42
-
43
- export interface FieldDiscoverySummary {
44
- claim_count: number;
45
- count: number;
46
- source_file_count: number;
47
- }
48
-
49
- export interface FieldDiscoveryResult {
50
- fields: FieldDiscoverySuggestion[];
51
- summary: FieldDiscoverySummary;
52
- }