UNPKG

@tsdi/pack

Version:

@tsdi/pack is simple build tasks, base on AOP, Ioc container, via @tsdi. dev build pack activities.

91 lines (89 loc) 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StreamActivity = void 0; var tslib_1 = require("tslib"); var ioc_1 = require("@tsdi/ioc"); var components_1 = require("@tsdi/components"); var activities_1 = require("@tsdi/activities"); var TransformActivity_1 = require("./TransformActivity"); var StreamActivity = /** @class */ (function (_super) { tslib_1.__extends(StreamActivity, _super); function StreamActivity() { return _super !== null && _super.apply(this, arguments) || this; } StreamActivity.prototype.execute = function (ctx) { return tslib_1.__awaiter(this, void 0, void 0, function () { var pipes; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, ctx.resolveExpression(this.pipes)]; case 1: pipes = _a.sent(); if (ioc_1.isArray(pipes)) { pipes = pipes.filter(function (p) { return p; }); } if (!(pipes && pipes.length)) return [3 /*break*/, 3]; return [4 /*yield*/, this.pipeStreams.apply(this, tslib_1.__spreadArrays([ctx, ctx.getData()], pipes))]; case 2: return [2 /*return*/, _a.sent()]; case 3: return [2 /*return*/]; } }); }); }; /** * stream pipe transform. * * @protected * @param {NodeActivityContext} ctx * @param {ITransform} stream * @param {...Expression<ITransform>[]} pipes * @returns {Promise<ITransform>} * @memberof StreamActivity */ StreamActivity.prototype.pipeStreams = function (ctx, stream) { var pipes = []; for (var _i = 2; _i < arguments.length; _i++) { pipes[_i - 2] = arguments[_i]; } return tslib_1.__awaiter(this, void 0, void 0, function () { var pstream; var _this = this; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (pipes.length < 1) { return [2 /*return*/, stream]; } if (!(pipes.length === 1)) return [3 /*break*/, 2]; return [4 /*yield*/, this.pipeStream(ctx, stream, pipes[0])]; case 1: return [2 /*return*/, _a.sent()]; case 2: pstream = Promise.resolve(stream); pipes.forEach(function (transform) { if (transform) { pstream = pstream .then(function (stm) { return _this.pipeStream(ctx, stm, transform); }); } }); return [4 /*yield*/, pstream]; case 3: return [2 /*return*/, _a.sent()]; } }); }); }; StreamActivityAnn = function () { return { "name": "StreamActivity", "params": { "execute": ["ctx"], "pipeStreams": ["ctx", "stream", "pipes"] } }; }; tslib_1.__decorate([ components_1.Input('pipes'), tslib_1.__metadata("design:type", Array) ], StreamActivity.prototype, "pipes", void 0); StreamActivity = tslib_1.__decorate([ activities_1.Task('pipes, [pipes]') ], StreamActivity); return StreamActivity; }(TransformActivity_1.TransformActivity)); exports.StreamActivity = StreamActivity; //# sourceMappingURL=../sourcemaps/transforms/StreamActivity.js.map