import type {Readable, Writable} from 'node:stream'; import type {ReadableStream, WritableStream, TransformStream} from 'node:stream/web'; import type { Not, And, Or, Unless, AndUnless, } from '../utils.js'; import type { GeneratorTransform, GeneratorTransformFull, DuplexTransform, WebTransform, } from '../transform/normalize.js'; type IsStandardStream = FdNumber extends keyof StandardStreams ? true : false; export type StandardStreams = readonly ['stdin', 'stdout', 'stderr']; // When `options.stdin|stdout|stderr|stdio` is set to one of those values, no stream is created export type NoStreamStdioOption = | 'ignore' | 'inherit' | 'ipc' | number | Readable | Writable | Unless, undefined> | readonly [NoStreamStdioOption]; // `options.stdio` when it is not an array type SimpleStdioOption< IsSync extends boolean, IsExtra extends boolean, IsArray extends boolean, > = | undefined | 'pipe' | Unless, IsArray>, IsExtra>, 'inherit'> | Unless | Unless; // Values available in both `options.stdin|stdio` and `options.stdout|stderr|stdio` type CommonStdioOption< IsSync extends boolean, IsExtra extends boolean, IsArray extends boolean, > = | SimpleStdioOption | URL | {readonly file: string; readonly append?: boolean} | GeneratorTransform | GeneratorTransformFull | Unless, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9> | Unless, 'ipc'> | Unless; // Synchronous iterables excluding strings, Uint8Arrays and Arrays type IterableObject = Iterable & object & {readonly BYTES_PER_ELEMENT?: never} & AndUnless; // `process.stdin|stdout|stderr` are `Duplex` with a `fd` property. // This ensures they can only be passed to `stdin`/`stdout`/`stderr`, based on their direction. type ProcessStdinFd = {readonly fd?: 0}; type ProcessStdoutStderrFd = {readonly fd?: 1 | 2}; // Values available only in `options.stdin|stdio` export type InputStdioOption< IsSync extends boolean = boolean, IsExtra extends boolean = boolean, IsArray extends boolean = boolean, > = | 0 | Unless, Uint8Array | IterableObject> | Unless, Readable & ProcessStdinFd> | Unless & ProcessStdinFd) | ReadableStream>; // Values available only in `options.stdout|stderr|stdio` type OutputStdioOption< IsSync extends boolean, IsArray extends boolean, > = | 1 | 2 | Unless, Writable & ProcessStdoutStderrFd> | Unless; // `options.stdin` array items type StdinSingleOption< IsSync extends boolean, IsExtra extends boolean, IsArray extends boolean, > = | CommonStdioOption | InputStdioOption; // `options.stdin` export type StdinOptionCommon< IsSync extends boolean = boolean, IsExtra extends boolean = boolean, > = | StdinSingleOption | ReadonlyArray>; // `options.stdin`, async export type StdinOption = StdinOptionCommon; // `options.stdin`, sync export type StdinSyncOption = StdinOptionCommon; // `options.stdout|stderr` array items type StdoutStderrSingleOption< IsSync extends boolean, IsExtra extends boolean, IsArray extends boolean, > = | CommonStdioOption | OutputStdioOption; // `options.stdout|stderr` export type StdoutStderrOptionCommon< IsSync extends boolean = boolean, IsExtra extends boolean = boolean, > = | StdoutStderrSingleOption | ReadonlyArray>; // `options.stdout|stderr`, async export type StdoutStderrOption = StdoutStderrOptionCommon; // `options.stdout|stderr`, sync export type StdoutStderrSyncOption = StdoutStderrOptionCommon; // `options.stdio[3+]` type StdioExtraOptionCommon = | StdinOptionCommon | StdoutStderrOptionCommon; // `options.stdin|stdout|stderr|stdio` array items type StdioSingleOption< IsSync extends boolean = boolean, IsExtra extends boolean = boolean, IsArray extends boolean = boolean, > = | StdinSingleOption | StdoutStderrSingleOption; // Get `options.stdin|stdout|stderr|stdio` items if it is an array, else keep as is export type StdioSingleOptionItems = StdioOptionType extends readonly StdioSingleOption[] ? StdioOptionType[number] : StdioOptionType; // `options.stdin|stdout|stderr|stdio` export type StdioOptionCommon = | StdinOptionCommon | StdoutStderrOptionCommon; // `options.stdio` when it is an array export type StdioOptionsArray = readonly [ StdinOptionCommon, StdoutStderrOptionCommon, StdoutStderrOptionCommon, ...ReadonlyArray>, ]; // `options.stdio` export type StdioOptionsProperty = | SimpleStdioOption | StdioOptionsArray;