Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171/** Mapper adapters exposing one uniform workload surface over this package's fork and upstream `p-map`, so the same generated workload can drive both. @module */
import pMapUpstream, { type Mapper as UpstreamMapper, pMapIterable as pMapIterableUpstream, pMapSkip as pMapSkipUpstream,} from 'p-map';
import { type Mapper, pMap, pMapIterable, pMapSkip,} from '@monochromatic-dev/module-p-map-fork/ts';
import { settleRun, } from './map-workload.ts';import type { MapAdapter, MapAdapterCall, MapAdapterOutcome,} from './workload.ts';
//region Fork surface
/** Runs one concurrent map through this package's fork. @param call - Workload source, mapper, and bounds. @returns Normalized settlement of the fork's run. @example ```ts const outcome = await runFork(call,); ``` */function runFork(call: MapAdapterCall,): Promise<MapAdapterOutcome> { return settleRun(pMap({ iterable: call.iterable, // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the workload mapper returns strings plus the adapter's skip sentinel; the fork's Mapper narrows that sentinel to its own pMapSkip symbol mapper: call.mapper as Mapper<string, string>, options: { concurrency: call.concurrency, stopOnError: call.stopOnError, }, },),);}
/** Streams one map through this package's fork. @param call - Workload source, mapper, and bounds. @returns Async iterable of the fork's mapper results. @example ```ts const stream = streamFork(call,); ``` */function streamFork(call: MapAdapterCall,): AsyncIterable<string | symbol> { return pMapIterable({ iterable: call.iterable, // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the workload mapper returns strings plus the adapter's skip sentinel; the fork's Mapper narrows that sentinel to its own pMapSkip symbol mapper: call.mapper as Mapper<string, string>, options: { concurrency: call.concurrency, backpressure: call.backpressure, }, },);}
//endregion Fork surface
//region Upstream surface
/** Runs one concurrent map through upstream `p-map`. @param call - Workload source, mapper, and bounds. @returns Normalized settlement of upstream's run. @example ```ts const outcome = await runUpstream(call,); ``` */function runUpstream(call: MapAdapterCall,): Promise<MapAdapterOutcome> { return settleRun(pMapUpstream( call.iterable, // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the workload mapper returns strings plus the adapter's skip sentinel; upstream's Mapper narrows that sentinel to its own pMapSkip symbol call.mapper as UpstreamMapper<string, string>, { concurrency: call.concurrency, stopOnError: call.stopOnError, }, ),);}
/** Streams one map through upstream `p-map`. @param call - Workload source, mapper, and bounds. @returns Async iterable of upstream's mapper results. @example ```ts const stream = streamUpstream(call,); ``` */function streamUpstream(call: MapAdapterCall,): AsyncIterable<string | symbol> { return pMapIterableUpstream( call.iterable, // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the workload mapper returns strings plus the adapter's skip sentinel; upstream's Mapper narrows that sentinel to its own pMapSkip symbol call.mapper as UpstreamMapper<string, string>, { concurrency: call.concurrency, backpressure: call.backpressure, }, );}
//endregion Upstream surface
//region Adapters
/** Adapts this package's fork to the workload surface. @returns Adapter driving the fork's `pMap` and `pMapIterable`. @example ```ts const adapter = createForkAdapter(); ``` */export function createForkAdapter(): MapAdapter { return { skip: pMapSkip, run: runFork, stream: streamFork, };}
/** Adapts upstream `p-map` to the workload surface. @returns Adapter driving upstream `pMap` and `pMapIterable`. @example ```ts const adapter = createUpstreamAdapter(); ``` */export function createUpstreamAdapter(): MapAdapter { return { skip: pMapSkipUpstream, run: runUpstream, stream: streamUpstream, };}
//endregion Adapters