@microsoft/connected-workbooks 2.1.16-beta → 2.1.24-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 +79 -15
- package/dist/GridParser.js +40 -47
- package/dist/index.d.ts +6 -3
- package/dist/index.js +26 -6
- package/dist/types.d.ts +6 -10
- package/dist/types.js +0 -1
- package/dist/utils/constants.js +4 -1
- package/dist/utils/documentUtils.js +5 -8
- package/dist/utils/htmlUtils.js +2 -8
- package/dist/utils/mashupDocumentParser.js +118 -121
- package/dist/utils/pqUtils.js +5 -9
- package/dist/utils/tableUtils.js +17 -19
- package/dist/utils/xmlPartsUtils.js +2 -2
- package/dist/workbookManager.d.ts +5 -8
- package/dist/workbookManager.js +20 -23
- package/dist/workbookTemplate.js +3 -5
- package/package.json +20 -6
- package/dist/GridParser.d.ts +0 -6
- package/dist/TableDataParserFactory.d.ts +0 -4
- package/dist/TableDataParserFactory.js +0 -15
- package/dist/constants.d.ts +0 -121
- package/dist/constants.js +0 -131
- package/dist/generators.d.ts +0 -3
- package/dist/mashupDocumentParser.d.ts +0 -7
- package/dist/mashupDocumentParser.js +0 -169
- package/dist/utils/arrayUtils.d.ts +0 -16
- package/dist/utils/constants.d.ts +0 -121
- package/dist/utils/documentUtils.d.ts +0 -15
- package/dist/utils/htmlUtils.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/mashupDocumentParser.d.ts +0 -7
- package/dist/utils/pqUtils.d.ts +0 -15
- package/dist/utils/tableUtils.d.ts +0 -10
- package/dist/utils/xmlInnerPartsUtils.d.ts +0 -24
- package/dist/utils/xmlPartsUtils.d.ts +0 -8
- package/dist/workbookTemplate.d.ts +0 -4
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
5
|
if (k2 === undefined) k2 = k;
|
|
6
|
-
Object.
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
7
11
|
}) : (function(o, m, k, k2) {
|
|
8
12
|
if (k2 === undefined) k2 = k;
|
|
9
13
|
o[k2] = m[k];
|
|
@@ -33,134 +37,127 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
38
|
};
|
|
35
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.replaceSingleQuery = void 0;
|
|
36
41
|
const base64 = __importStar(require("base64-js"));
|
|
37
42
|
const jszip_1 = __importDefault(require("jszip"));
|
|
38
43
|
const constants_1 = require("./constants");
|
|
39
44
|
const _1 = require(".");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const replaceSingleQuery = (base64Str, queryName, queryMashupDoc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const { version, packageOPC, permissionsSize, permissions, metadata, endBuffer } = getPackageComponents(base64Str);
|
|
47
|
+
const newPackageBuffer = yield editSingleQueryPackage(packageOPC, queryMashupDoc);
|
|
48
|
+
const packageSizeBuffer = _1.arrayUtils.getInt32Buffer(newPackageBuffer.byteLength);
|
|
49
|
+
const permissionsSizeBuffer = _1.arrayUtils.getInt32Buffer(permissionsSize);
|
|
50
|
+
const newMetadataBuffer = editSingleQueryMetadata(metadata, { queryName });
|
|
51
|
+
const metadataSizeBuffer = _1.arrayUtils.getInt32Buffer(newMetadataBuffer.byteLength);
|
|
52
|
+
const newMashup = _1.arrayUtils.concatArrays(version, packageSizeBuffer, newPackageBuffer, permissionsSizeBuffer, permissions, metadataSizeBuffer, newMetadataBuffer, endBuffer);
|
|
53
|
+
return base64.fromByteArray(newMashup);
|
|
54
|
+
});
|
|
55
|
+
exports.replaceSingleQuery = replaceSingleQuery;
|
|
56
|
+
const getPackageComponents = (base64Str) => {
|
|
57
|
+
const buffer = base64.toByteArray(base64Str).buffer;
|
|
58
|
+
const mashupArray = new _1.arrayUtils.ArrayReader(buffer);
|
|
59
|
+
const version = mashupArray.getBytes(4);
|
|
60
|
+
const packageSize = mashupArray.getInt32();
|
|
61
|
+
const packageOPC = mashupArray.getBytes(packageSize);
|
|
62
|
+
const permissionsSize = mashupArray.getInt32();
|
|
63
|
+
const permissions = mashupArray.getBytes(permissionsSize);
|
|
64
|
+
const metadataSize = mashupArray.getInt32();
|
|
65
|
+
const metadata = mashupArray.getBytes(metadataSize);
|
|
66
|
+
const endBuffer = mashupArray.getBytes();
|
|
67
|
+
return {
|
|
68
|
+
version,
|
|
69
|
+
packageOPC,
|
|
70
|
+
permissionsSize,
|
|
71
|
+
permissions,
|
|
72
|
+
metadata,
|
|
73
|
+
endBuffer,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const editSingleQueryPackage = (packageOPC, queryMashupDoc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
const packageZip = yield jszip_1.default.loadAsync(packageOPC);
|
|
78
|
+
setSection1m(queryMashupDoc, packageZip);
|
|
79
|
+
return yield packageZip.generateAsync({ type: constants_1.uint8ArrayType });
|
|
80
|
+
});
|
|
81
|
+
const setSection1m = (queryMashupDoc, zip) => {
|
|
82
|
+
var _a;
|
|
83
|
+
if (!((_a = zip.file(constants_1.section1mPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))) {
|
|
84
|
+
throw new Error(constants_1.formulaSectionNotFoundErr);
|
|
85
|
+
}
|
|
86
|
+
const newSection1m = queryMashupDoc;
|
|
87
|
+
zip.file(constants_1.section1mPath, newSection1m, {
|
|
88
|
+
compression: constants_1.emptyValue,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const editSingleQueryMetadata = (metadataArray, metadata) => {
|
|
92
|
+
var _a;
|
|
93
|
+
//extract metadataXml
|
|
94
|
+
const mashupArray = new _1.arrayUtils.ArrayReader(metadataArray.buffer);
|
|
95
|
+
const metadataVersion = mashupArray.getBytes(4);
|
|
96
|
+
const metadataXmlSize = mashupArray.getInt32();
|
|
97
|
+
const metadataXml = mashupArray.getBytes(metadataXmlSize);
|
|
98
|
+
const endBuffer = mashupArray.getBytes();
|
|
99
|
+
//parse metdataXml
|
|
100
|
+
const textDecoder = new TextDecoder();
|
|
101
|
+
const metadataString = textDecoder.decode(metadataXml);
|
|
102
|
+
const parser = new DOMParser();
|
|
103
|
+
const serializer = new XMLSerializer();
|
|
104
|
+
const parsedMetadata = parser.parseFromString(metadataString, constants_1.xmlTextResultType);
|
|
105
|
+
// Update InfoPaths to new QueryName
|
|
106
|
+
const itemPaths = parsedMetadata.getElementsByTagName(constants_1.element.itemPath);
|
|
107
|
+
if (itemPaths && itemPaths.length) {
|
|
108
|
+
for (let i = 0; i < itemPaths.length; i++) {
|
|
109
|
+
const itemPath = itemPaths[i];
|
|
110
|
+
const content = itemPath.innerHTML;
|
|
111
|
+
if (content.includes(constants_1.section1PathPrefix)) {
|
|
112
|
+
const strArr = content.split(constants_1.divider);
|
|
113
|
+
strArr[1] = metadata.queryName;
|
|
114
|
+
const newContent = strArr.join(constants_1.divider);
|
|
115
|
+
itemPath.textContent = newContent;
|
|
46
116
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const entries = parsedMetadata.getElementsByTagName(constants_1.element.entry);
|
|
120
|
+
if (entries && entries.length) {
|
|
121
|
+
for (let i = 0; i < entries.length; i++) {
|
|
122
|
+
const entry = entries[i];
|
|
123
|
+
const entryAttributes = entry.attributes;
|
|
124
|
+
const entryAttributesArr = [...entryAttributes];
|
|
125
|
+
const entryProp = entryAttributesArr.find((prop) => {
|
|
126
|
+
return (prop === null || prop === void 0 ? void 0 : prop.name) === constants_1.elementAttributes.type;
|
|
50
127
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const metadataVersion = mashupArray.getBytes(4);
|
|
57
|
-
const metadataXmlSize = mashupArray.getInt32();
|
|
58
|
-
const metadataXml = mashupArray.getBytes(metadataXmlSize);
|
|
59
|
-
const endBuffer = mashupArray.getBytes();
|
|
60
|
-
//parse metdataXml
|
|
61
|
-
const textDecoder = new TextDecoder();
|
|
62
|
-
const metadataString = textDecoder.decode(metadataXml);
|
|
63
|
-
const parser = new DOMParser();
|
|
64
|
-
const serializer = new XMLSerializer();
|
|
65
|
-
const parsedMetadata = parser.parseFromString(metadataString, constants_1.xmlTextResultType);
|
|
66
|
-
// Update InfoPaths to new QueryName
|
|
67
|
-
const itemPaths = parsedMetadata.getElementsByTagName(constants_1.element.itemPath);
|
|
68
|
-
if (itemPaths && itemPaths.length) {
|
|
69
|
-
for (let i = 0; i < itemPaths.length; i++) {
|
|
70
|
-
const itemPath = itemPaths[i];
|
|
71
|
-
const content = itemPath.innerHTML;
|
|
72
|
-
if (content.includes(constants_1.section1PathPrefix)) {
|
|
73
|
-
const strArr = content.split(constants_1.divider);
|
|
74
|
-
strArr[1] = metadata.queryName;
|
|
75
|
-
const newContent = strArr.join(constants_1.divider);
|
|
76
|
-
itemPath.textContent = newContent;
|
|
77
|
-
}
|
|
128
|
+
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.relationshipInfo) {
|
|
129
|
+
const newValue = (_a = entry
|
|
130
|
+
.getAttribute(constants_1.elementAttributes.value)) === null || _a === void 0 ? void 0 : _a.replace(/Query1/g, metadata.queryName);
|
|
131
|
+
if (newValue) {
|
|
132
|
+
entry.setAttribute(constants_1.elementAttributes.value, newValue);
|
|
78
133
|
}
|
|
79
134
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return (prop === null || prop === void 0 ? void 0 : prop.name) === constants_1.elementAttributes.type;
|
|
88
|
-
});
|
|
89
|
-
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.relationshipInfo) {
|
|
90
|
-
const newValue = (_a = entry
|
|
91
|
-
.getAttribute(constants_1.elementAttributes.value)) === null || _a === void 0 ? void 0 : _a.replace(/Query1/g, metadata.queryName);
|
|
92
|
-
if (newValue) {
|
|
93
|
-
entry.setAttribute(constants_1.elementAttributes.value, newValue);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.resultType) {
|
|
97
|
-
entry.setAttribute(constants_1.elementAttributes.value, constants_1.elementAttributesValues.tableResultType());
|
|
98
|
-
}
|
|
99
|
-
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.fillColumnNames) {
|
|
100
|
-
const oldValue = entry.getAttribute(constants_1.elementAttributes.value);
|
|
101
|
-
if (oldValue) {
|
|
102
|
-
entry.setAttribute(constants_1.elementAttributes.value, oldValue.replace(constants_1.defaults.queryName, metadata.queryName));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.fillTarget) {
|
|
106
|
-
const oldValue = entry.getAttribute(constants_1.elementAttributes.value);
|
|
107
|
-
if (oldValue) {
|
|
108
|
-
entry.setAttribute(constants_1.elementAttributes.value, oldValue.replace(constants_1.defaults.queryName, metadata.queryName));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.fillLastUpdated) {
|
|
112
|
-
const nowTime = new Date().toISOString();
|
|
113
|
-
entry.setAttribute(constants_1.elementAttributes.value, (constants_1.elementAttributes.day + nowTime).replace(/Z/, "0000Z"));
|
|
114
|
-
}
|
|
135
|
+
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.resultType) {
|
|
136
|
+
entry.setAttribute(constants_1.elementAttributes.value, constants_1.elementAttributesValues.tableResultType());
|
|
137
|
+
}
|
|
138
|
+
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.fillColumnNames) {
|
|
139
|
+
const oldValue = entry.getAttribute(constants_1.elementAttributes.value);
|
|
140
|
+
if (oldValue) {
|
|
141
|
+
entry.setAttribute(constants_1.elementAttributes.value, oldValue.replace(constants_1.defaults.queryName, metadata.queryName));
|
|
115
142
|
}
|
|
116
143
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const { version, packageOPC, permissionsSize, permissions, metadata, endBuffer } = this.getPackageComponents(base64Str);
|
|
129
|
-
const newPackageBuffer = yield this.editSingleQueryPackage(packageOPC, queryMashupDoc);
|
|
130
|
-
const packageSizeBuffer = _1.arrayUtils.getInt32Buffer(newPackageBuffer.byteLength);
|
|
131
|
-
const permissionsSizeBuffer = _1.arrayUtils.getInt32Buffer(permissionsSize);
|
|
132
|
-
const newMetadataBuffer = this.editSingleQueryMetadata(metadata, { queryName });
|
|
133
|
-
const metadataSizeBuffer = _1.arrayUtils.getInt32Buffer(newMetadataBuffer.byteLength);
|
|
134
|
-
const newMashup = _1.arrayUtils.concatArrays(version, packageSizeBuffer, newPackageBuffer, permissionsSizeBuffer, permissions, metadataSizeBuffer, newMetadataBuffer, endBuffer);
|
|
135
|
-
return base64.fromByteArray(newMashup);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
getPackageComponents(base64Str) {
|
|
139
|
-
const buffer = base64.toByteArray(base64Str).buffer;
|
|
140
|
-
const mashupArray = new _1.arrayUtils.ArrayReader(buffer);
|
|
141
|
-
const version = mashupArray.getBytes(4);
|
|
142
|
-
const packageSize = mashupArray.getInt32();
|
|
143
|
-
const packageOPC = mashupArray.getBytes(packageSize);
|
|
144
|
-
const permissionsSize = mashupArray.getInt32();
|
|
145
|
-
const permissions = mashupArray.getBytes(permissionsSize);
|
|
146
|
-
const metadataSize = mashupArray.getInt32();
|
|
147
|
-
const metadata = mashupArray.getBytes(metadataSize);
|
|
148
|
-
const endBuffer = mashupArray.getBytes();
|
|
149
|
-
return {
|
|
150
|
-
version,
|
|
151
|
-
packageOPC,
|
|
152
|
-
permissionsSize,
|
|
153
|
-
permissions,
|
|
154
|
-
metadata,
|
|
155
|
-
endBuffer,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
editSingleQueryPackage(packageOPC, queryMashupDoc) {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const packageZip = yield jszip_1.default.loadAsync(packageOPC);
|
|
161
|
-
this.setSection1m(queryMashupDoc, packageZip);
|
|
162
|
-
return yield packageZip.generateAsync({ type: constants_1.uint8ArrayType });
|
|
163
|
-
});
|
|
144
|
+
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.fillTarget) {
|
|
145
|
+
const oldValue = entry.getAttribute(constants_1.elementAttributes.value);
|
|
146
|
+
if (oldValue) {
|
|
147
|
+
entry.setAttribute(constants_1.elementAttributes.value, oldValue.replace(constants_1.defaults.queryName, metadata.queryName));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if ((entryProp === null || entryProp === void 0 ? void 0 : entryProp.nodeValue) == constants_1.elementAttributes.fillLastUpdated) {
|
|
151
|
+
const nowTime = new Date().toISOString();
|
|
152
|
+
entry.setAttribute(constants_1.elementAttributes.value, (constants_1.elementAttributes.day + nowTime).replace(/Z/, "0000Z"));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
164
155
|
}
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
// Convert new metadataXml to Uint8Array
|
|
157
|
+
const newMetadataString = serializer.serializeToString(parsedMetadata);
|
|
158
|
+
const encoder = new TextEncoder();
|
|
159
|
+
const newMetadataXml = encoder.encode(newMetadataString);
|
|
160
|
+
const newMetadataXmlSize = _1.arrayUtils.getInt32Buffer(newMetadataXml.byteLength);
|
|
161
|
+
const newMetadataArray = _1.arrayUtils.concatArrays(metadataVersion, newMetadataXmlSize, newMetadataXml, endBuffer);
|
|
162
|
+
return newMetadataArray;
|
|
163
|
+
};
|
package/dist/utils/pqUtils.js
CHANGED
|
@@ -10,11 +10,7 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const iconv_lite_1 = __importDefault(require("iconv-lite"));
|
|
18
14
|
const constants_1 = require("./constants");
|
|
19
15
|
const generators_1 = require("../generators");
|
|
20
16
|
const getBase64 = (zip) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -22,8 +18,8 @@ const getBase64 = (zip) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
22
18
|
return mashup.value;
|
|
23
19
|
});
|
|
24
20
|
const setBase64 = (zip, base64) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const newXml = generators_1.generateMashupXMLTemplate(base64);
|
|
26
|
-
const encoded =
|
|
21
|
+
const newXml = (0, generators_1.generateMashupXMLTemplate)(base64);
|
|
22
|
+
const encoded = Buffer.from(constants_1.BOM + newXml, 'ucs2');
|
|
27
23
|
const mashup = yield getDataMashupFile(zip);
|
|
28
24
|
zip.file(mashup === null || mashup === void 0 ? void 0 : mashup.path, encoded);
|
|
29
25
|
});
|
|
@@ -41,7 +37,7 @@ const getDataMashupFile = (zip) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
41
37
|
}
|
|
42
38
|
return mashup;
|
|
43
39
|
});
|
|
44
|
-
const getCustomXmlFile = (zip, url, encoding =
|
|
40
|
+
const getCustomXmlFile = (zip, url, encoding = 'utf16le') => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
41
|
var _a, _b;
|
|
46
42
|
const parser = new DOMParser();
|
|
47
43
|
const itemsArray = yield zip.file(/customXml\/item\d.xml/);
|
|
@@ -53,12 +49,12 @@ const getCustomXmlFile = (zip, url, encoding = "UTF-16") => __awaiter(void 0, vo
|
|
|
53
49
|
let xmlString;
|
|
54
50
|
let value;
|
|
55
51
|
for (let i = 1; i <= itemsArray.length; i++) {
|
|
56
|
-
path = generators_1.generateCustomXmlFilePath(i);
|
|
52
|
+
path = (0, generators_1.generateCustomXmlFilePath)(i);
|
|
57
53
|
const xmlValue = yield ((_a = zip.file(path)) === null || _a === void 0 ? void 0 : _a.async("uint8array"));
|
|
58
54
|
if (xmlValue === undefined) {
|
|
59
55
|
break;
|
|
60
56
|
}
|
|
61
|
-
xmlString =
|
|
57
|
+
xmlString = Buffer.from(xmlValue).toString(encoding).replace(/^\ufeff/, '');
|
|
62
58
|
const doc = parser.parseFromString(xmlString, "text/xml");
|
|
63
59
|
found = ((_b = doc === null || doc === void 0 ? void 0 : doc.documentElement) === null || _b === void 0 ? void 0 : _b.namespaceURI) === url;
|
|
64
60
|
if (found) {
|
package/dist/utils/tableUtils.js
CHANGED
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const types_1 = require("../types");
|
|
16
15
|
const constants_1 = require("./constants");
|
|
17
16
|
const documentUtils_1 = __importDefault(require("./documentUtils"));
|
|
18
17
|
const uuid_1 = require("uuid");
|
|
@@ -55,35 +54,34 @@ const updateTablesInitialData = (tableXmlString, tableData, updateQueryTable = f
|
|
|
55
54
|
const tableDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
56
55
|
const tableColumns = tableDoc.getElementsByTagName(constants_1.element.tableColumns)[0];
|
|
57
56
|
tableColumns.textContent = "";
|
|
58
|
-
tableData.
|
|
57
|
+
tableData.columnNames.forEach((column, columnIndex) => {
|
|
59
58
|
const tableColumn = tableDoc.createElementNS(tableDoc.documentElement.namespaceURI, constants_1.element.tableColumn);
|
|
60
59
|
tableColumn.setAttribute(constants_1.elementAttributes.id, (columnIndex + 1).toString());
|
|
61
|
-
tableColumn.setAttribute(constants_1.elementAttributes.name,
|
|
60
|
+
tableColumn.setAttribute(constants_1.elementAttributes.name, column);
|
|
62
61
|
tableColumns.appendChild(tableColumn);
|
|
63
|
-
tableColumn.setAttribute(constants_1.elementAttributes.xr3uid, "{" + uuid_1.v4().toUpperCase() + "}");
|
|
62
|
+
tableColumn.setAttribute(constants_1.elementAttributes.xr3uid, "{" + (0, uuid_1.v4)().toUpperCase() + "}");
|
|
64
63
|
if (updateQueryTable) {
|
|
65
64
|
tableColumn.setAttribute(constants_1.elementAttributes.uniqueName, (columnIndex + 1).toString());
|
|
66
65
|
tableColumn.setAttribute(constants_1.elementAttributes.queryTableFieldId, (columnIndex + 1).toString());
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
|
-
tableColumns.setAttribute(constants_1.elementAttributes.count, tableData.
|
|
68
|
+
tableColumns.setAttribute(constants_1.elementAttributes.count, tableData.columnNames.length.toString());
|
|
70
69
|
tableDoc
|
|
71
70
|
.getElementsByTagName(constants_1.element.table)[0]
|
|
72
|
-
.setAttribute(constants_1.elementAttributes.reference, `A1:${documentUtils_1.default.getCellReferenceRelative(tableData.
|
|
71
|
+
.setAttribute(constants_1.elementAttributes.reference, `A1:${documentUtils_1.default.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)}`);
|
|
73
72
|
tableDoc
|
|
74
73
|
.getElementsByTagName(constants_1.element.autoFilter)[0]
|
|
75
|
-
.setAttribute(constants_1.elementAttributes.reference, `A1:${documentUtils_1.default.getCellReferenceRelative(tableData.
|
|
74
|
+
.setAttribute(constants_1.elementAttributes.reference, `A1:${documentUtils_1.default.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)}`);
|
|
76
75
|
return serializer.serializeToString(tableDoc);
|
|
77
76
|
});
|
|
78
|
-
const updateWorkbookInitialData = (workbookXmlString, tableData
|
|
77
|
+
const updateWorkbookInitialData = (workbookXmlString, tableData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
78
|
const newParser = new DOMParser();
|
|
80
79
|
const newSerializer = new XMLSerializer();
|
|
81
80
|
const workbookDoc = newParser.parseFromString(workbookXmlString, constants_1.xmlTextResultType);
|
|
82
81
|
const definedName = workbookDoc.getElementsByTagName(constants_1.element.definedName)[0];
|
|
83
|
-
const prefix = queryName === undefined ? constants_1.defaults.queryName : queryName;
|
|
84
82
|
definedName.textContent =
|
|
85
|
-
|
|
86
|
-
`!$A$1:${documentUtils_1.default.getCellReferenceAbsolute(tableData.
|
|
83
|
+
constants_1.defaults.sheetName +
|
|
84
|
+
`!$A$1:${documentUtils_1.default.getCellReferenceAbsolute(tableData.columnNames.length - 1, tableData.rows.length + 1)}`;
|
|
87
85
|
return newSerializer.serializeToString(workbookDoc);
|
|
88
86
|
});
|
|
89
87
|
const updateQueryTablesInitialData = (queryTableXmlString, tableData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -92,17 +90,17 @@ const updateQueryTablesInitialData = (queryTableXmlString, tableData) => __await
|
|
|
92
90
|
const queryTableDoc = parser.parseFromString(queryTableXmlString, constants_1.xmlTextResultType);
|
|
93
91
|
const queryTableFields = queryTableDoc.getElementsByTagName(constants_1.element.queryTableFields)[0];
|
|
94
92
|
queryTableFields.textContent = "";
|
|
95
|
-
tableData.
|
|
93
|
+
tableData.columnNames.forEach((column, columnIndex) => {
|
|
96
94
|
const queryTableField = queryTableDoc.createElementNS(queryTableDoc.documentElement.namespaceURI, constants_1.element.queryTableField);
|
|
97
95
|
queryTableField.setAttribute(constants_1.elementAttributes.id, (columnIndex + 1).toString());
|
|
98
|
-
queryTableField.setAttribute(constants_1.elementAttributes.name,
|
|
96
|
+
queryTableField.setAttribute(constants_1.elementAttributes.name, column);
|
|
99
97
|
queryTableField.setAttribute(constants_1.elementAttributes.tableColumnId, (columnIndex + 1).toString());
|
|
100
98
|
queryTableFields.appendChild(queryTableField);
|
|
101
99
|
});
|
|
102
|
-
queryTableFields.setAttribute(constants_1.elementAttributes.count, tableData.
|
|
100
|
+
queryTableFields.setAttribute(constants_1.elementAttributes.count, tableData.columnNames.length.toString());
|
|
103
101
|
queryTableDoc
|
|
104
102
|
.getElementsByTagName(constants_1.element.queryTableRefresh)[0]
|
|
105
|
-
.setAttribute(constants_1.elementAttributes.nextId, (tableData.
|
|
103
|
+
.setAttribute(constants_1.elementAttributes.nextId, (tableData.columnNames.length + 1).toString());
|
|
106
104
|
return serializer.serializeToString(queryTableDoc);
|
|
107
105
|
});
|
|
108
106
|
const updateSheetsInitialData = (sheetsXmlString, tableData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -114,10 +112,10 @@ const updateSheetsInitialData = (sheetsXmlString, tableData) => __awaiter(void 0
|
|
|
114
112
|
let rowIndex = 0;
|
|
115
113
|
const columnRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, constants_1.element.row);
|
|
116
114
|
columnRow.setAttribute(constants_1.elementAttributes.row, (rowIndex + 1).toString());
|
|
117
|
-
columnRow.setAttribute(constants_1.elementAttributes.spans, "1:" + tableData.
|
|
115
|
+
columnRow.setAttribute(constants_1.elementAttributes.spans, "1:" + tableData.columnNames.length);
|
|
118
116
|
columnRow.setAttribute(constants_1.elementAttributes.x14acDyDescent, "0.3");
|
|
119
|
-
tableData.
|
|
120
|
-
columnRow.appendChild(documentUtils_1.default.createCell(sheetsDoc, colIndex, rowIndex,
|
|
117
|
+
tableData.columnNames.forEach((col, colIndex) => {
|
|
118
|
+
columnRow.appendChild(documentUtils_1.default.createCell(sheetsDoc, colIndex, rowIndex, col));
|
|
121
119
|
});
|
|
122
120
|
sheetData.appendChild(columnRow);
|
|
123
121
|
rowIndex++;
|
|
@@ -127,7 +125,7 @@ const updateSheetsInitialData = (sheetsXmlString, tableData) => __awaiter(void 0
|
|
|
127
125
|
newRow.setAttribute(constants_1.elementAttributes.spans, "1:" + row.length);
|
|
128
126
|
newRow.setAttribute(constants_1.elementAttributes.x14acDyDescent, "0.3");
|
|
129
127
|
row.forEach((cellContent, colIndex) => {
|
|
130
|
-
newRow.appendChild(documentUtils_1.default.createCell(sheetsDoc, colIndex, rowIndex,
|
|
128
|
+
newRow.appendChild(documentUtils_1.default.createCell(sheetsDoc, colIndex, rowIndex, cellContent));
|
|
131
129
|
});
|
|
132
130
|
sheetData.appendChild(newRow);
|
|
133
131
|
rowIndex++;
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const constants_1 = require("./constants");
|
|
16
|
-
const mashupDocumentParser_1 =
|
|
16
|
+
const mashupDocumentParser_1 = require("./mashupDocumentParser");
|
|
17
17
|
const pqUtils_1 = __importDefault(require("./pqUtils"));
|
|
18
18
|
const xmlInnerPartsUtils_1 = __importDefault(require("./xmlInnerPartsUtils"));
|
|
19
19
|
const tableUtils_1 = __importDefault(require("./tableUtils"));
|
|
@@ -26,7 +26,7 @@ const updateWorkbookPowerQueryDocument = (zip, queryName, queryMashupDoc) => __a
|
|
|
26
26
|
if (!old_base64) {
|
|
27
27
|
throw new Error(constants_1.base64NotFoundErr);
|
|
28
28
|
}
|
|
29
|
-
const new_base64 = yield
|
|
29
|
+
const new_base64 = yield (0, mashupDocumentParser_1.replaceSingleQuery)(old_base64, queryName, queryMashupDoc);
|
|
30
30
|
yield pqUtils_1.default.setBase64(zip, new_base64);
|
|
31
31
|
});
|
|
32
32
|
const updateWorkbookSingleQueryAttributes = (zip, queryName, refreshOnOpen) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { DocProps, QueryInfo, Grid } from "./types";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
downloadWorkbook: (file: Blob, filename: string) => void;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
1
|
+
import { DocProps, QueryInfo, Grid, FileConfigs } from "./types";
|
|
2
|
+
export declare const generateSingleQueryWorkbook: (query: QueryInfo, initialDataGrid?: Grid, fileConfigs?: FileConfigs) => Promise<Blob>;
|
|
3
|
+
export declare const generateTableWorkbookFromHtml: (htmlTable: HTMLTableElement, docProps?: DocProps) => Promise<Blob>;
|
|
4
|
+
export declare const generateTableWorkbookFromGrid: (grid: Grid, docProps?: DocProps) => Promise<Blob>;
|
|
5
|
+
export declare const downloadWorkbook: (file: Blob, filename: string) => void;
|
package/dist/workbookManager.js
CHANGED
|
@@ -14,39 +14,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.downloadWorkbook = exports.generateTableWorkbookFromGrid = exports.generateTableWorkbookFromHtml = exports.generateSingleQueryWorkbook = void 0;
|
|
17
18
|
const jszip_1 = __importDefault(require("jszip"));
|
|
18
19
|
const utils_1 = require("./utils");
|
|
19
|
-
const workbookTemplate_1 =
|
|
20
|
+
const workbookTemplate_1 = require("./workbookTemplate");
|
|
20
21
|
const constants_1 = require("./utils/constants");
|
|
21
|
-
const types_1 = require("./types");
|
|
22
|
-
const TableDataParserFactory_1 = __importDefault(require("./TableDataParserFactory"));
|
|
23
22
|
const generators_1 = require("./generators");
|
|
24
23
|
const htmlUtils_1 = require("./utils/htmlUtils");
|
|
25
|
-
const
|
|
24
|
+
const GridParser_1 = require("./GridParser");
|
|
25
|
+
const generateSingleQueryWorkbook = (query, initialDataGrid, fileConfigs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
if (!query.queryMashup) {
|
|
27
27
|
throw new Error(constants_1.emptyQueryMashupErr);
|
|
28
28
|
}
|
|
29
29
|
if (!query.queryName) {
|
|
30
30
|
query.queryName = constants_1.defaults.queryName;
|
|
31
31
|
}
|
|
32
|
+
const templateFile = fileConfigs === null || fileConfigs === void 0 ? void 0 : fileConfigs.templateFile;
|
|
32
33
|
if (templateFile !== undefined && initialDataGrid !== undefined) {
|
|
33
34
|
throw new Error(constants_1.templateWithInitialDataErr);
|
|
34
35
|
}
|
|
35
36
|
utils_1.pqUtils.validateQueryName(query.queryName);
|
|
36
37
|
const zip = templateFile === undefined
|
|
37
|
-
? yield jszip_1.default.loadAsync(workbookTemplate_1.
|
|
38
|
+
? yield jszip_1.default.loadAsync(workbookTemplate_1.SIMPLE_QUERY_WORKBOOK_TEMPLATE, { base64: true })
|
|
38
39
|
: yield jszip_1.default.loadAsync(templateFile);
|
|
39
40
|
const tableData = yield parseInitialDataGrid(initialDataGrid);
|
|
40
|
-
return yield generateSingleQueryWorkbookFromZip(zip, query, docProps, tableData);
|
|
41
|
+
return yield generateSingleQueryWorkbookFromZip(zip, query, fileConfigs === null || fileConfigs === void 0 ? void 0 : fileConfigs.docProps, tableData);
|
|
41
42
|
});
|
|
43
|
+
exports.generateSingleQueryWorkbook = generateSingleQueryWorkbook;
|
|
42
44
|
const generateTableWorkbookFromHtml = (htmlTable, docProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return yield generateTableWorkbookFromGrid({ gridData, header }, docProps);
|
|
45
|
+
const gridData = (0, htmlUtils_1.extractTableValues)(htmlTable);
|
|
46
|
+
return yield (0, exports.generateTableWorkbookFromGrid)({ data: gridData, promoteHeaders: false }, docProps);
|
|
46
47
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
48
|
+
exports.generateTableWorkbookFromHtml = generateTableWorkbookFromHtml;
|
|
49
|
+
const generateTableWorkbookFromGrid = (grid, docProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const zip = yield jszip_1.default.loadAsync(workbookTemplate_1.SIMPLE_BLANK_TABLE_TEMPLATE, { base64: true });
|
|
51
|
+
const tableData = yield parseInitialDataGrid(grid);
|
|
50
52
|
if (tableData === undefined) {
|
|
51
53
|
throw new Error(constants_1.tableNotFoundErr);
|
|
52
54
|
}
|
|
@@ -56,19 +58,19 @@ const generateTableWorkbookFromGrid = (initialDataGrid, docProps) => __awaiter(v
|
|
|
56
58
|
mimeType: constants_1.application,
|
|
57
59
|
});
|
|
58
60
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
exports.generateTableWorkbookFromGrid = generateTableWorkbookFromGrid;
|
|
62
|
+
const parseInitialDataGrid = (grid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
if (!grid) {
|
|
61
64
|
return undefined;
|
|
62
65
|
}
|
|
63
|
-
const
|
|
64
|
-
const tableData = parser.parseToTableData(initialDataGrid);
|
|
66
|
+
const tableData = (0, GridParser_1.parseToTableData)(grid);
|
|
65
67
|
return tableData;
|
|
66
68
|
});
|
|
67
69
|
const generateSingleQueryWorkbookFromZip = (zip, query, docProps, tableData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
70
|
if (!query.queryName) {
|
|
69
71
|
query.queryName = constants_1.defaults.queryName;
|
|
70
72
|
}
|
|
71
|
-
yield utils_1.xmlPartsUtils.updateWorkbookPowerQueryDocument(zip, query.queryName, generators_1.generateSingleQueryMashup(query.queryName, query.queryMashup));
|
|
73
|
+
yield utils_1.xmlPartsUtils.updateWorkbookPowerQueryDocument(zip, query.queryName, (0, generators_1.generateSingleQueryMashup)(query.queryName, query.queryMashup));
|
|
72
74
|
yield utils_1.xmlPartsUtils.updateWorkbookSingleQueryAttributes(zip, query.queryName, query.refreshOnOpen);
|
|
73
75
|
yield utils_1.xmlPartsUtils.updateWorkbookInitialDataIfNeeded(zip, docProps, tableData, true /*updateQueryTable*/);
|
|
74
76
|
return yield zip.generateAsync({
|
|
@@ -95,9 +97,4 @@ const downloadWorkbook = (file, filename) => {
|
|
|
95
97
|
}, 0);
|
|
96
98
|
}
|
|
97
99
|
};
|
|
98
|
-
exports.
|
|
99
|
-
generateSingleQueryWorkbook,
|
|
100
|
-
generateTableWorkbookFromHtml,
|
|
101
|
-
generateTableWorkbookFromGrid,
|
|
102
|
-
downloadWorkbook,
|
|
103
|
-
};
|
|
100
|
+
exports.downloadWorkbook = downloadWorkbook;
|