Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User/mabezen/add support to nodejs #87

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 56 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/connected-workbooks",
"version": "3.0.0",
"version": "3.0.3",
"description": "Microsoft backed, Excel advanced xlsx workbook generation JavaScript library",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -40,7 +40,9 @@
"base64-js": "^1.5.1",
"buffer": "^6.0.3",
"jszip": "^3.5.0",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"xmldom": "^0.6.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both?

"xmldom-qsa": "^1.1.3"
},
"devDependencies": {
"@babel/core": "^7.14.6",
Expand All @@ -51,6 +53,7 @@
"@types/jszip": "^3.4.1",
"@types/uuid": "^9.0.2",
"@types/webpack-bundle-analyzer": "^4.6.0",
"@types/xmldom": "^0.1.32",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question (do we need it?)

"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"@webpack-cli/generators": "^3.0.7",
Expand Down
1 change: 1 addition & 0 deletions src/utils/documentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import JSZip from "jszip";
import { DOMParser } from "xmldom-qsa";
import {
dataTypeKind,
docPropsCoreXmlPath,
Expand Down
6 changes: 3 additions & 3 deletions src/utils/mashupDocumentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as base64 from "base64-js";
import JSZip from "jszip";
import { DOMParser, XMLSerializer } from "xmldom-qsa";
import {
section1mPath,
defaults,
Expand Down Expand Up @@ -111,7 +112,7 @@ export const editSingleQueryMetadata = (metadataArray: Uint8Array, metadata: Met
if (itemPaths && itemPaths.length) {
for (let i = 0; i < itemPaths.length; i++) {
const itemPath: Element = itemPaths[i];
const content: string = itemPath.innerHTML;
const content: string = itemPath.textContent as string;
if (content.includes(section1PathPrefix)) {
const strArr: string[] = content.split(divider);
strArr[1] = encodeURIComponent(metadata.queryName);
Expand All @@ -125,8 +126,7 @@ export const editSingleQueryMetadata = (metadataArray: Uint8Array, metadata: Met
if (entries && entries.length) {
for (let i = 0; i < entries.length; i++) {
const entry: Element = entries[i];
const entryAttributes: NamedNodeMap = entry.attributes;
const entryAttributesArr: Attr[] = [...entryAttributes];
const entryAttributesArr: Attr[] = Array.from(entry.attributes);
const entryProp: Attr | undefined = entryAttributesArr.find((prop) => {
return prop?.name === elementAttributes.type;
});
Expand Down
9 changes: 5 additions & 4 deletions src/utils/pqUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import JSZip from "jszip";
import { EmptyQueryNameErr, QueryNameMaxLengthErr, maxQueryLength, URLS, BOM, QueryNameInvalidCharsErr } from "./constants";
import { generateMashupXMLTemplate, generateCustomXmlFilePath } from "../generators";
import { Buffer } from "buffer";
import { DOMParser } from "xmldom-qsa";

type CustomXmlFile = {
found: boolean;
path: string;
xmlString: string | undefined;
value: string | undefined;
value: string | null;
};

const getBase64 = async (zip: JSZip): Promise<string | undefined> => {
const getBase64 = async (zip: JSZip): Promise<string | null> => {
const mashup = await getDataMashupFile(zip);
return mashup.value;
};
Expand Down Expand Up @@ -54,7 +55,7 @@ const getCustomXmlFile = async (zip: JSZip, url: string, encoding: BufferEncodin
let found = false;
let path: string;
let xmlString: string | undefined;
let value: string | undefined;
let value: string | null = null;

for (let i = 1; i <= itemsArray.length; i++) {
path = generateCustomXmlFilePath(i);
Expand All @@ -72,7 +73,7 @@ const getCustomXmlFile = async (zip: JSZip, url: string, encoding: BufferEncodin
found = doc?.documentElement?.namespaceURI === url;

if (found) {
value = doc.documentElement.innerHTML;
value = doc.documentElement.textContent;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/tableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import JSZip from "jszip";
import { TableData } from "../types";
import { DOMParser, XMLSerializer } from "xmldom-qsa";
import {
defaults,
element,
Expand Down
9 changes: 5 additions & 4 deletions src/utils/xmlInnerPartsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import JSZip from "jszip";
import { DOMParser, XMLSerializer } from "xmldom-qsa";
import { DocProps, DocPropsAutoUpdatedElements, DocPropsModifiableElements } from "../types";
import {
docPropsCoreXmlPath,
Expand Down Expand Up @@ -100,11 +101,11 @@ const updateConnections = (
dbPr.setAttribute(elementAttributes.refreshOnLoad, refreshOnLoadValue);

// Update query details to match queryName
dbPr.parentElement?.setAttribute(elementAttributes.name, elementAttributesValues.connectionName(queryName));
dbPr.parentElement?.setAttribute(elementAttributes.description, elementAttributesValues.connectionDescription(queryName));
(dbPr.parentNode as Element)?.setAttribute(elementAttributes.name, elementAttributesValues.connectionName(queryName));
(dbPr.parentNode as Element)?.setAttribute(elementAttributes.description, elementAttributesValues.connectionDescription(queryName));
dbPr.setAttribute(elementAttributes.connection, elementAttributesValues.connection(queryName));
dbPr.setAttribute(elementAttributes.command, elementAttributesValues.connectionCommand(queryName));
const connectionId: string | null | undefined = dbPr.parentElement?.getAttribute(elementAttributes.id);
const connectionId: string | null | undefined = (dbPr.parentNode as Element)?.getAttribute(elementAttributes.id);
const connectionXmlFileString: string = serializer.serializeToString(connectionsDoc);

if (connectionId === null) {
Expand All @@ -128,7 +129,7 @@ const updateSharedStrings = (sharedStringsXmlString: string, queryName: string):
let sharedStringIndex: number = textElementCollection.length;
if (textElementCollection && textElementCollection.length) {
for (let i = 0; i < textElementCollection.length; i++) {
if (textElementCollection[i].innerHTML === queryName) {
if (textElementCollection[i].textContent === queryName) {
textElement = textElementCollection[i];
sharedStringIndex = i + 1;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xmlPartsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const updateWorkbookDataAndConfigurations = async (zip: JSZip, fileConfigs?: Fil
};

const updateWorkbookPowerQueryDocument = async (zip: JSZip, queryName: string, queryMashupDoc: string): Promise<void> => {
const old_base64: string | undefined = await pqUtils.getBase64(zip);
const old_base64: string | null = await pqUtils.getBase64(zip);

if (!old_base64) {
throw new Error(base64NotFoundErr);
Expand Down