patram 0.11.0 → 0.12.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 (110) hide show
  1. package/bin/patram.js +4 -4
  2. package/lib/cli/commands/fields.js +0 -4
  3. package/lib/cli/commands/queries.js +10 -20
  4. package/lib/cli/commands/query.js +1 -8
  5. package/lib/cli/commands/refs.js +3 -10
  6. package/lib/cli/commands/show.js +1 -8
  7. package/lib/cli/help-metadata.js +71 -106
  8. package/lib/cli/main.js +10 -10
  9. package/lib/cli/parse-arguments-helpers.js +165 -59
  10. package/lib/cli/parse-arguments.js +4 -4
  11. package/lib/cli/render-help.js +2 -2
  12. package/lib/config/defaults.js +33 -25
  13. package/lib/config/load-patram-config.d.ts +8 -33
  14. package/lib/config/load-patram-config.js +9 -33
  15. package/lib/config/load-patram-config.types.d.ts +3 -40
  16. package/lib/config/manage-stored-queries-helpers.d.ts +4 -4
  17. package/lib/config/manage-stored-queries-helpers.js +91 -33
  18. package/lib/config/manage-stored-queries.d.ts +4 -4
  19. package/lib/config/manage-stored-queries.js +11 -5
  20. package/lib/config/patram-config.d.ts +34 -34
  21. package/lib/config/patram-config.js +3 -3
  22. package/lib/config/patram-config.types.d.ts +5 -11
  23. package/lib/config/resolve-patram-graph-config.d.ts +5 -1
  24. package/lib/config/resolve-patram-graph-config.js +3 -119
  25. package/lib/config/schema.d.ts +158 -269
  26. package/lib/config/schema.js +72 -210
  27. package/lib/config/validate-patram-config-value.js +6 -31
  28. package/lib/config/validation.d.ts +2 -12
  29. package/lib/config/validation.js +125 -483
  30. package/lib/find-close-match.d.ts +4 -1
  31. package/lib/graph/build-graph-identity.d.ts +1 -32
  32. package/lib/graph/build-graph-identity.js +5 -269
  33. package/lib/graph/build-graph.d.ts +13 -4
  34. package/lib/graph/build-graph.js +347 -488
  35. package/lib/graph/build-graph.types.d.ts +8 -9
  36. package/lib/graph/check-directive-metadata-helpers.d.ts +30 -0
  37. package/lib/graph/check-directive-metadata-helpers.js +126 -0
  38. package/lib/graph/check-directive-metadata.d.ts +8 -9
  39. package/lib/graph/check-directive-metadata.js +70 -561
  40. package/lib/graph/check-directive-path-target.d.ts +6 -13
  41. package/lib/graph/check-directive-path-target.js +26 -57
  42. package/lib/graph/check-directive-value.d.ts +1 -5
  43. package/lib/graph/check-directive-value.js +40 -180
  44. package/lib/graph/check-graph.d.ts +5 -5
  45. package/lib/graph/check-graph.js +8 -6
  46. package/lib/graph/document-node-identity.d.ts +23 -7
  47. package/lib/graph/document-node-identity.js +417 -160
  48. package/lib/graph/graph-node.d.ts +42 -0
  49. package/lib/graph/graph-node.js +83 -0
  50. package/lib/graph/inspect-reverse-references.js +16 -11
  51. package/lib/graph/load-project-graph.d.ts +7 -7
  52. package/lib/graph/load-project-graph.js +7 -7
  53. package/lib/graph/parse-where-clause.types.d.ts +3 -2
  54. package/lib/graph/query/cypher-reader.d.ts +59 -0
  55. package/lib/graph/query/cypher-reader.js +151 -0
  56. package/lib/graph/query/cypher-support.d.ts +79 -0
  57. package/lib/graph/query/cypher-support.js +213 -0
  58. package/lib/graph/query/cypher-tokenize.d.ts +13 -0
  59. package/lib/graph/query/cypher-tokenize.js +225 -0
  60. package/lib/graph/query/cypher.types.d.ts +43 -0
  61. package/lib/graph/query/execute.d.ts +7 -7
  62. package/lib/graph/query/execute.js +71 -33
  63. package/lib/graph/query/inspect.js +58 -24
  64. package/lib/graph/query/parse-cypher-patterns.d.ts +27 -0
  65. package/lib/graph/query/parse-cypher-patterns.js +382 -0
  66. package/lib/graph/query/parse-cypher.d.ts +7 -0
  67. package/lib/graph/query/parse-cypher.js +580 -0
  68. package/lib/graph/query/parse-query.d.ts +13 -0
  69. package/lib/graph/query/parse-query.js +97 -0
  70. package/lib/graph/query/resolve.js +77 -23
  71. package/lib/output/command-output.js +12 -5
  72. package/lib/output/compact-layout.js +221 -0
  73. package/lib/output/format-output-item-block.js +31 -1
  74. package/lib/output/format-output-metadata.js +16 -29
  75. package/lib/output/format-stored-query-block.js +95 -0
  76. package/lib/output/layout-incoming-references.js +101 -19
  77. package/lib/output/layout-stored-queries.js +23 -330
  78. package/lib/output/list-queries.js +1 -1
  79. package/lib/output/render-field-discovery.js +11 -2
  80. package/lib/output/render-output-view.js +9 -5
  81. package/lib/output/renderers/json.js +5 -26
  82. package/lib/output/renderers/plain.js +155 -35
  83. package/lib/output/renderers/rich.js +250 -36
  84. package/lib/output/resolved-link-layout.js +43 -0
  85. package/lib/output/rich-source/render.js +193 -35
  86. package/lib/output/show-document.js +25 -18
  87. package/lib/output/view-model/index.js +124 -103
  88. package/lib/parse/jsdoc/parse-jsdoc-blocks.js +1 -1
  89. package/lib/parse/jsdoc/parse-jsdoc-claims.js +12 -6
  90. package/lib/parse/markdown/parse-markdown-claims.js +99 -62
  91. package/lib/parse/markdown/parse-markdown-directives.d.ts +10 -6
  92. package/lib/parse/markdown/parse-markdown-directives.js +104 -18
  93. package/lib/parse/markdown/parse-markdown-prose.d.ts +27 -0
  94. package/lib/parse/markdown/parse-markdown-prose.js +243 -0
  95. package/lib/parse/parse-claims.d.ts +2 -6
  96. package/lib/parse/parse-claims.js +11 -53
  97. package/lib/parse/tagged-fenced/tagged-fenced-blocks.d.ts +4 -4
  98. package/lib/parse/tagged-fenced/tagged-fenced-blocks.js +4 -4
  99. package/lib/parse/yaml/parse-yaml-claims.js +4 -4
  100. package/lib/patram.d.ts +3 -5
  101. package/lib/patram.js +1 -1
  102. package/lib/scan/discover-fields.js +194 -55
  103. package/lib/scan/list-source-files.d.ts +4 -4
  104. package/lib/scan/list-source-files.js +4 -4
  105. package/package.json +1 -1
  106. package/lib/directive-validation-test-helpers.js +0 -87
  107. package/lib/graph/query/parse.d.ts +0 -75
  108. package/lib/graph/query/parse.js +0 -1064
  109. package/lib/output/derived-summary.js +0 -280
  110. package/lib/output/format-derived-summary-row.js +0 -9
@@ -1,14 +1,13 @@
1
1
  import type { ClaimOrigin } from '../parse/parse-claims.types.d.ts';
2
- export interface GraphNode {
3
- $class?: string;
4
- $id?: string;
5
- $path?: string;
2
+ export interface GraphNodeIdentity {
3
+ class_name: string;
6
4
  id: string;
7
- kind?: string;
8
- key?: string;
9
5
  path?: string;
10
- title?: string;
11
- [field: string]: string | string[] | undefined;
6
+ }
7
+ export interface GraphNode {
8
+ identity: GraphNodeIdentity;
9
+ key?: string;
10
+ metadata: Record<string, string | string[] | undefined>;
12
11
  }
13
12
  export interface GraphEdge {
14
13
  from: string;
@@ -18,7 +17,7 @@ export interface GraphEdge {
18
17
  to: string;
19
18
  }
20
19
  export interface BuildGraphResult {
21
- document_node_ids?: Record<string, string>;
20
+ document_path_ids?: Record<string, string>;
22
21
  edges: GraphEdge[];
23
22
  nodes: Record<string, GraphNode>;
24
23
  }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @param {PatramClaim[]} claims
3
+ * @returns {Map<string, PatramClaim[]>}
4
+ */
5
+ export function groupDirectiveClaimsByDocument(claims: PatramClaim[]): Map<string, PatramClaim[]>;
6
+ /**
7
+ * @param {PatramRepoConfig} repo_config
8
+ * @param {string} document_path
9
+ * @param {string} document_type
10
+ * @param {Map<string, number>} directive_counts
11
+ * @returns {PatramDiagnostic[]}
12
+ */
13
+ export function collectRequiredFieldDiagnostics(repo_config: PatramRepoConfig, document_path: string, document_type: string, directive_counts: Map<string, number>): PatramDiagnostic[];
14
+ /**
15
+ * @param {PatramRepoConfig} repo_config
16
+ * @param {string} document_path
17
+ * @param {string} document_type
18
+ * @returns {PatramDiagnostic[]}
19
+ */
20
+ export function collectTypePlacementDiagnostics(repo_config: PatramRepoConfig, document_path: string, document_type: string): PatramDiagnostic[];
21
+ /**
22
+ * @param {BuildGraphResult} graph
23
+ * @param {string} document_path
24
+ * @returns {string}
25
+ */
26
+ export function resolveDocumentType(graph: BuildGraphResult, document_path: string): string;
27
+ import type { PatramClaim } from '../parse/parse-claims.types.d.ts';
28
+ import type { PatramRepoConfig } from '../config/load-patram-config.types.d.ts';
29
+ import type { PatramDiagnostic } from '../config/load-patram-config.types.d.ts';
30
+ import type { BuildGraphResult } from './build-graph.types.d.ts';
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @import { BuildGraphResult } from './build-graph.types.ts';
3
+ * @import { PatramDiagnostic, PatramRepoConfig } from '../config/load-patram-config.types.ts';
4
+ * @import { PatramClaim } from '../parse/parse-claims.types.ts';
5
+ */
6
+
7
+ import { matchesGlob } from 'node:path';
8
+
9
+ import {
10
+ normalizeRepoRelativePath,
11
+ resolveDocumentNodeId,
12
+ } from './build-graph-identity.js';
13
+ import { createDocumentDiagnostic } from './directive-diagnostics.js';
14
+ import { getGraphNodeClassName } from './graph-node.js';
15
+
16
+ /**
17
+ * @param {PatramClaim[]} claims
18
+ * @returns {Map<string, PatramClaim[]>}
19
+ */
20
+ export function groupDirectiveClaimsByDocument(claims) {
21
+ /** @type {Map<string, PatramClaim[]>} */
22
+ const directive_claims_by_document = new Map();
23
+
24
+ for (const claim of claims) {
25
+ if (claim.type !== 'directive') {
26
+ continue;
27
+ }
28
+
29
+ const document_path = normalizeRepoRelativePath(claim.origin.path);
30
+ let document_claims = directive_claims_by_document.get(document_path);
31
+
32
+ if (!document_claims) {
33
+ document_claims = [];
34
+ directive_claims_by_document.set(document_path, document_claims);
35
+ }
36
+
37
+ document_claims.push(claim);
38
+ }
39
+
40
+ return directive_claims_by_document;
41
+ }
42
+
43
+ /**
44
+ * @param {PatramRepoConfig} repo_config
45
+ * @param {string} document_path
46
+ * @param {string} document_type
47
+ * @param {Map<string, number>} directive_counts
48
+ * @returns {PatramDiagnostic[]}
49
+ */
50
+ export function collectRequiredFieldDiagnostics(
51
+ repo_config,
52
+ document_path,
53
+ document_type,
54
+ directive_counts,
55
+ ) {
56
+ /** @type {PatramDiagnostic[]} */
57
+ const diagnostics = [];
58
+
59
+ for (const [field_name, field_definition] of Object.entries(
60
+ repo_config.fields ?? {},
61
+ )) {
62
+ if (!field_definition.required_on?.includes(document_type)) {
63
+ continue;
64
+ }
65
+
66
+ if ((directive_counts.get(field_name) ?? 0) > 0) {
67
+ continue;
68
+ }
69
+
70
+ diagnostics.push(
71
+ createDocumentDiagnostic(
72
+ document_path,
73
+ 'directive.missing_required_field',
74
+ `Type "${document_type}" requires directive "${field_name}".`,
75
+ ),
76
+ );
77
+ }
78
+
79
+ return diagnostics;
80
+ }
81
+
82
+ /**
83
+ * @param {PatramRepoConfig} repo_config
84
+ * @param {string} document_path
85
+ * @param {string} document_type
86
+ * @returns {PatramDiagnostic[]}
87
+ */
88
+ export function collectTypePlacementDiagnostics(
89
+ repo_config,
90
+ document_path,
91
+ document_type,
92
+ ) {
93
+ const type_definition = repo_config.types?.[document_type];
94
+
95
+ if (!type_definition?.in || document_type === 'document') {
96
+ return [];
97
+ }
98
+
99
+ const patterns = Array.isArray(type_definition.in)
100
+ ? type_definition.in
101
+ : [type_definition.in];
102
+
103
+ if (patterns.some((pattern) => matchesGlob(document_path, pattern))) {
104
+ return [];
105
+ }
106
+
107
+ return [
108
+ createDocumentDiagnostic(
109
+ document_path,
110
+ 'directive.invalid_type_placement',
111
+ `Type "${document_type}" must be placed under one of its configured "in" globs.`,
112
+ ),
113
+ ];
114
+ }
115
+
116
+ /**
117
+ * @param {BuildGraphResult} graph
118
+ * @param {string} document_path
119
+ * @returns {string}
120
+ */
121
+ export function resolveDocumentType(graph, document_path) {
122
+ const document_node =
123
+ graph.nodes[resolveDocumentNodeId(graph.document_path_ids, document_path)];
124
+
125
+ return getGraphNodeClassName(document_node) ?? 'document';
126
+ }
@@ -1,15 +1,14 @@
1
1
  /**
2
- * Directive and placement validation.
2
+ * Validate declared metadata fields and typed document placement.
3
3
  *
4
- * Kind: graph
5
- * Status: active
6
- * Tracked in: ../../docs/plans/v0/directive-type-validation.md
7
- * Decided by: ../../docs/decisions/directive-type-validation.md
8
- * @see {@link ../../docs/decisions/directive-type-validation.md}
4
+ * kind: graph
5
+ * status: active
6
+ * tracked_in: ../../docs/plans/v2/types-and-fields-config.md
7
+ * decided_by: ../../docs/decisions/types-and-fields-config.md
9
8
  * @patram
10
- * @see {@link ./check-graph.js}
11
- */
12
- /**
9
+ * @see {@link ./check-directive-value.js}
10
+ * @see {@link ../../docs/decisions/types-and-fields-config.md}
11
+ *
13
12
  * @param {BuildGraphResult} graph
14
13
  * @param {PatramRepoConfig} repo_config
15
14
  * @param {PatramClaim[]} claims