glost-processor 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/LICENSE +21 -0
- package/README.md +262 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/processor.d.ts +256 -0
- package/dist/processor.d.ts.map +1 -0
- package/dist/processor.js +482 -0
- package/dist/processor.js.map +1 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
- package/src/index.ts +76 -0
- package/src/processor.ts +574 -0
- package/src/types.ts +203 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processor Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the unified-style GLOST processor.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { GLOSTRoot } from "glost-core";
|
|
10
|
+
import type { GLOSTExtension, ProcessorOptions as ExtensionProcessorOptions } from "glost-extensions";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Plugin function signature
|
|
14
|
+
*
|
|
15
|
+
* A plugin is a function that returns an extension or modifies the processor.
|
|
16
|
+
* Similar to remark/unified plugins.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const myPlugin: Plugin = (options) => {
|
|
21
|
+
* return {
|
|
22
|
+
* id: "my-plugin",
|
|
23
|
+
* name: "My Plugin",
|
|
24
|
+
* transform: (tree) => tree
|
|
25
|
+
* };
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type Plugin<TOptions = any> = (
|
|
30
|
+
options?: TOptions
|
|
31
|
+
) => GLOSTExtension | void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Plugin specification
|
|
35
|
+
*
|
|
36
|
+
* Can be a plugin function, extension object, or string ID.
|
|
37
|
+
*/
|
|
38
|
+
export type PluginSpec = Plugin | GLOSTExtension | string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Preset definition
|
|
42
|
+
*
|
|
43
|
+
* A preset is a collection of plugins with their options.
|
|
44
|
+
* Similar to babel presets.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const preset: Preset = {
|
|
49
|
+
* id: "language-learning",
|
|
50
|
+
* name: "Language Learning",
|
|
51
|
+
* description: "Full language learning stack",
|
|
52
|
+
* plugins: [
|
|
53
|
+
* ["transcription", { scheme: "ipa" }],
|
|
54
|
+
* ["translation", { target: "en" }],
|
|
55
|
+
* ["frequency"],
|
|
56
|
+
* ]
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export interface Preset {
|
|
61
|
+
/** Unique preset identifier */
|
|
62
|
+
id: string;
|
|
63
|
+
|
|
64
|
+
/** Human-readable name */
|
|
65
|
+
name: string;
|
|
66
|
+
|
|
67
|
+
/** Optional description */
|
|
68
|
+
description?: string;
|
|
69
|
+
|
|
70
|
+
/** Plugins to apply with their options */
|
|
71
|
+
plugins: Array<PluginSpec | [PluginSpec, any]>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Processing hook types
|
|
76
|
+
*/
|
|
77
|
+
export type BeforeHook = (document: GLOSTRoot, pluginId: string) => void | Promise<void>;
|
|
78
|
+
export type AfterHook = (document: GLOSTRoot, pluginId: string) => void | Promise<void>;
|
|
79
|
+
export type ErrorHook = (error: Error, pluginId: string) => void;
|
|
80
|
+
export type SkipHook = (pluginId: string, reason: string) => void;
|
|
81
|
+
export type ProgressHook = (stats: ProgressStats) => void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Progress statistics
|
|
85
|
+
*/
|
|
86
|
+
export interface ProgressStats {
|
|
87
|
+
/** Total number of plugins */
|
|
88
|
+
total: number;
|
|
89
|
+
|
|
90
|
+
/** Number of plugins completed */
|
|
91
|
+
completed: number;
|
|
92
|
+
|
|
93
|
+
/** Current plugin being processed */
|
|
94
|
+
current?: string;
|
|
95
|
+
|
|
96
|
+
/** Processing start time */
|
|
97
|
+
startTime: number;
|
|
98
|
+
|
|
99
|
+
/** Elapsed time in ms */
|
|
100
|
+
elapsed: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Processing hooks
|
|
105
|
+
*/
|
|
106
|
+
export interface ProcessorHooks {
|
|
107
|
+
before: Map<string, BeforeHook[]>;
|
|
108
|
+
after: Map<string, AfterHook[]>;
|
|
109
|
+
onError: ErrorHook[];
|
|
110
|
+
onSkip: SkipHook[];
|
|
111
|
+
onProgress: ProgressHook[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Processor options
|
|
116
|
+
*/
|
|
117
|
+
export interface ProcessorOptions extends ExtensionProcessorOptions {
|
|
118
|
+
/** Data storage for sharing state between plugins */
|
|
119
|
+
data?: Map<string, any>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Processing result with detailed metadata
|
|
124
|
+
*/
|
|
125
|
+
export interface ProcessingResult {
|
|
126
|
+
/** The processed document */
|
|
127
|
+
document: GLOSTRoot;
|
|
128
|
+
|
|
129
|
+
/** Processing metadata */
|
|
130
|
+
metadata: {
|
|
131
|
+
/** Plugins that were applied */
|
|
132
|
+
appliedPlugins: string[];
|
|
133
|
+
|
|
134
|
+
/** Plugins that were skipped */
|
|
135
|
+
skippedPlugins: string[];
|
|
136
|
+
|
|
137
|
+
/** Processing errors */
|
|
138
|
+
errors: ProcessingError[];
|
|
139
|
+
|
|
140
|
+
/** Processing warnings */
|
|
141
|
+
warnings: ProcessingWarning[];
|
|
142
|
+
|
|
143
|
+
/** Processing statistics */
|
|
144
|
+
stats: ProcessingStats;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Processing error details
|
|
150
|
+
*/
|
|
151
|
+
export interface ProcessingError {
|
|
152
|
+
/** Plugin that caused the error */
|
|
153
|
+
plugin: string;
|
|
154
|
+
|
|
155
|
+
/** Processing phase */
|
|
156
|
+
phase: "transform" | "visit" | "enhance";
|
|
157
|
+
|
|
158
|
+
/** Error message */
|
|
159
|
+
message: string;
|
|
160
|
+
|
|
161
|
+
/** Error stack trace */
|
|
162
|
+
stack?: string;
|
|
163
|
+
|
|
164
|
+
/** Whether the error is recoverable */
|
|
165
|
+
recoverable: boolean;
|
|
166
|
+
|
|
167
|
+
/** Original error object */
|
|
168
|
+
error: Error;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Processing warning details
|
|
173
|
+
*/
|
|
174
|
+
export interface ProcessingWarning {
|
|
175
|
+
/** Plugin that issued the warning */
|
|
176
|
+
plugin: string;
|
|
177
|
+
|
|
178
|
+
/** Warning message */
|
|
179
|
+
message: string;
|
|
180
|
+
|
|
181
|
+
/** Warning severity */
|
|
182
|
+
severity: "low" | "medium" | "high";
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Processing statistics
|
|
187
|
+
*/
|
|
188
|
+
export interface ProcessingStats {
|
|
189
|
+
/** Total processing time in ms */
|
|
190
|
+
totalTime: number;
|
|
191
|
+
|
|
192
|
+
/** Time per plugin in ms */
|
|
193
|
+
timing: Map<string, number>;
|
|
194
|
+
|
|
195
|
+
/** Total nodes processed */
|
|
196
|
+
nodesProcessed: number;
|
|
197
|
+
|
|
198
|
+
/** Processing start timestamp */
|
|
199
|
+
startTime: number;
|
|
200
|
+
|
|
201
|
+
/** Processing end timestamp */
|
|
202
|
+
endTime: number;
|
|
203
|
+
}
|