patram 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/lib/build-graph-identity.js +57 -24
  2. package/lib/build-graph.js +383 -17
  3. package/lib/build-graph.types.ts +5 -2
  4. package/lib/check-directive-metadata.js +516 -0
  5. package/lib/check-directive-value.js +282 -0
  6. package/lib/check-graph.js +24 -5
  7. package/lib/cli-help-metadata.js +580 -0
  8. package/lib/derived-summary.js +280 -0
  9. package/lib/directive-diagnostics.js +38 -0
  10. package/lib/directive-type-rules.js +133 -0
  11. package/lib/discover-fields.js +427 -0
  12. package/lib/discover-fields.types.ts +52 -0
  13. package/lib/format-derived-summary-row.js +9 -0
  14. package/lib/format-node-header.js +21 -0
  15. package/lib/format-output-item-block.js +22 -0
  16. package/lib/format-output-metadata.js +54 -0
  17. package/lib/layout-stored-queries.js +96 -2
  18. package/lib/load-patram-config.js +754 -18
  19. package/lib/load-patram-config.types.ts +128 -2
  20. package/lib/load-project-graph.js +4 -1
  21. package/lib/output-view.types.ts +29 -6
  22. package/lib/parse-cli-arguments-helpers.js +263 -90
  23. package/lib/parse-cli-arguments.js +160 -8
  24. package/lib/parse-cli-arguments.types.ts +49 -4
  25. package/lib/parse-where-clause.js +670 -209
  26. package/lib/parse-where-clause.types.ts +72 -0
  27. package/lib/patram-cli.js +180 -21
  28. package/lib/patram-config.js +31 -31
  29. package/lib/patram-config.types.ts +10 -4
  30. package/lib/patram.js +6 -0
  31. package/lib/query-graph.js +444 -113
  32. package/lib/query-inspection.js +798 -0
  33. package/lib/render-check-output.js +1 -1
  34. package/lib/render-cli-help.js +419 -0
  35. package/lib/render-field-discovery.js +148 -0
  36. package/lib/render-json-output.js +66 -14
  37. package/lib/render-output-view.js +272 -22
  38. package/lib/render-plain-output.js +31 -86
  39. package/lib/render-rich-output.js +34 -87
  40. package/lib/resolve-patram-graph-config.js +15 -9
  41. package/lib/resolve-where-clause.js +18 -3
  42. package/lib/show-document.js +51 -7
  43. package/lib/tagged-fenced-block-error.js +17 -0
  44. package/lib/tagged-fenced-block-markdown.js +111 -0
  45. package/lib/tagged-fenced-block-metadata.js +97 -0
  46. package/lib/tagged-fenced-block-parser.js +292 -0
  47. package/lib/tagged-fenced-blocks.js +100 -0
  48. package/lib/tagged-fenced-blocks.types.ts +38 -0
  49. package/package.json +12 -7
@@ -27,14 +27,14 @@ export function collectDocumentEntityKeys(mappings, claims) {
27
27
  const source_path = normalizeRepoRelativePath(claim.origin.path);
28
28
  const entity_map_key = getDocumentEntityMapKey(
29
29
  source_path,
30
- mapping_definition.node.kind,
30
+ mapping_definition.node.class,
31
31
  );
32
32
  const entity_key = getStringClaimValue(claim);
33
33
  const existing_entity_key = document_entity_keys.get(entity_map_key);
34
34
 
35
35
  if (existing_entity_key && existing_entity_key !== entity_key) {
36
36
  throw new Error(
37
- `Document "${source_path}" defines multiple ${mapping_definition.node.kind} ids.`,
37
+ `Document "${source_path}" defines multiple ${mapping_definition.node.class} ids.`,
38
38
  );
39
39
  }
40
40
 
@@ -47,7 +47,7 @@ export function collectDocumentEntityKeys(mappings, claims) {
47
47
  /**
48
48
  * Resolve the node key for one mapped claim.
49
49
  *
50
- * @param {{ field: string, key?: 'path' | 'value', kind: string }} node_mapping
50
+ * @param {{ field: string, key?: 'path' | 'value', class: string }} node_mapping
51
51
  * @param {PatramClaim} claim
52
52
  * @param {Map<string, string>} document_entity_keys
53
53
  * @returns {string}
@@ -55,7 +55,7 @@ export function collectDocumentEntityKeys(mappings, claims) {
55
55
  export function resolveNodeKey(node_mapping, claim, document_entity_keys) {
56
56
  const source_key = normalizeRepoRelativePath(claim.origin.path);
57
57
 
58
- if (node_mapping.kind === 'document') {
58
+ if (node_mapping.class === 'document') {
59
59
  return source_key;
60
60
  }
61
61
 
@@ -65,7 +65,7 @@ export function resolveNodeKey(node_mapping, claim, document_entity_keys) {
65
65
 
66
66
  return (
67
67
  document_entity_keys.get(
68
- getDocumentEntityMapKey(source_key, node_mapping.kind),
68
+ getDocumentEntityMapKey(source_key, node_mapping.class),
69
69
  ) ?? source_key
70
70
  );
71
71
  }
@@ -73,23 +73,30 @@ export function resolveNodeKey(node_mapping, claim, document_entity_keys) {
73
73
  /**
74
74
  * Resolve one edge target key and canonical path.
75
75
  *
76
- * @param {string} target_kind
76
+ * @param {string} target_class
77
77
  * @param {'path' | 'value'} target_type
78
78
  * @param {PatramClaim} claim
79
79
  * @param {Map<string, string>} document_entity_keys
80
+ * @param {Set<string>} document_paths
80
81
  * @returns {{ key: string, path?: string }}
81
82
  */
82
83
  export function resolveTargetReference(
83
- target_kind,
84
+ target_class,
84
85
  target_type,
85
86
  claim,
86
87
  document_entity_keys,
88
+ document_paths,
87
89
  ) {
88
90
  if (target_type === 'value') {
89
- return resolveValueTargetReference(target_kind, claim);
91
+ return resolveValueTargetReference(target_class, claim);
90
92
  }
91
93
 
92
- return resolvePathTargetReference(target_kind, claim, document_entity_keys);
94
+ return resolvePathTargetReference(
95
+ target_class,
96
+ claim,
97
+ document_entity_keys,
98
+ document_paths,
99
+ );
93
100
  }
94
101
 
95
102
  /**
@@ -99,16 +106,17 @@ export function resolveTargetReference(
99
106
  * @param {string | undefined} source_path
100
107
  */
101
108
  export function setNonDocumentPath(graph_node, source_path) {
102
- if (!source_path || graph_node.kind === 'document') {
109
+ if (!source_path || graph_node.$class === 'document') {
103
110
  return;
104
111
  }
105
112
 
106
- if (!graph_node.path) {
113
+ if (!graph_node.$path) {
114
+ graph_node.$path = source_path;
107
115
  graph_node.path = source_path;
108
116
  return;
109
117
  }
110
118
 
111
- if (graph_node.path !== source_path) {
119
+ if (graph_node.$path !== source_path) {
112
120
  throw new Error(
113
121
  `Node "${graph_node.id}" maps to multiple canonical paths.`,
114
122
  );
@@ -173,21 +181,26 @@ function resolveValueTargetReference(target_kind, claim) {
173
181
  }
174
182
 
175
183
  /**
176
- * @param {string} target_kind
184
+ * @param {string} target_class
177
185
  * @param {PatramClaim} claim
178
186
  * @param {Map<string, string>} document_entity_keys
187
+ * @param {Set<string>} document_paths
179
188
  * @returns {{ key: string, path?: string }}
180
189
  */
181
- function resolvePathTargetReference(target_kind, claim, document_entity_keys) {
182
- const source_directory = posix.dirname(
183
- normalizeRepoRelativePath(claim.origin.path),
184
- );
190
+ function resolvePathTargetReference(
191
+ target_class,
192
+ claim,
193
+ document_entity_keys,
194
+ document_paths,
195
+ ) {
185
196
  const raw_target = getPathTargetValue(claim);
186
- const target_path = normalizeRepoRelativePath(
187
- posix.join(source_directory, raw_target),
197
+ const target_path = resolveDirectiveAwareTargetPath(
198
+ claim,
199
+ raw_target,
200
+ document_paths,
188
201
  );
189
202
 
190
- if (target_kind === 'document') {
203
+ if (target_class === 'document') {
191
204
  return {
192
205
  key: target_path,
193
206
  path: target_path,
@@ -195,7 +208,7 @@ function resolvePathTargetReference(target_kind, claim, document_entity_keys) {
195
208
  }
196
209
 
197
210
  const semantic_target_key = document_entity_keys.get(
198
- getDocumentEntityMapKey(target_path, target_kind),
211
+ getDocumentEntityMapKey(target_path, target_class),
199
212
  );
200
213
 
201
214
  return {
@@ -204,6 +217,26 @@ function resolvePathTargetReference(target_kind, claim, document_entity_keys) {
204
217
  };
205
218
  }
206
219
 
220
+ /**
221
+ * @param {PatramClaim} claim
222
+ * @param {string} raw_target
223
+ * @param {Set<string>} document_paths
224
+ * @returns {string}
225
+ */
226
+ function resolveDirectiveAwareTargetPath(claim, raw_target, document_paths) {
227
+ const normalized_raw_target = normalizeRepoRelativePath(raw_target);
228
+
229
+ if (claim.type === 'directive' && document_paths.has(normalized_raw_target)) {
230
+ return normalized_raw_target;
231
+ }
232
+
233
+ const source_directory = posix.dirname(
234
+ normalizeRepoRelativePath(claim.origin.path),
235
+ );
236
+
237
+ return normalizeRepoRelativePath(posix.join(source_directory, raw_target));
238
+ }
239
+
207
240
  /**
208
241
  * @param {PatramClaim} claim
209
242
  * @returns {string}
@@ -230,9 +263,9 @@ function getStringClaimValue(claim) {
230
263
 
231
264
  /**
232
265
  * @param {string} document_path
233
- * @param {string} kind_name
266
+ * @param {string} class_name
234
267
  * @returns {string}
235
268
  */
236
- function getDocumentEntityMapKey(document_path, kind_name) {
237
- return `${kind_name}:${document_path}`;
269
+ function getDocumentEntityMapKey(document_path, class_name) {
270
+ return `${class_name}:${document_path}`;
238
271
  }