@microsoft/connected-workbooks 3.1.2-beta.2 → 3.2.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/main.js +357 -106
- package/dist/src/generators.js +7 -6
- package/dist/src/types.d.ts +1 -0
- package/dist/src/utils/arrayUtils.js +26 -21
- package/dist/src/utils/constants.js +20 -8
- package/dist/src/utils/documentUtils.js +92 -42
- package/dist/src/utils/gridUtils.js +23 -23
- package/dist/src/utils/htmlUtils.js +8 -8
- package/dist/src/utils/mashupDocumentParser.js +110 -67
- package/dist/src/utils/pqUtils.js +158 -65
- package/dist/src/utils/tableUtils.js +118 -74
- package/dist/src/utils/xmlInnerPartsUtils.js +213 -152
- package/dist/src/utils/xmlPartsUtils.js +116 -50
- package/dist/tests/arrayUtils.test.js +21 -21
- package/dist/tests/documentUtils.test.js +37 -8
- package/dist/tests/gridUtils.test.js +9 -9
- package/dist/tests/htmlUtils.test.js +48 -47
- package/dist/tests/mashupDocumentParser.test.js +91 -38
- package/dist/tests/mocks/PqMock.js +1 -1
- package/dist/tests/mocks/section1mSimpleQueryMock.js +5 -15
- package/dist/tests/mocks/xmlMocks.js +2 -2
- package/dist/tests/tableUtils.test.js +18 -18
- package/dist/tests/workbookQueryTemplate.test.js +127 -45
- package/dist/tests/workbookTableTemplate.test.js +104 -33
- package/dist/tests/xmlInnerPartsUtils.test.js +118 -37
- package/dist/utils/constants.js +3 -1
- package/dist/utils/pqUtils.js +63 -45
- package/dist/workbookManager.d.ts +1 -0
- package/dist/workbookManager.js +31 -9
- package/package.json +1 -1
|
@@ -10,96 +10,140 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
13
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
42
|
};
|
|
16
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
var types_1 = require("../types");
|
|
45
|
+
var constants_1 = require("./constants");
|
|
46
|
+
var documentUtils_1 = __importDefault(require("./documentUtils"));
|
|
47
|
+
var xmldom_qsa_1 = require("xmldom-qsa");
|
|
48
|
+
var updateDocProps = function (zip, docProps) {
|
|
49
|
+
if (docProps === void 0) { docProps = {}; }
|
|
50
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var _a, doc, properties, docPropsAutoUpdatedElementsArr, nowTime, docPropsModifiableElementsArr, serializer, newDoc;
|
|
52
|
+
return __generator(this, function (_b) {
|
|
53
|
+
switch (_b.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, documentUtils_1.default.getDocPropsProperties(zip)];
|
|
55
|
+
case 1:
|
|
56
|
+
_a = _b.sent(), doc = _a.doc, properties = _a.properties;
|
|
57
|
+
docPropsAutoUpdatedElementsArr = Object.keys(types_1.DocPropsAutoUpdatedElements);
|
|
58
|
+
nowTime = new Date().toISOString();
|
|
59
|
+
docPropsAutoUpdatedElementsArr.forEach(function (tag) {
|
|
60
|
+
documentUtils_1.default.createOrUpdateProperty(doc, properties, types_1.DocPropsAutoUpdatedElements[tag], nowTime);
|
|
61
|
+
});
|
|
62
|
+
docPropsModifiableElementsArr = Object.keys(types_1.DocPropsModifiableElements);
|
|
63
|
+
docPropsModifiableElementsArr
|
|
64
|
+
.map(function (key) { return ({
|
|
65
|
+
name: types_1.DocPropsModifiableElements[key],
|
|
66
|
+
value: docProps[key],
|
|
67
|
+
}); })
|
|
68
|
+
.forEach(function (kvp) {
|
|
69
|
+
documentUtils_1.default.createOrUpdateProperty(doc, properties, kvp.name, kvp.value);
|
|
70
|
+
});
|
|
71
|
+
serializer = new xmldom_qsa_1.XMLSerializer();
|
|
72
|
+
newDoc = serializer.serializeToString(doc);
|
|
73
|
+
zip.file(constants_1.docPropsCoreXmlPath, newDoc);
|
|
74
|
+
return [2 /*return*/];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
38
77
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
const clearLabelInfo = (zip) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
};
|
|
79
|
+
var clearLabelInfo = function (zip) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var relsString, parser, doc, relationships, element, serializer, newDoc;
|
|
44
81
|
var _a, _b, _c, _d;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
return __generator(this, function (_e) {
|
|
83
|
+
switch (_e.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
// remove docMetadata folder that contains only LabelInfo.xml in template file.
|
|
86
|
+
zip.remove(constants_1.docMetadataXmlPath);
|
|
87
|
+
return [4 /*yield*/, ((_a = zip.file(constants_1.relsXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
88
|
+
case 1:
|
|
89
|
+
relsString = _e.sent();
|
|
90
|
+
if (relsString === undefined) {
|
|
91
|
+
throw new Error(constants_1.relsNotFoundErr);
|
|
92
|
+
}
|
|
93
|
+
parser = new xmldom_qsa_1.DOMParser();
|
|
94
|
+
doc = parser.parseFromString(relsString, constants_1.xmlTextResultType);
|
|
95
|
+
relationships = doc.querySelector("Relationships");
|
|
96
|
+
if (relationships === null) {
|
|
97
|
+
throw new Error(constants_1.unexpectedErr);
|
|
98
|
+
}
|
|
99
|
+
element = relationships.querySelector('Relationship[Target="docMetadata/LabelInfo.xml"]');
|
|
100
|
+
if (element) {
|
|
101
|
+
relationships.removeChild(element);
|
|
102
|
+
}
|
|
103
|
+
(_b = relationships.querySelector('Relationship[Target="xl/workbook.xml"]')) === null || _b === void 0 ? void 0 : _b.setAttribute("Id", "rId1");
|
|
104
|
+
(_c = relationships.querySelector('Relationship[Target="docProps/core.xml"]')) === null || _c === void 0 ? void 0 : _c.setAttribute("Id", "rId2");
|
|
105
|
+
(_d = relationships.querySelector('Relationship[Target="docProps/app.xml"]')) === null || _d === void 0 ? void 0 : _d.setAttribute("Id", "rId3");
|
|
106
|
+
serializer = new xmldom_qsa_1.XMLSerializer();
|
|
107
|
+
newDoc = serializer.serializeToString(doc);
|
|
108
|
+
zip.file(constants_1.relsXmlPath, newDoc);
|
|
109
|
+
return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}); };
|
|
113
|
+
var updateConnections = function (connectionsXmlString, queryName, refreshOnOpen) {
|
|
70
114
|
var _a, _b, _c;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
115
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
116
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
117
|
+
var refreshOnLoadValue = refreshOnOpen ? constants_1.trueValue : constants_1.falseValue;
|
|
118
|
+
var connectionsDoc = parser.parseFromString(connectionsXmlString, constants_1.xmlTextResultType);
|
|
119
|
+
var connectionsProperties = connectionsDoc.getElementsByTagName(constants_1.element.databaseProperties);
|
|
120
|
+
var dbPr = connectionsProperties[0];
|
|
77
121
|
dbPr.setAttribute(constants_1.elementAttributes.refreshOnLoad, refreshOnLoadValue);
|
|
78
122
|
// Update query details to match queryName
|
|
79
123
|
(_a = dbPr.parentNode) === null || _a === void 0 ? void 0 : _a.setAttribute(constants_1.elementAttributes.name, constants_1.elementAttributesValues.connectionName(queryName));
|
|
80
124
|
(_b = dbPr.parentNode) === null || _b === void 0 ? void 0 : _b.setAttribute(constants_1.elementAttributes.description, constants_1.elementAttributesValues.connectionDescription(queryName));
|
|
81
125
|
dbPr.setAttribute(constants_1.elementAttributes.connection, constants_1.elementAttributesValues.connection(queryName));
|
|
82
126
|
dbPr.setAttribute(constants_1.elementAttributes.command, constants_1.elementAttributesValues.connectionCommand(queryName));
|
|
83
|
-
|
|
84
|
-
|
|
127
|
+
var connectionId = (_c = dbPr.parentNode) === null || _c === void 0 ? void 0 : _c.getAttribute(constants_1.elementAttributes.id);
|
|
128
|
+
var connectionXmlFileString = serializer.serializeToString(connectionsDoc);
|
|
85
129
|
if (connectionId === null) {
|
|
86
130
|
throw new Error(constants_1.connectionsNotFoundErr);
|
|
87
131
|
}
|
|
88
|
-
return { connectionId, connectionXmlFileString };
|
|
132
|
+
return { connectionId: connectionId, connectionXmlFileString: connectionXmlFileString };
|
|
89
133
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
134
|
+
var updateSharedStrings = function (sharedStringsXmlString, queryName) {
|
|
135
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
136
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
137
|
+
var sharedStringsDoc = parser.parseFromString(sharedStringsXmlString, constants_1.xmlTextResultType);
|
|
138
|
+
var sharedStringsTable = sharedStringsDoc.getElementsByTagName(constants_1.element.sharedStringTable)[0];
|
|
95
139
|
if (!sharedStringsTable) {
|
|
96
140
|
throw new Error(constants_1.sharedStringsNotFoundErr);
|
|
97
141
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
142
|
+
var textElementCollection = sharedStringsDoc.getElementsByTagName(constants_1.element.text);
|
|
143
|
+
var textElement = null;
|
|
144
|
+
var sharedStringIndex = textElementCollection.length;
|
|
101
145
|
if (textElementCollection && textElementCollection.length) {
|
|
102
|
-
for (
|
|
146
|
+
for (var i = 0; i < textElementCollection.length; i++) {
|
|
103
147
|
if (textElementCollection[i].textContent === queryName) {
|
|
104
148
|
textElement = textElementCollection[i];
|
|
105
149
|
sharedStringIndex = i + 1;
|
|
@@ -111,118 +155,135 @@ const updateSharedStrings = (sharedStringsXmlString, queryName) => {
|
|
|
111
155
|
if (sharedStringsDoc.documentElement.namespaceURI) {
|
|
112
156
|
textElement = sharedStringsDoc.createElementNS(sharedStringsDoc.documentElement.namespaceURI, constants_1.element.text);
|
|
113
157
|
textElement.textContent = queryName;
|
|
114
|
-
|
|
158
|
+
var siElement = sharedStringsDoc.createElementNS(sharedStringsDoc.documentElement.namespaceURI, constants_1.element.sharedStringItem);
|
|
115
159
|
siElement.appendChild(textElement);
|
|
116
160
|
sharedStringsDoc.getElementsByTagName(constants_1.element.sharedStringTable)[0].appendChild(siElement);
|
|
117
161
|
}
|
|
118
|
-
|
|
162
|
+
var value = sharedStringsTable.getAttribute(constants_1.elementAttributes.count);
|
|
119
163
|
if (value) {
|
|
120
164
|
sharedStringsTable.setAttribute(constants_1.elementAttributes.count, (parseInt(value) + 1).toString());
|
|
121
165
|
}
|
|
122
|
-
|
|
166
|
+
var uniqueValue = sharedStringsTable.getAttribute(constants_1.elementAttributes.uniqueCount);
|
|
123
167
|
if (uniqueValue) {
|
|
124
168
|
sharedStringsTable.setAttribute(constants_1.elementAttributes.uniqueCount, (parseInt(uniqueValue) + 1).toString());
|
|
125
169
|
}
|
|
126
170
|
}
|
|
127
|
-
|
|
128
|
-
return { sharedStringIndex, newSharedStrings };
|
|
171
|
+
var newSharedStrings = serializer.serializeToString(sharedStringsDoc);
|
|
172
|
+
return { sharedStringIndex: sharedStringIndex, newSharedStrings: newSharedStrings };
|
|
129
173
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
174
|
+
var updateWorksheet = function (sheetsXmlString, sharedStringIndex) {
|
|
175
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
176
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
177
|
+
var sheetsDoc = parser.parseFromString(sheetsXmlString, constants_1.xmlTextResultType);
|
|
134
178
|
sheetsDoc.getElementsByTagName(constants_1.element.cellValue)[0].innerHTML = sharedStringIndex.toString();
|
|
135
|
-
|
|
179
|
+
var newSheet = serializer.serializeToString(sheetsDoc);
|
|
136
180
|
return newSheet;
|
|
137
181
|
};
|
|
138
|
-
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return pivotCacheFile.async(constants_1.textResultType).then((pivotCacheString) => {
|
|
169
|
-
return {
|
|
170
|
-
path: relativePath,
|
|
171
|
-
pivotCacheXmlString: pivotCacheString,
|
|
172
|
-
};
|
|
182
|
+
var updatePivotTablesandQueryTables = function (zip, queryName, refreshOnOpen, connectionId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
183
|
+
var found, queryTablePromises, pivotCachePromises;
|
|
184
|
+
var _a, _b;
|
|
185
|
+
return __generator(this, function (_c) {
|
|
186
|
+
switch (_c.label) {
|
|
187
|
+
case 0:
|
|
188
|
+
found = false;
|
|
189
|
+
queryTablePromises = [];
|
|
190
|
+
(_a = zip.folder(constants_1.queryTablesPath)) === null || _a === void 0 ? void 0 : _a.forEach(function (relativePath, queryTableFile) { return __awaiter(void 0, void 0, void 0, function () {
|
|
191
|
+
return __generator(this, function (_a) {
|
|
192
|
+
queryTablePromises.push((function () {
|
|
193
|
+
return queryTableFile.async(constants_1.textResultType).then(function (queryTableString) {
|
|
194
|
+
return {
|
|
195
|
+
path: relativePath,
|
|
196
|
+
queryTableXmlString: queryTableString,
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
})());
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
});
|
|
202
|
+
}); });
|
|
203
|
+
return [4 /*yield*/, Promise.all(queryTablePromises)];
|
|
204
|
+
case 1:
|
|
205
|
+
(_c.sent()).forEach(function (_a) {
|
|
206
|
+
var path = _a.path, queryTableXmlString = _a.queryTableXmlString;
|
|
207
|
+
var _b = updateQueryTable(queryTableXmlString, connectionId, refreshOnOpen), isQueryTableUpdated = _b.isQueryTableUpdated, newQueryTable = _b.newQueryTable;
|
|
208
|
+
zip.file(constants_1.queryTablesPath + path, newQueryTable);
|
|
209
|
+
if (isQueryTableUpdated) {
|
|
210
|
+
found = true;
|
|
211
|
+
}
|
|
173
212
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
213
|
+
if (found) {
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
pivotCachePromises = [];
|
|
217
|
+
(_b = zip.folder(constants_1.pivotCachesPath)) === null || _b === void 0 ? void 0 : _b.forEach(function (relativePath, pivotCacheFile) { return __awaiter(void 0, void 0, void 0, function () {
|
|
218
|
+
return __generator(this, function (_a) {
|
|
219
|
+
if (relativePath.startsWith(constants_1.pivotCachesPathPrefix)) {
|
|
220
|
+
pivotCachePromises.push((function () {
|
|
221
|
+
return pivotCacheFile.async(constants_1.textResultType).then(function (pivotCacheString) {
|
|
222
|
+
return {
|
|
223
|
+
path: relativePath,
|
|
224
|
+
pivotCacheXmlString: pivotCacheString,
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
})());
|
|
228
|
+
}
|
|
229
|
+
return [2 /*return*/];
|
|
230
|
+
});
|
|
231
|
+
}); });
|
|
232
|
+
return [4 /*yield*/, Promise.all(pivotCachePromises)];
|
|
233
|
+
case 2:
|
|
234
|
+
(_c.sent()).forEach(function (_a) {
|
|
235
|
+
var path = _a.path, pivotCacheXmlString = _a.pivotCacheXmlString;
|
|
236
|
+
var _b = updatePivotTable(pivotCacheXmlString, connectionId, refreshOnOpen), isPivotTableUpdated = _b.isPivotTableUpdated, newPivotTable = _b.newPivotTable;
|
|
237
|
+
zip.file(constants_1.pivotCachesPath + path, newPivotTable);
|
|
238
|
+
if (isPivotTableUpdated) {
|
|
239
|
+
found = true;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
if (!found) {
|
|
243
|
+
throw new Error(constants_1.queryAndPivotTableNotFoundErr);
|
|
244
|
+
}
|
|
245
|
+
return [2 /*return*/];
|
|
182
246
|
}
|
|
183
247
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const queryTableDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
194
|
-
const queryTable = queryTableDoc.getElementsByTagName(constants_1.element.queryTable)[0];
|
|
195
|
-
let newQueryTable = constants_1.emptyValue;
|
|
248
|
+
}); };
|
|
249
|
+
var updateQueryTable = function (tableXmlString, connectionId, refreshOnOpen) {
|
|
250
|
+
var refreshOnLoadValue = refreshOnOpen ? constants_1.trueValue : constants_1.falseValue;
|
|
251
|
+
var isQueryTableUpdated = false;
|
|
252
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
253
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
254
|
+
var queryTableDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
255
|
+
var queryTable = queryTableDoc.getElementsByTagName(constants_1.element.queryTable)[0];
|
|
256
|
+
var newQueryTable = constants_1.emptyValue;
|
|
196
257
|
if (queryTable.getAttribute(constants_1.elementAttributes.connectionId) == connectionId) {
|
|
197
258
|
queryTable.setAttribute(constants_1.elementAttributes.refreshOnLoad, refreshOnLoadValue);
|
|
198
259
|
newQueryTable = serializer.serializeToString(queryTableDoc);
|
|
199
260
|
isQueryTableUpdated = true;
|
|
200
261
|
}
|
|
201
|
-
return { isQueryTableUpdated, newQueryTable };
|
|
262
|
+
return { isQueryTableUpdated: isQueryTableUpdated, newQueryTable: newQueryTable };
|
|
202
263
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
264
|
+
var updatePivotTable = function (tableXmlString, connectionId, refreshOnOpen) {
|
|
265
|
+
var refreshOnLoadValue = refreshOnOpen ? constants_1.trueValue : constants_1.falseValue;
|
|
266
|
+
var isPivotTableUpdated = false;
|
|
267
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
268
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
269
|
+
var pivotCacheDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
270
|
+
var cacheSource = pivotCacheDoc.getElementsByTagName(constants_1.element.cacheSource)[0];
|
|
271
|
+
var newPivotTable = constants_1.emptyValue;
|
|
211
272
|
if (cacheSource.getAttribute(constants_1.elementAttributes.connectionId) == connectionId) {
|
|
212
273
|
cacheSource = cacheSource.parentElement;
|
|
213
274
|
cacheSource.setAttribute(constants_1.elementAttributes.refreshOnLoad, refreshOnLoadValue);
|
|
214
275
|
newPivotTable = serializer.serializeToString(pivotCacheDoc);
|
|
215
276
|
isPivotTableUpdated = true;
|
|
216
277
|
}
|
|
217
|
-
return { isPivotTableUpdated, newPivotTable };
|
|
278
|
+
return { isPivotTableUpdated: isPivotTableUpdated, newPivotTable: newPivotTable };
|
|
218
279
|
};
|
|
219
280
|
exports.default = {
|
|
220
|
-
updateDocProps,
|
|
221
|
-
clearLabelInfo,
|
|
222
|
-
updateConnections,
|
|
223
|
-
updateSharedStrings,
|
|
224
|
-
updateWorksheet,
|
|
225
|
-
updatePivotTablesandQueryTables,
|
|
226
|
-
updateQueryTable,
|
|
227
|
-
updatePivotTable,
|
|
281
|
+
updateDocProps: updateDocProps,
|
|
282
|
+
clearLabelInfo: clearLabelInfo,
|
|
283
|
+
updateConnections: updateConnections,
|
|
284
|
+
updateSharedStrings: updateSharedStrings,
|
|
285
|
+
updateWorksheet: updateWorksheet,
|
|
286
|
+
updatePivotTablesandQueryTables: updatePivotTablesandQueryTables,
|
|
287
|
+
updateQueryTable: updateQueryTable,
|
|
288
|
+
updatePivotTable: updatePivotTable,
|
|
228
289
|
};
|
|
@@ -10,59 +10,125 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
13
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
42
|
};
|
|
16
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
44
|
+
var constants_1 = require("./constants");
|
|
45
|
+
var mashupDocumentParser_1 = require("./mashupDocumentParser");
|
|
46
|
+
var pqUtils_1 = __importDefault(require("./pqUtils"));
|
|
47
|
+
var xmlInnerPartsUtils_1 = __importDefault(require("./xmlInnerPartsUtils"));
|
|
48
|
+
var tableUtils_1 = __importDefault(require("./tableUtils"));
|
|
49
|
+
var updateWorkbookDataAndConfigurations = function (zip, fileConfigs, tableData, updateQueryTable) {
|
|
50
|
+
if (updateQueryTable === void 0) { updateQueryTable = false; }
|
|
51
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, xmlInnerPartsUtils_1.default.updateDocProps(zip, fileConfigs === null || fileConfigs === void 0 ? void 0 : fileConfigs.docProps)];
|
|
55
|
+
case 1:
|
|
56
|
+
_a.sent();
|
|
57
|
+
if (!((fileConfigs === null || fileConfigs === void 0 ? void 0 : fileConfigs.templateFile) === undefined)) return [3 /*break*/, 3];
|
|
58
|
+
// If we are using our base template, we need to clear label info
|
|
59
|
+
return [4 /*yield*/, xmlInnerPartsUtils_1.default.clearLabelInfo(zip)];
|
|
60
|
+
case 2:
|
|
61
|
+
// If we are using our base template, we need to clear label info
|
|
62
|
+
_a.sent();
|
|
63
|
+
_a.label = 3;
|
|
64
|
+
case 3: return [4 /*yield*/, tableUtils_1.default.updateTableInitialDataIfNeeded(zip, tableData, updateQueryTable)];
|
|
65
|
+
case 4:
|
|
66
|
+
_a.sent();
|
|
67
|
+
return [2 /*return*/];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
var updateWorkbookPowerQueryDocument = function (zip, queryName, queryMashupDoc) { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
|
+
var old_base64, new_base64;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, pqUtils_1.default.getBase64(zip)];
|
|
77
|
+
case 1:
|
|
78
|
+
old_base64 = _a.sent();
|
|
79
|
+
if (!old_base64) {
|
|
80
|
+
throw new Error(constants_1.base64NotFoundErr);
|
|
81
|
+
}
|
|
82
|
+
return [4 /*yield*/, (0, mashupDocumentParser_1.replaceSingleQuery)(old_base64, queryName, queryMashupDoc)];
|
|
83
|
+
case 2:
|
|
84
|
+
new_base64 = _a.sent();
|
|
85
|
+
return [4 /*yield*/, pqUtils_1.default.setBase64(zip, new_base64)];
|
|
86
|
+
case 3:
|
|
87
|
+
_a.sent();
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); };
|
|
92
|
+
var updateWorkbookSingleQueryAttributes = function (zip, queryName, refreshOnOpen) { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
var connectionsXmlString, _a, connectionId, connectionXmlFileString, sharedStringsXmlString, _b, sharedStringIndex, newSharedStrings, sheetsXmlString, worksheetString;
|
|
94
|
+
var _c, _d, _e;
|
|
95
|
+
return __generator(this, function (_f) {
|
|
96
|
+
switch (_f.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, ((_c = zip.file(constants_1.connectionsXmlPath)) === null || _c === void 0 ? void 0 : _c.async(constants_1.textResultType))];
|
|
98
|
+
case 1:
|
|
99
|
+
connectionsXmlString = _f.sent();
|
|
100
|
+
if (connectionsXmlString === undefined) {
|
|
101
|
+
throw new Error(constants_1.connectionsNotFoundErr);
|
|
102
|
+
}
|
|
103
|
+
_a = xmlInnerPartsUtils_1.default.updateConnections(connectionsXmlString, queryName, refreshOnOpen), connectionId = _a.connectionId, connectionXmlFileString = _a.connectionXmlFileString;
|
|
104
|
+
zip.file(constants_1.connectionsXmlPath, connectionXmlFileString);
|
|
105
|
+
return [4 /*yield*/, ((_d = zip.file(constants_1.sharedStringsXmlPath)) === null || _d === void 0 ? void 0 : _d.async(constants_1.textResultType))];
|
|
106
|
+
case 2:
|
|
107
|
+
sharedStringsXmlString = _f.sent();
|
|
108
|
+
if (sharedStringsXmlString === undefined) {
|
|
109
|
+
throw new Error(constants_1.sharedStringsNotFoundErr);
|
|
110
|
+
}
|
|
111
|
+
_b = xmlInnerPartsUtils_1.default.updateSharedStrings(sharedStringsXmlString, queryName), sharedStringIndex = _b.sharedStringIndex, newSharedStrings = _b.newSharedStrings;
|
|
112
|
+
zip.file(constants_1.sharedStringsXmlPath, newSharedStrings);
|
|
113
|
+
return [4 /*yield*/, ((_e = zip.file(constants_1.sheetsXmlPath)) === null || _e === void 0 ? void 0 : _e.async(constants_1.textResultType))];
|
|
114
|
+
case 3:
|
|
115
|
+
sheetsXmlString = _f.sent();
|
|
116
|
+
if (sheetsXmlString === undefined) {
|
|
117
|
+
throw new Error(constants_1.sheetsNotFoundErr);
|
|
118
|
+
}
|
|
119
|
+
worksheetString = xmlInnerPartsUtils_1.default.updateWorksheet(sheetsXmlString, sharedStringIndex.toString());
|
|
120
|
+
zip.file(constants_1.sheetsXmlPath, worksheetString);
|
|
121
|
+
// Update tables
|
|
122
|
+
return [4 /*yield*/, xmlInnerPartsUtils_1.default.updatePivotTablesandQueryTables(zip, queryName, refreshOnOpen, connectionId)];
|
|
123
|
+
case 4:
|
|
124
|
+
// Update tables
|
|
125
|
+
_f.sent();
|
|
126
|
+
return [2 /*return*/];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}); };
|
|
64
130
|
exports.default = {
|
|
65
|
-
updateWorkbookDataAndConfigurations,
|
|
66
|
-
updateWorkbookPowerQueryDocument,
|
|
67
|
-
updateWorkbookSingleQueryAttributes,
|
|
131
|
+
updateWorkbookDataAndConfigurations: updateWorkbookDataAndConfigurations,
|
|
132
|
+
updateWorkbookPowerQueryDocument: updateWorkbookPowerQueryDocument,
|
|
133
|
+
updateWorkbookSingleQueryAttributes: updateWorkbookSingleQueryAttributes,
|
|
68
134
|
};
|