1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const logger_1 = require("../../util/logger");
|
13 | const projectEditor_1 = require("./projectEditor");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function chainEditors(...projectEditors) {
|
20 | const asProjectEditors = projectEditors.map(projectEditor_1.toEditor);
|
21 | return (p, ctx, params) => __awaiter(this, void 0, void 0, function* () {
|
22 | try {
|
23 | let cumulativeResult = {
|
24 | target: p,
|
25 | success: true,
|
26 | edited: false,
|
27 | };
|
28 | for (const pe of asProjectEditors) {
|
29 | const lastResult = yield pe(p, ctx, params);
|
30 | cumulativeResult = combineEditResults(lastResult, cumulativeResult);
|
31 | }
|
32 | return cumulativeResult;
|
33 | }
|
34 | catch (error) {
|
35 | logger_1.logger.warn("Editor failure in editorChain: %s", error);
|
36 | return { target: p, edited: false, success: false, error };
|
37 | }
|
38 | });
|
39 | }
|
40 | exports.chainEditors = chainEditors;
|
41 | function combineEditResults(r1, r2) {
|
42 | return Object.assign(Object.assign(Object.assign({}, r1), r2), { edited: (r1.edited || r2.edited) ? true :
|
43 | (r1.edited === false && r2.edited === false) ? false : undefined, success: r1.success && r2.success });
|
44 | }
|
45 | exports.combineEditResults = combineEditResults;
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | exports.NoOpEditor = p => Promise.resolve(projectEditor_1.successfulEdit(p, false));
|
52 |
|
\ | No newline at end of file |