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
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @import {
3
+ * TaggedFencedBlock,
4
+ * TaggedFencedBlockCriteria,
5
+ * TaggedFencedBlockFile,
6
+ * TaggedFencedBlocksInput,
7
+ * } from './tagged-fenced-blocks.types.ts';
8
+ */
9
+
10
+ import { readFile } from 'node:fs/promises';
11
+
12
+ import { createTaggedFencedBlockError } from './tagged-fenced-block-error.js';
13
+ import { extractTaggedFencedBlocksFromSource } from './tagged-fenced-block-parser.js';
14
+
15
+ /**
16
+ * Tagged fenced block public API.
17
+ *
18
+ * Loads or extracts one markdown file worth of tagged fenced blocks and
19
+ * provides exact-match selection helpers.
20
+ *
21
+ * Kind: parse
22
+ * Status: active
23
+ * Tracked in: ../docs/plans/v0/tagged-fenced-block-extraction.md
24
+ * Decided by: ../docs/decisions/tagged-fenced-block-extraction.md
25
+ * @patram
26
+ * @see {@link ../docs/decisions/tagged-fenced-block-extraction.md}
27
+ */
28
+
29
+ /**
30
+ * @param {TaggedFencedBlocksInput} input
31
+ * @returns {TaggedFencedBlockFile}
32
+ */
33
+ export function extractTaggedFencedBlocks(input) {
34
+ return extractTaggedFencedBlocksFromSource(input);
35
+ }
36
+
37
+ /**
38
+ * @param {string} file_path
39
+ * @returns {Promise<TaggedFencedBlockFile>}
40
+ */
41
+ export async function loadTaggedFencedBlocks(file_path) {
42
+ const source_text = await readFile(file_path, 'utf8');
43
+
44
+ return extractTaggedFencedBlocks({
45
+ file_path,
46
+ source_text,
47
+ });
48
+ }
49
+
50
+ /**
51
+ * @param {TaggedFencedBlock[]} blocks
52
+ * @param {TaggedFencedBlockCriteria} criteria
53
+ * @returns {TaggedFencedBlock[]}
54
+ */
55
+ export function selectTaggedBlocks(blocks, criteria) {
56
+ const criteria_entries = Object.entries(criteria);
57
+
58
+ return blocks.filter((block) =>
59
+ criteria_entries.every(
60
+ ([key, value]) =>
61
+ block.metadata[key] !== undefined && block.metadata[key] === value,
62
+ ),
63
+ );
64
+ }
65
+
66
+ /**
67
+ * @param {TaggedFencedBlock[]} blocks
68
+ * @param {TaggedFencedBlockCriteria} criteria
69
+ * @returns {TaggedFencedBlock}
70
+ */
71
+ export function selectTaggedBlock(blocks, criteria) {
72
+ const matches = selectTaggedBlocks(blocks, criteria);
73
+
74
+ if (matches.length === 1) {
75
+ return matches[0];
76
+ }
77
+
78
+ if (matches.length === 0) {
79
+ throw createTaggedFencedBlockError(
80
+ 'tagged_fenced_blocks.not_found',
81
+ `No tagged fenced block matches ${formatSelectionCriteria(criteria)}.`,
82
+ );
83
+ }
84
+
85
+ throw createTaggedFencedBlockError(
86
+ 'tagged_fenced_blocks.not_unique',
87
+ `Multiple tagged fenced blocks match ${formatSelectionCriteria(criteria)}.`,
88
+ );
89
+ }
90
+
91
+ /**
92
+ * @param {TaggedFencedBlockCriteria} criteria
93
+ * @returns {string}
94
+ */
95
+ function formatSelectionCriteria(criteria) {
96
+ return Object.entries(criteria)
97
+ .sort(([left_key], [right_key]) => left_key.localeCompare(right_key))
98
+ .map(([key, value]) => `${key}=${value}`)
99
+ .join(', ');
100
+ }
@@ -0,0 +1,38 @@
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
+ }
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "patram",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
+ "main": "./lib/patram.js",
6
+ "exports": {
7
+ ".": "./lib/patram.js",
8
+ "./bin/patram.js": "./bin/patram.js"
9
+ },
5
10
  "files": [
6
11
  "bin/patram.js",
7
12
  "lib/**/*.js",
@@ -12,7 +17,7 @@
12
17
  "!lib/**/*.test-helpers.js"
13
18
  ],
14
19
  "bin": {
15
- "patram": "./bin/patram.js"
20
+ "patram": "bin/patram.js"
16
21
  },
17
22
  "homepage": "https://github.com/mantoni/patram",
18
23
  "repository": {
@@ -29,7 +34,7 @@
29
34
  "check:format": "prettier --check .",
30
35
  "check:lint": "eslint .",
31
36
  "check:patram": "./bin/patram.js check",
32
- "check:staged": "lint-staged --quiet",
37
+ "check:staged": "lint-staged",
33
38
  "check:types": "tsc",
34
39
  "postversion": "git push && git push --tags",
35
40
  "preversion": "npm run all",
@@ -60,8 +65,8 @@
60
65
  "devDependencies": {
61
66
  "@eslint/js": "^10.0.1",
62
67
  "@types/node": "^24.12.0",
63
- "@vitest/coverage-v8": "^4.1.0",
64
- "eslint": "^10.0.3",
68
+ "@vitest/coverage-v8": "^4.1.1",
69
+ "eslint": "^10.1.0",
65
70
  "eslint-plugin-jsdoc": "^62.8.0",
66
71
  "globals": "^17.4.0",
67
72
  "husky": "^9.1.7",
@@ -69,7 +74,7 @@
69
74
  "lint-staged": "^16.2.6",
70
75
  "prettier": "^3.5.3",
71
76
  "slice-ansi": "^8.0.0",
72
- "typescript": "^5.8.2",
73
- "vitest": "^4.1.0"
77
+ "typescript": "^6.0.2",
78
+ "vitest": "^4.1.1"
74
79
  }
75
80
  }