web-csv-toolbox 0.13.0-next-bd865d6ddb1cf9691d7b9a83d0790651f074dd47 → 0.13.0-next-b21b6d89a7a3f18dcbf79ec04ffefde0d7ff4c4c
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 +132 -6
- package/dist/CSVLexer.js.map +1 -1
- package/dist/CSVLexerTransformer.d.ts +52 -3
- package/dist/CSVLexerTransformer.js +58 -13
- package/dist/CSVLexerTransformer.js.map +1 -1
- package/dist/CSVRecordAssembler.js.map +1 -1
- package/dist/CSVRecordAssemblerTransformer.d.ts +49 -3
- package/dist/CSVRecordAssemblerTransformer.js +55 -18
- package/dist/CSVRecordAssemblerTransformer.js.map +1 -1
- package/dist/_virtual/web_csv_toolbox_wasm_bg.wasm.js +1 -1
- package/dist/assertCommonOptions.js.map +1 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/errors.js.map +1 -1
- package/dist/common/types.d.ts +336 -14
- package/dist/commonParseErrorHandling.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/createWorker.node.d.ts +2 -0
- package/dist/createWorker.web.d.ts +2 -0
- package/dist/execution/EnginePresets.d.ts +143 -0
- package/dist/execution/EnginePresets.js +129 -0
- package/dist/execution/EnginePresets.js.map +1 -0
- package/dist/execution/InternalEngineConfig.d.ts +89 -0
- package/dist/execution/InternalEngineConfig.js +175 -0
- package/dist/execution/InternalEngineConfig.js.map +1 -0
- package/dist/execution/main/parseBinaryInMain.d.ts +12 -0
- package/dist/execution/main/parseStreamInMain.d.ts +12 -0
- package/dist/execution/main/parseStringInMain.d.ts +12 -0
- package/dist/execution/main/parseUint8ArrayStreamInMain.d.ts +12 -0
- package/dist/execution/wasm/parseBinaryInWASM.d.ts +18 -0
- package/dist/execution/wasm/parseBinaryInWASM.js +15 -0
- package/dist/execution/wasm/parseBinaryInWASM.js.map +1 -0
- package/dist/execution/wasm/parseStringInWASM.d.ts +16 -0
- package/dist/execution/worker/helpers/ReusableWorkerPool.d.ts +152 -0
- package/dist/execution/worker/helpers/ReusableWorkerPool.js +238 -0
- package/dist/execution/worker/helpers/ReusableWorkerPool.js.map +1 -0
- package/dist/execution/worker/helpers/TransientWorkerPool.d.ts +89 -0
- package/dist/execution/worker/helpers/WorkerManager.d.ts +27 -0
- package/dist/execution/worker/helpers/WorkerPool.d.ts +50 -0
- package/dist/execution/worker/helpers/WorkerSession.d.ts +78 -0
- package/dist/execution/worker/helpers/WorkerSession.js +58 -0
- package/dist/execution/worker/helpers/WorkerSession.js.map +1 -0
- package/dist/execution/worker/helpers/createWorker.node.d.ts +8 -0
- package/dist/execution/worker/helpers/createWorker.node.js +15 -0
- package/dist/execution/worker/helpers/createWorker.node.js.map +1 -0
- package/dist/execution/worker/helpers/createWorker.web.d.ts +8 -0
- package/dist/execution/worker/helpers/createWorker.web.js +11 -0
- package/dist/execution/worker/helpers/createWorker.web.js.map +1 -0
- package/dist/execution/worker/helpers/worker.node.d.ts +1 -0
- package/dist/execution/worker/helpers/worker.node.js +11 -0
- package/dist/execution/worker/helpers/worker.node.js.map +1 -0
- package/dist/execution/worker/helpers/worker.shared.d.ts +90 -0
- package/dist/execution/worker/helpers/worker.shared.js +241 -0
- package/dist/execution/worker/helpers/worker.shared.js.map +1 -0
- package/dist/execution/worker/helpers/worker.web.d.ts +1 -0
- package/dist/execution/worker/helpers/worker.web.js +16 -0
- package/dist/execution/worker/helpers/worker.web.js.map +1 -0
- package/dist/execution/worker/parseBinaryInWorker.node.d.ts +8 -0
- package/dist/execution/worker/parseBinaryInWorker.node.js +24 -0
- package/dist/execution/worker/parseBinaryInWorker.node.js.map +1 -0
- package/dist/execution/worker/parseBinaryInWorker.web.d.ts +8 -0
- package/dist/execution/worker/parseBinaryInWorker.web.js +24 -0
- package/dist/execution/worker/parseBinaryInWorker.web.js.map +1 -0
- package/dist/execution/worker/parseBinaryInWorkerWASM.node.d.ts +8 -0
- package/dist/execution/worker/parseBinaryInWorkerWASM.node.js +24 -0
- package/dist/execution/worker/parseBinaryInWorkerWASM.node.js.map +1 -0
- package/dist/execution/worker/parseBinaryInWorkerWASM.web.d.ts +8 -0
- package/dist/execution/worker/parseBinaryInWorkerWASM.web.js +24 -0
- package/dist/execution/worker/parseBinaryInWorkerWASM.web.js.map +1 -0
- package/dist/execution/worker/parseStreamInWorker.node.d.ts +15 -0
- package/dist/execution/worker/parseStreamInWorker.node.js +26 -0
- package/dist/execution/worker/parseStreamInWorker.node.js.map +1 -0
- package/dist/execution/worker/parseStreamInWorker.web.d.ts +12 -0
- package/dist/execution/worker/parseStreamInWorker.web.js +25 -0
- package/dist/execution/worker/parseStreamInWorker.web.js.map +1 -0
- package/dist/execution/worker/parseStringInWorker.node.d.ts +11 -0
- package/dist/execution/worker/parseStringInWorker.node.js +24 -0
- package/dist/execution/worker/parseStringInWorker.node.js.map +1 -0
- package/dist/execution/worker/parseStringInWorker.web.d.ts +11 -0
- package/dist/execution/worker/parseStringInWorker.web.js +24 -0
- package/dist/execution/worker/parseStringInWorker.web.js.map +1 -0
- package/dist/execution/worker/parseStringInWorkerWASM.node.d.ts +8 -0
- package/dist/execution/worker/parseStringInWorkerWASM.node.js +24 -0
- package/dist/execution/worker/parseStringInWorkerWASM.node.js.map +1 -0
- package/dist/execution/worker/parseStringInWorkerWASM.web.d.ts +8 -0
- package/dist/execution/worker/parseStringInWorkerWASM.web.js +24 -0
- package/dist/execution/worker/parseStringInWorkerWASM.web.js.map +1 -0
- package/dist/execution/worker/parseUint8ArrayStreamInWorker.node.d.ts +12 -0
- package/dist/execution/worker/parseUint8ArrayStreamInWorker.node.js +26 -0
- package/dist/execution/worker/parseUint8ArrayStreamInWorker.node.js.map +1 -0
- package/dist/execution/worker/parseUint8ArrayStreamInWorker.web.d.ts +9 -0
- package/dist/execution/worker/parseUint8ArrayStreamInWorker.web.js +25 -0
- package/dist/execution/worker/parseUint8ArrayStreamInWorker.web.js.map +1 -0
- package/dist/execution/worker/strategies/MessageStreamingStrategy.d.ts +17 -0
- package/dist/execution/worker/strategies/MessageStreamingStrategy.js +58 -0
- package/dist/execution/worker/strategies/MessageStreamingStrategy.js.map +1 -0
- package/dist/execution/worker/strategies/TransferableStreamStrategy.d.ts +25 -0
- package/dist/execution/worker/strategies/TransferableStreamStrategy.js +159 -0
- package/dist/execution/worker/strategies/TransferableStreamStrategy.js.map +1 -0
- package/dist/execution/worker/strategies/WorkerStrategy.d.ts +27 -0
- package/dist/execution/worker/strategies/WorkerStrategySelector.d.ts +43 -0
- package/dist/execution/worker/strategies/WorkerStrategySelector.js +89 -0
- package/dist/execution/worker/strategies/WorkerStrategySelector.js.map +1 -0
- package/dist/execution/worker/utils/messageHandler.d.ts +21 -0
- package/dist/execution/worker/utils/messageHandler.js +109 -0
- package/dist/execution/worker/utils/messageHandler.js.map +1 -0
- package/dist/execution/worker/utils/serializeOptions.d.ts +9 -0
- package/dist/execution/worker/utils/serializeOptions.js +14 -0
- package/dist/execution/worker/utils/serializeOptions.js.map +1 -0
- package/dist/execution/worker/utils/streamCollector.node.d.ts +14 -0
- package/dist/execution/worker/utils/streamCollector.node.js +78 -0
- package/dist/execution/worker/utils/streamCollector.node.js.map +1 -0
- package/dist/execution/worker/utils/workerUtils.d.ts +14 -0
- package/dist/execution/worker/utils/workerUtils.js +25 -0
- package/dist/execution/worker/utils/workerUtils.js.map +1 -0
- package/dist/getOptionsFromResponse.constants.node.d.ts +10 -0
- package/dist/getOptionsFromResponse.constants.node.js +8 -0
- package/dist/getOptionsFromResponse.constants.node.js.map +1 -0
- package/dist/getOptionsFromResponse.constants.web.d.ts +30 -0
- package/dist/getOptionsFromResponse.constants.web.js +7 -0
- package/dist/getOptionsFromResponse.constants.web.js.map +1 -0
- package/dist/getOptionsFromResponse.d.ts +2 -1
- package/dist/getOptionsFromResponse.js +5 -9
- package/dist/getOptionsFromResponse.js.map +1 -1
- package/dist/loadWASM.js.map +1 -1
- package/dist/loadWASM.web.js.map +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +29 -5
- package/dist/parse.js.map +1 -1
- package/dist/parseBinary.d.ts +2 -1
- package/dist/parseBinary.js +32 -3
- package/dist/parseBinary.js.map +1 -1
- package/dist/parseBinaryInWorker.node.d.ts +2 -0
- package/dist/parseBinaryInWorker.web.d.ts +2 -0
- package/dist/parseBinaryInWorkerWASM.node.d.ts +2 -0
- package/dist/parseBinaryInWorkerWASM.web.d.ts +2 -0
- package/dist/parseBinaryToArraySync.d.ts +2 -1
- package/dist/parseBinaryToArraySync.js.map +1 -1
- package/dist/parseBinaryToIterableIterator.d.ts +2 -1
- package/dist/parseBinaryToIterableIterator.js.map +1 -1
- package/dist/parseBinaryToStream.d.ts +2 -1
- package/dist/parseBinaryToStream.js.map +1 -1
- package/dist/parseResponse.d.ts +1 -1
- package/dist/parseResponse.js +15 -8
- package/dist/parseResponse.js.map +1 -1
- package/dist/parseResponseToStream.d.ts +2 -1
- package/dist/parseResponseToStream.js.map +1 -1
- package/dist/parseStreamInWorker.node.d.ts +2 -0
- package/dist/parseStreamInWorker.web.d.ts +2 -0
- package/dist/parseString.d.ts +31 -0
- package/dist/parseString.js +27 -1
- package/dist/parseString.js.map +1 -1
- package/dist/parseStringInWorker.node.d.ts +2 -0
- package/dist/parseStringInWorker.web.d.ts +2 -0
- package/dist/parseStringInWorkerWASM.node.d.ts +2 -0
- package/dist/parseStringInWorkerWASM.web.d.ts +2 -0
- package/dist/parseStringStream.d.ts +43 -1
- package/dist/parseStringStream.js +24 -3
- package/dist/parseStringStream.js.map +1 -1
- package/dist/parseStringStreamToStream.js.map +1 -1
- package/dist/parseStringToArraySync.js.map +1 -1
- package/dist/parseStringToArraySyncWASM.js.map +1 -1
- package/dist/parseStringToIterableIterator.js.map +1 -1
- package/dist/parseStringToStream.js.map +1 -1
- package/dist/parseUint8ArrayStream.d.ts +4 -3
- package/dist/parseUint8ArrayStream.js +24 -3
- package/dist/parseUint8ArrayStream.js.map +1 -1
- package/dist/parseUint8ArrayStreamInWorker.node.d.ts +2 -0
- package/dist/parseUint8ArrayStreamInWorker.web.d.ts +2 -0
- package/dist/parseUint8ArrayStreamToStream.d.ts +2 -1
- package/dist/parseUint8ArrayStreamToStream.js +11 -5
- package/dist/parseUint8ArrayStreamToStream.js.map +1 -1
- package/dist/utils/convertBinaryToString.js.map +1 -1
- package/dist/utils/convertIterableIteratorToAsync.js.map +1 -1
- package/dist/utils/convertStreamToAsyncIterableIterator.js +2 -2
- package/dist/utils/convertStreamToAsyncIterableIterator.js.map +1 -1
- package/dist/utils/convertThisAsyncIterableIteratorToArray.d.ts +1 -1
- package/dist/utils/convertThisAsyncIterableIteratorToArray.js.map +1 -1
- package/dist/utils/escapeRegExp.js.map +1 -1
- package/dist/utils/parseMime.js.map +1 -1
- package/dist/utils/pipeline.js.map +1 -1
- package/dist/web-csv-toolbox.d.ts +4 -0
- package/dist/web-csv-toolbox.js +3 -0
- package/dist/web-csv-toolbox.js.map +1 -1
- package/dist/web_csv_toolbox_wasm_bg.wasm +0 -0
- package/dist/worker.node.d.ts +1 -0
- package/dist/worker.web.d.ts +1 -0
- package/package.json +53 -10
package/dist/common/types.d.ts
CHANGED
|
@@ -184,7 +184,7 @@ export interface BinaryOptions {
|
|
|
184
184
|
*
|
|
185
185
|
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream#browser_compatibility | DecompressionStream Compatibility}.
|
|
186
186
|
*/
|
|
187
|
-
|
|
187
|
+
decompression?: CompressionFormat;
|
|
188
188
|
/**
|
|
189
189
|
* You can specify the character encoding of the binary.
|
|
190
190
|
*
|
|
@@ -236,15 +236,34 @@ export interface BinaryOptions {
|
|
|
236
236
|
*/
|
|
237
237
|
fatal?: boolean;
|
|
238
238
|
/**
|
|
239
|
-
* Allow experimental or
|
|
239
|
+
* Allow experimental or non-standard compression formats not explicitly supported by this library.
|
|
240
240
|
*
|
|
241
241
|
* @remarks
|
|
242
|
-
* When `true`,
|
|
243
|
-
* to the runtime's DecompressionStream without
|
|
244
|
-
*
|
|
245
|
-
*
|
|
242
|
+
* When `true`, compression formats from Content-Encoding headers that are not in the
|
|
243
|
+
* default supported list will be passed to the runtime's DecompressionStream without
|
|
244
|
+
* validation. This allows using compression formats that may not be universally supported
|
|
245
|
+
* across all browsers.
|
|
246
246
|
*
|
|
247
|
-
*
|
|
247
|
+
* ### Default Supported Formats (cross-browser compatible)
|
|
248
|
+
*
|
|
249
|
+
* When `false` (default), only universally supported formats are allowed:
|
|
250
|
+
* - **Node.js**: `gzip`, `deflate`, `br` (Brotli)
|
|
251
|
+
* - **Browsers**: `gzip`, `deflate`
|
|
252
|
+
*
|
|
253
|
+
* ### Experimental Formats (require this flag)
|
|
254
|
+
*
|
|
255
|
+
* Some compression formats are only supported in specific environments:
|
|
256
|
+
* - **`deflate-raw`**: Supported in Chromium-based browsers (Chrome, Edge) but may not work
|
|
257
|
+
* in Firefox or Safari
|
|
258
|
+
* - **`br` (Brotli)**: Future browser support may vary
|
|
259
|
+
* - Other formats: Depends on runtime implementation
|
|
260
|
+
*
|
|
261
|
+
* ### Browser Compatibility Notes
|
|
262
|
+
*
|
|
263
|
+
* If you enable this option and use `deflate-raw`:
|
|
264
|
+
* - ✅ Works in Chrome, Edge (Chromium-based)
|
|
265
|
+
* - ❌ May fail in Firefox, Safari
|
|
266
|
+
* - Consider implementing fallback logic or detecting browser support at runtime
|
|
248
267
|
*
|
|
249
268
|
* **Use with caution**: Enabling this bypasses library validation and relies entirely
|
|
250
269
|
* on runtime error handling. If the runtime doesn't support the format, you'll get
|
|
@@ -254,14 +273,21 @@ export interface BinaryOptions {
|
|
|
254
273
|
*
|
|
255
274
|
* @example
|
|
256
275
|
* ```ts
|
|
257
|
-
* // Safe mode (default): Only
|
|
276
|
+
* // Safe mode (default): Only universally supported formats
|
|
258
277
|
* const response = await fetch('data.csv.gz');
|
|
259
|
-
* await parse(response); // ✓ Works
|
|
278
|
+
* await parse(response); // ✓ Works in all browsers
|
|
260
279
|
*
|
|
261
|
-
* // Experimental mode: Allow
|
|
262
|
-
* const response = await fetch('data.csv
|
|
280
|
+
* // Experimental mode: Allow deflate-raw (Chromium-only)
|
|
281
|
+
* const response = await fetch('data.csv'); // Content-Encoding: deflate-raw
|
|
263
282
|
* await parse(response, { allowExperimentalCompressions: true });
|
|
264
|
-
* // Works
|
|
283
|
+
* // ✓ Works in Chrome/Edge
|
|
284
|
+
* // ✗ May fail in Firefox/Safari
|
|
285
|
+
*
|
|
286
|
+
* // Browser-aware usage
|
|
287
|
+
* const isChromium = navigator.userAgent.includes('Chrome');
|
|
288
|
+
* await parse(response, {
|
|
289
|
+
* allowExperimentalCompressions: isChromium
|
|
290
|
+
* });
|
|
265
291
|
* ```
|
|
266
292
|
*/
|
|
267
293
|
allowExperimentalCompressions?: boolean;
|
|
@@ -318,17 +344,288 @@ export interface CSVRecordAssemblerOptions<Header extends ReadonlyArray<string>>
|
|
|
318
344
|
*/
|
|
319
345
|
skipEmptyLines?: boolean;
|
|
320
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Worker communication strategy.
|
|
349
|
+
*
|
|
350
|
+
* Defines how data is communicated between the main thread and worker threads.
|
|
351
|
+
*
|
|
352
|
+
* @category Types
|
|
353
|
+
*/
|
|
354
|
+
export type WorkerCommunicationStrategy = "message-streaming" | "stream-transfer";
|
|
355
|
+
/**
|
|
356
|
+
* Engine fallback information.
|
|
357
|
+
*
|
|
358
|
+
* Provided when the requested engine configuration fails and falls back to a safer configuration.
|
|
359
|
+
*
|
|
360
|
+
* @category Types
|
|
361
|
+
*/
|
|
362
|
+
export interface EngineFallbackInfo {
|
|
363
|
+
/**
|
|
364
|
+
* Original requested configuration.
|
|
365
|
+
*/
|
|
366
|
+
requestedConfig: EngineConfig;
|
|
367
|
+
/**
|
|
368
|
+
* Actual configuration after fallback.
|
|
369
|
+
*/
|
|
370
|
+
actualConfig: EngineConfig;
|
|
371
|
+
/**
|
|
372
|
+
* Reason for fallback.
|
|
373
|
+
*/
|
|
374
|
+
reason: string;
|
|
375
|
+
/**
|
|
376
|
+
* Original error if any.
|
|
377
|
+
*/
|
|
378
|
+
error?: Error;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Engine configuration for CSV parsing.
|
|
382
|
+
*
|
|
383
|
+
* All parsing engine settings are unified in this interface.
|
|
384
|
+
*
|
|
385
|
+
* @category Types
|
|
386
|
+
*/
|
|
387
|
+
export interface EngineConfig {
|
|
388
|
+
/**
|
|
389
|
+
* Execute in Worker thread.
|
|
390
|
+
*
|
|
391
|
+
* @default false
|
|
392
|
+
*
|
|
393
|
+
* @example Worker execution
|
|
394
|
+
* ```ts
|
|
395
|
+
* parse(csv, { engine: { worker: true } })
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
worker?: boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Custom Worker URL.
|
|
401
|
+
* Only applicable when `worker: true`.
|
|
402
|
+
*
|
|
403
|
+
* If not provided, uses the bundled worker.
|
|
404
|
+
*
|
|
405
|
+
* @remarks
|
|
406
|
+
* The custom worker must implement the same message protocol as the bundled worker.
|
|
407
|
+
*
|
|
408
|
+
* @example Custom worker
|
|
409
|
+
* ```ts
|
|
410
|
+
* parse(csv, {
|
|
411
|
+
* engine: {
|
|
412
|
+
* worker: true,
|
|
413
|
+
* workerURL: new URL('./custom-worker.js', import.meta.url)
|
|
414
|
+
* }
|
|
415
|
+
* })
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
workerURL?: string | URL;
|
|
419
|
+
/**
|
|
420
|
+
* Worker pool for managing worker lifecycle.
|
|
421
|
+
* Only applicable when `worker: true`.
|
|
422
|
+
*
|
|
423
|
+
* When provided, the parsing function will use this pool's worker instance
|
|
424
|
+
* instead of creating/reusing a module-level singleton worker.
|
|
425
|
+
*
|
|
426
|
+
* Use {@link WorkerPool} with the `using` syntax for automatic cleanup.
|
|
427
|
+
*
|
|
428
|
+
* @example Using ReusableWorkerPool with automatic cleanup
|
|
429
|
+
* ```ts
|
|
430
|
+
* import { ReusableWorkerPool, parseString } from 'web-csv-toolbox';
|
|
431
|
+
*
|
|
432
|
+
* async function processCSV(csv: string) {
|
|
433
|
+
* using pool = new ReusableWorkerPool();
|
|
434
|
+
*
|
|
435
|
+
* const records = [];
|
|
436
|
+
* for await (const record of parseString(csv, {
|
|
437
|
+
* engine: { worker: true, workerPool: pool }
|
|
438
|
+
* })) {
|
|
439
|
+
* records.push(record);
|
|
440
|
+
* }
|
|
441
|
+
*
|
|
442
|
+
* return records;
|
|
443
|
+
* // Worker is automatically terminated when leaving this scope
|
|
444
|
+
* }
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* @example Multiple operations with same pool
|
|
448
|
+
* ```ts
|
|
449
|
+
* import { ReusableWorkerPool, parseString } from 'web-csv-toolbox';
|
|
450
|
+
*
|
|
451
|
+
* using pool = new ReusableWorkerPool();
|
|
452
|
+
*
|
|
453
|
+
* await parseString(csv1, { engine: { worker: true, workerPool: pool } });
|
|
454
|
+
* await parseString(csv2, { engine: { worker: true, workerPool: pool } });
|
|
455
|
+
* // Worker is reused for both operations
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
workerPool?: import('../execution/worker/helpers/WorkerPool.ts').WorkerPool;
|
|
459
|
+
/**
|
|
460
|
+
* Use WASM implementation.
|
|
461
|
+
*
|
|
462
|
+
* Requires prior initialization with {@link loadWASM}.
|
|
463
|
+
*
|
|
464
|
+
* @default false
|
|
465
|
+
*
|
|
466
|
+
* @example Main thread + WASM
|
|
467
|
+
* ```ts
|
|
468
|
+
* import { loadWASM, parse } from 'web-csv-toolbox';
|
|
469
|
+
*
|
|
470
|
+
* await loadWASM();
|
|
471
|
+
* parse(csv, { engine: { wasm: true } })
|
|
472
|
+
* ```
|
|
473
|
+
*
|
|
474
|
+
* @example Worker + WASM
|
|
475
|
+
* ```ts
|
|
476
|
+
* await loadWASM();
|
|
477
|
+
* parse(csv, { engine: { worker: true, wasm: true } })
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
wasm?: boolean;
|
|
481
|
+
/**
|
|
482
|
+
* Worker communication strategy.
|
|
483
|
+
* Only applicable when `worker: true`.
|
|
484
|
+
*
|
|
485
|
+
* - `"message-streaming"` (default): Message-based streaming
|
|
486
|
+
* - ✅ All browsers including Safari
|
|
487
|
+
* - ✅ Stable and reliable
|
|
488
|
+
* - Records are sent one-by-one via postMessage
|
|
489
|
+
*
|
|
490
|
+
* - `"stream-transfer"`: TransferableStreams
|
|
491
|
+
* - ✅ Chrome 87+, Firefox 103+, Edge 87+
|
|
492
|
+
* - ❌ Safari (not supported, will fallback unless strict mode)
|
|
493
|
+
* - ⚡ Zero-copy transfer, more efficient
|
|
494
|
+
* - Uses ReadableStream transfer
|
|
495
|
+
*
|
|
496
|
+
* @default "message-streaming"
|
|
497
|
+
*
|
|
498
|
+
* @see https://caniuse.com/mdn-api_readablestream_transferable
|
|
499
|
+
*
|
|
500
|
+
* @example Message streaming (default, safe)
|
|
501
|
+
* ```ts
|
|
502
|
+
* parse(csv, { engine: { worker: true } })
|
|
503
|
+
* // or explicitly
|
|
504
|
+
* parse(csv, { engine: { worker: true, workerStrategy: "message-streaming" } })
|
|
505
|
+
* ```
|
|
506
|
+
*
|
|
507
|
+
* @example Stream transfer (Chrome/Firefox/Edge, auto-fallback on Safari)
|
|
508
|
+
* ```ts
|
|
509
|
+
* parse(csv, {
|
|
510
|
+
* engine: {
|
|
511
|
+
* worker: true,
|
|
512
|
+
* workerStrategy: "stream-transfer",
|
|
513
|
+
* onFallback: (info) => {
|
|
514
|
+
* console.warn(`Fallback to message-streaming: ${info.reason}`);
|
|
515
|
+
* }
|
|
516
|
+
* }
|
|
517
|
+
* })
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
workerStrategy?: WorkerCommunicationStrategy;
|
|
521
|
+
/**
|
|
522
|
+
* Strict mode: disable automatic fallback.
|
|
523
|
+
* Only applicable when `workerStrategy: "stream-transfer"`.
|
|
524
|
+
*
|
|
525
|
+
* When enabled:
|
|
526
|
+
* - Throws error immediately if stream transfer fails
|
|
527
|
+
* - Does not fallback to message-streaming
|
|
528
|
+
* - `onFallback` is never called
|
|
529
|
+
*
|
|
530
|
+
* When disabled (default):
|
|
531
|
+
* - Automatically falls back to message-streaming on failure
|
|
532
|
+
* - Calls `onFallback` if provided
|
|
533
|
+
*
|
|
534
|
+
* @default false
|
|
535
|
+
*
|
|
536
|
+
* @example Strict mode (Chrome/Firefox/Edge only)
|
|
537
|
+
* ```ts
|
|
538
|
+
* try {
|
|
539
|
+
* parse(csv, {
|
|
540
|
+
* engine: {
|
|
541
|
+
* worker: true,
|
|
542
|
+
* workerStrategy: "stream-transfer",
|
|
543
|
+
* strict: true
|
|
544
|
+
* }
|
|
545
|
+
* })
|
|
546
|
+
* } catch (error) {
|
|
547
|
+
* // Safari will throw error here
|
|
548
|
+
* console.error('Stream transfer not supported:', error);
|
|
549
|
+
* }
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
strict?: boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Callback when engine configuration fallback occurs.
|
|
555
|
+
*
|
|
556
|
+
* Called when the requested configuration fails and falls back to a safer configuration.
|
|
557
|
+
* Not called if `strict: true` (throws error instead).
|
|
558
|
+
*
|
|
559
|
+
* Common fallback scenario:
|
|
560
|
+
* - `workerStrategy: "stream-transfer"` → `"message-streaming"` (Safari)
|
|
561
|
+
*
|
|
562
|
+
* @example Track fallback in analytics
|
|
563
|
+
* ```ts
|
|
564
|
+
* parse(csv, {
|
|
565
|
+
* engine: {
|
|
566
|
+
* worker: true,
|
|
567
|
+
* workerStrategy: "stream-transfer",
|
|
568
|
+
* onFallback: (info) => {
|
|
569
|
+
* console.warn(`Fallback occurred: ${info.reason}`);
|
|
570
|
+
* analytics.track('engine-fallback', {
|
|
571
|
+
* reason: info.reason,
|
|
572
|
+
* userAgent: navigator.userAgent
|
|
573
|
+
* });
|
|
574
|
+
* }
|
|
575
|
+
* }
|
|
576
|
+
* })
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
onFallback?: (info: EngineFallbackInfo) => void;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Engine configuration options.
|
|
583
|
+
*
|
|
584
|
+
* @category Types
|
|
585
|
+
*/
|
|
586
|
+
export interface EngineOptions {
|
|
587
|
+
/**
|
|
588
|
+
* Engine configuration for CSV parsing.
|
|
589
|
+
*
|
|
590
|
+
* @example Default (main thread)
|
|
591
|
+
* ```ts
|
|
592
|
+
* parse(csv)
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @example Worker
|
|
596
|
+
* ```ts
|
|
597
|
+
* parse(csv, { engine: { worker: true } })
|
|
598
|
+
* ```
|
|
599
|
+
*
|
|
600
|
+
* @example Worker + WASM
|
|
601
|
+
* ```ts
|
|
602
|
+
* await loadWASM();
|
|
603
|
+
* parse(csv, { engine: { worker: true, wasm: true } })
|
|
604
|
+
* ```
|
|
605
|
+
*
|
|
606
|
+
* @example Worker + Stream transfer
|
|
607
|
+
* ```ts
|
|
608
|
+
* parse(csv, {
|
|
609
|
+
* engine: {
|
|
610
|
+
* worker: true,
|
|
611
|
+
* workerStrategy: "stream-transfer"
|
|
612
|
+
* }
|
|
613
|
+
* })
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
engine?: EngineConfig;
|
|
617
|
+
}
|
|
321
618
|
/**
|
|
322
619
|
* Parse options for CSV string.
|
|
323
620
|
* @category Types
|
|
324
621
|
*/
|
|
325
|
-
export interface ParseOptions<Header extends ReadonlyArray<string> = ReadonlyArray<string>, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION> extends CommonOptions<Delimiter, Quotation>, CSVRecordAssemblerOptions<Header>, AbortSignalOptions {
|
|
622
|
+
export interface ParseOptions<Header extends ReadonlyArray<string> = ReadonlyArray<string>, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION> extends CommonOptions<Delimiter, Quotation>, CSVRecordAssemblerOptions<Header>, EngineOptions, AbortSignalOptions {
|
|
326
623
|
}
|
|
327
624
|
/**
|
|
328
625
|
* Parse options for CSV binary.
|
|
329
626
|
* @category Types
|
|
330
627
|
*/
|
|
331
|
-
export interface ParseBinaryOptions<Header extends ReadonlyArray<string
|
|
628
|
+
export interface ParseBinaryOptions<Header extends ReadonlyArray<string> = ReadonlyArray<string>, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION> extends ParseOptions<Header, Delimiter, Quotation>, BinaryOptions {
|
|
332
629
|
}
|
|
333
630
|
/**
|
|
334
631
|
* CSV Record.
|
|
@@ -356,6 +653,31 @@ export type CSVString<Header extends ReadonlyArray<string> = [], Delimiter exten
|
|
|
356
653
|
* @category Types
|
|
357
654
|
*/
|
|
358
655
|
export type CSVBinary = ReadableStream<Uint8Array> | Response | ArrayBuffer | Uint8Array;
|
|
656
|
+
/**
|
|
657
|
+
* Backpressure monitoring options.
|
|
658
|
+
*
|
|
659
|
+
* @category Types
|
|
660
|
+
*/
|
|
661
|
+
export interface BackpressureOptions {
|
|
662
|
+
/**
|
|
663
|
+
* How often to check for backpressure (in number of items processed).
|
|
664
|
+
*
|
|
665
|
+
* Lower values = more responsive to backpressure but slight performance overhead.
|
|
666
|
+
* Higher values = less overhead but slower backpressure response.
|
|
667
|
+
*
|
|
668
|
+
* Default:
|
|
669
|
+
* - CSVLexerTransformer: 100 tokens
|
|
670
|
+
* - CSVRecordAssemblerTransformer: 10 records
|
|
671
|
+
*/
|
|
672
|
+
checkInterval?: number;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Extended queuing strategy with backpressure monitoring options.
|
|
676
|
+
*
|
|
677
|
+
* @category Types
|
|
678
|
+
*/
|
|
679
|
+
export interface ExtendedQueuingStrategy<T> extends QueuingStrategy<T>, BackpressureOptions {
|
|
680
|
+
}
|
|
359
681
|
/**
|
|
360
682
|
* CSV.
|
|
361
683
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonParseErrorHandling.js","sources":["../src/commonParseErrorHandling.ts"],"sourcesContent":["import { ParseError } from \"./common/errors\";\n\n/**\n * Common error handling for parsing CSV data.\n *\n * @param error - The error to handle.\n * @throws {ParseError} When an error occurs while parsing the CSV data.\n * @throws {RangeError} When an invalid option is provided.\n * @throws {TypeError} When an invalid option is provided.\n */\n\nexport function commonParseErrorHandling(error: unknown): never {\n if (\n error instanceof ParseError ||\n error instanceof RangeError ||\n error instanceof TypeError\n ) {\n throw error;\n }\n throw new ParseError(\"An error occurred while parsing the CSV data.\", {\n cause: error,\n });\n}\n"],"names":[],"mappings":";;AAWO,SAAS,yBAAyB,
|
|
1
|
+
{"version":3,"file":"commonParseErrorHandling.js","sources":["../src/commonParseErrorHandling.ts"],"sourcesContent":["import { ParseError } from \"./common/errors\";\n\n/**\n * Common error handling for parsing CSV data.\n *\n * @param error - The error to handle.\n * @throws {ParseError} When an error occurs while parsing the CSV data.\n * @throws {RangeError} When an invalid option is provided.\n * @throws {TypeError} When an invalid option is provided.\n */\n\nexport function commonParseErrorHandling(error: unknown): never {\n if (\n error instanceof ParseError ||\n error instanceof RangeError ||\n error instanceof TypeError\n ) {\n throw error;\n }\n throw new ParseError(\"An error occurred while parsing the CSV data.\", {\n cause: error,\n });\n}\n"],"names":[],"mappings":";;AAWO,SAAS,yBAAyB,KAAA,EAAuB;AAC9D,EAAA,IACE,KAAA,YAAiB,UAAA,IACjB,KAAA,YAAiB,UAAA,IACjB,iBAAiB,SAAA,EACjB;AACA,IAAA,MAAM,KAAA;AAAA,EACR;AACA,EAAA,MAAM,IAAI,WAAW,+CAAA,EAAiD;AAAA,IACpE,KAAA,EAAO;AAAA,GACR,CAAA;AACH;;;;"}
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const CR = \"\\r\";\nexport type CR = typeof CR;\n\nexport const CRLF = \"\\r\\n\";\nexport type CRLF = typeof CRLF;\n\nexport const LF = \"\\n\";\nexport type LF = typeof LF;\n\nexport type Newline = CRLF | CR | LF;\n\n/**\n * COMMA is a symbol for comma(,).\n */\nexport const COMMA = \",\";\n\n/**\n * DOUBLE_QUOTE is a symbol for double quote(\").\n */\nexport const DOUBLE_QUOTE = '\"';\n\nexport const DEFAULT_DELIMITER = COMMA;\nexport type DEFAULT_DELIMITER = typeof DEFAULT_DELIMITER;\n\nexport const DEFAULT_QUOTATION = DOUBLE_QUOTE;\nexport type DEFAULT_QUOTATION = typeof DEFAULT_QUOTATION;\n"],"names":[],"mappings":"AAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const CR = \"\\r\";\nexport type CR = typeof CR;\n\nexport const CRLF = \"\\r\\n\";\nexport type CRLF = typeof CRLF;\n\nexport const LF = \"\\n\";\nexport type LF = typeof LF;\n\nexport type Newline = CRLF | CR | LF;\n\n/**\n * COMMA is a symbol for comma(,).\n */\nexport const COMMA = \",\";\n\n/**\n * DOUBLE_QUOTE is a symbol for double quote(\").\n */\nexport const DOUBLE_QUOTE = '\"';\n\nexport const DEFAULT_DELIMITER = COMMA;\nexport type DEFAULT_DELIMITER = typeof DEFAULT_DELIMITER;\n\nexport const DEFAULT_QUOTATION = DOUBLE_QUOTE;\nexport type DEFAULT_QUOTATION = typeof DEFAULT_QUOTATION;\n"],"names":[],"mappings":"AAAO,MAAM,EAAA,GAAK;AAGX,MAAM,IAAA,GAAO;AAGb,MAAM,EAAA,GAAK;AAQX,MAAM,KAAA,GAAQ;AAKd,MAAM,YAAA,GAAe;AAErB,MAAM,iBAAA,GAAoB;AAG1B,MAAM,iBAAA,GAAoB;;;;"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { EngineConfig, EngineFallbackInfo } from '../common/types.ts';
|
|
2
|
+
import { WorkerPool } from './worker/helpers/WorkerPool.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Options for customizing engine presets.
|
|
5
|
+
*/
|
|
6
|
+
export interface EnginePresetOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Worker pool for managing worker lifecycle.
|
|
9
|
+
* Reuse workers across multiple parse operations.
|
|
10
|
+
*/
|
|
11
|
+
workerPool?: WorkerPool;
|
|
12
|
+
/**
|
|
13
|
+
* Custom worker URL.
|
|
14
|
+
* Use a custom worker script instead of the bundled worker.
|
|
15
|
+
*/
|
|
16
|
+
workerURL?: string | URL;
|
|
17
|
+
/**
|
|
18
|
+
* Callback for fallback notifications.
|
|
19
|
+
* Called when the engine falls back to a less optimal strategy.
|
|
20
|
+
*/
|
|
21
|
+
onFallback?: (info: EngineFallbackInfo) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Predefined engine configuration presets for common use cases.
|
|
25
|
+
*
|
|
26
|
+
* All presets are functions that optionally accept configuration options.
|
|
27
|
+
*
|
|
28
|
+
* @example Basic usage
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { parseString, EnginePresets } from 'web-csv-toolbox';
|
|
31
|
+
*
|
|
32
|
+
* // Use fastest available execution method
|
|
33
|
+
* for await (const record of parseString(csv, {
|
|
34
|
+
* engine: EnginePresets.fastest()
|
|
35
|
+
* })) {
|
|
36
|
+
* console.log(record);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example With WorkerPool
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { parseString, EnginePresets, WorkerPool } from 'web-csv-toolbox';
|
|
43
|
+
*
|
|
44
|
+
* const pool = new WorkerPool({ maxWorkers: 4 });
|
|
45
|
+
*
|
|
46
|
+
* for await (const record of parseString(csv, {
|
|
47
|
+
* engine: EnginePresets.fastest({ workerPool: pool })
|
|
48
|
+
* })) {
|
|
49
|
+
* console.log(record);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const EnginePresets: Readonly<{
|
|
54
|
+
/**
|
|
55
|
+
* Main thread execution (default).
|
|
56
|
+
* - No worker overhead
|
|
57
|
+
* - Synchronous execution on main thread
|
|
58
|
+
* - Best for small files (< 1MB)
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration options (not used for main thread)
|
|
61
|
+
* @returns Engine configuration
|
|
62
|
+
*/
|
|
63
|
+
readonly mainThread: (options?: EnginePresetOptions) => EngineConfig;
|
|
64
|
+
/**
|
|
65
|
+
* Worker execution with message streaming.
|
|
66
|
+
* - Offloads parsing to worker thread
|
|
67
|
+
* - Records sent via postMessage
|
|
68
|
+
* - Works on all browsers including Safari
|
|
69
|
+
* - Best for medium files (1-10MB)
|
|
70
|
+
*
|
|
71
|
+
* @param options - Configuration options
|
|
72
|
+
* @returns Engine configuration
|
|
73
|
+
*/
|
|
74
|
+
readonly worker: (options?: EnginePresetOptions) => EngineConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Worker execution with stream transfer (zero-copy).
|
|
77
|
+
* - Offloads parsing to worker thread
|
|
78
|
+
* - Streams transferred directly (zero-copy)
|
|
79
|
+
* - Only works on Chrome, Firefox, Edge (not Safari)
|
|
80
|
+
* - Best for large streaming files (> 10MB)
|
|
81
|
+
* - Automatically falls back to message-streaming if not supported
|
|
82
|
+
*
|
|
83
|
+
* @param options - Configuration options
|
|
84
|
+
* @returns Engine configuration
|
|
85
|
+
*/
|
|
86
|
+
readonly workerStreamTransfer: (options?: EnginePresetOptions) => EngineConfig;
|
|
87
|
+
/**
|
|
88
|
+
* WebAssembly execution on main thread.
|
|
89
|
+
* - Fast parsing with WASM
|
|
90
|
+
* - Runs on main thread
|
|
91
|
+
* - Limited to UTF-8 encoding and double-quote (")
|
|
92
|
+
* - Best for medium-sized UTF-8 files (1-10MB)
|
|
93
|
+
*
|
|
94
|
+
* @param options - Configuration options
|
|
95
|
+
* @returns Engine configuration
|
|
96
|
+
*/
|
|
97
|
+
readonly wasm: (options?: EnginePresetOptions) => EngineConfig;
|
|
98
|
+
/**
|
|
99
|
+
* Worker + WASM execution.
|
|
100
|
+
* - Combines worker offloading with WASM speed
|
|
101
|
+
* - Best for large UTF-8 files (> 10MB)
|
|
102
|
+
* - Limited to UTF-8 encoding and double-quote (")
|
|
103
|
+
*
|
|
104
|
+
* @param options - Configuration options
|
|
105
|
+
* @returns Engine configuration
|
|
106
|
+
*/
|
|
107
|
+
readonly workerWasm: (options?: EnginePresetOptions) => EngineConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Fastest available method.
|
|
110
|
+
* Automatically selects the best execution strategy:
|
|
111
|
+
* - For streams: Worker with stream-transfer (falls back to message-streaming)
|
|
112
|
+
* - For strings/binary: Worker + WASM
|
|
113
|
+
* - For all inputs: Offloads to worker for better performance
|
|
114
|
+
*
|
|
115
|
+
* @param options - Configuration options
|
|
116
|
+
* @returns Engine configuration
|
|
117
|
+
*/
|
|
118
|
+
readonly fastest: (options?: EnginePresetOptions) => EngineConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Balanced configuration for production use.
|
|
121
|
+
* - Worker execution for offloading
|
|
122
|
+
* - No WASM (broader encoding support)
|
|
123
|
+
* - Stream-transfer with automatic fallback
|
|
124
|
+
* - Works with all encodings
|
|
125
|
+
*
|
|
126
|
+
* @param options - Configuration options
|
|
127
|
+
* @returns Engine configuration
|
|
128
|
+
*/
|
|
129
|
+
readonly balanced: (options?: EnginePresetOptions) => EngineConfig;
|
|
130
|
+
/**
|
|
131
|
+
* Strict mode: no automatic fallbacks.
|
|
132
|
+
* - Throws errors instead of falling back to main thread
|
|
133
|
+
* - Useful for testing or when you need guaranteed execution mode
|
|
134
|
+
*
|
|
135
|
+
* @param options - Configuration options
|
|
136
|
+
* @returns Engine configuration
|
|
137
|
+
*/
|
|
138
|
+
readonly strict: (options?: EnginePresetOptions) => EngineConfig;
|
|
139
|
+
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Type for engine preset names.
|
|
142
|
+
*/
|
|
143
|
+
export type EnginePresetName = keyof typeof EnginePresets;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const EnginePresets = Object.freeze({
|
|
2
|
+
/**
|
|
3
|
+
* Main thread execution (default).
|
|
4
|
+
* - No worker overhead
|
|
5
|
+
* - Synchronous execution on main thread
|
|
6
|
+
* - Best for small files (< 1MB)
|
|
7
|
+
*
|
|
8
|
+
* @param options - Configuration options (not used for main thread)
|
|
9
|
+
* @returns Engine configuration
|
|
10
|
+
*/
|
|
11
|
+
mainThread: (options) => ({
|
|
12
|
+
worker: false,
|
|
13
|
+
wasm: false,
|
|
14
|
+
...options
|
|
15
|
+
}),
|
|
16
|
+
/**
|
|
17
|
+
* Worker execution with message streaming.
|
|
18
|
+
* - Offloads parsing to worker thread
|
|
19
|
+
* - Records sent via postMessage
|
|
20
|
+
* - Works on all browsers including Safari
|
|
21
|
+
* - Best for medium files (1-10MB)
|
|
22
|
+
*
|
|
23
|
+
* @param options - Configuration options
|
|
24
|
+
* @returns Engine configuration
|
|
25
|
+
*/
|
|
26
|
+
worker: (options) => ({
|
|
27
|
+
worker: true,
|
|
28
|
+
wasm: false,
|
|
29
|
+
workerStrategy: "message-streaming",
|
|
30
|
+
...options
|
|
31
|
+
}),
|
|
32
|
+
/**
|
|
33
|
+
* Worker execution with stream transfer (zero-copy).
|
|
34
|
+
* - Offloads parsing to worker thread
|
|
35
|
+
* - Streams transferred directly (zero-copy)
|
|
36
|
+
* - Only works on Chrome, Firefox, Edge (not Safari)
|
|
37
|
+
* - Best for large streaming files (> 10MB)
|
|
38
|
+
* - Automatically falls back to message-streaming if not supported
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration options
|
|
41
|
+
* @returns Engine configuration
|
|
42
|
+
*/
|
|
43
|
+
workerStreamTransfer: (options) => ({
|
|
44
|
+
worker: true,
|
|
45
|
+
wasm: false,
|
|
46
|
+
workerStrategy: "stream-transfer",
|
|
47
|
+
...options
|
|
48
|
+
}),
|
|
49
|
+
/**
|
|
50
|
+
* WebAssembly execution on main thread.
|
|
51
|
+
* - Fast parsing with WASM
|
|
52
|
+
* - Runs on main thread
|
|
53
|
+
* - Limited to UTF-8 encoding and double-quote (")
|
|
54
|
+
* - Best for medium-sized UTF-8 files (1-10MB)
|
|
55
|
+
*
|
|
56
|
+
* @param options - Configuration options
|
|
57
|
+
* @returns Engine configuration
|
|
58
|
+
*/
|
|
59
|
+
wasm: (options) => ({
|
|
60
|
+
worker: false,
|
|
61
|
+
wasm: true,
|
|
62
|
+
...options
|
|
63
|
+
}),
|
|
64
|
+
/**
|
|
65
|
+
* Worker + WASM execution.
|
|
66
|
+
* - Combines worker offloading with WASM speed
|
|
67
|
+
* - Best for large UTF-8 files (> 10MB)
|
|
68
|
+
* - Limited to UTF-8 encoding and double-quote (")
|
|
69
|
+
*
|
|
70
|
+
* @param options - Configuration options
|
|
71
|
+
* @returns Engine configuration
|
|
72
|
+
*/
|
|
73
|
+
workerWasm: (options) => ({
|
|
74
|
+
worker: true,
|
|
75
|
+
wasm: true,
|
|
76
|
+
workerStrategy: "message-streaming",
|
|
77
|
+
...options
|
|
78
|
+
}),
|
|
79
|
+
/**
|
|
80
|
+
* Fastest available method.
|
|
81
|
+
* Automatically selects the best execution strategy:
|
|
82
|
+
* - For streams: Worker with stream-transfer (falls back to message-streaming)
|
|
83
|
+
* - For strings/binary: Worker + WASM
|
|
84
|
+
* - For all inputs: Offloads to worker for better performance
|
|
85
|
+
*
|
|
86
|
+
* @param options - Configuration options
|
|
87
|
+
* @returns Engine configuration
|
|
88
|
+
*/
|
|
89
|
+
fastest: (options) => ({
|
|
90
|
+
worker: true,
|
|
91
|
+
wasm: true,
|
|
92
|
+
workerStrategy: "stream-transfer",
|
|
93
|
+
...options
|
|
94
|
+
}),
|
|
95
|
+
/**
|
|
96
|
+
* Balanced configuration for production use.
|
|
97
|
+
* - Worker execution for offloading
|
|
98
|
+
* - No WASM (broader encoding support)
|
|
99
|
+
* - Stream-transfer with automatic fallback
|
|
100
|
+
* - Works with all encodings
|
|
101
|
+
*
|
|
102
|
+
* @param options - Configuration options
|
|
103
|
+
* @returns Engine configuration
|
|
104
|
+
*/
|
|
105
|
+
balanced: (options) => ({
|
|
106
|
+
worker: true,
|
|
107
|
+
wasm: false,
|
|
108
|
+
workerStrategy: "stream-transfer",
|
|
109
|
+
...options
|
|
110
|
+
}),
|
|
111
|
+
/**
|
|
112
|
+
* Strict mode: no automatic fallbacks.
|
|
113
|
+
* - Throws errors instead of falling back to main thread
|
|
114
|
+
* - Useful for testing or when you need guaranteed execution mode
|
|
115
|
+
*
|
|
116
|
+
* @param options - Configuration options
|
|
117
|
+
* @returns Engine configuration
|
|
118
|
+
*/
|
|
119
|
+
strict: (options) => ({
|
|
120
|
+
worker: true,
|
|
121
|
+
wasm: false,
|
|
122
|
+
workerStrategy: "stream-transfer",
|
|
123
|
+
strict: true,
|
|
124
|
+
...options
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export { EnginePresets };
|
|
129
|
+
//# sourceMappingURL=EnginePresets.js.map
|