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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 GLOST Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# glost-processor
|
|
2
|
+
|
|
3
|
+
Unified-style processor API for GLOST documents with fluent plugin composition.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`glost-processor` provides a fluent API for processing GLOST documents through plugin pipelines, similar to the [unified](https://unifiedjs.com/) ecosystem (remark, rehype, etc.).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install glost-processor
|
|
13
|
+
# or
|
|
14
|
+
pnpm add glost-processor
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Basic Processing
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { glost } from "glost-processor";
|
|
23
|
+
import { transcription } from "glost-transcription";
|
|
24
|
+
import { translation } from "glost-translation";
|
|
25
|
+
import { frequency } from "glost-frequency";
|
|
26
|
+
|
|
27
|
+
const processor = glost()
|
|
28
|
+
.use(transcription, { scheme: "ipa" })
|
|
29
|
+
.use(translation, { target: "en" })
|
|
30
|
+
.use(frequency);
|
|
31
|
+
|
|
32
|
+
const result = await processor.process(document);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Freezing for Reuse
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const frozen = glost()
|
|
39
|
+
.use(transcription)
|
|
40
|
+
.use(translation)
|
|
41
|
+
.freeze();
|
|
42
|
+
|
|
43
|
+
// Reuse across multiple documents
|
|
44
|
+
const result1 = await frozen.process(doc1);
|
|
45
|
+
const result2 = await frozen.process(doc2);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Using Presets
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { languageLearningPreset } from "glost-presets";
|
|
52
|
+
|
|
53
|
+
const processor = glost()
|
|
54
|
+
.use(languageLearningPreset);
|
|
55
|
+
|
|
56
|
+
const result = await processor.process(document);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Hooks and Middleware
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const processor = glost()
|
|
63
|
+
.use(transcription)
|
|
64
|
+
.use(translation)
|
|
65
|
+
.before("translation", (doc) => {
|
|
66
|
+
console.log("About to translate");
|
|
67
|
+
})
|
|
68
|
+
.after("translation", (doc) => {
|
|
69
|
+
console.log("Translation complete");
|
|
70
|
+
})
|
|
71
|
+
.onError((error, plugin) => {
|
|
72
|
+
console.error(`Plugin ${plugin} failed:`, error);
|
|
73
|
+
})
|
|
74
|
+
.onProgress((stats) => {
|
|
75
|
+
console.log(`Progress: ${stats.completed}/${stats.total}`);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const result = await processor.process(document);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Data Storage
|
|
82
|
+
|
|
83
|
+
Share data between plugins:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const processor = glost()
|
|
87
|
+
.data("config", { theme: "dark" })
|
|
88
|
+
.use(plugin1)
|
|
89
|
+
.use(plugin2);
|
|
90
|
+
|
|
91
|
+
// Access in plugins
|
|
92
|
+
const config = processor.data("config");
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Processing with Metadata
|
|
96
|
+
|
|
97
|
+
Get detailed processing information:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const result = await processor.processWithMeta(document);
|
|
101
|
+
|
|
102
|
+
console.log(result.document); // Processed document
|
|
103
|
+
console.log(result.metadata.appliedPlugins); // Which plugins ran
|
|
104
|
+
console.log(result.metadata.stats.totalTime); // Total time
|
|
105
|
+
console.log(result.metadata.errors); // Any errors
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## API
|
|
109
|
+
|
|
110
|
+
### `glost(options?)`
|
|
111
|
+
|
|
112
|
+
Create a new processor instance.
|
|
113
|
+
|
|
114
|
+
**Options:**
|
|
115
|
+
- `lenient?: boolean` - If true, continue processing on errors (default: false)
|
|
116
|
+
- `conflictStrategy?: "error" | "warn" | "lastWins"` - How to handle metadata conflicts
|
|
117
|
+
- `debug?: boolean` - Enable debug logging
|
|
118
|
+
- `data?: Map<string, any>` - Initial data store
|
|
119
|
+
|
|
120
|
+
### `processor.use(plugin, options?)`
|
|
121
|
+
|
|
122
|
+
Add a plugin to the pipeline.
|
|
123
|
+
|
|
124
|
+
**Parameters:**
|
|
125
|
+
- `plugin` - Plugin function, extension object, preset, or plugin ID string
|
|
126
|
+
- `options` - Plugin-specific options
|
|
127
|
+
|
|
128
|
+
**Returns:** The processor for chaining
|
|
129
|
+
|
|
130
|
+
### `processor.freeze()`
|
|
131
|
+
|
|
132
|
+
Freeze the processor configuration for reuse.
|
|
133
|
+
|
|
134
|
+
**Returns:** A frozen processor that can only process documents
|
|
135
|
+
|
|
136
|
+
### `processor.process(document)`
|
|
137
|
+
|
|
138
|
+
Process a document through the pipeline.
|
|
139
|
+
|
|
140
|
+
**Parameters:**
|
|
141
|
+
- `document` - GLOST document to process
|
|
142
|
+
|
|
143
|
+
**Returns:** Promise resolving to the processed document
|
|
144
|
+
|
|
145
|
+
### `processor.processWithMeta(document)`
|
|
146
|
+
|
|
147
|
+
Process a document and get detailed metadata.
|
|
148
|
+
|
|
149
|
+
**Parameters:**
|
|
150
|
+
- `document` - GLOST document to process
|
|
151
|
+
|
|
152
|
+
**Returns:** Promise resolving to processing result with metadata
|
|
153
|
+
|
|
154
|
+
### `processor.before(pluginId, hook)`
|
|
155
|
+
|
|
156
|
+
Register a hook to run before a plugin.
|
|
157
|
+
|
|
158
|
+
**Parameters:**
|
|
159
|
+
- `pluginId` - Plugin ID to hook into
|
|
160
|
+
- `hook` - Function to run before the plugin
|
|
161
|
+
|
|
162
|
+
**Returns:** The processor for chaining
|
|
163
|
+
|
|
164
|
+
### `processor.after(pluginId, hook)`
|
|
165
|
+
|
|
166
|
+
Register a hook to run after a plugin.
|
|
167
|
+
|
|
168
|
+
**Parameters:**
|
|
169
|
+
- `pluginId` - Plugin ID to hook into
|
|
170
|
+
- `hook` - Function to run after the plugin
|
|
171
|
+
|
|
172
|
+
**Returns:** The processor for chaining
|
|
173
|
+
|
|
174
|
+
### `processor.onError(hook)`
|
|
175
|
+
|
|
176
|
+
Register an error handler.
|
|
177
|
+
|
|
178
|
+
**Parameters:**
|
|
179
|
+
- `hook` - Function to handle errors
|
|
180
|
+
|
|
181
|
+
**Returns:** The processor for chaining
|
|
182
|
+
|
|
183
|
+
### `processor.onSkip(hook)`
|
|
184
|
+
|
|
185
|
+
Register a skip handler.
|
|
186
|
+
|
|
187
|
+
**Parameters:**
|
|
188
|
+
- `hook` - Function to handle skipped plugins
|
|
189
|
+
|
|
190
|
+
**Returns:** The processor for chaining
|
|
191
|
+
|
|
192
|
+
### `processor.onProgress(hook)`
|
|
193
|
+
|
|
194
|
+
Register a progress handler.
|
|
195
|
+
|
|
196
|
+
**Parameters:**
|
|
197
|
+
- `hook` - Function to handle progress updates
|
|
198
|
+
|
|
199
|
+
**Returns:** The processor for chaining
|
|
200
|
+
|
|
201
|
+
### `processor.data(key, value?)`
|
|
202
|
+
|
|
203
|
+
Get or set data in the processor data store.
|
|
204
|
+
|
|
205
|
+
**Parameters:**
|
|
206
|
+
- `key` - Data key
|
|
207
|
+
- `value` - Data value (omit to get)
|
|
208
|
+
|
|
209
|
+
**Returns:** Value if getting, processor if setting
|
|
210
|
+
|
|
211
|
+
## Plugin Format
|
|
212
|
+
|
|
213
|
+
Plugins can be:
|
|
214
|
+
|
|
215
|
+
1. **Plugin functions** (returns an extension)
|
|
216
|
+
```typescript
|
|
217
|
+
const myPlugin = (options) => {
|
|
218
|
+
return {
|
|
219
|
+
id: "my-plugin",
|
|
220
|
+
name: "My Plugin",
|
|
221
|
+
transform: (tree) => tree
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
2. **Extension objects** (used directly)
|
|
227
|
+
```typescript
|
|
228
|
+
const myExtension = {
|
|
229
|
+
id: "my-extension",
|
|
230
|
+
name: "My Extension",
|
|
231
|
+
transform: (tree) => tree
|
|
232
|
+
};
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
3. **Plugin ID strings** (looked up in registry)
|
|
236
|
+
```typescript
|
|
237
|
+
processor.use("transcription");
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Comparison with Old API
|
|
241
|
+
|
|
242
|
+
**Old API:**
|
|
243
|
+
```typescript
|
|
244
|
+
import { processGLOSTWithExtensions } from "glost-extensions";
|
|
245
|
+
|
|
246
|
+
const result = processGLOSTWithExtensions(doc, [ext1, ext2, ext3]);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**New API:**
|
|
250
|
+
```typescript
|
|
251
|
+
import { glost } from "glost-processor";
|
|
252
|
+
|
|
253
|
+
const result = await glost()
|
|
254
|
+
.use(ext1)
|
|
255
|
+
.use(ext2)
|
|
256
|
+
.use(ext3)
|
|
257
|
+
.process(doc);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GLOST Processor
|
|
3
|
+
*
|
|
4
|
+
* Unified-style processor for GLOST documents.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { glost } from "glost-processor";
|
|
11
|
+
* import { transcription } from "glost-transcription";
|
|
12
|
+
* import { translation } from "glost-translation";
|
|
13
|
+
*
|
|
14
|
+
* const processor = glost()
|
|
15
|
+
* .use(transcription, { scheme: "ipa" })
|
|
16
|
+
* .use(translation, { target: "en" })
|
|
17
|
+
* .freeze();
|
|
18
|
+
*
|
|
19
|
+
* const result = await processor.process(document);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { GLOSTProcessor } from "./processor.js";
|
|
23
|
+
export type { FrozenProcessor } from "./processor.js";
|
|
24
|
+
export type { Plugin, PluginSpec, Preset, ProcessorOptions, ProcessingResult, ProcessingError, ProcessingWarning, ProcessingStats, BeforeHook, AfterHook, ErrorHook, SkipHook, ProgressHook, ProgressStats, } from "./types.js";
|
|
25
|
+
import { GLOSTProcessor } from "./processor.js";
|
|
26
|
+
import type { ProcessorOptions } from "./types.js";
|
|
27
|
+
/**
|
|
28
|
+
* Create a new GLOST processor
|
|
29
|
+
*
|
|
30
|
+
* Factory function for creating a new processor instance.
|
|
31
|
+
* Similar to `unified()` from the unified ecosystem.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Initial processor options
|
|
34
|
+
* @returns A new processor instance
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { glost } from "glost-processor";
|
|
39
|
+
*
|
|
40
|
+
* const processor = glost()
|
|
41
|
+
* .use(plugin1)
|
|
42
|
+
* .use(plugin2)
|
|
43
|
+
* .use(plugin3);
|
|
44
|
+
*
|
|
45
|
+
* const result = await processor.process(document);
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // With options
|
|
51
|
+
* const processor = glost({ lenient: true, debug: true })
|
|
52
|
+
* .use(plugin1)
|
|
53
|
+
* .use(plugin2);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function glost(options?: ProcessorOptions): GLOSTProcessor;
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EACV,MAAM,EACN,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAEhE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GLOST Processor
|
|
3
|
+
*
|
|
4
|
+
* Unified-style processor for GLOST documents.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { glost } from "glost-processor";
|
|
11
|
+
* import { transcription } from "glost-transcription";
|
|
12
|
+
* import { translation } from "glost-translation";
|
|
13
|
+
*
|
|
14
|
+
* const processor = glost()
|
|
15
|
+
* .use(transcription, { scheme: "ipa" })
|
|
16
|
+
* .use(translation, { target: "en" })
|
|
17
|
+
* .freeze();
|
|
18
|
+
*
|
|
19
|
+
* const result = await processor.process(document);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { GLOSTProcessor } from "./processor.js";
|
|
23
|
+
import { GLOSTProcessor } from "./processor.js";
|
|
24
|
+
/**
|
|
25
|
+
* Create a new GLOST processor
|
|
26
|
+
*
|
|
27
|
+
* Factory function for creating a new processor instance.
|
|
28
|
+
* Similar to `unified()` from the unified ecosystem.
|
|
29
|
+
*
|
|
30
|
+
* @param options - Initial processor options
|
|
31
|
+
* @returns A new processor instance
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { glost } from "glost-processor";
|
|
36
|
+
*
|
|
37
|
+
* const processor = glost()
|
|
38
|
+
* .use(plugin1)
|
|
39
|
+
* .use(plugin2)
|
|
40
|
+
* .use(plugin3);
|
|
41
|
+
*
|
|
42
|
+
* const result = await processor.process(document);
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // With options
|
|
48
|
+
* const processor = glost({ lenient: true, debug: true })
|
|
49
|
+
* .use(plugin1)
|
|
50
|
+
* .use(plugin2);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function glost(options) {
|
|
54
|
+
return new GLOSTProcessor(options);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAmBhD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,KAAK,CAAC,OAA0B;IAC9C,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GLOST Processor
|
|
3
|
+
*
|
|
4
|
+
* Unified-style processor for GLOST documents with fluent API.
|
|
5
|
+
* Similar to unified/remark processors.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { GLOSTRoot } from "glost-core";
|
|
10
|
+
import type { PluginSpec, Preset, ProcessorOptions, ProcessingResult, BeforeHook, AfterHook, ErrorHook, SkipHook, ProgressHook } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* GLOST Processor
|
|
13
|
+
*
|
|
14
|
+
* Fluent API for processing GLOST documents through plugin pipelines.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { GLOSTProcessor } from "glost-processor";
|
|
19
|
+
*
|
|
20
|
+
* const processor = new GLOSTProcessor()
|
|
21
|
+
* .use(transcription, { scheme: "ipa" })
|
|
22
|
+
* .use(translation, { target: "en" })
|
|
23
|
+
* .use(frequency);
|
|
24
|
+
*
|
|
25
|
+
* const result = await processor.process(document);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class GLOSTProcessor {
|
|
29
|
+
private plugins;
|
|
30
|
+
private hooks;
|
|
31
|
+
private dataStore;
|
|
32
|
+
private options;
|
|
33
|
+
private frozen;
|
|
34
|
+
/**
|
|
35
|
+
* Create a new processor instance
|
|
36
|
+
*
|
|
37
|
+
* @param options - Initial processor options
|
|
38
|
+
*/
|
|
39
|
+
constructor(options?: ProcessorOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Use a plugin, preset, or extension
|
|
42
|
+
*
|
|
43
|
+
* @param spec - Plugin function, extension object, preset, or plugin ID
|
|
44
|
+
* @param options - Plugin options
|
|
45
|
+
* @returns This processor for chaining
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* processor
|
|
50
|
+
* .use(transcription, { scheme: "ipa" })
|
|
51
|
+
* .use(translation)
|
|
52
|
+
* .use("frequency");
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
use(spec: PluginSpec | Preset, options?: any): this;
|
|
56
|
+
/**
|
|
57
|
+
* Apply a preset (collection of plugins)
|
|
58
|
+
*
|
|
59
|
+
* @param preset - Preset to apply
|
|
60
|
+
* @returns This processor for chaining
|
|
61
|
+
*/
|
|
62
|
+
private usePreset;
|
|
63
|
+
/**
|
|
64
|
+
* Register a hook to run before a plugin
|
|
65
|
+
*
|
|
66
|
+
* @param pluginId - Plugin ID to hook into
|
|
67
|
+
* @param hook - Hook function to run
|
|
68
|
+
* @returns This processor for chaining
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* processor.before("translation", (doc) => {
|
|
73
|
+
* console.log("About to translate");
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
before(pluginId: string, hook: BeforeHook): this;
|
|
78
|
+
/**
|
|
79
|
+
* Register a hook to run after a plugin
|
|
80
|
+
*
|
|
81
|
+
* @param pluginId - Plugin ID to hook into
|
|
82
|
+
* @param hook - Hook function to run
|
|
83
|
+
* @returns This processor for chaining
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* processor.after("translation", (doc) => {
|
|
88
|
+
* console.log("Translation complete");
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
after(pluginId: string, hook: AfterHook): this;
|
|
93
|
+
/**
|
|
94
|
+
* Register an error handler
|
|
95
|
+
*
|
|
96
|
+
* @param hook - Error handler function
|
|
97
|
+
* @returns This processor for chaining
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* processor.onError((error, plugin) => {
|
|
102
|
+
* console.error(`Plugin ${plugin} failed:`, error);
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
onError(hook: ErrorHook): this;
|
|
107
|
+
/**
|
|
108
|
+
* Register a skip handler
|
|
109
|
+
*
|
|
110
|
+
* @param hook - Skip handler function
|
|
111
|
+
* @returns This processor for chaining
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* processor.onSkip((plugin, reason) => {
|
|
116
|
+
* console.log(`Plugin ${plugin} skipped: ${reason}`);
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
onSkip(hook: SkipHook): this;
|
|
121
|
+
/**
|
|
122
|
+
* Register a progress handler
|
|
123
|
+
*
|
|
124
|
+
* @param hook - Progress handler function
|
|
125
|
+
* @returns This processor for chaining
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* processor.onProgress((stats) => {
|
|
130
|
+
* console.log(`Progress: ${stats.completed}/${stats.total}`);
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
onProgress(hook: ProgressHook): this;
|
|
135
|
+
/**
|
|
136
|
+
* Set or get data in the processor data store
|
|
137
|
+
*
|
|
138
|
+
* @param key - Data key
|
|
139
|
+
* @param value - Data value (omit to get)
|
|
140
|
+
* @returns Value if getting, this processor if setting
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* processor.data("config", { theme: "dark" });
|
|
145
|
+
* const config = processor.data("config");
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
data(key: string): any;
|
|
149
|
+
data(key: string, value: any): this;
|
|
150
|
+
/**
|
|
151
|
+
* Freeze the processor
|
|
152
|
+
*
|
|
153
|
+
* Returns a frozen processor that cannot be modified.
|
|
154
|
+
* Useful for reusing the same configuration across multiple documents.
|
|
155
|
+
*
|
|
156
|
+
* @returns A frozen copy of this processor
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const frozen = processor
|
|
161
|
+
* .use(transcription)
|
|
162
|
+
* .use(translation)
|
|
163
|
+
* .freeze();
|
|
164
|
+
*
|
|
165
|
+
* // Can process multiple documents with the same pipeline
|
|
166
|
+
* const result1 = await frozen.process(doc1);
|
|
167
|
+
* const result2 = await frozen.process(doc2);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
freeze(): FrozenProcessor;
|
|
171
|
+
/**
|
|
172
|
+
* Process a document through the pipeline
|
|
173
|
+
*
|
|
174
|
+
* @param document - GLOST document to process
|
|
175
|
+
* @returns Promise resolving to the processed document
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const result = await processor.process(document);
|
|
180
|
+
* console.log(result);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
process(document: GLOSTRoot): Promise<GLOSTRoot>;
|
|
184
|
+
/**
|
|
185
|
+
* Process a document and return detailed metadata
|
|
186
|
+
*
|
|
187
|
+
* @param document - GLOST document to process
|
|
188
|
+
* @returns Promise resolving to processing result with metadata
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const result = await processor.processWithMeta(document);
|
|
193
|
+
* console.log(result.metadata.appliedPlugins);
|
|
194
|
+
* console.log(result.metadata.stats.totalTime);
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
processWithMeta(document: GLOSTRoot): Promise<ProcessingResult>;
|
|
198
|
+
/**
|
|
199
|
+
* Process a document synchronously (only if all plugins are sync)
|
|
200
|
+
*
|
|
201
|
+
* @param document - GLOST document to process
|
|
202
|
+
* @returns The processed document
|
|
203
|
+
* @throws {Error} If any plugin is async
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const result = processor.processSync(document);
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
processSync(document: GLOSTRoot): GLOSTRoot;
|
|
211
|
+
/**
|
|
212
|
+
* Resolve all plugins to extensions
|
|
213
|
+
*/
|
|
214
|
+
private resolveExtensions;
|
|
215
|
+
/**
|
|
216
|
+
* Resolve a single plugin to an extension
|
|
217
|
+
*/
|
|
218
|
+
private resolvePlugin;
|
|
219
|
+
/**
|
|
220
|
+
* Check if a spec is a preset
|
|
221
|
+
*/
|
|
222
|
+
private isPreset;
|
|
223
|
+
/**
|
|
224
|
+
* Run before hooks for a plugin
|
|
225
|
+
*/
|
|
226
|
+
private runBeforeHooks;
|
|
227
|
+
/**
|
|
228
|
+
* Run after hooks for a plugin
|
|
229
|
+
*/
|
|
230
|
+
private runAfterHooks;
|
|
231
|
+
/**
|
|
232
|
+
* Emit error to error handlers
|
|
233
|
+
*/
|
|
234
|
+
private emitError;
|
|
235
|
+
/**
|
|
236
|
+
* Emit skip to skip handlers
|
|
237
|
+
*/
|
|
238
|
+
private emitSkip;
|
|
239
|
+
/**
|
|
240
|
+
* Emit progress to progress handlers
|
|
241
|
+
*/
|
|
242
|
+
private emitProgress;
|
|
243
|
+
/**
|
|
244
|
+
* Assert that the processor is not frozen
|
|
245
|
+
*/
|
|
246
|
+
private assertNotFrozen;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Frozen processor type
|
|
250
|
+
*
|
|
251
|
+
* A frozen processor cannot be modified, only used for processing.
|
|
252
|
+
*/
|
|
253
|
+
export type FrozenProcessor = Omit<GLOSTProcessor, "use" | "before" | "after" | "onError" | "onSkip" | "onProgress" | "data" | "freeze"> & {
|
|
254
|
+
readonly frozen: true;
|
|
255
|
+
};
|
|
256
|
+
//# sourceMappingURL=processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,KAAK,EACV,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EAEhB,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EAIb,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAkD;IACjE,OAAO,CAAC,KAAK,CAMX;IACF,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,OAAO,GAAE,gBAAqB;IAO1C;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAanD;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAYjB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAShD;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAS9C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAM9B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAM5B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAMpC;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IACtB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAUnC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,IAAI,eAAe;IAezB;;;;;;;;;;;OAWG;IACG,OAAO,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAKtD;;;;;;;;;;;;OAYG;IACG,eAAe,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkHrE;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS;IAM3C;;OAEG;YACW,iBAAiB;IAa/B;;OAEG;YACW,aAAa;IAuB3B;;OAEG;IACH,OAAO,CAAC,QAAQ;IAShB;;OAEG;YACW,cAAc;IAO5B;;OAEG;YACW,aAAa;IAO3B;;OAEG;IACH,OAAO,CAAC,SAAS;IAUjB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAUhB;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,OAAO,CAAC,eAAe;CAKxB;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,cAAc,EACd,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,QAAQ,CACrF,GAAG;IACF,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;CACvB,CAAC"}
|