@dnax/core 0.16.2 → 0.16.4
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/index.ts +3 -1
- package/lib/docs/index.ts +109 -0
- package/lib/socket/instance.ts +4 -2
- package/package.json +10 -7
package/index.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { MongoClient, useRest } from "./driver/mongo";
|
|
|
3
3
|
import { toBson } from "./driver/mongo/utils";
|
|
4
4
|
import { runApp } from "./app";
|
|
5
5
|
import Joi from "joi";
|
|
6
|
+
import { $ } from "bun";
|
|
6
7
|
import define from "./define";
|
|
7
8
|
import * as utils from "./utils";
|
|
8
9
|
import { searchEngine } from "./lib/orama";
|
|
9
10
|
import { dataCache } from "./lib/bento";
|
|
10
11
|
import { ai } from "./lib/ai";
|
|
11
12
|
import { crypt } from "./lib/crypto";
|
|
13
|
+
import { Document as document } from "./lib/docs";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* v is internal data validation and based of Joi validation.
|
|
@@ -17,4 +19,4 @@ import { crypt } from "./lib/crypto";
|
|
|
17
19
|
*/
|
|
18
20
|
const v = Joi;
|
|
19
21
|
|
|
20
|
-
export { runApp, define, utils, useRest, v, dataCache, ai, crypt };
|
|
22
|
+
export { runApp, define, utils, useRest, v, dataCache, ai, crypt, document, $ };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import Docxtemplater from "docxtemplater";
|
|
2
|
+
import PizZip from "pizzip";
|
|
3
|
+
import libre from "libreoffice-convert";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
const convertToPdf = (docBuffer: any) => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
libre.convert(docBuffer, ".pdf", undefined, (err, done) => {
|
|
10
|
+
if (err) reject(err);
|
|
11
|
+
else resolve(done);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type optionTypeBuffer = {
|
|
17
|
+
/**
|
|
18
|
+
* default is "nodebuffer"
|
|
19
|
+
@default "nodebuffer"
|
|
20
|
+
*/
|
|
21
|
+
type?: "nodebuffer" | "base64" | "blob" | "arraybuffer" | "base64";
|
|
22
|
+
compression?: "DEFLATE" | "STORE";
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type documentConfig = {
|
|
26
|
+
dir: string;
|
|
27
|
+
delimiters?: { start: string; end: string };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class Document {
|
|
31
|
+
dir?: string | null;
|
|
32
|
+
delimiters?: { start?: string; end?: string };
|
|
33
|
+
constructor(config?: documentConfig) {
|
|
34
|
+
this.dir = config?.dir || null;
|
|
35
|
+
this.delimiters = config?.delimiters || { start: "{{", end: "}}" };
|
|
36
|
+
}
|
|
37
|
+
getBuffer(file: string, tags?: object, options?: optionTypeBuffer): Buffer {
|
|
38
|
+
let pathfile = "";
|
|
39
|
+
if (!this?.dir) {
|
|
40
|
+
pathfile = path.resolve(file);
|
|
41
|
+
} else {
|
|
42
|
+
path?.resolve(this.dir + file);
|
|
43
|
+
}
|
|
44
|
+
let templateFile = fs.readFileSync(pathfile, "binary");
|
|
45
|
+
let zip = new PizZip(templateFile);
|
|
46
|
+
let doc = new Docxtemplater(zip, {
|
|
47
|
+
paragraphLoop: true,
|
|
48
|
+
linebreaks: true,
|
|
49
|
+
delimiters: {
|
|
50
|
+
start: this.delimiters?.start || "{{",
|
|
51
|
+
end: this.delimiters?.end || "}}",
|
|
52
|
+
},
|
|
53
|
+
nullGetter: () => {
|
|
54
|
+
return "";
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (tags) {
|
|
59
|
+
doc.render(tags);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let buffer = doc.getZip().generate({
|
|
63
|
+
type: "nodebuffer",
|
|
64
|
+
compression: "DEFLATE",
|
|
65
|
+
});
|
|
66
|
+
return buffer;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getPdfBuffer(file: string, tags?: object, options?: optionTypeBuffer) {
|
|
70
|
+
let pathfile = "";
|
|
71
|
+
if (!this?.dir) {
|
|
72
|
+
pathfile = path.resolve(file);
|
|
73
|
+
} else {
|
|
74
|
+
path?.resolve(this.dir + file);
|
|
75
|
+
}
|
|
76
|
+
let templateFile = fs.readFileSync(pathfile, "binary");
|
|
77
|
+
let zip = new PizZip(templateFile);
|
|
78
|
+
let doc = new Docxtemplater(zip, {
|
|
79
|
+
paragraphLoop: true,
|
|
80
|
+
linebreaks: true,
|
|
81
|
+
delimiters: {
|
|
82
|
+
start: this.delimiters?.start || "{{",
|
|
83
|
+
end: this.delimiters?.end || "}}",
|
|
84
|
+
},
|
|
85
|
+
nullGetter: () => {
|
|
86
|
+
return "";
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (tags) {
|
|
91
|
+
doc.render(tags);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let docBuffer = doc.getZip().generate({
|
|
95
|
+
type: "nodebuffer",
|
|
96
|
+
compression: "DEFLATE",
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const pdfBuffer = await convertToPdf(docBuffer);
|
|
100
|
+
|
|
101
|
+
return pdfBuffer;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
saveTo(path: string, buffer: Buffer) {
|
|
105
|
+
fs.writeFileSync(path, buffer);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { Document };
|
package/lib/socket/instance.ts
CHANGED
|
@@ -75,9 +75,9 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
75
75
|
let id = v4();
|
|
76
76
|
ws.id = id;
|
|
77
77
|
wsClients.set(id, ws);
|
|
78
|
+
|
|
78
79
|
// set Id to client and emit it
|
|
79
80
|
ws.send(JSON.stringify({ type: "setId", id: id }));
|
|
80
|
-
|
|
81
81
|
// run all listenners event for connection
|
|
82
82
|
let evs = wsEvents.filter(
|
|
83
83
|
(e) => e.type == "on" && e?.event == "connection"
|
|
@@ -113,13 +113,15 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
+
|
|
117
|
+
wsClients?.delete(ws.id);
|
|
116
118
|
// console.log("close", code, reason);
|
|
117
119
|
// console.log(ws.id);
|
|
118
120
|
},
|
|
119
121
|
message: (ws, message: any) => {
|
|
120
122
|
try {
|
|
121
123
|
let options: optionsIo = JSON.parse(message);
|
|
122
|
-
|
|
124
|
+
|
|
123
125
|
// find all listeners : On
|
|
124
126
|
let evs = wsEvents.filter(
|
|
125
127
|
(e) => e.event == options?.event && e?.type == "on"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@clack/prompts": "^0.7.0",
|
|
22
22
|
"@colors/colors": "^1.6.0",
|
|
23
23
|
"@lukeed/ms": "^2.0.2",
|
|
24
|
-
"@mistralai/mistralai": "^1.3.
|
|
24
|
+
"@mistralai/mistralai": "^1.3.4",
|
|
25
25
|
"@orama/orama": "^2.0.23",
|
|
26
26
|
"@types/dot-object": "^2.1.6",
|
|
27
27
|
"@types/jsonwebtoken": "^9.0.6",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"cookie": "^0.6.0",
|
|
36
36
|
"croner": "^8.1.1",
|
|
37
37
|
"deepcopy": "^2.1.0",
|
|
38
|
+
"docxtemplater": "^3.54.1",
|
|
38
39
|
"dot-object": "^2.1.5",
|
|
39
40
|
"find-open-port": "^2.0.3",
|
|
40
41
|
"fs-extra": "^11.2.0",
|
|
@@ -44,18 +45,20 @@
|
|
|
44
45
|
"joi": "^17.13.3",
|
|
45
46
|
"json-joy": "16.8.0",
|
|
46
47
|
"jsonwebtoken": "^9.0.2",
|
|
48
|
+
"libreoffice-convert": "^1.6.0",
|
|
47
49
|
"mime-types": "^2.1.35",
|
|
48
|
-
"mingo": "^6.
|
|
50
|
+
"mingo": "^6.5.0",
|
|
49
51
|
"moment": "^2.30.1",
|
|
50
|
-
"mongodb": "^6.
|
|
52
|
+
"mongodb": "^6.11.0",
|
|
51
53
|
"nodemailer": "^6.9.14",
|
|
52
|
-
"ollama": "^0.5.
|
|
53
|
-
"openai": "^4.
|
|
54
|
+
"ollama": "^0.5.10",
|
|
55
|
+
"openai": "^4.73.1",
|
|
54
56
|
"pidusage": "^3.0.2",
|
|
57
|
+
"pizzip": "^3.1.7",
|
|
55
58
|
"radash": "^12.1.0",
|
|
56
59
|
"rfc6902": "^5.1.2",
|
|
57
60
|
"sharp": "^0.33.5",
|
|
58
|
-
"signaldb": "^0.
|
|
61
|
+
"signaldb": "^0.24.0",
|
|
59
62
|
"socket.io": "^4.8.1",
|
|
60
63
|
"ufo": "^1.5.3",
|
|
61
64
|
"urlencode": "^2.0.0",
|