glost 0.2.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,161 @@
1
1
  # glost
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Fixed critical production issues (ESM imports, BCP-47 language standardization, removed redundant transcription schema fields, renamed translation API sourceLanguage/targetLanguage → from/to) and added major DX improvements (typed extras via declaration merging, comprehensive error classes with suggestions, standard GLOSTDataProvider interface, built-in migration CLI tool npx glost migrate).
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - glost-common@0.2.0
13
+ - glost-utils@0.2.0
14
+
15
+ ## 0.4.0
16
+
17
+ ### Major Changes
18
+
19
+ GLOST v0.4.0 brings critical production fixes and developer experience improvements based on 6+ months of real-world usage feedback from the lalia-prism team processing 50+ language learning stories across Thai and French.
20
+
21
+ #### Breaking Changes
22
+
23
+ **1. ESM Imports Fixed** 🔧
24
+
25
+ - Added `.js` extensions to all barrel exports for proper Node.js ESM support
26
+ - Updated TypeScript config to `moduleResolution: "node16"`
27
+ - **Impact**: Fixes `Cannot find module` errors in Node.js ESM
28
+ - **Migration**: Automatic when upgrading packages
29
+
30
+ **2. BCP-47 Language Code Standard** 🌍
31
+
32
+ - All language codes now standardized on BCP-47 format (e.g., `en-US`, `th-TH`)
33
+ - Added comprehensive language utilities: `normalizeLanguageCode()`, `matchLanguage()`, `parseLanguageCode()`, `findBestMatch()`, `getLanguageFallbacks()`
34
+ - **Impact**: Language codes like `"th"` become `"th-TH"`
35
+ - **Migration**: Use `npx glost-migrate v0.3-to-v0.4 ./src` or `migrateAllLanguageCodes()` utility
36
+
37
+ **3. Transcription Schema Cleanup** ✨
38
+
39
+ - Removed redundant `system` field from `TranscriptionInfo` type
40
+ - System name is already the key in the transcription object
41
+ - **Before**: `{ ipa: { text: "hello", system: "ipa" } }`
42
+ - **After**: `{ ipa: { text: "hello" } }`
43
+ - **Migration**: Use `migrateTranscriptionSchema()` utility
44
+
45
+ **4. Translation API Clarity** 📝
46
+
47
+ - Renamed confusing `sourceLanguage`/`targetLanguage` to clear `from`/`to`
48
+ - **Before**: `createTranslationExtension({ sourceLanguage: "th", targetLanguage: "en", ... })`
49
+ - **After**: `createTranslationExtension({ from: "th", to: "en", ... })`
50
+ - **Migration**: Manual update of extension calls
51
+
52
+ #### New Features
53
+
54
+ **Typed Extras via Declaration Merging** 🎯
55
+
56
+ - Extensions can now augment `GLOSTExtras` interface for full type safety
57
+ - Automatic TypeScript autocomplete for extension fields
58
+ - No runtime overhead, pure type-level enhancement
59
+
60
+ ```typescript
61
+ // In extension package
62
+ declare module "glost" {
63
+ interface GLOSTExtras {
64
+ frequency?: {
65
+ rank: number;
66
+ category: "very-common" | "common" | "uncommon" | "rare";
67
+ };
68
+ }
69
+ }
70
+
71
+ // In user code - full autocomplete!
72
+ word.extras.frequency?.rank; // number | undefined
73
+ ```
74
+
75
+ **Standard Provider Interface** 🔌
76
+
77
+ - New `GLOSTDataProvider<TInput, TOutput>` interface for consistency
78
+ - Built-in support for batch processing, caching, and cleanup
79
+ - Helper utilities: `createSimpleProvider()`, `createCachedProvider()`, `createFallbackProvider()`
80
+
81
+ **Better Error Messages** 💬
82
+
83
+ - New error classes with context, suggestions, and documentation links
84
+ - Helpful error formatting with file paths and node locations
85
+ - Error types: `GLOSTValidationError`, `GLOSTExtensionError`, `GLOSTProviderError`, etc.
86
+
87
+ ```typescript
88
+ GLOSTValidationError: Missing required field 'text' on WordNode
89
+
90
+ Location: document.children[0]
91
+ Node type: WordNode
92
+ File: stories/test.glost.json:42
93
+
94
+ Suggestion: Add a 'text' field containing the word's text content.
95
+ Documentation: https://glost.dev/docs/node-types#wordnode
96
+ ```
97
+
98
+ **Language Code Utilities** 🛠️
99
+
100
+ - `normalizeLanguageCode()` - Convert to BCP-47
101
+ - `matchLanguage()` - Flexible matching with options
102
+ - `parseLanguageCode()` - Parse into components
103
+ - `findBestMatch()` - Find closest match from available codes
104
+ - `getLanguageFallbacks()` - Get fallback chain
105
+ - `isValidBCP47()` - Validation
106
+ - `asBCP47()` - Type-safe casting
107
+
108
+ **Migration CLI** 🚀
109
+
110
+ - Built-in migration CLI: `npx glost migrate`
111
+ - Automated migration from v0.3.x to v0.4.0
112
+ - Commands: `v0.3-to-v0.4`, `analyze`, `help`
113
+ - Dry-run support for safe testing
114
+ - Programmatic migration utilities in `glost-utils`
115
+
116
+ ### Improvements
117
+
118
+ - **Bundle Size**: Foundation laid for future optimizations
119
+ - **Type Safety**: Changed `GLOSTExtras` from type to interface for declaration merging
120
+ - **Documentation**: Comprehensive migration guide and updated language docs
121
+ - **Developer Experience**: Better error messages save significant debugging time
122
+
123
+ ### Fixes
124
+
125
+ - Fixed ESM imports in all language packages
126
+ - Fixed TypeScript moduleResolution for proper ESM output
127
+ - Removed redundant schema fields reducing JSON size
128
+
129
+ ### Migration Guide
130
+
131
+ See [MIGRATION_v0.3_to_v0.4.md](../../MIGRATION_v0.3_to_v0.4.md) for complete upgrade instructions.
132
+
133
+ Quick migration:
134
+
135
+ ```bash
136
+ npx glost migrate v0.3-to-v0.4 ./src
137
+ ```
138
+
139
+ ### Acknowledgments
140
+
141
+ Special thanks to the lalia-prism team for their comprehensive RFC and 6+ months of production feedback that made this release possible. Their real-world experience with Thai and French language learning content identified critical issues and guided these improvements.
142
+
143
+ ### Dependencies
144
+
145
+ - glost-common@0.4.0
146
+ - glost-utils@0.4.0
147
+
148
+ ## 0.3.0
149
+
150
+ ### Minor Changes
151
+
152
+ - Externalized language-specific helpers and data-dependent extensions into dedicated packages. Language helpers (`createThaiWord`, `createJapaneseWord`) moved to `glost-th` and `glost-ja`. Extensions (frequency, difficulty, POS, gender, clause-segmenter, transcription, translation) now require explicit data providers instead of fallback data. See `MIGRATION_EXTENSIONS.md` for migration guide.
153
+
154
+ ### Patch Changes
155
+
156
+ - Updated dependencies
157
+ - glost-common@0.1.3
158
+
3
159
  ## 0.2.0
4
160
 
5
161
  ### Minor Changes
package/README.md CHANGED
@@ -4,7 +4,7 @@ Core types and node creation for GLOST (Glossed Syntax Tree).
4
4
 
5
5
  ## What is GLOST?
6
6
 
7
- GLOST (Glossed Syntax Tree) is a Concrete Syntax Tree format that extends nlcst to support rich language learning annotations:
7
+ GLOST (Glossed Syntax Tree) is a Concrete Syntax Tree format that extends nlcst to support language learning annotations:
8
8
 
9
9
  - **Translations and glosses** in multiple languages
10
10
  - **Difficulty levels** and word frequency data
@@ -154,11 +154,11 @@ See [glost-ja documentation](../languages/ja/README.md).
154
154
 
155
155
  ## Features
156
156
 
157
- - Full TypeScript support
157
+ - TypeScript support
158
158
  - Extends nlcst (Natural Language Concrete Syntax Tree)
159
- - Compatible with unist ecosystem
159
+ - Aims for compatibility with unist ecosystem
160
160
  - Framework-agnostic
161
- - Zod validation schemas included
161
+ - Includes Zod validation schemas
162
162
 
163
163
  ## Related Packages
164
164
 
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * GLOST Migration CLI
4
+ *
5
+ * Command-line interface for migrating GLOST documents
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/cli/migrate.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
@@ -0,0 +1,229 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * GLOST Migration CLI
4
+ *
5
+ * Command-line interface for migrating GLOST documents
6
+ */
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+ // Import migration functions from glost-utils
10
+ async function loadUtils() {
11
+ try {
12
+ // @ts-expect-error - glost-utils is an optional peer dependency
13
+ const utils = await import('glost-utils');
14
+ return {
15
+ migrateAllLanguageCodes: utils.migrateAllLanguageCodes,
16
+ migrateTranscriptionSchema: utils.migrateTranscriptionSchema,
17
+ };
18
+ }
19
+ catch (error) {
20
+ console.error('Error: glost-utils is required for migration.');
21
+ console.error('Install it with: npm install glost-utils');
22
+ process.exit(1);
23
+ }
24
+ }
25
+ async function migrateToV04(doc, options = {}) {
26
+ const { dryRun = false } = options;
27
+ const utils = await loadUtils();
28
+ const languageCodes = utils.migrateAllLanguageCodes(doc, {
29
+ addDefaultRegions: options.addDefaultRegions ?? true,
30
+ dryRun,
31
+ });
32
+ const transcriptionSchema = utils.migrateTranscriptionSchema(doc, {
33
+ dryRun,
34
+ });
35
+ const totalChanges = languageCodes.changes.length + transcriptionSchema.transcriptionsUpdated;
36
+ return {
37
+ languageCodes,
38
+ transcriptionSchema,
39
+ totalChanges,
40
+ success: true,
41
+ };
42
+ }
43
+ const args = process.argv.slice(2);
44
+ function showHelp() {
45
+ console.log(`
46
+ GLOST Migration Tool
47
+
48
+ Usage:
49
+ glost migrate <command> <path>
50
+
51
+ Commands:
52
+ v0.3-to-v0.4 <path> Migrate documents from v0.3.x to v0.4.0
53
+ analyze <path> Analyze what would be migrated (dry run)
54
+ help Show this help message
55
+
56
+ Options:
57
+ --no-regions Don't add default regions to language codes
58
+ --dry-run Show what would change without modifying files
59
+
60
+ Examples:
61
+ glost migrate v0.3-to-v0.4 ./docs
62
+ glost migrate analyze ./docs/story.glost.json
63
+ glost migrate v0.3-to-v0.4 ./docs --dry-run
64
+ `);
65
+ }
66
+ function isGlostFile(filePath) {
67
+ return filePath.endsWith('.glost.json') || filePath.endsWith('.json');
68
+ }
69
+ function findGlostFiles(dir) {
70
+ const files = [];
71
+ try {
72
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
73
+ for (const entry of entries) {
74
+ const fullPath = path.join(dir, entry.name);
75
+ if (entry.isDirectory()) {
76
+ if (entry.name !== 'node_modules' && entry.name !== '.git') {
77
+ files.push(...findGlostFiles(fullPath));
78
+ }
79
+ }
80
+ else if (entry.isFile() && isGlostFile(entry.name)) {
81
+ files.push(fullPath);
82
+ }
83
+ }
84
+ }
85
+ catch (error) {
86
+ console.error(`Error reading directory ${dir}:`, error);
87
+ }
88
+ return files;
89
+ }
90
+ async function migrateFile(filePath, options) {
91
+ try {
92
+ const content = fs.readFileSync(filePath, 'utf-8');
93
+ const doc = JSON.parse(content);
94
+ const result = await migrateToV04(doc, options);
95
+ if (result.totalChanges === 0) {
96
+ console.log(`✓ ${filePath} - No changes needed`);
97
+ return { changed: false, file: filePath };
98
+ }
99
+ console.log(`${options.dryRun ? '○' : '✓'} ${filePath} - ${result.totalChanges} changes`);
100
+ if (result.languageCodes.changes.length > 0) {
101
+ console.log(` Language codes: ${result.languageCodes.nodesUpdated} nodes updated`);
102
+ }
103
+ if (result.transcriptionSchema.transcriptionsUpdated > 0) {
104
+ console.log(` Transcriptions: ${result.transcriptionSchema.transcriptionsUpdated} updated`);
105
+ }
106
+ if (!options.dryRun) {
107
+ fs.writeFileSync(filePath, JSON.stringify(doc, null, 2));
108
+ }
109
+ return { changed: true, file: filePath, changes: result.totalChanges };
110
+ }
111
+ catch (error) {
112
+ console.error(`✗ ${filePath} - Error:`, error.message);
113
+ return { changed: false, file: filePath, error };
114
+ }
115
+ }
116
+ async function main() {
117
+ if (args.length === 0 || args[0] === 'help') {
118
+ showHelp();
119
+ process.exit(0);
120
+ }
121
+ const command = args[0];
122
+ const targetPath = args[1];
123
+ if (!targetPath) {
124
+ console.error('Error: No path provided');
125
+ showHelp();
126
+ process.exit(1);
127
+ }
128
+ const options = {
129
+ dryRun: args.includes('--dry-run'),
130
+ addDefaultRegions: !args.includes('--no-regions'),
131
+ };
132
+ const fullPath = path.resolve(targetPath);
133
+ if (!fs.existsSync(fullPath)) {
134
+ console.error(`Error: Path does not exist: ${fullPath}`);
135
+ process.exit(1);
136
+ }
137
+ const stats = fs.statSync(fullPath);
138
+ let files;
139
+ if (stats.isDirectory()) {
140
+ files = findGlostFiles(fullPath);
141
+ if (files.length === 0) {
142
+ console.log('No GLOST files found in directory');
143
+ process.exit(0);
144
+ }
145
+ console.log(`Found ${files.length} GLOST file(s)\n`);
146
+ }
147
+ else if (stats.isFile()) {
148
+ if (!isGlostFile(fullPath)) {
149
+ console.error('Error: File does not appear to be a GLOST document');
150
+ process.exit(1);
151
+ }
152
+ files = [fullPath];
153
+ }
154
+ else {
155
+ console.error('Error: Path is neither a file nor a directory');
156
+ process.exit(1);
157
+ }
158
+ switch (command) {
159
+ case 'v0.3-to-v0.4':
160
+ case 'v0-to-v04':
161
+ case 'migrate': {
162
+ if (options.dryRun) {
163
+ console.log('DRY RUN - No files will be modified\n');
164
+ }
165
+ let totalChanged = 0;
166
+ let totalChanges = 0;
167
+ for (const file of files) {
168
+ const result = await migrateFile(file, options);
169
+ if (result.changed) {
170
+ totalChanged++;
171
+ totalChanges += result.changes || 0;
172
+ }
173
+ }
174
+ console.log(`\nSummary:`);
175
+ console.log(` Files processed: ${files.length}`);
176
+ console.log(` Files ${options.dryRun ? 'needing changes' : 'changed'}: ${totalChanged}`);
177
+ console.log(` Total changes: ${totalChanges}`);
178
+ if (options.dryRun && totalChanged > 0) {
179
+ console.log(`\nRun without --dry-run to apply changes`);
180
+ }
181
+ break;
182
+ }
183
+ case 'analyze': {
184
+ for (const file of files) {
185
+ try {
186
+ const content = fs.readFileSync(file, 'utf-8');
187
+ const doc = JSON.parse(content);
188
+ const result = await migrateToV04(doc, { dryRun: true });
189
+ console.log(`\nFile: ${file}`);
190
+ console.log(`Total changes needed: ${result.totalChanges}`);
191
+ if (result.languageCodes.changes.length > 0) {
192
+ console.log(`\nLanguage code changes (${result.languageCodes.changes.length}):`);
193
+ result.languageCodes.changes.slice(0, 5).forEach(change => {
194
+ console.log(` ${change.path}: ${change.oldCode} → ${change.newCode}`);
195
+ });
196
+ if (result.languageCodes.changes.length > 5) {
197
+ console.log(` ... and ${result.languageCodes.changes.length - 5} more`);
198
+ }
199
+ }
200
+ if (result.transcriptionSchema.changes.length > 0) {
201
+ console.log(`\nTranscription schema changes (${result.transcriptionSchema.changes.length}):`);
202
+ result.transcriptionSchema.changes.slice(0, 5).forEach(change => {
203
+ console.log(` ${change.path}: systems ${change.systems.join(', ')}`);
204
+ });
205
+ if (result.transcriptionSchema.changes.length > 5) {
206
+ console.log(` ... and ${result.transcriptionSchema.changes.length - 5} more`);
207
+ }
208
+ }
209
+ if (result.totalChanges === 0) {
210
+ console.log('No changes needed');
211
+ }
212
+ }
213
+ catch (error) {
214
+ console.error(`Error analyzing ${file}:`, error.message);
215
+ }
216
+ }
217
+ break;
218
+ }
219
+ default:
220
+ console.error(`Unknown command: ${command}`);
221
+ showHelp();
222
+ process.exit(1);
223
+ }
224
+ }
225
+ main().catch(error => {
226
+ console.error('Fatal error:', error);
227
+ process.exit(1);
228
+ });
229
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/cli/migrate.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAsBxB,8CAA8C;AAC9C,KAAK,UAAU,SAAS;IACtB,IAAI,CAAC;QACH,gEAAgE;QAChE,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,aAAa,CAAQ,CAAC;QACjD,OAAO;YACL,uBAAuB,EAAE,KAAK,CAAC,uBAAuB;YACtD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;SAC7D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAC/D,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AASD,KAAK,UAAU,YAAY,CAAC,GAAQ,EAAE,UAA6D,EAAE;IACnG,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAC;IAEhC,MAAM,aAAa,GAA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MAAM,CAAC,IAAI,aAAa,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;wBACxE,CAAC,CAAC,CAAC;wBACH,IAAI,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BAClD,OAAO,CAAC,GAAG,CAAC,aAAa,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC;wBACjF,CAAC;oBACH,CAAC;oBAED,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;wBAC9B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;oBACnC,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,mBAAmB,IAAI,GAAG,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;gBACtE,CAAC;YACH,CAAC;YACD,MAAM;QACR,CAAC;QAED;YACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * GLOST Error Classes
3
+ *
4
+ * Comprehensive error handling with context, suggestions, and helpful messages
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { GLOSTNode } from './types.js';
9
+ /**
10
+ * Context information for GLOST errors
11
+ */
12
+ export interface GLOSTErrorContext {
13
+ /** The node where the error occurred */
14
+ node?: GLOSTNode;
15
+ /** Path to the node in the document tree */
16
+ path?: string[];
17
+ /** Source file path (if known) */
18
+ file?: string;
19
+ /** Suggestion for fixing the error */
20
+ suggestion?: string;
21
+ /** URL to relevant documentation */
22
+ docsUrl?: string;
23
+ /** Additional context data */
24
+ [key: string]: any;
25
+ }
26
+ /**
27
+ * Base class for all GLOST errors
28
+ */
29
+ export declare class GLOSTError extends Error {
30
+ readonly context: GLOSTErrorContext;
31
+ constructor(message: string, context?: GLOSTErrorContext);
32
+ /**
33
+ * Format error message with context
34
+ */
35
+ toString(): string;
36
+ /**
37
+ * Get a concise error summary
38
+ */
39
+ toSummary(): string;
40
+ }
41
+ /**
42
+ * Validation error for schema violations
43
+ */
44
+ export declare class GLOSTValidationError extends GLOSTError {
45
+ constructor(message: string, context?: GLOSTErrorContext);
46
+ toString(): string;
47
+ }
48
+ /**
49
+ * Error for missing required fields
50
+ */
51
+ export declare class GLOSTMissingFieldError extends GLOSTValidationError {
52
+ constructor(fieldName: string, nodeType: string, context?: GLOSTErrorContext);
53
+ }
54
+ /**
55
+ * Error for invalid field types
56
+ */
57
+ export declare class GLOSTInvalidTypeError extends GLOSTValidationError {
58
+ constructor(fieldName: string, expectedType: string, receivedType: string, context?: GLOSTErrorContext);
59
+ }
60
+ /**
61
+ * Error for invalid language codes
62
+ */
63
+ export declare class GLOSTInvalidLanguageCodeError extends GLOSTValidationError {
64
+ constructor(code: string, context?: GLOSTErrorContext);
65
+ }
66
+ /**
67
+ * Error for extension processing
68
+ */
69
+ export declare class GLOSTExtensionError extends GLOSTError {
70
+ constructor(extensionName: string, message: string, context?: GLOSTErrorContext);
71
+ }
72
+ /**
73
+ * Error for provider issues
74
+ */
75
+ export declare class GLOSTProviderError extends GLOSTError {
76
+ constructor(providerName: string, message: string, context?: GLOSTErrorContext);
77
+ }
78
+ /**
79
+ * Error for document parsing
80
+ */
81
+ export declare class GLOSTParseError extends GLOSTError {
82
+ constructor(message: string, context?: GLOSTErrorContext);
83
+ }
84
+ /**
85
+ * Error for serialization issues
86
+ */
87
+ export declare class GLOSTSerializationError extends GLOSTError {
88
+ constructor(message: string, context?: GLOSTErrorContext);
89
+ }
90
+ /**
91
+ * Create a validation error with helpful context
92
+ *
93
+ * @param message - Error message
94
+ * @param options - Error options
95
+ * @returns GLOSTValidationError instance
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * throw createValidationError('Invalid word node', {
100
+ * node: wordNode,
101
+ * path: ['document', 'children', '0'],
102
+ * suggestion: 'Add a "text" field to the word node',
103
+ * docsUrl: 'https://glost.dev/docs/node-types#word'
104
+ * });
105
+ * ```
106
+ */
107
+ export declare function createValidationError(message: string, options?: {
108
+ node?: GLOSTNode;
109
+ path?: string[];
110
+ file?: string;
111
+ suggestion?: string;
112
+ docsUrl?: string;
113
+ expected?: any;
114
+ received?: any;
115
+ problem?: string;
116
+ }): GLOSTValidationError;
117
+ /**
118
+ * Format a path array as a readable string
119
+ *
120
+ * @param path - Path array
121
+ * @returns Formatted path string
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * formatPath(['document', 'children', '0', 'text'])
126
+ * // Returns: "document.children[0].text"
127
+ * ```
128
+ */
129
+ export declare function formatPath(path: Array<string | number>): string;
130
+ /**
131
+ * Assert that a condition is true, throw validation error if not
132
+ *
133
+ * @param condition - Condition to check
134
+ * @param message - Error message if condition is false
135
+ * @param context - Error context
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * glostAssert(
140
+ * node.type === 'word',
141
+ * 'Node must be a word node',
142
+ * { node, path: ['document', 'children', '0'] }
143
+ * );
144
+ * ```
145
+ */
146
+ export declare function glostAssert(condition: any, message: string, context?: GLOSTErrorContext): asserts condition;
147
+ /**
148
+ * Wrap an error with additional GLOST context
149
+ *
150
+ * @param error - Original error
151
+ * @param context - Additional context
152
+ * @returns GLOST error
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * try {
157
+ * await processNode(node);
158
+ * } catch (error) {
159
+ * throw wrapError(error, {
160
+ * node,
161
+ * path: ['document', 'children', '0'],
162
+ * suggestion: 'Check that the node has all required fields'
163
+ * });
164
+ * }
165
+ * ```
166
+ */
167
+ export declare function wrapError(error: Error, context: GLOSTErrorContext): GLOSTError;
168
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wCAAwC;IACxC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,OAAO,EAAE,iBAAiB,CAAC;gBAE/B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAW5D;;OAEG;IACH,QAAQ,IAAI,MAAM;IAyClB;;OAEG;IACH,SAAS,IAAI,MAAM;CAOpB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAK5D,QAAQ,IAAI,MAAM;CAqDnB;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,oBAAoB;gBAE5D,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iBAAsB;CAUlC;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,oBAAoB;gBAE3D,SAAS,EAAE,MAAM,EACjB,YAAY,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