From 8fe3a5a88ad0e717c0cbca0c65ddd38f6d6bde1c Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Mon, 15 Apr 2024 16:12:56 +1000 Subject: [PATCH] get rid of typedoc warnings --- src/handler.ts | 3 +-- src/index.ts | 3 ++- src/stream/base.ts | 4 ++++ src/stream/consumption.ts | 6 +++--- src/stream/higher-order.ts | 8 ++------ src/stream/index.ts | 2 ++ src/stream/transforms.ts | 5 ++--- src/util.ts | 17 +++++++++++++++++ 8 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 src/util.ts diff --git a/src/handler.ts b/src/handler.ts index 5c34baf..cc06c00 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -1,7 +1,6 @@ import type { Atom, MaybeAtom } from "./atom"; import * as atom from "./atom"; - -export type MaybePromise = Promise | T; +import type { MaybePromise } from "./util"; /** * Given some value, will either await it if it's a promise, or return the value un-modified. This diff --git a/src/index.ts b/src/index.ts index 66b7135..1ca2f6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,9 @@ import { Stream } from "./stream"; import type { StreamBase } from "./stream/base"; export * as atom from "./atom"; +export * from "./util"; -export { Stream } from "./stream"; +export { Stream, type StreamEnd } from "./stream"; // Attempt to emulate Highland API type HighlandConstructor = (typeof StreamBase)["from"] & { of: (typeof StreamBase)["of"] }; diff --git a/src/stream/base.ts b/src/stream/base.ts index 52048f6..018ff77 100644 --- a/src/stream/base.ts +++ b/src/stream/base.ts @@ -6,6 +6,10 @@ import { Readable, Writable } from "stream"; * Marker for the end of a stream. */ export const StreamEnd = Symbol.for("STREAM_END"); + +/** + * Unique type to represent the stream end marker. + */ export type StreamEnd = typeof StreamEnd; export class StreamBase { diff --git a/src/stream/consumption.ts b/src/stream/consumption.ts index 5660f8c..01d7943 100644 --- a/src/stream/consumption.ts +++ b/src/stream/consumption.ts @@ -47,17 +47,17 @@ export class StreamConsumption extends StreamBase { /** * Iterate through each atom in the stream, and return them as a single array. * - * @param options.atom - Return every atom on the stream. + * @param options.atoms - Return every atom on the stream. * * @group Consumption */ async toArray(options?: { atoms: false }): Promise; async toArray(options?: { atoms: true }): Promise[]>; - async toArray({ atoms = false }: { atoms?: boolean } = {}): Promise<(Atom | T)[]> { + async toArray(options?: { atoms?: boolean }): Promise<(Atom | T)[]> { const array: (Atom | T)[] = []; for await (const atom of this) { - if (atoms) { + if (options?.atoms) { array.push(atom); } else if (isOk(atom)) { array.push(atom.value); diff --git a/src/stream/higher-order.ts b/src/stream/higher-order.ts index d525977..e98647f 100644 --- a/src/stream/higher-order.ts +++ b/src/stream/higher-order.ts @@ -1,15 +1,11 @@ import type { Stream } from "."; import { isError, isOk, type Atom, type MaybeAtom, isUnknown } from "../atom"; -import { handler, type MaybePromise } from "../handler"; +import { handler } from "../handler"; +import type { CallbackOrStream, MaybePromise } from "../util"; import { StreamTransforms } from "./transforms"; type FlatMapResult = { atom: Atom } | { stream: Promise, E>> }; -/** - * Type that may be a callback that resolves to a stream, or just a stream. - */ -type CallbackOrStream = (() => Stream) | Stream; - export class HigherOrderStream extends StreamTransforms { /** * Map over each value in the stream, produce a stream from it, and flatten all the value diff --git a/src/stream/index.ts b/src/stream/index.ts index ba30b3b..442420d 100644 --- a/src/stream/index.ts +++ b/src/stream/index.ts @@ -1,3 +1,5 @@ import { HigherOrderStream } from "./higher-order"; +export type { StreamEnd } from "./base"; + export class Stream extends HigherOrderStream {} diff --git a/src/stream/transforms.ts b/src/stream/transforms.ts index acd9bfb..caca913 100644 --- a/src/stream/transforms.ts +++ b/src/stream/transforms.ts @@ -1,11 +1,10 @@ import { Stream } from "."; import { isOk, isUnknown, type MaybeAtom, type Atom, isError, unknown, ok } from "../atom"; -import { handler, type MaybePromise } from "../handler"; +import { handler } from "../handler"; import { StreamConsumption } from "./consumption"; import { Readable } from "stream"; import util from "node:util"; - -type Truthy = NonNullable>; +import type { Truthy, MaybePromise } from "../util"; export class StreamTransforms extends StreamConsumption { /** diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..545a735 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,17 @@ +import type { Stream } from "."; + +/** + * Maybe it's a promise. Maybe it's not. Who's to say. + */ +export type MaybePromise = Promise | T; + +/** + * The truthy representation of some type. Will ensure that the type is not null/undefined, and + * isn't false, or an empty string. + */ +export type Truthy = NonNullable>; + +/** + * Type that may be a callback that resolves to a stream, or just a stream. + */ +export type CallbackOrStream = (() => Stream) | Stream;