@dnax/core 0.16.1 → 0.16.3

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/app/hono.ts CHANGED
@@ -583,4 +583,4 @@ function HonoInstance(): typeof app {
583
583
  return app;
584
584
  }
585
585
 
586
- export { HonoInstance };
586
+ export { HonoInstance, app };
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 };
@@ -3,6 +3,7 @@ import { Glob } from "bun";
3
3
  import { Cfg } from "../../config";
4
4
  import path from "path";
5
5
  import type { cronConfig } from "../../types";
6
+ import { app } from "../../app/hono";
6
7
  import cleanDeep from "clean-deep";
7
8
  import { useRest } from "../../driver/mongo";
8
9
  async function initScript() {
@@ -21,6 +22,7 @@ async function initScript() {
21
22
  if (scriptInject?.ok && scriptInject?.enabled) {
22
23
  setTimeout(() => {
23
24
  scriptInject.exec({
25
+ router: app,
24
26
  io: Cfg.io,
25
27
  rest: new useRest({
26
28
  tenant_id: t.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.16.1",
3
+ "version": "0.16.3",
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.0",
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.4.15",
50
+ "mingo": "^6.5.0",
49
51
  "moment": "^2.30.1",
50
- "mongodb": "^6.10.0",
52
+ "mongodb": "^6.11.0",
51
53
  "nodemailer": "^6.9.14",
52
- "ollama": "^0.5.9",
53
- "openai": "^4.72.0",
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.18.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",
package/types/index.ts CHANGED
@@ -3,6 +3,7 @@ import { Cron } from "croner";
3
3
  import { updateParams } from "./../driver/mongo/@types";
4
4
  import * as v from "valibot";
5
5
  import type { Db, MongoClient } from "mongodb";
6
+
6
7
  import { useRest } from "../driver/mongo/rest";
7
8
  import { sessionStorage } from "../lib/asyncLocalStorage";
8
9
  import type { Context, Hono } from "hono";
@@ -480,7 +481,11 @@ export type routeCtx = {
480
481
 
481
482
  type scriptCtx = {
482
483
  enabled: boolean;
483
- exec: (ctx: { rest: InstanceType<typeof useRest>; io: socketIoType }) => any;
484
+ exec: (ctx: {
485
+ rest: InstanceType<typeof useRest>;
486
+ io: socketIoType;
487
+ router: Hono;
488
+ }) => any;
484
489
  };
485
490
 
486
491
  export type Endpoint = endpointCtx;