patram 0.8.0 → 0.10.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 (143) hide show
  1. package/bin/patram.js +2 -2
  2. package/lib/cli/arguments.types.d.ts +63 -0
  3. package/lib/{parse-cli-color-options.js → cli/color-options.js} +2 -2
  4. package/lib/cli/command-helpers.js +35 -0
  5. package/lib/cli/commands/check.js +73 -0
  6. package/lib/cli/commands/fields.js +57 -0
  7. package/lib/cli/commands/queries.js +41 -0
  8. package/lib/cli/commands/query.js +242 -0
  9. package/lib/cli/commands/refs.js +72 -0
  10. package/lib/cli/commands/show.js +58 -0
  11. package/lib/{cli-help-metadata.js → cli/help-metadata.js} +7 -102
  12. package/lib/cli/main.js +76 -0
  13. package/lib/{parse-cli-arguments-helpers.js → cli/parse-arguments-helpers.js} +24 -12
  14. package/lib/{parse-cli-arguments.js → cli/parse-arguments.js} +12 -12
  15. package/lib/{parse-cli-query-pagination.js → cli/query-pagination.js} +2 -2
  16. package/lib/{render-cli-help.js → cli/render-help.js} +84 -3
  17. package/lib/{resolve-output-mode.js → cli/resolve-output-mode.js} +2 -2
  18. package/lib/cli/test-helpers.js +30 -0
  19. package/lib/config/defaults.d.ts +10 -0
  20. package/lib/config/defaults.js +80 -0
  21. package/lib/config/load-patram-config.d.ts +76 -0
  22. package/lib/config/load-patram-config.js +315 -0
  23. package/lib/config/load-patram-config.types.d.ts +45 -0
  24. package/lib/{patram-config.d.ts → config/patram-config.d.ts} +31 -31
  25. package/lib/{patram-config.js → config/patram-config.js} +3 -3
  26. package/lib/{patram-config.types.d.ts → config/patram-config.types.d.ts} +1 -1
  27. package/lib/{resolve-patram-graph-config.d.ts → config/resolve-patram-graph-config.d.ts} +2 -2
  28. package/lib/{resolve-patram-graph-config.js → config/resolve-patram-graph-config.js} +3 -3
  29. package/lib/{load-patram-config.d.ts → config/schema.d.ts} +149 -191
  30. package/lib/config/schema.js +328 -0
  31. package/lib/{source-file-defaults.d.ts → config/source-file-defaults.d.ts} +0 -1
  32. package/lib/{source-file-defaults.js → config/source-file-defaults.js} +1 -1
  33. package/lib/config/validation.d.ts +27 -0
  34. package/lib/config/validation.js +615 -0
  35. package/lib/directive-validation-test-helpers.js +1 -1
  36. package/lib/find-close-match.d.ts +8 -0
  37. package/lib/find-close-match.js +98 -0
  38. package/lib/{build-graph-identity.d.ts → graph/build-graph-identity.d.ts} +2 -2
  39. package/lib/{build-graph-identity.js → graph/build-graph-identity.js} +1 -1
  40. package/lib/{build-graph.d.ts → graph/build-graph.d.ts} +3 -3
  41. package/lib/{build-graph.js → graph/build-graph.js} +17 -13
  42. package/lib/{build-graph.types.d.ts → graph/build-graph.types.d.ts} +1 -1
  43. package/lib/graph/check-directive-metadata.d.ts +23 -0
  44. package/lib/{check-directive-metadata.js → graph/check-directive-metadata.js} +7 -7
  45. package/lib/graph/check-directive-path-target.d.ts +32 -0
  46. package/lib/{check-directive-path-target.js → graph/check-directive-path-target.js} +4 -4
  47. package/lib/graph/check-directive-value.d.ts +19 -0
  48. package/lib/{check-directive-value.js → graph/check-directive-value.js} +3 -3
  49. package/lib/graph/check-graph.d.ts +29 -0
  50. package/lib/{check-graph.js → graph/check-graph.js} +6 -6
  51. package/lib/graph/directive-diagnostics.d.ts +20 -0
  52. package/lib/{directive-diagnostics.js → graph/directive-diagnostics.js} +2 -2
  53. package/lib/graph/directive-type-rules.d.ts +18 -0
  54. package/lib/{directive-type-rules.js → graph/directive-type-rules.js} +3 -3
  55. package/lib/{document-node-identity.d.ts → graph/document-node-identity.d.ts} +2 -2
  56. package/lib/{document-node-identity.js → graph/document-node-identity.js} +2 -2
  57. package/lib/graph/inspect-reverse-references.d.ts +22 -0
  58. package/lib/{inspect-reverse-references.js → graph/inspect-reverse-references.js} +2 -2
  59. package/lib/{load-project-graph.d.ts → graph/load-project-graph.d.ts} +10 -10
  60. package/lib/{load-project-graph.js → graph/load-project-graph.js} +12 -12
  61. package/lib/{parse-where-clause.types.d.ts → graph/parse-where-clause.types.d.ts} +1 -1
  62. package/lib/{query-graph.d.ts → graph/query/execute.d.ts} +11 -11
  63. package/lib/{query-graph.js → graph/query/execute.js} +12 -12
  64. package/lib/{query-inspection.d.ts → graph/query/inspect.d.ts} +10 -8
  65. package/lib/{query-inspection.js → graph/query/inspect.js} +16 -17
  66. package/lib/{parse-where-clause.d.ts → graph/query/parse.d.ts} +6 -6
  67. package/lib/{parse-where-clause.js → graph/query/parse.js} +2 -2
  68. package/lib/graph/query/resolve.d.ts +28 -0
  69. package/lib/{resolve-where-clause.js → graph/query/resolve.js} +39 -5
  70. package/lib/graph/reverse-reference-test-helpers.d.ts +55 -0
  71. package/lib/{command-output.js → output/command-output.js} +5 -5
  72. package/lib/{derived-summary.js → output/derived-summary.js} +7 -7
  73. package/lib/{layout-incoming-references.js → output/layout-incoming-references.js} +4 -4
  74. package/lib/{layout-incoming-summary-lines.js → output/layout-incoming-summary-lines.js} +0 -5
  75. package/lib/{layout-stored-queries.js → output/layout-stored-queries.js} +27 -11
  76. package/lib/{list-queries.js → output/list-queries.js} +3 -2
  77. package/lib/{render-check-output.js → output/render-check-output.js} +1 -1
  78. package/lib/{render-field-discovery.js → output/render-field-discovery.js} +3 -3
  79. package/lib/output/render-output-view.js +56 -0
  80. package/lib/{render-json-output.js → output/renderers/json.js} +10 -6
  81. package/lib/{render-plain-output.js → output/renderers/plain.js} +34 -33
  82. package/lib/{render-rich-output.js → output/renderers/rich.js} +44 -32
  83. package/lib/{resolve-check-target.js → output/resolve-check-target.js} +1 -1
  84. package/lib/{render-rich-source.js → output/rich-source/render.js} +6 -6
  85. package/lib/{show-document.js → output/show-document.js} +12 -12
  86. package/lib/{render-output-view.js → output/view-model/index.js} +11 -70
  87. package/lib/{write-paged-output.js → output/write-paged-output.js} +9 -5
  88. package/lib/{claim-helpers.d.ts → parse/claim-helpers.d.ts} +2 -2
  89. package/lib/{parse-jsdoc-claims.d.ts → parse/jsdoc/parse-jsdoc-claims.d.ts} +2 -2
  90. package/lib/{parse-jsdoc-claims.js → parse/jsdoc/parse-jsdoc-claims.js} +9 -9
  91. package/lib/{parse-jsdoc-prose.d.ts → parse/jsdoc/parse-jsdoc-prose.d.ts} +1 -1
  92. package/lib/{parse-jsdoc-prose.js → parse/jsdoc/parse-jsdoc-prose.js} +1 -1
  93. package/lib/{parse-markdown-claims.d.ts → parse/markdown/parse-markdown-claims.d.ts} +3 -3
  94. package/lib/{parse-markdown-claims.js → parse/markdown/parse-markdown-claims.js} +8 -8
  95. package/lib/{parse-markdown-directives.d.ts → parse/markdown/parse-markdown-directives.d.ts} +2 -2
  96. package/lib/{parse-markdown-directives.js → parse/markdown/parse-markdown-directives.js} +3 -3
  97. package/lib/{parse-claims.d.ts → parse/parse-claims.d.ts} +4 -13
  98. package/lib/{parse-claims.js → parse/parse-claims.js} +18 -26
  99. package/lib/{parse-claims.types.d.ts → parse/parse-claims.types.d.ts} +1 -1
  100. package/lib/{tagged-fenced-block-error.d.ts → parse/tagged-fenced/tagged-fenced-block-error.d.ts} +2 -2
  101. package/lib/{tagged-fenced-block-parser.d.ts → parse/tagged-fenced/tagged-fenced-block-parser.d.ts} +3 -3
  102. package/lib/{tagged-fenced-blocks.d.ts → parse/tagged-fenced/tagged-fenced-blocks.d.ts} +7 -7
  103. package/lib/{tagged-fenced-blocks.js → parse/tagged-fenced/tagged-fenced-blocks.js} +3 -3
  104. package/lib/{parse-yaml-claims.d.ts → parse/yaml/parse-yaml-claims.d.ts} +4 -4
  105. package/lib/{parse-yaml-claims.js → parse/yaml/parse-yaml-claims.js} +22 -13
  106. package/lib/patram.d.ts +29 -28
  107. package/lib/patram.js +5 -6
  108. package/lib/{discover-fields.js → scan/discover-fields.js} +145 -18
  109. package/lib/scan/list-repo-files.d.ts +16 -0
  110. package/lib/{list-source-files.js → scan/list-repo-files.js} +2 -35
  111. package/lib/{list-source-files.d.ts → scan/list-source-files.d.ts} +4 -11
  112. package/lib/scan/list-source-files.js +45 -0
  113. package/package.json +8 -7
  114. package/lib/build-graph.types.ts +0 -27
  115. package/lib/discover-fields.types.ts +0 -52
  116. package/lib/load-patram-config.js +0 -1215
  117. package/lib/load-patram-config.types.d.ts +0 -45
  118. package/lib/load-patram-config.types.ts +0 -56
  119. package/lib/output-view.types.d.ts +0 -88
  120. package/lib/output-view.types.ts +0 -113
  121. package/lib/overlay-graph.d.ts +0 -43
  122. package/lib/overlay-graph.js +0 -191
  123. package/lib/parse-claims.types.ts +0 -41
  124. package/lib/parse-cli-arguments.types.ts +0 -75
  125. package/lib/parse-where-clause.types.ts +0 -87
  126. package/lib/patram-cli.js +0 -593
  127. package/lib/patram-config.types.ts +0 -22
  128. package/lib/tagged-fenced-blocks.types.ts +0 -38
  129. /package/lib/{reverse-reference-test-helpers.js → graph/reverse-reference-test-helpers.js} +0 -0
  130. /package/lib/{format-derived-summary-row.js → output/format-derived-summary-row.js} +0 -0
  131. /package/lib/{format-node-header.js → output/format-node-header.js} +0 -0
  132. /package/lib/{format-output-item-block.js → output/format-output-item-block.js} +0 -0
  133. /package/lib/{format-output-metadata.js → output/format-output-metadata.js} +0 -0
  134. /package/lib/{claim-helpers.js → parse/claim-helpers.js} +0 -0
  135. /package/lib/{parse-jsdoc-blocks.d.ts → parse/jsdoc/parse-jsdoc-blocks.d.ts} +0 -0
  136. /package/lib/{parse-jsdoc-blocks.js → parse/jsdoc/parse-jsdoc-blocks.js} +0 -0
  137. /package/lib/{tagged-fenced-block-error.js → parse/tagged-fenced/tagged-fenced-block-error.js} +0 -0
  138. /package/lib/{tagged-fenced-block-markdown.d.ts → parse/tagged-fenced/tagged-fenced-block-markdown.d.ts} +0 -0
  139. /package/lib/{tagged-fenced-block-markdown.js → parse/tagged-fenced/tagged-fenced-block-markdown.js} +0 -0
  140. /package/lib/{tagged-fenced-block-metadata.d.ts → parse/tagged-fenced/tagged-fenced-block-metadata.d.ts} +0 -0
  141. /package/lib/{tagged-fenced-block-metadata.js → parse/tagged-fenced/tagged-fenced-block-metadata.js} +0 -0
  142. /package/lib/{tagged-fenced-block-parser.js → parse/tagged-fenced/tagged-fenced-block-parser.js} +0 -0
  143. /package/lib/{tagged-fenced-blocks.types.d.ts → parse/tagged-fenced/tagged-fenced-blocks.types.d.ts} +0 -0
@@ -1,29 +1,155 @@
1
1
  /**
2
- * @typedef {object} LoadPatramConfigResult
3
- * @property {PatramRepoConfig | null} config
4
- * @property {string} config_path
5
- * @property {PatramDiagnostic[]} diagnostics
2
+ * @param {string} field_name
3
+ * @returns {boolean}
6
4
  */
5
+ export function isReservedStructuralFieldName(field_name: string): boolean;
7
6
  /**
8
- * Load and validate the repo Patram config.
9
- *
10
- * @param {string} [project_directory]
11
- * @returns {Promise<LoadPatramConfigResult>}
7
+ * @param {string} markdown_style
8
+ * @returns {boolean}
12
9
  */
13
- export function loadPatramConfig(project_directory?: string): Promise<LoadPatramConfigResult>;
14
- export type LoadPatramConfigResult = {
15
- config: PatramRepoConfig | null;
16
- config_path: string;
17
- diagnostics: PatramDiagnostic[];
18
- };
19
- export type PatramDiagnostic = {
20
- code: string;
21
- column: number;
22
- level: "error";
23
- line: number;
24
- message: string;
25
- path: string;
26
- };
10
+ export function isKnownMarkdownStyle(markdown_style: string): boolean;
11
+ /**
12
+ * @param {string} mixed_styles
13
+ * @returns {boolean}
14
+ */
15
+ export function isMixedStyleValue(mixed_styles: string): boolean;
16
+ export const CONFIG_FILE_NAME: ".patram.json";
17
+ /**
18
+ * @typedef {z.output<typeof patram_repo_config_schema>} PatramRepoConfig
19
+ */
20
+ export const patram_repo_config_schema: z.ZodObject<{
21
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
22
+ builtin: z.ZodOptional<z.ZodBoolean>;
23
+ label: z.ZodOptional<z.ZodString>;
24
+ schema: z.ZodOptional<z.ZodObject<{
25
+ document_path_class: z.ZodOptional<z.ZodString>;
26
+ fields: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
27
+ markdown_styles: z.ZodOptional<z.ZodArray<z.ZodString>>;
28
+ presence: z.ZodEnum<{
29
+ optional: "optional";
30
+ required: "required";
31
+ forbidden: "forbidden";
32
+ }>;
33
+ }, z.core.$strict>>>;
34
+ markdown_styles: z.ZodOptional<z.ZodArray<z.ZodString>>;
35
+ mixed_styles: z.ZodOptional<z.ZodString>;
36
+ unknown_fields: z.ZodOptional<z.ZodEnum<{
37
+ error: "error";
38
+ ignore: "ignore";
39
+ }>>;
40
+ }, z.core.$strict>>;
41
+ }, z.core.$strict>>>;
42
+ derived_summaries: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
43
+ classes: z.ZodArray<z.ZodString>;
44
+ fields: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
45
+ count: z.ZodObject<{
46
+ traversal: z.ZodString;
47
+ where: z.ZodString;
48
+ }, z.core.$strict>;
49
+ name: z.ZodString;
50
+ }, z.core.$strict>, z.ZodObject<{
51
+ default: z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodNull]>;
52
+ name: z.ZodString;
53
+ select: z.ZodArray<z.ZodObject<{
54
+ value: z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodNull]>;
55
+ when: z.ZodString;
56
+ }, z.core.$strict>>;
57
+ }, z.core.$strict>]>>;
58
+ }, z.core.$strict>>>;
59
+ fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
60
+ query: z.ZodOptional<z.ZodObject<{
61
+ contains: z.ZodOptional<z.ZodBoolean>;
62
+ prefix: z.ZodOptional<z.ZodBoolean>;
63
+ }, z.core.$strict>>;
64
+ type: z.ZodLiteral<"string">;
65
+ display: z.ZodOptional<z.ZodObject<{
66
+ hidden: z.ZodOptional<z.ZodBoolean>;
67
+ order: z.ZodOptional<z.ZodNumber>;
68
+ }, z.core.$strict>>;
69
+ multiple: z.ZodOptional<z.ZodBoolean>;
70
+ path_class: z.ZodOptional<z.ZodString>;
71
+ }, z.core.$strict>, z.ZodObject<{
72
+ type: z.ZodLiteral<"integer">;
73
+ display: z.ZodOptional<z.ZodObject<{
74
+ hidden: z.ZodOptional<z.ZodBoolean>;
75
+ order: z.ZodOptional<z.ZodNumber>;
76
+ }, z.core.$strict>>;
77
+ multiple: z.ZodOptional<z.ZodBoolean>;
78
+ path_class: z.ZodOptional<z.ZodString>;
79
+ }, z.core.$strict>, z.ZodObject<{
80
+ type: z.ZodLiteral<"enum">;
81
+ values: z.ZodArray<z.ZodString>;
82
+ display: z.ZodOptional<z.ZodObject<{
83
+ hidden: z.ZodOptional<z.ZodBoolean>;
84
+ order: z.ZodOptional<z.ZodNumber>;
85
+ }, z.core.$strict>>;
86
+ multiple: z.ZodOptional<z.ZodBoolean>;
87
+ path_class: z.ZodOptional<z.ZodString>;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ type: z.ZodLiteral<"path">;
90
+ display: z.ZodOptional<z.ZodObject<{
91
+ hidden: z.ZodOptional<z.ZodBoolean>;
92
+ order: z.ZodOptional<z.ZodNumber>;
93
+ }, z.core.$strict>>;
94
+ multiple: z.ZodOptional<z.ZodBoolean>;
95
+ path_class: z.ZodOptional<z.ZodString>;
96
+ }, z.core.$strict>, z.ZodObject<{
97
+ type: z.ZodLiteral<"glob">;
98
+ display: z.ZodOptional<z.ZodObject<{
99
+ hidden: z.ZodOptional<z.ZodBoolean>;
100
+ order: z.ZodOptional<z.ZodNumber>;
101
+ }, z.core.$strict>>;
102
+ multiple: z.ZodOptional<z.ZodBoolean>;
103
+ path_class: z.ZodOptional<z.ZodString>;
104
+ }, z.core.$strict>, z.ZodObject<{
105
+ type: z.ZodLiteral<"date">;
106
+ display: z.ZodOptional<z.ZodObject<{
107
+ hidden: z.ZodOptional<z.ZodBoolean>;
108
+ order: z.ZodOptional<z.ZodNumber>;
109
+ }, z.core.$strict>>;
110
+ multiple: z.ZodOptional<z.ZodBoolean>;
111
+ path_class: z.ZodOptional<z.ZodString>;
112
+ }, z.core.$strict>, z.ZodObject<{
113
+ type: z.ZodLiteral<"date_time">;
114
+ display: z.ZodOptional<z.ZodObject<{
115
+ hidden: z.ZodOptional<z.ZodBoolean>;
116
+ order: z.ZodOptional<z.ZodNumber>;
117
+ }, z.core.$strict>>;
118
+ multiple: z.ZodOptional<z.ZodBoolean>;
119
+ path_class: z.ZodOptional<z.ZodString>;
120
+ }, z.core.$strict>], "type">>>;
121
+ include: z.ZodDefault<z.ZodArray<z.ZodString>>;
122
+ mappings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
123
+ emit: z.ZodOptional<z.ZodObject<{
124
+ relation: z.ZodString;
125
+ target: z.ZodEnum<{
126
+ path: "path";
127
+ value: "value";
128
+ }>;
129
+ target_class: z.ZodString;
130
+ }, z.core.$strict>>;
131
+ node: z.ZodOptional<z.ZodObject<{
132
+ class: z.ZodString;
133
+ field: z.ZodString;
134
+ key: z.ZodOptional<z.ZodEnum<{
135
+ path: "path";
136
+ value: "value";
137
+ }>>;
138
+ }, z.core.$strict>>;
139
+ }, z.core.$strict>>>;
140
+ path_classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
141
+ prefixes: z.ZodArray<z.ZodString>;
142
+ }, z.core.$strict>>>;
143
+ queries: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
144
+ description: z.ZodOptional<z.ZodString>;
145
+ where: z.ZodString;
146
+ }, z.core.$strict>>>;
147
+ relations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
148
+ builtin: z.ZodOptional<z.ZodBoolean>;
149
+ from: z.ZodArray<z.ZodString>;
150
+ to: z.ZodArray<z.ZodString>;
151
+ }, z.core.$strict>>>;
152
+ }, z.core.$strict>;
27
153
  export type StoredQueryConfig = z.output<typeof stored_query_schema>;
28
154
  export type DerivedSummaryScalar = z.output<typeof derived_summary_scalar_schema>;
29
155
  export type DerivedSummaryCountConfig = z.output<typeof derived_summary_count_schema>;
@@ -35,23 +161,14 @@ export type FieldQueryConfig = z.output<typeof field_query_schema>;
35
161
  export type MetadataFieldConfig = z.output<typeof metadata_field_schema>;
36
162
  export type ClassFieldRuleConfig = z.output<typeof class_field_rule_schema>;
37
163
  export type ClassSchemaConfig = z.output<typeof class_schema_schema>;
38
- export type RepoClassConfig = z.output<typeof repo_class_definition_schema>;
39
164
  export type PathClassConfig = z.output<typeof path_class_schema>;
40
165
  export type PatramRepoConfig = z.output<typeof patram_repo_config_schema>;
41
166
  import { z } from 'zod';
42
- /**
43
- * @typedef {object} PatramDiagnostic
44
- * @property {string} code
45
- * @property {number} column
46
- * @property {'error'} level
47
- * @property {number} line
48
- * @property {string} message
49
- * @property {string} path
50
- */
51
167
  /**
52
168
  * @typedef {z.output<typeof stored_query_schema>} StoredQueryConfig
53
169
  */
54
170
  declare const stored_query_schema: z.ZodObject<{
171
+ description: z.ZodOptional<z.ZodString>;
55
172
  where: z.ZodString;
56
173
  }, z.core.$strict>;
57
174
  /**
@@ -216,169 +333,10 @@ declare const class_schema_schema: z.ZodObject<{
216
333
  ignore: "ignore";
217
334
  }>>;
218
335
  }, z.core.$strict>;
219
- /**
220
- * @typedef {z.output<typeof repo_class_definition_schema>} RepoClassConfig
221
- */
222
- declare const repo_class_definition_schema: z.ZodObject<{
223
- builtin: z.ZodOptional<z.ZodBoolean>;
224
- label: z.ZodOptional<z.ZodString>;
225
- schema: z.ZodOptional<z.ZodObject<{
226
- document_path_class: z.ZodOptional<z.ZodString>;
227
- fields: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
228
- markdown_styles: z.ZodOptional<z.ZodArray<z.ZodString>>;
229
- presence: z.ZodEnum<{
230
- optional: "optional";
231
- required: "required";
232
- forbidden: "forbidden";
233
- }>;
234
- }, z.core.$strict>>>;
235
- markdown_styles: z.ZodOptional<z.ZodArray<z.ZodString>>;
236
- mixed_styles: z.ZodOptional<z.ZodString>;
237
- unknown_fields: z.ZodOptional<z.ZodEnum<{
238
- error: "error";
239
- ignore: "ignore";
240
- }>>;
241
- }, z.core.$strict>>;
242
- }, z.core.$strict>;
243
336
  /**
244
337
  * @typedef {z.output<typeof path_class_schema>} PathClassConfig
245
338
  */
246
339
  declare const path_class_schema: z.ZodObject<{
247
340
  prefixes: z.ZodArray<z.ZodString>;
248
341
  }, z.core.$strict>;
249
- /**
250
- * @typedef {z.output<typeof patram_repo_config_schema>} PatramRepoConfig
251
- */
252
- declare const patram_repo_config_schema: z.ZodObject<{
253
- classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
254
- builtin: z.ZodOptional<z.ZodBoolean>;
255
- label: z.ZodOptional<z.ZodString>;
256
- schema: z.ZodOptional<z.ZodObject<{
257
- document_path_class: z.ZodOptional<z.ZodString>;
258
- fields: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
259
- markdown_styles: z.ZodOptional<z.ZodArray<z.ZodString>>;
260
- presence: z.ZodEnum<{
261
- optional: "optional";
262
- required: "required";
263
- forbidden: "forbidden";
264
- }>;
265
- }, z.core.$strict>>>;
266
- markdown_styles: z.ZodOptional<z.ZodArray<z.ZodString>>;
267
- mixed_styles: z.ZodOptional<z.ZodString>;
268
- unknown_fields: z.ZodOptional<z.ZodEnum<{
269
- error: "error";
270
- ignore: "ignore";
271
- }>>;
272
- }, z.core.$strict>>;
273
- }, z.core.$strict>>>;
274
- derived_summaries: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
275
- classes: z.ZodArray<z.ZodString>;
276
- fields: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
277
- count: z.ZodObject<{
278
- traversal: z.ZodString;
279
- where: z.ZodString;
280
- }, z.core.$strict>;
281
- name: z.ZodString;
282
- }, z.core.$strict>, z.ZodObject<{
283
- default: z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodNull]>;
284
- name: z.ZodString;
285
- select: z.ZodArray<z.ZodObject<{
286
- value: z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodNull]>;
287
- when: z.ZodString;
288
- }, z.core.$strict>>;
289
- }, z.core.$strict>]>>;
290
- }, z.core.$strict>>>;
291
- fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
292
- query: z.ZodOptional<z.ZodObject<{
293
- contains: z.ZodOptional<z.ZodBoolean>;
294
- prefix: z.ZodOptional<z.ZodBoolean>;
295
- }, z.core.$strict>>;
296
- type: z.ZodLiteral<"string">;
297
- display: z.ZodOptional<z.ZodObject<{
298
- hidden: z.ZodOptional<z.ZodBoolean>;
299
- order: z.ZodOptional<z.ZodNumber>;
300
- }, z.core.$strict>>;
301
- multiple: z.ZodOptional<z.ZodBoolean>;
302
- path_class: z.ZodOptional<z.ZodString>;
303
- }, z.core.$strict>, z.ZodObject<{
304
- type: z.ZodLiteral<"integer">;
305
- display: z.ZodOptional<z.ZodObject<{
306
- hidden: z.ZodOptional<z.ZodBoolean>;
307
- order: z.ZodOptional<z.ZodNumber>;
308
- }, z.core.$strict>>;
309
- multiple: z.ZodOptional<z.ZodBoolean>;
310
- path_class: z.ZodOptional<z.ZodString>;
311
- }, z.core.$strict>, z.ZodObject<{
312
- type: z.ZodLiteral<"enum">;
313
- values: z.ZodArray<z.ZodString>;
314
- display: z.ZodOptional<z.ZodObject<{
315
- hidden: z.ZodOptional<z.ZodBoolean>;
316
- order: z.ZodOptional<z.ZodNumber>;
317
- }, z.core.$strict>>;
318
- multiple: z.ZodOptional<z.ZodBoolean>;
319
- path_class: z.ZodOptional<z.ZodString>;
320
- }, z.core.$strict>, z.ZodObject<{
321
- type: z.ZodLiteral<"path">;
322
- display: z.ZodOptional<z.ZodObject<{
323
- hidden: z.ZodOptional<z.ZodBoolean>;
324
- order: z.ZodOptional<z.ZodNumber>;
325
- }, z.core.$strict>>;
326
- multiple: z.ZodOptional<z.ZodBoolean>;
327
- path_class: z.ZodOptional<z.ZodString>;
328
- }, z.core.$strict>, z.ZodObject<{
329
- type: z.ZodLiteral<"glob">;
330
- display: z.ZodOptional<z.ZodObject<{
331
- hidden: z.ZodOptional<z.ZodBoolean>;
332
- order: z.ZodOptional<z.ZodNumber>;
333
- }, z.core.$strict>>;
334
- multiple: z.ZodOptional<z.ZodBoolean>;
335
- path_class: z.ZodOptional<z.ZodString>;
336
- }, z.core.$strict>, z.ZodObject<{
337
- type: z.ZodLiteral<"date">;
338
- display: z.ZodOptional<z.ZodObject<{
339
- hidden: z.ZodOptional<z.ZodBoolean>;
340
- order: z.ZodOptional<z.ZodNumber>;
341
- }, z.core.$strict>>;
342
- multiple: z.ZodOptional<z.ZodBoolean>;
343
- path_class: z.ZodOptional<z.ZodString>;
344
- }, z.core.$strict>, z.ZodObject<{
345
- type: z.ZodLiteral<"date_time">;
346
- display: z.ZodOptional<z.ZodObject<{
347
- hidden: z.ZodOptional<z.ZodBoolean>;
348
- order: z.ZodOptional<z.ZodNumber>;
349
- }, z.core.$strict>>;
350
- multiple: z.ZodOptional<z.ZodBoolean>;
351
- path_class: z.ZodOptional<z.ZodString>;
352
- }, z.core.$strict>], "type">>>;
353
- include: z.ZodDefault<z.ZodArray<z.ZodString>>;
354
- mappings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
355
- emit: z.ZodOptional<z.ZodObject<{
356
- relation: z.ZodString;
357
- target: z.ZodEnum<{
358
- path: "path";
359
- value: "value";
360
- }>;
361
- target_class: z.ZodString;
362
- }, z.core.$strict>>;
363
- node: z.ZodOptional<z.ZodObject<{
364
- class: z.ZodString;
365
- field: z.ZodString;
366
- key: z.ZodOptional<z.ZodEnum<{
367
- path: "path";
368
- value: "value";
369
- }>>;
370
- }, z.core.$strict>>;
371
- }, z.core.$strict>>>;
372
- path_classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
373
- prefixes: z.ZodArray<z.ZodString>;
374
- }, z.core.$strict>>>;
375
- queries: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
376
- where: z.ZodString;
377
- }, z.core.$strict>>>;
378
- relations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
379
- builtin: z.ZodOptional<z.ZodBoolean>;
380
- from: z.ZodArray<z.ZodString>;
381
- to: z.ZodArray<z.ZodString>;
382
- }, z.core.$strict>>>;
383
- }, z.core.$strict>;
384
342
  export {};
@@ -0,0 +1,328 @@
1
+ /** @import * as $k$$l$patram$j$config$k$js from './patram-config.js'; */
2
+ /* eslint-disable max-lines */
3
+
4
+ import { z } from 'zod';
5
+
6
+ import {
7
+ class_definition_schema,
8
+ mapping_definition_schema,
9
+ relation_definition_schema,
10
+ } from './patram-config.js';
11
+ import { DEFAULT_INCLUDE_PATTERNS } from './source-file-defaults.js';
12
+
13
+ export const CONFIG_FILE_NAME = '.patram.json';
14
+
15
+ const RESERVED_STRUCTURAL_FIELD_NAMES = new Set(['$class', '$id', '$path']);
16
+ const MARKDOWN_STYLE_NAMES = [
17
+ 'front_matter',
18
+ 'visible_line',
19
+ 'list_item',
20
+ 'hidden_tag',
21
+ ];
22
+ const MARKDOWN_STYLE_NAME_SET = new Set(MARKDOWN_STYLE_NAMES);
23
+ const MIXED_STYLE_VALUES = new Set(['ignore', 'error']);
24
+
25
+ /**
26
+ * @typedef {z.output<typeof stored_query_schema>} StoredQueryConfig
27
+ */
28
+ const stored_query_schema = z
29
+ .object({
30
+ description: z
31
+ .string()
32
+ .min(1, 'Stored query "description" must not be empty.')
33
+ .optional(),
34
+ where: z.string().min(1, 'Stored query "where" must not be empty.'),
35
+ })
36
+ .strict();
37
+
38
+ /**
39
+ * @typedef {z.output<typeof derived_summary_scalar_schema>} DerivedSummaryScalar
40
+ */
41
+ const derived_summary_scalar_schema = z.union([
42
+ z.boolean(),
43
+ z.number(),
44
+ z.string(),
45
+ z.null(),
46
+ ]);
47
+
48
+ /**
49
+ * @typedef {z.output<typeof derived_summary_count_schema>} DerivedSummaryCountConfig
50
+ */
51
+ const derived_summary_count_schema = z
52
+ .object({
53
+ traversal: z
54
+ .string()
55
+ .min(1, 'Derived summary count "traversal" must not be empty.'),
56
+ where: z
57
+ .string()
58
+ .min(1, 'Derived summary count "where" must not be empty.'),
59
+ })
60
+ .strict();
61
+
62
+ /**
63
+ * @typedef {z.output<typeof derived_summary_select_case_schema>} DerivedSummarySelectCaseConfig
64
+ */
65
+ const derived_summary_select_case_schema = z
66
+ .object({
67
+ value: derived_summary_scalar_schema,
68
+ when: z.string().min(1, 'Derived summary select "when" must not be empty.'),
69
+ })
70
+ .strict();
71
+
72
+ const derived_summary_field_name_schema = z
73
+ .string()
74
+ .regex(
75
+ /^[a-z][a-z0-9_]*$/du,
76
+ 'Derived summary field names must use lower_snake_case.',
77
+ );
78
+
79
+ /**
80
+ * @typedef {z.output<typeof derived_summary_field_schema>} DerivedSummaryFieldConfig
81
+ */
82
+ const derived_summary_count_field_schema = z
83
+ .object({
84
+ count: derived_summary_count_schema,
85
+ name: derived_summary_field_name_schema,
86
+ })
87
+ .strict();
88
+
89
+ const derived_summary_select_field_schema = z
90
+ .object({
91
+ default: derived_summary_scalar_schema,
92
+ name: derived_summary_field_name_schema,
93
+ select: z
94
+ .array(derived_summary_select_case_schema)
95
+ .min(1, 'Derived summary "select" must contain at least one case.'),
96
+ })
97
+ .strict();
98
+
99
+ const derived_summary_field_schema = z.union([
100
+ derived_summary_count_field_schema,
101
+ derived_summary_select_field_schema,
102
+ ]);
103
+
104
+ /**
105
+ * @typedef {z.output<typeof derived_summary_schema>} DerivedSummaryConfig
106
+ */
107
+ const derived_summary_schema = z
108
+ .object({
109
+ classes: z
110
+ .array(z.string().min(1))
111
+ .min(1, 'Derived summary "classes" must contain at least one class.'),
112
+ fields: z
113
+ .array(derived_summary_field_schema)
114
+ .min(1, 'Derived summary "fields" must contain at least one field.'),
115
+ })
116
+ .strict()
117
+ .superRefine(validateDerivedSummaryDefinition);
118
+
119
+ /**
120
+ * @typedef {z.output<typeof field_display_schema>} FieldDisplayConfig
121
+ */
122
+ const field_display_schema = z
123
+ .object({
124
+ hidden: z.boolean().optional(),
125
+ order: z.number().optional(),
126
+ })
127
+ .strict();
128
+
129
+ /**
130
+ * @typedef {z.output<typeof field_query_schema>} FieldQueryConfig
131
+ */
132
+ const field_query_schema = z
133
+ .object({
134
+ contains: z.boolean().optional(),
135
+ prefix: z.boolean().optional(),
136
+ })
137
+ .strict();
138
+
139
+ const field_base_shape = {
140
+ display: field_display_schema.optional(),
141
+ multiple: z.boolean().optional(),
142
+ path_class: z.string().min(1).optional(),
143
+ };
144
+
145
+ /**
146
+ * @typedef {z.output<typeof metadata_field_schema>} MetadataFieldConfig
147
+ */
148
+ const metadata_field_schema = z.discriminatedUnion('type', [
149
+ z
150
+ .object({
151
+ ...field_base_shape,
152
+ query: field_query_schema.optional(),
153
+ type: z.literal('string'),
154
+ })
155
+ .strict(),
156
+ z
157
+ .object({
158
+ ...field_base_shape,
159
+ type: z.literal('integer'),
160
+ })
161
+ .strict(),
162
+ z
163
+ .object({
164
+ ...field_base_shape,
165
+ type: z.literal('enum'),
166
+ values: z
167
+ .array(z.string().min(1, 'Field enum values must not be empty.'))
168
+ .min(1, 'Field enum values must contain at least one value.'),
169
+ })
170
+ .strict(),
171
+ z
172
+ .object({
173
+ ...field_base_shape,
174
+ type: z.literal('path'),
175
+ })
176
+ .strict(),
177
+ z
178
+ .object({
179
+ ...field_base_shape,
180
+ type: z.literal('glob'),
181
+ })
182
+ .strict(),
183
+ z
184
+ .object({
185
+ ...field_base_shape,
186
+ type: z.literal('date'),
187
+ })
188
+ .strict(),
189
+ z
190
+ .object({
191
+ ...field_base_shape,
192
+ type: z.literal('date_time'),
193
+ })
194
+ .strict(),
195
+ ]);
196
+
197
+ /**
198
+ * @typedef {z.output<typeof class_field_rule_schema>} ClassFieldRuleConfig
199
+ */
200
+ const class_field_rule_schema = z
201
+ .object({
202
+ markdown_styles: z.array(z.string().min(1)).optional(),
203
+ presence: z.enum(['required', 'optional', 'forbidden']),
204
+ })
205
+ .strict();
206
+
207
+ /**
208
+ * @typedef {z.output<typeof class_schema_schema>} ClassSchemaConfig
209
+ */
210
+ const class_schema_schema = z
211
+ .object({
212
+ document_path_class: z.string().min(1).optional(),
213
+ fields: z.record(z.string().min(1), class_field_rule_schema).default({}),
214
+ markdown_styles: z.array(z.string().min(1)).optional(),
215
+ mixed_styles: z.string().min(1).optional(),
216
+ unknown_fields: z.enum(['ignore', 'error']).optional(),
217
+ })
218
+ .strict();
219
+
220
+ const repo_class_definition_schema = class_definition_schema.extend({
221
+ schema: class_schema_schema.optional(),
222
+ });
223
+
224
+ /**
225
+ * @typedef {z.output<typeof path_class_schema>} PathClassConfig
226
+ */
227
+ const path_class_schema = z
228
+ .object({
229
+ prefixes: z
230
+ .array(z.string().min(1, 'Path class prefixes must not be empty.'))
231
+ .min(1, 'Path classes must contain at least one prefix.'),
232
+ })
233
+ .strict();
234
+
235
+ /**
236
+ * @typedef {z.output<typeof patram_repo_config_schema>} PatramRepoConfig
237
+ */
238
+ export const patram_repo_config_schema = z
239
+ .object({
240
+ classes: z
241
+ .record(z.string().min(1), repo_class_definition_schema)
242
+ .optional(),
243
+ derived_summaries: z
244
+ .record(z.string().min(1), derived_summary_schema)
245
+ .optional(),
246
+ fields: z.record(z.string().min(1), metadata_field_schema).optional(),
247
+ include: z
248
+ .array(z.string().min(1, 'Include globs must not be empty.'))
249
+ .min(1, 'Include must contain at least one glob.')
250
+ .default(DEFAULT_INCLUDE_PATTERNS),
251
+ mappings: z.record(z.string().min(1), mapping_definition_schema).optional(),
252
+ path_classes: z.record(z.string().min(1), path_class_schema).optional(),
253
+ queries: z.record(z.string().min(1), stored_query_schema).default({}),
254
+ relations: z
255
+ .record(z.string().min(1), relation_definition_schema)
256
+ .optional(),
257
+ })
258
+ .strict()
259
+ .superRefine(validateFieldDefinitionKeys);
260
+
261
+ /**
262
+ * @param {{ fields?: Record<string, MetadataFieldConfig> }} repo_config
263
+ * @param {import('zod').RefinementCtx} refinement_context
264
+ */
265
+ function validateFieldDefinitionKeys(repo_config, refinement_context) {
266
+ for (const field_name of Object.keys(repo_config.fields ?? {})) {
267
+ if (!field_name.startsWith('$')) {
268
+ continue;
269
+ }
270
+
271
+ refinement_context.addIssue({
272
+ code: 'custom',
273
+ message: 'Metadata field names must not start with "$".',
274
+ path: ['fields', field_name],
275
+ });
276
+ }
277
+ }
278
+
279
+ /**
280
+ * @param {{ fields: Array<{ name: string }> }} summary_definition
281
+ * @param {import('zod').RefinementCtx} refinement_context
282
+ */
283
+ function validateDerivedSummaryDefinition(
284
+ summary_definition,
285
+ refinement_context,
286
+ ) {
287
+ const seen_field_names = new Set();
288
+
289
+ for (const [
290
+ field_index,
291
+ field_definition,
292
+ ] of summary_definition.fields.entries()) {
293
+ if (!seen_field_names.has(field_definition.name)) {
294
+ seen_field_names.add(field_definition.name);
295
+ continue;
296
+ }
297
+
298
+ refinement_context.addIssue({
299
+ code: 'custom',
300
+ message: `Duplicate derived summary field "${field_definition.name}".`,
301
+ path: ['fields', field_index, 'name'],
302
+ });
303
+ }
304
+ }
305
+
306
+ /**
307
+ * @param {string} field_name
308
+ * @returns {boolean}
309
+ */
310
+ export function isReservedStructuralFieldName(field_name) {
311
+ return RESERVED_STRUCTURAL_FIELD_NAMES.has(field_name);
312
+ }
313
+
314
+ /**
315
+ * @param {string} markdown_style
316
+ * @returns {boolean}
317
+ */
318
+ export function isKnownMarkdownStyle(markdown_style) {
319
+ return MARKDOWN_STYLE_NAME_SET.has(markdown_style);
320
+ }
321
+
322
+ /**
323
+ * @param {string} mixed_styles
324
+ * @returns {boolean}
325
+ */
326
+ export function isMixedStyleValue(mixed_styles) {
327
+ return MIXED_STYLE_VALUES.has(mixed_styles);
328
+ }