@mcpher/gas-fakes 1.2.15 → 1.2.16
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/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"archiver": "^7.0.1",
|
|
11
11
|
"commander": "^14.0.1",
|
|
12
12
|
"dotenv": "^17.2.3",
|
|
13
|
-
"
|
|
13
|
+
"fast-xml-parser": "^5.3.0",
|
|
14
14
|
"get-stream": "^9.0.1",
|
|
15
15
|
"googleapis": "^161.0.0",
|
|
16
16
|
"got": "^14.4.7",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"name": "@mcpher/gas-fakes",
|
|
33
33
|
"author": "bruce mcpherson",
|
|
34
|
-
"version": "1.2.
|
|
34
|
+
"version": "1.2.16",
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"main": "main.js",
|
|
37
37
|
"description": "A proof of concept implementation of Apps Script Environment on Node",
|
|
@@ -16,7 +16,8 @@ import { newFakeProtection } from "./fakeprotection.js";
|
|
|
16
16
|
import { newFakeOverGridImage } from "./fakeovergridimage.js";
|
|
17
17
|
|
|
18
18
|
import { Syncit } from "../../support/syncit.js";
|
|
19
|
-
|
|
19
|
+
import { XMLParser } from "fast-xml-parser";
|
|
20
|
+
import { nullable } from "zod/v4";
|
|
20
21
|
|
|
21
22
|
const { is, isEnum } = Utils;
|
|
22
23
|
|
|
@@ -1067,28 +1068,98 @@ export class FakeSheet {
|
|
|
1067
1068
|
return [];
|
|
1068
1069
|
}
|
|
1069
1070
|
|
|
1070
|
-
// This function is used for testing getImages without a worker.
|
|
1071
|
-
// async test_getImages() {
|
|
1072
|
-
// const url = `https://docs.google.com/spreadsheets/export?exportFormat=xlsx&id=${
|
|
1073
|
-
// this.__parent.__meta.spreadsheetId
|
|
1074
|
-
// }&access_token=${ScriptApp.getOAuthToken()}`;
|
|
1075
|
-
// const res = UrlFetchApp.fetch(url);
|
|
1076
|
-
// const buf = new Uint8Array(res.getBlob()._data).buffer;
|
|
1077
|
-
// const workbook = new ExcelJS.Workbook();
|
|
1078
|
-
// await workbook.xlsx.load(buf);
|
|
1079
|
-
// const worksheet = workbook.worksheets[this.getIndex() - 1];
|
|
1080
|
-
// const images = worksheet.getImages();
|
|
1081
|
-
// console.log(images);
|
|
1082
|
-
// }
|
|
1083
|
-
|
|
1084
1071
|
getImages() {
|
|
1085
|
-
const url = `https://docs.google.com/spreadsheets/export?exportFormat=xlsx&id=${
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
const
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1072
|
+
const url = `https://docs.google.com/spreadsheets/export?exportFormat=xlsx&id=${this.__parent.__meta.spreadsheetId}`;
|
|
1073
|
+
const res = UrlFetchApp.fetch(url, {
|
|
1074
|
+
headers: { authorization: "Bearer " + ScriptApp.getOAuthToken() },
|
|
1075
|
+
});
|
|
1076
|
+
const blob = res.getBlob().setContentType("application/zip");
|
|
1077
|
+
const unzipped = Utilities.unzip(blob);
|
|
1078
|
+
const xmlObj = unzipped.reduce((o, b) => {
|
|
1079
|
+
const filename = b.getName();
|
|
1080
|
+
const parser = new XMLParser({ ignoreAttributes: false });
|
|
1081
|
+
try {
|
|
1082
|
+
const p = parser.parse(b.getDataAsString());
|
|
1083
|
+
o[filename] = p;
|
|
1084
|
+
} catch (err) {
|
|
1085
|
+
// console.log(err);
|
|
1086
|
+
}
|
|
1087
|
+
return o;
|
|
1088
|
+
}, {});
|
|
1089
|
+
const tempObj = { sheets: {} };
|
|
1090
|
+
if (xmlObj["xl/workbook.xml"]) {
|
|
1091
|
+
const t = xmlObj[
|
|
1092
|
+
"xl/_rels/workbook.xml.rels"
|
|
1093
|
+
].Relationships.Relationship.reduce(
|
|
1094
|
+
(o, e) => ((o[e["@_Id"]] = e["@_Target"]), o),
|
|
1095
|
+
{}
|
|
1096
|
+
);
|
|
1097
|
+
xmlObj["xl/workbook.xml"].workbook.sheets.sheet.forEach((e) => {
|
|
1098
|
+
const target = `xl/${t[e["@_r:id"]]}`;
|
|
1099
|
+
const k = `xl/worksheets/_rels/${target.split("/").pop()}.rels`;
|
|
1100
|
+
let drawing;
|
|
1101
|
+
if (Array.isArray(xmlObj[k].Relationships.Relationship)) {
|
|
1102
|
+
xmlObj[k].Relationships.Relationship.forEach((f) => {
|
|
1103
|
+
if (f["@_Type"].split("/").pop() == "drawing") {
|
|
1104
|
+
drawing = `xl/drawings/${f["@_Target"].split("/").pop()}`;
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
} else {
|
|
1108
|
+
drawing = `xl/drawings/${xmlObj[k].Relationships.Relationship[
|
|
1109
|
+
"@_Target"
|
|
1110
|
+
]
|
|
1111
|
+
.split("/")
|
|
1112
|
+
.pop()}`;
|
|
1113
|
+
}
|
|
1114
|
+
const imgs = [];
|
|
1115
|
+
if (
|
|
1116
|
+
xmlObj[drawing]["xdr:wsDr"] &&
|
|
1117
|
+
xmlObj[drawing]["xdr:wsDr"]["xdr:oneCellAnchor"]
|
|
1118
|
+
) {
|
|
1119
|
+
const t = xmlObj[drawing]["xdr:wsDr"]["xdr:oneCellAnchor"];
|
|
1120
|
+
if (Array.isArray(t)) {
|
|
1121
|
+
t.forEach((f) => {
|
|
1122
|
+
imgs.push({
|
|
1123
|
+
col: f["xdr:from"]["xdr:col"],
|
|
1124
|
+
row: f["xdr:from"]["xdr:row"],
|
|
1125
|
+
anchorCellXOffset: f["xdr:from"]["xdr:colOff"] / 9525,
|
|
1126
|
+
anchorCellYOffset: f["xdr:from"]["xdr:rowOff"] / 9525,
|
|
1127
|
+
width: f["xdr:ext"]["@_cx"] / 9525,
|
|
1128
|
+
height: f["xdr:ext"]["@_cy"] / 9525,
|
|
1129
|
+
innerCell:
|
|
1130
|
+
f["xdr:from"]["xdr:colOff"] == 0 &&
|
|
1131
|
+
f["xdr:from"]["xdr:rowOff"] == 0,
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
} else {
|
|
1135
|
+
imgs.push({
|
|
1136
|
+
col: t["xdr:from"]["xdr:col"],
|
|
1137
|
+
row: t["xdr:from"]["xdr:row"],
|
|
1138
|
+
anchorCellXOffset: t["xdr:from"]["xdr:colOff"] / 9525,
|
|
1139
|
+
anchorCellYOffset: t["xdr:from"]["xdr:rowOff"] / 9525,
|
|
1140
|
+
width: t["xdr:ext"]["@_cx"] / 9525,
|
|
1141
|
+
height: t["xdr:ext"]["@_cy"] / 9525,
|
|
1142
|
+
innerCell:
|
|
1143
|
+
f["xdr:from"]["xdr:colOff"] == 0 &&
|
|
1144
|
+
f["xdr:from"]["xdr:rowOff"] == 0,
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
tempObj.sheets[e["@_name"]] = {
|
|
1149
|
+
...e,
|
|
1150
|
+
name: `xl/${t[e["@_r:id"]]}`,
|
|
1151
|
+
drawing,
|
|
1152
|
+
imgs: imgs.filter(({ innerCell }) => !innerCell), // Images over cells are retrieved.
|
|
1153
|
+
};
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
const sheetName = this.getName();
|
|
1157
|
+
const o = tempObj.sheets[sheetName];
|
|
1158
|
+
if (o.imgs && o.imgs.length > 0) {
|
|
1159
|
+
const sheet = this;
|
|
1160
|
+
return o.imgs.map((e) => newFakeOverGridImage(sheet, e));
|
|
1161
|
+
}
|
|
1162
|
+
return [];
|
|
1092
1163
|
}
|
|
1093
1164
|
|
|
1094
1165
|
__batchUpdate({ spreadsheetId, requests }) {
|
package/src/support/sxxlsx.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import got from "got";
|
|
2
|
-
import ExcelJS from "exceljs";
|
|
1
|
+
// import got from "got";
|
|
2
|
+
// import ExcelJS from "exceljs";
|
|
3
3
|
|
|
4
|
-
async function __getWorkbook(url) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
4
|
+
// async function __getWorkbook(url) {
|
|
5
|
+
// const res = await got(url, { responseType: "buffer" });
|
|
6
|
+
// let buf;
|
|
7
|
+
// if (res.rawBody && Buffer.isBuffer(res.rawBody)) {
|
|
8
|
+
// buf = res.rawBody;
|
|
9
|
+
// } else if (res.body && Buffer.isBuffer(res.body)) {
|
|
10
|
+
// buf = res.body;
|
|
11
|
+
// } else {
|
|
12
|
+
// throw new Error(res);
|
|
13
|
+
// }
|
|
14
|
+
// const workbook = new ExcelJS.Workbook();
|
|
15
|
+
// await workbook.xlsx.load(buf);
|
|
16
|
+
// return workbook;
|
|
17
|
+
// }
|
|
18
18
|
|
|
19
|
-
export const sxGetImagesFromXlsx = async (_, { url, idx }) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
19
|
+
// export const sxGetImagesFromXlsx = async (_, { url, idx }) => {
|
|
20
|
+
// const workbook = await __getWorkbook(url);
|
|
21
|
+
// const worksheet = workbook.worksheets[idx];
|
|
22
|
+
// const ar = worksheet.getImages().reduce((arr, image) => {
|
|
23
|
+
// const imageId = image.imageId;
|
|
24
|
+
// if (image.range.tl.nativeColOff != 0 && image.range.tl.nativeRowOff != 0) {
|
|
25
|
+
// const col = image.range.tl.nativeCol;
|
|
26
|
+
// const row = image.range.tl.nativeRow;
|
|
27
|
+
// const { width, height } = image.range.ext;
|
|
28
|
+
// arr.push({
|
|
29
|
+
// imageId,
|
|
30
|
+
// row,
|
|
31
|
+
// col,
|
|
32
|
+
// width,
|
|
33
|
+
// height,
|
|
34
|
+
// anchorCellXOffset: image.range.tl.nativeColOff,
|
|
35
|
+
// anchorCellYOffset: image.range.tl.nativeRowOff,
|
|
36
|
+
// });
|
|
37
|
+
// }
|
|
38
|
+
// return arr;
|
|
39
|
+
// }, []);
|
|
40
|
+
// return ar;
|
|
41
|
+
// };
|
package/src/support/syncit.js
CHANGED
|
@@ -266,7 +266,6 @@ const fxInit = ({
|
|
|
266
266
|
cachePath = cacheDefaultPath,
|
|
267
267
|
propertiesPath = propertiesDefaultPath,
|
|
268
268
|
} = {}) => {
|
|
269
|
-
|
|
270
269
|
// this is the path of the runing main process
|
|
271
270
|
const mainDir = path.dirname(process.argv[1]);
|
|
272
271
|
|
|
@@ -382,7 +381,7 @@ const fxGmail = (args) =>
|
|
|
382
381
|
idField: "id",
|
|
383
382
|
});
|
|
384
383
|
|
|
385
|
-
const fxGetImagesFromXlsx = (args) => callSync("sxGetImagesFromXlsx", args);
|
|
384
|
+
// const fxGetImagesFromXlsx = (args) => callSync("sxGetImagesFromXlsx", args);
|
|
386
385
|
|
|
387
386
|
export const Syncit = {
|
|
388
387
|
fxFetch,
|
|
@@ -400,5 +399,5 @@ export const Syncit = {
|
|
|
400
399
|
fxDocs,
|
|
401
400
|
fxForms,
|
|
402
401
|
fxGmail,
|
|
403
|
-
fxGetImagesFromXlsx
|
|
402
|
+
// fxGetImagesFromXlsx
|
|
404
403
|
};
|