Skip to content

Tempo Plugin

@magmacomputing/tempo-plugin-batch ​

npm version npm peer dependency version License TypeScript Ready

This is a Community plugin for the Tempo library that parallelizes massive epoch mutation tasks across worker threads utilizing lock-free SharedArrayBuffer shared memory architecture for extreme throughput.

Perfect For

Heavy data ETL pipelines, massive IoT telemetry ingestion, financial ledger backtesting, and parallel bulk date-processing workloads.


🚀 Installation & Quickstart ​

bash
npm install @magmacomputing/tempo-plugin-batch
Interactive Demo (@magmacomputing/tempo-plugin-batch)
Open in Full REPL↗
// ⚡ Parallel Bulk Mutation Demo (@magmacomputing/tempo-plugin-batch)
// Note: @magmacomputing/tempo-plugin-batch uses Node.js worker_threads for multi-threaded processing.
const timestamps = [1700000000000, 1700086400000, 1700172800000];
console.log('Original timestamps count:', timestamps.length);

let mutated;
const isNode = typeof process !== 'undefined' && Boolean(process.versions?.node);

if (isNode) {
  const { BatchPlugin } = await import('@magmacomputing/tempo-plugin-batch');
  Tempo.use(BatchPlugin);
  mutated = await Tempo.batch(timestamps, '+1w');
} else {
  console.info('Running browser fallback (BatchPlugin worker_threads requires Node.js).');
  mutated = timestamps.map(ts => new Tempo(ts).add({ weeks: 1 }).epoch.ms);
}

console.log('Mutated +1 week timestamps:', mutated);
return `Batch processed ${mutated.length} timestamps successfully!`;
Executes 100% in browser via native ESM sandbox
typescript
import { Tempo } from '@magmacomputing/tempo';
import { BatchPlugin } from '@magmacomputing/tempo-plugin-batch';

Tempo.use(BatchPlugin);

// Assume `epochs` is a massive array of integers representing timestamps
const epochs = [1700000000000, 1700000001000, /* ... millions more ... */];

// Mutate millions of dates concurrently using the background worker pool!
// The engine automatically splits the payload and offloads to workers
const batchResult = await Tempo.batch(epochs, '+1w', { threads: 4 });

console.log(batchResult); // Returns an array of mutated timestamp integers

Zero-Boilerplate Auto-Installation (Side-Effect Import) ​

typescript
import { Tempo } from '@magmacomputing/tempo';
import '@magmacomputing/tempo-plugin-batch/install';

const epochs = [1700000000000, 1700000001000];
const batchResult = await Tempo.batch(epochs, '+1w');

📚 API Surface Catalog ​

The Batch plugin mounts the static Tempo.batch() method and exports the underlying BatchOrchestrator:

Export / MethodSignatureReturnsDescription
Tempo.batch()(epochs: number[], operation: string, options?: BatchOptions)Promise<number[] | Tempo[]>Splits the input array across worker threads and applies duration mutation.
BatchOrchestratorStatic classBatchOrchestratorLow-level orchestration engine with transform() and sanitizeExecArgv() tools.

Configuration Options (BatchOptions) ​

OptionTypeDefaultDescription
threadsnumberos.cpus().lengthNumber of worker threads to allocate for the pool.
rehydratebooleanfalseWhen false, returns raw numeric timestamps (number[]) for peak throughput. When true, rehydrates output numbers into Tempo[] instances.

Supported Mutation Operations ​

The operation parameter accepts either standard duration strings or shorthand intervals:

  • Days: '+1d', '+2 days', '-5d'
  • Weeks: '+1w', '+4 weeks'
  • Hours: '+1h', '+8 hours'
  • Minutes: '+30m', '-15 mins'
  • Months / Years: '+1mo', '+1y'

📖 Architecture & Specialized Guides ​


📄 Licensing ​

This is a Community plugin. It is completely free and open-source for personal and commercial use under the MIT license. No license token is required.

Released under the MIT License.