Socket
Socket
Sign inDemoInstall

rxjs-async-map

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rxjs-async-map - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0-preview.0

out/cjs/index.d.ts

30

package.json
{
"name": "rxjs-async-map",
"version": "0.2.0",
"version": "0.3.0-preview.0",
"description": "Map an observable using an async function with a configurable concurreny level, while preserving element order.",
"main": "out/index.js",
"typings": "out/index.d.ts",
"main": "out/cjs/index.js",
"module": "out/esm/index.js",
"typings": "out/cjs/index.d.ts",
"sideEffects": false,
"scripts": {
"lint": "tslint -p tsconfig.json",
"compile": "tsc",
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"test": "jest --no-watchman"

@@ -18,12 +22,12 @@ },

},
"dependencies": {
"rxjs": "^6.3.3"
"peerDependencies": {
"rxjs": "^7.4.0"
},
"devDependencies": {
"@types/jest": "^22.1.1",
"jasmine-promise-tools": "^1.1.0",
"jest": "^22.2.1",
"ts-jest": "^22.0.3",
"tslint": "^5.9.1",
"typescript": "^2.7.1"
"@types/jest": "^27.0.2",
"jest": "^27.2.5",
"rxjs": "^7.4.0",
"ts-jest": "^27.0.5",
"tslint": "^6.1.3",
"typescript": "^4.4.3"
},

@@ -48,3 +52,3 @@ "greenkeeper": {

"transform": {
".ts": "<rootDir>/node_modules/ts-jest/preprocessor.js"
".ts": "ts-jest"
},

@@ -51,0 +55,0 @@ "testRegex": "src/.*\\.spec\\.ts$",

@@ -1,10 +0,13 @@

import { of, empty } from 'rxjs';
import { toArray,delay } from 'rxjs/operators';
import { asyncMap } from './index';
import { of, empty } from "rxjs";
import { toArray, delay } from "rxjs/operators";
import { asyncMap } from "./index";
describe('asyncMap', () => {
it('returns empty observable for empty input', async () => {
describe("asyncMap", () => {
it("returns empty observable for empty input", async () => {
const project = jest.fn();
const input = empty();
const output = await input.pipe(asyncMap(project, 0)).pipe(toArray()).toPromise();
const output = await input
.pipe(asyncMap(project, 0))
.pipe(toArray())
.toPromise();

@@ -14,29 +17,32 @@ expect(output).toEqual([]);

it('calls project function in-order for all values in input', async () => {
const project = jest.fn(x => Promise.resolve(x.length));
const input = of('f', 'ba', 'baz');
const output = await input.pipe(asyncMap(project, 1)).pipe(toArray()).toPromise();
it("calls project function in-order for all values in input", async () => {
const project = jest.fn((x) => Promise.resolve(x.length));
const input = of("f", "ba", "baz");
const output = await input
.pipe(asyncMap(project, 1))
.pipe(toArray())
.toPromise();
expect(output).toEqual([1, 2, 3]);
expect(project.mock.calls).toEqual([['f'], ['ba'], ['baz']]);
expect(project.mock.calls).toEqual([["f"], ["ba"], ["baz"]]);
});
it('calls project function with the given concurrency', async () => {
const invocations: {[v: string]: number} = {};
const input = of('foo', 'bar', 'baz');
const project = jest.fn(v => {
it("calls project function with the given concurrency", async () => {
const invocations: { [v: string]: number } = {};
const input = of("foo", "bar", "baz");
const project = jest.fn((v) => {
invocations[v] = Date.now();
return of().pipe(delay(10)).toPromise();
return of(42).pipe(delay(10)).toPromise();
});
await input.pipe(asyncMap(project, 2)).pipe(toArray()).toPromise();
expect(invocations['bar'] - invocations['foo']).toBeLessThan(5);
expect(invocations['baz']).toBeGreaterThan(invocations['foo']);
expect(invocations['baz']).toBeGreaterThan(invocations['bar']);
expect(invocations["bar"] - invocations["foo"]).toBeLessThan(5);
expect(invocations["baz"]).toBeGreaterThan(invocations["foo"]);
expect(invocations["baz"]).toBeGreaterThan(invocations["bar"]);
});
it('returns projected values in-order even if promises resolve out of order', async () => {
const project = jest.fn(x => {
if (x === 'foo') {
it("returns projected values in-order even if promises resolve out of order", async () => {
const project = jest.fn((x) => {
if (x === "foo") {
return of(1).pipe(delay(20)).toPromise();

@@ -47,4 +53,7 @@ } else {

});
const input = of('foo', 'bar');
const output = await input.pipe(asyncMap(project, 1)).pipe(toArray()).toPromise();
const input = of("foo", "bar");
const output = await input
.pipe(asyncMap(project, 1))
.pipe(toArray())
.toPromise();

@@ -51,0 +60,0 @@ expect(output).toEqual([1, 2]);

@@ -1,5 +0,5 @@

import { Observable } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { Observable } from "rxjs";
import { mergeMap } from "rxjs/operators";
import { Notifier, notify } from './notify';
import { Notifier, notify } from "./notify";

@@ -12,3 +12,5 @@ const mapper = <T, U>(project: (value: T) => PromiseLike<U>) => {

// while invoking all ready notifiers that we encounter along the way
const notReadyIdx = notifiers.findIndex(notifier => !notifier.notifyIfReady());
const notReadyIdx = notifiers.findIndex(
(notifier) => !notifier.notifyIfReady()
);
if (notReadyIdx > 0) {

@@ -20,5 +22,6 @@ // remove all the notifiers we invoked

return (value: T) => new Observable<U>(sub => {
notifiers.push(notify(project(value), sub, onReady));
});
return (value: T) =>
new Observable<U>((sub) => {
notifiers.push(notify(project(value), sub, onReady));
});
};

@@ -29,3 +32,3 @@

concurrent: number
): (source: Observable<T>) => Observable<U> =>
): ((source: Observable<T>) => Observable<U>) =>
mergeMap(mapper(project), concurrent);

@@ -1,16 +0,20 @@

import { Observable, Observer } from 'rxjs';
import { expectToReject } from 'jasmine-promise-tools';
import { notify } from './notify';
import { Observable, Observer } from "rxjs";
import { notify } from "./notify";
const emptyObserver: Observer<any> = {
closed: true,
next(value: any): void { /* noop */ },
error(err: any): void { throw err; },
complete(): void { /*noop*/ }
next(value: any): void {
/* noop */
},
error(err: any): void {
throw err;
},
complete(): void {
/* noop */
},
};
describe('Notify', () => {
it('calls onReady when wrapped promise resolves', async () => {
const onReady = jest.fn(p => p.notifyIfReady());
await new Observable<void>(sub => {
describe("Notify", () => {
it("calls onReady when wrapped promise resolves", async () => {
const onReady = jest.fn((p) => p.notifyIfReady());
await new Observable<void>((sub) => {
notify(Promise.resolve(), sub, onReady);

@@ -22,16 +26,15 @@ }).toPromise();

it('calls onReady when wrapped promise rejects', async () => {
const onReady = jest.fn(p => p.notifyIfReady());
const promise = new Observable<void>(sub => {
notify(Promise.reject('error'), sub, onReady);
it("calls onReady when wrapped promise rejects", async () => {
const onReady = jest.fn((p) => p.notifyIfReady());
const promise = new Observable<void>((sub) => {
notify(Promise.reject("error"), sub, onReady);
}).toPromise();
const err = await expectToReject(promise);
expect(err).toBe('error');
await expect(() => promise).rejects.toBe("error");
expect(onReady).toHaveBeenCalledTimes(1);
});
it('signals non-readiness when the wrapped promise has not been resolved yet', () => {
it("signals non-readiness when the wrapped promise has not been resolved yet", () => {
const onReady = jest.fn();
const notifier = notify(Promise.reject('error'), emptyObserver, onReady);
const notifier = notify(Promise.reject("error"), emptyObserver, onReady);

@@ -38,0 +41,0 @@ expect(notifier.notifyIfReady()).toBe(false);

@@ -1,2 +0,2 @@

import { Observer } from 'rxjs';
import { Observer } from "rxjs";

@@ -13,7 +13,7 @@ export interface Notifier {

const notifier = {
notifyIfReady: () => false
notifyIfReady: () => false,
};
promise.then(
value => {
(value) => {
notifier.notifyIfReady = () => {

@@ -27,3 +27,3 @@ observer.next(value);

},
reason => {
(reason) => {
notifier.notifyIfReady = () => {

@@ -30,0 +30,0 @@ observer.error(reason);

{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": true,
"sourceMap": true,
"declaration": true,
"outDir": "out",
"lib": [
"dom",
"es5",
"es2015.core",
"es2015.promise",
"es2015.iterable",
"es2015.symbol"
]
"target": "esnext",
"moduleResolution": "node",
"esModuleInterop": true
},

@@ -18,0 +10,0 @@ "include": [

@@ -9,4 +9,2 @@ {

"no-unused-expression": true,
"no-unused-variable": true,
"no-use-before-declare": true,
"no-var-keyword": true,

@@ -24,3 +22,3 @@ "radix": true,

"array-type": [true, "generic"],
"arrow-parens": [true, "ban-single-arg-parens"],
"arrow-parens": [true],
"arrow-return-shorthand": [true, "multiline"],

@@ -36,3 +34,3 @@ "class-name": true,

"one-variable-per-declaration": [true, "ignore-for-loop"],
"quotemark": [true, "single"],
"quotemark": [true, "double"],
"semicolon": [true, "always"],

@@ -39,0 +37,0 @@ "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc