@truto/truto-jsonata 1.0.11 → 1.0.13
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/dist/main.cjs +37 -15
- package/dist/main.cjs.map +1 -1
- package/dist/module.js +40 -16
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/main.cjs
CHANGED
|
@@ -12,10 +12,8 @@ var $dxT2C$mime = require("mime");
|
|
|
12
12
|
var $dxT2C$pmap = require("p-map");
|
|
13
13
|
var $dxT2C$pretry = require("p-retry");
|
|
14
14
|
var $dxT2C$officeparser = require("officeparser");
|
|
15
|
-
var $dxT2C$filetype = require("file-type");
|
|
16
15
|
var $dxT2C$pdfjsserverless = require("pdfjs-serverless");
|
|
17
16
|
var $dxT2C$langchaintextsplitters = require("@langchain/textsplitters");
|
|
18
|
-
var $dxT2C$nodestreamweb = require("node:stream/web");
|
|
19
17
|
|
|
20
18
|
function $parcel$interopDefault(a) {
|
|
21
19
|
return a && a.__esModule ? a.default : a;
|
|
@@ -1410,6 +1408,17 @@ var $caaee789061bb8bb$export$2e2bcd8739ae039 = $caaee789061bb8bb$var$generateEmb
|
|
|
1410
1408
|
|
|
1411
1409
|
|
|
1412
1410
|
|
|
1411
|
+
async function $0f748d6318103cdf$var$bufferToString(value, encoding) {
|
|
1412
|
+
if (value instanceof ReadableStream) {
|
|
1413
|
+
const chunks = [];
|
|
1414
|
+
for await (const chunk of value)chunks.push(Buffer.from(chunk));
|
|
1415
|
+
const buffer = Buffer.concat(chunks);
|
|
1416
|
+
return buffer.toString(encoding);
|
|
1417
|
+
}
|
|
1418
|
+
return value.toString(encoding);
|
|
1419
|
+
}
|
|
1420
|
+
var $0f748d6318103cdf$export$2e2bcd8739ae039 = $0f748d6318103cdf$var$bufferToString;
|
|
1421
|
+
|
|
1413
1422
|
|
|
1414
1423
|
async function $05e3378f7c17d263$var$parsePdf(buffer) {
|
|
1415
1424
|
const data = buffer.buffer.slice(buffer?.byteOffset, buffer?.byteOffset + buffer?.byteLength);
|
|
@@ -1434,16 +1443,23 @@ async function $05e3378f7c17d263$var$parsePdf(buffer) {
|
|
|
1434
1443
|
// Return the results as JSON
|
|
1435
1444
|
return (0, $dxT2C$lodashes.join)(output, "\n");
|
|
1436
1445
|
}
|
|
1437
|
-
async function $05e3378f7c17d263$var$parseDocument(file) {
|
|
1438
|
-
|
|
1446
|
+
async function $05e3378f7c17d263$var$parseDocument(file, fileType) {
|
|
1447
|
+
let buffer;
|
|
1448
|
+
if (file instanceof ReadableStream) {
|
|
1439
1449
|
const chunks = [];
|
|
1440
1450
|
for await (const chunk of file)chunks.push(Buffer.from(chunk));
|
|
1441
|
-
|
|
1442
|
-
const fileExt = (await (0, $dxT2C$filetype.fileTypeFromBuffer)(buffer))?.ext;
|
|
1443
|
-
if (fileExt === "pdf") return await $05e3378f7c17d263$var$parsePdf(buffer);
|
|
1444
|
-
return await (0, $dxT2C$officeparser.parseOfficeAsync)(buffer);
|
|
1451
|
+
buffer = Buffer.concat(chunks);
|
|
1445
1452
|
}
|
|
1446
|
-
|
|
1453
|
+
if ((0, $dxT2C$lodashes.includes)([
|
|
1454
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
1455
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
1456
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
1457
|
+
"application/vnd.oasis.opendocument.text",
|
|
1458
|
+
"application/vnd.oasis.opendocument.presentation",
|
|
1459
|
+
"application/vnd.oasis.opendocument.spreadsheet"
|
|
1460
|
+
], fileType)) return await (0, $dxT2C$officeparser.parseOfficeAsync)(buffer);
|
|
1461
|
+
if (fileType === "application/pdf") return await $05e3378f7c17d263$var$parsePdf(buffer);
|
|
1462
|
+
return (0, $0f748d6318103cdf$export$2e2bcd8739ae039)(buffer, "utf-8");
|
|
1447
1463
|
}
|
|
1448
1464
|
var $05e3378f7c17d263$export$2e2bcd8739ae039 = $05e3378f7c17d263$var$parseDocument;
|
|
1449
1465
|
|
|
@@ -1458,27 +1474,31 @@ function $fe4dcef142601b8c$export$e600492876ee595b(text, options = {
|
|
|
1458
1474
|
}
|
|
1459
1475
|
|
|
1460
1476
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
if (file instanceof (0, $dxT2C$nodestreamweb.ReadableStream)) {
|
|
1477
|
+
async function $15c432f5f036a88a$var$getDataUri(file, mimeType) {
|
|
1478
|
+
if (!mimeType) throw new Error("Mime type is required");
|
|
1479
|
+
if (file instanceof ReadableStream) {
|
|
1465
1480
|
const chunks = [];
|
|
1466
1481
|
for await (const chunk of file)chunks.push(Buffer.from(chunk));
|
|
1467
1482
|
const buffer = Buffer.concat(chunks);
|
|
1468
1483
|
const base64Image = buffer.toString("base64");
|
|
1469
|
-
const mimeType = (await (0, $dxT2C$filetype.fileTypeFromBuffer)(buffer))?.mime;
|
|
1470
1484
|
// Construct the data URI for a PNG image
|
|
1471
1485
|
return `data:${mimeType};base64,${base64Image}`;
|
|
1472
1486
|
}
|
|
1473
1487
|
const arrayBuffer = file instanceof Blob ? await file.arrayBuffer() : file;
|
|
1474
1488
|
const buffer = Buffer.from(arrayBuffer);
|
|
1475
1489
|
const base64Image = buffer.toString("base64");
|
|
1476
|
-
const mimeType = (await (0, $dxT2C$filetype.fileTypeFromBuffer)(buffer))?.mime;
|
|
1477
1490
|
return `data:${mimeType};base64,${base64Image}`;
|
|
1478
1491
|
}
|
|
1479
1492
|
var $15c432f5f036a88a$export$2e2bcd8739ae039 = $15c432f5f036a88a$var$getDataUri;
|
|
1480
1493
|
|
|
1481
1494
|
|
|
1495
|
+
async function $9a2529096849a04f$var$teeStream(stream) {
|
|
1496
|
+
return stream.tee();
|
|
1497
|
+
}
|
|
1498
|
+
var $9a2529096849a04f$export$2e2bcd8739ae039 = $9a2529096849a04f$var$teeStream;
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
|
|
1482
1502
|
function $af351c41b7fd6f79$export$2e2bcd8739ae039(expression) {
|
|
1483
1503
|
expression.registerFunction("dtFromIso", (0, $bab42b5e4be720d3$export$2e2bcd8739ae039));
|
|
1484
1504
|
expression.registerFunction("base64decode", (0, $77081a2d6d46cd50$export$2e2bcd8739ae039));
|
|
@@ -1559,6 +1579,8 @@ function $af351c41b7fd6f79$export$2e2bcd8739ae039(expression) {
|
|
|
1559
1579
|
expression.registerFunction("parseDocument", (0, $05e3378f7c17d263$export$2e2bcd8739ae039));
|
|
1560
1580
|
expression.registerFunction("recursiveCharacterTextSplitter", (0, $fe4dcef142601b8c$export$e600492876ee595b));
|
|
1561
1581
|
expression.registerFunction("getDataUri", (0, $15c432f5f036a88a$export$2e2bcd8739ae039));
|
|
1582
|
+
expression.registerFunction("teeStream", (0, $9a2529096849a04f$export$2e2bcd8739ae039));
|
|
1583
|
+
expression.registerFunction("bufferToString", (0, $0f748d6318103cdf$export$2e2bcd8739ae039));
|
|
1562
1584
|
return expression;
|
|
1563
1585
|
}
|
|
1564
1586
|
|