@computekit/core 0.1.2 → 0.2.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/dist/index.cjs +80 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -14
- package/dist/index.d.ts +138 -14
- package/dist/index.js +80 -8
- package/dist/index.js.map +1 -1
- package/dist/types-BNUPDwV-.d.cts +363 -0
- package/dist/types-BNUPDwV-.d.ts +363 -0
- package/dist/worker.cjs +54 -2
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +54 -2
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +154 -28
- package/src/pool.ts +9 -1
- package/src/registry.ts +132 -0
- package/src/types.ts +222 -0
- package/src/utils.ts +74 -0
- package/src/worker/runtime.ts +8 -1
- package/dist/types-2XRPtzH9.d.cts +0 -145
- package/dist/types-2XRPtzH9.d.ts +0 -145
package/src/types.ts
CHANGED
|
@@ -55,6 +55,10 @@ export interface ComputeResult<T> {
|
|
|
55
55
|
cached: boolean;
|
|
56
56
|
/** Worker ID that processed this */
|
|
57
57
|
workerId: string;
|
|
58
|
+
/** Size of input data in bytes (available in debug mode) */
|
|
59
|
+
inputSize?: number;
|
|
60
|
+
/** Size of output data in bytes (available in debug mode) */
|
|
61
|
+
outputSize?: number;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
/** Function definition for registration */
|
|
@@ -111,6 +115,8 @@ export interface ResultPayload<T = unknown> {
|
|
|
111
115
|
data: T;
|
|
112
116
|
duration: number;
|
|
113
117
|
transfer?: ArrayBuffer[];
|
|
118
|
+
/** Size of the output data in bytes */
|
|
119
|
+
outputSize?: number;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
/** Error message payload */
|
|
@@ -118,6 +124,10 @@ export interface ErrorPayload {
|
|
|
118
124
|
message: string;
|
|
119
125
|
stack?: string;
|
|
120
126
|
code?: string;
|
|
127
|
+
/** Name of the function that failed */
|
|
128
|
+
functionName?: string;
|
|
129
|
+
/** Duration before the error occurred in ms */
|
|
130
|
+
duration?: number;
|
|
121
131
|
}
|
|
122
132
|
|
|
123
133
|
/** Progress message payload */
|
|
@@ -213,6 +223,174 @@ export type ComputeFn<TInput, TOutput> = (
|
|
|
213
223
|
/** Registry of compute functions */
|
|
214
224
|
export type ComputeRegistry = Map<string, ComputeFunction>;
|
|
215
225
|
|
|
226
|
+
// ============================================================================
|
|
227
|
+
// Pipeline Types - Multi-stage Processing
|
|
228
|
+
// ============================================================================
|
|
229
|
+
|
|
230
|
+
/** Status of a pipeline stage */
|
|
231
|
+
export type StageStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
|
|
232
|
+
|
|
233
|
+
/** Detailed information about a single pipeline stage */
|
|
234
|
+
export interface StageInfo<TInput = unknown, TOutput = unknown> {
|
|
235
|
+
/** Unique identifier for the stage */
|
|
236
|
+
id: string;
|
|
237
|
+
/** Display name for the stage */
|
|
238
|
+
name: string;
|
|
239
|
+
/** Name of the registered compute function to execute */
|
|
240
|
+
functionName: string;
|
|
241
|
+
/** Current status of this stage */
|
|
242
|
+
status: StageStatus;
|
|
243
|
+
/** Input data for this stage (set when stage starts) */
|
|
244
|
+
input?: TInput;
|
|
245
|
+
/** Output data from this stage (set when stage completes) */
|
|
246
|
+
output?: TOutput;
|
|
247
|
+
/** Error if stage failed */
|
|
248
|
+
error?: Error;
|
|
249
|
+
/** Start timestamp (ms since epoch) */
|
|
250
|
+
startedAt?: number;
|
|
251
|
+
/** End timestamp (ms since epoch) */
|
|
252
|
+
completedAt?: number;
|
|
253
|
+
/** Duration in milliseconds */
|
|
254
|
+
duration?: number;
|
|
255
|
+
/** Progress within this stage (0-100) */
|
|
256
|
+
progress?: number;
|
|
257
|
+
/** Number of retry attempts */
|
|
258
|
+
retryCount: number;
|
|
259
|
+
/** Compute options specific to this stage */
|
|
260
|
+
options?: ComputeOptions;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Pipeline execution mode */
|
|
264
|
+
export type PipelineMode =
|
|
265
|
+
| 'sequential' // Each stage runs after previous completes
|
|
266
|
+
| 'parallel'; // All items in a stage run in parallel, then next stage
|
|
267
|
+
|
|
268
|
+
/** Configuration for a pipeline stage */
|
|
269
|
+
export interface StageConfig<TInput = unknown, TOutput = unknown> {
|
|
270
|
+
/** Unique identifier for the stage */
|
|
271
|
+
id: string;
|
|
272
|
+
/** Display name for the stage */
|
|
273
|
+
name: string;
|
|
274
|
+
/** Name of the registered compute function */
|
|
275
|
+
functionName: string;
|
|
276
|
+
/** Transform input before passing to compute function */
|
|
277
|
+
transformInput?: (input: TInput, previousResults: unknown[]) => unknown;
|
|
278
|
+
/** Transform output after compute function returns */
|
|
279
|
+
transformOutput?: (output: unknown) => TOutput;
|
|
280
|
+
/** Whether to skip this stage based on previous results */
|
|
281
|
+
shouldSkip?: (input: TInput, previousResults: unknown[]) => boolean;
|
|
282
|
+
/** Maximum retry attempts on failure (default: 0) */
|
|
283
|
+
maxRetries?: number;
|
|
284
|
+
/** Delay between retries in ms (default: 1000) */
|
|
285
|
+
retryDelay?: number;
|
|
286
|
+
/** Compute options for this stage */
|
|
287
|
+
options?: ComputeOptions;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Overall pipeline status */
|
|
291
|
+
export type PipelineStatus =
|
|
292
|
+
| 'idle' // Not started
|
|
293
|
+
| 'running' // Currently executing
|
|
294
|
+
| 'paused' // Paused mid-execution
|
|
295
|
+
| 'completed' // All stages completed successfully
|
|
296
|
+
| 'failed' // A stage failed (and wasn't recovered)
|
|
297
|
+
| 'cancelled'; // User cancelled
|
|
298
|
+
|
|
299
|
+
/** Comprehensive pipeline state for debugging */
|
|
300
|
+
export interface PipelineState<TInput = unknown, TOutput = unknown> {
|
|
301
|
+
/** Overall pipeline status */
|
|
302
|
+
status: PipelineStatus;
|
|
303
|
+
/** All stage information */
|
|
304
|
+
stages: StageInfo[];
|
|
305
|
+
/** Index of currently executing stage (-1 if not running) */
|
|
306
|
+
currentStageIndex: number;
|
|
307
|
+
/** Current stage info (convenience) */
|
|
308
|
+
currentStage: StageInfo | null;
|
|
309
|
+
/** Overall progress percentage (0-100) */
|
|
310
|
+
progress: number;
|
|
311
|
+
/** Final output from the last stage */
|
|
312
|
+
output: TOutput | null;
|
|
313
|
+
/** Initial input that started the pipeline */
|
|
314
|
+
input: TInput | null;
|
|
315
|
+
/** Error that caused pipeline failure */
|
|
316
|
+
error: Error | null;
|
|
317
|
+
/** Pipeline start timestamp */
|
|
318
|
+
startedAt: number | null;
|
|
319
|
+
/** Pipeline completion timestamp */
|
|
320
|
+
completedAt: number | null;
|
|
321
|
+
/** Total duration in milliseconds */
|
|
322
|
+
totalDuration: number | null;
|
|
323
|
+
/** Results from each completed stage */
|
|
324
|
+
stageResults: unknown[];
|
|
325
|
+
/** Execution metrics for debugging */
|
|
326
|
+
metrics: PipelineMetrics;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Metrics for pipeline debugging and reporting */
|
|
330
|
+
export interface PipelineMetrics {
|
|
331
|
+
/** Total stages in pipeline */
|
|
332
|
+
totalStages: number;
|
|
333
|
+
/** Number of completed stages */
|
|
334
|
+
completedStages: number;
|
|
335
|
+
/** Number of failed stages */
|
|
336
|
+
failedStages: number;
|
|
337
|
+
/** Number of skipped stages */
|
|
338
|
+
skippedStages: number;
|
|
339
|
+
/** Total retry attempts across all stages */
|
|
340
|
+
totalRetries: number;
|
|
341
|
+
/** Slowest stage info */
|
|
342
|
+
slowestStage: { id: string; name: string; duration: number } | null;
|
|
343
|
+
/** Fastest stage info */
|
|
344
|
+
fastestStage: { id: string; name: string; duration: number } | null;
|
|
345
|
+
/** Average stage duration */
|
|
346
|
+
averageStageDuration: number;
|
|
347
|
+
/** Timestamp of each stage transition for timeline view */
|
|
348
|
+
timeline: Array<{
|
|
349
|
+
stageId: string;
|
|
350
|
+
stageName: string;
|
|
351
|
+
event: 'started' | 'completed' | 'failed' | 'skipped' | 'retry';
|
|
352
|
+
timestamp: number;
|
|
353
|
+
duration?: number;
|
|
354
|
+
error?: string;
|
|
355
|
+
}>;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Pipeline configuration options */
|
|
359
|
+
export interface PipelineOptions {
|
|
360
|
+
/** Execution mode (default: 'sequential') */
|
|
361
|
+
mode?: PipelineMode;
|
|
362
|
+
/** Stop pipeline on first stage failure (default: true) */
|
|
363
|
+
stopOnError?: boolean;
|
|
364
|
+
/** Global timeout for entire pipeline in ms */
|
|
365
|
+
timeout?: number;
|
|
366
|
+
/** Enable detailed timeline tracking (default: true) */
|
|
367
|
+
trackTimeline?: boolean;
|
|
368
|
+
/** Called when pipeline state changes */
|
|
369
|
+
onStateChange?: (state: PipelineState) => void;
|
|
370
|
+
/** Called when a stage starts */
|
|
371
|
+
onStageStart?: (stage: StageInfo) => void;
|
|
372
|
+
/** Called when a stage completes */
|
|
373
|
+
onStageComplete?: (stage: StageInfo) => void;
|
|
374
|
+
/** Called when a stage fails */
|
|
375
|
+
onStageError?: (stage: StageInfo, error: Error) => void;
|
|
376
|
+
/** Called when a stage is retried */
|
|
377
|
+
onStageRetry?: (stage: StageInfo, attempt: number) => void;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Events emitted by Pipeline */
|
|
381
|
+
export interface PipelineEvents {
|
|
382
|
+
'pipeline:start': { input: unknown };
|
|
383
|
+
'pipeline:complete': { output: unknown; duration: number };
|
|
384
|
+
'pipeline:error': { error: Error; stageId: string };
|
|
385
|
+
'pipeline:cancel': { stageId: string };
|
|
386
|
+
'stage:start': StageInfo;
|
|
387
|
+
'stage:progress': { stageId: string; progress: number };
|
|
388
|
+
'stage:complete': StageInfo;
|
|
389
|
+
'stage:error': { stage: StageInfo; error: Error };
|
|
390
|
+
'stage:skip': StageInfo;
|
|
391
|
+
'stage:retry': { stage: StageInfo; attempt: number };
|
|
392
|
+
}
|
|
393
|
+
|
|
216
394
|
/** Transferable types */
|
|
217
395
|
export type Transferable = ArrayBuffer | MessagePort | ImageBitmap | OffscreenCanvas;
|
|
218
396
|
|
|
@@ -229,3 +407,47 @@ export type Serializable =
|
|
|
229
407
|
| ArrayBufferView
|
|
230
408
|
| Map<Serializable, Serializable>
|
|
231
409
|
| Set<Serializable>;
|
|
410
|
+
|
|
411
|
+
// ============================================================================
|
|
412
|
+
// Parallel Batch Types - For parallel processing within stages
|
|
413
|
+
// ============================================================================
|
|
414
|
+
|
|
415
|
+
/** Configuration for parallel batch processing */
|
|
416
|
+
export interface ParallelBatchConfig<TItem = unknown> {
|
|
417
|
+
/** Items to process in parallel */
|
|
418
|
+
items: TItem[];
|
|
419
|
+
/** Name of the registered compute function */
|
|
420
|
+
functionName: string;
|
|
421
|
+
/** Maximum concurrent executions (default: all) */
|
|
422
|
+
concurrency?: number;
|
|
423
|
+
/** Compute options for batch items */
|
|
424
|
+
options?: ComputeOptions;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Result of a single item in parallel batch */
|
|
428
|
+
export interface BatchItemResult<TOutput = unknown> {
|
|
429
|
+
/** Index of the item in original array */
|
|
430
|
+
index: number;
|
|
431
|
+
/** Whether this item succeeded */
|
|
432
|
+
success: boolean;
|
|
433
|
+
/** Result if successful */
|
|
434
|
+
data?: TOutput;
|
|
435
|
+
/** Error if failed */
|
|
436
|
+
error?: Error;
|
|
437
|
+
/** Duration in ms */
|
|
438
|
+
duration: number;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** Aggregate result of parallel batch processing */
|
|
442
|
+
export interface ParallelBatchResult<TOutput = unknown> {
|
|
443
|
+
/** All individual results */
|
|
444
|
+
results: BatchItemResult<TOutput>[];
|
|
445
|
+
/** Successfully processed items */
|
|
446
|
+
successful: TOutput[];
|
|
447
|
+
/** Failed items with their errors */
|
|
448
|
+
failed: Array<{ index: number; error: Error }>;
|
|
449
|
+
/** Total duration */
|
|
450
|
+
totalDuration: number;
|
|
451
|
+
/** Success rate (0-1) */
|
|
452
|
+
successRate: number;
|
|
453
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -279,6 +279,80 @@ export function serializeFunction(fn: Function): string {
|
|
|
279
279
|
return fn.toString();
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Estimate the byte size of a value for structured cloning.
|
|
284
|
+
* This is an approximation useful for debugging and performance monitoring.
|
|
285
|
+
*/
|
|
286
|
+
export function estimatePayloadSize(value: unknown): number {
|
|
287
|
+
if (value === null || value === undefined) return 0;
|
|
288
|
+
if (typeof value === 'boolean') return 4;
|
|
289
|
+
if (typeof value === 'number') return 8;
|
|
290
|
+
if (typeof value === 'string') return value.length * 2; // UTF-16
|
|
291
|
+
|
|
292
|
+
if (value instanceof ArrayBuffer) return value.byteLength;
|
|
293
|
+
if (ArrayBuffer.isView(value)) return value.byteLength;
|
|
294
|
+
if (value instanceof Blob) return value.size;
|
|
295
|
+
|
|
296
|
+
const seen = new WeakSet<object>();
|
|
297
|
+
|
|
298
|
+
function traverse(obj: unknown): number {
|
|
299
|
+
if (obj === null || typeof obj !== 'object') {
|
|
300
|
+
if (typeof obj === 'boolean') return 4;
|
|
301
|
+
if (typeof obj === 'number') return 8;
|
|
302
|
+
if (typeof obj === 'string') return (obj as string).length * 2;
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (seen.has(obj)) return 0; // Avoid infinite loops
|
|
307
|
+
seen.add(obj);
|
|
308
|
+
|
|
309
|
+
if (obj instanceof ArrayBuffer) return obj.byteLength;
|
|
310
|
+
if (ArrayBuffer.isView(obj)) return obj.byteLength;
|
|
311
|
+
if (obj instanceof Blob) return obj.size;
|
|
312
|
+
if (obj instanceof Date) return 8;
|
|
313
|
+
if (obj instanceof RegExp) return obj.source.length * 2;
|
|
314
|
+
|
|
315
|
+
if (Array.isArray(obj)) {
|
|
316
|
+
return obj.reduce((sum, item) => sum + traverse(item), 0);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (obj instanceof Map) {
|
|
320
|
+
let size = 0;
|
|
321
|
+
obj.forEach((val, key) => {
|
|
322
|
+
size += traverse(key) + traverse(val);
|
|
323
|
+
});
|
|
324
|
+
return size;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (obj instanceof Set) {
|
|
328
|
+
let size = 0;
|
|
329
|
+
obj.forEach((val) => {
|
|
330
|
+
size += traverse(val);
|
|
331
|
+
});
|
|
332
|
+
return size;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Plain object
|
|
336
|
+
return Object.entries(obj).reduce(
|
|
337
|
+
(sum, [key, val]) => sum + key.length * 2 + traverse(val),
|
|
338
|
+
0
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return traverse(value);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Format bytes to human-readable string
|
|
347
|
+
*/
|
|
348
|
+
export function formatBytes(bytes: number): string {
|
|
349
|
+
if (bytes === 0) return '0 B';
|
|
350
|
+
const k = 1024;
|
|
351
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
352
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
353
|
+
return `${(bytes / Math.pow(k, i)).toFixed(i > 0 ? 1 : 0)} ${sizes[i]}`;
|
|
354
|
+
}
|
|
355
|
+
|
|
282
356
|
/**
|
|
283
357
|
* Logger utility
|
|
284
358
|
*/
|
package/src/worker/runtime.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
ComputeProgress,
|
|
12
12
|
} from '../types';
|
|
13
13
|
|
|
14
|
-
import { generateId, findTransferables } from '../utils';
|
|
14
|
+
import { generateId, findTransferables, estimatePayloadSize } from '../utils';
|
|
15
15
|
|
|
16
16
|
/** Registry of compute functions available in the worker */
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
@@ -91,12 +91,16 @@ async function handleMessage(event: MessageEvent<WorkerMessage>): Promise<void>
|
|
|
91
91
|
// Find transferable objects in result
|
|
92
92
|
const transfer = findTransferables(result);
|
|
93
93
|
|
|
94
|
+
// Estimate output size for debugging
|
|
95
|
+
const outputSize = estimatePayloadSize(result);
|
|
96
|
+
|
|
94
97
|
const response: WorkerMessage<ResultPayload> = {
|
|
95
98
|
id,
|
|
96
99
|
type: 'result',
|
|
97
100
|
payload: {
|
|
98
101
|
data: result,
|
|
99
102
|
duration,
|
|
103
|
+
outputSize,
|
|
100
104
|
},
|
|
101
105
|
timestamp: Date.now(),
|
|
102
106
|
};
|
|
@@ -104,6 +108,7 @@ async function handleMessage(event: MessageEvent<WorkerMessage>): Promise<void>
|
|
|
104
108
|
self.postMessage(response, transfer as Transferable[]);
|
|
105
109
|
} catch (err) {
|
|
106
110
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
111
|
+
const duration = performance.now() - startTime;
|
|
107
112
|
|
|
108
113
|
const response: WorkerMessage<ErrorPayload> = {
|
|
109
114
|
id,
|
|
@@ -111,6 +116,8 @@ async function handleMessage(event: MessageEvent<WorkerMessage>): Promise<void>
|
|
|
111
116
|
payload: {
|
|
112
117
|
message: error.message,
|
|
113
118
|
stack: error.stack,
|
|
119
|
+
functionName,
|
|
120
|
+
duration,
|
|
114
121
|
},
|
|
115
122
|
timestamp: Date.now(),
|
|
116
123
|
};
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ComputeKit Core Types
|
|
3
|
-
* Type definitions for the WASM + Worker toolkit
|
|
4
|
-
*/
|
|
5
|
-
/** Configuration options for ComputeKit */
|
|
6
|
-
interface ComputeKitOptions {
|
|
7
|
-
/** Maximum number of workers in the pool (default: navigator.hardwareConcurrency || 4) */
|
|
8
|
-
maxWorkers?: number;
|
|
9
|
-
/** Timeout for compute operations in milliseconds (default: 30000) */
|
|
10
|
-
timeout?: number;
|
|
11
|
-
/** Enable debug logging (default: false) */
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
/** Custom path to worker script */
|
|
14
|
-
workerPath?: string;
|
|
15
|
-
/** Whether to use SharedArrayBuffer when available (default: true) */
|
|
16
|
-
useSharedMemory?: boolean;
|
|
17
|
-
/** Remote scripts to load in workers via importScripts */
|
|
18
|
-
remoteDependencies?: string[];
|
|
19
|
-
}
|
|
20
|
-
/** Options for individual compute operations */
|
|
21
|
-
interface ComputeOptions {
|
|
22
|
-
/** Timeout for this specific operation (overrides global) */
|
|
23
|
-
timeout?: number;
|
|
24
|
-
/** Transfer these ArrayBuffers to the worker (improves performance) */
|
|
25
|
-
transfer?: ArrayBuffer[];
|
|
26
|
-
/** Priority level for scheduling (0-10, higher = more priority) */
|
|
27
|
-
priority?: number;
|
|
28
|
-
/** Abort signal to cancel the operation */
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
/** Progress callback for long-running operations */
|
|
31
|
-
onProgress?: (progress: ComputeProgress) => void;
|
|
32
|
-
}
|
|
33
|
-
/** Progress information for compute operations */
|
|
34
|
-
interface ComputeProgress {
|
|
35
|
-
/** Progress percentage (0-100) */
|
|
36
|
-
percent: number;
|
|
37
|
-
/** Current step/phase name */
|
|
38
|
-
phase?: string;
|
|
39
|
-
/** Estimated time remaining in milliseconds */
|
|
40
|
-
estimatedTimeRemaining?: number;
|
|
41
|
-
/** Any additional data from the compute function */
|
|
42
|
-
data?: unknown;
|
|
43
|
-
}
|
|
44
|
-
/** Result wrapper with metadata */
|
|
45
|
-
interface ComputeResult<T> {
|
|
46
|
-
/** The computed result */
|
|
47
|
-
data: T;
|
|
48
|
-
/** Time taken in milliseconds */
|
|
49
|
-
duration: number;
|
|
50
|
-
/** Whether the result came from cache */
|
|
51
|
-
cached: boolean;
|
|
52
|
-
/** Worker ID that processed this */
|
|
53
|
-
workerId: string;
|
|
54
|
-
}
|
|
55
|
-
/** Function definition for registration */
|
|
56
|
-
interface ComputeFunction<TInput = unknown, TOutput = unknown> {
|
|
57
|
-
/** The compute function implementation */
|
|
58
|
-
fn: (input: TInput) => TOutput | Promise<TOutput>;
|
|
59
|
-
/** Optional WASM module to load */
|
|
60
|
-
wasmModule?: WebAssembly.Module | ArrayBuffer | string;
|
|
61
|
-
/** Whether this function supports progress reporting */
|
|
62
|
-
supportsProgress?: boolean;
|
|
63
|
-
}
|
|
64
|
-
/** WASM module configuration */
|
|
65
|
-
interface WasmModuleConfig {
|
|
66
|
-
/** Path to the WASM file or base64 encoded WASM */
|
|
67
|
-
source: string | ArrayBuffer;
|
|
68
|
-
/** Imports to provide to the WASM module */
|
|
69
|
-
imports?: WebAssembly.Imports;
|
|
70
|
-
/** Memory configuration */
|
|
71
|
-
memory?: {
|
|
72
|
-
initial: number;
|
|
73
|
-
maximum?: number;
|
|
74
|
-
shared?: boolean;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/** Worker state */
|
|
78
|
-
type WorkerState = 'idle' | 'busy' | 'error' | 'terminated';
|
|
79
|
-
/** Worker info */
|
|
80
|
-
interface WorkerInfo {
|
|
81
|
-
id: string;
|
|
82
|
-
state: WorkerState;
|
|
83
|
-
currentTask?: string;
|
|
84
|
-
tasksCompleted: number;
|
|
85
|
-
errors: number;
|
|
86
|
-
createdAt: number;
|
|
87
|
-
lastActiveAt: number;
|
|
88
|
-
}
|
|
89
|
-
/** Pool statistics */
|
|
90
|
-
interface PoolStats {
|
|
91
|
-
workers: WorkerInfo[];
|
|
92
|
-
totalWorkers: number;
|
|
93
|
-
activeWorkers: number;
|
|
94
|
-
idleWorkers: number;
|
|
95
|
-
queueLength: number;
|
|
96
|
-
tasksCompleted: number;
|
|
97
|
-
tasksFailed: number;
|
|
98
|
-
averageTaskDuration: number;
|
|
99
|
-
}
|
|
100
|
-
/** Event data for worker:created */
|
|
101
|
-
interface WorkerCreatedEvent {
|
|
102
|
-
info: WorkerInfo;
|
|
103
|
-
}
|
|
104
|
-
/** Event data for worker:terminated */
|
|
105
|
-
interface WorkerTerminatedEvent {
|
|
106
|
-
info: WorkerInfo;
|
|
107
|
-
}
|
|
108
|
-
/** Event data for worker:error */
|
|
109
|
-
interface WorkerErrorEvent {
|
|
110
|
-
error: Error;
|
|
111
|
-
info: WorkerInfo;
|
|
112
|
-
}
|
|
113
|
-
/** Event data for task:start */
|
|
114
|
-
interface TaskStartEvent {
|
|
115
|
-
taskId: string;
|
|
116
|
-
functionName: string;
|
|
117
|
-
}
|
|
118
|
-
/** Event data for task:complete */
|
|
119
|
-
interface TaskCompleteEvent {
|
|
120
|
-
taskId: string;
|
|
121
|
-
duration: number;
|
|
122
|
-
}
|
|
123
|
-
/** Event data for task:error */
|
|
124
|
-
interface TaskErrorEvent {
|
|
125
|
-
taskId: string;
|
|
126
|
-
error: Error;
|
|
127
|
-
}
|
|
128
|
-
/** Event data for task:progress */
|
|
129
|
-
interface TaskProgressEvent {
|
|
130
|
-
taskId: string;
|
|
131
|
-
progress: ComputeProgress;
|
|
132
|
-
}
|
|
133
|
-
/** Events emitted by ComputeKit */
|
|
134
|
-
type ComputeKitEvents = {
|
|
135
|
-
'worker:created': WorkerCreatedEvent;
|
|
136
|
-
'worker:terminated': WorkerTerminatedEvent;
|
|
137
|
-
'worker:error': WorkerErrorEvent;
|
|
138
|
-
'task:start': TaskStartEvent;
|
|
139
|
-
'task:complete': TaskCompleteEvent;
|
|
140
|
-
'task:error': TaskErrorEvent;
|
|
141
|
-
'task:progress': TaskProgressEvent;
|
|
142
|
-
[key: string]: unknown;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export type { ComputeKitOptions as C, PoolStats as P, WasmModuleConfig as W, ComputeOptions as a, ComputeKitEvents as b, ComputeResult as c, ComputeProgress as d, ComputeFunction as e, WorkerInfo as f };
|
package/dist/types-2XRPtzH9.d.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ComputeKit Core Types
|
|
3
|
-
* Type definitions for the WASM + Worker toolkit
|
|
4
|
-
*/
|
|
5
|
-
/** Configuration options for ComputeKit */
|
|
6
|
-
interface ComputeKitOptions {
|
|
7
|
-
/** Maximum number of workers in the pool (default: navigator.hardwareConcurrency || 4) */
|
|
8
|
-
maxWorkers?: number;
|
|
9
|
-
/** Timeout for compute operations in milliseconds (default: 30000) */
|
|
10
|
-
timeout?: number;
|
|
11
|
-
/** Enable debug logging (default: false) */
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
/** Custom path to worker script */
|
|
14
|
-
workerPath?: string;
|
|
15
|
-
/** Whether to use SharedArrayBuffer when available (default: true) */
|
|
16
|
-
useSharedMemory?: boolean;
|
|
17
|
-
/** Remote scripts to load in workers via importScripts */
|
|
18
|
-
remoteDependencies?: string[];
|
|
19
|
-
}
|
|
20
|
-
/** Options for individual compute operations */
|
|
21
|
-
interface ComputeOptions {
|
|
22
|
-
/** Timeout for this specific operation (overrides global) */
|
|
23
|
-
timeout?: number;
|
|
24
|
-
/** Transfer these ArrayBuffers to the worker (improves performance) */
|
|
25
|
-
transfer?: ArrayBuffer[];
|
|
26
|
-
/** Priority level for scheduling (0-10, higher = more priority) */
|
|
27
|
-
priority?: number;
|
|
28
|
-
/** Abort signal to cancel the operation */
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
/** Progress callback for long-running operations */
|
|
31
|
-
onProgress?: (progress: ComputeProgress) => void;
|
|
32
|
-
}
|
|
33
|
-
/** Progress information for compute operations */
|
|
34
|
-
interface ComputeProgress {
|
|
35
|
-
/** Progress percentage (0-100) */
|
|
36
|
-
percent: number;
|
|
37
|
-
/** Current step/phase name */
|
|
38
|
-
phase?: string;
|
|
39
|
-
/** Estimated time remaining in milliseconds */
|
|
40
|
-
estimatedTimeRemaining?: number;
|
|
41
|
-
/** Any additional data from the compute function */
|
|
42
|
-
data?: unknown;
|
|
43
|
-
}
|
|
44
|
-
/** Result wrapper with metadata */
|
|
45
|
-
interface ComputeResult<T> {
|
|
46
|
-
/** The computed result */
|
|
47
|
-
data: T;
|
|
48
|
-
/** Time taken in milliseconds */
|
|
49
|
-
duration: number;
|
|
50
|
-
/** Whether the result came from cache */
|
|
51
|
-
cached: boolean;
|
|
52
|
-
/** Worker ID that processed this */
|
|
53
|
-
workerId: string;
|
|
54
|
-
}
|
|
55
|
-
/** Function definition for registration */
|
|
56
|
-
interface ComputeFunction<TInput = unknown, TOutput = unknown> {
|
|
57
|
-
/** The compute function implementation */
|
|
58
|
-
fn: (input: TInput) => TOutput | Promise<TOutput>;
|
|
59
|
-
/** Optional WASM module to load */
|
|
60
|
-
wasmModule?: WebAssembly.Module | ArrayBuffer | string;
|
|
61
|
-
/** Whether this function supports progress reporting */
|
|
62
|
-
supportsProgress?: boolean;
|
|
63
|
-
}
|
|
64
|
-
/** WASM module configuration */
|
|
65
|
-
interface WasmModuleConfig {
|
|
66
|
-
/** Path to the WASM file or base64 encoded WASM */
|
|
67
|
-
source: string | ArrayBuffer;
|
|
68
|
-
/** Imports to provide to the WASM module */
|
|
69
|
-
imports?: WebAssembly.Imports;
|
|
70
|
-
/** Memory configuration */
|
|
71
|
-
memory?: {
|
|
72
|
-
initial: number;
|
|
73
|
-
maximum?: number;
|
|
74
|
-
shared?: boolean;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/** Worker state */
|
|
78
|
-
type WorkerState = 'idle' | 'busy' | 'error' | 'terminated';
|
|
79
|
-
/** Worker info */
|
|
80
|
-
interface WorkerInfo {
|
|
81
|
-
id: string;
|
|
82
|
-
state: WorkerState;
|
|
83
|
-
currentTask?: string;
|
|
84
|
-
tasksCompleted: number;
|
|
85
|
-
errors: number;
|
|
86
|
-
createdAt: number;
|
|
87
|
-
lastActiveAt: number;
|
|
88
|
-
}
|
|
89
|
-
/** Pool statistics */
|
|
90
|
-
interface PoolStats {
|
|
91
|
-
workers: WorkerInfo[];
|
|
92
|
-
totalWorkers: number;
|
|
93
|
-
activeWorkers: number;
|
|
94
|
-
idleWorkers: number;
|
|
95
|
-
queueLength: number;
|
|
96
|
-
tasksCompleted: number;
|
|
97
|
-
tasksFailed: number;
|
|
98
|
-
averageTaskDuration: number;
|
|
99
|
-
}
|
|
100
|
-
/** Event data for worker:created */
|
|
101
|
-
interface WorkerCreatedEvent {
|
|
102
|
-
info: WorkerInfo;
|
|
103
|
-
}
|
|
104
|
-
/** Event data for worker:terminated */
|
|
105
|
-
interface WorkerTerminatedEvent {
|
|
106
|
-
info: WorkerInfo;
|
|
107
|
-
}
|
|
108
|
-
/** Event data for worker:error */
|
|
109
|
-
interface WorkerErrorEvent {
|
|
110
|
-
error: Error;
|
|
111
|
-
info: WorkerInfo;
|
|
112
|
-
}
|
|
113
|
-
/** Event data for task:start */
|
|
114
|
-
interface TaskStartEvent {
|
|
115
|
-
taskId: string;
|
|
116
|
-
functionName: string;
|
|
117
|
-
}
|
|
118
|
-
/** Event data for task:complete */
|
|
119
|
-
interface TaskCompleteEvent {
|
|
120
|
-
taskId: string;
|
|
121
|
-
duration: number;
|
|
122
|
-
}
|
|
123
|
-
/** Event data for task:error */
|
|
124
|
-
interface TaskErrorEvent {
|
|
125
|
-
taskId: string;
|
|
126
|
-
error: Error;
|
|
127
|
-
}
|
|
128
|
-
/** Event data for task:progress */
|
|
129
|
-
interface TaskProgressEvent {
|
|
130
|
-
taskId: string;
|
|
131
|
-
progress: ComputeProgress;
|
|
132
|
-
}
|
|
133
|
-
/** Events emitted by ComputeKit */
|
|
134
|
-
type ComputeKitEvents = {
|
|
135
|
-
'worker:created': WorkerCreatedEvent;
|
|
136
|
-
'worker:terminated': WorkerTerminatedEvent;
|
|
137
|
-
'worker:error': WorkerErrorEvent;
|
|
138
|
-
'task:start': TaskStartEvent;
|
|
139
|
-
'task:complete': TaskCompleteEvent;
|
|
140
|
-
'task:error': TaskErrorEvent;
|
|
141
|
-
'task:progress': TaskProgressEvent;
|
|
142
|
-
[key: string]: unknown;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export type { ComputeKitOptions as C, PoolStats as P, WasmModuleConfig as W, ComputeOptions as a, ComputeKitEvents as b, ComputeResult as c, ComputeProgress as d, ComputeFunction as e, WorkerInfo as f };
|