beddel 0.1.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/README.md +297 -0
- package/dist/agents/agentRegistry.d.ts +68 -0
- package/dist/agents/agentRegistry.d.ts.map +1 -0
- package/dist/agents/agentRegistry.js +222 -0
- package/dist/agents/agentRegistry.js.map +1 -0
- package/dist/agents/formatter-agent.d.ts +10 -0
- package/dist/agents/formatter-agent.d.ts.map +1 -0
- package/dist/agents/formatter-agent.js +49 -0
- package/dist/agents/formatter-agent.js.map +1 -0
- package/dist/agents/genkit-agent.d.ts +12 -0
- package/dist/agents/genkit-agent.d.ts.map +1 -0
- package/dist/agents/genkit-agent.js +119 -0
- package/dist/agents/genkit-agent.js.map +1 -0
- package/dist/agents/i18n-messages.d.ts +17 -0
- package/dist/agents/i18n-messages.d.ts.map +1 -0
- package/dist/agents/i18n-messages.js +92 -0
- package/dist/agents/i18n-messages.js.map +1 -0
- package/dist/agents/index.d.ts +10 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +26 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/pipeline.d.ts +15 -0
- package/dist/agents/pipeline.d.ts.map +1 -0
- package/dist/agents/pipeline.js +45 -0
- package/dist/agents/pipeline.js.map +1 -0
- package/dist/agents/schema-factory.d.ts +40 -0
- package/dist/agents/schema-factory.d.ts.map +1 -0
- package/dist/agents/schema-factory.js +121 -0
- package/dist/agents/schema-factory.js.map +1 -0
- package/dist/agents/translation-validators.d.ts +26 -0
- package/dist/agents/translation-validators.d.ts.map +1 -0
- package/dist/agents/translation-validators.js +77 -0
- package/dist/agents/translation-validators.js.map +1 -0
- package/dist/agents/translator-agents.d.ts +184 -0
- package/dist/agents/translator-agents.d.ts.map +1 -0
- package/dist/agents/translator-agents.js +613 -0
- package/dist/agents/translator-agents.js.map +1 -0
- package/dist/agents/types/translation.types.d.ts +100 -0
- package/dist/agents/types/translation.types.d.ts.map +1 -0
- package/dist/agents/types/translation.types.js +3 -0
- package/dist/agents/types/translation.types.js.map +1 -0
- package/dist/agents/validator-agent.d.ts +42 -0
- package/dist/agents/validator-agent.d.ts.map +1 -0
- package/dist/agents/validator-agent.js +122 -0
- package/dist/agents/validator-agent.js.map +1 -0
- package/dist/audit/auditTrail.d.ts +55 -0
- package/dist/audit/auditTrail.d.ts.map +1 -0
- package/dist/audit/auditTrail.js +93 -0
- package/dist/audit/auditTrail.js.map +1 -0
- package/dist/compliance/gdprEngine.d.ts +44 -0
- package/dist/compliance/gdprEngine.d.ts.map +1 -0
- package/dist/compliance/gdprEngine.js +178 -0
- package/dist/compliance/gdprEngine.js.map +1 -0
- package/dist/compliance/lgpdEngine.d.ts +51 -0
- package/dist/compliance/lgpdEngine.d.ts.map +1 -0
- package/dist/compliance/lgpdEngine.js +221 -0
- package/dist/compliance/lgpdEngine.js.map +1 -0
- package/dist/config.d.ts +78 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +77 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/firebase/tenantManager.d.ts +84 -0
- package/dist/firebase/tenantManager.d.ts.map +1 -0
- package/dist/firebase/tenantManager.js +378 -0
- package/dist/firebase/tenantManager.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/secure-yaml-runtime.d.ts +68 -0
- package/dist/integration/secure-yaml-runtime.d.ts.map +1 -0
- package/dist/integration/secure-yaml-runtime.js +245 -0
- package/dist/integration/secure-yaml-runtime.js.map +1 -0
- package/dist/parser/secure-yaml-parser.d.ts +62 -0
- package/dist/parser/secure-yaml-parser.d.ts.map +1 -0
- package/dist/parser/secure-yaml-parser.js +234 -0
- package/dist/parser/secure-yaml-parser.js.map +1 -0
- package/dist/performance/autoscaling.d.ts +100 -0
- package/dist/performance/autoscaling.d.ts.map +1 -0
- package/dist/performance/autoscaling.js +339 -0
- package/dist/performance/autoscaling.js.map +1 -0
- package/dist/performance/benchmark.d.ts +104 -0
- package/dist/performance/benchmark.d.ts.map +1 -0
- package/dist/performance/benchmark.js +514 -0
- package/dist/performance/benchmark.js.map +1 -0
- package/dist/performance/index.d.ts +14 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +35 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/monitor.d.ts +126 -0
- package/dist/performance/monitor.d.ts.map +1 -0
- package/dist/performance/monitor.js +324 -0
- package/dist/performance/monitor.js.map +1 -0
- package/dist/performance/streaming.d.ts +82 -0
- package/dist/performance/streaming.d.ts.map +1 -0
- package/dist/performance/streaming.js +287 -0
- package/dist/performance/streaming.js.map +1 -0
- package/dist/runtime/audit.d.ts +240 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +641 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts +123 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.js +576 -0
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -0
- package/dist/runtime/isolatedRuntime.d.ts +119 -0
- package/dist/runtime/isolatedRuntime.d.ts.map +1 -0
- package/dist/runtime/isolatedRuntime.js +425 -0
- package/dist/runtime/isolatedRuntime.js.map +1 -0
- package/dist/runtime/schemaCompiler.d.ts +35 -0
- package/dist/runtime/schemaCompiler.d.ts.map +1 -0
- package/dist/runtime/schemaCompiler.js +151 -0
- package/dist/runtime/schemaCompiler.js.map +1 -0
- package/dist/runtime/simpleRuntime.d.ts +57 -0
- package/dist/runtime/simpleRuntime.d.ts.map +1 -0
- package/dist/runtime/simpleRuntime.js +187 -0
- package/dist/runtime/simpleRuntime.js.map +1 -0
- package/dist/security/dashboard.d.ts +89 -0
- package/dist/security/dashboard.d.ts.map +1 -0
- package/dist/security/dashboard.js +300 -0
- package/dist/security/dashboard.js.map +1 -0
- package/dist/security/hardening.d.ts +130 -0
- package/dist/security/hardening.d.ts.map +1 -0
- package/dist/security/hardening.js +414 -0
- package/dist/security/hardening.js.map +1 -0
- package/dist/security/index.d.ts +128 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +353 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/monitor.d.ts +88 -0
- package/dist/security/monitor.d.ts.map +1 -0
- package/dist/security/monitor.js +356 -0
- package/dist/security/monitor.js.map +1 -0
- package/dist/security/scanner.d.ts +104 -0
- package/dist/security/scanner.d.ts.map +1 -0
- package/dist/security/scanner.js +298 -0
- package/dist/security/scanner.js.map +1 -0
- package/dist/security/score.d.ts +150 -0
- package/dist/security/score.d.ts.map +1 -0
- package/dist/security/score.js +983 -0
- package/dist/security/score.js.map +1 -0
- package/dist/security/test-security.d.ts +22 -0
- package/dist/security/test-security.d.ts.map +1 -0
- package/dist/security/test-security.js +154 -0
- package/dist/security/test-security.js.map +1 -0
- package/dist/security/threatDetector.d.ts +39 -0
- package/dist/security/threatDetector.d.ts.map +1 -0
- package/dist/security/threatDetector.js +354 -0
- package/dist/security/threatDetector.js.map +1 -0
- package/dist/security/validation.d.ts +69 -0
- package/dist/security/validation.d.ts.map +1 -0
- package/dist/security/validation.js +286 -0
- package/dist/security/validation.js.map +1 -0
- package/dist/server/api/clientsRoute.d.ts +9 -0
- package/dist/server/api/clientsRoute.d.ts.map +1 -0
- package/dist/server/api/clientsRoute.js +71 -0
- package/dist/server/api/clientsRoute.js.map +1 -0
- package/dist/server/api/endpointsRoute.d.ts +8 -0
- package/dist/server/api/endpointsRoute.d.ts.map +1 -0
- package/dist/server/api/endpointsRoute.js +76 -0
- package/dist/server/api/endpointsRoute.js.map +1 -0
- package/dist/server/api/graphql.d.ts +9 -0
- package/dist/server/api/graphql.d.ts.map +1 -0
- package/dist/server/api/graphql.js +180 -0
- package/dist/server/api/graphql.js.map +1 -0
- package/dist/server/errors.d.ts +19 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +42 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +24 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/kvStore.d.ts +27 -0
- package/dist/server/kvStore.d.ts.map +1 -0
- package/dist/server/kvStore.js +128 -0
- package/dist/server/kvStore.js.map +1 -0
- package/dist/server/runtimeSecurity.d.ts +28 -0
- package/dist/server/runtimeSecurity.d.ts.map +1 -0
- package/dist/server/runtimeSecurity.js +85 -0
- package/dist/server/runtimeSecurity.js.map +1 -0
- package/dist/server/types.d.ts +53 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +8 -0
- package/dist/server/types.js.map +1 -0
- package/dist/types/executionContext.d.ts +16 -0
- package/dist/types/executionContext.d.ts.map +1 -0
- package/dist/types/executionContext.js +3 -0
- package/dist/types/executionContext.js.map +1 -0
- package/package.json +77 -0
- package/src/agents/agentRegistry.ts +272 -0
- package/src/agents/image-agent.yaml +86 -0
- package/src/agents/joker-agent.yaml +47 -0
- package/src/agents/translator-agent.yaml +80 -0
- package/src/audit/auditTrail.ts +134 -0
- package/src/compliance/gdprEngine.ts +209 -0
- package/src/compliance/lgpdEngine.ts +268 -0
- package/src/config.ts +179 -0
- package/src/errors.ts +35 -0
- package/src/firebase/tenantManager.ts +443 -0
- package/src/index.ts +125 -0
- package/src/integration/secure-yaml-runtime.ts +341 -0
- package/src/parser/secure-yaml-parser.ts +273 -0
- package/src/performance/autoscaling.ts +495 -0
- package/src/performance/benchmark.ts +644 -0
- package/src/performance/index.ts +34 -0
- package/src/performance/monitor.ts +469 -0
- package/src/performance/streaming.ts +317 -0
- package/src/runtime/audit.ts +907 -0
- package/src/runtime/declarativeAgentRuntime.ts +836 -0
- package/src/runtime/isolatedRuntime.ts +572 -0
- package/src/runtime/schemaCompiler.ts +228 -0
- package/src/runtime/simpleRuntime.ts +201 -0
- package/src/security/dashboard.ts +462 -0
- package/src/security/hardening.ts +560 -0
- package/src/security/index.ts +439 -0
- package/src/security/monitor.ts +490 -0
- package/src/security/scanner.ts +368 -0
- package/src/security/score.ts +1138 -0
- package/src/security/threatDetector.ts +481 -0
- package/src/security/validation.ts +365 -0
- package/src/server/api/clientsRoute.ts +92 -0
- package/src/server/api/endpointsRoute.ts +97 -0
- package/src/server/api/graphql.ts +249 -0
- package/src/server/errors.ts +38 -0
- package/src/server/index.ts +6 -0
- package/src/server/kvStore.ts +152 -0
- package/src/server/runtimeSecurity.ts +102 -0
- package/src/server/types.ts +60 -0
- package/src/types/executionContext.ts +16 -0
- package/tools/seed.ts +365 -0
- package/tools/test-endpoints.ts +174 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { createReadStream } from 'fs';
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { load, FAILSAFE_SCHEMA } from 'js-yaml';
|
|
4
|
+
import { YAMLParseError, YAMLSecurityError } from '../errors';
|
|
5
|
+
import { SecureYamlParser } from '../parser/secure-yaml-parser';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Interface para opções de streaming
|
|
9
|
+
*/
|
|
10
|
+
export interface StreamingOptions {
|
|
11
|
+
chunkSize?: number;
|
|
12
|
+
maxChunkSize?: number;
|
|
13
|
+
validateChunkSize?: boolean;
|
|
14
|
+
enableStreaming?: boolean;
|
|
15
|
+
lazyParsing?: boolean;
|
|
16
|
+
parallelProcessing?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Parser YAML com suporte a streaming para arquivos grandes
|
|
21
|
+
*/
|
|
22
|
+
export class StreamingYamlParser extends SecureYamlParser {
|
|
23
|
+
private readonly streamingOptions: Required<StreamingOptions>;
|
|
24
|
+
|
|
25
|
+
constructor(options: { config?: any; streaming?: StreamingOptions } = {}) {
|
|
26
|
+
super(options.config);
|
|
27
|
+
|
|
28
|
+
this.streamingOptions = {
|
|
29
|
+
chunkSize: options.streaming?.chunkSize ?? 64 * 1024, // 64KB default
|
|
30
|
+
maxChunkSize: options.streaming?.maxChunkSize ?? 1024 * 1024, // 1MB max
|
|
31
|
+
validateChunkSize: options.streaming?.validateChunkSize ?? true,
|
|
32
|
+
enableStreaming: options.streaming?.enableStreaming ?? true,
|
|
33
|
+
lazyParsing: options.streaming?.lazyParsing ?? true,
|
|
34
|
+
parallelProcessing: options.streaming?.parallelProcessing ?? false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parse arquivo YAML via streaming
|
|
40
|
+
*/
|
|
41
|
+
async parseFileStreaming(filePath: string): Promise<any> {
|
|
42
|
+
if (!this.streamingOptions.enableStreaming) {
|
|
43
|
+
throw new Error('Streaming desabilitado nas opções');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const stream = createReadStream(filePath, {
|
|
47
|
+
encoding: 'utf8',
|
|
48
|
+
highWaterMark: this.streamingOptions.chunkSize
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return this.parseStream(stream);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Parse YAML a partir de stream
|
|
56
|
+
*/
|
|
57
|
+
async parseStream(stream: Readable): Promise<any> {
|
|
58
|
+
let buffer = '';
|
|
59
|
+
let chunks = 0;
|
|
60
|
+
let totalSize = 0;
|
|
61
|
+
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const startTime = performance.now();
|
|
64
|
+
|
|
65
|
+
stream.on('data', (chunk: Buffer | string) => {
|
|
66
|
+
buffer += chunk.toString();
|
|
67
|
+
chunks++;
|
|
68
|
+
totalSize += chunk.length;
|
|
69
|
+
|
|
70
|
+
// Validação de tamanho do chunk
|
|
71
|
+
if (this.streamingOptions.validateChunkSize) {
|
|
72
|
+
if (chunk.length > this.streamingOptions.maxChunkSize) {
|
|
73
|
+
reject(new YAMLSecurityError(
|
|
74
|
+
`Chunk ${chunks} excedeu tamanho máximo: ${chunk.length} > ${this.streamingOptions.maxChunkSize}`
|
|
75
|
+
));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
stream.on('end', () => {
|
|
81
|
+
try {
|
|
82
|
+
const metrics = {
|
|
83
|
+
chunks,
|
|
84
|
+
totalSize,
|
|
85
|
+
chunkSize: this.streamingOptions.chunkSize,
|
|
86
|
+
parseTime: performance.now() - startTime
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
console.log(`[StreamingYamlParser] Processamento via streaming concluído:`, metrics);
|
|
90
|
+
|
|
91
|
+
const result = super.parseSecure(buffer);
|
|
92
|
+
resolve(result);
|
|
93
|
+
|
|
94
|
+
} catch (error) {
|
|
95
|
+
reject(error);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
stream.on('error', (error: Error) => {
|
|
100
|
+
reject(new YAMLParseError(`Erro durante streaming: ${error.message}`));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Parse YAML com lazy loading e streaming
|
|
107
|
+
*/
|
|
108
|
+
async parseStreamingLazy(yamlContent: string): Promise<any> {
|
|
109
|
+
if (this.streamingOptions.lazyParsing) {
|
|
110
|
+
// Lazy parsing - criar Promise que só processa quando necessário
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
try {
|
|
114
|
+
const result = this.parseSecureChunked(yamlContent);
|
|
115
|
+
resolve(result);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
reject(error);
|
|
118
|
+
}
|
|
119
|
+
}, 0);
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
return this.parseSecureChunked(yamlContent);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Parse YAML em chunks para não bloquear o event loop
|
|
128
|
+
*/
|
|
129
|
+
private async parseSecureChunked(yamlContent: string, chunkSize?: number): Promise<any> {
|
|
130
|
+
const effectiveChunkSize = chunkSize ?? this.streamingOptions.chunkSize;
|
|
131
|
+
const chunks = [];
|
|
132
|
+
let position = 0;
|
|
133
|
+
|
|
134
|
+
while (position < yamlContent.length) {
|
|
135
|
+
const endPosition = Math.min(position + effectiveChunkSize, yamlContent.length);
|
|
136
|
+
chunks.push(yamlContent.slice(position, endPosition));
|
|
137
|
+
position = endPosition;
|
|
138
|
+
|
|
139
|
+
// Permitir que o event loop processe outros eventos
|
|
140
|
+
if (position < yamlContent.length) {
|
|
141
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Juntar todos os chunks e processar como um único documento
|
|
146
|
+
const completeContent = chunks.join('');
|
|
147
|
+
return super.parseSecure(completeContent);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Parser otimizado para streams de entrada com configurações pré-definidas
|
|
152
|
+
*/
|
|
153
|
+
async parseStreamOptimized(content: string | Readable): Promise<any> {
|
|
154
|
+
if (typeof content === 'string') {
|
|
155
|
+
return this.parseStreamingLarge(content);
|
|
156
|
+
} else {
|
|
157
|
+
return this.parseStream(content);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Otimização para arquivos grandes (> 1MB)
|
|
163
|
+
*/
|
|
164
|
+
private async parseStreamingLarge(content: string): Promise<any> {
|
|
165
|
+
const startTime = performance.now();
|
|
166
|
+
|
|
167
|
+
if (content.length < 1024 * 1024) {
|
|
168
|
+
// Para arquivos pequenos, usar parsing direto
|
|
169
|
+
return super.parseSecure(content);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Para arquivos grandes, usar parsing segmentado
|
|
173
|
+
let segments = this.segmentLargeContent(content);
|
|
174
|
+
const results = [];
|
|
175
|
+
|
|
176
|
+
if (this.streamingOptions.parallelProcessing) {
|
|
177
|
+
// Processamento paralelo de segmentos (experimental)
|
|
178
|
+
results.push(...await Promise.all(
|
|
179
|
+
segments.map(segment => this.parseSegmentAsync(segment))
|
|
180
|
+
));
|
|
181
|
+
} else {
|
|
182
|
+
// Processamento sequencial (mais seguro para YAML)
|
|
183
|
+
for (const segment of segments) {
|
|
184
|
+
results.push(await this.parseSegmentAsync(segment));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const endTime = performance.now();
|
|
189
|
+
console.log(`[StreamingYamlParser] Arquivo grande processado: ${content.length} bytes em ${endTime - startTime}ms`);
|
|
190
|
+
|
|
191
|
+
return this.mergeResults(results);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Segmenta conteúdo grande em partes manejáveis
|
|
196
|
+
*/
|
|
197
|
+
private segmentLargeContent(content: string): string[] {
|
|
198
|
+
const segmentSize = Math.floor(content.length / 4); // Dividir em 4 partes
|
|
199
|
+
const segments = [];
|
|
200
|
+
|
|
201
|
+
for (let i = 0; i < content.length; i += segmentSize) {
|
|
202
|
+
segments.push(content.slice(i, Math.min(i + segmentSize, content.length)));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return segments;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Processa segmento de forma assíncrona
|
|
210
|
+
*/
|
|
211
|
+
private async parseSegmentAsync(segment: string): Promise<any> {
|
|
212
|
+
return new Promise((resolve, reject) => {
|
|
213
|
+
setTimeout(() => {
|
|
214
|
+
try {
|
|
215
|
+
const result = load(segment, { schema: FAILSAFE_SCHEMA });
|
|
216
|
+
resolve(result);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
reject(new YAMLParseError(`Erro ao processar segmento: ${error}`));
|
|
219
|
+
}
|
|
220
|
+
}, 0);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Merge resultados de múltiplos segmentos (simplificado)
|
|
226
|
+
*/
|
|
227
|
+
private mergeResults(results: any[]): any {
|
|
228
|
+
if (results.length === 1) return results[0];
|
|
229
|
+
|
|
230
|
+
// Para YAML simples, retornar o primeiro resultado completo
|
|
231
|
+
// Isso é uma simplificação - YAML completo requer lógica mais complexa
|
|
232
|
+
return results.find(result => result !== null && result !== undefined) ?? null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Wrapper com monitoramento de performance para parsing de arquivos grandes
|
|
237
|
+
*/
|
|
238
|
+
async parseFileWithMonitoring(filePath: string): Promise<{ result: any; metrics: any }> {
|
|
239
|
+
const startTime = performance.now();
|
|
240
|
+
const startMemory = process.memoryUsage();
|
|
241
|
+
|
|
242
|
+
try {
|
|
243
|
+
const result = await this.parseFileStreaming(filePath);
|
|
244
|
+
|
|
245
|
+
const endTime = performance.now();
|
|
246
|
+
const endMemory = process.memoryUsage();
|
|
247
|
+
|
|
248
|
+
const metrics = {
|
|
249
|
+
parseTime: endTime - startTime,
|
|
250
|
+
memoryUsage: endMemory.heapUsed - startMemory.heapUsed,
|
|
251
|
+
fileSize: (await import('fs')).statSync(filePath).size,
|
|
252
|
+
chunksProcessed: Math.ceil((await import('fs')).statSync(filePath).size / this.streamingOptions.chunkSize),
|
|
253
|
+
streaming: true,
|
|
254
|
+
timestamp: Date.now()
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
return { result, metrics };
|
|
258
|
+
|
|
259
|
+
} catch (error) {
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Wrapper para parsing com streaming
|
|
267
|
+
*/
|
|
268
|
+
export async function parseYamlStreaming(
|
|
269
|
+
content: string | Readable,
|
|
270
|
+
config?: { streaming?: StreamingOptions; parser?: any }
|
|
271
|
+
): Promise<any> {
|
|
272
|
+
const parser = new StreamingYamlParser(config);
|
|
273
|
+
|
|
274
|
+
if (typeof content === 'string') {
|
|
275
|
+
return parser.parseStreamingLazy(content);
|
|
276
|
+
} else {
|
|
277
|
+
return parser.parseStream(content);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Benchmark compartivo entre parsing normal e streaming
|
|
283
|
+
*/
|
|
284
|
+
export async function benchmarkStreamingComparison(
|
|
285
|
+
content: string,
|
|
286
|
+
iterations: number = 100
|
|
287
|
+
): Promise<{ normal: any; streaming: any }> {
|
|
288
|
+
const { PerformanceMonitor } = await import('./monitor');
|
|
289
|
+
const monitor = new PerformanceMonitor();
|
|
290
|
+
|
|
291
|
+
// Normal parser benchmark
|
|
292
|
+
const normalResult = await monitor.benchmark(
|
|
293
|
+
() => parseSecureYaml(content),
|
|
294
|
+
'Normal Parser',
|
|
295
|
+
iterations,
|
|
296
|
+
content.length
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// Streaming parser benchmark
|
|
300
|
+
const streamingResult = await monitor.benchmark(
|
|
301
|
+
() => {
|
|
302
|
+
const parser = new StreamingYamlParser({ streaming: { enableStreaming: true } });
|
|
303
|
+
return parser.parseStreamingLazy(content);
|
|
304
|
+
},
|
|
305
|
+
'Streaming Parser',
|
|
306
|
+
iterations,
|
|
307
|
+
content.length
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
return { normal: normalResult, streaming: streamingResult };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Import dinâmico para evitar circular dependencies
|
|
314
|
+
export async function parseSecureYaml(content: string): Promise<any> {
|
|
315
|
+
const { parseSecureYaml } = await import('../parser/secure-yaml-parser');
|
|
316
|
+
return parseSecureYaml(content);
|
|
317
|
+
}
|