patram 0.10.0 → 0.12.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 (117) hide show
  1. package/bin/patram.js +4 -4
  2. package/lib/cli/arguments.types.d.ts +1 -0
  3. package/lib/cli/commands/check.js +27 -15
  4. package/lib/cli/commands/fields.js +0 -4
  5. package/lib/cli/commands/queries.js +179 -1
  6. package/lib/cli/commands/query.js +1 -8
  7. package/lib/cli/commands/refs.js +3 -10
  8. package/lib/cli/commands/show.js +1 -8
  9. package/lib/cli/help-metadata.js +106 -111
  10. package/lib/cli/main.js +10 -10
  11. package/lib/cli/parse-arguments-helpers.js +416 -66
  12. package/lib/cli/parse-arguments.js +4 -4
  13. package/lib/cli/render-help.js +10 -4
  14. package/lib/config/defaults.js +33 -25
  15. package/lib/config/load-patram-config.d.ts +19 -33
  16. package/lib/config/load-patram-config.js +18 -121
  17. package/lib/config/load-patram-config.types.d.ts +3 -40
  18. package/lib/config/manage-stored-queries-helpers.d.ts +69 -0
  19. package/lib/config/manage-stored-queries-helpers.js +320 -0
  20. package/lib/config/manage-stored-queries-jsonc.d.ts +31 -0
  21. package/lib/config/manage-stored-queries-jsonc.js +95 -0
  22. package/lib/config/manage-stored-queries.d.ts +77 -0
  23. package/lib/config/manage-stored-queries.js +300 -0
  24. package/lib/config/patram-config.d.ts +34 -34
  25. package/lib/config/patram-config.js +3 -3
  26. package/lib/config/patram-config.types.d.ts +5 -11
  27. package/lib/config/resolve-patram-graph-config.d.ts +5 -1
  28. package/lib/config/resolve-patram-graph-config.js +3 -119
  29. package/lib/config/schema.d.ts +158 -269
  30. package/lib/config/schema.js +72 -210
  31. package/lib/config/validate-patram-config-value.d.ts +13 -0
  32. package/lib/config/validate-patram-config-value.js +94 -0
  33. package/lib/config/validation.d.ts +2 -12
  34. package/lib/config/validation.js +125 -483
  35. package/lib/find-close-match.d.ts +4 -1
  36. package/lib/graph/build-graph-identity.d.ts +1 -32
  37. package/lib/graph/build-graph-identity.js +5 -269
  38. package/lib/graph/build-graph.d.ts +13 -4
  39. package/lib/graph/build-graph.js +347 -488
  40. package/lib/graph/build-graph.types.d.ts +8 -9
  41. package/lib/graph/check-directive-metadata-helpers.d.ts +30 -0
  42. package/lib/graph/check-directive-metadata-helpers.js +126 -0
  43. package/lib/graph/check-directive-metadata.d.ts +8 -9
  44. package/lib/graph/check-directive-metadata.js +70 -561
  45. package/lib/graph/check-directive-path-target.d.ts +6 -13
  46. package/lib/graph/check-directive-path-target.js +26 -57
  47. package/lib/graph/check-directive-value.d.ts +1 -5
  48. package/lib/graph/check-directive-value.js +40 -180
  49. package/lib/graph/check-graph.d.ts +5 -5
  50. package/lib/graph/check-graph.js +8 -6
  51. package/lib/graph/document-node-identity.d.ts +23 -7
  52. package/lib/graph/document-node-identity.js +417 -160
  53. package/lib/graph/graph-node.d.ts +42 -0
  54. package/lib/graph/graph-node.js +83 -0
  55. package/lib/graph/inspect-reverse-references.js +16 -11
  56. package/lib/graph/load-project-graph.d.ts +7 -7
  57. package/lib/graph/load-project-graph.js +7 -7
  58. package/lib/graph/parse-where-clause.types.d.ts +3 -2
  59. package/lib/graph/query/cypher-reader.d.ts +59 -0
  60. package/lib/graph/query/cypher-reader.js +151 -0
  61. package/lib/graph/query/cypher-support.d.ts +79 -0
  62. package/lib/graph/query/cypher-support.js +213 -0
  63. package/lib/graph/query/cypher-tokenize.d.ts +13 -0
  64. package/lib/graph/query/cypher-tokenize.js +225 -0
  65. package/lib/graph/query/cypher.types.d.ts +43 -0
  66. package/lib/graph/query/execute.d.ts +7 -7
  67. package/lib/graph/query/execute.js +71 -33
  68. package/lib/graph/query/inspect.js +58 -24
  69. package/lib/graph/query/parse-cypher-patterns.d.ts +27 -0
  70. package/lib/graph/query/parse-cypher-patterns.js +382 -0
  71. package/lib/graph/query/parse-cypher.d.ts +7 -0
  72. package/lib/graph/query/parse-cypher.js +580 -0
  73. package/lib/graph/query/parse-query.d.ts +13 -0
  74. package/lib/graph/query/parse-query.js +97 -0
  75. package/lib/graph/query/resolve.d.ts +6 -0
  76. package/lib/graph/query/resolve.js +81 -24
  77. package/lib/output/command-output.js +12 -5
  78. package/lib/output/compact-layout.js +221 -0
  79. package/lib/output/format-output-item-block.js +31 -1
  80. package/lib/output/format-output-metadata.js +16 -29
  81. package/lib/output/format-stored-query-block.js +95 -0
  82. package/lib/output/layout-incoming-references.js +101 -19
  83. package/lib/output/layout-stored-queries.js +23 -330
  84. package/lib/output/list-queries.js +1 -1
  85. package/lib/output/render-field-discovery.js +11 -2
  86. package/lib/output/render-output-view.js +9 -5
  87. package/lib/output/renderers/json.js +5 -26
  88. package/lib/output/renderers/plain.js +155 -35
  89. package/lib/output/renderers/rich.js +250 -36
  90. package/lib/output/resolve-check-target.js +120 -11
  91. package/lib/output/resolved-link-layout.js +43 -0
  92. package/lib/output/rich-source/render.js +193 -35
  93. package/lib/output/show-document.js +25 -18
  94. package/lib/output/view-model/index.js +124 -103
  95. package/lib/parse/jsdoc/parse-jsdoc-blocks.js +1 -1
  96. package/lib/parse/jsdoc/parse-jsdoc-claims.js +12 -6
  97. package/lib/parse/markdown/parse-markdown-claims.js +99 -62
  98. package/lib/parse/markdown/parse-markdown-directives.d.ts +10 -6
  99. package/lib/parse/markdown/parse-markdown-directives.js +104 -18
  100. package/lib/parse/markdown/parse-markdown-prose.d.ts +27 -0
  101. package/lib/parse/markdown/parse-markdown-prose.js +243 -0
  102. package/lib/parse/parse-claims.d.ts +2 -6
  103. package/lib/parse/parse-claims.js +11 -53
  104. package/lib/parse/tagged-fenced/tagged-fenced-blocks.d.ts +4 -4
  105. package/lib/parse/tagged-fenced/tagged-fenced-blocks.js +4 -4
  106. package/lib/parse/yaml/parse-yaml-claims.js +4 -4
  107. package/lib/patram.d.ts +9 -3
  108. package/lib/patram.js +1 -1
  109. package/lib/scan/discover-fields.js +194 -55
  110. package/lib/scan/list-source-files.d.ts +4 -4
  111. package/lib/scan/list-source-files.js +4 -4
  112. package/package.json +2 -1
  113. package/lib/directive-validation-test-helpers.js +0 -87
  114. package/lib/graph/query/parse.d.ts +0 -75
  115. package/lib/graph/query/parse.js +0 -1064
  116. package/lib/output/derived-summary.js +0 -280
  117. package/lib/output/format-derived-summary-row.js +0 -9
@@ -0,0 +1,300 @@
1
+ /**
2
+ * @import { CliParseError } from '../cli/arguments.types.ts';
3
+ * @import {
4
+ * PatramDiagnostic,
5
+ * PatramRepoConfig,
6
+ * } from './load-patram-config.types.ts';
7
+ */
8
+
9
+ import { resolve } from 'node:path';
10
+
11
+ import { loadPatramConfig } from './load-patram-config.js';
12
+ import {
13
+ createStoredQueryDefinition,
14
+ createUpdatedStoredQueryDefinition,
15
+ ensureRawQueries,
16
+ loadRawConfig,
17
+ persistStoredQueryMutation,
18
+ rawQueryValueToRecord,
19
+ } from './manage-stored-queries-helpers.js';
20
+ import { CONFIG_FILE_NAME } from './schema.js';
21
+ import { createUnknownStoredQueryError } from '../graph/query/resolve.js';
22
+
23
+ /**
24
+ * @typedef {{
25
+ * action: 'add',
26
+ * cypher?: string,
27
+ * description?: string,
28
+ * name: string,
29
+ * } | {
30
+ * action: 'remove',
31
+ * name: string,
32
+ * } | {
33
+ * action: 'update',
34
+ * cypher?: string,
35
+ * description?: string,
36
+ * name: string,
37
+ * next_name?: string,
38
+ * }} StoredQueryMutation
39
+ */
40
+
41
+ /**
42
+ * @typedef {{
43
+ * action: 'added',
44
+ * name: string,
45
+ * } | {
46
+ * action: 'removed',
47
+ * name: string,
48
+ * } | {
49
+ * action: 'updated',
50
+ * name: string,
51
+ * previous_name?: string,
52
+ * }} StoredQueryMutationResult
53
+ */
54
+
55
+ /**
56
+ * @param {string} project_directory
57
+ * @param {StoredQueryMutation} stored_query_mutation
58
+ * @returns {Promise<
59
+ * | { success: true, value: StoredQueryMutationResult }
60
+ * | { diagnostics: PatramDiagnostic[], success: false }
61
+ * | { error: CliParseError, success: false }
62
+ * >}
63
+ */
64
+ export async function manageStoredQueries(
65
+ project_directory,
66
+ stored_query_mutation,
67
+ ) {
68
+ const load_result = await loadPatramConfig(project_directory);
69
+
70
+ if (load_result.diagnostics.length > 0) {
71
+ return {
72
+ diagnostics: load_result.diagnostics,
73
+ success: false,
74
+ };
75
+ }
76
+
77
+ const repo_config = load_result.config;
78
+
79
+ if (!repo_config) {
80
+ throw new Error('Expected a valid Patram repo config.');
81
+ }
82
+
83
+ const config_file_path = resolve(project_directory, CONFIG_FILE_NAME);
84
+ const raw_config_result = await loadRawConfig(config_file_path);
85
+
86
+ if (!raw_config_result.success) {
87
+ return {
88
+ diagnostics: [raw_config_result.diagnostic],
89
+ success: false,
90
+ };
91
+ }
92
+
93
+ if (stored_query_mutation.action === 'add') {
94
+ return applyAddStoredQuery(
95
+ config_file_path,
96
+ raw_config_result.value,
97
+ repo_config,
98
+ stored_query_mutation,
99
+ );
100
+ }
101
+
102
+ if (stored_query_mutation.action === 'remove') {
103
+ return applyRemoveStoredQuery(
104
+ config_file_path,
105
+ raw_config_result.value,
106
+ repo_config,
107
+ stored_query_mutation,
108
+ );
109
+ }
110
+
111
+ return applyUpdateStoredQuery(
112
+ config_file_path,
113
+ raw_config_result.value,
114
+ repo_config,
115
+ stored_query_mutation,
116
+ );
117
+ }
118
+
119
+ /**
120
+ * @param {string} config_file_path
121
+ * @param {Record<string, unknown>} raw_config
122
+ * @param {PatramRepoConfig} repo_config
123
+ * @param {{ cypher?: string, description?: string, name: string }} stored_query_mutation
124
+ * @returns {Promise<
125
+ * | { success: true, value: StoredQueryMutationResult }
126
+ * | { diagnostics: PatramDiagnostic[], success: false }
127
+ * | { error: CliParseError, success: false }
128
+ * >}
129
+ */
130
+ async function applyAddStoredQuery(
131
+ config_file_path,
132
+ raw_config,
133
+ repo_config,
134
+ stored_query_mutation,
135
+ ) {
136
+ if (repo_config.queries[stored_query_mutation.name]) {
137
+ return {
138
+ error: {
139
+ code: 'message',
140
+ message: `Stored query already exists: ${stored_query_mutation.name}.`,
141
+ },
142
+ success: false,
143
+ };
144
+ }
145
+
146
+ const raw_queries = ensureRawQueries(raw_config);
147
+ const query_text = stored_query_mutation.cypher;
148
+
149
+ if (!query_text) {
150
+ throw new Error('Expected add mutations to contain query text.');
151
+ }
152
+
153
+ raw_queries[stored_query_mutation.name] = createStoredQueryDefinition(
154
+ query_text,
155
+ stored_query_mutation.description,
156
+ );
157
+
158
+ return persistStoredQueryMutation(config_file_path, raw_config, {
159
+ action: 'added',
160
+ name: stored_query_mutation.name,
161
+ });
162
+ }
163
+
164
+ /**
165
+ * @param {string} config_file_path
166
+ * @param {Record<string, unknown>} raw_config
167
+ * @param {PatramRepoConfig} repo_config
168
+ * @param {{ name: string }} stored_query_mutation
169
+ * @returns {Promise<
170
+ * | { success: true, value: StoredQueryMutationResult }
171
+ * | { diagnostics: PatramDiagnostic[], success: false }
172
+ * | { error: CliParseError, success: false }
173
+ * >}
174
+ */
175
+ async function applyRemoveStoredQuery(
176
+ config_file_path,
177
+ raw_config,
178
+ repo_config,
179
+ stored_query_mutation,
180
+ ) {
181
+ if (!repo_config.queries[stored_query_mutation.name]) {
182
+ return {
183
+ error: createQueryMutationUnknownStoredQueryError(
184
+ stored_query_mutation.name,
185
+ Object.keys(repo_config.queries),
186
+ 'remove',
187
+ ),
188
+ success: false,
189
+ };
190
+ }
191
+
192
+ const raw_queries = ensureRawQueries(raw_config);
193
+ delete raw_queries[stored_query_mutation.name];
194
+
195
+ return persistStoredQueryMutation(config_file_path, raw_config, {
196
+ action: 'removed',
197
+ name: stored_query_mutation.name,
198
+ });
199
+ }
200
+
201
+ /**
202
+ * @param {string} config_file_path
203
+ * @param {Record<string, unknown>} raw_config
204
+ * @param {PatramRepoConfig} repo_config
205
+ * @param {{ cypher?: string, description?: string, name: string, next_name?: string }} stored_query_mutation
206
+ * @returns {Promise<
207
+ * | { success: true, value: StoredQueryMutationResult }
208
+ * | { diagnostics: PatramDiagnostic[], success: false }
209
+ * | { error: CliParseError, success: false }
210
+ * >}
211
+ */
212
+ async function applyUpdateStoredQuery(
213
+ config_file_path,
214
+ raw_config,
215
+ repo_config,
216
+ stored_query_mutation,
217
+ ) {
218
+ const existing_query = repo_config.queries[stored_query_mutation.name];
219
+
220
+ if (!existing_query) {
221
+ return {
222
+ error: createQueryMutationUnknownStoredQueryError(
223
+ stored_query_mutation.name,
224
+ Object.keys(repo_config.queries),
225
+ 'update',
226
+ ),
227
+ success: false,
228
+ };
229
+ }
230
+
231
+ const next_name =
232
+ stored_query_mutation.next_name ?? stored_query_mutation.name;
233
+
234
+ if (
235
+ next_name !== stored_query_mutation.name &&
236
+ repo_config.queries[next_name]
237
+ ) {
238
+ return {
239
+ error: {
240
+ code: 'message',
241
+ message: `Stored query already exists: ${next_name}.`,
242
+ },
243
+ success: false,
244
+ };
245
+ }
246
+
247
+ const raw_queries = ensureRawQueries(raw_config);
248
+ const raw_query_value = rawQueryValueToRecord(
249
+ raw_queries[stored_query_mutation.name],
250
+ );
251
+ const next_query = createUpdatedStoredQueryDefinition(
252
+ raw_query_value,
253
+ existing_query,
254
+ stored_query_mutation,
255
+ );
256
+
257
+ if (next_name !== stored_query_mutation.name) {
258
+ delete raw_queries[stored_query_mutation.name];
259
+ }
260
+
261
+ raw_queries[next_name] = next_query;
262
+
263
+ return persistStoredQueryMutation(config_file_path, raw_config, {
264
+ action: 'updated',
265
+ name: next_name,
266
+ previous_name:
267
+ next_name === stored_query_mutation.name
268
+ ? undefined
269
+ : stored_query_mutation.name,
270
+ });
271
+ }
272
+
273
+ /**
274
+ * @param {string} stored_query_name
275
+ * @param {string[]} stored_query_names
276
+ * @param {'remove' | 'update'} subcommand_name
277
+ * @returns {CliParseError}
278
+ */
279
+ function createQueryMutationUnknownStoredQueryError(
280
+ stored_query_name,
281
+ stored_query_names,
282
+ subcommand_name,
283
+ ) {
284
+ const parse_error = createUnknownStoredQueryError(
285
+ stored_query_name,
286
+ stored_query_names,
287
+ );
288
+
289
+ if (
290
+ parse_error.code !== 'unknown_stored_query' ||
291
+ parse_error.suggestion === undefined
292
+ ) {
293
+ return parse_error;
294
+ }
295
+
296
+ return {
297
+ ...parse_error,
298
+ next_path: `patram queries ${subcommand_name} ${parse_error.suggestion}`,
299
+ };
300
+ }
@@ -5,49 +5,28 @@
5
5
  * @returns {PatramGraphConfig}
6
6
  */
7
7
  export function parsePatramConfig(config_json: unknown): PatramGraphConfig;
8
+ export type ClassDefinition = z.output<typeof class_definition_schema>;
9
+ export type RelationDefinition = z.output<typeof relation_definition_schema>;
10
+ export type MappingNodeDefinition = z.output<typeof mapping_node_schema>;
11
+ export type MappingEmitDefinition = z.output<typeof mapping_emit_schema>;
12
+ export type MappingDefinition = z.output<typeof mapping_definition_schema>;
13
+ export type PatramGraphConfig = z.output<typeof patram_config_schema>;
14
+ import { z } from 'zod';
8
15
  /**
9
16
  * @typedef {z.output<typeof class_definition_schema>} ClassDefinition
10
17
  */
11
- export const class_definition_schema: z.ZodObject<{
18
+ declare const class_definition_schema: z.ZodObject<{
12
19
  builtin: z.ZodOptional<z.ZodBoolean>;
13
20
  label: z.ZodOptional<z.ZodString>;
14
21
  }, z.core.$strict>;
15
22
  /**
16
23
  * @typedef {z.output<typeof relation_definition_schema>} RelationDefinition
17
24
  */
18
- export const relation_definition_schema: z.ZodObject<{
25
+ declare const relation_definition_schema: z.ZodObject<{
19
26
  builtin: z.ZodOptional<z.ZodBoolean>;
20
27
  from: z.ZodArray<z.ZodString>;
21
28
  to: z.ZodArray<z.ZodString>;
22
29
  }, 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
- export type ClassDefinition = z.output<typeof class_definition_schema>;
45
- export type RelationDefinition = z.output<typeof relation_definition_schema>;
46
- export type MappingNodeDefinition = z.output<typeof mapping_node_schema>;
47
- export type MappingEmitDefinition = z.output<typeof mapping_emit_schema>;
48
- export type MappingDefinition = z.output<typeof mapping_definition_schema>;
49
- export type PatramGraphConfig = z.output<typeof patram_config_schema>;
50
- import { z } from 'zod';
51
30
  /**
52
31
  * @typedef {z.output<typeof mapping_node_schema>} MappingNodeDefinition
53
32
  */
@@ -55,8 +34,8 @@ declare const mapping_node_schema: z.ZodObject<{
55
34
  class: z.ZodString;
56
35
  field: z.ZodString;
57
36
  key: z.ZodOptional<z.ZodEnum<{
58
- path: "path";
59
37
  value: "value";
38
+ path: "path";
60
39
  }>>;
61
40
  }, z.core.$strict>;
62
41
  /**
@@ -65,11 +44,32 @@ declare const mapping_node_schema: z.ZodObject<{
65
44
  declare const mapping_emit_schema: z.ZodObject<{
66
45
  relation: z.ZodString;
67
46
  target: z.ZodEnum<{
68
- path: "path";
69
47
  value: "value";
48
+ path: "path";
70
49
  }>;
71
50
  target_class: z.ZodString;
72
51
  }, z.core.$strict>;
52
+ /**
53
+ * @typedef {z.output<typeof mapping_definition_schema>} MappingDefinition
54
+ */
55
+ declare const mapping_definition_schema: z.ZodObject<{
56
+ emit: z.ZodOptional<z.ZodObject<{
57
+ relation: z.ZodString;
58
+ target: z.ZodEnum<{
59
+ value: "value";
60
+ path: "path";
61
+ }>;
62
+ target_class: z.ZodString;
63
+ }, z.core.$strict>>;
64
+ node: z.ZodOptional<z.ZodObject<{
65
+ class: z.ZodString;
66
+ field: z.ZodString;
67
+ key: z.ZodOptional<z.ZodEnum<{
68
+ value: "value";
69
+ path: "path";
70
+ }>>;
71
+ }, z.core.$strict>>;
72
+ }, z.core.$strict>;
73
73
  /**
74
74
  * @typedef {z.output<typeof patram_config_schema>} PatramGraphConfig
75
75
  */
@@ -83,8 +83,8 @@ declare const patram_config_schema: z.ZodObject<{
83
83
  emit: z.ZodOptional<z.ZodObject<{
84
84
  relation: z.ZodString;
85
85
  target: z.ZodEnum<{
86
- path: "path";
87
86
  value: "value";
87
+ path: "path";
88
88
  }>;
89
89
  target_class: z.ZodString;
90
90
  }, z.core.$strict>>;
@@ -92,8 +92,8 @@ declare const patram_config_schema: z.ZodObject<{
92
92
  class: z.ZodString;
93
93
  field: z.ZodString;
94
94
  key: z.ZodOptional<z.ZodEnum<{
95
- path: "path";
96
95
  value: "value";
96
+ path: "path";
97
97
  }>>;
98
98
  }, z.core.$strict>>;
99
99
  }, z.core.$strict>>;
@@ -13,7 +13,7 @@ const TARGET_SCHEMA = z.enum(['path', 'value']);
13
13
  /**
14
14
  * @typedef {z.output<typeof class_definition_schema>} ClassDefinition
15
15
  */
16
- export const class_definition_schema = z
16
+ const class_definition_schema = z
17
17
  .object({
18
18
  builtin: z.boolean().optional(),
19
19
  label: z.string().min(1).optional(),
@@ -23,7 +23,7 @@ export const class_definition_schema = z
23
23
  /**
24
24
  * @typedef {z.output<typeof relation_definition_schema>} RelationDefinition
25
25
  */
26
- export const relation_definition_schema = z
26
+ const relation_definition_schema = z
27
27
  .object({
28
28
  builtin: z.boolean().optional(),
29
29
  from: z.array(CLASS_NAME_SCHEMA).min(1),
@@ -56,7 +56,7 @@ const mapping_emit_schema = z
56
56
  /**
57
57
  * @typedef {z.output<typeof mapping_definition_schema>} MappingDefinition
58
58
  */
59
- export const mapping_definition_schema = z
59
+ const mapping_definition_schema = z
60
60
  .object({
61
61
  emit: mapping_emit_schema.optional(),
62
62
  node: mapping_node_schema.optional(),
@@ -1,14 +1,8 @@
1
- import type { ClassSchemaConfig, MetadataFieldConfig } from './load-patram-config.types.d.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;
1
+ import type { MetadataFieldConfig, PatramRepoConfig, TypeDefinitionConfig } from './load-patram-config.types.d.ts';
2
+ export type PatramTypeConfig = TypeDefinitionConfig & {
3
+ label?: string;
10
4
  };
11
- export type PatramConfig = Omit<PatramGraphConfig, 'classes'> & {
12
- classes: Record<string, PatramClassConfig>;
5
+ export type PatramConfig = PatramRepoConfig & {
13
6
  fields?: Record<string, MetadataFieldConfig>;
7
+ types?: Record<string, PatramTypeConfig>;
14
8
  };
@@ -1,5 +1,9 @@
1
1
  /**
2
- * Merge built-in Patram graph semantics with repo-defined schema.
2
+ * @import { PatramConfig } from './patram-config.types.d.ts';
3
+ * @import { PatramRepoConfig } from './load-patram-config.types.d.ts';
4
+ */
5
+ /**
6
+ * Normalize the loaded repo config for graph materialization.
3
7
  *
4
8
  * @param {PatramRepoConfig} repo_config
5
9
  * @returns {PatramConfig}
@@ -1,132 +1,16 @@
1
1
  /**
2
- * @import { ClassDefinition } from './patram-config.js';
3
- * @import { PatramRepoConfig } from './load-patram-config.types.ts';
4
2
  * @import { PatramConfig } from './patram-config.types.ts';
3
+ * @import { PatramRepoConfig } from './load-patram-config.types.ts';
5
4
  */
6
5
 
7
- import { parsePatramConfig } from './patram-config.js';
8
-
9
- /**
10
- * Built-in graph semantics.
11
- *
12
- * Merges repo-defined graph config with Patram's built-in document and link
13
- * semantics before graph materialization.
14
- *
15
- * Kind: config
16
- * Status: active
17
- * Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
18
- * Decided by: ../../docs/decisions/graph-materialization.md
19
- * @patram
20
- * @see {@link ./load-patram-config.js}
21
- * @see {@link ../../docs/graph-v0.md}
22
- */
23
-
24
- const BUILT_IN_PATRAM_CONFIG = {
25
- classes: {
26
- document: {
27
- builtin: true,
28
- label: 'Document',
29
- },
30
- },
31
- mappings: {
32
- 'document.title': {
33
- node: {
34
- class: 'document',
35
- field: 'title',
36
- },
37
- },
38
- 'document.description': {
39
- node: {
40
- class: 'document',
41
- field: 'description',
42
- },
43
- },
44
- 'jsdoc.link': {
45
- emit: {
46
- relation: 'links_to',
47
- target: 'path',
48
- target_class: 'document',
49
- },
50
- },
51
- 'markdown.link': {
52
- emit: {
53
- relation: 'links_to',
54
- target: 'path',
55
- target_class: 'document',
56
- },
57
- },
58
- },
59
- relations: {
60
- links_to: {
61
- builtin: true,
62
- from: ['document'],
63
- to: ['document'],
64
- },
65
- },
66
- };
67
-
68
6
  /**
69
- * Merge built-in Patram graph semantics with repo-defined schema.
7
+ * Normalize the loaded repo config for graph materialization.
70
8
  *
71
9
  * @param {PatramRepoConfig} repo_config
72
10
  * @returns {PatramConfig}
73
11
  */
74
12
  export function resolvePatramGraphConfig(repo_config) {
75
- const graph_config = parsePatramConfig({
76
- classes: {
77
- ...BUILT_IN_PATRAM_CONFIG.classes,
78
- ...collectGraphClassDefinitions(repo_config.classes),
79
- },
80
- mappings: {
81
- ...BUILT_IN_PATRAM_CONFIG.mappings,
82
- ...repo_config.mappings,
83
- },
84
- relations: {
85
- ...BUILT_IN_PATRAM_CONFIG.relations,
86
- ...repo_config.relations,
87
- },
88
- });
89
-
90
13
  return {
91
- ...graph_config,
92
- classes: mergeResolvedClasses(graph_config.classes, repo_config.classes),
93
- fields: repo_config.fields,
14
+ ...repo_config,
94
15
  };
95
16
  }
96
-
97
- /**
98
- * @param {PatramRepoConfig['classes']} classes
99
- * @returns {Record<string, ClassDefinition>}
100
- */
101
- function collectGraphClassDefinitions(classes) {
102
- /** @type {Record<string, ClassDefinition>} */
103
- const graph_class_definitions = {};
104
-
105
- for (const [class_name, class_definition] of Object.entries(classes ?? {})) {
106
- graph_class_definitions[class_name] = {
107
- builtin: class_definition.builtin,
108
- label: class_definition.label,
109
- };
110
- }
111
-
112
- return graph_class_definitions;
113
- }
114
-
115
- /**
116
- * @param {Record<string, ClassDefinition>} graph_classes
117
- * @param {PatramRepoConfig['classes']} repo_classes
118
- * @returns {PatramConfig['classes']}
119
- */
120
- function mergeResolvedClasses(graph_classes, repo_classes) {
121
- /** @type {PatramConfig['classes']} */
122
- const resolved_classes = {};
123
-
124
- for (const [class_name, class_definition] of Object.entries(graph_classes)) {
125
- resolved_classes[class_name] = {
126
- ...class_definition,
127
- schema: repo_classes?.[class_name]?.schema,
128
- };
129
- }
130
-
131
- return resolved_classes;
132
- }