glost-core 0.5.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 +63 -0
- package/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/__benchmarks__/document-creation.bench.d.ts +7 -0
- package/dist/__benchmarks__/document-creation.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/document-creation.bench.js +71 -0
- package/dist/__benchmarks__/document-creation.bench.js.map +1 -0
- package/dist/__benchmarks__/traversal.bench.d.ts +7 -0
- package/dist/__benchmarks__/traversal.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/traversal.bench.js +124 -0
- package/dist/__benchmarks__/traversal.bench.js.map +1 -0
- package/dist/cli/migrate.d.ts +8 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +229 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/errors.d.ts +168 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +300 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards.d.ts +103 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +264 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes.d.ts +227 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +243 -0
- package/dist/nodes.js.map +1 -0
- package/dist/types.d.ts +442 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +247 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +564 -0
- package/dist/utils.js.map +1 -0
- package/dist/validators.d.ts +1876 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +302 -0
- package/dist/validators.js.map +1 -0
- package/package.json +73 -0
- package/src/__benchmarks__/document-creation.bench.ts +92 -0
- package/src/__benchmarks__/traversal.bench.ts +152 -0
- package/src/__tests__/README.md +20 -0
- package/src/__tests__/example.test.ts +43 -0
- package/src/__tests__/example.ts +186 -0
- package/src/__tests__/helpers.test.ts +178 -0
- package/src/__tests__/mock-data.ts +624 -0
- package/src/__tests__/performance.test.ts +317 -0
- package/src/__tests__/traversal.test.ts +170 -0
- package/src/cli/migrate.ts +294 -0
- package/src/errors.ts +394 -0
- package/src/guards.ts +341 -0
- package/src/index.ts +69 -0
- package/src/nodes.ts +409 -0
- package/src/types.ts +633 -0
- package/src/utils.ts +730 -0
- package/src/validators.ts +336 -0
- package/tsconfig.json +9 -0
|
@@ -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,GAAG,KAAK,CAAC,uBAAu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Aa,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"}
|
package/dist/errors.d.ts
ADDED
|
@@ -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,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