Skip to content

Commit

Permalink
get rid of typedoc warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
andogq committed Apr 15, 2024
1 parent ef2b1fa commit 8fe3a5a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Atom, MaybeAtom } from "./atom";
import * as atom from "./atom";

export type MaybePromise<T> = Promise<T> | 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
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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"] };
Expand Down
4 changes: 4 additions & 0 deletions src/stream/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/stream/consumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ export class StreamConsumption<T, E> 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<T[]>;
async toArray(options?: { atoms: true }): Promise<Atom<T, E>[]>;
async toArray({ atoms = false }: { atoms?: boolean } = {}): Promise<(Atom<T, E> | T)[]> {
async toArray(options?: { atoms?: boolean }): Promise<(Atom<T, E> | T)[]> {
const array: (Atom<T, E> | T)[] = [];

for await (const atom of this) {
if (atoms) {
if (options?.atoms) {
array.push(atom);
} else if (isOk(atom)) {
array.push(atom.value);
Expand Down
8 changes: 2 additions & 6 deletions src/stream/higher-order.ts
Original file line number Diff line number Diff line change
@@ -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<T, E> = { atom: Atom<T, E> } | { stream: Promise<Atom<Stream<T, E>, E>> };

/**
* Type that may be a callback that resolves to a stream, or just a stream.
*/
type CallbackOrStream<T, E> = (() => Stream<T, E>) | Stream<T, E>;

export class HigherOrderStream<T, E> extends StreamTransforms<T, E> {
/**
* Map over each value in the stream, produce a stream from it, and flatten all the value
Expand Down
2 changes: 2 additions & 0 deletions src/stream/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HigherOrderStream } from "./higher-order";

export type { StreamEnd } from "./base";

export class Stream<T, E> extends HigherOrderStream<T, E> {}
5 changes: 2 additions & 3 deletions src/stream/transforms.ts
Original file line number Diff line number Diff line change
@@ -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<T> = NonNullable<Exclude<T, false | "">>;
import type { Truthy, MaybePromise } from "../util";

export class StreamTransforms<T, E> extends StreamConsumption<T, E> {
/**
Expand Down
17 changes: 17 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Stream } from ".";

/**
* Maybe it's a promise. Maybe it's not. Who's to say.
*/
export type MaybePromise<T> = Promise<T> | 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<T> = NonNullable<Exclude<T, false | "">>;

/**
* Type that may be a callback that resolves to a stream, or just a stream.
*/
export type CallbackOrStream<T, E> = (() => Stream<T, E>) | Stream<T, E>;

0 comments on commit 8fe3a5a

Please sign in to comment.