Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(types): Fixing types #341

Merged
merged 13 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
node: [14.x, 16.x, 18.x]
module: [cjs, esm, umd]
target: [es5, es2015, esnext]
exclude:
- {node: 14.x, target: esnext}
steps:
- name: Setup node v${{ matrix.node }}
uses: actions/setup-node@v3
Expand Down
2 changes: 2 additions & 0 deletions gulp/closure-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ Symbol.iterator;
Symbol.observable;
/** @type {symbol} */
Symbol.asyncIterator;
/** @type {symbol} */
var symbolObservable = function() {};
`);
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
"eslint-plugin-jest": "26.1.1",
"esm": "https://github.com/jsg2021/esm/releases/download/v3.x.x-pr883/esm-3.x.x-pr883.tgz",
"glob": "7.1.6",
"google-closure-compiler": "20220202.0.0",
"google-closure-compiler": "20220601.0.0",
"gulp": "4.0.2",
"gulp-json-transform": "0.4.7",
"gulp-rename": "2.0.0",
"gulp-sourcemaps": "2.6.5",
"gulp-typescript": "5.0.1",
"husky": "4.2.3",
"jest": "27.5.1",
"jest": "28.1.3",
"jest-environment-node-debug": "2.0.0",
"jest-silent-reporter": "0.5.0",
"json": "9.0.6",
Expand All @@ -95,7 +95,7 @@
"source-map-loader": "0.2.4",
"terser": "4.6.4",
"terser-webpack-plugin": "2.3.5",
"ts-jest": "27.1.3",
"ts-jest": "28.0.7",
"ts-node": "8.6.2",
"typedoc": "0.16.10",
"typescript": "4.6.2",
Expand Down
8 changes: 4 additions & 4 deletions spec/asynciterable-operators/groupby-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasNext, noNext } from '../asynciterablehelpers';
import { empty, from } from 'ix/asynciterable';
import { empty, AsyncIterableX } from 'ix/asynciterable';
import { groupBy } from 'ix/asynciterable/operators';

interface Employee {
Expand All @@ -17,7 +17,7 @@ test('AsyncIterable#groupBy normal', async () => {
{ name: 'Lisa', age: 23 },
{ name: 'Eric', age: 42 },
];
const xss = from<Employee, Employee>(xs);
const xss = AsyncIterableX.from<Employee, Employee>(xs);
const ys = xss.pipe(groupBy(async (x) => Math.floor(x.age / 10)));

const it = ys[Symbol.asyncIterator]();
Expand Down Expand Up @@ -65,7 +65,7 @@ test('AsyncIterable#groupBy normal can get results later', async () => {
{ name: 'Lisa', age: 23 },
{ name: 'Eric', age: 42 },
];
const xss = from<Employee, Employee>(xs);
const xss = AsyncIterableX.from<Employee, Employee>(xs);
const ys = xss.pipe(groupBy(async (x) => Math.floor(x.age / 10)));

const it = ys[Symbol.asyncIterator]();
Expand Down Expand Up @@ -117,7 +117,7 @@ test('AsyncIterable#groupBy empty', async () => {

test('AsyncIterable#groupBy element selector', async () => {
const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const xss = from<number, number>(xs);
const xss = AsyncIterableX.from<number, number>(xs);
const ys = xss.pipe(
groupBy(
async (x) => x % 3,
Expand Down
6 changes: 3 additions & 3 deletions spec/asynciterable-operators/repeat-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../asynciterablehelpers';
import { sum } from 'ix/iterable';
import { from, every, of, toArray } from 'ix/asynciterable';
import { as, every, of, toArray } from 'ix/asynciterable';
import { buffer, map, repeat, tap, take } from 'ix/asynciterable/operators';

test('AsyncIterable#repeat infinite', async () => {
Expand All @@ -18,7 +18,7 @@ test('AsyncIterable#repeat infinite', async () => {
expect(10).toBe(res.length);
expect(
every(
from(res).pipe(
as(res).pipe(
buffer(2),
map((b) => sum(b))
),
Expand All @@ -40,7 +40,7 @@ test('AsyncIterable#repeat finite', async () => {
expect(10).toBe(res.length);
expect(
every(
from(res).pipe(
as(res).pipe(
buffer(2),
map((b) => sum(b))
),
Expand Down
12 changes: 6 additions & 6 deletions spec/asynciterable-operators/slice-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { hasNext, noNext } from '../asynciterablehelpers';
import { slice } from 'ix/asynciterable/operators';
import { from } from 'ix/asynciterable';
import { as } from 'ix/asynciterable';

test('AsyncIterable#slice slices at zero with one item', async () => {
const xs = from([1, 2, 3, 4]);
const xs = as([1, 2, 3, 4]);
const ys = xs.pipe(slice(0, 1));

const it = ys[Symbol.asyncIterator]();
Expand All @@ -12,7 +12,7 @@ test('AsyncIterable#slice slices at zero with one item', async () => {
});

test('AsyncIterable#slice slices at one with one item', async () => {
const xs = from([1, 2, 3, 4]);
const xs = as([1, 2, 3, 4]);
const ys = xs.pipe(slice(1, 1));

const it = ys[Symbol.asyncIterator]();
Expand All @@ -21,7 +21,7 @@ test('AsyncIterable#slice slices at one with one item', async () => {
});

test('AsyncIterable#slice slices at one with multiple items', async () => {
const xs = from([1, 2, 3, 4]);
const xs = as([1, 2, 3, 4]);
const ys = xs.pipe(slice(1, 2));

const it = ys[Symbol.asyncIterator]();
Expand All @@ -31,7 +31,7 @@ test('AsyncIterable#slice slices at one with multiple items', async () => {
});

test('AsyncIterable#slice slices at one with no end', async () => {
const xs = from([1, 2, 3, 4]);
const xs = as([1, 2, 3, 4]);
const ys = xs.pipe(slice(1));

const it = ys[Symbol.asyncIterator]();
Expand All @@ -42,7 +42,7 @@ test('AsyncIterable#slice slices at one with no end', async () => {
});

test('AsyncIterable#slice slices at zero with no end', async () => {
const xs = from([1, 2, 3, 4]);
const xs = as([1, 2, 3, 4]);
const ys = xs.pipe(slice(0));

const it = ys[Symbol.asyncIterator]();
Expand Down
3 changes: 1 addition & 2 deletions spec/asynciterable-operators/takeuntil-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { hasNext, noNext, delayValue } from '../asynciterablehelpers';
import { takeUntil } from 'ix/asynciterable/operators';
import { as } from 'ix/asynciterable';
import { AsyncSink } from 'ix/asynciterable';
import { as, AsyncSink } from 'ix/asynciterable';

test('AsyncIterable#takeUntil hits', async () => {
const xs = async function* () {
Expand Down
18 changes: 9 additions & 9 deletions spec/asynciterable-operators/todomstream-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../asynciterablehelpers';
import { from } from 'ix/asynciterable';
import { as } from 'ix/asynciterable';
import { map, toDOMStream } from 'ix/asynciterable/operators';

// eslint-disable-next-line consistent-return
Expand All @@ -10,7 +10,7 @@ import { map, toDOMStream } from 'ix/asynciterable/operators';
});
}

const stringsItr = () => from([1, 2, 3]).pipe(map((i) => `${i}`));
const stringsItr = () => as([1, 2, 3]).pipe(map((i) => `${i}`));
const buffersItr = () => stringsItr().pipe(map((val) => Buffer.from(val)));
const objectsItr = () => stringsItr().pipe(map((val) => ({ val })));
const compare = <T>(a: T, b: T) => {
Expand All @@ -31,17 +31,17 @@ import { map, toDOMStream } from 'ix/asynciterable/operators';
const expectedObjects = expectedStrings.map((val) => ({ val }));
const expectedBuffers = expectedStrings.map((x) => Buffer.from(x));
test('yields Strings', async () => {
const expected = from(expectedStrings);
const expected = as(expectedStrings);
const actual = stringsItr().pipe(toDOMStream());
await expect(actual).toEqualStream(expected, compare);
});
test('yields Buffers', async () => {
const expected = from(expectedBuffers);
const expected = as(expectedBuffers);
const actual = buffersItr().pipe(toDOMStream());
await expect(actual).toEqualStream(expected, compare);
});
test('yields Objects', async () => {
const expected = from(expectedObjects);
const expected = as(expectedObjects);
const actual = objectsItr().pipe(toDOMStream());
await expect(actual).toEqualStream(expected, compare);
});
Expand All @@ -51,14 +51,14 @@ import { map, toDOMStream } from 'ix/asynciterable/operators';
const expectedStrings = ['123'];
const expectedBuffers = expectedStrings.map((x) => Buffer.from(x));
test('yields Strings', async () => {
const expected = from(expectedBuffers);
const expected = as(expectedBuffers);
const actual = stringsItr()
.pipe(map((x) => Buffer.from(x)))
.pipe(toDOMStream({ type: 'bytes' }));
await expect(actual).toEqualStream(expected, compare);
});
test('yields Buffers', async () => {
const expected = from(expectedBuffers);
const expected = as(expectedBuffers);
const actual = buffersItr().pipe(toDOMStream({ type: 'bytes' }));
await expect(actual).toEqualStream(expected, compare);
});
Expand All @@ -68,14 +68,14 @@ import { map, toDOMStream } from 'ix/asynciterable/operators';
const expectedStrings = ['123'];
const expectedBuffers = expectedStrings.map((x) => Buffer.from(x));
test('yields Strings', async () => {
const expected = from(expectedBuffers);
const expected = as(expectedBuffers);
const actual = stringsItr()
.pipe(map((x) => Buffer.from(x)))
.pipe(toDOMStream({ type: 'bytes', autoAllocateChunkSize: 1024 }));
await expect(actual).toEqualStream(expected, compare);
});
test('yields Buffers', async () => {
const expected = from(expectedBuffers);
const expected = as(expectedBuffers);
const actual = buffersItr().pipe(
toDOMStream({ type: 'bytes', autoAllocateChunkSize: 1024 })
);
Expand Down
18 changes: 9 additions & 9 deletions spec/asynciterable/as-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { hasNext, noNext } from '../asynciterablehelpers';
import { as } from 'ix/asynciterable';
import { AsyncIterableX } from 'ix/asynciterable';

test('AsyncIterable#as from non-iterable', async () => {
const xs = {};
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await hasNext(it, xs);
Expand All @@ -12,7 +12,7 @@ test('AsyncIterable#as from non-iterable', async () => {

test('AsyncIterable#as from string emits the string, not chars', async () => {
const x = 'foo';
const res = as(x);
const res = AsyncIterableX.as(x);
const it = res[Symbol.asyncIterator]();
await hasNext(it, x);
await noNext(it);
Expand All @@ -24,7 +24,7 @@ test('AsyncIterable#as from promise list', async () => {
Promise.resolve(2),
Promise.resolve(3),
];
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await hasNext(it, 1);
Expand All @@ -41,7 +41,7 @@ async function* getData(): AsyncIterable<number> {

test('AsyncIterable#as from async generator', async () => {
const xs = getData();
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await hasNext(it, 1);
Expand All @@ -52,7 +52,7 @@ test('AsyncIterable#as from async generator', async () => {

test('AsyncIterable#as from array/iterable', async () => {
const xs = [1, 2, 3];
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await hasNext(it, 1);
Expand All @@ -63,15 +63,15 @@ test('AsyncIterable#as from array/iterable', async () => {

test('AsyncIterable#as from empty array/iterable', async () => {
const xs: number[] = [];
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await noNext(it);
});

test('AsyncIterable#as from array-like', async () => {
const xs = { length: 3 };
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await hasNext(it, undefined);
Expand All @@ -82,7 +82,7 @@ test('AsyncIterable#as from array-like', async () => {

test('AsyncIterable#as from promise', async () => {
const xs = Promise.resolve(42);
const res = as(xs);
const res = AsyncIterableX.as(xs);

const it = res[Symbol.asyncIterator]();
await hasNext(it, 42);
Expand Down
6 changes: 3 additions & 3 deletions spec/asynciterable/asasynciterable-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../asynciterablehelpers';
import { from } from 'ix/asynciterable';
import { as } from 'ix/asynciterable';
import { Readable, ReadableOptions } from 'stream';
import { asAsyncIterable } from 'ix/asynciterable/asasynciterable';

Expand Down Expand Up @@ -34,7 +34,7 @@ import { asAsyncIterable } from 'ix/asynciterable/asasynciterable';
const xs = c.pipe(
asAsyncIterable<string>({ objectMode: true })
);
const expected = from(['1', '2', '3']);
const expected = as(['1', '2', '3']);
await expect(xs).toEqualStream(expected, compare);
});

Expand All @@ -43,7 +43,7 @@ import { asAsyncIterable } from 'ix/asynciterable/asasynciterable';
const xs = c.pipe(
asAsyncIterable<string>({ objectMode: false })
);
const expected = from(['123']);
const expected = as(['123']);
await expect(xs).toEqualStream(expected, compare);
});
});
Expand Down
6 changes: 3 additions & 3 deletions spec/asynciterable/fromdomstream-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../asynciterablehelpers';
import { Readable, ReadableOptions } from 'stream';
import { from, fromDOMStream } from 'ix/asynciterable';
import { as, fromDOMStream } from 'ix/asynciterable';

// eslint-disable-next-line consistent-return
(() => {
Expand Down Expand Up @@ -44,14 +44,14 @@ import { from, fromDOMStream } from 'ix/asynciterable';
test('objectMode: true', async () => {
const c = toStream(new Counter({ objectMode: true }));
const xs = fromDOMStream(c) as AsyncIterable<string>;
const expected = from(['1', '2', '3']);
const expected = as(['1', '2', '3']);
await expect(xs).toEqualStream(expected, compare);
});

test('objectMode: false', async () => {
const c = toStream(new Counter({ objectMode: false }));
const xs = fromDOMStream(c) as AsyncIterable<Buffer>;
const expected = from(['1', '2', '3'].map((s) => Buffer.from(s)));
const expected = as(['1', '2', '3'].map((s) => Buffer.from(s)));
await expect(xs).toEqualStream(expected, compare);
});
});
Expand Down
16 changes: 15 additions & 1 deletion spec/asynciterable/fromevent-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const EVENT_TYPE = 'data';

test('AsyncIterable#fromEvent writes before emit', async () => {
const e = new EventEmitter();
const a = fromEvent(e, EVENT_TYPE);
const a = fromEvent<number>(e, EVENT_TYPE);

e.emit(EVENT_TYPE, 1);
e.emit(EVENT_TYPE, 2);
Expand All @@ -17,3 +17,17 @@ test('AsyncIterable#fromEvent writes before emit', async () => {
await hasNext(it, 2);
await hasNext(it, 3);
});

test('AsyncIterable#fromEvent has selector', async () => {
const e = new EventEmitter();
const a = fromEvent(e, EVENT_TYPE, (x) => x * 2);

e.emit(EVENT_TYPE, 1);
e.emit(EVENT_TYPE, 2);
e.emit(EVENT_TYPE, 3);

const it = a[Symbol.asyncIterator]();
await hasNext(it, 2);
await hasNext(it, 4);
await hasNext(it, 6);
});
Loading