@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.
@@ -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
- const xmldom_1 = require("xmldom");
18
- const types_1 = require("../types");
19
- const constants_1 = require("./constants");
20
- const documentUtils_1 = __importDefault(require("./documentUtils"));
21
- const updateDocProps = (zip, docProps = {}) => __awaiter(void 0, void 0, void 0, function* () {
22
- const { doc, properties } = yield documentUtils_1.default.getDocPropsProperties(zip);
23
- //set auto updated elements
24
- const docPropsAutoUpdatedElementsArr = Object.keys(types_1.DocPropsAutoUpdatedElements);
25
- const nowTime = new Date().toISOString();
26
- docPropsAutoUpdatedElementsArr.forEach((tag) => {
27
- documentUtils_1.default.createOrUpdateProperty(doc, properties, types_1.DocPropsAutoUpdatedElements[tag], nowTime);
28
- });
29
- //set modifiable elements
30
- const docPropsModifiableElementsArr = Object.keys(types_1.DocPropsModifiableElements);
31
- docPropsModifiableElementsArr
32
- .map((key) => ({
33
- name: types_1.DocPropsModifiableElements[key],
34
- value: docProps[key],
35
- }))
36
- .forEach((kvp) => {
37
- documentUtils_1.default.createOrUpdateProperty(doc, properties, kvp.name, kvp.value);
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
- const serializer = new xmldom_1.XMLSerializer();
40
- const newDoc = serializer.serializeToString(doc);
41
- zip.file(constants_1.docPropsCoreXmlPath, newDoc);
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
- // remove docMetadata folder that contains only LabelInfo.xml in template file.
46
- zip.remove(constants_1.docMetadataXmlPath);
47
- // fix rels
48
- const relsString = yield ((_a = zip.file(constants_1.relsXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType));
49
- if (relsString === undefined) {
50
- throw new Error(constants_1.relsNotFoundErr);
51
- }
52
- const parser = new xmldom_1.DOMParser();
53
- const doc = parser.parseFromString(relsString, constants_1.xmlTextResultType);
54
- const relationships = doc.querySelector("Relationships");
55
- if (relationships === null) {
56
- throw new Error(constants_1.unexpectedErr);
57
- }
58
- const element = relationships.querySelector('Relationship[Target="docMetadata/LabelInfo.xml"]');
59
- if (element) {
60
- relationships.removeChild(element);
61
- }
62
- (_b = relationships.querySelector('Relationship[Target="xl/workbook.xml"]')) === null || _b === void 0 ? void 0 : _b.setAttribute("Id", "rId1");
63
- (_c = relationships.querySelector('Relationship[Target="docProps/core.xml"]')) === null || _c === void 0 ? void 0 : _c.setAttribute("Id", "rId2");
64
- (_d = relationships.querySelector('Relationship[Target="docProps/app.xml"]')) === null || _d === void 0 ? void 0 : _d.setAttribute("Id", "rId3");
65
- const serializer = new xmldom_1.XMLSerializer();
66
- const newDoc = serializer.serializeToString(doc);
67
- zip.file(constants_1.relsXmlPath, newDoc);
68
- });
69
- const updateConnections = (connectionsXmlString, queryName, refreshOnOpen) => {
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
- const parser = new xmldom_1.DOMParser();
72
- const serializer = new xmldom_1.XMLSerializer();
73
- const refreshOnLoadValue = refreshOnOpen ? constants_1.trueValue : constants_1.falseValue;
74
- const connectionsDoc = parser.parseFromString(connectionsXmlString, constants_1.xmlTextResultType);
75
- const connectionsProperties = connectionsDoc.getElementsByTagName(constants_1.element.databaseProperties);
76
- const dbPr = connectionsProperties[0];
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
- const connectionId = (_c = dbPr.parentNode) === null || _c === void 0 ? void 0 : _c.getAttribute(constants_1.elementAttributes.id);
84
- const connectionXmlFileString = serializer.serializeToString(connectionsDoc);
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
- const updateSharedStrings = (sharedStringsXmlString, queryName) => {
91
- const parser = new xmldom_1.DOMParser();
92
- const serializer = new xmldom_1.XMLSerializer();
93
- const sharedStringsDoc = parser.parseFromString(sharedStringsXmlString, constants_1.xmlTextResultType);
94
- const sharedStringsTable = sharedStringsDoc.getElementsByTagName(constants_1.element.sharedStringTable)[0];
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
- const textElementCollection = sharedStringsDoc.getElementsByTagName(constants_1.element.text);
99
- let textElement = null;
100
- let sharedStringIndex = textElementCollection.length;
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 (let i = 0; i < textElementCollection.length; i++) {
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
- const siElement = sharedStringsDoc.createElementNS(sharedStringsDoc.documentElement.namespaceURI, constants_1.element.sharedStringItem);
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
- const value = sharedStringsTable.getAttribute(constants_1.elementAttributes.count);
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
- const uniqueValue = sharedStringsTable.getAttribute(constants_1.elementAttributes.uniqueCount);
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
- const newSharedStrings = serializer.serializeToString(sharedStringsDoc);
128
- return { sharedStringIndex, newSharedStrings };
171
+ var newSharedStrings = serializer.serializeToString(sharedStringsDoc);
172
+ return { sharedStringIndex: sharedStringIndex, newSharedStrings: newSharedStrings };
129
173
  };
130
- const updateWorksheet = (sheetsXmlString, sharedStringIndex) => {
131
- const parser = new xmldom_1.DOMParser();
132
- const serializer = new xmldom_1.XMLSerializer();
133
- const sheetsDoc = parser.parseFromString(sheetsXmlString, constants_1.xmlTextResultType);
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
- const newSheet = serializer.serializeToString(sheetsDoc);
179
+ var newSheet = serializer.serializeToString(sheetsDoc);
136
180
  return newSheet;
137
181
  };
138
- const updatePivotTablesandQueryTables = (zip, queryName, refreshOnOpen, connectionId) => __awaiter(void 0, void 0, void 0, function* () {
139
- var _e, _f;
140
- // Find Query Table
141
- let found = false;
142
- const queryTablePromises = [];
143
- (_e = zip.folder(constants_1.queryTablesPath)) === null || _e === void 0 ? void 0 : _e.forEach((relativePath, queryTableFile) => __awaiter(void 0, void 0, void 0, function* () {
144
- queryTablePromises.push((() => {
145
- return queryTableFile.async(constants_1.textResultType).then((queryTableString) => {
146
- return {
147
- path: relativePath,
148
- queryTableXmlString: queryTableString,
149
- };
150
- });
151
- })());
152
- }));
153
- (yield Promise.all(queryTablePromises)).forEach(({ path, queryTableXmlString }) => {
154
- const { isQueryTableUpdated, newQueryTable } = updateQueryTable(queryTableXmlString, connectionId, refreshOnOpen);
155
- zip.file(constants_1.queryTablesPath + path, newQueryTable);
156
- if (isQueryTableUpdated) {
157
- found = true;
158
- }
159
- });
160
- if (found) {
161
- return;
162
- }
163
- // Find Pivot Table
164
- const pivotCachePromises = [];
165
- (_f = zip.folder(constants_1.pivotCachesPath)) === null || _f === void 0 ? void 0 : _f.forEach((relativePath, pivotCacheFile) => __awaiter(void 0, void 0, void 0, function* () {
166
- if (relativePath.startsWith(constants_1.pivotCachesPathPrefix)) {
167
- pivotCachePromises.push((() => {
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
- (yield Promise.all(pivotCachePromises)).forEach(({ path, pivotCacheXmlString }) => {
178
- const { isPivotTableUpdated, newPivotTable } = updatePivotTable(pivotCacheXmlString, connectionId, refreshOnOpen);
179
- zip.file(constants_1.pivotCachesPath + path, newPivotTable);
180
- if (isPivotTableUpdated) {
181
- found = true;
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
- if (!found) {
185
- throw new Error(constants_1.queryAndPivotTableNotFoundErr);
186
- }
187
- });
188
- const updateQueryTable = (tableXmlString, connectionId, refreshOnOpen) => {
189
- const refreshOnLoadValue = refreshOnOpen ? constants_1.trueValue : constants_1.falseValue;
190
- let isQueryTableUpdated = false;
191
- const parser = new xmldom_1.DOMParser();
192
- const serializer = new xmldom_1.XMLSerializer();
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
- const updatePivotTable = (tableXmlString, connectionId, refreshOnOpen) => {
204
- const refreshOnLoadValue = refreshOnOpen ? constants_1.trueValue : constants_1.falseValue;
205
- let isPivotTableUpdated = false;
206
- const parser = new xmldom_1.DOMParser();
207
- const serializer = new xmldom_1.XMLSerializer();
208
- const pivotCacheDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
209
- let cacheSource = pivotCacheDoc.getElementsByTagName(constants_1.element.cacheSource)[0];
210
- let newPivotTable = constants_1.emptyValue;
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
- const constants_1 = require("./constants");
18
- const mashupDocumentParser_1 = require("./mashupDocumentParser");
19
- const pqUtils_1 = __importDefault(require("./pqUtils"));
20
- const xmlInnerPartsUtils_1 = __importDefault(require("./xmlInnerPartsUtils"));
21
- const tableUtils_1 = __importDefault(require("./tableUtils"));
22
- const updateWorkbookDataAndConfigurations = (zip, fileConfigs, tableData, updateQueryTable = false) => __awaiter(void 0, void 0, void 0, function* () {
23
- yield xmlInnerPartsUtils_1.default.updateDocProps(zip, fileConfigs === null || fileConfigs === void 0 ? void 0 : fileConfigs.docProps);
24
- if ((fileConfigs === null || fileConfigs === void 0 ? void 0 : fileConfigs.templateFile) === undefined) {
25
- // If we are using our base template, we need to clear label info
26
- yield xmlInnerPartsUtils_1.default.clearLabelInfo(zip);
27
- }
28
- yield tableUtils_1.default.updateTableInitialDataIfNeeded(zip, tableData, updateQueryTable);
29
- });
30
- const updateWorkbookPowerQueryDocument = (zip, queryName, queryMashupDoc) => __awaiter(void 0, void 0, void 0, function* () {
31
- const old_base64 = yield pqUtils_1.default.getBase64(zip);
32
- if (!old_base64) {
33
- throw new Error(constants_1.base64NotFoundErr);
34
- }
35
- const new_base64 = yield (0, mashupDocumentParser_1.replaceSingleQuery)(old_base64, queryName, queryMashupDoc);
36
- yield pqUtils_1.default.setBase64(zip, new_base64);
37
- });
38
- const updateWorkbookSingleQueryAttributes = (zip, queryName, refreshOnOpen) => __awaiter(void 0, void 0, void 0, function* () {
39
- var _a, _b, _c;
40
- // Update connections
41
- const connectionsXmlString = yield ((_a = zip.file(constants_1.connectionsXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType));
42
- if (connectionsXmlString === undefined) {
43
- throw new Error(constants_1.connectionsNotFoundErr);
44
- }
45
- const { connectionId, connectionXmlFileString } = xmlInnerPartsUtils_1.default.updateConnections(connectionsXmlString, queryName, refreshOnOpen);
46
- zip.file(constants_1.connectionsXmlPath, connectionXmlFileString);
47
- // Update sharedStrings
48
- const sharedStringsXmlString = yield ((_b = zip.file(constants_1.sharedStringsXmlPath)) === null || _b === void 0 ? void 0 : _b.async(constants_1.textResultType));
49
- if (sharedStringsXmlString === undefined) {
50
- throw new Error(constants_1.sharedStringsNotFoundErr);
51
- }
52
- const { sharedStringIndex, newSharedStrings } = xmlInnerPartsUtils_1.default.updateSharedStrings(sharedStringsXmlString, queryName);
53
- zip.file(constants_1.sharedStringsXmlPath, newSharedStrings);
54
- // Update sheet
55
- const sheetsXmlString = yield ((_c = zip.file(constants_1.sheetsXmlPath)) === null || _c === void 0 ? void 0 : _c.async(constants_1.textResultType));
56
- if (sheetsXmlString === undefined) {
57
- throw new Error(constants_1.sheetsNotFoundErr);
58
- }
59
- const worksheetString = xmlInnerPartsUtils_1.default.updateWorksheet(sheetsXmlString, sharedStringIndex.toString());
60
- zip.file(constants_1.sheetsXmlPath, worksheetString);
61
- // Update tables
62
- yield xmlInnerPartsUtils_1.default.updatePivotTablesandQueryTables(zip, queryName, refreshOnOpen, connectionId);
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
  };