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
@@ -1,5 +1,5 @@
1
1
  import type {
2
- KindDefinition,
2
+ ClassDefinition,
3
3
  MappingDefinition,
4
4
  RelationDefinition,
5
5
  } from './patram-config.types.ts';
@@ -8,10 +8,136 @@ export interface StoredQueryConfig {
8
8
  where: string;
9
9
  }
10
10
 
11
+ export type FieldValueTypeName =
12
+ | 'string'
13
+ | 'integer'
14
+ | 'enum'
15
+ | 'path'
16
+ | 'glob'
17
+ | 'date'
18
+ | 'date_time';
19
+
20
+ export interface FieldDisplayConfig {
21
+ hidden?: boolean;
22
+ order?: number;
23
+ }
24
+
25
+ export interface FieldQueryConfig {
26
+ contains?: boolean;
27
+ prefix?: boolean;
28
+ }
29
+
30
+ export interface StringFieldConfig {
31
+ display?: FieldDisplayConfig;
32
+ multiple?: boolean;
33
+ query?: FieldQueryConfig;
34
+ type: 'string';
35
+ }
36
+
37
+ export interface IntegerFieldConfig {
38
+ display?: FieldDisplayConfig;
39
+ multiple?: boolean;
40
+ type: 'integer';
41
+ }
42
+
43
+ export interface EnumFieldConfig {
44
+ display?: FieldDisplayConfig;
45
+ multiple?: boolean;
46
+ type: 'enum';
47
+ values: string[];
48
+ }
49
+
50
+ export interface PathFieldConfig {
51
+ display?: FieldDisplayConfig;
52
+ multiple?: boolean;
53
+ path_class?: string;
54
+ type: 'path';
55
+ }
56
+
57
+ export interface GlobFieldConfig {
58
+ display?: FieldDisplayConfig;
59
+ multiple?: boolean;
60
+ type: 'glob';
61
+ }
62
+
63
+ export interface DateFieldConfig {
64
+ display?: FieldDisplayConfig;
65
+ multiple?: boolean;
66
+ type: 'date';
67
+ }
68
+
69
+ export interface DateTimeFieldConfig {
70
+ display?: FieldDisplayConfig;
71
+ multiple?: boolean;
72
+ type: 'date_time';
73
+ }
74
+
75
+ export type MetadataFieldConfig =
76
+ | DateFieldConfig
77
+ | DateTimeFieldConfig
78
+ | EnumFieldConfig
79
+ | GlobFieldConfig
80
+ | IntegerFieldConfig
81
+ | PathFieldConfig
82
+ | StringFieldConfig;
83
+
84
+ export interface ClassFieldRuleConfig {
85
+ presence: 'required' | 'optional' | 'forbidden';
86
+ }
87
+
88
+ export type DirectiveTypeConfig = MetadataFieldConfig;
89
+ export type MetadataDirectiveRuleConfig = ClassFieldRuleConfig;
90
+
91
+ export interface ClassSchemaConfig {
92
+ document_path_class?: string;
93
+ fields: Record<string, ClassFieldRuleConfig>;
94
+ unknown_fields?: 'ignore' | 'error';
95
+ }
96
+
97
+ export type MetadataSchemaConfig = ClassSchemaConfig;
98
+
99
+ export interface PathClassConfig {
100
+ prefixes: string[];
101
+ }
102
+
103
+ export type DerivedSummaryScalar = boolean | number | string | null;
104
+
105
+ export interface DerivedSummaryCountFieldConfig {
106
+ count: {
107
+ traversal: string;
108
+ where: string;
109
+ };
110
+ name: string;
111
+ }
112
+
113
+ export interface DerivedSummarySelectCaseConfig {
114
+ value: DerivedSummaryScalar;
115
+ when: string;
116
+ }
117
+
118
+ export interface DerivedSummarySelectFieldConfig {
119
+ default: DerivedSummaryScalar;
120
+ name: string;
121
+ select: DerivedSummarySelectCaseConfig[];
122
+ }
123
+
124
+ export type DerivedSummaryFieldConfig =
125
+ | DerivedSummaryCountFieldConfig
126
+ | DerivedSummarySelectFieldConfig;
127
+
128
+ export interface DerivedSummaryConfig {
129
+ classes: string[];
130
+ fields: DerivedSummaryFieldConfig[];
131
+ }
132
+
11
133
  export interface PatramRepoConfig {
134
+ class_schemas?: Record<string, ClassSchemaConfig>;
135
+ classes?: Record<string, ClassDefinition>;
136
+ derived_summaries?: Record<string, DerivedSummaryConfig>;
137
+ fields?: Record<string, MetadataFieldConfig>;
12
138
  include: string[];
13
- kinds?: Record<string, KindDefinition>;
14
139
  mappings?: Record<string, MappingDefinition>;
140
+ path_classes?: Record<string, PathClassConfig>;
15
141
  queries: Record<string, StoredQueryConfig>;
16
142
  relations?: Record<string, RelationDefinition>;
17
143
  }
@@ -36,13 +36,14 @@ import { resolvePatramGraphConfig } from './resolve-patram-graph-config.js';
36
36
  * project directory.
37
37
  *
38
38
  * @param {string} project_directory
39
- * @returns {Promise<{ config: PatramRepoConfig, diagnostics: PatramDiagnostic[], graph: BuildGraphResult, source_file_paths: string[] }>}
39
+ * @returns {Promise<{ claims: PatramClaim[], config: PatramRepoConfig, diagnostics: PatramDiagnostic[], graph: BuildGraphResult, source_file_paths: string[] }>}
40
40
  */
41
41
  export async function loadProjectGraph(project_directory) {
42
42
  const load_result = await loadPatramConfig(project_directory);
43
43
 
44
44
  if (load_result.diagnostics.length > 0) {
45
45
  return {
46
+ claims: [],
46
47
  config: {
47
48
  include: [],
48
49
  queries: {},
@@ -74,6 +75,7 @@ export async function loadProjectGraph(project_directory) {
74
75
 
75
76
  if (collect_result.diagnostics.length > 0) {
76
77
  return {
78
+ claims: collect_result.claims,
77
79
  config: repo_config,
78
80
  diagnostics: collect_result.diagnostics,
79
81
  graph: {
@@ -85,6 +87,7 @@ export async function loadProjectGraph(project_directory) {
85
87
  }
86
88
 
87
89
  return {
90
+ claims: collect_result.claims,
88
91
  config: repo_config,
89
92
  diagnostics: [],
90
93
  graph: buildGraph(graph_config, collect_result.claims),
@@ -1,5 +1,22 @@
1
1
  import type { GraphNode } from './build-graph.types.ts';
2
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
+
3
20
  export interface OutputViewSummary {
4
21
  count: number;
5
22
  kind: 'resolved_link_list' | 'result_list' | 'stored_query_list';
@@ -13,12 +30,14 @@ export interface QueryOutputViewSummary extends OutputViewSummary {
13
30
  }
14
31
 
15
32
  export interface OutputNodeItem {
33
+ derived_summary?: OutputDerivedSummary;
34
+ fields: Record<string, string | string[]>;
16
35
  id: string;
17
36
  kind: 'node';
18
- node_kind: GraphNode['kind'];
19
- path: string;
20
- status?: string;
37
+ node_kind: string;
38
+ path?: string;
21
39
  title: string;
40
+ visible_fields: OutputMetadataField[];
22
41
  }
23
42
 
24
43
  export interface OutputStoredQueryItem {
@@ -28,10 +47,13 @@ export interface OutputStoredQueryItem {
28
47
  }
29
48
 
30
49
  export interface OutputResolvedLinkTarget {
31
- kind?: string;
32
- path: string;
33
- status?: string;
50
+ derived_summary?: OutputDerivedSummary;
51
+ fields: Record<string, string | string[]>;
52
+ id: string;
53
+ kind: string;
54
+ path?: string;
34
55
  title: string;
56
+ visible_fields: OutputMetadataField[];
35
57
  }
36
58
 
37
59
  export interface OutputResolvedLinkItem {
@@ -57,6 +79,7 @@ export interface QueriesOutputView {
57
79
 
58
80
  export interface ShowOutputView {
59
81
  command: 'show';
82
+ document?: OutputNodeItem;
60
83
  hints: string[];
61
84
  items: OutputResolvedLinkItem[];
62
85
  path: string;