legal-markdown-js 0.1.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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -0
  3. package/dist/browser.d.ts +87 -0
  4. package/dist/browser.d.ts.map +1 -0
  5. package/dist/browser.js +157 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/cli/index.d.ts +34 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +221 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/service.d.ts +128 -0
  12. package/dist/cli/service.d.ts.map +1 -0
  13. package/dist/cli/service.js +284 -0
  14. package/dist/cli/service.js.map +1 -0
  15. package/dist/constants/index.d.ts +229 -0
  16. package/dist/constants/index.d.ts.map +1 -0
  17. package/dist/constants/index.js +232 -0
  18. package/dist/constants/index.js.map +1 -0
  19. package/dist/core/exporters/metadata-exporter.d.ts +104 -0
  20. package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
  21. package/dist/core/exporters/metadata-exporter.js +201 -0
  22. package/dist/core/exporters/metadata-exporter.js.map +1 -0
  23. package/dist/core/index.d.ts +40 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/index.js +56 -0
  26. package/dist/core/index.js.map +1 -0
  27. package/dist/core/parsers/yaml-parser.d.ts +149 -0
  28. package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
  29. package/dist/core/parsers/yaml-parser.js +321 -0
  30. package/dist/core/parsers/yaml-parser.js.map +1 -0
  31. package/dist/core/processors/clause-processor.d.ts +74 -0
  32. package/dist/core/processors/clause-processor.d.ts.map +1 -0
  33. package/dist/core/processors/clause-processor.js +213 -0
  34. package/dist/core/processors/clause-processor.js.map +1 -0
  35. package/dist/core/processors/date-processor.d.ts +90 -0
  36. package/dist/core/processors/date-processor.d.ts.map +1 -0
  37. package/dist/core/processors/date-processor.js +336 -0
  38. package/dist/core/processors/date-processor.js.map +1 -0
  39. package/dist/core/processors/header-processor.d.ts +104 -0
  40. package/dist/core/processors/header-processor.d.ts.map +1 -0
  41. package/dist/core/processors/header-processor.js +585 -0
  42. package/dist/core/processors/header-processor.js.map +1 -0
  43. package/dist/core/processors/import-processor.d.ts +116 -0
  44. package/dist/core/processors/import-processor.d.ts.map +1 -0
  45. package/dist/core/processors/import-processor.js +236 -0
  46. package/dist/core/processors/import-processor.js.map +1 -0
  47. package/dist/core/processors/mixin-processor.d.ts +93 -0
  48. package/dist/core/processors/mixin-processor.d.ts.map +1 -0
  49. package/dist/core/processors/mixin-processor.js +378 -0
  50. package/dist/core/processors/mixin-processor.js.map +1 -0
  51. package/dist/core/processors/reference-processor.d.ts +115 -0
  52. package/dist/core/processors/reference-processor.d.ts.map +1 -0
  53. package/dist/core/processors/reference-processor.js +273 -0
  54. package/dist/core/processors/reference-processor.js.map +1 -0
  55. package/dist/errors/index.d.ts +234 -0
  56. package/dist/errors/index.d.ts.map +1 -0
  57. package/dist/errors/index.js +267 -0
  58. package/dist/errors/index.js.map +1 -0
  59. package/dist/extensions/batch-processor.d.ts +197 -0
  60. package/dist/extensions/batch-processor.d.ts.map +1 -0
  61. package/dist/extensions/batch-processor.js +392 -0
  62. package/dist/extensions/batch-processor.js.map +1 -0
  63. package/dist/extensions/formatters/index.d.ts +99 -0
  64. package/dist/extensions/formatters/index.d.ts.map +1 -0
  65. package/dist/extensions/formatters/index.js +128 -0
  66. package/dist/extensions/formatters/index.js.map +1 -0
  67. package/dist/extensions/index.d.ts +53 -0
  68. package/dist/extensions/index.d.ts.map +1 -0
  69. package/dist/extensions/index.js +71 -0
  70. package/dist/extensions/index.js.map +1 -0
  71. package/dist/extensions/latex-parser.d.ts +111 -0
  72. package/dist/extensions/latex-parser.d.ts.map +1 -0
  73. package/dist/extensions/latex-parser.js +563 -0
  74. package/dist/extensions/latex-parser.js.map +1 -0
  75. package/dist/extensions/rst-parser.d.ts +112 -0
  76. package/dist/extensions/rst-parser.d.ts.map +1 -0
  77. package/dist/extensions/rst-parser.js +268 -0
  78. package/dist/extensions/rst-parser.js.map +1 -0
  79. package/dist/extensions/template-loops.d.ts +61 -0
  80. package/dist/extensions/template-loops.d.ts.map +1 -0
  81. package/dist/extensions/template-loops.js +418 -0
  82. package/dist/extensions/template-loops.js.map +1 -0
  83. package/dist/extensions/utilities/index.d.ts +114 -0
  84. package/dist/extensions/utilities/index.d.ts.map +1 -0
  85. package/dist/extensions/utilities/index.js +137 -0
  86. package/dist/extensions/utilities/index.js.map +1 -0
  87. package/dist/extensions/validators/index.d.ts +65 -0
  88. package/dist/extensions/validators/index.d.ts.map +1 -0
  89. package/dist/extensions/validators/index.js +88 -0
  90. package/dist/extensions/validators/index.js.map +1 -0
  91. package/dist/generators/html-generator.d.ts +184 -0
  92. package/dist/generators/html-generator.d.ts.map +1 -0
  93. package/dist/generators/html-generator.js +361 -0
  94. package/dist/generators/html-generator.js.map +1 -0
  95. package/dist/generators/pdf-generator.d.ts +165 -0
  96. package/dist/generators/pdf-generator.d.ts.map +1 -0
  97. package/dist/generators/pdf-generator.js +275 -0
  98. package/dist/generators/pdf-generator.js.map +1 -0
  99. package/dist/helpers/date-helpers.d.ts +216 -0
  100. package/dist/helpers/date-helpers.d.ts.map +1 -0
  101. package/dist/helpers/date-helpers.js +402 -0
  102. package/dist/helpers/date-helpers.js.map +1 -0
  103. package/dist/helpers/index.d.ts +87 -0
  104. package/dist/helpers/index.d.ts.map +1 -0
  105. package/dist/helpers/index.js +149 -0
  106. package/dist/helpers/index.js.map +1 -0
  107. package/dist/helpers/number-helpers.d.ts +269 -0
  108. package/dist/helpers/number-helpers.d.ts.map +1 -0
  109. package/dist/helpers/number-helpers.js +406 -0
  110. package/dist/helpers/number-helpers.js.map +1 -0
  111. package/dist/helpers/string-helpers.d.ts +391 -0
  112. package/dist/helpers/string-helpers.d.ts.map +1 -0
  113. package/dist/helpers/string-helpers.js +549 -0
  114. package/dist/helpers/string-helpers.js.map +1 -0
  115. package/dist/index.d.ts +229 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +384 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/legal-markdown.umd.min.js +2 -0
  120. package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
  121. package/dist/legal-markdown.umd.min.js.map +1 -0
  122. package/dist/lib/index.d.ts +150 -0
  123. package/dist/lib/index.d.ts.map +1 -0
  124. package/dist/lib/index.js +265 -0
  125. package/dist/lib/index.js.map +1 -0
  126. package/dist/parsers/content-detector.d.ts +131 -0
  127. package/dist/parsers/content-detector.d.ts.map +1 -0
  128. package/dist/parsers/content-detector.js +220 -0
  129. package/dist/parsers/content-detector.js.map +1 -0
  130. package/dist/parsers/fallback-parsers.d.ts +14 -0
  131. package/dist/parsers/fallback-parsers.d.ts.map +1 -0
  132. package/dist/parsers/fallback-parsers.js +188 -0
  133. package/dist/parsers/fallback-parsers.js.map +1 -0
  134. package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
  135. package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
  136. package/dist/parsers/implementations/pandoc-native.js +63 -0
  137. package/dist/parsers/implementations/pandoc-native.js.map +1 -0
  138. package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
  139. package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
  140. package/dist/parsers/implementations/pandoc-wasm.js +64 -0
  141. package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
  142. package/dist/parsers/pandoc-factory.d.ts +97 -0
  143. package/dist/parsers/pandoc-factory.d.ts.map +1 -0
  144. package/dist/parsers/pandoc-factory.js +146 -0
  145. package/dist/parsers/pandoc-factory.js.map +1 -0
  146. package/dist/parsers/pandoc-loader.d.ts +24 -0
  147. package/dist/parsers/pandoc-loader.d.ts.map +1 -0
  148. package/dist/parsers/pandoc-loader.js +124 -0
  149. package/dist/parsers/pandoc-loader.js.map +1 -0
  150. package/dist/parsers/pandoc-parser.d.ts +27 -0
  151. package/dist/parsers/pandoc-parser.d.ts.map +1 -0
  152. package/dist/parsers/pandoc-parser.js +3 -0
  153. package/dist/parsers/pandoc-parser.js.map +1 -0
  154. package/dist/styles/default.css +125 -0
  155. package/dist/styles/headers.css +146 -0
  156. package/dist/styles/highlight.css +171 -0
  157. package/dist/tracking/field-tracker.d.ts +206 -0
  158. package/dist/tracking/field-tracker.d.ts.map +1 -0
  159. package/dist/tracking/field-tracker.js +247 -0
  160. package/dist/tracking/field-tracker.js.map +1 -0
  161. package/dist/types.d.ts +186 -0
  162. package/dist/types.d.ts.map +1 -0
  163. package/dist/types.js +33 -0
  164. package/dist/types.js.map +1 -0
  165. package/dist/utils/logger.d.ts +107 -0
  166. package/dist/utils/logger.d.ts.map +1 -0
  167. package/dist/utils/logger.js +122 -0
  168. package/dist/utils/logger.js.map +1 -0
  169. package/dist/web/bundle-standalone.js +28 -0
  170. package/dist/web/bundle.js +17 -0
  171. package/dist/web/index.html +1465 -0
  172. package/dist/web/legal-markdown.umd.min.js +2 -0
  173. package/dist/web/standalone.html +390 -0
  174. package/dist/web/styles.css +874 -0
  175. package/package.json +118 -0
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Cross-Reference Processing Module for Legal Markdown Documents
4
+ *
5
+ * This module provides functionality to process cross-references in Legal Markdown
6
+ * documents, replacing reference placeholders with actual values from metadata.
7
+ * It supports various formatting options including date formatting, currency
8
+ * formatting, and nested metadata access through dot notation.
9
+ *
10
+ * Features:
11
+ * - Cross-reference syntax: |reference_key|
12
+ * - Date reference processing with @today support
13
+ * - Automatic currency formatting for amount fields
14
+ * - Nested metadata value access with dot notation
15
+ * - Type-aware value formatting (dates, numbers, strings)
16
+ * - Fallback to original reference if value not found
17
+ * - Integration with date-processor for date handling
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { processCrossReferences } from './reference-processor';
22
+ *
23
+ * const content = `
24
+ * This agreement is between |client.name| and |provider.name|.
25
+ * The total amount is |contract.amount| due on |contract.due_date|.
26
+ * Document generated on |@today|.
27
+ * `;
28
+ *
29
+ * const metadata = {
30
+ * client: { name: "Acme Corp" },
31
+ * provider: { name: "Service Ltd" },
32
+ * contract: {
33
+ * amount: 25000,
34
+ * due_date: new Date("2024-12-31")
35
+ * },
36
+ * payment_currency: "USD"
37
+ * };
38
+ *
39
+ * const processed = processCrossReferences(content, metadata);
40
+ * console.log(processed);
41
+ * // Output:
42
+ * // This agreement is between Acme Corp and Service Ltd.
43
+ * // The total amount is $25,000.00 due on 2024-12-31.
44
+ * // Document generated on 2024-01-15.
45
+ * ```
46
+ */
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.processCrossReferences = processCrossReferences;
49
+ exports.formatReferenceValue = formatReferenceValue;
50
+ const date_processor_1 = require("./date-processor");
51
+ /**
52
+ * Processes cross-references in a LegalMarkdown document
53
+ *
54
+ * This is the main function that processes cross-references using the |reference_key|
55
+ * syntax. It first processes date references, then handles regular cross-references
56
+ * with automatic formatting based on value type and field names.
57
+ *
58
+ * @param {string} content - The document content containing cross-references
59
+ * @param {Record<string, any>} metadata - Document metadata with reference values
60
+ * @returns {string} Processed content with references replaced by their values
61
+ * @example
62
+ * ```typescript
63
+ * // Basic reference processing
64
+ * const content = "Payment due: |payment.amount| on |payment.date|";
65
+ * const metadata = {
66
+ * payment: {
67
+ * amount: 1500,
68
+ * date: new Date("2024-03-15")
69
+ * },
70
+ * payment_currency: "EUR"
71
+ * };
72
+ *
73
+ * const result = processCrossReferences(content, metadata);
74
+ * // Output: "Payment due: €1,500.00 on 2024-03-15"
75
+ *
76
+ * // Nested reference access
77
+ * const content2 = "Contact: |client.contact.email| (|client.contact.phone|)";
78
+ * const metadata2 = {
79
+ * client: {
80
+ * contact: {
81
+ * email: "info@client.com",
82
+ * phone: "+1-555-0123"
83
+ * }
84
+ * }
85
+ * };
86
+ *
87
+ * const result2 = processCrossReferences(content2, metadata2);
88
+ * // Output: "Contact: info@client.com (+1-555-0123)"
89
+ * ```
90
+ */
91
+ function processCrossReferences(content, metadata) {
92
+ // First process date references (@today)
93
+ const processedContent = (0, date_processor_1.processDateReferences)(content, metadata);
94
+ // Then process regular cross-references
95
+ // Format: |reference_key|
96
+ const referencePattern = /\|(.*?)\|/g;
97
+ return processedContent.replace(referencePattern, (match, key) => {
98
+ // Get the reference value from metadata
99
+ const value = getNestedValue(metadata, key.trim());
100
+ if (value === undefined) {
101
+ return match;
102
+ }
103
+ // Format value based on type
104
+ if (value instanceof Date) {
105
+ return formatDate(value);
106
+ }
107
+ else if (typeof value === 'number' && key.includes('amount')) {
108
+ // Format currency if key contains 'amount'
109
+ const currency = metadata.payment_currency || 'USD';
110
+ return formatCurrency(value, `currency:${currency}`);
111
+ }
112
+ // Default string conversion
113
+ return String(value);
114
+ });
115
+ }
116
+ /**
117
+ * Gets a potentially nested value from an object
118
+ *
119
+ * Traverses an object using dot notation to access nested properties safely.
120
+ * Returns undefined if any part of the path doesn't exist, preventing errors
121
+ * when accessing deeply nested properties.
122
+ *
123
+ * @private
124
+ * @param {Record<string, any>} obj - Object to extract value from
125
+ * @param {string} path - Dot-separated path to the value (e.g., "user.profile.name")
126
+ * @returns {any} The value at the specified path, or undefined if not found
127
+ * @example
128
+ * ```typescript
129
+ * const obj = {
130
+ * contract: {
131
+ * parties: {
132
+ * client: { name: "Acme Corp", id: 12345 },
133
+ * provider: { name: "Service Ltd" }
134
+ * },
135
+ * terms: { duration: 12 }
136
+ * }
137
+ * };
138
+ *
139
+ * console.log(getNestedValue(obj, "contract.parties.client.name")); // "Acme Corp"
140
+ * console.log(getNestedValue(obj, "contract.terms.duration")); // 12
141
+ * console.log(getNestedValue(obj, "contract.nonexistent")); // undefined
142
+ * ```
143
+ */
144
+ function getNestedValue(obj, path) {
145
+ const keys = path.split('.');
146
+ let value = obj;
147
+ for (const key of keys) {
148
+ if (value === undefined || value === null) {
149
+ return undefined;
150
+ }
151
+ value = value[key];
152
+ }
153
+ return value;
154
+ }
155
+ /**
156
+ * Processes special reference formats like dates and currency amounts
157
+ *
158
+ * Applies appropriate formatting to reference values based on their type and
159
+ * optional format specifiers. Handles dates, currency amounts, and falls back
160
+ * to string conversion for other types.
161
+ *
162
+ * @param {any} value - The reference value to format
163
+ * @param {string} [format] - Optional format specifier (e.g., "currency:USD:en-US")
164
+ * @returns {string} Formatted value as string
165
+ * @example
166
+ * ```typescript
167
+ * // Date formatting
168
+ * const date = new Date("2024-03-15");
169
+ * console.log(formatReferenceValue(date)); // "2024-03-15"
170
+ * console.log(formatReferenceValue(date, "long")); // "March 15, 2024"
171
+ * console.log(formatReferenceValue(date, "short")); // "3/15/2024"
172
+ *
173
+ * // Currency formatting
174
+ * console.log(formatReferenceValue(1500, "currency:USD")); // "$1,500.00"
175
+ * console.log(formatReferenceValue(1500, "currency:EUR:de-DE")); // "1.500,00 €"
176
+ *
177
+ * // Default string conversion
178
+ * console.log(formatReferenceValue("Hello World")); // "Hello World"
179
+ * console.log(formatReferenceValue(12345)); // "12345"
180
+ * ```
181
+ */
182
+ function formatReferenceValue(value, format) {
183
+ if (value === undefined || value === null) {
184
+ return '';
185
+ }
186
+ // Handle different types
187
+ if (typeof value === 'object' && value instanceof Date) {
188
+ return formatDate(value, format);
189
+ }
190
+ if (typeof value === 'number' && format?.startsWith('currency')) {
191
+ return formatCurrency(value, format);
192
+ }
193
+ // Default: convert to string
194
+ return String(value);
195
+ }
196
+ /**
197
+ * Formats a date value
198
+ *
199
+ * Converts a Date object to a formatted string using various format options.
200
+ * Supports ISO format (default), short format, and long format for different
201
+ * document presentation needs.
202
+ *
203
+ * @private
204
+ * @param {Date} date - Date to format
205
+ * @param {string} [format] - Date format specification ("short", "long", or default ISO)
206
+ * @returns {string} Formatted date string
207
+ * @example
208
+ * ```typescript
209
+ * const date = new Date("2024-03-15T10:30:00Z");
210
+ *
211
+ * console.log(formatDate(date)); // "2024-03-15" (ISO format)
212
+ * console.log(formatDate(date, "short")); // "3/15/2024" (locale-specific)
213
+ * console.log(formatDate(date, "long")); // "March 15, 2024" (long format)
214
+ * ```
215
+ */
216
+ function formatDate(date, format) {
217
+ if (!format) {
218
+ // Default format: YYYY-MM-DD
219
+ return date.toISOString().split('T')[0];
220
+ }
221
+ // Custom date formatting
222
+ if (format === 'short') {
223
+ return date.toLocaleDateString();
224
+ }
225
+ else if (format === 'long') {
226
+ return date.toLocaleDateString(undefined, {
227
+ year: 'numeric',
228
+ month: 'long',
229
+ day: 'numeric',
230
+ });
231
+ }
232
+ return date.toISOString().split('T')[0]; // Default to ISO format
233
+ }
234
+ /**
235
+ * Formats a number as currency
236
+ *
237
+ * Converts a numeric amount to a formatted currency string using the
238
+ * Intl.NumberFormat API. Supports different currencies and locales
239
+ * based on the format specification.
240
+ *
241
+ * @private
242
+ * @param {number} amount - Amount to format
243
+ * @param {string} [format] - Currency format specification ("currency:CODE:locale")
244
+ * @returns {string} Formatted currency string
245
+ * @example
246
+ * ```typescript
247
+ * console.log(formatCurrency(1500)); // "$1,500.00" (default USD)
248
+ * console.log(formatCurrency(1500, "currency:EUR")); // "€1,500.00"
249
+ * console.log(formatCurrency(1500, "currency:GBP:en-GB")); // "£1,500.00"
250
+ * console.log(formatCurrency(1500, "currency:JPY:ja-JP")); // "¥1,500"
251
+ * console.log(formatCurrency(1500, "currency:EUR:de-DE")); // "1.500,00 €"
252
+ * ```
253
+ */
254
+ function formatCurrency(amount, format) {
255
+ let currency = 'USD';
256
+ let locale = 'en-US';
257
+ // Parse format specification
258
+ if (format) {
259
+ const parts = format.split(':');
260
+ if (parts.length > 1) {
261
+ currency = parts[1].trim().toUpperCase();
262
+ }
263
+ if (parts.length > 2) {
264
+ locale = parts[2].trim();
265
+ }
266
+ }
267
+ // Format using Intl.NumberFormat
268
+ return new Intl.NumberFormat(locale, {
269
+ style: 'currency',
270
+ currency,
271
+ }).format(amount);
272
+ }
273
+ //# sourceMappingURL=reference-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-processor.js","sourceRoot":"","sources":["../../../src/core/processors/reference-processor.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C,CAAC;SAAM,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE;YACxC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;YACb,GAAG,EAAE,SAAS;SACf,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,wBAAwB;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,cAAc,CAAC,MAAc,EAAE,MAAe;IACrD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,MAAM,GAAG,OAAO,CAAC;IAErB,6BAA6B;IAC7B,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QACnC,KAAK,EAAE,UAAU;QACjB,QAAQ;KACT,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACpB,CAAC"}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * @fileoverview Custom Error Classes for Legal Markdown Processing
3
+ *
4
+ * This module provides a comprehensive set of custom error classes for the Legal Markdown
5
+ * processing system. All errors inherit from a base LegalMarkdownError class that provides
6
+ * structured error handling with error codes and contextual information.
7
+ *
8
+ * Features:
9
+ * - Base LegalMarkdownError class with error codes and context
10
+ * - Specialized error classes for different failure scenarios
11
+ * - Structured error information for debugging and user feedback
12
+ * - Proper stack trace preservation
13
+ * - Contextual data attachment for detailed error reporting
14
+ * - Type-safe error handling throughout the system
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { YamlParsingError, FileNotFoundError, ValidationError } from './errors';
19
+ *
20
+ * // YAML parsing error
21
+ * throw new YamlParsingError('Invalid YAML syntax', { line: 5, column: 12 });
22
+ *
23
+ * // File not found error
24
+ * throw new FileNotFoundError('./missing-file.md', { operation: 'import' });
25
+ *
26
+ * // Validation error
27
+ * throw new ValidationError('Field is required', 'client.name', { value: '' });
28
+ * ```
29
+ */
30
+ /**
31
+ * Base error class for all Legal Markdown processing errors
32
+ *
33
+ * Provides structured error handling with error codes and contextual information.
34
+ * All other error types in the system inherit from this base class.
35
+ *
36
+ * @class LegalMarkdownError
37
+ * @extends {Error}
38
+ * @example
39
+ * ```typescript
40
+ * import { LegalMarkdownError } from './errors';
41
+ *
42
+ * // Create a custom error with context
43
+ * const error = new LegalMarkdownError(
44
+ * 'Processing failed',
45
+ * 'PROCESSING_ERROR',
46
+ * { file: 'contract.md', step: 'field-resolution' }
47
+ * );
48
+ *
49
+ * console.log(error.code); // 'PROCESSING_ERROR'
50
+ * console.log(error.context); // { file: 'contract.md', step: 'field-resolution' }
51
+ * ```
52
+ */
53
+ export declare class LegalMarkdownError extends Error {
54
+ /** Error code for programmatic error handling */
55
+ readonly code: string;
56
+ /** Optional contextual data about the error */
57
+ readonly context?: Record<string, unknown>;
58
+ /**
59
+ * Creates a new LegalMarkdownError instance
60
+ *
61
+ * @param {string} message - Human-readable error message
62
+ * @param {string} code - Error code for programmatic handling
63
+ * @param {Record<string, unknown>} [context] - Optional contextual data
64
+ * @example
65
+ * ```typescript
66
+ * const error = new LegalMarkdownError(
67
+ * 'Field resolution failed',
68
+ * 'FIELD_RESOLUTION_ERROR',
69
+ * { fieldName: 'client.name', value: undefined }
70
+ * );
71
+ * ```
72
+ */
73
+ constructor(message: string, code: string, context?: Record<string, unknown>);
74
+ }
75
+ /**
76
+ * Error thrown when YAML frontmatter parsing fails
77
+ *
78
+ * @class YamlParsingError
79
+ * @extends {LegalMarkdownError}
80
+ * @example
81
+ * ```typescript
82
+ * import { YamlParsingError } from './errors';
83
+ *
84
+ * // YAML parsing error with context
85
+ * throw new YamlParsingError('Invalid YAML syntax at line 5', {
86
+ * line: 5,
87
+ * column: 12,
88
+ * yamlContent: 'title: "Unterminated string...'
89
+ * });
90
+ * ```
91
+ */
92
+ export declare class YamlParsingError extends LegalMarkdownError {
93
+ /**
94
+ * Creates a new YamlParsingError instance
95
+ *
96
+ * @param {string} message - Human-readable error message describing the YAML parsing issue
97
+ * @param {Record<string, unknown>} [context] - Optional contextual data like line number, column, etc.
98
+ */
99
+ constructor(message: string, context?: Record<string, unknown>);
100
+ }
101
+ /**
102
+ * Error thrown when a required file cannot be found
103
+ *
104
+ * @class FileNotFoundError
105
+ * @extends {LegalMarkdownError}
106
+ * @example
107
+ * ```typescript
108
+ * import { FileNotFoundError } from './errors';
109
+ *
110
+ * // File not found during import
111
+ * throw new FileNotFoundError('./imports/header.md', {
112
+ * operation: 'import',
113
+ * basePath: './documents'
114
+ * });
115
+ * ```
116
+ */
117
+ export declare class FileNotFoundError extends LegalMarkdownError {
118
+ /**
119
+ * Creates a new FileNotFoundError instance
120
+ *
121
+ * @param {string} filePath - The path of the file that could not be found
122
+ * @param {Record<string, unknown>} [context] - Optional contextual data like operation type, base path, etc.
123
+ */
124
+ constructor(filePath: string, context?: Record<string, unknown>);
125
+ }
126
+ /**
127
+ * Error thrown when import processing fails
128
+ *
129
+ * @class ImportProcessingError
130
+ * @extends {LegalMarkdownError}
131
+ * @example
132
+ * ```typescript
133
+ * import { ImportProcessingError } from './errors';
134
+ *
135
+ * // Import processing error
136
+ * throw new ImportProcessingError(
137
+ * 'Circular import detected',
138
+ * './imports/header.md',
139
+ * { importChain: ['main.md', 'header.md', 'header.md'] }
140
+ * );
141
+ * ```
142
+ */
143
+ export declare class ImportProcessingError extends LegalMarkdownError {
144
+ /**
145
+ * Creates a new ImportProcessingError instance
146
+ *
147
+ * @param {string} message - Human-readable error message describing the import processing issue
148
+ * @param {string} [filePath] - Optional file path where the import error occurred
149
+ * @param {Record<string, unknown>} [context] - Optional contextual data like import chain, operation details, etc.
150
+ */
151
+ constructor(message: string, filePath?: string, context?: Record<string, unknown>);
152
+ }
153
+ /**
154
+ * Error thrown when metadata export operations fail
155
+ *
156
+ * @class MetadataExportError
157
+ * @extends {LegalMarkdownError}
158
+ * @example
159
+ * ```typescript
160
+ * import { MetadataExportError } from './errors';
161
+ *
162
+ * // Metadata export error
163
+ * throw new MetadataExportError(
164
+ * 'Failed to write metadata file',
165
+ * './output/metadata.yaml',
166
+ * { format: 'yaml', permissions: 'denied' }
167
+ * );
168
+ * ```
169
+ */
170
+ export declare class MetadataExportError extends LegalMarkdownError {
171
+ /**
172
+ * Creates a new MetadataExportError instance
173
+ *
174
+ * @param {string} message - Human-readable error message describing the metadata export issue
175
+ * @param {string} [exportPath] - Optional path where the export was attempted
176
+ * @param {Record<string, unknown>} [context] - Optional contextual data like export format, permissions, etc.
177
+ */
178
+ constructor(message: string, exportPath?: string, context?: Record<string, unknown>);
179
+ }
180
+ /**
181
+ * Error thrown when document validation fails
182
+ *
183
+ * @class ValidationError
184
+ * @extends {LegalMarkdownError}
185
+ * @example
186
+ * ```typescript
187
+ * import { ValidationError } from './errors';
188
+ *
189
+ * // Validation error for a specific field
190
+ * throw new ValidationError(
191
+ * 'Field value is required',
192
+ * 'client.name',
193
+ * { value: '', required: true, type: 'string' }
194
+ * );
195
+ * ```
196
+ */
197
+ export declare class ValidationError extends LegalMarkdownError {
198
+ /**
199
+ * Creates a new ValidationError instance
200
+ *
201
+ * @param {string} message - Human-readable error message describing the validation issue
202
+ * @param {string} [field] - Optional field name that failed validation
203
+ * @param {Record<string, unknown>} [context] - Optional contextual data like expected value, validation rules, etc.
204
+ */
205
+ constructor(message: string, field?: string, context?: Record<string, unknown>);
206
+ }
207
+ /**
208
+ * Error thrown when general processing operations fail
209
+ *
210
+ * @class ProcessingError
211
+ * @extends {LegalMarkdownError}
212
+ * @example
213
+ * ```typescript
214
+ * import { ProcessingError } from './errors';
215
+ *
216
+ * // Processing error with processor information
217
+ * throw new ProcessingError(
218
+ * 'Field resolution failed',
219
+ * 'field-processor',
220
+ * { fieldCount: 25, failedFields: ['client.name', 'date'] }
221
+ * );
222
+ * ```
223
+ */
224
+ export declare class ProcessingError extends LegalMarkdownError {
225
+ /**
226
+ * Creates a new ProcessingError instance
227
+ *
228
+ * @param {string} message - Human-readable error message describing the processing issue
229
+ * @param {string} [processor] - Optional name of the processor that failed
230
+ * @param {Record<string, unknown>} [context] - Optional contextual data like processing stage, affected items, etc.
231
+ */
232
+ constructor(message: string, processor?: string, context?: Record<string, unknown>);
233
+ }
234
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,iDAAiD;IACjD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,+CAA+C;IAC/C,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElD;;;;;;;;;;;;;;OAcG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAW7E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MA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