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
@@ -5,4 +5,7 @@
5
5
  * @param {readonly string[]} candidates
6
6
  * @returns {string | undefined}
7
7
  */
8
- export function findCloseMatch(input_text: string, candidates: readonly string[]): string | undefined;
8
+ export function findCloseMatch(
9
+ input_text: string,
10
+ candidates: readonly string[],
11
+ ): string | undefined;
@@ -1,32 +1,3 @@
1
- /**
2
- * Resolve the node key for one mapped claim.
3
- *
4
- * @param {{ field: string, key?: 'path' | 'value', class: string }} node_mapping
5
- * @param {PatramClaim} claim
6
- * @param {Map<string, string>} document_entity_keys
7
- * @returns {string}
8
- */
9
- export function resolveNodeKey(node_mapping: {
10
- field: string;
11
- key?: "path" | "value";
12
- class: string;
13
- }, claim: PatramClaim, document_entity_keys: Map<string, string>): string;
14
- /**
15
- * Resolve one edge target key and canonical path.
16
- *
17
- * @param {string} target_class
18
- * @param {'path' | 'value'} target_type
19
- * @param {PatramClaim} claim
20
- * @param {Map<string, string>} document_entity_keys
21
- * @param {Map<string, DocumentNodeReference>} document_node_references
22
- * @param {Set<string>} document_paths
23
- * @returns {{ class_name: string, key: string, path?: string }}
24
- */
25
- export function resolveTargetReference(target_class: string, target_type: "path" | "value", claim: PatramClaim, document_entity_keys: Map<string, string>, document_node_references: Map<string, DocumentNodeReference>, document_paths: Set<string>): {
26
- class_name: string;
27
- key: string;
28
- path?: string;
29
- };
30
1
  /**
31
2
  * Attach one canonical path to a graph node.
32
3
  *
@@ -34,7 +5,5 @@ export function resolveTargetReference(target_class: string, target_type: "path"
34
5
  * @param {string | undefined} source_path
35
6
  */
36
7
  export function setCanonicalPath(graph_node: GraphNode, source_path: string | undefined): void;
37
- import type { PatramClaim } from '../parse/parse-claims.types.d.ts';
38
- import type { DocumentNodeReference } from './document-node-identity.js';
39
8
  import type { GraphNode } from './build-graph.types.d.ts';
40
- export { collectDocumentEntityKeys, collectDocumentNodeReferences, normalizeRepoRelativePath, resolveDocumentNodeId } from "./document-node-identity.js";
9
+ export { collectDocumentEntityKeys, collectDocumentNodeReferences, normalizeRepoRelativePath, resolveDocumentNodeId, resolveTargetReference } from "./document-node-identity.js";
@@ -1,78 +1,15 @@
1
1
  /**
2
- * @import { DocumentNodeReference } from './document-node-identity.js';
3
2
  * @import { GraphNode } from './build-graph.types.ts';
4
- * @import { PatramClaim } from '../parse/parse-claims.types.ts';
5
3
  */
6
4
 
7
- import { posix } from 'node:path';
8
-
9
- import { normalizeRepoRelativePath } from './document-node-identity.js';
10
-
11
5
  export {
12
6
  collectDocumentEntityKeys,
13
7
  collectDocumentNodeReferences,
14
8
  normalizeRepoRelativePath,
15
9
  resolveDocumentNodeId,
10
+ resolveTargetReference,
16
11
  } from './document-node-identity.js';
17
12
 
18
- /**
19
- * Resolve the node key for one mapped claim.
20
- *
21
- * @param {{ field: string, key?: 'path' | 'value', class: string }} node_mapping
22
- * @param {PatramClaim} claim
23
- * @param {Map<string, string>} document_entity_keys
24
- * @returns {string}
25
- */
26
- export function resolveNodeKey(node_mapping, claim, document_entity_keys) {
27
- const source_key = normalizeRepoRelativePath(claim.origin.path);
28
-
29
- if (node_mapping.class === 'document') {
30
- return source_key;
31
- }
32
-
33
- if (node_mapping.key === 'value') {
34
- return getStringClaimValue(claim);
35
- }
36
-
37
- return (
38
- document_entity_keys.get(
39
- getDocumentEntityMapKey(source_key, node_mapping.class),
40
- ) ?? source_key
41
- );
42
- }
43
-
44
- /**
45
- * Resolve one edge target key and canonical path.
46
- *
47
- * @param {string} target_class
48
- * @param {'path' | 'value'} target_type
49
- * @param {PatramClaim} claim
50
- * @param {Map<string, string>} document_entity_keys
51
- * @param {Map<string, DocumentNodeReference>} document_node_references
52
- * @param {Set<string>} document_paths
53
- * @returns {{ class_name: string, key: string, path?: string }}
54
- */
55
- export function resolveTargetReference(
56
- target_class,
57
- target_type,
58
- claim,
59
- document_entity_keys,
60
- document_node_references,
61
- document_paths,
62
- ) {
63
- if (target_type === 'value') {
64
- return resolveValueTargetReference(target_class, claim);
65
- }
66
-
67
- return resolvePathTargetReference(
68
- target_class,
69
- claim,
70
- document_entity_keys,
71
- document_node_references,
72
- document_paths,
73
- );
74
- }
75
-
76
13
  /**
77
14
  * Attach one canonical path to a graph node.
78
15
  *
@@ -84,215 +21,14 @@ export function setCanonicalPath(graph_node, source_path) {
84
21
  return;
85
22
  }
86
23
 
87
- if (!graph_node.$path) {
88
- graph_node.$path = source_path;
89
- graph_node.path = source_path;
24
+ if (!graph_node.identity.path) {
25
+ graph_node.identity.path = source_path;
90
26
  return;
91
27
  }
92
28
 
93
- if (graph_node.$path !== source_path) {
29
+ if (graph_node.identity.path !== source_path) {
94
30
  throw new Error(
95
- `Node "${graph_node.id}" maps to multiple canonical paths.`,
31
+ `Node "${graph_node.identity.id}" maps to multiple canonical paths.`,
96
32
  );
97
33
  }
98
34
  }
99
-
100
- /**
101
- * @param {string} target_kind
102
- * @param {PatramClaim} claim
103
- * @returns {{ class_name: string, key: string, path?: string }}
104
- */
105
- function resolveValueTargetReference(target_kind, claim) {
106
- const target_key = getStringClaimValue(claim);
107
-
108
- if (target_kind === 'document') {
109
- return {
110
- class_name: 'document',
111
- key: target_key,
112
- path: target_key,
113
- };
114
- }
115
-
116
- return {
117
- class_name: target_kind,
118
- key: target_key,
119
- path: normalizeRepoRelativePath(claim.origin.path),
120
- };
121
- }
122
-
123
- /**
124
- * @param {string} target_class
125
- * @param {PatramClaim} claim
126
- * @param {Map<string, string>} document_entity_keys
127
- * @param {Map<string, DocumentNodeReference>} document_node_references
128
- * @param {Set<string>} document_paths
129
- * @returns {{ class_name: string, key: string, path?: string }}
130
- */
131
- function resolvePathTargetReference(
132
- target_class,
133
- claim,
134
- document_entity_keys,
135
- document_node_references,
136
- document_paths,
137
- ) {
138
- const raw_target = getPathTargetValue(claim);
139
- const target_path = resolveDirectiveAwareTargetPath(
140
- claim,
141
- raw_target,
142
- document_paths,
143
- );
144
-
145
- if (target_class === 'document') {
146
- return resolveDocumentTargetReference(
147
- target_path,
148
- document_node_references,
149
- );
150
- }
151
-
152
- const document_node_reference = document_node_references.get(target_path);
153
-
154
- if (documentNodeReferenceIsPromoted(document_node_reference)) {
155
- return {
156
- class_name: document_node_reference.class_name,
157
- key: document_node_reference.key,
158
- path: target_path,
159
- };
160
- }
161
-
162
- return {
163
- class_name: target_class,
164
- key:
165
- document_entity_keys.get(
166
- getDocumentEntityMapKey(target_path, target_class),
167
- ) ?? target_path,
168
- path: target_path,
169
- };
170
- }
171
-
172
- /**
173
- * @param {string} target_path
174
- * @param {Map<string, DocumentNodeReference>} document_node_references
175
- * @returns {{ class_name: string, key: string, path?: string }}
176
- */
177
- function resolveDocumentTargetReference(target_path, document_node_references) {
178
- const document_node_reference = document_node_references.get(target_path);
179
-
180
- if (!document_node_reference) {
181
- return {
182
- class_name: 'document',
183
- key: target_path,
184
- path: target_path,
185
- };
186
- }
187
-
188
- return {
189
- class_name: document_node_reference.class_name,
190
- key: document_node_reference.key,
191
- path: target_path,
192
- };
193
- }
194
-
195
- /**
196
- * @param {PatramClaim} claim
197
- * @param {string} raw_target
198
- * @param {Set<string>} document_paths
199
- * @returns {string}
200
- */
201
- function resolveDirectiveAwareTargetPath(claim, raw_target, document_paths) {
202
- const normalized_raw_target = normalizeRepoRelativePath(raw_target);
203
-
204
- if (
205
- claim.type === 'directive' &&
206
- shouldKeepDirectiveTargetRepoRelative(
207
- raw_target,
208
- normalized_raw_target,
209
- document_paths,
210
- )
211
- ) {
212
- return normalized_raw_target;
213
- }
214
-
215
- const source_directory = posix.dirname(
216
- normalizeRepoRelativePath(claim.origin.path),
217
- );
218
-
219
- return normalizeRepoRelativePath(posix.join(source_directory, raw_target));
220
- }
221
-
222
- /**
223
- * @param {string} raw_target
224
- * @param {string} normalized_raw_target
225
- * @param {Set<string>} document_paths
226
- * @returns {boolean}
227
- */
228
- function shouldKeepDirectiveTargetRepoRelative(
229
- raw_target,
230
- normalized_raw_target,
231
- document_paths,
232
- ) {
233
- if (raw_target.startsWith('./') || raw_target.startsWith('../')) {
234
- return false;
235
- }
236
-
237
- if (document_paths.has(normalized_raw_target)) {
238
- return true;
239
- }
240
-
241
- const target_root_segment = normalized_raw_target.split('/')[0];
242
-
243
- if (!target_root_segment) {
244
- return false;
245
- }
246
-
247
- for (const document_path of document_paths) {
248
- if (document_path.split('/')[0] === target_root_segment) {
249
- return true;
250
- }
251
- }
252
-
253
- return false;
254
- }
255
-
256
- /**
257
- * @param {PatramClaim} claim
258
- * @returns {string}
259
- */
260
- function getPathTargetValue(claim) {
261
- if (typeof claim.value === 'string') {
262
- return claim.value;
263
- }
264
-
265
- return claim.value.target;
266
- }
267
-
268
- /**
269
- * @param {PatramClaim} claim
270
- * @returns {string}
271
- */
272
- function getStringClaimValue(claim) {
273
- if (typeof claim.value === 'string') {
274
- return claim.value;
275
- }
276
-
277
- throw new Error(`Claim "${claim.id}" does not carry a string value.`);
278
- }
279
-
280
- /**
281
- * @param {string} document_path
282
- * @param {string} class_name
283
- * @returns {string}
284
- */
285
- function getDocumentEntityMapKey(document_path, class_name) {
286
- return `${class_name}:${document_path}`;
287
- }
288
-
289
- /**
290
- * @param {DocumentNodeReference | undefined} document_node_reference
291
- * @returns {document_node_reference is DocumentNodeReference}
292
- */
293
- function documentNodeReferenceIsPromoted(document_node_reference) {
294
- return (
295
- document_node_reference !== undefined &&
296
- document_node_reference.class_name !== 'document'
297
- );
298
- }
@@ -1,11 +1,20 @@
1
1
  /**
2
- * Build a Patram graph from semantic config and parsed claims.
2
+ * Build a Patram graph from repo config and parsed claims.
3
3
  *
4
- * @param {PatramConfig} patram_config
4
+ * kind: graph
5
+ * status: active
6
+ * uses_term: ../../docs/reference/terms/graph.md
7
+ * tracked_in: ../../docs/plans/v2/types-and-fields-config.md
8
+ * decided_by: ../../docs/decisions/types-and-fields-config.md
9
+ * @patram
10
+ * @see {@link ./build-graph-identity.js}
11
+ * @see {@link ../../docs/decisions/types-and-fields-config.md}
12
+ *
13
+ * @param {PatramRepoConfig} repo_config
5
14
  * @param {PatramClaim[]} claims
6
15
  * @returns {BuildGraphResult}
7
16
  */
8
- export function buildGraph(patram_config: PatramConfig, claims: PatramClaim[]): BuildGraphResult;
9
- import type { PatramConfig } from '../config/patram-config.types.d.ts';
17
+ export function buildGraph(repo_config: PatramRepoConfig, claims: PatramClaim[]): BuildGraphResult;
18
+ import type { PatramRepoConfig } from '../config/load-patram-config.types.d.ts';
10
19
  import type { PatramClaim } from '../parse/parse-claims.types.d.ts';
11
20
  import type { BuildGraphResult } from './build-graph.types.d.ts';