150 lines
No EOL
18 KiB
JavaScript
150 lines
No EOL
18 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var bluebird_1 = __importDefault(require("bluebird"));
|
|
var Result = /** @class */ (function () {
|
|
function Result(converter) {
|
|
this.converter = converter;
|
|
this.finalResult = [];
|
|
}
|
|
Object.defineProperty(Result.prototype, "needEmitLine", {
|
|
get: function () {
|
|
return !!this.converter.parseRuntime.subscribe && !!this.converter.parseRuntime.subscribe.onNext || this.needPushDownstream;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(Result.prototype, "needPushDownstream", {
|
|
get: function () {
|
|
if (this._needPushDownstream === undefined) {
|
|
this._needPushDownstream = this.converter.listeners("data").length > 0 || this.converter.listeners("readable").length > 0;
|
|
}
|
|
return this._needPushDownstream;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(Result.prototype, "needEmitAll", {
|
|
get: function () {
|
|
return !!this.converter.parseRuntime.then;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Result.prototype.processResult = function (resultLines) {
|
|
var _this = this;
|
|
var startPos = this.converter.parseRuntime.parsedLineNumber;
|
|
// let prom: P<any>;
|
|
return new bluebird_1.default(function (resolve, reject) {
|
|
if (_this.needEmitLine) {
|
|
processLineByLine(resultLines, _this.converter, 0, _this.needPushDownstream, function (err) {
|
|
if (err) {
|
|
reject(err);
|
|
}
|
|
else {
|
|
_this.appendFinalResult(resultLines);
|
|
resolve();
|
|
}
|
|
});
|
|
// resolve();
|
|
}
|
|
else {
|
|
_this.appendFinalResult(resultLines);
|
|
resolve();
|
|
}
|
|
});
|
|
};
|
|
Result.prototype.appendFinalResult = function (lines) {
|
|
if (this.needEmitAll) {
|
|
this.finalResult = this.finalResult.concat(lines);
|
|
}
|
|
this.converter.parseRuntime.parsedLineNumber += lines.length;
|
|
};
|
|
Result.prototype.processError = function (err) {
|
|
if (this.converter.parseRuntime.subscribe && this.converter.parseRuntime.subscribe.onError) {
|
|
this.converter.parseRuntime.subscribe.onError(err);
|
|
}
|
|
if (this.converter.parseRuntime.then && this.converter.parseRuntime.then.onrejected) {
|
|
this.converter.parseRuntime.then.onrejected(err);
|
|
}
|
|
};
|
|
Result.prototype.endProcess = function () {
|
|
if (this.needEmitAll) {
|
|
if (this.converter.parseRuntime.then && this.converter.parseRuntime.then.onfulfilled) {
|
|
this.converter.parseRuntime.then.onfulfilled(this.finalResult);
|
|
}
|
|
}
|
|
if (this.converter.parseRuntime.subscribe && this.converter.parseRuntime.subscribe.onCompleted) {
|
|
this.converter.parseRuntime.subscribe.onCompleted();
|
|
}
|
|
};
|
|
return Result;
|
|
}());
|
|
exports.Result = Result;
|
|
function processLineByLine(lines, conv, offset, needPushDownstream, cb) {
|
|
if (offset >= lines.length) {
|
|
cb();
|
|
}
|
|
else {
|
|
if (conv.parseRuntime.subscribe && conv.parseRuntime.subscribe.onNext) {
|
|
var hook_1 = conv.parseRuntime.subscribe.onNext;
|
|
var nextLine_1 = lines[offset];
|
|
var res = hook_1(nextLine_1, conv.parseRuntime.parsedLineNumber + offset);
|
|
offset++;
|
|
// if (isAsync === undefined) {
|
|
if (res && res.then) {
|
|
res.then(function () {
|
|
processRecursive(lines, hook_1, conv, offset, needPushDownstream, cb, nextLine_1);
|
|
}, cb);
|
|
}
|
|
else {
|
|
// processRecursive(lines, hook, conv, offset, needPushDownstream, cb, nextLine, false);
|
|
if (needPushDownstream) {
|
|
pushDownstream(conv, nextLine_1);
|
|
}
|
|
while (offset < lines.length) {
|
|
var line = lines[offset];
|
|
hook_1(line, conv.parseRuntime.parsedLineNumber + offset);
|
|
offset++;
|
|
if (needPushDownstream) {
|
|
pushDownstream(conv, line);
|
|
}
|
|
}
|
|
cb();
|
|
}
|
|
// } else if (isAsync === true) {
|
|
// (res as PromiseLike<void>).then(function () {
|
|
// processRecursive(lines, hook, conv, offset, needPushDownstream, cb, nextLine, true);
|
|
// }, cb);
|
|
// } else if (isAsync === false) {
|
|
// processRecursive(lines, hook, conv, offset, needPushDownstream, cb, nextLine, false);
|
|
// }
|
|
}
|
|
else {
|
|
if (needPushDownstream) {
|
|
while (offset < lines.length) {
|
|
var line = lines[offset++];
|
|
pushDownstream(conv, line);
|
|
}
|
|
}
|
|
cb();
|
|
}
|
|
}
|
|
}
|
|
function processRecursive(lines, hook, conv, offset, needPushDownstream, cb, res) {
|
|
if (needPushDownstream) {
|
|
pushDownstream(conv, res);
|
|
}
|
|
processLineByLine(lines, conv, offset, needPushDownstream, cb);
|
|
}
|
|
function pushDownstream(conv, res) {
|
|
if (typeof res === "object" && !conv.options.objectMode) {
|
|
conv.push(JSON.stringify(res) + "\n", "utf8");
|
|
}
|
|
else {
|
|
conv.push(res);
|
|
}
|
|
}
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiL1VzZXJzL2t4aWFuZy93b3JrL3Byb2plY3RzL2NzdjJqc29uL3NyYy9SZXN1bHQudHMiLCJzb3VyY2VzIjpbIi9Vc2Vycy9reGlhbmcvd29yay9wcm9qZWN0cy9jc3YyanNvbi9zcmMvUmVzdWx0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBRUEsc0RBQXlCO0FBR3pCO0lBZUUsZ0JBQW9CLFNBQW9CO1FBQXBCLGNBQVMsR0FBVCxTQUFTLENBQVc7UUFEaEMsZ0JBQVcsR0FBVSxFQUFFLENBQUM7SUFDWSxDQUFDO0lBZDdDLHNCQUFZLGdDQUFZO2FBQXhCO1lBQ0UsT0FBTyxDQUFDLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxZQUFZLENBQUMsU0FBUyxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLFlBQVksQ0FBQyxT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9yKHByaXZhdGUgY29udmVydGVyOiBDb252ZXJ0ZXIpIHsgfVxuICBwcm9jZXNzUmVzdWx0KHJlc3VsdExpbmVzOiBQcm9jZXNzTGluZVJlc3VsdFtdKTogUDxhbnk+IHtcbiAgICBjb25zdCBzdGFydFBvcyA9IHRoaXMuY29udmVydGVyLnBhcnNlUnVudGltZS5wYXJzZWRMaW5lTnVtYmVyO1xuICAgIC8vIGxldCBwcm9tOiBQPGFueT47XG4gICAgcmV0dXJuIG5ldyBQKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIGlmICh0aGlzLm5lZWRFbWl0TGluZSkge1xuICAgICAgICBwcm9jZXNzTGluZUJ5TGluZShcbiAgICAgICAgICByZXN1bHRMaW5lcyxcbiAgICAgICAgICB0aGlzLmNvbnZlcnRlcixcbiAgICAgICAgICAwLFxuICAgICAgICAgIHRoaXMubmVlZFB1c2hEb3duc3RyZWFtLFxuICAgICAgICAgIChlcnIpID0+IHtcbiAgICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgICAgcmVqZWN0KGVycik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICB0aGlzLmFwcGVuZEZpbmFsUmVzdWx0KHJlc3VsdExpbmVzKTtcbiAgICAgICAgICAgICAgcmVzb2x2ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0sXG4gICAgICAgIClcbiAgICAgICAgLy8gcmVzb2x2ZSgpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdGhpcy5hcHBlbmRGaW5hbFJlc3VsdChyZXN1bHRMaW5lcyk7XG4gICAgICAgIHJlc29sdmUoKTtcbiAgICAgIH1cbiAgICB9KVxuICB9XG4gIGFwcGVuZEZpbmFsUmVzdWx0KGxpbmVzOiBhbnlbXSkge1xuICAgIGlmICh0aGlzLm5lZWRFbWl0QWxsKSB7XG4gICAgICB0aGlzLmZpbmFsUmVzdWx0ID0gdGhpcy5maW5hbFJlc3VsdC5jb25j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