glost-processor 0.7.0 → 1.0.2

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.
@@ -0,0 +1,202 @@
1
+ /**
2
+ * GLOSTStreamProcessor Performance Benchmarks
3
+ *
4
+ * Compares batch (eager) processing against streaming for documents
5
+ * of various sizes. Includes 10K and 100K word documents.
6
+ */
7
+ import { bench, describe } from "vitest";
8
+ import { createGLOSTWordNode, createSimpleDocument, createSentenceFromWords, createParagraphFromSentences, createGLOSTRootNode, } from "glost-core";
9
+ import { GLOSTProcessor } from "../processor.js";
10
+ import { GLOSTStreamProcessor } from "../stream-processor.js";
11
+ // ============================================================================
12
+ // Document factories
13
+ // ============================================================================
14
+ /** Create a document with `wordCount` words in a single sentence */
15
+ function makeDocumentByWords(wordCount) {
16
+ const words = Array.from({ length: wordCount }, (_, i) => createGLOSTWordNode({ value: `word${i}` }));
17
+ return createSimpleDocument(words, "en", "latin");
18
+ }
19
+ /**
20
+ * Create a document with `sentenceCount` sentences, each sentence
21
+ * containing `wordsPerSentence` words, spread across `paragraphCount`
22
+ * paragraphs.
23
+ */
24
+ function makeDocumentBySentences(sentenceCount, wordsPerSentence = 10, paragraphCount = 1) {
25
+ const sentencesPerParagraph = Math.ceil(sentenceCount / paragraphCount);
26
+ const paragraphs = [];
27
+ let remaining = sentenceCount;
28
+ for (let p = 0; p < paragraphCount; p++) {
29
+ const count = Math.min(remaining, sentencesPerParagraph);
30
+ const sentences = Array.from({ length: count }, (_, s) => {
31
+ const words = Array.from({ length: wordsPerSentence }, (_, w) => createGLOSTWordNode({ value: `p${p}s${s}w${w}` }));
32
+ return createSentenceFromWords(words, "en", "latin");
33
+ });
34
+ paragraphs.push(createParagraphFromSentences(sentences));
35
+ remaining -= count;
36
+ if (remaining <= 0)
37
+ break;
38
+ }
39
+ return createGLOSTRootNode({
40
+ lang: "en",
41
+ script: "latin",
42
+ children: paragraphs,
43
+ });
44
+ }
45
+ // ============================================================================
46
+ // Extensions
47
+ // ============================================================================
48
+ function createVisitExtension(id) {
49
+ return {
50
+ id,
51
+ name: `Visit Extension ${id}`,
52
+ visit: {
53
+ word: (node) => {
54
+ return {
55
+ ...node,
56
+ extras: { ...node.extras, [id]: true },
57
+ };
58
+ },
59
+ },
60
+ };
61
+ }
62
+ function createChunkVisitExtension(id) {
63
+ return {
64
+ id,
65
+ name: `Chunk Visit Extension ${id}`,
66
+ streamingSupport: "chunk",
67
+ visit: {
68
+ word: (node) => {
69
+ return {
70
+ ...node,
71
+ extras: { ...node.extras, [id]: true },
72
+ };
73
+ },
74
+ },
75
+ };
76
+ }
77
+ // ============================================================================
78
+ // Benchmark: medium documents (for baseline comparison)
79
+ // ============================================================================
80
+ describe("Streaming vs Batch: Medium Documents", () => {
81
+ const doc1k = makeDocumentBySentences(100, 10); // 1K words
82
+ const ext = createVisitExtension("test");
83
+ const chunkExt = createChunkVisitExtension("chunk-test");
84
+ bench("batch — 1K words (GLOSTProcessor)", async () => {
85
+ const proc = new GLOSTProcessor().use(ext);
86
+ await proc.process(doc1k);
87
+ });
88
+ bench("stream — 1K words, batchSize=50", async () => {
89
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
90
+ for await (const _chunk of proc.stream(doc1k, { batchSize: 50 })) {
91
+ // consume
92
+ }
93
+ });
94
+ bench("stream — 1K words, batchSize=10", async () => {
95
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
96
+ for await (const _chunk of proc.stream(doc1k, { batchSize: 10 })) {
97
+ // consume
98
+ }
99
+ });
100
+ bench("stream — 1K words, batchSize=100", async () => {
101
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
102
+ for await (const _chunk of proc.stream(doc1k, { batchSize: 100 })) {
103
+ // consume
104
+ }
105
+ });
106
+ });
107
+ // ============================================================================
108
+ // Benchmark: 10K word documents
109
+ // ============================================================================
110
+ describe("Streaming: 10K Word Documents", () => {
111
+ // 1000 sentences * 10 words = 10K words
112
+ const doc10k = makeDocumentBySentences(1000, 10);
113
+ const ext = createVisitExtension("test");
114
+ const chunkExt = createChunkVisitExtension("chunk-test");
115
+ bench("batch — 10K words (GLOSTProcessor)", async () => {
116
+ const proc = new GLOSTProcessor().use(ext);
117
+ await proc.process(doc10k);
118
+ });
119
+ bench("stream — 10K words, batchSize=50", async () => {
120
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
121
+ for await (const _chunk of proc.stream(doc10k, { batchSize: 50 })) {
122
+ // consume
123
+ }
124
+ });
125
+ bench("stream — 10K words, batchSize=100", async () => {
126
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
127
+ for await (const _chunk of proc.stream(doc10k, {
128
+ batchSize: 100,
129
+ })) {
130
+ // consume
131
+ }
132
+ });
133
+ bench("stream — 10K words, batchSize=500", async () => {
134
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
135
+ for await (const _chunk of proc.stream(doc10k, {
136
+ batchSize: 500,
137
+ })) {
138
+ // consume
139
+ }
140
+ });
141
+ });
142
+ // ============================================================================
143
+ // Benchmark: 100K word documents
144
+ // ============================================================================
145
+ describe("Streaming: 100K Word Documents", () => {
146
+ // 10000 sentences * 10 words = 100K words
147
+ const doc100k = makeDocumentBySentences(10_000, 10, 100);
148
+ const ext = createVisitExtension("test");
149
+ const chunkExt = createChunkVisitExtension("chunk-test");
150
+ bench("batch — 100K words (GLOSTProcessor)", async () => {
151
+ const proc = new GLOSTProcessor().use(ext);
152
+ await proc.process(doc100k);
153
+ });
154
+ bench("stream — 100K words, batchSize=50", async () => {
155
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
156
+ for await (const _chunk of proc.stream(doc100k, {
157
+ batchSize: 50,
158
+ })) {
159
+ // consume
160
+ }
161
+ });
162
+ bench("stream — 100K words, batchSize=500", async () => {
163
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
164
+ for await (const _chunk of proc.stream(doc100k, {
165
+ batchSize: 500,
166
+ })) {
167
+ // consume
168
+ }
169
+ });
170
+ bench("stream — 100K words, batchSize=1000", async () => {
171
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
172
+ for await (const _chunk of proc.stream(doc100k, {
173
+ batchSize: 1000,
174
+ })) {
175
+ // consume
176
+ }
177
+ });
178
+ });
179
+ // ============================================================================
180
+ // Benchmark: early termination via break
181
+ // ============================================================================
182
+ describe("Streaming: Early Termination", () => {
183
+ const doc10k = makeDocumentBySentences(1000, 10);
184
+ const chunkExt = createChunkVisitExtension("chunk-test");
185
+ bench("stream — cancel after first chunk (lazy win)", async () => {
186
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
187
+ for await (const chunk of proc.stream(doc10k, { batchSize: 50 })) {
188
+ break; // Only consume first chunk
189
+ }
190
+ });
191
+ bench("stream — cancel after 10 chunks vs full batch", async () => {
192
+ const proc = new GLOSTStreamProcessor().use(chunkExt);
193
+ let count = 0;
194
+ for await (const _chunk of proc.stream(doc10k, {
195
+ batchSize: 50,
196
+ })) {
197
+ if (++count >= 10)
198
+ break;
199
+ }
200
+ });
201
+ });
202
+ //# sourceMappingURL=stream-processor.bench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-processor.bench.js","sourceRoot":"","sources":["stream-processor.bench.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,oEAAoE;AACpE,SAAS,mBAAmB,CAAC,SAAiB;IAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE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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
+ export { GLOSTStreamProcessor } from "./stream-processor.js";
26
+ export type { FrozenStreamProcessor, StreamOptions, ProcessedChunk, } from "./stream-processor.js";
27
+ import { GLOSTProcessor } from "./processor.js";
28
+ import type { ProcessorOptions } from "./types.js";
29
+ /**
30
+ * Create a new GLOST processor
31
+ *
32
+ * Factory function for creating a new processor instance.
33
+ * Similar to `unified()` from the unified ecosystem.
34
+ *
35
+ * @param options - Initial processor options
36
+ * @returns A new processor instance
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { glost } from "glost-processor";
41
+ *
42
+ * const processor = glost()
43
+ * .use(plugin1)
44
+ * .use(plugin2)
45
+ * .use(plugin3);
46
+ *
47
+ * const result = await processor.process(document);
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // With options
53
+ * const processor = glost({ lenient: true, debug: true })
54
+ * .use(plugin1)
55
+ * .use(plugin2);
56
+ * ```
57
+ */
58
+ export declare function glost(options?: ProcessorOptions): GLOSTProcessor;
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["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;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B,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/src/index.js 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 { GLOSTStreamProcessor } from "./stream-processor.js";
24
+ import { GLOSTProcessor } from "./processor.js";
25
+ /**
26
+ * Create a new GLOST processor
27
+ *
28
+ * Factory function for creating a new processor instance.
29
+ * Similar to `unified()` from the unified ecosystem.
30
+ *
31
+ * @param options - Initial processor options
32
+ * @returns A new processor instance
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { glost } from "glost-processor";
37
+ *
38
+ * const processor = glost()
39
+ * .use(plugin1)
40
+ * .use(plugin2)
41
+ * .use(plugin3);
42
+ *
43
+ * const result = await processor.process(document);
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // With options
49
+ * const processor = glost({ lenient: true, debug: true })
50
+ * .use(plugin1)
51
+ * .use(plugin2);
52
+ * ```
53
+ */
54
+ export function glost(options) {
55
+ return new GLOSTProcessor(options);
56
+ }
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAO7D,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":["processor.ts"],"names":[],"mappings":"AAAA;;;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