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
@@ -1,45 +0,0 @@
1
- export type StoredQueryConfig = import('./load-patram-config.js').StoredQueryConfig;
2
- export type FieldDisplayConfig = import('./load-patram-config.js').FieldDisplayConfig;
3
- export type FieldQueryConfig = import('./load-patram-config.js').FieldQueryConfig;
4
- export type FieldValueTypeName = import('./load-patram-config.js').MetadataFieldConfig['type'];
5
- export type MetadataFieldConfig = import('./load-patram-config.js').MetadataFieldConfig;
6
- export type StringFieldConfig = Extract<MetadataFieldConfig, {
7
- type: 'string';
8
- }>;
9
- export type IntegerFieldConfig = Extract<MetadataFieldConfig, {
10
- type: 'integer';
11
- }>;
12
- export type EnumFieldConfig = Extract<MetadataFieldConfig, {
13
- type: 'enum';
14
- }>;
15
- export type PathFieldConfig = Extract<MetadataFieldConfig, {
16
- type: 'path';
17
- }>;
18
- export type GlobFieldConfig = Extract<MetadataFieldConfig, {
19
- type: 'glob';
20
- }>;
21
- export type DateFieldConfig = Extract<MetadataFieldConfig, {
22
- type: 'date';
23
- }>;
24
- export type DateTimeFieldConfig = Extract<MetadataFieldConfig, {
25
- type: 'date_time';
26
- }>;
27
- export type ClassFieldRuleConfig = import('./load-patram-config.js').ClassFieldRuleConfig;
28
- export type DirectiveTypeConfig = MetadataFieldConfig;
29
- export type MetadataDirectiveRuleConfig = ClassFieldRuleConfig;
30
- export type ClassSchemaConfig = import('./load-patram-config.js').ClassSchemaConfig;
31
- export type MetadataSchemaConfig = ClassSchemaConfig;
32
- export type PathClassConfig = import('./load-patram-config.js').PathClassConfig;
33
- export type DerivedSummaryScalar = import('./load-patram-config.js').DerivedSummaryScalar;
34
- export type DerivedSummarySelectCaseConfig = import('./load-patram-config.js').DerivedSummarySelectCaseConfig;
35
- export type DerivedSummaryFieldConfig = import('./load-patram-config.js').DerivedSummaryFieldConfig;
36
- export type DerivedSummaryCountFieldConfig = Extract<DerivedSummaryFieldConfig, {
37
- count: unknown;
38
- }>;
39
- export type DerivedSummarySelectFieldConfig = Extract<DerivedSummaryFieldConfig, {
40
- select: unknown;
41
- }>;
42
- export type DerivedSummaryConfig = import('./load-patram-config.js').DerivedSummaryConfig;
43
- export type PatramRepoConfig = import('./load-patram-config.js').PatramRepoConfig;
44
- export type PatramDiagnostic = import('./load-patram-config.js').PatramDiagnostic;
45
- export type LoadPatramConfigResult = import('./load-patram-config.js').LoadPatramConfigResult;
@@ -1,56 +0,0 @@
1
- export type StoredQueryConfig =
2
- import('./load-patram-config.js').StoredQueryConfig;
3
- export type FieldDisplayConfig =
4
- import('./load-patram-config.js').FieldDisplayConfig;
5
- export type FieldQueryConfig =
6
- import('./load-patram-config.js').FieldQueryConfig;
7
- export type FieldValueTypeName =
8
- import('./load-patram-config.js').MetadataFieldConfig['type'];
9
- export type MetadataFieldConfig =
10
- import('./load-patram-config.js').MetadataFieldConfig;
11
- export type StringFieldConfig = Extract<
12
- MetadataFieldConfig,
13
- { type: 'string' }
14
- >;
15
- export type IntegerFieldConfig = Extract<
16
- MetadataFieldConfig,
17
- { type: 'integer' }
18
- >;
19
- export type EnumFieldConfig = Extract<MetadataFieldConfig, { type: 'enum' }>;
20
- export type PathFieldConfig = Extract<MetadataFieldConfig, { type: 'path' }>;
21
- export type GlobFieldConfig = Extract<MetadataFieldConfig, { type: 'glob' }>;
22
- export type DateFieldConfig = Extract<MetadataFieldConfig, { type: 'date' }>;
23
- export type DateTimeFieldConfig = Extract<
24
- MetadataFieldConfig,
25
- { type: 'date_time' }
26
- >;
27
- export type ClassFieldRuleConfig =
28
- import('./load-patram-config.js').ClassFieldRuleConfig;
29
- export type DirectiveTypeConfig = MetadataFieldConfig;
30
- export type MetadataDirectiveRuleConfig = ClassFieldRuleConfig;
31
- export type ClassSchemaConfig =
32
- import('./load-patram-config.js').ClassSchemaConfig;
33
- export type MetadataSchemaConfig = ClassSchemaConfig;
34
- export type PathClassConfig = import('./load-patram-config.js').PathClassConfig;
35
- export type DerivedSummaryScalar =
36
- import('./load-patram-config.js').DerivedSummaryScalar;
37
- export type DerivedSummarySelectCaseConfig =
38
- import('./load-patram-config.js').DerivedSummarySelectCaseConfig;
39
- export type DerivedSummaryFieldConfig =
40
- import('./load-patram-config.js').DerivedSummaryFieldConfig;
41
- export type DerivedSummaryCountFieldConfig = Extract<
42
- DerivedSummaryFieldConfig,
43
- { count: unknown }
44
- >;
45
- export type DerivedSummarySelectFieldConfig = Extract<
46
- DerivedSummaryFieldConfig,
47
- { select: unknown }
48
- >;
49
- export type DerivedSummaryConfig =
50
- import('./load-patram-config.js').DerivedSummaryConfig;
51
- export type PatramRepoConfig =
52
- import('./load-patram-config.js').PatramRepoConfig;
53
- export type PatramDiagnostic =
54
- import('./load-patram-config.js').PatramDiagnostic;
55
- export type LoadPatramConfigResult =
56
- import('./load-patram-config.js').LoadPatramConfigResult;
@@ -1,80 +0,0 @@
1
- export type OutputDerivedValue = boolean | number | string | null;
2
- export interface OutputDerivedField {
3
- name: string;
4
- value: OutputDerivedValue;
5
- }
6
- export interface OutputDerivedSummary {
7
- fields: OutputDerivedField[];
8
- name: string;
9
- }
10
- export interface OutputMetadataField {
11
- name: string;
12
- value: string | string[];
13
- }
14
- export interface OutputViewSummary {
15
- count: number;
16
- kind: 'resolved_link_list' | 'result_list' | 'stored_query_list';
17
- }
18
- export interface QueryOutputViewSummary extends OutputViewSummary {
19
- kind: 'result_list';
20
- limit: number;
21
- offset: number;
22
- total_count: number;
23
- }
24
- export interface OutputNodeItem {
25
- derived_summary?: OutputDerivedSummary;
26
- fields: Record<string, string | string[]>;
27
- id: string;
28
- kind: 'node';
29
- node_kind: string;
30
- path?: string;
31
- title: string;
32
- visible_fields: OutputMetadataField[];
33
- }
34
- export interface OutputStoredQueryItem {
35
- kind: 'stored_query';
36
- name: string;
37
- where: string;
38
- }
39
- export interface OutputResolvedLinkTarget {
40
- derived_summary?: OutputDerivedSummary;
41
- fields: Record<string, string | string[]>;
42
- id: string;
43
- kind: string;
44
- path?: string;
45
- title: string;
46
- visible_fields: OutputMetadataField[];
47
- }
48
- export interface OutputResolvedLinkItem {
49
- kind: 'resolved_link';
50
- label: string;
51
- reference: number;
52
- target: OutputResolvedLinkTarget;
53
- }
54
- export interface QueryOutputView {
55
- command: 'query';
56
- hints: string[];
57
- items: OutputNodeItem[];
58
- summary: QueryOutputViewSummary;
59
- }
60
- export interface QueriesOutputView {
61
- command: 'queries';
62
- hints: string[];
63
- items: OutputStoredQueryItem[];
64
- summary: OutputViewSummary;
65
- }
66
- export interface ShowOutputView {
67
- command: 'show';
68
- document?: OutputNodeItem;
69
- hints: string[];
70
- items: OutputResolvedLinkItem[];
71
- path: string;
72
- rendered_source: string;
73
- source: string;
74
- summary: OutputViewSummary;
75
- }
76
- export type OutputView = QueryOutputView | QueriesOutputView | ShowOutputView;
77
- export interface ResolvedOutputMode {
78
- color_enabled: boolean;
79
- renderer_name: 'json' | 'plain' | 'rich';
80
- }
@@ -1,96 +0,0 @@
1
- import type { GraphNode } from './build-graph.types.ts';
2
-
3
- export type OutputDerivedValue = boolean | number | string | null;
4
-
5
- export interface OutputDerivedField {
6
- name: string;
7
- value: OutputDerivedValue;
8
- }
9
-
10
- export interface OutputDerivedSummary {
11
- fields: OutputDerivedField[];
12
- name: string;
13
- }
14
-
15
- export interface OutputMetadataField {
16
- name: string;
17
- value: string | string[];
18
- }
19
-
20
- export interface OutputViewSummary {
21
- count: number;
22
- kind: 'resolved_link_list' | 'result_list' | 'stored_query_list';
23
- }
24
-
25
- export interface QueryOutputViewSummary extends OutputViewSummary {
26
- kind: 'result_list';
27
- limit: number;
28
- offset: number;
29
- total_count: number;
30
- }
31
-
32
- export interface OutputNodeItem {
33
- derived_summary?: OutputDerivedSummary;
34
- fields: Record<string, string | string[]>;
35
- id: string;
36
- kind: 'node';
37
- node_kind: string;
38
- path?: string;
39
- title: string;
40
- visible_fields: OutputMetadataField[];
41
- }
42
-
43
- export interface OutputStoredQueryItem {
44
- kind: 'stored_query';
45
- name: string;
46
- where: string;
47
- }
48
-
49
- export interface OutputResolvedLinkTarget {
50
- derived_summary?: OutputDerivedSummary;
51
- fields: Record<string, string | string[]>;
52
- id: string;
53
- kind: string;
54
- path?: string;
55
- title: string;
56
- visible_fields: OutputMetadataField[];
57
- }
58
-
59
- export interface OutputResolvedLinkItem {
60
- kind: 'resolved_link';
61
- label: string;
62
- reference: number;
63
- target: OutputResolvedLinkTarget;
64
- }
65
-
66
- export interface QueryOutputView {
67
- command: 'query';
68
- hints: string[];
69
- items: OutputNodeItem[];
70
- summary: QueryOutputViewSummary;
71
- }
72
-
73
- export interface QueriesOutputView {
74
- command: 'queries';
75
- hints: string[];
76
- items: OutputStoredQueryItem[];
77
- summary: OutputViewSummary;
78
- }
79
-
80
- export interface ShowOutputView {
81
- command: 'show';
82
- document?: OutputNodeItem;
83
- hints: string[];
84
- items: OutputResolvedLinkItem[];
85
- path: string;
86
- rendered_source: string;
87
- source: string;
88
- summary: OutputViewSummary;
89
- }
90
-
91
- export type OutputView = QueryOutputView | QueriesOutputView | ShowOutputView;
92
-
93
- export interface ResolvedOutputMode {
94
- color_enabled: boolean;
95
- renderer_name: 'json' | 'plain' | 'rich';
96
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * @import { BuildGraphResult, GraphEdge, GraphNode } from './build-graph.types.ts';
3
- */
4
- /**
5
- * @typedef {{
6
- * document_node_ids?: BuildGraphResult['document_node_ids'],
7
- * edges?: GraphEdge[],
8
- * nodes?: GraphNode[] | Record<string, GraphNode>,
9
- * }} GraphOverlay
10
- */
11
- /**
12
- * Graph overlay composition.
13
- *
14
- * Composes transient nodes and edges onto an existing Patram graph while
15
- * preserving the graph shape expected by query and document resolution
16
- * helpers.
17
- *
18
- * Kind: graph
19
- * Status: active
20
- * Uses Term: ../docs/reference/terms/document.md
21
- * Uses Term: ../docs/reference/terms/graph.md
22
- * Tracked in: ../docs/plans/v0/package-graph-overlay-helper.md
23
- * Decided by: ../docs/decisions/package-graph-overlay-helper.md
24
- * @patram
25
- * @see {@link ./query-graph.js}
26
- * @see {@link ../docs/decisions/package-graph-overlay-helper.md}
27
- */
28
- /**
29
- * Compose additional nodes and edges onto a loaded Patram graph.
30
- *
31
- * @param {BuildGraphResult} base_graph
32
- * @param {GraphOverlay} [graph_overlay]
33
- * @returns {BuildGraphResult}
34
- */
35
- export function overlayGraph(base_graph: BuildGraphResult, graph_overlay?: GraphOverlay): BuildGraphResult;
36
- export type GraphOverlay = {
37
- document_node_ids?: BuildGraphResult["document_node_ids"];
38
- edges?: GraphEdge[];
39
- nodes?: GraphNode[] | Record<string, GraphNode>;
40
- };
41
- import type { BuildGraphResult } from './build-graph.types.ts';
42
- import type { GraphEdge } from './build-graph.types.ts';
43
- import type { GraphNode } from './build-graph.types.ts';
@@ -1,191 +0,0 @@
1
- /**
2
- * @import { BuildGraphResult, GraphEdge, GraphNode } from './build-graph.types.ts';
3
- */
4
-
5
- /**
6
- * @typedef {{
7
- * document_node_ids?: BuildGraphResult['document_node_ids'],
8
- * edges?: GraphEdge[],
9
- * nodes?: GraphNode[] | Record<string, GraphNode>,
10
- * }} GraphOverlay
11
- */
12
-
13
- /**
14
- * Graph overlay composition.
15
- *
16
- * Composes transient nodes and edges onto an existing Patram graph while
17
- * preserving the graph shape expected by query and document resolution
18
- * helpers.
19
- *
20
- * Kind: graph
21
- * Status: active
22
- * Uses Term: ../docs/reference/terms/document.md
23
- * Uses Term: ../docs/reference/terms/graph.md
24
- * Tracked in: ../docs/plans/v0/package-graph-overlay-helper.md
25
- * Decided by: ../docs/decisions/package-graph-overlay-helper.md
26
- * @patram
27
- * @see {@link ./query-graph.js}
28
- * @see {@link ../docs/decisions/package-graph-overlay-helper.md}
29
- */
30
-
31
- /**
32
- * Compose additional nodes and edges onto a loaded Patram graph.
33
- *
34
- * @param {BuildGraphResult} base_graph
35
- * @param {GraphOverlay} [graph_overlay]
36
- * @returns {BuildGraphResult}
37
- */
38
- export function overlayGraph(base_graph, graph_overlay = {}) {
39
- const graph_nodes = cloneGraphNodes(base_graph.nodes);
40
- const overlay_nodes = normalizeOverlayNodes(graph_overlay.nodes);
41
-
42
- applyOverlayNodes(graph_nodes, overlay_nodes);
43
-
44
- const graph = {
45
- edges: [...base_graph.edges, ...(graph_overlay.edges ?? [])],
46
- nodes: graph_nodes,
47
- };
48
- const document_node_ids = createDocumentNodeIds(
49
- base_graph.document_node_ids,
50
- graph_nodes,
51
- graph_overlay.document_node_ids,
52
- );
53
-
54
- attachDocumentNodeAliases(graph.nodes, document_node_ids);
55
- Object.defineProperty(graph, 'document_node_ids', {
56
- configurable: false,
57
- enumerable: false,
58
- value: document_node_ids,
59
- writable: false,
60
- });
61
-
62
- return graph;
63
- }
64
-
65
- /**
66
- * @param {BuildGraphResult['nodes']} base_graph_nodes
67
- * @returns {BuildGraphResult['nodes']}
68
- */
69
- function cloneGraphNodes(base_graph_nodes) {
70
- return Object.fromEntries(
71
- Object.entries(base_graph_nodes).map(([node_id, graph_node]) => [
72
- node_id,
73
- { ...graph_node },
74
- ]),
75
- );
76
- }
77
-
78
- /**
79
- * @param {GraphOverlay['nodes']} overlay_nodes
80
- * @returns {GraphNode[]}
81
- */
82
- function normalizeOverlayNodes(overlay_nodes) {
83
- if (!overlay_nodes) {
84
- return [];
85
- }
86
-
87
- if (Array.isArray(overlay_nodes)) {
88
- return overlay_nodes.map((graph_node) =>
89
- normalizeOverlayNode(undefined, graph_node),
90
- );
91
- }
92
-
93
- return Object.entries(overlay_nodes).map(([node_id, graph_node]) =>
94
- normalizeOverlayNode(node_id, graph_node),
95
- );
96
- }
97
-
98
- /**
99
- * @param {string | undefined} node_id
100
- * @param {GraphNode} graph_node
101
- * @returns {GraphNode}
102
- */
103
- function normalizeOverlayNode(node_id, graph_node) {
104
- if (node_id === undefined) {
105
- if (typeof graph_node.id !== 'string' || graph_node.id.length === 0) {
106
- throw new Error('Overlay nodes must define an id.');
107
- }
108
-
109
- return { ...graph_node };
110
- }
111
-
112
- if (graph_node.id !== undefined && graph_node.id !== node_id) {
113
- throw new Error(
114
- `Overlay node "${node_id}" does not match embedded id "${graph_node.id}".`,
115
- );
116
- }
117
-
118
- return {
119
- ...graph_node,
120
- id: node_id,
121
- };
122
- }
123
-
124
- /**
125
- * @param {BuildGraphResult['nodes']} graph_nodes
126
- * @param {GraphNode[]} overlay_nodes
127
- */
128
- function applyOverlayNodes(graph_nodes, overlay_nodes) {
129
- for (const overlay_node of overlay_nodes) {
130
- const existing_node = graph_nodes[overlay_node.id];
131
-
132
- graph_nodes[overlay_node.id] = existing_node
133
- ? { ...existing_node, ...overlay_node }
134
- : { ...overlay_node };
135
- }
136
- }
137
-
138
- /**
139
- * @param {BuildGraphResult['document_node_ids']} base_document_node_ids
140
- * @param {BuildGraphResult['nodes']} graph_nodes
141
- * @param {BuildGraphResult['document_node_ids']} overlay_document_node_ids
142
- * @returns {Record<string, string>}
143
- */
144
- function createDocumentNodeIds(
145
- base_document_node_ids,
146
- graph_nodes,
147
- overlay_document_node_ids,
148
- ) {
149
- /** @type {Record<string, string>} */
150
- const document_node_ids = {
151
- ...(base_document_node_ids ?? {}),
152
- };
153
-
154
- for (const graph_node of Object.values(graph_nodes)) {
155
- if (!graph_node.$path) {
156
- continue;
157
- }
158
-
159
- document_node_ids[graph_node.$path] = graph_node.id;
160
- }
161
-
162
- return {
163
- ...document_node_ids,
164
- ...(overlay_document_node_ids ?? {}),
165
- };
166
- }
167
-
168
- /**
169
- * @param {BuildGraphResult['nodes']} graph_nodes
170
- * @param {Record<string, string>} document_node_ids
171
- */
172
- function attachDocumentNodeAliases(graph_nodes, document_node_ids) {
173
- for (const [document_path, node_id] of Object.entries(document_node_ids)) {
174
- if (`doc:${document_path}` === node_id) {
175
- continue;
176
- }
177
-
178
- const graph_node = graph_nodes[node_id];
179
-
180
- if (!graph_node) {
181
- continue;
182
- }
183
-
184
- Object.defineProperty(graph_nodes, `doc:${document_path}`, {
185
- configurable: false,
186
- enumerable: false,
187
- value: graph_node,
188
- writable: false,
189
- });
190
- }
191
- }
@@ -1,41 +0,0 @@
1
- import type { PatramDiagnostic } from './load-patram-config.types.ts';
2
-
3
- export type MarkdownDirectiveStyle =
4
- | 'front_matter'
5
- | 'visible_line'
6
- | 'list_item'
7
- | 'hidden_tag';
8
-
9
- export interface ParseClaimsInput {
10
- path: string;
11
- source: string;
12
- }
13
-
14
- export interface ClaimOrigin {
15
- path: string;
16
- line: number;
17
- column: number;
18
- }
19
-
20
- export interface PatramClaim {
21
- document_id: string;
22
- id: string;
23
- markdown_style?: MarkdownDirectiveStyle;
24
- name?: string;
25
- origin: ClaimOrigin;
26
- parser?: string;
27
- type: string;
28
- value: string | { target: string; text: string };
29
- }
30
-
31
- export type PatramClaimFields = Omit<
32
- PatramClaim,
33
- 'document_id' | 'id' | 'origin' | 'type'
34
- > & {
35
- origin?: ClaimOrigin;
36
- };
37
-
38
- export interface ParseSourceFileResult {
39
- claims: PatramClaim[];
40
- diagnostics: PatramDiagnostic[];
41
- }
@@ -1,69 +0,0 @@
1
- export type CliCommandName = 'check' | 'fields' | 'query' | 'queries' | 'show';
2
- export type CliHelpTopicName = 'query-language';
3
- export type CliHelpTargetKind = 'root' | 'command' | 'topic';
4
-
5
- export type CliOutputMode = 'default' | 'plain' | 'json';
6
-
7
- export type CliColorMode = 'auto' | 'always' | 'never';
8
-
9
- export interface ParsedCliCommandRequest {
10
- kind?: 'command';
11
- color_mode: CliColorMode;
12
- command_arguments: string[];
13
- command_name: CliCommandName;
14
- output_mode: CliOutputMode;
15
- query_inspection_mode?: 'explain' | 'lint';
16
- query_limit?: number;
17
- query_offset?: number;
18
- }
19
-
20
- export interface ParsedCliHelpRequest {
21
- kind: 'help';
22
- target_kind: CliHelpTargetKind;
23
- target_name?: CliCommandName | CliHelpTopicName;
24
- }
25
-
26
- export type ParsedCliArguments = ParsedCliCommandRequest;
27
- export type ParsedCliRequest = ParsedCliCommandRequest | ParsedCliHelpRequest;
28
-
29
- export type CliParseError =
30
- | {
31
- code: 'message';
32
- message: string;
33
- }
34
- | {
35
- code: 'missing_required_argument';
36
- argument_label: string;
37
- command_name: 'query' | 'show';
38
- }
39
- | {
40
- code: 'option_not_valid_for_command';
41
- command_name: CliCommandName;
42
- token: string;
43
- }
44
- | {
45
- code: 'unknown_command';
46
- suggestion?: CliCommandName;
47
- token: string;
48
- }
49
- | {
50
- code: 'unknown_help_target';
51
- suggestion?: CliCommandName | CliHelpTopicName;
52
- token: string;
53
- }
54
- | {
55
- code: 'unknown_option';
56
- command_name?: CliCommandName;
57
- suggestion?: string;
58
- token: string;
59
- };
60
-
61
- export type ParseCliArgumentsResult =
62
- | {
63
- success: true;
64
- value: ParsedCliRequest;
65
- }
66
- | {
67
- error: CliParseError;
68
- success: false;
69
- };