new license file version [CI SKIP]
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{"name":"combined-stream","version":"1.0.8","files":{"License":{"checkedAt":1678887829673,"integrity":"sha512-QC/HN+kDgNYpC7i33wfvn5wKaEz8H4mMLjVuA6w03m1OlQFq5w7L4MbJZrWZaWlso2u4xIS7xZDZT6574cQ1Og==","mode":388,"size":1085},"package.json":{"checkedAt":1678887830520,"integrity":"sha512-t7prZfhD550sZMBl2cm8/foTtZJhBIzqcvrri6fH5pnvPD5TrnMC+mvMoZ1+B3dCg6JIkUnv8qmfFJhohTWSGg==","mode":388,"size":640},"Readme.md":{"checkedAt":1678887830522,"integrity":"sha512-AMSXvw5GumnxK1C7XXz6mOZKXT0KVZkZ9ezcDU+xBg516b1Gn5wuwp2cR52XZK+C/wSnebqoSf63Wg+yts2B6g==","mode":388,"size":4551},"yarn.lock":{"checkedAt":1678887830522,"integrity":"sha512-wos/5bMpanOEY86KR8YcIyfL+DaYC1h6Hrf5urk4G4qmSpBhJ9B0a+iJdaKU4rE2bpxuvSm+s1M8JqNMCDbsYw==","mode":388,"size":551},"lib/combined_stream.js":{"checkedAt":1678887830522,"integrity":"sha512-NLJJG4D921foMMCtUqm22p78dWVUkLEXof2LtGSVnVSsJYXd1nJpdftgpAF9M69Q+ETEMR8VcMCcQTVZtKBpmg==","mode":420,"size":4687}}}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { Observable } from '../Observable';
|
||||
import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
|
||||
export declare function catchError<T, O extends ObservableInput<any>>(selector: (err: any, caught: Observable<T>) => O): OperatorFunction<T, T | ObservedValueOf<O>>;
|
||||
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
}
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Subscriber_1 = require("../Subscriber");
|
||||
var Subject_1 = require("../Subject");
|
||||
function windowCount(windowSize, startWindowEvery) {
|
||||
if (startWindowEvery === void 0) { startWindowEvery = 0; }
|
||||
return function windowCountOperatorFunction(source) {
|
||||
return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
|
||||
};
|
||||
}
|
||||
exports.windowCount = windowCount;
|
||||
var WindowCountOperator = (function () {
|
||||
function WindowCountOperator(windowSize, startWindowEvery) {
|
||||
this.windowSize = windowSize;
|
||||
this.startWindowEvery = startWindowEvery;
|
||||
}
|
||||
WindowCountOperator.prototype.call = function (subscriber, source) {
|
||||
return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
|
||||
};
|
||||
return WindowCountOperator;
|
||||
}());
|
||||
var WindowCountSubscriber = (function (_super) {
|
||||
__extends(WindowCountSubscriber, _super);
|
||||
function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
|
||||
var _this = _super.call(this, destination) || this;
|
||||
_this.destination = destination;
|
||||
_this.windowSize = windowSize;
|
||||
_this.startWindowEvery = startWindowEvery;
|
||||
_this.windows = [new Subject_1.Subject()];
|
||||
_this.count = 0;
|
||||
destination.next(_this.windows[0]);
|
||||
return _this;
|
||||
}
|
||||
WindowCountSubscriber.prototype._next = function (value) {
|
||||
var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
|
||||
var destination = this.destination;
|
||||
var windowSize = this.windowSize;
|
||||
var windows = this.windows;
|
||||
var len = windows.length;
|
||||
for (var i = 0; i < len && !this.closed; i++) {
|
||||
windows[i].next(value);
|
||||
}
|
||||
var c = this.count - windowSize + 1;
|
||||
if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
|
||||
windows.shift().complete();
|
||||
}
|
||||
if (++this.count % startWindowEvery === 0 && !this.closed) {
|
||||
var window_1 = new Subject_1.Subject();
|
||||
windows.push(window_1);
|
||||
destination.next(window_1);
|
||||
}
|
||||
};
|
||||
WindowCountSubscriber.prototype._error = function (err) {
|
||||
var windows = this.windows;
|
||||
if (windows) {
|
||||
while (windows.length > 0 && !this.closed) {
|
||||
windows.shift().error(err);
|
||||
}
|
||||
}
|
||||
this.destination.error(err);
|
||||
};
|
||||
WindowCountSubscriber.prototype._complete = function () {
|
||||
var windows = this.windows;
|
||||
if (windows) {
|
||||
while (windows.length > 0 && !this.closed) {
|
||||
windows.shift().complete();
|
||||
}
|
||||
}
|
||||
this.destination.complete();
|
||||
};
|
||||
WindowCountSubscriber.prototype._unsubscribe = function () {
|
||||
this.count = 0;
|
||||
this.windows = null;
|
||||
};
|
||||
return WindowCountSubscriber;
|
||||
}(Subscriber_1.Subscriber));
|
||||
//# sourceMappingURL=windowCount.js.map
|
||||
@@ -0,0 +1 @@
|
||||
import 'rxjs-compat/add/operator/mergeScan';
|
||||
@@ -0,0 +1 @@
|
||||
import 'rxjs-compat/add/operator/map';
|
||||
@@ -0,0 +1,129 @@
|
||||
import { SubjectSubscriber } from '../Subject';
|
||||
import { Observable } from '../Observable';
|
||||
import { Subscriber } from '../Subscriber';
|
||||
import { Subscription } from '../Subscription';
|
||||
import { refCount as higherOrderRefCount } from '../operators/refCount';
|
||||
export class ConnectableObservable extends Observable {
|
||||
constructor(source, subjectFactory) {
|
||||
super();
|
||||
this.source = source;
|
||||
this.subjectFactory = subjectFactory;
|
||||
this._refCount = 0;
|
||||
this._isComplete = false;
|
||||
}
|
||||
_subscribe(subscriber) {
|
||||
return this.getSubject().subscribe(subscriber);
|
||||
}
|
||||
getSubject() {
|
||||
const subject = this._subject;
|
||||
if (!subject || subject.isStopped) {
|
||||
this._subject = this.subjectFactory();
|
||||
}
|
||||
return this._subject;
|
||||
}
|
||||
connect() {
|
||||
let connection = this._connection;
|
||||
if (!connection) {
|
||||
this._isComplete = false;
|
||||
connection = this._connection = new Subscription();
|
||||
connection.add(this.source
|
||||
.subscribe(new ConnectableSubscriber(this.getSubject(), this)));
|
||||
if (connection.closed) {
|
||||
this._connection = null;
|
||||
connection = Subscription.EMPTY;
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
refCount() {
|
||||
return higherOrderRefCount()(this);
|
||||
}
|
||||
}
|
||||
export const connectableObservableDescriptor = (() => {
|
||||
const connectableProto = ConnectableObservable.prototype;
|
||||
return {
|
||||
operator: { value: null },
|
||||
_refCount: { value: 0, writable: true },
|
||||
_subject: { value: null, writable: true },
|
||||
_connection: { value: null, writable: true },
|
||||
_subscribe: { value: connectableProto._subscribe },
|
||||
_isComplete: { value: connectableProto._isComplete, writable: true },
|
||||
getSubject: { value: connectableProto.getSubject },
|
||||
connect: { value: connectableProto.connect },
|
||||
refCount: { value: connectableProto.refCount }
|
||||
};
|
||||
})();
|
||||
class ConnectableSubscriber extends SubjectSubscriber {
|
||||
constructor(destination, connectable) {
|
||||
super(destination);
|
||||
this.connectable = connectable;
|
||||
}
|
||||
_error(err) {
|
||||
this._unsubscribe();
|
||||
super._error(err);
|
||||
}
|
||||
_complete() {
|
||||
this.connectable._isComplete = true;
|
||||
this._unsubscribe();
|
||||
super._complete();
|
||||
}
|
||||
_unsubscribe() {
|
||||
const connectable = this.connectable;
|
||||
if (connectable) {
|
||||
this.connectable = null;
|
||||
const connection = connectable._connection;
|
||||
connectable._refCount = 0;
|
||||
connectable._subject = null;
|
||||
connectable._connection = null;
|
||||
if (connection) {
|
||||
connection.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class RefCountOperator {
|
||||
constructor(connectable) {
|
||||
this.connectable = connectable;
|
||||
}
|
||||
call(subscriber, source) {
|
||||
const { connectable } = this;
|
||||
connectable._refCount++;
|
||||
const refCounter = new RefCountSubscriber(subscriber, connectable);
|
||||
const subscription = source.subscribe(refCounter);
|
||||
if (!refCounter.closed) {
|
||||
refCounter.connection = connectable.connect();
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
}
|
||||
class RefCountSubscriber extends Subscriber {
|
||||
constructor(destination, connectable) {
|
||||
super(destination);
|
||||
this.connectable = connectable;
|
||||
}
|
||||
_unsubscribe() {
|
||||
const { connectable } = this;
|
||||
if (!connectable) {
|
||||
this.connection = null;
|
||||
return;
|
||||
}
|
||||
this.connectable = null;
|
||||
const refCount = connectable._refCount;
|
||||
if (refCount <= 0) {
|
||||
this.connection = null;
|
||||
return;
|
||||
}
|
||||
connectable._refCount = refCount - 1;
|
||||
if (refCount > 1) {
|
||||
this.connection = null;
|
||||
return;
|
||||
}
|
||||
const { connection } = this;
|
||||
const sharedConnection = connectable._connection;
|
||||
this.connection = null;
|
||||
if (sharedConnection && (!connection || sharedConnection === connection)) {
|
||||
sharedConnection.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ConnectableObservable.js.map
|
||||
@@ -0,0 +1,20 @@
|
||||
import { errorObject } from './errorObject';
|
||||
let tryCatchTarget;
|
||||
function tryCatcher() {
|
||||
errorObject.e = undefined;
|
||||
try {
|
||||
return tryCatchTarget.apply(this, arguments);
|
||||
}
|
||||
catch (e) {
|
||||
errorObject.e = e;
|
||||
return errorObject;
|
||||
}
|
||||
finally {
|
||||
tryCatchTarget = undefined;
|
||||
}
|
||||
}
|
||||
export function tryCatch(fn) {
|
||||
tryCatchTarget = fn;
|
||||
return tryCatcher;
|
||||
}
|
||||
//# sourceMappingURL=tryCatch.js.map
|
||||
@@ -0,0 +1 @@
|
||||
export * from 'rxjs-compat/operator/publishReplay';
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"timestamp.js","sources":["../../src/add/operator/timestamp.ts"],"names":[],"mappings":";;AAAA,8CAA4C"}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"concatMapTo.js","sources":["../src/operator/concatMapTo.ts"],"names":[],"mappings":";;;;;AAAA,sDAAiD"}
|
||||
@@ -0,0 +1 @@
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).uuidParse=n()}(this,(function(){"use strict";var e=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;return function(n){if(!function(n){return"string"==typeof n&&e.test(n)}(n))throw TypeError("Invalid UUID");var t,i=new Uint8Array(16);return i[0]=(t=parseInt(n.slice(0,8),16))>>>24,i[1]=t>>>16&255,i[2]=t>>>8&255,i[3]=255&t,i[4]=(t=parseInt(n.slice(9,13),16))>>>8,i[5]=255&t,i[6]=(t=parseInt(n.slice(14,18),16))>>>8,i[7]=255&t,i[8]=(t=parseInt(n.slice(19,23),16))>>>8,i[9]=255&t,i[10]=(t=parseInt(n.slice(24,36),16))/1099511627776&255,i[11]=t/4294967296&255,i[12]=t>>>24&255,i[13]=t>>>16&255,i[14]=t>>>8&255,i[15]=255&t,i}}));
|
||||
@@ -0,0 +1,124 @@
|
||||
import assertString from './util/assertString';
|
||||
/**
|
||||
11.3. Examples
|
||||
|
||||
The following addresses
|
||||
|
||||
fe80::1234 (on the 1st link of the node)
|
||||
ff02::5678 (on the 5th link of the node)
|
||||
ff08::9abc (on the 10th organization of the node)
|
||||
|
||||
would be represented as follows:
|
||||
|
||||
fe80::1234%1
|
||||
ff02::5678%5
|
||||
ff08::9abc%10
|
||||
|
||||
(Here we assume a natural translation from a zone index to the
|
||||
<zone_id> part, where the Nth zone of any scope is translated into
|
||||
"N".)
|
||||
|
||||
If we use interface names as <zone_id>, those addresses could also be
|
||||
represented as follows:
|
||||
|
||||
fe80::1234%ne0
|
||||
ff02::5678%pvc1.3
|
||||
ff08::9abc%interface10
|
||||
|
||||
where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
|
||||
to the 5th link, and "interface10" belongs to the 10th organization.
|
||||
* * */
|
||||
|
||||
var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
|
||||
var ipv6Block = /^[0-9A-F]{1,4}$/i;
|
||||
export default function isIP(str) {
|
||||
var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
||||
assertString(str);
|
||||
version = String(version);
|
||||
|
||||
if (!version) {
|
||||
return isIP(str, 4) || isIP(str, 6);
|
||||
} else if (version === '4') {
|
||||
if (!ipv4Maybe.test(str)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var parts = str.split('.').sort(function (a, b) {
|
||||
return a - b;
|
||||
});
|
||||
return parts[3] <= 255;
|
||||
} else if (version === '6') {
|
||||
var addressAndZone = [str]; // ipv6 addresses could have scoped architecture
|
||||
// according to https://tools.ietf.org/html/rfc4007#section-11
|
||||
|
||||
if (str.includes('%')) {
|
||||
addressAndZone = str.split('%');
|
||||
|
||||
if (addressAndZone.length !== 2) {
|
||||
// it must be just two parts
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!addressAndZone[0].includes(':')) {
|
||||
// the first part must be the address
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addressAndZone[1] === '') {
|
||||
// the second part must not be empty
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var blocks = addressAndZone[0].split(':');
|
||||
var foundOmissionBlock = false; // marker to indicate ::
|
||||
// At least some OS accept the last 32 bits of an IPv6 address
|
||||
// (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says
|
||||
// that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses,
|
||||
// and '::a.b.c.d' is deprecated, but also valid.
|
||||
|
||||
var foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4);
|
||||
var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8;
|
||||
|
||||
if (blocks.length > expectedNumberOfBlocks) {
|
||||
return false;
|
||||
} // initial or final ::
|
||||
|
||||
|
||||
if (str === '::') {
|
||||
return true;
|
||||
} else if (str.substr(0, 2) === '::') {
|
||||
blocks.shift();
|
||||
blocks.shift();
|
||||
foundOmissionBlock = true;
|
||||
} else if (str.substr(str.length - 2) === '::') {
|
||||
blocks.pop();
|
||||
blocks.pop();
|
||||
foundOmissionBlock = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < blocks.length; ++i) {
|
||||
// test for a :: which can not be at the string start/end
|
||||
// since those cases have been handled above
|
||||
if (blocks[i] === '' && i > 0 && i < blocks.length - 1) {
|
||||
if (foundOmissionBlock) {
|
||||
return false; // multiple :: in address
|
||||
}
|
||||
|
||||
foundOmissionBlock = true;
|
||||
} else if (foundIPv4TransitionBlock && i === blocks.length - 1) {// it has been checked before that the last
|
||||
// block is a valid IPv4 address
|
||||
} else if (!ipv6Block.test(blocks[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundOmissionBlock) {
|
||||
return blocks.length >= 1;
|
||||
}
|
||||
|
||||
return blocks.length === expectedNumberOfBlocks;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"skipLast.js","sources":["../../src/internal/operators/skipLast.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,4CAA2C;AAC3C,2EAA0E;AA0C1E,SAAgB,QAAQ,CAAI,KAAa;IACvC,OAAO,UAAC,MAAqB,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAxC,CAAwC,CAAC;AAC7E,CAAC;AAFD,4BAEC;AAED;IACE,0BAAoB,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;QACpC,IAAI,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE;YACvB,MAAM,IAAI,iDAAuB,CAAC;SACnC;IACH,CAAC;IAED,+BAAI,GAAJ,UAAK,UAAyB,EAAE,MAAW;QACzC,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC,EAAE;YAGzB,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,uBAAU,CAAC,UAAU,CAAC,CAAC,CAAC;SACrD;aAAM;YACL,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;SAC9E;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAhBD,IAgBC;AAOD;IAAoC,sCAAa;IAI/C,4BAAY,WAA0B,EAAU,UAAkB;QAAlE,YACE,kBAAM,WAAW,CAAC,SAEnB;QAH+C,gBAAU,GAAV,UAAU,CAAQ;QAF1D,YAAM,GAAW,CAAC,CAAC;QAIzB,KAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAI,UAAU,CAAC,CAAC;;IACxC,CAAC;IAES,kCAAK,GAAf,UAAgB,KAAQ;QACtB,IAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAE5B,IAAI,KAAK,GAAG,SAAS,EAAE;YACrB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;SAC3B;aAAM;YACL,IAAM,YAAY,GAAG,KAAK,GAAG,SAAS,CAAC;YACvC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YACxB,IAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;YAEpC,IAAI,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;YAC3B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;IACH,CAAC;IACH,yBAAC;AAAD,CAAC,AAxBD,CAAoC,uBAAU,GAwB7C"}
|
||||
@@ -0,0 +1,168 @@
|
||||
import { Operator } from '../Operator';
|
||||
import { Observable } from '../Observable';
|
||||
import { Subscriber } from '../Subscriber';
|
||||
import { Subscription } from '../Subscription';
|
||||
import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
|
||||
import { map } from './map';
|
||||
import { from } from '../observable/from';
|
||||
import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';
|
||||
|
||||
/* tslint:disable:max-line-length */
|
||||
export function switchMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O): OperatorFunction<T, ObservedValueOf<O>>;
|
||||
/** @deprecated resultSelector is no longer supported, use inner map instead */
|
||||
export function switchMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
|
||||
/** @deprecated resultSelector is no longer supported, use inner map instead */
|
||||
export function switchMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;
|
||||
/* tslint:enable:max-line-length */
|
||||
|
||||
/**
|
||||
* Projects each source value to an Observable which is merged in the output
|
||||
* Observable, emitting values only from the most recently projected Observable.
|
||||
*
|
||||
* <span class="informal">Maps each value to an Observable, then flattens all of
|
||||
* these inner Observables.</span>
|
||||
*
|
||||
* 
|
||||
*
|
||||
* Returns an Observable that emits items based on applying a function that you
|
||||
* supply to each item emitted by the source Observable, where that function
|
||||
* returns an (so-called "inner") Observable. Each time it observes one of these
|
||||
* inner Observables, the output Observable begins emitting the items emitted by
|
||||
* that inner Observable. When a new inner Observable is emitted, `switchMap`
|
||||
* stops emitting items from the earlier-emitted inner Observable and begins
|
||||
* emitting items from the new one. It continues to behave like this for
|
||||
* subsequent inner Observables.
|
||||
*
|
||||
* ## Example
|
||||
* Generate new Observable according to source Observable values
|
||||
* ```typescript
|
||||
* import { of } from 'rxjs';
|
||||
* import { switchMap } from 'rxjs/operators';
|
||||
*
|
||||
* const switched = of(1, 2, 3).pipe(switchMap((x: number) => of(x, x ** 2, x ** 3)));
|
||||
* switched.subscribe(x => console.log(x));
|
||||
* // outputs
|
||||
* // 1
|
||||
* // 1
|
||||
* // 1
|
||||
* // 2
|
||||
* // 4
|
||||
* // 8
|
||||
* // ... and so on
|
||||
* ```
|
||||
*
|
||||
* Rerun an interval Observable on every click event
|
||||
* ```ts
|
||||
* import { fromEvent, interval } from 'rxjs';
|
||||
* import { switchMap } from 'rxjs/operators';
|
||||
*
|
||||
* const clicks = fromEvent(document, 'click');
|
||||
* const result = clicks.pipe(switchMap((ev) => interval(1000)));
|
||||
* result.subscribe(x => console.log(x));
|
||||
* ```
|
||||
*
|
||||
* @see {@link concatMap}
|
||||
* @see {@link exhaustMap}
|
||||
* @see {@link mergeMap}
|
||||
* @see {@link switchAll}
|
||||
* @see {@link switchMapTo}
|
||||
*
|
||||
* @param {function(value: T, ?index: number): ObservableInput} project A function
|
||||
* that, when applied to an item emitted by the source Observable, returns an
|
||||
* Observable.
|
||||
* @return {Observable} An Observable that emits the result of applying the
|
||||
* projection function (and the optional deprecated `resultSelector`) to each item
|
||||
* emitted by the source Observable and taking only the values from the most recently
|
||||
* projected inner Observable.
|
||||
* @method switchMap
|
||||
* @owner Observable
|
||||
*/
|
||||
export function switchMap<T, R, O extends ObservableInput<any>>(
|
||||
project: (value: T, index: number) => O,
|
||||
resultSelector?: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R,
|
||||
): OperatorFunction<T, ObservedValueOf<O>|R> {
|
||||
if (typeof resultSelector === 'function') {
|
||||
return (source: Observable<T>) => source.pipe(
|
||||
switchMap((a, i) => from(project(a, i)).pipe(
|
||||
map((b, ii) => resultSelector(a, b, i, ii))
|
||||
))
|
||||
);
|
||||
}
|
||||
return (source: Observable<T>) => source.lift(new SwitchMapOperator(project));
|
||||
}
|
||||
|
||||
class SwitchMapOperator<T, R> implements Operator<T, R> {
|
||||
constructor(private project: (value: T, index: number) => ObservableInput<R>) {
|
||||
}
|
||||
|
||||
call(subscriber: Subscriber<R>, source: any): any {
|
||||
return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We need this JSDoc comment for affecting ESDoc.
|
||||
* @ignore
|
||||
* @extends {Ignored}
|
||||
*/
|
||||
class SwitchMapSubscriber<T, R> extends SimpleOuterSubscriber<T, R> {
|
||||
private index = 0;
|
||||
private innerSubscription?: Subscription;
|
||||
|
||||
constructor(destination: Subscriber<R>,
|
||||
private project: (value: T, index: number) => ObservableInput<R>) {
|
||||
super(destination);
|
||||
}
|
||||
|
||||
protected _next(value: T) {
|
||||
let result: ObservableInput<R>;
|
||||
const index = this.index++;
|
||||
try {
|
||||
result = this.project(value, index);
|
||||
} catch (error) {
|
||||
this.destination.error!(error);
|
||||
return;
|
||||
}
|
||||
this._innerSub(result);
|
||||
}
|
||||
|
||||
private _innerSub(result: ObservableInput<R>) {
|
||||
const innerSubscription = this.innerSubscription;
|
||||
if (innerSubscription) {
|
||||
innerSubscription.unsubscribe();
|
||||
}
|
||||
const innerSubscriber = new SimpleInnerSubscriber(this);
|
||||
const destination = this.destination as Subscription;
|
||||
destination.add(innerSubscriber);
|
||||
this.innerSubscription = innerSubscribe(result, innerSubscriber);
|
||||
// The returned subscription will usually be the subscriber that was
|
||||
// passed. However, interop subscribers will be wrapped and for
|
||||
// unsubscriptions to chain correctly, the wrapper needs to be added, too.
|
||||
if (this.innerSubscription !== innerSubscriber) {
|
||||
destination.add(this.innerSubscription);
|
||||
}
|
||||
}
|
||||
|
||||
protected _complete(): void {
|
||||
const {innerSubscription} = this;
|
||||
if (!innerSubscription || innerSubscription.closed) {
|
||||
super._complete();
|
||||
}
|
||||
this.unsubscribe();
|
||||
}
|
||||
|
||||
protected _unsubscribe() {
|
||||
this.innerSubscription = undefined;
|
||||
}
|
||||
|
||||
notifyComplete(): void {
|
||||
this.innerSubscription = undefined;
|
||||
if (this.isStopped) {
|
||||
super._complete();
|
||||
}
|
||||
}
|
||||
|
||||
notifyNext(innerValue: R): void {
|
||||
this.destination.next!(innerValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"OuterSubscriber.js","sources":["src/OuterSubscriber.ts"],"names":[],"mappings":";;;;;AAAA,iDAA4C"}
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
const onetime = require('onetime');
|
||||
const signalExit = require('signal-exit');
|
||||
|
||||
module.exports = onetime(() => {
|
||||
signalExit(() => {
|
||||
process.stderr.write('\u001B[?25h');
|
||||
}, {alwaysLast: true});
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
const semver = require('semver')
|
||||
const { cmd, niceDate } = require('./utils')
|
||||
|
||||
const DIVIDER = '---'
|
||||
const MATCH_V = /^v\d/
|
||||
|
||||
const fetchTags = async (options, remote) => {
|
||||
const format = `%(refname:short)${DIVIDER}%(creatordate:short)`
|
||||
const tags = (await cmd(`git tag -l --sort=-creatordate --format=${format}`))
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(parseTag(options))
|
||||
.filter(isValidTag(options))
|
||||
.sort(sortTags(options))
|
||||
|
||||
const { latestVersion, unreleased, unreleasedOnly, getCompareLink } = options
|
||||
if (latestVersion || unreleased || unreleasedOnly) {
|
||||
const v = !MATCH_V.test(latestVersion) && tags.some(({ version }) => MATCH_V.test(version)) ? 'v' : ''
|
||||
const previous = tags[0]
|
||||
const compareTo = latestVersion ? `${v}${latestVersion}` : 'HEAD'
|
||||
tags.unshift({
|
||||
tag: null,
|
||||
title: latestVersion ? `${v}${latestVersion}` : 'Unreleased',
|
||||
date: new Date().toISOString(),
|
||||
diff: previous ? `${previous.tag}..` : '',
|
||||
href: previous ? getCompareLink(previous.tag, compareTo) : null
|
||||
})
|
||||
}
|
||||
|
||||
return tags
|
||||
.map(enrichTag(options))
|
||||
.slice(0, getLimit(tags, options))
|
||||
}
|
||||
|
||||
const getLimit = (tags, { unreleasedOnly, startingVersion }) => {
|
||||
if (unreleasedOnly) {
|
||||
return 1
|
||||
}
|
||||
if (startingVersion) {
|
||||
const index = tags.findIndex(({ tag }) => tag === startingVersion)
|
||||
if (index !== -1) {
|
||||
return index + 1
|
||||
}
|
||||
}
|
||||
return tags.length
|
||||
}
|
||||
|
||||
const parseTag = ({ tagPrefix }) => string => {
|
||||
const [tag, date] = string.split(DIVIDER)
|
||||
return {
|
||||
tag,
|
||||
date,
|
||||
title: tag,
|
||||
version: inferSemver(tag.replace(tagPrefix, ''))
|
||||
}
|
||||
}
|
||||
|
||||
const enrichTag = ({ getCompareLink, tagPattern }) => (t, index, tags) => {
|
||||
const previous = tags[index + 1]
|
||||
return {
|
||||
isoDate: t.date.slice(0, 10),
|
||||
niceDate: niceDate(t.date),
|
||||
diff: previous ? `${previous.tag}..${t.tag}` : t.tag,
|
||||
href: previous ? getCompareLink(previous.tag, t.tag || 'HEAD') : null,
|
||||
major: Boolean(
|
||||
previous &&
|
||||
semver.valid(t.version) &&
|
||||
semver.valid(previous.version) &&
|
||||
semver.diff(t.version, previous.version) === 'major'
|
||||
),
|
||||
...t
|
||||
}
|
||||
}
|
||||
|
||||
const isValidTag = ({ tagPattern }) => ({ tag, version }) => {
|
||||
if (tagPattern) {
|
||||
return new RegExp(tagPattern).test(tag)
|
||||
}
|
||||
return semver.valid(version)
|
||||
}
|
||||
|
||||
const sortTags = ({ tagPrefix }) => ({ version: a }, { version: b }) => {
|
||||
if (semver.valid(a) && semver.valid(b)) {
|
||||
return semver.rcompare(a, b)
|
||||
}
|
||||
return a < b ? 1 : -1
|
||||
}
|
||||
|
||||
const inferSemver = tag => {
|
||||
if (/^v?\d+$/.test(tag)) {
|
||||
// v1 becomes v1.0.0
|
||||
return `${tag}.0.0`
|
||||
}
|
||||
if (/^v?\d+\.\d+$/.test(tag)) {
|
||||
// v1.0 becomes v1.0.0
|
||||
return `${tag}.0`
|
||||
}
|
||||
return tag
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchTags
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
import 'rxjs-compat/add/operator/subscribeOn';
|
||||
Reference in New Issue
Block a user