patram 0.6.2 → 0.7.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 (39) hide show
  1. package/lib/build-graph-identity.d.ts +40 -0
  2. package/lib/build-graph.d.ts +11 -0
  3. package/lib/build-graph.types.d.ts +24 -0
  4. package/lib/claim-helpers.d.ts +20 -0
  5. package/lib/document-node-identity.d.ts +47 -0
  6. package/lib/list-source-files.d.ts +29 -0
  7. package/lib/load-patram-config.d.ts +384 -0
  8. package/lib/load-patram-config.types.d.ts +45 -0
  9. package/lib/load-project-graph.d.ts +35 -0
  10. package/lib/output-view.types.d.ts +80 -0
  11. package/lib/overlay-graph.d.ts +43 -0
  12. package/lib/overlay-graph.js +191 -0
  13. package/lib/parse-claims.d.ts +40 -0
  14. package/lib/parse-claims.types.d.ts +31 -0
  15. package/lib/parse-jsdoc-blocks.d.ts +15 -0
  16. package/lib/parse-jsdoc-claims.d.ts +9 -0
  17. package/lib/parse-jsdoc-prose.d.ts +28 -0
  18. package/lib/parse-markdown-claims.d.ts +14 -0
  19. package/lib/parse-markdown-directives.d.ts +34 -0
  20. package/lib/parse-where-clause.d.ts +75 -0
  21. package/lib/parse-where-clause.js +157 -37
  22. package/lib/parse-where-clause.types.d.ts +63 -0
  23. package/lib/parse-yaml-claims.d.ts +38 -0
  24. package/lib/patram-config.d.ts +106 -0
  25. package/lib/patram-config.types.d.ts +14 -0
  26. package/lib/patram.d.ts +73 -0
  27. package/lib/patram.js +3 -0
  28. package/lib/query-graph.d.ts +68 -0
  29. package/lib/query-graph.js +27 -24
  30. package/lib/query-inspection.d.ts +86 -0
  31. package/lib/resolve-patram-graph-config.d.ts +9 -0
  32. package/lib/source-file-defaults.d.ts +5 -0
  33. package/lib/tagged-fenced-block-error.d.ts +10 -0
  34. package/lib/tagged-fenced-block-markdown.d.ts +47 -0
  35. package/lib/tagged-fenced-block-metadata.d.ts +26 -0
  36. package/lib/tagged-fenced-block-parser.d.ts +61 -0
  37. package/lib/tagged-fenced-blocks.d.ts +39 -0
  38. package/lib/tagged-fenced-blocks.types.d.ts +32 -0
  39. package/package.json +13 -2
@@ -14,38 +14,51 @@
14
14
  */
15
15
 
16
16
  /**
17
- * @typedef {{ index: number, where_clause: string }} ParserState
17
+ * @typedef {{ bindings: Record<string, string>, index: number, where_clause: string }} ParserState
18
18
  */
19
19
 
20
20
  /**
21
21
  * @typedef {{
22
- * expression: ParsedExpression,
23
- * success: true,
24
- * } | {
25
22
  * diagnostic: PatramDiagnostic,
26
23
  * success: false,
27
- * }} ParseExpressionResult
24
+ * }} ParseFailureResult
25
+ */
26
+
27
+ /**
28
+ * @typedef {{
29
+ * expression: ParsedExpression,
30
+ * success: true,
31
+ * } | ParseFailureResult} ParseExpressionResult
28
32
  */
29
33
 
30
34
  /**
31
35
  * @typedef {{
32
36
  * success: true,
33
37
  * term: ParsedTerm,
34
- * } | {
35
- * diagnostic: PatramDiagnostic,
36
- * success: false,
37
- * }} ParseTermResult
38
+ * } | ParseFailureResult} ParseTermResult
39
+ */
40
+
41
+ /**
42
+ * @typedef {{
43
+ * success: true,
44
+ * value: string,
45
+ * } | ParseFailureResult} ParseValueResult
38
46
  */
39
47
 
40
48
  /**
41
49
  * Parse one where clause into a structured boolean expression.
42
50
  *
43
51
  * @param {string} where_clause
52
+ * @param {{ bindings?: Record<string, string> }=} options
44
53
  * @returns {ParseWhereClauseResult}
45
54
  */
46
- export function parseWhereClause(where_clause) {
55
+ export function parseWhereClause(where_clause, options = {}) {
47
56
  /** @type {ParserState} */
48
- const parser_state = { index: 0, where_clause };
57
+ const parser_state = {
58
+ bindings: options.bindings ?? {},
59
+ index: 0,
60
+ where_clause,
61
+ };
49
62
 
50
63
  skipWhitespace(parser_state);
51
64
 
@@ -429,15 +442,21 @@ function parseFieldSet(parser_state, start_index, field_name) {
429
442
 
430
443
  const values = parseList(parser_state);
431
444
 
432
- return values
433
- ? successTerm({
434
- column: start_index + 1,
435
- field_name,
436
- kind: 'field_set',
437
- operator,
438
- values,
439
- })
440
- : failToken(parser_state);
445
+ if (!values) {
446
+ return failToken(parser_state);
447
+ }
448
+
449
+ if (!Array.isArray(values)) {
450
+ return values;
451
+ }
452
+
453
+ return successTerm({
454
+ column: start_index + 1,
455
+ field_name,
456
+ kind: 'field_set',
457
+ operator,
458
+ values,
459
+ });
441
460
  }
442
461
 
443
462
  /**
@@ -582,15 +601,23 @@ function parsePrefixTerm(parser_state, start_index, field_name) {
582
601
  }
583
602
 
584
603
  skipWhitespace(parser_state);
585
- const value = parseBareValue(parser_state);
604
+ const value_result = parseResolvedBareValue(parser_state);
605
+
606
+ if (!value_result) {
607
+ return failToken(parser_state);
608
+ }
586
609
 
587
- return value
610
+ if (!value_result.success) {
611
+ return value_result;
612
+ }
613
+
614
+ return value_result.value
588
615
  ? successTerm({
589
616
  column: start_index + 1,
590
617
  field_name,
591
618
  kind: 'field',
592
619
  operator: '^=',
593
- value,
620
+ value: value_result.value,
594
621
  })
595
622
  : failToken(parser_state);
596
623
  }
@@ -607,15 +634,23 @@ function parseContainsTerm(parser_state, start_index, field_name) {
607
634
  }
608
635
 
609
636
  skipWhitespace(parser_state);
610
- const value = parseBareValue(parser_state);
637
+ const value_result = parseResolvedBareValue(parser_state);
638
+
639
+ if (!value_result) {
640
+ return failToken(parser_state);
641
+ }
642
+
643
+ if (!value_result.success) {
644
+ return value_result;
645
+ }
611
646
 
612
- return value
647
+ return value_result.value
613
648
  ? successTerm({
614
649
  column: start_index + 1,
615
650
  field_name,
616
651
  kind: 'field',
617
652
  operator: '~',
618
- value,
653
+ value: value_result.value,
619
654
  })
620
655
  : failToken(parser_state);
621
656
  }
@@ -632,12 +667,18 @@ function parseEqualityTerm(parser_state, start_index, field_or_relation_name) {
632
667
  }
633
668
 
634
669
  skipWhitespace(parser_state);
635
- const value = parseBareValue(parser_state);
670
+ const value_result = parseResolvedBareValue(parser_state);
636
671
 
637
- if (!value) {
672
+ if (!value_result) {
638
673
  return failToken(parser_state);
639
674
  }
640
675
 
676
+ if (!value_result.success) {
677
+ return value_result;
678
+ }
679
+
680
+ const value = value_result.value;
681
+
641
682
  if (
642
683
  field_or_relation_name.startsWith('$') ||
643
684
  field_or_relation_name === 'title' ||
@@ -674,18 +715,22 @@ function parseFieldComparisonTerm(parser_state, start_index, field_name) {
674
715
  }
675
716
 
676
717
  skipWhitespace(parser_state);
677
- const value = parseBareValue(parser_state);
718
+ const value_result = parseResolvedBareValue(parser_state);
678
719
 
679
- if (!value) {
720
+ if (!value_result) {
680
721
  return failToken(parser_state);
681
722
  }
682
723
 
724
+ if (!value_result.success) {
725
+ return value_result;
726
+ }
727
+
683
728
  return successTerm({
684
729
  column: start_index + 1,
685
730
  field_name,
686
731
  kind: 'field',
687
732
  operator,
688
- value,
733
+ value: value_result.value,
689
734
  });
690
735
  }
691
736
 
@@ -704,7 +749,7 @@ function parseFieldComparisonOperator(parser_state) {
704
749
 
705
750
  /**
706
751
  * @param {ParserState} parser_state
707
- * @returns {string[] | null}
752
+ * @returns {string[] | ParseFailureResult | null}
708
753
  */
709
754
  function parseList(parser_state) {
710
755
  if (!consumeOperator(parser_state, '[')) {
@@ -721,13 +766,17 @@ function parseList(parser_state) {
721
766
  return values.length > 0 ? values : null;
722
767
  }
723
768
 
724
- const list_value = parseListValue(parser_state);
769
+ const list_value_result = parseResolvedListValue(parser_state);
725
770
 
726
- if (!list_value) {
771
+ if (!list_value_result) {
727
772
  return null;
728
773
  }
729
774
 
730
- values.push(list_value);
775
+ if (!list_value_result.success) {
776
+ return list_value_result;
777
+ }
778
+
779
+ values.push(list_value_result.value);
731
780
  skipWhitespace(parser_state);
732
781
 
733
782
  if (consumeOperator(parser_state, ']')) {
@@ -787,6 +836,76 @@ function parseListValue(parser_state) {
787
836
  return list_value?.trim() || null;
788
837
  }
789
838
 
839
+ /**
840
+ * @param {ParserState} parser_state
841
+ * @returns {ParseValueResult | null}
842
+ */
843
+ function parseResolvedBareValue(parser_state) {
844
+ const start_index = parser_state.index;
845
+ const raw_value = parseBareValue(parser_state);
846
+
847
+ if (!raw_value) {
848
+ return null;
849
+ }
850
+
851
+ return resolveBindingValue(parser_state, raw_value, start_index);
852
+ }
853
+
854
+ /**
855
+ * @param {ParserState} parser_state
856
+ * @returns {ParseValueResult | null}
857
+ */
858
+ function parseResolvedListValue(parser_state) {
859
+ const start_index = parser_state.index;
860
+ const raw_value = parseListValue(parser_state);
861
+
862
+ if (!raw_value) {
863
+ return null;
864
+ }
865
+
866
+ return resolveBindingValue(parser_state, raw_value, start_index);
867
+ }
868
+
869
+ /**
870
+ * @param {ParserState} parser_state
871
+ * @param {string} raw_value
872
+ * @param {number} start_index
873
+ * @returns {ParseValueResult}
874
+ */
875
+ function resolveBindingValue(parser_state, raw_value, start_index) {
876
+ if (!raw_value.startsWith('@')) {
877
+ return {
878
+ success: true,
879
+ value: raw_value,
880
+ };
881
+ }
882
+
883
+ const binding_name = raw_value.slice(1);
884
+
885
+ if (!/^[a-z_][a-z0-9_]*$/u.test(binding_name)) {
886
+ return fail(
887
+ start_index + 1,
888
+ `Unsupported query binding "${raw_value}".`,
889
+ 'query.invalid',
890
+ );
891
+ }
892
+
893
+ const binding_value = parser_state.bindings[binding_name];
894
+
895
+ if (binding_value === undefined) {
896
+ return fail(
897
+ start_index + 1,
898
+ `Missing query binding "${binding_name}".`,
899
+ 'query.binding_missing',
900
+ );
901
+ }
902
+
903
+ return {
904
+ success: true,
905
+ value: binding_value,
906
+ };
907
+ }
908
+
790
909
  /**
791
910
  * @param {ParserState} parser_state
792
911
  * @param {RegExp} pattern
@@ -918,12 +1037,13 @@ function failExpectedTerm(parser_state) {
918
1037
  /**
919
1038
  * @param {number} column
920
1039
  * @param {string} message
1040
+ * @param {string} code
921
1041
  * @returns {{ diagnostic: PatramDiagnostic, success: false }}
922
1042
  */
923
- function fail(column, message) {
1043
+ function fail(column, message, code = 'query.invalid') {
924
1044
  return {
925
1045
  diagnostic: {
926
- code: 'query.invalid',
1046
+ code,
927
1047
  column,
928
1048
  level: 'error',
929
1049
  line: 1,
@@ -0,0 +1,63 @@
1
+ import type { PatramDiagnostic } from './load-patram-config.types.ts';
2
+ export type ParsedFieldName = string;
3
+ export interface ParsedFieldTerm {
4
+ column: number;
5
+ field_name: ParsedFieldName;
6
+ kind: 'field';
7
+ operator: '!=' | '<' | '<=' | '=' | '>' | '>=' | '^=' | '~';
8
+ value: string;
9
+ }
10
+ export interface ParsedFieldSetTerm {
11
+ column: number;
12
+ field_name: ParsedFieldName;
13
+ kind: 'field_set';
14
+ operator: 'in' | 'not in';
15
+ values: string[];
16
+ }
17
+ export interface ParsedTraversalTerm {
18
+ column: number;
19
+ direction: 'in' | 'out';
20
+ relation_name: string;
21
+ }
22
+ export interface ParsedRelationTerm {
23
+ column: number;
24
+ kind: 'relation';
25
+ relation_name: string;
26
+ }
27
+ export interface ParsedRelationTargetTerm {
28
+ column: number;
29
+ kind: 'relation_target';
30
+ relation_name: string;
31
+ target_id: string;
32
+ }
33
+ export type ParsedAggregateComparison = '!=' | '<' | '<=' | '=' | '>' | '>=';
34
+ export type ParsedAggregateName = 'any' | 'count' | 'none';
35
+ export interface ParsedAggregateTerm {
36
+ aggregate_name: ParsedAggregateName;
37
+ comparison?: ParsedAggregateComparison;
38
+ expression: ParsedExpression;
39
+ kind: 'aggregate';
40
+ traversal: ParsedTraversalTerm;
41
+ value?: number;
42
+ }
43
+ export interface ParsedTermExpression {
44
+ kind: 'term';
45
+ term: ParsedTerm;
46
+ }
47
+ export interface ParsedNotExpression {
48
+ expression: ParsedExpression;
49
+ kind: 'not';
50
+ }
51
+ export interface ParsedBooleanExpression {
52
+ expressions: ParsedExpression[];
53
+ kind: 'and' | 'or';
54
+ }
55
+ export type ParsedTerm = ParsedAggregateTerm | ParsedFieldSetTerm | ParsedFieldTerm | ParsedRelationTargetTerm | ParsedRelationTerm;
56
+ export type ParsedExpression = ParsedBooleanExpression | ParsedNotExpression | ParsedTermExpression;
57
+ export type ParseWhereClauseResult = {
58
+ expression: ParsedExpression;
59
+ success: true;
60
+ } | {
61
+ diagnostic: PatramDiagnostic;
62
+ success: false;
63
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Parse standalone YAML source into neutral directive claims.
3
+ *
4
+ * @param {ParseClaimsInput} parse_input
5
+ * @param {{ multi_value_directive_names?: ReadonlySet<string> }} [parse_options]
6
+ * @returns {ParseSourceFileResult}
7
+ */
8
+ export function parseYamlClaims(parse_input: ParseClaimsInput, parse_options?: {
9
+ multi_value_directive_names?: ReadonlySet<string>;
10
+ }): ParseSourceFileResult;
11
+ /**
12
+ * Parse YAML metadata into neutral directive fields.
13
+ *
14
+ * @param {{
15
+ * file_path: string,
16
+ * parser: 'markdown' | 'yaml',
17
+ * source_text: string,
18
+ * start_line: number,
19
+ * markdown_style?: 'front_matter',
20
+ * multi_value_directive_names?: ReadonlySet<string>,
21
+ * }} parse_input
22
+ * @returns {{ diagnostics: PatramDiagnostic[], directive_fields: PatramClaimFields[] }}
23
+ */
24
+ export function parseYamlDirectiveFields(parse_input: {
25
+ file_path: string;
26
+ parser: "markdown" | "yaml";
27
+ source_text: string;
28
+ start_line: number;
29
+ markdown_style?: "front_matter";
30
+ multi_value_directive_names?: ReadonlySet<string>;
31
+ }): {
32
+ diagnostics: PatramDiagnostic[];
33
+ directive_fields: PatramClaimFields[];
34
+ };
35
+ import type { ParseClaimsInput } from './parse-claims.types.ts';
36
+ import type { ParseSourceFileResult } from './parse-claims.types.ts';
37
+ import type { PatramDiagnostic } from './load-patram-config.types.ts';
38
+ import type { PatramClaimFields } from './parse-claims.types.ts';
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Parse and validate Patram JSON configuration.
3
+ *
4
+ * @param {unknown} config_json
5
+ * @returns {PatramGraphConfig}
6
+ */
7
+ export function parsePatramConfig(config_json: unknown): PatramGraphConfig;
8
+ /**
9
+ * @typedef {z.output<typeof class_definition_schema>} ClassDefinition
10
+ */
11
+ export const class_definition_schema: z.ZodObject<{
12
+ builtin: z.ZodOptional<z.ZodBoolean>;
13
+ label: z.ZodOptional<z.ZodString>;
14
+ }, z.core.$strict>;
15
+ /**
16
+ * @typedef {z.output<typeof relation_definition_schema>} RelationDefinition
17
+ */
18
+ export const relation_definition_schema: z.ZodObject<{
19
+ builtin: z.ZodOptional<z.ZodBoolean>;
20
+ from: z.ZodArray<z.ZodString>;
21
+ to: z.ZodArray<z.ZodString>;
22
+ }, z.core.$strict>;
23
+ /**
24
+ * @typedef {z.output<typeof mapping_definition_schema>} MappingDefinition
25
+ */
26
+ export const mapping_definition_schema: z.ZodObject<{
27
+ emit: z.ZodOptional<z.ZodObject<{
28
+ relation: z.ZodString;
29
+ target: z.ZodEnum<{
30
+ path: "path";
31
+ value: "value";
32
+ }>;
33
+ target_class: z.ZodString;
34
+ }, z.core.$strict>>;
35
+ node: z.ZodOptional<z.ZodObject<{
36
+ class: z.ZodString;
37
+ field: z.ZodString;
38
+ key: z.ZodOptional<z.ZodEnum<{
39
+ path: "path";
40
+ value: "value";
41
+ }>>;
42
+ }, z.core.$strict>>;
43
+ }, z.core.$strict>;
44
+ /**
45
+ * @typedef {z.output<typeof patramConfigSchema>} PatramGraphConfig
46
+ */
47
+ export const patramConfigSchema: z.ZodObject<{
48
+ $schema: z.ZodOptional<z.ZodURL>;
49
+ classes: z.ZodRecord<z.ZodString, z.ZodObject<{
50
+ builtin: z.ZodOptional<z.ZodBoolean>;
51
+ label: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$strict>>;
53
+ mappings: z.ZodRecord<z.ZodString, z.ZodObject<{
54
+ emit: z.ZodOptional<z.ZodObject<{
55
+ relation: z.ZodString;
56
+ target: z.ZodEnum<{
57
+ path: "path";
58
+ value: "value";
59
+ }>;
60
+ target_class: z.ZodString;
61
+ }, z.core.$strict>>;
62
+ node: z.ZodOptional<z.ZodObject<{
63
+ class: z.ZodString;
64
+ field: z.ZodString;
65
+ key: z.ZodOptional<z.ZodEnum<{
66
+ path: "path";
67
+ value: "value";
68
+ }>>;
69
+ }, z.core.$strict>>;
70
+ }, z.core.$strict>>;
71
+ relations: z.ZodRecord<z.ZodString, z.ZodObject<{
72
+ builtin: z.ZodOptional<z.ZodBoolean>;
73
+ from: z.ZodArray<z.ZodString>;
74
+ to: z.ZodArray<z.ZodString>;
75
+ }, z.core.$strict>>;
76
+ }, z.core.$strict>;
77
+ export type ClassDefinition = z.output<typeof class_definition_schema>;
78
+ export type RelationDefinition = z.output<typeof relation_definition_schema>;
79
+ export type MappingNodeDefinition = z.output<typeof mapping_node_schema>;
80
+ export type MappingEmitDefinition = z.output<typeof mapping_emit_schema>;
81
+ export type MappingDefinition = z.output<typeof mapping_definition_schema>;
82
+ export type PatramGraphConfig = z.output<typeof patramConfigSchema>;
83
+ import { z } from 'zod';
84
+ /**
85
+ * @typedef {z.output<typeof mapping_node_schema>} MappingNodeDefinition
86
+ */
87
+ declare const mapping_node_schema: z.ZodObject<{
88
+ class: z.ZodString;
89
+ field: z.ZodString;
90
+ key: z.ZodOptional<z.ZodEnum<{
91
+ path: "path";
92
+ value: "value";
93
+ }>>;
94
+ }, z.core.$strict>;
95
+ /**
96
+ * @typedef {z.output<typeof mapping_emit_schema>} MappingEmitDefinition
97
+ */
98
+ declare const mapping_emit_schema: z.ZodObject<{
99
+ relation: z.ZodString;
100
+ target: z.ZodEnum<{
101
+ path: "path";
102
+ value: "value";
103
+ }>;
104
+ target_class: z.ZodString;
105
+ }, z.core.$strict>;
106
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { ClassSchemaConfig, MetadataFieldConfig } from './load-patram-config.types.ts';
2
+ export type ClassDefinition = import('./patram-config.js').ClassDefinition;
3
+ export type RelationDefinition = import('./patram-config.js').RelationDefinition;
4
+ export type MappingNodeDefinition = import('./patram-config.js').MappingNodeDefinition;
5
+ export type MappingEmitDefinition = import('./patram-config.js').MappingEmitDefinition;
6
+ export type MappingDefinition = import('./patram-config.js').MappingDefinition;
7
+ export type PatramGraphConfig = import('./patram-config.js').PatramGraphConfig;
8
+ export type PatramClassConfig = ClassDefinition & {
9
+ schema?: ClassSchemaConfig;
10
+ };
11
+ export type PatramConfig = Omit<PatramGraphConfig, 'classes'> & {
12
+ classes: Record<string, PatramClassConfig>;
13
+ fields?: Record<string, MetadataFieldConfig>;
14
+ };
@@ -0,0 +1,73 @@
1
+ export {
2
+ extractTaggedFencedBlocks,
3
+ loadTaggedFencedBlocks,
4
+ selectTaggedBlock,
5
+ selectTaggedBlocks,
6
+ } from './tagged-fenced-blocks.js';
7
+
8
+ export { parseWhereClause } from './parse-where-clause.js';
9
+ export { getQuerySemanticDiagnostics } from './query-inspection.js';
10
+ export { loadProjectGraph } from './load-project-graph.js';
11
+ export { overlayGraph } from './overlay-graph.js';
12
+ export { queryGraph } from './query-graph.js';
13
+
14
+ export type PatramGraphNode = import('./build-graph.types.ts').GraphNode;
15
+ export type PatramGraphEdge = import('./build-graph.types.ts').GraphEdge;
16
+ export type PatramBuildGraphResult =
17
+ import('./build-graph.types.ts').BuildGraphResult;
18
+ export type PatramDiagnostic =
19
+ import('./load-patram-config.types.ts').PatramDiagnostic;
20
+ export type PatramRepoConfig =
21
+ import('./load-patram-config.types.ts').PatramRepoConfig;
22
+ export type PatramParsedFieldName =
23
+ import('./parse-where-clause.types.ts').ParsedFieldName;
24
+ export type PatramParsedFieldTerm =
25
+ import('./parse-where-clause.types.ts').ParsedFieldTerm;
26
+ export type PatramParsedFieldSetTerm =
27
+ import('./parse-where-clause.types.ts').ParsedFieldSetTerm;
28
+ export type PatramParsedTraversalTerm =
29
+ import('./parse-where-clause.types.ts').ParsedTraversalTerm;
30
+ export type PatramParsedRelationTerm =
31
+ import('./parse-where-clause.types.ts').ParsedRelationTerm;
32
+ export type PatramParsedRelationTargetTerm =
33
+ import('./parse-where-clause.types.ts').ParsedRelationTargetTerm;
34
+ export type PatramParsedAggregateComparison =
35
+ import('./parse-where-clause.types.ts').ParsedAggregateComparison;
36
+ export type PatramParsedAggregateName =
37
+ import('./parse-where-clause.types.ts').ParsedAggregateName;
38
+ export type PatramParsedAggregateTerm =
39
+ import('./parse-where-clause.types.ts').ParsedAggregateTerm;
40
+ export type PatramParsedTermExpression =
41
+ import('./parse-where-clause.types.ts').ParsedTermExpression;
42
+ export type PatramParsedNotExpression =
43
+ import('./parse-where-clause.types.ts').ParsedNotExpression;
44
+ export type PatramParsedBooleanExpression =
45
+ import('./parse-where-clause.types.ts').ParsedBooleanExpression;
46
+ export type PatramParsedTerm =
47
+ import('./parse-where-clause.types.ts').ParsedTerm;
48
+ export type PatramParsedExpression =
49
+ import('./parse-where-clause.types.ts').ParsedExpression;
50
+ export type PatramParseWhereClauseResult =
51
+ import('./parse-where-clause.types.ts').ParseWhereClauseResult;
52
+ export type PatramQuerySource =
53
+ | {
54
+ kind: 'ad_hoc';
55
+ }
56
+ | {
57
+ kind: 'stored_query';
58
+ name: string;
59
+ };
60
+
61
+ export interface PatramProjectGraphResult {
62
+ claims: import('./parse-claims.types.ts').PatramClaim[];
63
+ config: import('./load-patram-config.types.ts').PatramRepoConfig;
64
+ diagnostics: PatramDiagnostic[];
65
+ graph: PatramBuildGraphResult;
66
+ source_file_paths: string[];
67
+ }
68
+
69
+ export interface PatramQueryResult {
70
+ diagnostics: PatramDiagnostic[];
71
+ nodes: PatramGraphNode[];
72
+ total_count: number;
73
+ }
package/lib/patram.js CHANGED
@@ -5,5 +5,8 @@ export {
5
5
  selectTaggedBlocks,
6
6
  } from './tagged-fenced-blocks.js';
7
7
 
8
+ export { parseWhereClause } from './parse-where-clause.js';
9
+ export { getQuerySemanticDiagnostics } from './query-inspection.js';
8
10
  export { loadProjectGraph } from './load-project-graph.js';
11
+ export { overlayGraph } from './overlay-graph.js';
9
12
  export { queryGraph } from './query-graph.js';
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @typedef {{
3
+ * incoming: Map<string, Map<string, Set<string>>>,
4
+ * outgoing: Map<string, Map<string, Set<string>>>,
5
+ * }} RelationIndexes
6
+ */
7
+ /**
8
+ * @typedef {{
9
+ * bindings?: Record<string, string>,
10
+ * limit?: number,
11
+ * offset?: number,
12
+ * }} QueryGraphOptions
13
+ */
14
+ /**
15
+ * @typedef {{
16
+ * nodes: BuildGraphResult['nodes'],
17
+ * relation_indexes: RelationIndexes,
18
+ * }} EvaluationContext
19
+ */
20
+ /**
21
+ * Filter graph nodes with the query language.
22
+ *
23
+ * @param {BuildGraphResult} graph
24
+ * @param {string} where_clause
25
+ * @param {PatramRepoConfig | QueryGraphOptions=} repo_config_or_query_options
26
+ * @param {QueryGraphOptions=} query_options
27
+ * @returns {{ diagnostics: PatramDiagnostic[], nodes: GraphNode[], total_count: number }}
28
+ */
29
+ export function queryGraph(graph: BuildGraphResult, where_clause: string, repo_config_or_query_options?: (PatramRepoConfig | QueryGraphOptions) | undefined, query_options?: QueryGraphOptions | undefined): {
30
+ diagnostics: PatramDiagnostic[];
31
+ nodes: GraphNode[];
32
+ total_count: number;
33
+ };
34
+ /**
35
+ * Query graph filtering.
36
+ *
37
+ * Applies the v0 where-clause language to graph nodes and keeps pagination
38
+ * separate from matching.
39
+ *
40
+ * Kind: graph
41
+ * Status: active
42
+ * Uses Term: ../docs/reference/terms/graph.md
43
+ * Uses Term: ../docs/reference/terms/query.md
44
+ * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
45
+ * Decided by: ../docs/decisions/query-language.md
46
+ * Implements: ../docs/tasks/v0/query-command.md
47
+ * @patram
48
+ * @see {@link ./load-project-graph.js}
49
+ * @see {@link ../docs/decisions/query-language.md}
50
+ */
51
+ export const DEFAULT_QUERY_LIMIT: 25;
52
+ export type RelationIndexes = {
53
+ incoming: Map<string, Map<string, Set<string>>>;
54
+ outgoing: Map<string, Map<string, Set<string>>>;
55
+ };
56
+ export type QueryGraphOptions = {
57
+ bindings?: Record<string, string>;
58
+ limit?: number;
59
+ offset?: number;
60
+ };
61
+ export type EvaluationContext = {
62
+ nodes: BuildGraphResult["nodes"];
63
+ relation_indexes: RelationIndexes;
64
+ };
65
+ import type { BuildGraphResult } from './build-graph.types.ts';
66
+ import type { PatramRepoConfig } from './load-patram-config.types.ts';
67
+ import type { PatramDiagnostic } from './load-patram-config.types.ts';
68
+ import type { GraphNode } from './build-graph.types.ts';