@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/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $hgUW1$jsonata from "jsonata";
|
|
2
|
-
import {difference as $hgUW1$difference, groupBy as $hgUW1$groupBy, castArray as $hgUW1$castArray, keyBy as $hgUW1$keyBy, pick as $hgUW1$pick, omit as $hgUW1$omit, compact as $hgUW1$compact, join as $hgUW1$join, orderBy as $hgUW1$orderBy, find as $hgUW1$find, filter as $hgUW1$filter, values as $hgUW1$values, chunk as $hgUW1$chunk, reduce as $hgUW1$reduce, each as $hgUW1$each, get as $hgUW1$get, isEmpty as $hgUW1$isEmpty, concat as $hgUW1$concat, isEqual as $hgUW1$isEqual, flatMap as $hgUW1$flatMap, map as $hgUW1$map, set as $hgUW1$set, isString as $hgUW1$isString, flattenDeep as $hgUW1$flattenDeep, sortBy as $hgUW1$sortBy, repeat as $hgUW1$repeat, flatten as $hgUW1$flatten, reject as $hgUW1$reject, isNil as $hgUW1$isNil, isFunction as $hgUW1$isFunction, toNumber as $hgUW1$toNumber} from "lodash-es";
|
|
2
|
+
import {difference as $hgUW1$difference, groupBy as $hgUW1$groupBy, castArray as $hgUW1$castArray, keyBy as $hgUW1$keyBy, pick as $hgUW1$pick, omit as $hgUW1$omit, compact as $hgUW1$compact, join as $hgUW1$join, orderBy as $hgUW1$orderBy, find as $hgUW1$find, filter as $hgUW1$filter, values as $hgUW1$values, chunk as $hgUW1$chunk, reduce as $hgUW1$reduce, each as $hgUW1$each, get as $hgUW1$get, isEmpty as $hgUW1$isEmpty, concat as $hgUW1$concat, isEqual as $hgUW1$isEqual, flatMap as $hgUW1$flatMap, map as $hgUW1$map, set as $hgUW1$set, isString as $hgUW1$isString, flattenDeep as $hgUW1$flattenDeep, sortBy as $hgUW1$sortBy, repeat as $hgUW1$repeat, flatten as $hgUW1$flatten, reject as $hgUW1$reject, isNil as $hgUW1$isNil, isFunction as $hgUW1$isFunction, toNumber as $hgUW1$toNumber, includes as $hgUW1$includes} from "lodash-es";
|
|
3
3
|
import {DateTime as $hgUW1$DateTime} from "luxon";
|
|
4
4
|
import {Lexer as $hgUW1$Lexer, marked as $hgUW1$marked} from "marked";
|
|
5
5
|
import {diceCoefficient as $hgUW1$diceCoefficient} from "dice-coefficient";
|
|
@@ -13,10 +13,8 @@ import $hgUW1$pmap from "p-map";
|
|
|
13
13
|
import $hgUW1$pretry from "p-retry";
|
|
14
14
|
import {Buffer as $hgUW1$Buffer} from "buffer";
|
|
15
15
|
import {parseOfficeAsync as $hgUW1$parseOfficeAsync} from "officeparser";
|
|
16
|
-
import {fileTypeFromBuffer as $hgUW1$fileTypeFromBuffer} from "file-type";
|
|
17
16
|
import {resolvePDFJS as $hgUW1$resolvePDFJS} from "pdfjs-serverless";
|
|
18
17
|
import {RecursiveCharacterTextSplitter as $hgUW1$RecursiveCharacterTextSplitter} from "@langchain/textsplitters";
|
|
19
|
-
import {ReadableStream as $hgUW1$ReadableStream} from "node:stream/web";
|
|
20
18
|
|
|
21
19
|
function $parcel$interopDefault(a) {
|
|
22
20
|
return a && a.__esModule ? a.default : a;
|
|
@@ -1402,6 +1400,19 @@ var $bf2fdaa075f6a5e5$export$2e2bcd8739ae039 = $bf2fdaa075f6a5e5$var$generateEmb
|
|
|
1402
1400
|
|
|
1403
1401
|
|
|
1404
1402
|
|
|
1403
|
+
var $65fc862361d7fe06$require$Buffer = $hgUW1$Buffer;
|
|
1404
|
+
async function $65fc862361d7fe06$var$bufferToString(value, encoding) {
|
|
1405
|
+
if (value instanceof ReadableStream) {
|
|
1406
|
+
const chunks = [];
|
|
1407
|
+
for await (const chunk of value)chunks.push($65fc862361d7fe06$require$Buffer.from(chunk));
|
|
1408
|
+
const buffer = $65fc862361d7fe06$require$Buffer.concat(chunks);
|
|
1409
|
+
return buffer.toString(encoding);
|
|
1410
|
+
}
|
|
1411
|
+
return value.toString(encoding);
|
|
1412
|
+
}
|
|
1413
|
+
var $65fc862361d7fe06$export$2e2bcd8739ae039 = $65fc862361d7fe06$var$bufferToString;
|
|
1414
|
+
|
|
1415
|
+
|
|
1405
1416
|
|
|
1406
1417
|
var $f29f00a7536a3143$require$Buffer = $hgUW1$Buffer;
|
|
1407
1418
|
async function $f29f00a7536a3143$var$parsePdf(buffer) {
|
|
@@ -1427,16 +1438,23 @@ async function $f29f00a7536a3143$var$parsePdf(buffer) {
|
|
|
1427
1438
|
// Return the results as JSON
|
|
1428
1439
|
return (0, $hgUW1$join)(output, "\n");
|
|
1429
1440
|
}
|
|
1430
|
-
async function $f29f00a7536a3143$var$parseDocument(file) {
|
|
1431
|
-
|
|
1441
|
+
async function $f29f00a7536a3143$var$parseDocument(file, fileType) {
|
|
1442
|
+
let buffer;
|
|
1443
|
+
if (file instanceof ReadableStream) {
|
|
1432
1444
|
const chunks = [];
|
|
1433
1445
|
for await (const chunk of file)chunks.push($f29f00a7536a3143$require$Buffer.from(chunk));
|
|
1434
|
-
|
|
1435
|
-
const fileExt = (await (0, $hgUW1$fileTypeFromBuffer)(buffer))?.ext;
|
|
1436
|
-
if (fileExt === "pdf") return await $f29f00a7536a3143$var$parsePdf(buffer);
|
|
1437
|
-
return await (0, $hgUW1$parseOfficeAsync)(buffer);
|
|
1446
|
+
buffer = $f29f00a7536a3143$require$Buffer.concat(chunks);
|
|
1438
1447
|
}
|
|
1439
|
-
|
|
1448
|
+
if ((0, $hgUW1$includes)([
|
|
1449
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
1450
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
1451
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
1452
|
+
"application/vnd.oasis.opendocument.text",
|
|
1453
|
+
"application/vnd.oasis.opendocument.presentation",
|
|
1454
|
+
"application/vnd.oasis.opendocument.spreadsheet"
|
|
1455
|
+
], fileType)) return await (0, $hgUW1$parseOfficeAsync)(buffer);
|
|
1456
|
+
if (fileType === "application/pdf") return await $f29f00a7536a3143$var$parsePdf(buffer);
|
|
1457
|
+
return (0, $65fc862361d7fe06$export$2e2bcd8739ae039)(buffer, "utf-8");
|
|
1440
1458
|
}
|
|
1441
1459
|
var $f29f00a7536a3143$export$2e2bcd8739ae039 = $f29f00a7536a3143$var$parseDocument;
|
|
1442
1460
|
|
|
@@ -1452,28 +1470,32 @@ function $a12871c9a32cbf3b$export$e600492876ee595b(text, options = {
|
|
|
1452
1470
|
|
|
1453
1471
|
|
|
1454
1472
|
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
1473
|
var $6b4f9d8bcf8ab446$require$Buffer = $hgUW1$Buffer;
|
|
1458
|
-
async function $6b4f9d8bcf8ab446$var$getDataUri(file) {
|
|
1459
|
-
if (
|
|
1474
|
+
async function $6b4f9d8bcf8ab446$var$getDataUri(file, mimeType) {
|
|
1475
|
+
if (!mimeType) throw new Error("Mime type is required");
|
|
1476
|
+
if (file instanceof ReadableStream) {
|
|
1460
1477
|
const chunks = [];
|
|
1461
1478
|
for await (const chunk of file)chunks.push($6b4f9d8bcf8ab446$require$Buffer.from(chunk));
|
|
1462
1479
|
const buffer = $6b4f9d8bcf8ab446$require$Buffer.concat(chunks);
|
|
1463
1480
|
const base64Image = buffer.toString("base64");
|
|
1464
|
-
const mimeType = (await (0, $hgUW1$fileTypeFromBuffer)(buffer))?.mime;
|
|
1465
1481
|
// Construct the data URI for a PNG image
|
|
1466
1482
|
return `data:${mimeType};base64,${base64Image}`;
|
|
1467
1483
|
}
|
|
1468
1484
|
const arrayBuffer = file instanceof Blob ? await file.arrayBuffer() : file;
|
|
1469
1485
|
const buffer = $6b4f9d8bcf8ab446$require$Buffer.from(arrayBuffer);
|
|
1470
1486
|
const base64Image = buffer.toString("base64");
|
|
1471
|
-
const mimeType = (await (0, $hgUW1$fileTypeFromBuffer)(buffer))?.mime;
|
|
1472
1487
|
return `data:${mimeType};base64,${base64Image}`;
|
|
1473
1488
|
}
|
|
1474
1489
|
var $6b4f9d8bcf8ab446$export$2e2bcd8739ae039 = $6b4f9d8bcf8ab446$var$getDataUri;
|
|
1475
1490
|
|
|
1476
1491
|
|
|
1492
|
+
async function $5e08a3608e719b52$var$teeStream(stream) {
|
|
1493
|
+
return stream.tee();
|
|
1494
|
+
}
|
|
1495
|
+
var $5e08a3608e719b52$export$2e2bcd8739ae039 = $5e08a3608e719b52$var$teeStream;
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1477
1499
|
function $3e1c03caddb74419$export$2e2bcd8739ae039(expression) {
|
|
1478
1500
|
expression.registerFunction("dtFromIso", (0, $9e00534fc92334a4$export$2e2bcd8739ae039));
|
|
1479
1501
|
expression.registerFunction("base64decode", (0, $52da679a67e0b066$export$2e2bcd8739ae039));
|
|
@@ -1554,6 +1576,8 @@ function $3e1c03caddb74419$export$2e2bcd8739ae039(expression) {
|
|
|
1554
1576
|
expression.registerFunction("parseDocument", (0, $f29f00a7536a3143$export$2e2bcd8739ae039));
|
|
1555
1577
|
expression.registerFunction("recursiveCharacterTextSplitter", (0, $a12871c9a32cbf3b$export$e600492876ee595b));
|
|
1556
1578
|
expression.registerFunction("getDataUri", (0, $6b4f9d8bcf8ab446$export$2e2bcd8739ae039));
|
|
1579
|
+
expression.registerFunction("teeStream", (0, $5e08a3608e719b52$export$2e2bcd8739ae039));
|
|
1580
|
+
expression.registerFunction("bufferToString", (0, $65fc862361d7fe06$export$2e2bcd8739ae039));
|
|
1557
1581
|
return expression;
|
|
1558
1582
|
}
|
|
1559
1583
|
|