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.
- package/bin/patram.js +2 -2
- package/lib/{parse-cli-color-options.js → cli/color-options.js} +2 -2
- package/lib/cli/command-helpers.js +35 -0
- package/lib/cli/commands/check.js +73 -0
- package/lib/cli/commands/fields.js +57 -0
- package/lib/cli/commands/queries.js +41 -0
- package/lib/cli/commands/query.js +239 -0
- package/lib/cli/commands/refs.js +72 -0
- package/lib/cli/commands/show.js +58 -0
- package/lib/{cli-help-metadata.js → cli/help-metadata.js} +54 -15
- package/lib/cli/main.js +76 -0
- package/lib/{parse-cli-arguments-helpers.js → cli/parse-arguments-helpers.js} +18 -11
- package/lib/{parse-cli-arguments.js → cli/parse-arguments.js} +12 -12
- package/lib/{parse-cli-query-pagination.js → cli/query-pagination.js} +2 -2
- package/lib/{render-cli-help.js → cli/render-help.js} +4 -4
- package/lib/{resolve-output-mode.js → cli/resolve-output-mode.js} +2 -2
- package/lib/cli/test-helpers.js +30 -0
- package/lib/config/defaults.d.ts +10 -0
- package/lib/config/defaults.js +80 -0
- package/lib/config/load-patram-config.d.ts +76 -0
- package/lib/config/load-patram-config.js +315 -0
- package/lib/config/load-patram-config.types.d.ts +45 -0
- package/lib/{patram-config.d.ts → config/patram-config.d.ts} +31 -31
- package/lib/{patram-config.js → config/patram-config.js} +3 -3
- package/lib/{patram-config.types.d.ts → config/patram-config.types.d.ts} +1 -1
- package/lib/{resolve-patram-graph-config.d.ts → config/resolve-patram-graph-config.d.ts} +2 -2
- package/lib/{resolve-patram-graph-config.js → config/resolve-patram-graph-config.js} +3 -3
- package/lib/{load-patram-config.d.ts → config/schema.d.ts} +147 -191
- package/lib/config/schema.js +324 -0
- package/lib/{source-file-defaults.d.ts → config/source-file-defaults.d.ts} +0 -1
- package/lib/{source-file-defaults.js → config/source-file-defaults.js} +1 -1
- package/lib/config/validation.d.ts +27 -0
- package/lib/config/validation.js +615 -0
- package/lib/directive-validation-test-helpers.js +1 -1
- package/lib/{build-graph-identity.d.ts → graph/build-graph-identity.d.ts} +2 -2
- package/lib/{build-graph-identity.js → graph/build-graph-identity.js} +1 -1
- package/lib/{build-graph.d.ts → graph/build-graph.d.ts} +3 -3
- package/lib/{build-graph.js → graph/build-graph.js} +17 -13
- package/lib/{build-graph.types.d.ts → graph/build-graph.types.d.ts} +1 -1
- package/lib/graph/check-directive-metadata.d.ts +23 -0
- package/lib/{check-directive-metadata.js → graph/check-directive-metadata.js} +7 -7
- package/lib/graph/check-directive-path-target.d.ts +32 -0
- package/lib/{check-directive-path-target.js → graph/check-directive-path-target.js} +4 -4
- package/lib/graph/check-directive-value.d.ts +19 -0
- package/lib/{check-directive-value.js → graph/check-directive-value.js} +3 -3
- package/lib/graph/check-graph.d.ts +29 -0
- package/lib/{check-graph.js → graph/check-graph.js} +6 -6
- package/lib/graph/directive-diagnostics.d.ts +20 -0
- package/lib/{directive-diagnostics.js → graph/directive-diagnostics.js} +2 -2
- package/lib/graph/directive-type-rules.d.ts +18 -0
- package/lib/{directive-type-rules.js → graph/directive-type-rules.js} +3 -3
- package/lib/{document-node-identity.d.ts → graph/document-node-identity.d.ts} +2 -2
- package/lib/{document-node-identity.js → graph/document-node-identity.js} +2 -2
- package/lib/graph/inspect-reverse-references.d.ts +22 -0
- package/lib/graph/inspect-reverse-references.js +184 -0
- package/lib/{load-project-graph.d.ts → graph/load-project-graph.d.ts} +10 -10
- package/lib/{load-project-graph.js → graph/load-project-graph.js} +12 -12
- package/lib/{parse-where-clause.types.d.ts → graph/parse-where-clause.types.d.ts} +1 -1
- package/lib/{query-graph.d.ts → graph/query/execute.d.ts} +11 -11
- package/lib/{query-graph.js → graph/query/execute.js} +12 -12
- package/lib/{query-inspection.d.ts → graph/query/inspect.d.ts} +10 -8
- package/lib/{query-inspection.js → graph/query/inspect.js} +16 -17
- package/lib/{parse-where-clause.d.ts → graph/query/parse.d.ts} +6 -6
- package/lib/{parse-where-clause.js → graph/query/parse.js} +2 -2
- package/lib/graph/query/resolve.d.ts +30 -0
- package/lib/{resolve-where-clause.js → graph/query/resolve.js} +1 -1
- package/lib/graph/reverse-reference-test-helpers.d.ts +55 -0
- package/lib/graph/reverse-reference-test-helpers.js +76 -0
- package/lib/{command-output.js → output/command-output.js} +6 -5
- package/lib/{derived-summary.js → output/derived-summary.js} +7 -7
- package/lib/output/layout-incoming-references.js +105 -0
- package/lib/output/layout-incoming-summary-lines.js +16 -0
- package/lib/{layout-stored-queries.js → output/layout-stored-queries.js} +9 -9
- package/lib/{list-queries.js → output/list-queries.js} +1 -1
- package/lib/{render-check-output.js → output/render-check-output.js} +1 -1
- package/lib/{render-field-discovery.js → output/render-field-discovery.js} +3 -3
- package/lib/output/render-output-view.js +56 -0
- package/lib/{render-json-output.js → output/renderers/json.js} +92 -63
- package/lib/{render-plain-output.js → output/renderers/plain.js} +62 -7
- package/lib/{render-rich-output.js → output/renderers/rich.js} +69 -8
- package/lib/{resolve-check-target.js → output/resolve-check-target.js} +1 -1
- package/lib/{render-rich-source.js → output/rich-source/render.js} +6 -6
- package/lib/{show-document.js → output/show-document.js} +54 -16
- package/lib/{render-output-view.js → output/view-model/index.js} +56 -47
- package/lib/{write-paged-output.js → output/write-paged-output.js} +9 -5
- package/lib/{claim-helpers.d.ts → parse/claim-helpers.d.ts} +2 -2
- package/lib/{parse-jsdoc-claims.d.ts → parse/jsdoc/parse-jsdoc-claims.d.ts} +2 -2
- package/lib/{parse-jsdoc-claims.js → parse/jsdoc/parse-jsdoc-claims.js} +9 -9
- package/lib/{parse-jsdoc-prose.d.ts → parse/jsdoc/parse-jsdoc-prose.d.ts} +1 -1
- package/lib/{parse-jsdoc-prose.js → parse/jsdoc/parse-jsdoc-prose.js} +1 -1
- package/lib/{parse-markdown-claims.d.ts → parse/markdown/parse-markdown-claims.d.ts} +3 -3
- package/lib/{parse-markdown-claims.js → parse/markdown/parse-markdown-claims.js} +8 -8
- package/lib/{parse-markdown-directives.d.ts → parse/markdown/parse-markdown-directives.d.ts} +2 -2
- package/lib/{parse-markdown-directives.js → parse/markdown/parse-markdown-directives.js} +3 -3
- package/lib/{parse-claims.d.ts → parse/parse-claims.d.ts} +4 -13
- package/lib/{parse-claims.js → parse/parse-claims.js} +18 -26
- package/lib/{parse-claims.types.d.ts → parse/parse-claims.types.d.ts} +1 -1
- package/lib/{tagged-fenced-block-error.d.ts → parse/tagged-fenced/tagged-fenced-block-error.d.ts} +2 -2
- package/lib/{tagged-fenced-block-parser.d.ts → parse/tagged-fenced/tagged-fenced-block-parser.d.ts} +3 -3
- package/lib/{tagged-fenced-blocks.d.ts → parse/tagged-fenced/tagged-fenced-blocks.d.ts} +7 -7
- package/lib/{tagged-fenced-blocks.js → parse/tagged-fenced/tagged-fenced-blocks.js} +3 -3
- package/lib/{parse-yaml-claims.d.ts → parse/yaml/parse-yaml-claims.d.ts} +4 -4
- package/lib/{parse-yaml-claims.js → parse/yaml/parse-yaml-claims.js} +22 -13
- package/lib/patram.d.ts +29 -28
- package/lib/patram.js +5 -6
- package/lib/{discover-fields.js → scan/discover-fields.js} +9 -8
- package/lib/scan/list-repo-files.d.ts +16 -0
- package/lib/{list-source-files.js → scan/list-repo-files.js} +2 -35
- package/lib/{list-source-files.d.ts → scan/list-source-files.d.ts} +4 -11
- package/lib/scan/list-source-files.js +45 -0
- package/package.json +8 -7
- package/lib/build-graph.types.ts +0 -27
- package/lib/discover-fields.types.ts +0 -52
- package/lib/load-patram-config.js +0 -1215
- package/lib/load-patram-config.types.d.ts +0 -45
- package/lib/load-patram-config.types.ts +0 -56
- package/lib/output-view.types.d.ts +0 -80
- package/lib/output-view.types.ts +0 -96
- package/lib/overlay-graph.d.ts +0 -43
- package/lib/overlay-graph.js +0 -191
- package/lib/parse-claims.types.ts +0 -41
- package/lib/parse-cli-arguments.types.ts +0 -69
- package/lib/parse-where-clause.types.ts +0 -87
- package/lib/patram-cli.js +0 -528
- package/lib/patram-config.types.ts +0 -22
- package/lib/tagged-fenced-blocks.types.ts +0 -38
- /package/lib/{format-derived-summary-row.js → output/format-derived-summary-row.js} +0 -0
- /package/lib/{format-node-header.js → output/format-node-header.js} +0 -0
- /package/lib/{format-output-item-block.js → output/format-output-item-block.js} +0 -0
- /package/lib/{format-output-metadata.js → output/format-output-metadata.js} +0 -0
- /package/lib/{claim-helpers.js → parse/claim-helpers.js} +0 -0
- /package/lib/{parse-jsdoc-blocks.d.ts → parse/jsdoc/parse-jsdoc-blocks.d.ts} +0 -0
- /package/lib/{parse-jsdoc-blocks.js → parse/jsdoc/parse-jsdoc-blocks.js} +0 -0
- /package/lib/{tagged-fenced-block-error.js → parse/tagged-fenced/tagged-fenced-block-error.js} +0 -0
- /package/lib/{tagged-fenced-block-markdown.d.ts → parse/tagged-fenced/tagged-fenced-block-markdown.d.ts} +0 -0
- /package/lib/{tagged-fenced-block-markdown.js → parse/tagged-fenced/tagged-fenced-block-markdown.js} +0 -0
- /package/lib/{tagged-fenced-block-metadata.d.ts → parse/tagged-fenced/tagged-fenced-block-metadata.d.ts} +0 -0
- /package/lib/{tagged-fenced-block-metadata.js → parse/tagged-fenced/tagged-fenced-block-metadata.js} +0 -0
- /package/lib/{tagged-fenced-block-parser.js → parse/tagged-fenced/tagged-fenced-block-parser.js} +0 -0
- /package/lib/{tagged-fenced-blocks.types.d.ts → parse/tagged-fenced/tagged-fenced-blocks.types.d.ts} +0 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* ClassFieldRuleConfig,
|
|
4
|
+
* ClassSchemaConfig,
|
|
5
|
+
* DerivedSummaryConfig,
|
|
6
|
+
* DerivedSummaryFieldConfig,
|
|
7
|
+
* DerivedSummaryScalar,
|
|
8
|
+
* DerivedSummarySelectCaseConfig,
|
|
9
|
+
* FieldDisplayConfig,
|
|
10
|
+
* FieldQueryConfig,
|
|
11
|
+
* MetadataFieldConfig,
|
|
12
|
+
* PathClassConfig,
|
|
13
|
+
* StoredQueryConfig,
|
|
14
|
+
* } from './schema.js';
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { readFile } from 'node:fs/promises';
|
|
18
|
+
import { resolve } from 'node:path';
|
|
19
|
+
import process from 'node:process';
|
|
20
|
+
|
|
21
|
+
import { CONFIG_FILE_NAME, patram_repo_config_schema } from './schema.js';
|
|
22
|
+
import { createDefaultRepoConfig, normalizeRepoConfig } from './defaults.js';
|
|
23
|
+
import {
|
|
24
|
+
validateDerivedSummaries,
|
|
25
|
+
validateFieldSchemaConfig,
|
|
26
|
+
validateGraphSchema,
|
|
27
|
+
validateLegacyConfigShape,
|
|
28
|
+
validateStoredQueries,
|
|
29
|
+
} from './validation.js';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Repo config loading.
|
|
33
|
+
*
|
|
34
|
+
* Reads `.patram.json`, applies defaults, and validates repo config and graph
|
|
35
|
+
* schema before command execution.
|
|
36
|
+
*
|
|
37
|
+
* Kind: config
|
|
38
|
+
* Status: active
|
|
39
|
+
* Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
|
|
40
|
+
* Decided by: ../../docs/decisions/single-config-file.md
|
|
41
|
+
* Decided by: ../../docs/decisions/optional-config-default-scan.md
|
|
42
|
+
* @patram
|
|
43
|
+
* @see {@link ./schema.js}
|
|
44
|
+
* @see {@link ./validation.js}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} PatramDiagnostic
|
|
49
|
+
* @property {string} code
|
|
50
|
+
* @property {number} column
|
|
51
|
+
* @property {'error'} level
|
|
52
|
+
* @property {number} line
|
|
53
|
+
* @property {string} message
|
|
54
|
+
* @property {string} path
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @typedef {object} LoadPatramConfigResult
|
|
59
|
+
* @property {import('./schema.js').PatramRepoConfig | null} config
|
|
60
|
+
* @property {string} config_path
|
|
61
|
+
* @property {PatramDiagnostic[]} diagnostics
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @typedef {import('./schema.js').StoredQueryConfig} StoredQueryConfig
|
|
66
|
+
* @typedef {import('./schema.js').FieldDisplayConfig} FieldDisplayConfig
|
|
67
|
+
* @typedef {import('./schema.js').FieldQueryConfig} FieldQueryConfig
|
|
68
|
+
* @typedef {import('./schema.js').MetadataFieldConfig} MetadataFieldConfig
|
|
69
|
+
* @typedef {import('./schema.js').ClassFieldRuleConfig} ClassFieldRuleConfig
|
|
70
|
+
* @typedef {import('./schema.js').ClassSchemaConfig} ClassSchemaConfig
|
|
71
|
+
* @typedef {import('./schema.js').PathClassConfig} PathClassConfig
|
|
72
|
+
* @typedef {import('./schema.js').DerivedSummaryScalar} DerivedSummaryScalar
|
|
73
|
+
* @typedef {import('./schema.js').DerivedSummarySelectCaseConfig} DerivedSummarySelectCaseConfig
|
|
74
|
+
* @typedef {import('./schema.js').DerivedSummaryFieldConfig} DerivedSummaryFieldConfig
|
|
75
|
+
* @typedef {import('./schema.js').DerivedSummaryConfig} DerivedSummaryConfig
|
|
76
|
+
* @typedef {import('./schema.js').PatramRepoConfig} PatramRepoConfig
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Load and validate the repo Patram config.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} [project_directory]
|
|
83
|
+
* @returns {Promise<LoadPatramConfigResult>}
|
|
84
|
+
*/
|
|
85
|
+
export async function loadPatramConfig(project_directory = process.cwd()) {
|
|
86
|
+
const config_file_path = resolve(project_directory, CONFIG_FILE_NAME);
|
|
87
|
+
const config_source = await readConfigSource(config_file_path);
|
|
88
|
+
|
|
89
|
+
if (config_source === null) {
|
|
90
|
+
return createLoadResult(createDefaultRepoConfig(), []);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const parse_result = parseConfigJson(config_source);
|
|
94
|
+
|
|
95
|
+
if (!parse_result.success) {
|
|
96
|
+
return createLoadResult(null, [parse_result.diagnostic]);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const legacy_config_diagnostics = validateLegacyConfigShape(
|
|
100
|
+
parse_result.value,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (legacy_config_diagnostics.length > 0) {
|
|
104
|
+
return createLoadResult(null, legacy_config_diagnostics);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const config_result = patram_repo_config_schema.safeParse(parse_result.value);
|
|
108
|
+
|
|
109
|
+
if (!config_result.success) {
|
|
110
|
+
return createLoadResult(
|
|
111
|
+
null,
|
|
112
|
+
config_result.error.issues.map(createValidationDiagnostic),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const graph_schema_diagnostics = validateGraphSchema(config_result.data);
|
|
117
|
+
|
|
118
|
+
if (graph_schema_diagnostics.length > 0) {
|
|
119
|
+
return createLoadResult(null, graph_schema_diagnostics);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const normalized_config = normalizeRepoConfig(config_result.data);
|
|
123
|
+
const field_schema_diagnostics = validateFieldSchemaConfig(normalized_config);
|
|
124
|
+
|
|
125
|
+
if (field_schema_diagnostics.length > 0) {
|
|
126
|
+
return createLoadResult(null, field_schema_diagnostics);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const stored_query_diagnostics = validateStoredQueries(normalized_config);
|
|
130
|
+
|
|
131
|
+
if (stored_query_diagnostics.length > 0) {
|
|
132
|
+
return createLoadResult(null, stored_query_diagnostics);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const derived_summary_diagnostics =
|
|
136
|
+
validateDerivedSummaries(normalized_config);
|
|
137
|
+
|
|
138
|
+
if (derived_summary_diagnostics.length > 0) {
|
|
139
|
+
return createLoadResult(null, derived_summary_diagnostics);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return createLoadResult(normalized_config, []);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {string} config_file_path
|
|
147
|
+
* @returns {Promise<string | null>}
|
|
148
|
+
*/
|
|
149
|
+
async function readConfigSource(config_file_path) {
|
|
150
|
+
try {
|
|
151
|
+
return await readFile(config_file_path, 'utf8');
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (isMissingFileError(error)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} config_source
|
|
163
|
+
* @returns {{ success: true, value: unknown } | { success: false, diagnostic: PatramDiagnostic }}
|
|
164
|
+
*/
|
|
165
|
+
function parseConfigJson(config_source) {
|
|
166
|
+
try {
|
|
167
|
+
return {
|
|
168
|
+
success: true,
|
|
169
|
+
value: JSON.parse(config_source),
|
|
170
|
+
};
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (error instanceof SyntaxError) {
|
|
173
|
+
return {
|
|
174
|
+
diagnostic: createInvalidJsonDiagnostic(config_source, error),
|
|
175
|
+
success: false,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {import('./schema.js').PatramRepoConfig | null} config
|
|
185
|
+
* @param {PatramDiagnostic[]} diagnostics
|
|
186
|
+
* @returns {LoadPatramConfigResult}
|
|
187
|
+
*/
|
|
188
|
+
function createLoadResult(config, diagnostics) {
|
|
189
|
+
return {
|
|
190
|
+
config,
|
|
191
|
+
config_path: CONFIG_FILE_NAME,
|
|
192
|
+
diagnostics,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {string} config_source
|
|
198
|
+
* @param {SyntaxError} error
|
|
199
|
+
* @returns {PatramDiagnostic}
|
|
200
|
+
*/
|
|
201
|
+
function createInvalidJsonDiagnostic(config_source, error) {
|
|
202
|
+
const origin = getJsonSyntaxOrigin(config_source, error.message);
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
code: 'config.invalid_json',
|
|
206
|
+
column: origin.column,
|
|
207
|
+
level: 'error',
|
|
208
|
+
line: origin.line,
|
|
209
|
+
message: 'Invalid JSON syntax.',
|
|
210
|
+
path: CONFIG_FILE_NAME,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @param {import('zod').core.$ZodIssue} issue
|
|
216
|
+
* @returns {PatramDiagnostic}
|
|
217
|
+
*/
|
|
218
|
+
function createValidationDiagnostic(issue) {
|
|
219
|
+
const issue_path = formatIssuePath(issue.path);
|
|
220
|
+
|
|
221
|
+
if (issue_path) {
|
|
222
|
+
return {
|
|
223
|
+
code: 'config.invalid',
|
|
224
|
+
column: 1,
|
|
225
|
+
level: 'error',
|
|
226
|
+
line: 1,
|
|
227
|
+
message: `Invalid config at "${issue_path}": ${issue.message}`,
|
|
228
|
+
path: CONFIG_FILE_NAME,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
code: 'config.invalid',
|
|
234
|
+
column: 1,
|
|
235
|
+
level: 'error',
|
|
236
|
+
line: 1,
|
|
237
|
+
message: `Invalid config: ${issue.message}`,
|
|
238
|
+
path: CONFIG_FILE_NAME,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @param {unknown} error
|
|
244
|
+
* @returns {error is NodeJS.ErrnoException}
|
|
245
|
+
*/
|
|
246
|
+
function isMissingFileError(error) {
|
|
247
|
+
if (!(error instanceof Error)) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return 'code' in error && error.code === 'ENOENT';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @param {string} config_source
|
|
256
|
+
* @param {string} error_message
|
|
257
|
+
* @returns {{ line: number, column: number }}
|
|
258
|
+
*/
|
|
259
|
+
function getJsonSyntaxOrigin(config_source, error_message) {
|
|
260
|
+
const position_match = error_message.match(/position (?<offset>\d+)/du);
|
|
261
|
+
|
|
262
|
+
if (position_match?.groups?.offset) {
|
|
263
|
+
const offset = Number.parseInt(position_match.groups.offset, 10);
|
|
264
|
+
|
|
265
|
+
return getLineAndColumnFromOffset(config_source, offset);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const token_match = error_message.match(/Unexpected token '(?<token>.)'/u);
|
|
269
|
+
|
|
270
|
+
if (token_match?.groups?.token) {
|
|
271
|
+
const offset = config_source.lastIndexOf(token_match.groups.token);
|
|
272
|
+
|
|
273
|
+
if (offset >= 0) {
|
|
274
|
+
return getLineAndColumnFromOffset(config_source, offset);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
column: 1,
|
|
280
|
+
line: 1,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @param {(string | number | symbol | undefined)[]} issue_path
|
|
286
|
+
* @returns {string}
|
|
287
|
+
*/
|
|
288
|
+
function formatIssuePath(issue_path) {
|
|
289
|
+
return issue_path.map(String).join('.');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @param {string} source_text
|
|
294
|
+
* @param {number} offset
|
|
295
|
+
* @returns {{ line: number, column: number }}
|
|
296
|
+
*/
|
|
297
|
+
function getLineAndColumnFromOffset(source_text, offset) {
|
|
298
|
+
let line_number = 1;
|
|
299
|
+
let column_number = 1;
|
|
300
|
+
|
|
301
|
+
for (const character of source_text.slice(0, offset)) {
|
|
302
|
+
if (character === '\n') {
|
|
303
|
+
line_number += 1;
|
|
304
|
+
column_number = 1;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
column_number += 1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
column: column_number,
|
|
313
|
+
line: line_number,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type StoredQueryConfig = import('./schema.js').StoredQueryConfig;
|
|
2
|
+
export type FieldDisplayConfig = import('./schema.js').FieldDisplayConfig;
|
|
3
|
+
export type FieldQueryConfig = import('./schema.js').FieldQueryConfig;
|
|
4
|
+
export type FieldValueTypeName = import('./schema.js').MetadataFieldConfig['type'];
|
|
5
|
+
export type MetadataFieldConfig = import('./schema.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('./schema.js').ClassFieldRuleConfig;
|
|
28
|
+
export type DirectiveTypeConfig = MetadataFieldConfig;
|
|
29
|
+
export type MetadataDirectiveRuleConfig = ClassFieldRuleConfig;
|
|
30
|
+
export type ClassSchemaConfig = import('./schema.js').ClassSchemaConfig;
|
|
31
|
+
export type MetadataSchemaConfig = ClassSchemaConfig;
|
|
32
|
+
export type PathClassConfig = import('./schema.js').PathClassConfig;
|
|
33
|
+
export type DerivedSummaryScalar = import('./schema.js').DerivedSummaryScalar;
|
|
34
|
+
export type DerivedSummarySelectCaseConfig = import('./schema.js').DerivedSummarySelectCaseConfig;
|
|
35
|
+
export type DerivedSummaryFieldConfig = import('./schema.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('./schema.js').DerivedSummaryConfig;
|
|
43
|
+
export type PatramRepoConfig = import('./schema.js').PatramRepoConfig;
|
|
44
|
+
export type PatramDiagnostic = import('./load-patram-config.js').PatramDiagnostic;
|
|
45
|
+
export type LoadPatramConfigResult = import('./load-patram-config.js').LoadPatramConfigResult;
|
|
@@ -41,10 +41,39 @@ export const mapping_definition_schema: z.ZodObject<{
|
|
|
41
41
|
}>>;
|
|
42
42
|
}, z.core.$strict>>;
|
|
43
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
|
+
/**
|
|
52
|
+
* @typedef {z.output<typeof mapping_node_schema>} MappingNodeDefinition
|
|
53
|
+
*/
|
|
54
|
+
declare const mapping_node_schema: z.ZodObject<{
|
|
55
|
+
class: z.ZodString;
|
|
56
|
+
field: z.ZodString;
|
|
57
|
+
key: z.ZodOptional<z.ZodEnum<{
|
|
58
|
+
path: "path";
|
|
59
|
+
value: "value";
|
|
60
|
+
}>>;
|
|
61
|
+
}, z.core.$strict>;
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {z.output<typeof mapping_emit_schema>} MappingEmitDefinition
|
|
64
|
+
*/
|
|
65
|
+
declare const mapping_emit_schema: z.ZodObject<{
|
|
66
|
+
relation: z.ZodString;
|
|
67
|
+
target: z.ZodEnum<{
|
|
68
|
+
path: "path";
|
|
69
|
+
value: "value";
|
|
70
|
+
}>;
|
|
71
|
+
target_class: z.ZodString;
|
|
72
|
+
}, z.core.$strict>;
|
|
44
73
|
/**
|
|
45
|
-
* @typedef {z.output<typeof
|
|
74
|
+
* @typedef {z.output<typeof patram_config_schema>} PatramGraphConfig
|
|
46
75
|
*/
|
|
47
|
-
|
|
76
|
+
declare const patram_config_schema: z.ZodObject<{
|
|
48
77
|
$schema: z.ZodOptional<z.ZodURL>;
|
|
49
78
|
classes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
50
79
|
builtin: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -74,33 +103,4 @@ export const patramConfigSchema: z.ZodObject<{
|
|
|
74
103
|
to: z.ZodArray<z.ZodString>;
|
|
75
104
|
}, z.core.$strict>>;
|
|
76
105
|
}, 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
106
|
export {};
|
|
@@ -65,9 +65,9 @@ export const mapping_definition_schema = z
|
|
|
65
65
|
.superRefine(validateMappingDefinition);
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* @typedef {z.output<typeof
|
|
68
|
+
* @typedef {z.output<typeof patram_config_schema>} PatramGraphConfig
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
const patram_config_schema = z
|
|
71
71
|
.object({
|
|
72
72
|
$schema: z.url().optional(),
|
|
73
73
|
classes: z.record(CLASS_NAME_SCHEMA, class_definition_schema),
|
|
@@ -84,7 +84,7 @@ export const patramConfigSchema = z
|
|
|
84
84
|
* @returns {PatramGraphConfig}
|
|
85
85
|
*/
|
|
86
86
|
export function parsePatramConfig(config_json) {
|
|
87
|
-
return
|
|
87
|
+
return patram_config_schema.parse(config_json);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassSchemaConfig, MetadataFieldConfig } from './load-patram-config.types.ts';
|
|
1
|
+
import type { ClassSchemaConfig, MetadataFieldConfig } from './load-patram-config.types.d.ts';
|
|
2
2
|
export type ClassDefinition = import('./patram-config.js').ClassDefinition;
|
|
3
3
|
export type RelationDefinition = import('./patram-config.js').RelationDefinition;
|
|
4
4
|
export type MappingNodeDefinition = import('./patram-config.js').MappingNodeDefinition;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* @returns {PatramConfig}
|
|
6
6
|
*/
|
|
7
7
|
export function resolvePatramGraphConfig(repo_config: PatramRepoConfig): PatramConfig;
|
|
8
|
-
import type { PatramRepoConfig } from './load-patram-config.types.ts';
|
|
9
|
-
import type { PatramConfig } from './patram-config.types.ts';
|
|
8
|
+
import type { PatramRepoConfig } from './load-patram-config.types.d.ts';
|
|
9
|
+
import type { PatramConfig } from './patram-config.types.d.ts';
|
|
@@ -14,11 +14,11 @@ import { parsePatramConfig } from './patram-config.js';
|
|
|
14
14
|
*
|
|
15
15
|
* Kind: config
|
|
16
16
|
* Status: active
|
|
17
|
-
* Tracked in:
|
|
18
|
-
* Decided by:
|
|
17
|
+
* Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
|
|
18
|
+
* Decided by: ../../docs/decisions/graph-materialization.md
|
|
19
19
|
* @patram
|
|
20
20
|
* @see {@link ./load-patram-config.js}
|
|
21
|
-
* @see {@link
|
|
21
|
+
* @see {@link ../../docs/graph-v0.md}
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
const BUILT_IN_PATRAM_CONFIG = {
|