patram 0.11.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.
- package/bin/patram.js +4 -4
- package/lib/cli/commands/fields.js +0 -4
- package/lib/cli/commands/queries.js +10 -20
- package/lib/cli/commands/query.js +1 -8
- package/lib/cli/commands/refs.js +3 -10
- package/lib/cli/commands/show.js +1 -8
- package/lib/cli/help-metadata.js +71 -106
- package/lib/cli/main.js +10 -10
- package/lib/cli/parse-arguments-helpers.js +165 -59
- package/lib/cli/parse-arguments.js +4 -4
- package/lib/cli/render-help.js +2 -2
- package/lib/config/defaults.js +33 -25
- package/lib/config/load-patram-config.d.ts +8 -33
- package/lib/config/load-patram-config.js +9 -33
- package/lib/config/load-patram-config.types.d.ts +3 -40
- package/lib/config/manage-stored-queries-helpers.d.ts +4 -4
- package/lib/config/manage-stored-queries-helpers.js +91 -33
- package/lib/config/manage-stored-queries.d.ts +4 -4
- package/lib/config/manage-stored-queries.js +11 -5
- package/lib/config/patram-config.d.ts +34 -34
- package/lib/config/patram-config.js +3 -3
- package/lib/config/patram-config.types.d.ts +5 -11
- package/lib/config/resolve-patram-graph-config.d.ts +5 -1
- package/lib/config/resolve-patram-graph-config.js +3 -119
- package/lib/config/schema.d.ts +158 -269
- package/lib/config/schema.js +72 -210
- package/lib/config/validate-patram-config-value.js +6 -31
- package/lib/config/validation.d.ts +2 -12
- package/lib/config/validation.js +125 -483
- package/lib/find-close-match.d.ts +4 -1
- package/lib/graph/build-graph-identity.d.ts +1 -32
- package/lib/graph/build-graph-identity.js +5 -269
- package/lib/graph/build-graph.d.ts +13 -4
- package/lib/graph/build-graph.js +347 -488
- package/lib/graph/build-graph.types.d.ts +8 -9
- package/lib/graph/check-directive-metadata-helpers.d.ts +30 -0
- package/lib/graph/check-directive-metadata-helpers.js +126 -0
- package/lib/graph/check-directive-metadata.d.ts +8 -9
- package/lib/graph/check-directive-metadata.js +70 -561
- package/lib/graph/check-directive-path-target.d.ts +6 -13
- package/lib/graph/check-directive-path-target.js +26 -57
- package/lib/graph/check-directive-value.d.ts +1 -5
- package/lib/graph/check-directive-value.js +40 -180
- package/lib/graph/check-graph.d.ts +5 -5
- package/lib/graph/check-graph.js +8 -6
- package/lib/graph/document-node-identity.d.ts +23 -7
- package/lib/graph/document-node-identity.js +417 -160
- package/lib/graph/graph-node.d.ts +42 -0
- package/lib/graph/graph-node.js +83 -0
- package/lib/graph/inspect-reverse-references.js +16 -11
- package/lib/graph/load-project-graph.d.ts +7 -7
- package/lib/graph/load-project-graph.js +7 -7
- package/lib/graph/parse-where-clause.types.d.ts +3 -2
- package/lib/graph/query/cypher-reader.d.ts +59 -0
- package/lib/graph/query/cypher-reader.js +151 -0
- package/lib/graph/query/cypher-support.d.ts +79 -0
- package/lib/graph/query/cypher-support.js +213 -0
- package/lib/graph/query/cypher-tokenize.d.ts +13 -0
- package/lib/graph/query/cypher-tokenize.js +225 -0
- package/lib/graph/query/cypher.types.d.ts +43 -0
- package/lib/graph/query/execute.d.ts +7 -7
- package/lib/graph/query/execute.js +71 -33
- package/lib/graph/query/inspect.js +58 -24
- package/lib/graph/query/parse-cypher-patterns.d.ts +27 -0
- package/lib/graph/query/parse-cypher-patterns.js +382 -0
- package/lib/graph/query/parse-cypher.d.ts +7 -0
- package/lib/graph/query/parse-cypher.js +580 -0
- package/lib/graph/query/parse-query.d.ts +13 -0
- package/lib/graph/query/parse-query.js +97 -0
- package/lib/graph/query/resolve.js +77 -23
- package/lib/output/command-output.js +12 -5
- package/lib/output/compact-layout.js +221 -0
- package/lib/output/format-output-item-block.js +31 -1
- package/lib/output/format-output-metadata.js +16 -29
- package/lib/output/format-stored-query-block.js +95 -0
- package/lib/output/layout-incoming-references.js +101 -19
- package/lib/output/layout-stored-queries.js +23 -330
- package/lib/output/list-queries.js +1 -1
- package/lib/output/render-field-discovery.js +11 -2
- package/lib/output/render-output-view.js +9 -5
- package/lib/output/renderers/json.js +5 -26
- package/lib/output/renderers/plain.js +155 -35
- package/lib/output/renderers/rich.js +250 -36
- package/lib/output/resolved-link-layout.js +43 -0
- package/lib/output/rich-source/render.js +193 -35
- package/lib/output/show-document.js +25 -18
- package/lib/output/view-model/index.js +124 -103
- package/lib/parse/jsdoc/parse-jsdoc-blocks.js +1 -1
- package/lib/parse/jsdoc/parse-jsdoc-claims.js +12 -6
- package/lib/parse/markdown/parse-markdown-claims.js +99 -62
- package/lib/parse/markdown/parse-markdown-directives.d.ts +10 -6
- package/lib/parse/markdown/parse-markdown-directives.js +104 -18
- package/lib/parse/markdown/parse-markdown-prose.d.ts +27 -0
- package/lib/parse/markdown/parse-markdown-prose.js +243 -0
- package/lib/parse/parse-claims.d.ts +2 -6
- package/lib/parse/parse-claims.js +11 -53
- package/lib/parse/tagged-fenced/tagged-fenced-blocks.d.ts +4 -4
- package/lib/parse/tagged-fenced/tagged-fenced-blocks.js +4 -4
- package/lib/parse/yaml/parse-yaml-claims.js +4 -4
- package/lib/patram.d.ts +3 -5
- package/lib/patram.js +1 -1
- package/lib/scan/discover-fields.js +194 -55
- package/lib/scan/list-source-files.d.ts +4 -4
- package/lib/scan/list-source-files.js +4 -4
- package/package.json +1 -1
- package/lib/directive-validation-test-helpers.js +0 -87
- package/lib/graph/query/parse.d.ts +0 -75
- package/lib/graph/query/parse.js +0 -1064
- package/lib/output/derived-summary.js +0 -280
- package/lib/output/format-derived-summary-row.js +0 -9
|
@@ -92,15 +92,16 @@ export async function persistStoredQueryMutation(
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* @param {string}
|
|
95
|
+
* @param {string} query_text
|
|
96
96
|
* @param {string | undefined} description
|
|
97
97
|
* @returns {StoredQueryConfig}
|
|
98
98
|
*/
|
|
99
|
-
export function createStoredQueryDefinition(
|
|
99
|
+
export function createStoredQueryDefinition(query_text, description) {
|
|
100
100
|
/** @type {StoredQueryConfig} */
|
|
101
101
|
const stored_query = {
|
|
102
|
-
|
|
102
|
+
cypher: query_text,
|
|
103
103
|
};
|
|
104
|
+
|
|
104
105
|
const normalized_description = normalizeDescription(description);
|
|
105
106
|
|
|
106
107
|
if (normalized_description !== undefined) {
|
|
@@ -113,7 +114,7 @@ export function createStoredQueryDefinition(where_clause, description) {
|
|
|
113
114
|
/**
|
|
114
115
|
* @param {Record<string, unknown> | null} raw_query_value
|
|
115
116
|
* @param {StoredQueryConfig} existing_query
|
|
116
|
-
* @param {{
|
|
117
|
+
* @param {{ cypher?: string, description?: string }} stored_query_mutation
|
|
117
118
|
* @returns {StoredQueryConfig}
|
|
118
119
|
*/
|
|
119
120
|
export function createUpdatedStoredQueryDefinition(
|
|
@@ -121,36 +122,13 @@ export function createUpdatedStoredQueryDefinition(
|
|
|
121
122
|
existing_query,
|
|
122
123
|
stored_query_mutation,
|
|
123
124
|
) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
raw_query_value &&
|
|
131
|
-
Object.hasOwn(raw_query_value, 'description') &&
|
|
132
|
-
typeof raw_query_value.description === 'string' &&
|
|
133
|
-
raw_query_value.description.length > 0
|
|
134
|
-
) {
|
|
135
|
-
next_query.description = raw_query_value.description;
|
|
136
|
-
} else if (
|
|
137
|
-
typeof existing_query.description === 'string' &&
|
|
138
|
-
existing_query.description.length > 0
|
|
139
|
-
) {
|
|
140
|
-
next_query.description = existing_query.description;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (stored_query_mutation.where !== undefined) {
|
|
144
|
-
next_query.where = stored_query_mutation.where;
|
|
145
|
-
}
|
|
125
|
+
const next_query = createBaseStoredQueryDefinition(
|
|
126
|
+
raw_query_value,
|
|
127
|
+
existing_query,
|
|
128
|
+
);
|
|
146
129
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
delete next_query.description;
|
|
150
|
-
} else {
|
|
151
|
-
next_query.description = stored_query_mutation.description;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
130
|
+
applyStoredQueryTextMutation(next_query, stored_query_mutation);
|
|
131
|
+
applyStoredQueryDescriptionMutation(next_query, stored_query_mutation);
|
|
154
132
|
|
|
155
133
|
return next_query;
|
|
156
134
|
}
|
|
@@ -205,6 +183,86 @@ function normalizeDescription(description) {
|
|
|
205
183
|
return description;
|
|
206
184
|
}
|
|
207
185
|
|
|
186
|
+
/**
|
|
187
|
+
* @param {Record<string, unknown> | null} raw_query_value
|
|
188
|
+
* @param {StoredQueryConfig} existing_query
|
|
189
|
+
* @returns {StoredQueryConfig}
|
|
190
|
+
*/
|
|
191
|
+
function createBaseStoredQueryDefinition(raw_query_value, existing_query) {
|
|
192
|
+
/** @type {StoredQueryConfig} */
|
|
193
|
+
const next_query = {};
|
|
194
|
+
|
|
195
|
+
if (existing_query.cypher !== undefined) {
|
|
196
|
+
next_query.cypher = existing_query.cypher;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const description = resolveExistingDescription(
|
|
200
|
+
raw_query_value,
|
|
201
|
+
existing_query,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (description !== undefined) {
|
|
205
|
+
next_query.description = description;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return next_query;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @param {StoredQueryConfig} next_query
|
|
213
|
+
* @param {{ cypher?: string, description?: string }} stored_query_mutation
|
|
214
|
+
*/
|
|
215
|
+
function applyStoredQueryTextMutation(next_query, stored_query_mutation) {
|
|
216
|
+
if (stored_query_mutation.cypher !== undefined) {
|
|
217
|
+
next_query.cypher = stored_query_mutation.cypher;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param {StoredQueryConfig} next_query
|
|
223
|
+
* @param {{ cypher?: string, description?: string }} stored_query_mutation
|
|
224
|
+
*/
|
|
225
|
+
function applyStoredQueryDescriptionMutation(
|
|
226
|
+
next_query,
|
|
227
|
+
stored_query_mutation,
|
|
228
|
+
) {
|
|
229
|
+
if (stored_query_mutation.description === undefined) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (stored_query_mutation.description.length === 0) {
|
|
234
|
+
delete next_query.description;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
next_query.description = stored_query_mutation.description;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @param {Record<string, unknown> | null} raw_query_value
|
|
243
|
+
* @param {StoredQueryConfig} existing_query
|
|
244
|
+
* @returns {string | undefined}
|
|
245
|
+
*/
|
|
246
|
+
function resolveExistingDescription(raw_query_value, existing_query) {
|
|
247
|
+
if (
|
|
248
|
+
raw_query_value &&
|
|
249
|
+
Object.hasOwn(raw_query_value, 'description') &&
|
|
250
|
+
typeof raw_query_value.description === 'string' &&
|
|
251
|
+
raw_query_value.description.length > 0
|
|
252
|
+
) {
|
|
253
|
+
return raw_query_value.description;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (
|
|
257
|
+
typeof existing_query.description === 'string' &&
|
|
258
|
+
existing_query.description.length > 0
|
|
259
|
+
) {
|
|
260
|
+
return existing_query.description;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
208
266
|
/**
|
|
209
267
|
* @returns {PatramDiagnostic}
|
|
210
268
|
*/
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {{
|
|
3
3
|
* action: 'add',
|
|
4
|
+
* cypher?: string,
|
|
4
5
|
* description?: string,
|
|
5
6
|
* name: string,
|
|
6
|
-
* where: string,
|
|
7
7
|
* } | {
|
|
8
8
|
* action: 'remove',
|
|
9
9
|
* name: string,
|
|
10
10
|
* } | {
|
|
11
11
|
* action: 'update',
|
|
12
|
+
* cypher?: string,
|
|
12
13
|
* description?: string,
|
|
13
14
|
* name: string,
|
|
14
15
|
* next_name?: string,
|
|
15
|
-
* where?: string,
|
|
16
16
|
* }} StoredQueryMutation
|
|
17
17
|
*/
|
|
18
18
|
/**
|
|
@@ -49,18 +49,18 @@ export function manageStoredQueries(project_directory: string, stored_query_muta
|
|
|
49
49
|
}>;
|
|
50
50
|
export type StoredQueryMutation = {
|
|
51
51
|
action: "add";
|
|
52
|
+
cypher?: string;
|
|
52
53
|
description?: string;
|
|
53
54
|
name: string;
|
|
54
|
-
where: string;
|
|
55
55
|
} | {
|
|
56
56
|
action: "remove";
|
|
57
57
|
name: string;
|
|
58
58
|
} | {
|
|
59
59
|
action: "update";
|
|
60
|
+
cypher?: string;
|
|
60
61
|
description?: string;
|
|
61
62
|
name: string;
|
|
62
63
|
next_name?: string;
|
|
63
|
-
where?: string;
|
|
64
64
|
};
|
|
65
65
|
export type StoredQueryMutationResult = {
|
|
66
66
|
action: "added";
|
|
@@ -23,18 +23,18 @@ import { createUnknownStoredQueryError } from '../graph/query/resolve.js';
|
|
|
23
23
|
/**
|
|
24
24
|
* @typedef {{
|
|
25
25
|
* action: 'add',
|
|
26
|
+
* cypher?: string,
|
|
26
27
|
* description?: string,
|
|
27
28
|
* name: string,
|
|
28
|
-
* where: string,
|
|
29
29
|
* } | {
|
|
30
30
|
* action: 'remove',
|
|
31
31
|
* name: string,
|
|
32
32
|
* } | {
|
|
33
33
|
* action: 'update',
|
|
34
|
+
* cypher?: string,
|
|
34
35
|
* description?: string,
|
|
35
36
|
* name: string,
|
|
36
37
|
* next_name?: string,
|
|
37
|
-
* where?: string,
|
|
38
38
|
* }} StoredQueryMutation
|
|
39
39
|
*/
|
|
40
40
|
|
|
@@ -120,7 +120,7 @@ export async function manageStoredQueries(
|
|
|
120
120
|
* @param {string} config_file_path
|
|
121
121
|
* @param {Record<string, unknown>} raw_config
|
|
122
122
|
* @param {PatramRepoConfig} repo_config
|
|
123
|
-
* @param {{
|
|
123
|
+
* @param {{ cypher?: string, description?: string, name: string }} stored_query_mutation
|
|
124
124
|
* @returns {Promise<
|
|
125
125
|
* | { success: true, value: StoredQueryMutationResult }
|
|
126
126
|
* | { diagnostics: PatramDiagnostic[], success: false }
|
|
@@ -144,8 +144,14 @@ async function applyAddStoredQuery(
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
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
|
+
|
|
147
153
|
raw_queries[stored_query_mutation.name] = createStoredQueryDefinition(
|
|
148
|
-
|
|
154
|
+
query_text,
|
|
149
155
|
stored_query_mutation.description,
|
|
150
156
|
);
|
|
151
157
|
|
|
@@ -196,7 +202,7 @@ async function applyRemoveStoredQuery(
|
|
|
196
202
|
* @param {string} config_file_path
|
|
197
203
|
* @param {Record<string, unknown>} raw_config
|
|
198
204
|
* @param {PatramRepoConfig} repo_config
|
|
199
|
-
* @param {{ description?: string, name: string, next_name?: string
|
|
205
|
+
* @param {{ cypher?: string, description?: string, name: string, next_name?: string }} stored_query_mutation
|
|
200
206
|
* @returns {Promise<
|
|
201
207
|
* | { success: true, value: StoredQueryMutationResult }
|
|
202
208
|
* | { diagnostics: PatramDiagnostic[], success: false }
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
-
export type
|
|
3
|
-
|
|
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 =
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
...
|
|
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
|
-
}
|