emilsoftware-utilities 2.0.0-dev.1 → 2.0.0-dev.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.
Files changed (95) hide show
  1. package/README.MD +38 -38
  2. package/dist/ContractGenerator.js.map +1 -1
  3. package/dist/DatabaseUpdater.js +24 -24
  4. package/dist/DatabaseUpdater.js.map +1 -1
  5. package/dist/EmilsoftwareModule.js.map +1 -1
  6. package/dist/ExecutionTimeLogger.js.map +1 -1
  7. package/dist/Logger.js.map +1 -1
  8. package/dist/Orm.d.ts +5 -0
  9. package/dist/Orm.js +149 -57
  10. package/dist/Orm.js.map +1 -1
  11. package/dist/RoutesLoggerMiddleware.js.map +1 -1
  12. package/dist/Utilities.d.ts +2 -2
  13. package/dist/Utilities.js +4 -0
  14. package/dist/Utilities.js.map +1 -1
  15. package/dist/accessi-module/AccessiModule.js.map +1 -1
  16. package/dist/accessi-module/Controllers/AuthController.js.map +1 -1
  17. package/dist/accessi-module/Controllers/ConfiguratorController.js.map +1 -1
  18. package/dist/accessi-module/Controllers/EmailController.js.map +1 -1
  19. package/dist/accessi-module/Controllers/FiltriController.js.map +1 -1
  20. package/dist/accessi-module/Controllers/PermissionController.js.map +1 -1
  21. package/dist/accessi-module/Controllers/UserController.js.map +1 -1
  22. package/dist/accessi-module/Dtos/Abilitazione.js.map +1 -1
  23. package/dist/accessi-module/Dtos/AbilitazioneMenu.js.map +1 -1
  24. package/dist/accessi-module/Dtos/AssignPermissionsToUserRequest.js.map +1 -1
  25. package/dist/accessi-module/Dtos/AssignRolesToUserRequest.js.map +1 -1
  26. package/dist/accessi-module/Dtos/BaseResponse.js.map +1 -1
  27. package/dist/accessi-module/Dtos/FiltriUtente.js.map +1 -1
  28. package/dist/accessi-module/Dtos/GetGroupsWithMenusResponse.js.map +1 -1
  29. package/dist/accessi-module/Dtos/GetMenusResponse.js.map +1 -1
  30. package/dist/accessi-module/Dtos/GetRolesResponse.js.map +1 -1
  31. package/dist/accessi-module/Dtos/GetUsersResponse.js.map +1 -1
  32. package/dist/accessi-module/Dtos/LoginRequest.js.map +1 -1
  33. package/dist/accessi-module/Dtos/LoginResponse.js.map +1 -1
  34. package/dist/accessi-module/Dtos/Permission.js.map +1 -1
  35. package/dist/accessi-module/Dtos/RegisterRequest.js.map +1 -1
  36. package/dist/accessi-module/Dtos/RegisterResponse.js.map +1 -1
  37. package/dist/accessi-module/Dtos/Role.js.map +1 -1
  38. package/dist/accessi-module/Dtos/RuoliMenu.js.map +1 -1
  39. package/dist/accessi-module/Dtos/SetStatoRegistrazione.js.map +1 -1
  40. package/dist/accessi-module/Dtos/StatoRegistrazione.js.map +1 -1
  41. package/dist/accessi-module/Dtos/TipoAbilitazione.js.map +1 -1
  42. package/dist/accessi-module/Dtos/TipoFiltro.js.map +1 -1
  43. package/dist/accessi-module/Dtos/TokenResult.js.map +1 -1
  44. package/dist/accessi-module/Dtos/UpdateEnabledStatusRequest.js.map +1 -1
  45. package/dist/accessi-module/Dtos/UserDto.js.map +1 -1
  46. package/dist/accessi-module/Dtos/UserGrantsDto.js.map +1 -1
  47. package/dist/accessi-module/Dtos/index.js.map +1 -1
  48. package/dist/accessi-module/Services/AuthService/AuthService.d.ts +1 -0
  49. package/dist/accessi-module/Services/AuthService/AuthService.js +12 -2
  50. package/dist/accessi-module/Services/AuthService/AuthService.js.map +1 -1
  51. package/dist/accessi-module/Services/ConfiguratorService/ConfiguratorService.js.map +1 -1
  52. package/dist/accessi-module/Services/EmailService/EmailService.js +11 -11
  53. package/dist/accessi-module/Services/EmailService/EmailService.js.map +1 -1
  54. package/dist/accessi-module/Services/FiltriService/FiltriService.js +1 -1
  55. package/dist/accessi-module/Services/FiltriService/FiltriService.js.map +1 -1
  56. package/dist/accessi-module/Services/PermissionService/PermissionService.js +87 -87
  57. package/dist/accessi-module/Services/PermissionService/PermissionService.js.map +1 -1
  58. package/dist/accessi-module/Services/UserService/UserService.js +65 -65
  59. package/dist/accessi-module/Services/UserService/UserService.js.map +1 -1
  60. package/dist/accessi-module/Views/reset-password.html +213 -213
  61. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.js +25 -16
  62. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.js.map +1 -1
  63. package/dist/accessi-module/database-updates/runAccessiDbUpdate.js.map +1 -1
  64. package/dist/accessi-module/index.js +16 -1
  65. package/dist/accessi-module/index.js.map +1 -1
  66. package/dist/accessi-module/jwt/jwt.strategy.js.map +1 -1
  67. package/dist/accessi-module/middleware/accessiRequirements.js.map +1 -1
  68. package/dist/accessi-module/middleware/authenticateGen.js.map +1 -1
  69. package/dist/accessi-module/security/accessControl.js.map +1 -1
  70. package/dist/accessi-module/security/authenticatedToken.js.map +1 -1
  71. package/dist/accessi-module/security/passwordResetToken.js.map +1 -1
  72. package/dist/accessi-module/security/publicAuthRateLimit.js.map +1 -1
  73. package/dist/allegati-module/AllegatiModule.js.map +1 -1
  74. package/dist/allegati-module/Controllers/AllegatiController.js.map +1 -1
  75. package/dist/allegati-module/Dtos/AllegatoDto.js.map +1 -1
  76. package/dist/allegati-module/Dtos/BaseResponse.js.map +1 -1
  77. package/dist/allegati-module/Dtos/UploadSingleFileRequest.js.map +1 -1
  78. package/dist/allegati-module/Dtos/index.js.map +1 -1
  79. package/dist/allegati-module/Dtos/responses/DownloadAllegatoResponseDto.js.map +1 -1
  80. package/dist/allegati-module/Dtos/responses/GetListResponse.js.map +1 -1
  81. package/dist/allegati-module/Dtos/responses/UploadAllegatoResponseDto.js.map +1 -1
  82. package/dist/allegati-module/Services/AllegatiService/AllegatiService.js +49 -49
  83. package/dist/allegati-module/Services/AllegatiService/AllegatiService.js.map +1 -1
  84. package/dist/allegati-module/index.js.map +1 -1
  85. package/dist/autobind.js.map +1 -1
  86. package/dist/firebird-compat.d.ts +15 -0
  87. package/dist/firebird-compat.js +198 -0
  88. package/dist/firebird-compat.js.map +1 -0
  89. package/dist/index.d.ts +4 -1
  90. package/dist/index.js +27 -1
  91. package/dist/index.js.map +1 -1
  92. package/dist/initEmilsoftwareModule.js.map +1 -1
  93. package/dist/swagger/SwaggerConfig.js.map +1 -1
  94. package/package.json +83 -83
  95. package/dist/emilsoftware-utilities-2.0.0-dev.1.tgz +0 -0
package/README.MD CHANGED
@@ -1,38 +1,38 @@
1
- Convenzioni per i Commit Message
2
-
3
- 1. feat:
4
- Descrizione: Nuova feature
5
- Esempio: feat: aggiunta endpoint per notifiche
6
- Trigger: MINOR release (es. 1.3.0 -> 1.4.0)
7
- Su dev: 1.4.0-dev.0
8
-
9
- 2. fix:
10
- Descrizione: Correzione di bug
11
- Esempio: fix: gestione errore null in login
12
- Trigger: PATCH release (es. 1.3.1)
13
- Su dev: 1.3.1-dev.0
14
-
15
- 3. BREAKING CHANGE:
16
- Descrizione: Cambiamento che rompe la compatibilità all'indietro
17
- Esempio:
18
- feat!: rimozione supporto legacy
19
- BREAKING CHANGE: cambia lo schema JWT
20
- Trigger: MAJOR release (es. 1.0.0 -> 2.0.0)
21
-
22
- 4. Altri tipi di commit
23
- Esempi: chore:, docs:, test:, refactor:
24
- Descrizione: Non triggerano una release di default, a meno che non siano configurati esplicitamente nel commit-analyzer.
25
- Esempio: chore: aggiorna dipendenze
26
-
27
- 5. Forzare una Release
28
- Descrizione: Utile in caso di merge o altre operazioni.
29
- Comandi:
30
- git commit --allow-empty -m "feat: trigger test release"
31
- Poi:
32
- git push origin dev
33
- Oppure:
34
- git push origin main
35
-
36
- ## Accessi
37
-
38
- La documentazione operativa del modulo accessi si trova in [src/accessi-module/README.md](src/accessi-module/README.md).
1
+ Convenzioni per i Commit Message
2
+
3
+ 1. feat:
4
+ Descrizione: Nuova feature
5
+ Esempio: feat: aggiunta endpoint per notifiche
6
+ Trigger: MINOR release (es. 1.3.0 -> 1.4.0)
7
+ Su dev: 1.4.0-dev.0
8
+
9
+ 2. fix:
10
+ Descrizione: Correzione di bug
11
+ Esempio: fix: gestione errore null in login
12
+ Trigger: PATCH release (es. 1.3.1)
13
+ Su dev: 1.3.1-dev.0
14
+
15
+ 3. BREAKING CHANGE:
16
+ Descrizione: Cambiamento che rompe la compatibilità all'indietro
17
+ Esempio:
18
+ feat!: rimozione supporto legacy
19
+ BREAKING CHANGE: cambia lo schema JWT
20
+ Trigger: MAJOR release (es. 1.0.0 -> 2.0.0)
21
+
22
+ 4. Altri tipi di commit
23
+ Esempi: chore:, docs:, test:, refactor:
24
+ Descrizione: Non triggerano una release di default, a meno che non siano configurati esplicitamente nel commit-analyzer.
25
+ Esempio: chore: aggiorna dipendenze
26
+
27
+ 5. Forzare una Release
28
+ Descrizione: Utile in caso di merge o altre operazioni.
29
+ Comandi:
30
+ git commit --allow-empty -m "feat: trigger test release"
31
+ Poi:
32
+ git push origin dev
33
+ Oppure:
34
+ git push origin main
35
+
36
+ ## Accessi
37
+
38
+ La documentazione operativa del modulo accessi si trova in [src/accessi-module/README.md](src/accessi-module/README.md).
@@ -1 +1 @@
1
- {"version":3,"file":"ContractGenerator.js","sourceRoot":"","sources":["../src/ContractGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iCAA8B;AAC9B,sEAAwC;AACxC,2BAAoC;AACpC,gDAAwB;AA2CxB,SAAe,iBAAiB,CAAC,SAAiB;;QAC9C,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,aAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,cAAc,GAAG,WAAW,MAAM,EAAE,CAAC;IAChD,CAAC;CAAA;AAED,MAAa,iBAAiB;IAO1B,YAAoB,UAAmB;QAAnB,eAAU,GAAV,UAAU,CAAS;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AC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;oBACxC,CAAC;gBACL,CAAC;gBACD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;YACxC,CAAC;YACD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,GAAG,CAAC;YAC1C,MAAM,QAAQ,GAAG,aAAa,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,MAAM,CAAC;YACvE,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;gBACpB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;gBACjD,MAAM,aAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;gBACrD,OAAO,QAAQ,CAAC;YACpB,CAAC;iBAAM,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAC1C,CAAC;iBAAM,CAAC;gBACJ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAC1C,CAAC;QACL,CAAC;KAAA;CACJ;AA5UD,8CA4UC","sourcesContent":["import { jsPDF } from \"jspdf\";\nimport autotable from \"jspdf-autotable\";\nimport { promises as fs } from 'fs';\nimport path from 'path';\n\nexport interface IPartiContratto {\n fornitore: { denominazione: string; codiceFiscale: string; indirizzoCompleto: string; };\n cliente: { denominazione: string; codiceFiscale: string; indirizzoCompleto: string; };\n}\n\nexport interface DocumentParams {\n parti: IPartiContratto;\n tipOutput?: 'f' | 'd' | 'u';\n dynamicFields?: { [key: string]: string };\n dynamicElements?: { [placeholder: string]: DynamicElement };\n}\n\nexport type DynamicElement = {\n type: 'table';\n config: {\n head: string[];\n body: string[][];\n options?: any;\n styles?: any;\n };\n};\n\ninterface DocumentConfig {\n fontTitolo: { nome: string; dimensione: number; colore: string; installPath?: string; };\n fontSottotitolo: { nome: string; dimensione: number; colore: string; installPath?: string; };\n fontTesto: { nome: string; dimensione: number; colore: string; installPath?: string; };\n fontBold: { nome: string; dimensione: number; colore: string; installPath?: string; };\n margini: { sx: number; dx: number; alto: number; basso: number; };\n staccoriga: number;\n rientro: number;\n testi: {\n titolo: string;\n premessa: string;\n Punti: Array<{ titolo: string; Sottopunti: Array<{ titolo: string; contenuto: string; }>; }>;\n versione: string;\n };\n immagini: Array<{ path: string; posizione: [number, number]; dimensioni: [number, number]; coeffDim?: number; }>;\n box: { backgrund: string; raggio: number; };\n tableStyle?: { lineColor?: string; lineWidth?: number; font?: string; fontSize?: number; cellPadding?: number; fillColor?: string; };\n}\n\nasync function loadImageAsBase64(imagePath: string): Promise<string> {\n const absolutePath = path.resolve(imagePath);\n const buffer = await fs.readFile(absolutePath);\n const ext = path.extname(imagePath).slice(1).toLowerCase();\n const base64 = buffer.toString('base64');\n return `data:image/${ext};base64,${base64}`;\n}\n\nexport class DocumentGenerator {\n private config!: DocumentConfig;\n private doc!: jsPDF;\n private curX: number = 0;\n private curY: number = 0;\n private configLoaded: boolean = false;\n\n constructor(private configPath?: string) { }\n\n public setConfig(config: DocumentConfig) {\n this.config = config;\n this.configLoaded = true;\n }\n\n private applyTemplate(template: string, dynamicFields?: { [key: string]: string }): string {\n if (!dynamicFields) return template;\n return template.replace(/\\$(\\w+)\\$/g, (match, key) =>\n dynamicFields[key] !== undefined ? dynamicFields[key] : match\n );\n }\n\n private applyPartiPlaceholders(text: string, parti: IPartiContratto): string {\n return text.replace(/\\$(fornitore|cliente):(\\w+)\\$/g, (match, party, field) =>\n (parti[party] && (parti[party] as any)[field]) ? (parti[party] as any)[field] : match\n );\n }\n\n private async loadConfig(): Promise<void> {\n if (this.configLoaded) return;\n if (!this.configPath) throw new Error(\"No configuration provided.\");\n try {\n const data = await fs.readFile(this.configPath, 'utf8');\n this.config = JSON.parse(data) as DocumentConfig;\n this.configLoaded = true;\n } catch (error) {\n throw new Error(`Error reading configuration file: ${error}`);\n }\n }\n\n private initDoc(): void {\n this.doc = new jsPDF();\n const margins = this.config.margini;\n this.curX = margins.sx;\n this.curY = margins.alto;\n }\n\n private extractPlaceholder(text: string): string | null {\n const match = text.match(/^\\$(\\w+)\\$$/);\n return match ? match[1] : null;\n }\n\n private async installFont(fontPath: string, fontName: string): Promise<void> {\n const absolutePath = path.resolve(fontPath);\n const buffer = await fs.readFile(absolutePath);\n const base64Font = buffer.toString('base64');\n //console.log(`Installing font ${fontName} from ${absolutePath}`);\n this.doc.addFileToVFS(`${fontName}.ttf`, base64Font);\n this.doc.addFont(`${fontName}.ttf`, fontName, 'normal');\n this.doc.setFont(fontName);\n }\n\n // Writes wrapped text, handling inline bold segments.\n private async writeWrappedTextCore(\n fontName: string,\n fontSize: number,\n color: string,\n text: string,\n x: number,\n y: number,\n maxWidth: number,\n lineSpacingFactor: number = 1.15\n ): Promise<number> {\n this.doc.setFont(fontName);\n this.doc.setFontSize(fontSize);\n this.doc.setTextColor(color);\n const lines = this.doc.splitTextToSize(text, maxWidth);\n const lineHeight = (fontSize * lineSpacingFactor / 72) * 25.4;\n for (const line of lines) {\n if (y + lineHeight > (this.doc.internal.pageSize.getHeight() - this.config.margini.basso)) {\n this.doc.addPage();\n y = this.config.margini.alto;\n }\n // If the line contains inline bold markers, process them.\n if (line.includes(\"**\")) {\n y = await this.writeLineWithInlineBold(line, x, y, fontName, fontSize, color, maxWidth, lineSpacingFactor);\n } else {\n this.doc.text(line, x, y);\n y += lineHeight;\n }\n }\n return y;\n }\n\n // Writes a single line with inline bold processing.\n private async writeLineWithInlineBold(\n line: string,\n x: number,\n y: number,\n normalFont: string,\n fontSize: number,\n color: string,\n maxWidth: number,\n lineSpacingFactor: number = 1.15\n ): Promise<number> {\n let currentX = x;\n // Split the line by bold segments. The regex keeps the markers.\n const segments = line.split(/(\\*\\*.*?\\*\\*)/);\n const lineHeight = (fontSize * lineSpacingFactor / 72) * 25.4;\n for (const seg of segments) {\n let segText = seg;\n let useBold = false;\n if (seg.startsWith(\"**\") && seg.endsWith(\"**\")) {\n useBold = true;\n segText = seg.substring(2, seg.length - 2);\n }\n if (useBold) {\n this.doc.setFont(this.config.fontBold.nome);\n } else {\n this.doc.setFont(normalFont);\n }\n this.doc.setFontSize(fontSize);\n this.doc.setTextColor(color);\n const segWidth = this.doc.getTextWidth(segText);\n // Write segment\n this.doc.text(segText, currentX, y);\n currentX += segWidth;\n }\n return y + lineHeight;\n }\n\n private async writeWrappedTextWithFont(\n fontConf: { nome: string; dimensione: number; colore: string; installPath?: string },\n text: string,\n x: number,\n y: number,\n maxWidth: number,\n lineSpacingFactor: number = 1.15\n ): Promise<void> {\n const fontList = this.doc.getFontList();\n if (!fontList[fontConf.nome]) {\n if (fontConf.installPath) await this.installFont(fontConf.installPath, fontConf.nome);\n else throw new Error(\"Font not present and no installPath provided\");\n } else {\n this.doc.setFont(fontConf.nome);\n }\n this.curY = await this.writeWrappedTextCore(fontConf.nome, fontConf.dimensione, fontConf.colore, text, x, y, maxWidth, lineSpacingFactor);\n }\n\n public async writeBoxedText(\n text: string,\n fontConf: { nome: string; dimensione: number; colore: string; installPath?: string },\n padding: number = 5,\n borderRadius: number = 5,\n borderWidth: number = 1,\n boxColor?: string\n ): Promise<void> {\n const fontList = this.doc.getFontList();\n if (!fontList[fontConf.nome]) {\n if (fontConf.installPath) await this.installFont(fontConf.installPath, fontConf.nome);\n else throw new Error(\"Font not present and no installPath provided\");\n } else {\n this.doc.setFont(fontConf.nome);\n }\n this.doc.setFontSize(fontConf.dimensione);\n this.doc.setTextColor(fontConf.colore);\n const pageWidth = this.doc.internal.pageSize.getWidth();\n const maxTextWidth = pageWidth - this.config.margini.sx - this.config.margini.dx - 2 * padding;\n const lines = this.doc.splitTextToSize(text, maxTextWidth);\n const lineHeight = (fontConf.dimensione * 1.15 / 72) * 25.4;\n const textHeight = lines.length * lineHeight;\n const boxX = this.curX;\n const boxY = this.curY;\n const boxWidth = maxTextWidth + 2 * padding;\n const boxHeight = textHeight + 2 * padding;\n if (boxColor) {\n this.doc.setFillColor(boxColor);\n this.doc.roundedRect(boxX, boxY, boxWidth, boxHeight, borderRadius, borderRadius, \"F\");\n }\n this.doc.setLineWidth(borderWidth);\n this.doc.roundedRect(boxX, boxY, boxWidth, boxHeight, borderRadius, borderRadius);\n const textX = boxX + padding;\n let textY = boxY + padding + lineHeight;\n for (const line of lines) {\n if (line.includes(\"**\")) {\n textY = await this.writeLineWithInlineBold(line, textX, textY, fontConf.nome, fontConf.dimensione, fontConf.colore, maxTextWidth, 1.15);\n } else {\n this.doc.text(line, textX, textY);\n textY += lineHeight;\n }\n }\n this.curY = boxY + boxHeight + this.config.staccoriga;\n }\n\n\n // Checks if text is wrapped in '^' markers for boxed text.\n private isBoxedText(text: string): boolean {\n return text.startsWith('^') && text.endsWith('^');\n }\n\n // Removes '^' markers.\n private stripBoxMarkers(text: string): string {\n return text.substring(1, text.length - 1);\n }\n\n // Checks if text is entirely wrapped in '**' markers (not inline).\n // (This function is kept for backward compatibility.)\n private isBoldText(text: string): boolean {\n return text.startsWith('**') && text.endsWith('**');\n }\n\n // Removes '**' markers.\n private stripBoldMarkers(text: string): string {\n return text.substring(2, text.length - 2);\n }\n\n // Inserts images using the current cursor position.\n private async insertLogo(): Promise<void> {\n if (this.config.immagini && this.config.immagini.length > 0) {\n const startX = this.curX;\n for (const imgConf of this.config.immagini) {\n const format = imgConf.path.split('.').pop()?.toUpperCase() || 'PNG';\n const base64Image = await loadImageAsBase64(imgConf.path);\n const startY = this.curY;\n if (startY + imgConf.dimensioni[1] > (this.doc.internal.pageSize.getHeight() - this.config.margini.basso)) {\n this.doc.addPage();\n this.curY = this.config.margini.alto;\n }\n this.doc.addImage(base64Image, format, startX, this.curY, imgConf.dimensioni[0], imgConf.dimensioni[1]);\n //console.log(`Image inserted at X: ${startX}, Y: ${this.curY}`);\n this.curY = this.curY + imgConf.dimensioni[1] + this.config.staccoriga;\n }\n }\n }\n\n // Generates the PDF document by processing images, dynamic fields, tables, and text.\n // Supports inline bold formatting and boxed text.\n public async generateDocument(params: DocumentParams): Promise<string | ArrayBuffer> {\n await this.loadConfig();\n this.initDoc();\n await this.insertLogo();\n const dynamicFields = params.dynamicFields || {};\n const dynamicElements = params.dynamicElements || {};\n const pageWidth = this.doc.internal.pageSize.getWidth();\n const maxWidth = pageWidth - (this.config.margini.sx + this.config.margini.dx);\n let titolo = this.applyTemplate(this.config.testi.titolo, dynamicFields);\n titolo = this.applyPartiPlaceholders(titolo, params.parti);\n await this.writeWrappedTextWithFont(this.config.fontTitolo, titolo, this.curX, this.curY, maxWidth);\n this.curY += this.config.staccoriga;\n let premessa = this.applyTemplate(this.config.testi.premessa, dynamicFields);\n premessa = this.applyPartiPlaceholders(premessa, params.parti);\n await this.writeWrappedTextWithFont(this.config.fontTesto, premessa, this.curX, this.curY, maxWidth);\n this.curY += this.config.staccoriga;\n for (const punto of this.config.testi.Punti) {\n let puntoTitolo = this.applyTemplate(punto.titolo, dynamicFields);\n puntoTitolo = this.applyPartiPlaceholders(puntoTitolo, params.parti);\n await this.writeWrappedTextWithFont(this.config.fontTitolo, puntoTitolo, this.curX, this.curY, maxWidth);\n this.curY += this.config.staccoriga;\n for (const sub of punto.Sottopunti) {\n const placeholder = this.extractPlaceholder(sub.titolo);\n if (placeholder && dynamicElements[placeholder] && dynamicElements[placeholder].type === 'table' && dynamicElements[placeholder].config) {\n const tableConfig = dynamicElements[placeholder].config!;\n const defaultTableOptions = this.config.tableStyle || {};\n autotable(this.doc, {\n startY: this.curY,\n head: [tableConfig.head],\n body: tableConfig.body,\n ...defaultTableOptions,\n ...tableConfig.options,\n ...tableConfig.styles\n });\n this.curY = (this.doc as any).lastAutoTable.finalY + this.config.staccoriga;\n } else {\n if (sub.titolo) {\n let titleText = this.applyTemplate(sub.titolo, dynamicFields);\n titleText = this.applyPartiPlaceholders(titleText, params.parti);\n if (this.isBoxedText(titleText)) {\n const boxText = this.stripBoxMarkers(titleText);\n await this.writeBoxedText(boxText, this.config.fontSottotitolo);\n } else if (this.isBoldText(titleText)) {\n const boldText = this.stripBoldMarkers(titleText);\n\n await this.writeWrappedTextWithFont({ ...this.config.fontSottotitolo, nome: this.config.fontSottotitolo.nome },\n boldText, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\n } else {\n await this.writeWrappedTextWithFont(this.config.fontSottotitolo, titleText, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\n }\n this.curY += this.config.staccoriga;\n }\n }\n const contentPlaceholder = this.extractPlaceholder(sub.contenuto);\n if (contentPlaceholder && dynamicElements[contentPlaceholder] && dynamicElements[contentPlaceholder].type === 'table' && dynamicElements[contentPlaceholder].config) {\n const tableConfig = dynamicElements[contentPlaceholder].config!;\n const defaultTableOptions = this.config.tableStyle || {};\n autotable(this.doc, {\n startY: this.curY,\n head: [tableConfig.head],\n body: tableConfig.body,\n ...defaultTableOptions,\n ...tableConfig.options,\n ...tableConfig.styles\n });\n this.curY = (this.doc as any).lastAutoTable.finalY + this.config.staccoriga;\n } else if (sub.contenuto) {\n let contenuto = this.applyTemplate(sub.contenuto, dynamicFields);\n contenuto = this.applyPartiPlaceholders(contenuto, params.parti);\n if (this.isBoxedText(contenuto)) {\n const boxText = this.stripBoxMarkers(contenuto);\n await this.writeBoxedText(boxText, this.config.fontTesto);\n } else if (this.isBoldText(contenuto)) {\n const boldText = this.stripBoldMarkers(contenuto);\n await this.writeWrappedTextWithFont({ ...this.config.fontTesto, nome: this.config.fontTesto.nome },\n boldText, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\n } else {\n await this.writeWrappedTextWithFont(this.config.fontTesto, contenuto, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\n }\n this.curY += this.config.staccoriga;\n }\n }\n this.curY += this.config.staccoriga;\n }\n const tipOutput = params.tipOutput || 'd';\n const fileName = `Documento_${params.parti.cliente.denominazione}.pdf`;\n if (tipOutput === 'd') {\n const pdfBuffer = this.doc.output('arraybuffer');\n await fs.writeFile(fileName, Buffer.from(pdfBuffer));\n return fileName;\n } else if (tipOutput === 'u') {\n return this.doc.output('arraybuffer');\n } else {\n return this.doc.output('arraybuffer');\n }\n }\n}"]}
1
+ {"version":3,"file":"ContractGenerator.js","sourceRoot":"","sources":["../src/ContractGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iCAA8B;AAC9B,sEAAwC;AACxC,2BAAoC;AACpC,gDAAwB;AA2CxB,SAAe,iBAAiB,CAAC,SAAiB;;QAC9C,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,aAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,cAAc,GAAG,WAAW,MAAM,EAAE,CAAC;IAChD,CAAC;CAAA;AAED,MAAa,iBAAiB;IAO1B,YAAoB,UAAmB;QAAnB,eAAU,GAAV,UAAU,CAAS;QAJ/B,SAAI,GAAW,CAAC,CAAC;QACjB,SAAI,GAAW,CAAC,CAAC;QACjB,iBAAY,GAAY,KAAK,CAAC;IAEK,CAAC;IAErC,SAAS,CAAC,MAAsB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC7B,CAAC;IAEO,aAAa,CAAC,QAAgB,EAAE,aAAyC;QAC7E,IAAI,CAAC,aAAa;YAAE,OAAO,QAAQ,CAAC;QACpC,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACjD,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,CAAC,CAAC;gBACjD,MAAM,aAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;gBACrD,OAAO,QAAQ,CAAC;YACpB,CAAC;iBAAM,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAC1C,CAAC;iBAAM,CAAC;gBACJ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAC1C,CAAC;QACL,CAAC;KAAA;CACJ;AA5UD,8CA4UC","sourcesContent":["import { jsPDF } from \"jspdf\";\r\nimport autotable from \"jspdf-autotable\";\r\nimport { promises as fs } from 'fs';\r\nimport path from 'path';\r\n\r\nexport interface IPartiContratto {\r\n fornitore: { denominazione: string; codiceFiscale: string; indirizzoCompleto: string; };\r\n cliente: { denominazione: string; codiceFiscale: string; indirizzoCompleto: string; };\r\n}\r\n\r\nexport interface DocumentParams {\r\n parti: IPartiContratto;\r\n tipOutput?: 'f' | 'd' | 'u';\r\n dynamicFields?: { [key: string]: string };\r\n dynamicElements?: { [placeholder: string]: DynamicElement };\r\n}\r\n\r\nexport type DynamicElement = {\r\n type: 'table';\r\n config: {\r\n head: string[];\r\n body: string[][];\r\n options?: any;\r\n styles?: any;\r\n };\r\n};\r\n\r\ninterface DocumentConfig {\r\n fontTitolo: { nome: string; dimensione: number; colore: string; installPath?: string; };\r\n fontSottotitolo: { nome: string; dimensione: number; colore: string; installPath?: string; };\r\n fontTesto: { nome: string; dimensione: number; colore: string; installPath?: string; };\r\n fontBold: { nome: string; dimensione: number; colore: string; installPath?: string; };\r\n margini: { sx: number; dx: number; alto: number; basso: number; };\r\n staccoriga: number;\r\n rientro: number;\r\n testi: {\r\n titolo: string;\r\n premessa: string;\r\n Punti: Array<{ titolo: string; Sottopunti: Array<{ titolo: string; contenuto: string; }>; }>;\r\n versione: string;\r\n };\r\n immagini: Array<{ path: string; posizione: [number, number]; dimensioni: [number, number]; coeffDim?: number; }>;\r\n box: { backgrund: string; raggio: number; };\r\n tableStyle?: { lineColor?: string; lineWidth?: number; font?: string; fontSize?: number; cellPadding?: number; fillColor?: string; };\r\n}\r\n\r\nasync function loadImageAsBase64(imagePath: string): Promise<string> {\r\n const absolutePath = path.resolve(imagePath);\r\n const buffer = await fs.readFile(absolutePath);\r\n const ext = path.extname(imagePath).slice(1).toLowerCase();\r\n const base64 = buffer.toString('base64');\r\n return `data:image/${ext};base64,${base64}`;\r\n}\r\n\r\nexport class DocumentGenerator {\r\n private config!: DocumentConfig;\r\n private doc!: jsPDF;\r\n private curX: number = 0;\r\n private curY: number = 0;\r\n private configLoaded: boolean = false;\r\n\r\n constructor(private configPath?: string) { }\r\n\r\n public setConfig(config: DocumentConfig) {\r\n this.config = config;\r\n this.configLoaded = true;\r\n }\r\n\r\n private applyTemplate(template: string, dynamicFields?: { [key: string]: string }): string {\r\n if (!dynamicFields) return template;\r\n return template.replace(/\\$(\\w+)\\$/g, (match, key) =>\r\n dynamicFields[key] !== undefined ? dynamicFields[key] : match\r\n );\r\n }\r\n\r\n private applyPartiPlaceholders(text: string, parti: IPartiContratto): string {\r\n return text.replace(/\\$(fornitore|cliente):(\\w+)\\$/g, (match, party, field) =>\r\n (parti[party] && (parti[party] as any)[field]) ? (parti[party] as any)[field] : match\r\n );\r\n }\r\n\r\n private async loadConfig(): Promise<void> {\r\n if (this.configLoaded) return;\r\n if (!this.configPath) throw new Error(\"No configuration provided.\");\r\n try {\r\n const data = await fs.readFile(this.configPath, 'utf8');\r\n this.config = JSON.parse(data) as DocumentConfig;\r\n this.configLoaded = true;\r\n } catch (error) {\r\n throw new Error(`Error reading configuration file: ${error}`);\r\n }\r\n }\r\n\r\n private initDoc(): void {\r\n this.doc = new jsPDF();\r\n const margins = this.config.margini;\r\n this.curX = margins.sx;\r\n this.curY = margins.alto;\r\n }\r\n\r\n private extractPlaceholder(text: string): string | null {\r\n const match = text.match(/^\\$(\\w+)\\$$/);\r\n return match ? match[1] : null;\r\n }\r\n\r\n private async installFont(fontPath: string, fontName: string): Promise<void> {\r\n const absolutePath = path.resolve(fontPath);\r\n const buffer = await fs.readFile(absolutePath);\r\n const base64Font = buffer.toString('base64');\r\n //console.log(`Installing font ${fontName} from ${absolutePath}`);\r\n this.doc.addFileToVFS(`${fontName}.ttf`, base64Font);\r\n this.doc.addFont(`${fontName}.ttf`, fontName, 'normal');\r\n this.doc.setFont(fontName);\r\n }\r\n\r\n // Writes wrapped text, handling inline bold segments.\r\n private async writeWrappedTextCore(\r\n fontName: string,\r\n fontSize: number,\r\n color: string,\r\n text: string,\r\n x: number,\r\n y: number,\r\n maxWidth: number,\r\n lineSpacingFactor: number = 1.15\r\n ): Promise<number> {\r\n this.doc.setFont(fontName);\r\n this.doc.setFontSize(fontSize);\r\n this.doc.setTextColor(color);\r\n const lines = this.doc.splitTextToSize(text, maxWidth);\r\n const lineHeight = (fontSize * lineSpacingFactor / 72) * 25.4;\r\n for (const line of lines) {\r\n if (y + lineHeight > (this.doc.internal.pageSize.getHeight() - this.config.margini.basso)) {\r\n this.doc.addPage();\r\n y = this.config.margini.alto;\r\n }\r\n // If the line contains inline bold markers, process them.\r\n if (line.includes(\"**\")) {\r\n y = await this.writeLineWithInlineBold(line, x, y, fontName, fontSize, color, maxWidth, lineSpacingFactor);\r\n } else {\r\n this.doc.text(line, x, y);\r\n y += lineHeight;\r\n }\r\n }\r\n return y;\r\n }\r\n\r\n // Writes a single line with inline bold processing.\r\n private async writeLineWithInlineBold(\r\n line: string,\r\n x: number,\r\n y: number,\r\n normalFont: string,\r\n fontSize: number,\r\n color: string,\r\n maxWidth: number,\r\n lineSpacingFactor: number = 1.15\r\n ): Promise<number> {\r\n let currentX = x;\r\n // Split the line by bold segments. The regex keeps the markers.\r\n const segments = line.split(/(\\*\\*.*?\\*\\*)/);\r\n const lineHeight = (fontSize * lineSpacingFactor / 72) * 25.4;\r\n for (const seg of segments) {\r\n let segText = seg;\r\n let useBold = false;\r\n if (seg.startsWith(\"**\") && seg.endsWith(\"**\")) {\r\n useBold = true;\r\n segText = seg.substring(2, seg.length - 2);\r\n }\r\n if (useBold) {\r\n this.doc.setFont(this.config.fontBold.nome);\r\n } else {\r\n this.doc.setFont(normalFont);\r\n }\r\n this.doc.setFontSize(fontSize);\r\n this.doc.setTextColor(color);\r\n const segWidth = this.doc.getTextWidth(segText);\r\n // Write segment\r\n this.doc.text(segText, currentX, y);\r\n currentX += segWidth;\r\n }\r\n return y + lineHeight;\r\n }\r\n\r\n private async writeWrappedTextWithFont(\r\n fontConf: { nome: string; dimensione: number; colore: string; installPath?: string },\r\n text: string,\r\n x: number,\r\n y: number,\r\n maxWidth: number,\r\n lineSpacingFactor: number = 1.15\r\n ): Promise<void> {\r\n const fontList = this.doc.getFontList();\r\n if (!fontList[fontConf.nome]) {\r\n if (fontConf.installPath) await this.installFont(fontConf.installPath, fontConf.nome);\r\n else throw new Error(\"Font not present and no installPath provided\");\r\n } else {\r\n this.doc.setFont(fontConf.nome);\r\n }\r\n this.curY = await this.writeWrappedTextCore(fontConf.nome, fontConf.dimensione, fontConf.colore, text, x, y, maxWidth, lineSpacingFactor);\r\n }\r\n\r\n public async writeBoxedText(\r\n text: string,\r\n fontConf: { nome: string; dimensione: number; colore: string; installPath?: string },\r\n padding: number = 5,\r\n borderRadius: number = 5,\r\n borderWidth: number = 1,\r\n boxColor?: string\r\n ): Promise<void> {\r\n const fontList = this.doc.getFontList();\r\n if (!fontList[fontConf.nome]) {\r\n if (fontConf.installPath) await this.installFont(fontConf.installPath, fontConf.nome);\r\n else throw new Error(\"Font not present and no installPath provided\");\r\n } else {\r\n this.doc.setFont(fontConf.nome);\r\n }\r\n this.doc.setFontSize(fontConf.dimensione);\r\n this.doc.setTextColor(fontConf.colore);\r\n const pageWidth = this.doc.internal.pageSize.getWidth();\r\n const maxTextWidth = pageWidth - this.config.margini.sx - this.config.margini.dx - 2 * padding;\r\n const lines = this.doc.splitTextToSize(text, maxTextWidth);\r\n const lineHeight = (fontConf.dimensione * 1.15 / 72) * 25.4;\r\n const textHeight = lines.length * lineHeight;\r\n const boxX = this.curX;\r\n const boxY = this.curY;\r\n const boxWidth = maxTextWidth + 2 * padding;\r\n const boxHeight = textHeight + 2 * padding;\r\n if (boxColor) {\r\n this.doc.setFillColor(boxColor);\r\n this.doc.roundedRect(boxX, boxY, boxWidth, boxHeight, borderRadius, borderRadius, \"F\");\r\n }\r\n this.doc.setLineWidth(borderWidth);\r\n this.doc.roundedRect(boxX, boxY, boxWidth, boxHeight, borderRadius, borderRadius);\r\n const textX = boxX + padding;\r\n let textY = boxY + padding + lineHeight;\r\n for (const line of lines) {\r\n if (line.includes(\"**\")) {\r\n textY = await this.writeLineWithInlineBold(line, textX, textY, fontConf.nome, fontConf.dimensione, fontConf.colore, maxTextWidth, 1.15);\r\n } else {\r\n this.doc.text(line, textX, textY);\r\n textY += lineHeight;\r\n }\r\n }\r\n this.curY = boxY + boxHeight + this.config.staccoriga;\r\n }\r\n\r\n\r\n // Checks if text is wrapped in '^' markers for boxed text.\r\n private isBoxedText(text: string): boolean {\r\n return text.startsWith('^') && text.endsWith('^');\r\n }\r\n\r\n // Removes '^' markers.\r\n private stripBoxMarkers(text: string): string {\r\n return text.substring(1, text.length - 1);\r\n }\r\n\r\n // Checks if text is entirely wrapped in '**' markers (not inline).\r\n // (This function is kept for backward compatibility.)\r\n private isBoldText(text: string): boolean {\r\n return text.startsWith('**') && text.endsWith('**');\r\n }\r\n\r\n // Removes '**' markers.\r\n private stripBoldMarkers(text: string): string {\r\n return text.substring(2, text.length - 2);\r\n }\r\n\r\n // Inserts images using the current cursor position.\r\n private async insertLogo(): Promise<void> {\r\n if (this.config.immagini && this.config.immagini.length > 0) {\r\n const startX = this.curX;\r\n for (const imgConf of this.config.immagini) {\r\n const format = imgConf.path.split('.').pop()?.toUpperCase() || 'PNG';\r\n const base64Image = await loadImageAsBase64(imgConf.path);\r\n const startY = this.curY;\r\n if (startY + imgConf.dimensioni[1] > (this.doc.internal.pageSize.getHeight() - this.config.margini.basso)) {\r\n this.doc.addPage();\r\n this.curY = this.config.margini.alto;\r\n }\r\n this.doc.addImage(base64Image, format, startX, this.curY, imgConf.dimensioni[0], imgConf.dimensioni[1]);\r\n //console.log(`Image inserted at X: ${startX}, Y: ${this.curY}`);\r\n this.curY = this.curY + imgConf.dimensioni[1] + this.config.staccoriga;\r\n }\r\n }\r\n }\r\n\r\n // Generates the PDF document by processing images, dynamic fields, tables, and text.\r\n // Supports inline bold formatting and boxed text.\r\n public async generateDocument(params: DocumentParams): Promise<string | ArrayBuffer> {\r\n await this.loadConfig();\r\n this.initDoc();\r\n await this.insertLogo();\r\n const dynamicFields = params.dynamicFields || {};\r\n const dynamicElements = params.dynamicElements || {};\r\n const pageWidth = this.doc.internal.pageSize.getWidth();\r\n const maxWidth = pageWidth - (this.config.margini.sx + this.config.margini.dx);\r\n let titolo = this.applyTemplate(this.config.testi.titolo, dynamicFields);\r\n titolo = this.applyPartiPlaceholders(titolo, params.parti);\r\n await this.writeWrappedTextWithFont(this.config.fontTitolo, titolo, this.curX, this.curY, maxWidth);\r\n this.curY += this.config.staccoriga;\r\n let premessa = this.applyTemplate(this.config.testi.premessa, dynamicFields);\r\n premessa = this.applyPartiPlaceholders(premessa, params.parti);\r\n await this.writeWrappedTextWithFont(this.config.fontTesto, premessa, this.curX, this.curY, maxWidth);\r\n this.curY += this.config.staccoriga;\r\n for (const punto of this.config.testi.Punti) {\r\n let puntoTitolo = this.applyTemplate(punto.titolo, dynamicFields);\r\n puntoTitolo = this.applyPartiPlaceholders(puntoTitolo, params.parti);\r\n await this.writeWrappedTextWithFont(this.config.fontTitolo, puntoTitolo, this.curX, this.curY, maxWidth);\r\n this.curY += this.config.staccoriga;\r\n for (const sub of punto.Sottopunti) {\r\n const placeholder = this.extractPlaceholder(sub.titolo);\r\n if (placeholder && dynamicElements[placeholder] && dynamicElements[placeholder].type === 'table' && dynamicElements[placeholder].config) {\r\n const tableConfig = dynamicElements[placeholder].config!;\r\n const defaultTableOptions = this.config.tableStyle || {};\r\n autotable(this.doc, {\r\n startY: this.curY,\r\n head: [tableConfig.head],\r\n body: tableConfig.body,\r\n ...defaultTableOptions,\r\n ...tableConfig.options,\r\n ...tableConfig.styles\r\n });\r\n this.curY = (this.doc as any).lastAutoTable.finalY + this.config.staccoriga;\r\n } else {\r\n if (sub.titolo) {\r\n let titleText = this.applyTemplate(sub.titolo, dynamicFields);\r\n titleText = this.applyPartiPlaceholders(titleText, params.parti);\r\n if (this.isBoxedText(titleText)) {\r\n const boxText = this.stripBoxMarkers(titleText);\r\n await this.writeBoxedText(boxText, this.config.fontSottotitolo);\r\n } else if (this.isBoldText(titleText)) {\r\n const boldText = this.stripBoldMarkers(titleText);\r\n\r\n await this.writeWrappedTextWithFont({ ...this.config.fontSottotitolo, nome: this.config.fontSottotitolo.nome },\r\n boldText, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\r\n } else {\r\n await this.writeWrappedTextWithFont(this.config.fontSottotitolo, titleText, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\r\n }\r\n this.curY += this.config.staccoriga;\r\n }\r\n }\r\n const contentPlaceholder = this.extractPlaceholder(sub.contenuto);\r\n if (contentPlaceholder && dynamicElements[contentPlaceholder] && dynamicElements[contentPlaceholder].type === 'table' && dynamicElements[contentPlaceholder].config) {\r\n const tableConfig = dynamicElements[contentPlaceholder].config!;\r\n const defaultTableOptions = this.config.tableStyle || {};\r\n autotable(this.doc, {\r\n startY: this.curY,\r\n head: [tableConfig.head],\r\n body: tableConfig.body,\r\n ...defaultTableOptions,\r\n ...tableConfig.options,\r\n ...tableConfig.styles\r\n });\r\n this.curY = (this.doc as any).lastAutoTable.finalY + this.config.staccoriga;\r\n } else if (sub.contenuto) {\r\n let contenuto = this.applyTemplate(sub.contenuto, dynamicFields);\r\n contenuto = this.applyPartiPlaceholders(contenuto, params.parti);\r\n if (this.isBoxedText(contenuto)) {\r\n const boxText = this.stripBoxMarkers(contenuto);\r\n await this.writeBoxedText(boxText, this.config.fontTesto);\r\n } else if (this.isBoldText(contenuto)) {\r\n const boldText = this.stripBoldMarkers(contenuto);\r\n await this.writeWrappedTextWithFont({ ...this.config.fontTesto, nome: this.config.fontTesto.nome },\r\n boldText, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\r\n } else {\r\n await this.writeWrappedTextWithFont(this.config.fontTesto, contenuto, this.curX + this.config.rientro, this.curY, maxWidth - this.config.rientro);\r\n }\r\n this.curY += this.config.staccoriga;\r\n }\r\n }\r\n this.curY += this.config.staccoriga;\r\n }\r\n const tipOutput = params.tipOutput || 'd';\r\n const fileName = `Documento_${params.parti.cliente.denominazione}.pdf`;\r\n if (tipOutput === 'd') {\r\n const pdfBuffer = this.doc.output('arraybuffer');\r\n await fs.writeFile(fileName, Buffer.from(pdfBuffer));\r\n return fileName;\r\n } else if (tipOutput === 'u') {\r\n return this.doc.output('arraybuffer');\r\n } else {\r\n return this.doc.output('arraybuffer');\r\n }\r\n }\r\n}"]}
@@ -24,10 +24,10 @@ class DatabaseUpdater {
24
24
  static tableExists(options, table) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  try {
27
- const query = `
28
- SELECT 1
29
- FROM RDB$RELATIONS
30
- WHERE RDB$RELATION_NAME = ?
27
+ const query = `
28
+ SELECT 1
29
+ FROM RDB$RELATIONS
30
+ WHERE RDB$RELATION_NAME = ?
31
31
  AND COALESCE(RDB$SYSTEM_FLAG, 0) = 0`;
32
32
  const result = yield Orm_1.Orm.query(options, query, [table.toUpperCase()]);
33
33
  return result.length > 0;
@@ -48,10 +48,10 @@ class DatabaseUpdater {
48
48
  static columnExists(options, table, column) {
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
50
  try {
51
- const query = `
52
- SELECT 1
53
- FROM RDB$RELATION_FIELDS
54
- WHERE RDB$RELATION_NAME = ?
51
+ const query = `
52
+ SELECT 1
53
+ FROM RDB$RELATION_FIELDS
54
+ WHERE RDB$RELATION_NAME = ?
55
55
  AND RDB$FIELD_NAME = ?`;
56
56
  const result = yield Orm_1.Orm.query(options, query, [
57
57
  table.toUpperCase(),
@@ -74,9 +74,9 @@ class DatabaseUpdater {
74
74
  static generatorExists(options, generator) {
75
75
  return __awaiter(this, void 0, void 0, function* () {
76
76
  try {
77
- const query = `
78
- SELECT 1
79
- FROM RDB$GENERATORS
77
+ const query = `
78
+ SELECT 1
79
+ FROM RDB$GENERATORS
80
80
  WHERE RDB$GENERATOR_NAME = ?`;
81
81
  const result = yield Orm_1.Orm.query(options, query, [generator.toUpperCase()]);
82
82
  return result.length > 0;
@@ -96,10 +96,10 @@ class DatabaseUpdater {
96
96
  static triggerExists(options, trigger) {
97
97
  return __awaiter(this, void 0, void 0, function* () {
98
98
  try {
99
- const query = `
100
- SELECT 1
101
- FROM RDB$TRIGGERS
102
- WHERE RDB$TRIGGER_NAME = ?
99
+ const query = `
100
+ SELECT 1
101
+ FROM RDB$TRIGGERS
102
+ WHERE RDB$TRIGGER_NAME = ?
103
103
  AND COALESCE(RDB$SYSTEM_FLAG, 0) = 0`;
104
104
  const result = yield Orm_1.Orm.query(options, query, [trigger.toUpperCase()]);
105
105
  return result.length > 0;
@@ -121,9 +121,9 @@ class DatabaseUpdater {
121
121
  if (!(yield this.tableExists(options, "PARAMETRI"))) {
122
122
  return null;
123
123
  }
124
- const parameters = (yield Orm_1.Orm.query(options, `SELECT CODPAR, DESPAR
125
- FROM PARAMETRI
126
- WHERE CODPAR IN (?, ?)
124
+ const parameters = (yield Orm_1.Orm.query(options, `SELECT CODPAR, DESPAR
125
+ FROM PARAMETRI
126
+ WHERE CODPAR IN (?, ?)
127
127
  ORDER BY CASE WHEN CODPAR = ? THEN 0 ELSE 1 END`, [
128
128
  this.versionParameterKeys[0],
129
129
  this.versionParameterKeys[1],
@@ -178,12 +178,12 @@ class DatabaseUpdater {
178
178
  try {
179
179
  const tableAlreadyExists = yield this.tableExists(options, "PARAMETRI");
180
180
  if (!tableAlreadyExists) {
181
- const createTableQuery = `
182
- CREATE TABLE PARAMETRI (
183
- CODPAR VARCHAR(15) NOT NULL,
184
- DESPAR VARCHAR(255),
185
- NOTE BLOB SUB_TYPE 1 SEGMENT SIZE 80,
186
- GRUPPO VARCHAR(20)
181
+ const createTableQuery = `
182
+ CREATE TABLE PARAMETRI (
183
+ CODPAR VARCHAR(15) NOT NULL,
184
+ DESPAR VARCHAR(255),
185
+ NOTE BLOB SUB_TYPE 1 SEGMENT SIZE 80,
186
+ GRUPPO VARCHAR(20)
187
187
  );`;
188
188
  yield Orm_1.Orm.query(options, createTableQuery);
189
189
  yield Orm_1.Orm.query(options, "ALTER TABLE PARAMETRI ADD CONSTRAINT PK_PARAMETRI PRIMARY KEY (CODPAR);");
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseUpdater.js","sourceRoot":"","sources":["../src/DatabaseUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA4B;AAC5B,qCAAkC;AAGlC,MAAsB,eAAe;IAKnC,YAAY;IAEZ,yBAAyB;IACzB;;;;;OAKG;IACO,MAAM,CAAO,WAAW,CAChC,OAAgB,EAChB,KAAa;;YAGb,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG;;;;6CAIyB,CAAC;gBACxC,MAAM,MAAM,GAAG,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACtE,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,KAAK,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC3D,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;IAED;;;;;;OAMG;IACO,MAAM,CAAO,YAAY,CACjC,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E3C,MAAM,SAAG,CAAC,KAAK,CACb,OAAO,EACP,yEAAyE,CAC1E,CAAC;oBAEF,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;oBAC9D,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,oCAAoC,CAAC,CAAC;gBACjE,CAAC;gBAED,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;gBAC1D,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBACpD,OAAO;gBACT,CAAC;gBAED,MAAM,SAAG,CAAC,OAAO,CACf,OAAO,EACP,uEAAuE,EACvE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CACzD,CAAC;YACJ,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;gBAC5D,MAAM,KAAK,CAAC;YACd,CAAC;QAGH,CAAC;KAAA;;AAvOH,0CAyOC;AAtOkB,sBAAM,GAAW,IAAI,eAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AACzC,oCAAoB,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { Orm } from \"./Orm\";\nimport { Logger } from \"./Logger\";\nimport { Options } from \"es-node-firebird\";\n\nexport abstract class DatabaseUpdater {\n //#region Fields and Options\n protected static options: Options;\n protected static logger: Logger = new Logger(DatabaseUpdater.name);\n protected static readonly versionParameterKeys = [\"VersioneDB\", \"DBVERSION\"];\n //#endregion\n\n //#region Utility Methods\n /**\n * Checks if a table exists.\n * @param options Database connection options.\n * @param table Table name.\n * @returns True if the table exists, false otherwise.\n */\n protected static async tableExists(\n options: Options,\n table: string\n ): Promise<boolean> {\n\n try {\n const query = `\n SELECT 1\n FROM RDB$RELATIONS\n WHERE RDB$RELATION_NAME = ?\n AND COALESCE(RDB$SYSTEM_FLAG, 0) = 0`;\n const result = await Orm.query(options, query, [table.toUpperCase()]);\n return result.length > 0;\n } catch (error: any) {\n this.logger.error(`Error checking table ${table}:`, error);\n throw error;\n }\n }\n\n /**\n * Checks if a column exists in a specific table.\n * @param options Database connection options.\n * @param table Table name.\n * @param column Column name.\n * @returns True if the column exists, false otherwise.\n */\n protected static async columnExists(\n options: Options,\n table: string,\n column: string\n ): Promise<boolean> {\n\n try {\n const query = `\n SELECT 1 \n FROM RDB$RELATION_FIELDS \n WHERE RDB$RELATION_NAME = ? \n AND RDB$FIELD_NAME = ?`;\n const result = await Orm.query(options, query, [\n table.toUpperCase(),\n column.toUpperCase(),\n ]);\n return result.length > 0;\n } catch (error: any) {\n this.logger.error(`Error checking column ${column} on table ${table}:`, error);\n throw error;\n }\n }\n\n /**\n * Checks if a generator/sequence exists.\n * @param options Database connection options.\n * @param generator Generator name.\n * @returns True if the generator exists, false otherwise.\n */\n protected static async generatorExists(\n options: Options,\n generator: string\n ): Promise<boolean> {\n\n try {\n const query = `\n SELECT 1\n FROM RDB$GENERATORS\n WHERE RDB$GENERATOR_NAME = ?`;\n const result = await Orm.query(options, query, [generator.toUpperCase()]);\n return result.length > 0;\n } catch (error: any) {\n this.logger.error(`Error checking generator ${generator}:`, error);\n throw error;\n }\n }\n\n /**\n * Checks if a trigger exists.\n * @param options Database connection options.\n * @param trigger Trigger name.\n * @returns True if the trigger exists, false otherwise.\n */\n protected static async triggerExists(\n options: Options,\n trigger: string\n ): Promise<boolean> {\n\n try {\n const query = `\n SELECT 1\n FROM RDB$TRIGGERS\n WHERE RDB$TRIGGER_NAME = ?\n AND COALESCE(RDB$SYSTEM_FLAG, 0) = 0`;\n const result = await Orm.query(options, query, [trigger.toUpperCase()]);\n return result.length > 0;\n } catch (error: any) {\n this.logger.error(`Error checking trigger ${trigger}:`, error);\n throw error;\n }\n }\n\n /**\n * Retrieves the current database version from the PARAMETRI table.\n * @param options Database connection options.\n * @returns The current database version or null if not found.\n */\n protected static async getDatabaseVersion(options: Options): Promise<string | null> {\n\n try {\n if (!(await this.tableExists(options, \"PARAMETRI\"))) {\n return null;\n }\n\n const parameters = (await Orm.query(\n options,\n `SELECT CODPAR, DESPAR\n FROM PARAMETRI\n WHERE CODPAR IN (?, ?)\n ORDER BY CASE WHEN CODPAR = ? THEN 0 ELSE 1 END`,\n [\n this.versionParameterKeys[0],\n this.versionParameterKeys[1],\n this.versionParameterKeys[0],\n ]\n )) as any[];\n\n return parameters.length > 0 ? parameters[0].DESPAR : null;\n } catch (error: any) {\n this.logger.error(`Error getting database version:`, error);\n throw error;\n }\n }\n\n /**\n * Updates the database version in the PARAMETRI table.\n * @param options Database connection options.\n * @param version The new database version.\n */\n protected static async setDatabaseVersion(\n options: Options,\n version: string\n ): Promise<void> {\n\n try {\n if (!(await this.tableExists(options, \"PARAMETRI\"))) {\n await this.createParametersTable(options);\n }\n\n const existingRows = (await Orm.query(\n options,\n \"SELECT CODPAR FROM PARAMETRI WHERE CODPAR IN (?, ?)\",\n [this.versionParameterKeys[0], this.versionParameterKeys[1]]\n )) as any[];\n\n if (existingRows.length === 0) {\n await Orm.execute(\n options,\n \"INSERT INTO PARAMETRI (CODPAR, DESPAR, NOTE, GRUPPO) VALUES (?, ?, ?, ?)\",\n [this.versionParameterKeys[0], version, \"versione\", null]\n );\n return;\n }\n\n for (const row of existingRows) {\n await Orm.execute(options, \"UPDATE PARAMETRI SET DESPAR = ? WHERE CODPAR = ?\", [\n version,\n row.CODPAR?.trim?.() ?? row.CODPAR,\n ]);\n }\n } catch (error: any) {\n this.logger.error(`Error setting database version:`, error);\n throw error;\n }\n }\n //#endregion\n\n //#region Initialization Methods\n /**\n * Ensures the PARAMETRI table exists and initializes it if necessary.\n * @param options Database connection options.\n */\n protected static async createParametersTable(options: Options): Promise<void> {\n try {\n const tableAlreadyExists = await this.tableExists(options, \"PARAMETRI\");\n if (!tableAlreadyExists) {\n const createTableQuery = `\n CREATE TABLE PARAMETRI (\n CODPAR VARCHAR(15) NOT NULL,\n DESPAR VARCHAR(255),\n NOTE BLOB SUB_TYPE 1 SEGMENT SIZE 80,\n GRUPPO VARCHAR(20)\n );`;\n\n await Orm.query(options, createTableQuery);\n\n await Orm.query(\n options,\n \"ALTER TABLE PARAMETRI ADD CONSTRAINT PK_PARAMETRI PRIMARY KEY (CODPAR);\"\n );\n\n await Orm.query(options, \"GRANT ALL ON PARAMETRI TO PUBLIC;\");\n await Orm.query(options, \"GRANT SELECT ON PARAMETRI TO TABX;\");\n }\n\n const versioneDb = await this.getDatabaseVersion(options);\n if (versioneDb !== null && versioneDb !== undefined) {\n return;\n }\n\n await Orm.execute(\n options,\n \"INSERT INTO PARAMETRI (CODPAR, DESPAR, NOTE, GRUPPO) VALUES (?,?,?,?)\",\n [this.versionParameterKeys[0], \"0.0a\", \"versione\", null]\n );\n } catch (error: any) {\n this.logger.error(\"Error creating table PARAMETRI:\", error);\n throw error;\n }\n\n\n }\n //#endregion\n}\n"]}
1
+ {"version":3,"file":"DatabaseUpdater.js","sourceRoot":"","sources":["../src/DatabaseUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA4B;AAC5B,qCAAkC;AAGlC,MAAsB,eAAe;IAKnC,YAAY;IAEZ,yBAAyB;IACzB;;;;;OAKG;IACO,MAAM,CAAO,WAAW,CAChC,OAAgB,EAChB,KAAa;;YAGb,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG;;;;6CAIyB,CAAC;gBACxC,MAAM,MAAM,GAAG,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACtE,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wB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,kBAAkB,EAAE,CAAC;oBACxB,MAAM,gBAAgB,GAAG;;;;;;aAMpB,CAAC;oBAEN,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;oBAE3C,MAAM,SAAG,CAAC,KAAK,CACb,OAAO,EACP,yEAAyE,CAC1E,CAAC;oBAEF,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;oBAC9D,MAAM,SAAG,CAAC,KAAK,CAAC,OAAO,EAAE,oCAAoC,CAAC,CAAC;gBACjE,CAAC;gBAED,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;gBAC1D,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBACpD,OAAO;gBACT,CAAC;gBAED,MAAM,SAAG,CAAC,OAAO,CACf,OAAO,EACP,uEAAuE,EACvE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CACzD,CAAC;YACJ,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;gBAC5D,MAAM,KAAK,CAAC;YACd,CAAC;QAGH,CAAC;KAAA;;AAvOH,0CAyOC;AAtOkB,sBAAM,GAAW,IAAI,eAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AACzC,oCAAoB,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { Orm } from \"./Orm\";\r\nimport { Logger } from \"./Logger\";\r\nimport { Options } from \"es-node-firebird\";\r\n\r\nexport abstract class DatabaseUpdater {\r\n //#region Fields and Options\r\n protected static options: Options;\r\n protected static logger: Logger = new Logger(DatabaseUpdater.name);\r\n protected static readonly versionParameterKeys = [\"VersioneDB\", \"DBVERSION\"];\r\n //#endregion\r\n\r\n //#region Utility Methods\r\n /**\r\n * Checks if a table exists.\r\n * @param options Database connection options.\r\n * @param table Table name.\r\n * @returns True if the table exists, false otherwise.\r\n */\r\n protected static async tableExists(\r\n options: Options,\r\n table: string\r\n ): Promise<boolean> {\r\n\r\n try {\r\n const query = `\r\n SELECT 1\r\n FROM RDB$RELATIONS\r\n WHERE RDB$RELATION_NAME = ?\r\n AND COALESCE(RDB$SYSTEM_FLAG, 0) = 0`;\r\n const result = await Orm.query(options, query, [table.toUpperCase()]);\r\n return result.length > 0;\r\n } catch (error: any) {\r\n this.logger.error(`Error checking table ${table}:`, error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Checks if a column exists in a specific table.\r\n * @param options Database connection options.\r\n * @param table Table name.\r\n * @param column Column name.\r\n * @returns True if the column exists, false otherwise.\r\n */\r\n protected static async columnExists(\r\n options: Options,\r\n table: string,\r\n column: string\r\n ): Promise<boolean> {\r\n\r\n try {\r\n const query = `\r\n SELECT 1 \r\n FROM RDB$RELATION_FIELDS \r\n WHERE RDB$RELATION_NAME = ? \r\n AND RDB$FIELD_NAME = ?`;\r\n const result = await Orm.query(options, query, [\r\n table.toUpperCase(),\r\n column.toUpperCase(),\r\n ]);\r\n return result.length > 0;\r\n } catch (error: any) {\r\n this.logger.error(`Error checking column ${column} on table ${table}:`, error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Checks if a generator/sequence exists.\r\n * @param options Database connection options.\r\n * @param generator Generator name.\r\n * @returns True if the generator exists, false otherwise.\r\n */\r\n protected static async generatorExists(\r\n options: Options,\r\n generator: string\r\n ): Promise<boolean> {\r\n\r\n try {\r\n const query = `\r\n SELECT 1\r\n FROM RDB$GENERATORS\r\n WHERE RDB$GENERATOR_NAME = ?`;\r\n const result = await Orm.query(options, query, [generator.toUpperCase()]);\r\n return result.length > 0;\r\n } catch (error: any) {\r\n this.logger.error(`Error checking generator ${generator}:`, error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Checks if a trigger exists.\r\n * @param options Database connection options.\r\n * @param trigger Trigger name.\r\n * @returns True if the trigger exists, false otherwise.\r\n */\r\n protected static async triggerExists(\r\n options: Options,\r\n trigger: string\r\n ): Promise<boolean> {\r\n\r\n try {\r\n const query = `\r\n SELECT 1\r\n FROM RDB$TRIGGERS\r\n WHERE RDB$TRIGGER_NAME = ?\r\n AND COALESCE(RDB$SYSTEM_FLAG, 0) = 0`;\r\n const result = await Orm.query(options, query, [trigger.toUpperCase()]);\r\n return result.length > 0;\r\n } catch (error: any) {\r\n this.logger.error(`Error checking trigger ${trigger}:`, error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves the current database version from the PARAMETRI table.\r\n * @param options Database connection options.\r\n * @returns The current database version or null if not found.\r\n */\r\n protected static async getDatabaseVersion(options: Options): Promise<string | null> {\r\n\r\n try {\r\n if (!(await this.tableExists(options, \"PARAMETRI\"))) {\r\n return null;\r\n }\r\n\r\n const parameters = (await Orm.query(\r\n options,\r\n `SELECT CODPAR, DESPAR\r\n FROM PARAMETRI\r\n WHERE CODPAR IN (?, ?)\r\n ORDER BY CASE WHEN CODPAR = ? THEN 0 ELSE 1 END`,\r\n [\r\n this.versionParameterKeys[0],\r\n this.versionParameterKeys[1],\r\n this.versionParameterKeys[0],\r\n ]\r\n )) as any[];\r\n\r\n return parameters.length > 0 ? parameters[0].DESPAR : null;\r\n } catch (error: any) {\r\n this.logger.error(`Error getting database version:`, error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Updates the database version in the PARAMETRI table.\r\n * @param options Database connection options.\r\n * @param version The new database version.\r\n */\r\n protected static async setDatabaseVersion(\r\n options: Options,\r\n version: string\r\n ): Promise<void> {\r\n\r\n try {\r\n if (!(await this.tableExists(options, \"PARAMETRI\"))) {\r\n await this.createParametersTable(options);\r\n }\r\n\r\n const existingRows = (await Orm.query(\r\n options,\r\n \"SELECT CODPAR FROM PARAMETRI WHERE CODPAR IN (?, ?)\",\r\n [this.versionParameterKeys[0], this.versionParameterKeys[1]]\r\n )) as any[];\r\n\r\n if (existingRows.length === 0) {\r\n await Orm.execute(\r\n options,\r\n \"INSERT INTO PARAMETRI (CODPAR, DESPAR, NOTE, GRUPPO) VALUES (?, ?, ?, ?)\",\r\n [this.versionParameterKeys[0], version, \"versione\", null]\r\n );\r\n return;\r\n }\r\n\r\n for (const row of existingRows) {\r\n await Orm.execute(options, \"UPDATE PARAMETRI SET DESPAR = ? WHERE CODPAR = ?\", [\r\n version,\r\n row.CODPAR?.trim?.() ?? row.CODPAR,\r\n ]);\r\n }\r\n } catch (error: any) {\r\n this.logger.error(`Error setting database version:`, error);\r\n throw error;\r\n }\r\n }\r\n //#endregion\r\n\r\n //#region Initialization Methods\r\n /**\r\n * Ensures the PARAMETRI table exists and initializes it if necessary.\r\n * @param options Database connection options.\r\n */\r\n protected static async createParametersTable(options: Options): Promise<void> {\r\n try {\r\n const tableAlreadyExists = await this.tableExists(options, \"PARAMETRI\");\r\n if (!tableAlreadyExists) {\r\n const createTableQuery = `\r\n CREATE TABLE PARAMETRI (\r\n CODPAR VARCHAR(15) NOT NULL,\r\n DESPAR VARCHAR(255),\r\n NOTE BLOB SUB_TYPE 1 SEGMENT SIZE 80,\r\n GRUPPO VARCHAR(20)\r\n );`;\r\n\r\n await Orm.query(options, createTableQuery);\r\n\r\n await Orm.query(\r\n options,\r\n \"ALTER TABLE PARAMETRI ADD CONSTRAINT PK_PARAMETRI PRIMARY KEY (CODPAR);\"\r\n );\r\n\r\n await Orm.query(options, \"GRANT ALL ON PARAMETRI TO PUBLIC;\");\r\n await Orm.query(options, \"GRANT SELECT ON PARAMETRI TO TABX;\");\r\n }\r\n\r\n const versioneDb = await this.getDatabaseVersion(options);\r\n if (versioneDb !== null && versioneDb !== undefined) {\r\n return;\r\n }\r\n\r\n await Orm.execute(\r\n options,\r\n \"INSERT INTO PARAMETRI (CODPAR, DESPAR, NOTE, GRUPPO) VALUES (?,?,?,?)\",\r\n [this.versionParameterKeys[0], \"0.0a\", \"versione\", null]\r\n );\r\n } catch (error: any) {\r\n this.logger.error(\"Error creating table PARAMETRI:\", error);\r\n throw error;\r\n }\r\n\r\n\r\n }\r\n //#endregion\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"EmilsoftwareModule.js","sourceRoot":"","sources":["../src/EmilsoftwareModule.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,kEAA+E;AAC/E,qEAAmF;AACnF,qCAAkC;AAUlC;;;GAGG;AAEI,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC3B,MAAM,CAAC,OAAO,CAAC,OAA4B;QAEvC,MAAM,MAAM,GAAW,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;QAC3D,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,OAAO,GAAG,EAAE,CAAC;QAEjB,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC5F,CAAC;QAGD,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;YACjE,OAAO,CAAC,IAAI,CAAC,6BAAa,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;YAC5D,OAAO,CAAC,IAAI,CAAC,6BAAa,CAAC,CAAC;QAChC,CAAC;aACI,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,0EAA0E,CAAC,CAAC;QAC/F,CAAC;QAED,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;YAClE,OAAO,CAAC,IAAI,CAAC,+BAAc,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,+BAAc,CAAC,CAAC;QACjC,CAAC;aACI,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,4EAA4E,CAAC,CAAC;QACjG,CAAC;QAED,OAAO;YACH,MAAM,EAAE,oBAAkB;YAC1B,OAAO;YACP,OAAO;SACV,CAAC;IACN,CAAC;CACJ,CAAA;AApCY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CAoC9B","sourcesContent":["import { DynamicModule, Module } from \"@nestjs/common\";\nimport { AccessiModule, AccessiOptions } from \"./accessi-module/AccessiModule\";\nimport { AllegatiModule, AllegatiOptions } from \"./allegati-module/AllegatiModule\";\nimport { Logger } from \"./Logger\";\n\n/**\n * Configuration options for the unified module that combines Accessi and Allegati functionality\n */\nexport interface EmilsoftwareOptions {\n accessiOptions: AccessiOptions;\n allegatiOptions: AllegatiOptions;\n}\n\n/**\n * Unified module that combines user access management (Accessi) and file attachment management (Allegati)\n * into a single NestJS module with shared Swagger documentation\n */\n@Module({})\nexport class EmilsoftwareModule {\n static forRoot(options: EmilsoftwareOptions): DynamicModule {\n\n const logger: Logger = new Logger(EmilsoftwareModule.name);\n let imports = [];\n let exports = [];\n\n if (!options) {\n throw new Error(\"EmilsoftwareModule requires valid accessiOptions and allegatiOptions\");\n }\n\n\n if (options.accessiOptions) {\n logger.info(\"Initializing AccessiModule with provided options.\");\n imports.push(AccessiModule.forRoot(options.accessiOptions));\n exports.push(AccessiModule);\n }\n else {\n logger.warning(\"Accessi options are not provided. AccessiModule will not be initialized.\");\n }\n\n if (options.allegatiOptions) {\n logger.info(\"Initializing AllegatiModule with provided options.\");\n imports.push(AllegatiModule.forRoot(options.allegatiOptions));\n exports.push(AllegatiModule);\n }\n else {\n logger.warning(\"Allegati options are not provided. AllegatiModule will not be initialized.\");\n }\n\n return {\n module: EmilsoftwareModule,\n imports,\n exports\n };\n }\n} "]}
1
+ {"version":3,"file":"EmilsoftwareModule.js","sourceRoot":"","sources":["../src/EmilsoftwareModule.ts"],"names":[],"mappings":";;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oC9B","sourcesContent":["import { DynamicModule, Module } from \"@nestjs/common\";\r\nimport { AccessiModule, AccessiOptions } from \"./accessi-module/AccessiModule\";\r\nimport { AllegatiModule, AllegatiOptions } from \"./allegati-module/AllegatiModule\";\r\nimport { Logger } from \"./Logger\";\r\n\r\n/**\r\n * Configuration options for the unified module that combines Accessi and Allegati functionality\r\n */\r\nexport interface EmilsoftwareOptions {\r\n accessiOptions: AccessiOptions;\r\n allegatiOptions: AllegatiOptions;\r\n}\r\n\r\n/**\r\n * Unified module that combines user access management (Accessi) and file attachment management (Allegati)\r\n * into a single NestJS module with shared Swagger documentation\r\n */\r\n@Module({})\r\nexport class EmilsoftwareModule {\r\n static forRoot(options: EmilsoftwareOptions): DynamicModule {\r\n\r\n const logger: Logger = new Logger(EmilsoftwareModule.name);\r\n let imports = [];\r\n let exports = [];\r\n\r\n if (!options) {\r\n throw new Error(\"EmilsoftwareModule requires valid accessiOptions and allegatiOptions\");\r\n }\r\n\r\n\r\n if (options.accessiOptions) {\r\n logger.info(\"Initializing AccessiModule with provided options.\");\r\n imports.push(AccessiModule.forRoot(options.accessiOptions));\r\n exports.push(AccessiModule);\r\n }\r\n else {\r\n logger.warning(\"Accessi options are not provided. AccessiModule will not be initialized.\");\r\n }\r\n\r\n if (options.allegatiOptions) {\r\n logger.info(\"Initializing AllegatiModule with provided options.\");\r\n imports.push(AllegatiModule.forRoot(options.allegatiOptions));\r\n exports.push(AllegatiModule);\r\n }\r\n else {\r\n logger.warning(\"Allegati options are not provided. AllegatiModule will not be initialized.\");\r\n }\r\n\r\n return {\r\n module: EmilsoftwareModule,\r\n imports,\r\n exports\r\n };\r\n }\r\n} "]}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionTimeLogger.js","sourceRoot":"","sources":["../src/ExecutionTimeLogger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAA4B;AAE5B,MAAa,mBAAmB;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,MAAW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AmCC","sourcesContent":["import { Logger } from \"./\";\n\nexport class ExecutionTimeLogger {\n /**\n * Wraps a method to log its execution time and errors.\n * @param target The target object.\n * @param propertyKey The name of the method.\n * @param descriptor The property descriptor of the method.\n * @description use ExecutionTimeLogger.apply on any method\n */\n static apply(target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n const originalMethod = descriptor.value;\n\n if (typeof originalMethod !== \"function\") {\n throw new TypeError(`ExecutionTimeLogger can only be applied to methods, not: ${typeof originalMethod}`);\n }\n\n descriptor.value = async function (...args: any[]) {\n const className = target.constructor.name; // Get the class name dynamically\n const logger = new Logger(className); // Use the class name for logger\n const start = process.hrtime();\n logger.info(`[${className}] ${propertyKey} method execution started . . .`);\n \n try {\n const result = await originalMethod.apply(this, args);\n const end = process.hrtime(start);\n const durationInMilliseconds = end[0] * 1000 + end[1] / 1e6;\n logger.info(`[${className}] ${propertyKey} method took ${durationInMilliseconds.toFixed(2)} ms to execute`);\n return result;\n } catch (error) {\n logger.error(`[${className}] ${propertyKey} method threw an error: ${error.message}`);\n throw error;\n }\n };\n\n return descriptor;\n }\n}\n"]}
1
+ {"version":3,"file":"ExecutionTimeLogger.js","sourceRoot":"","sources":["../src/ExecutionTimeLogger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAA4B;AAE5B,MAAa,mBAAmB;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B;QACzE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE,CAAC;YACvC,MAAM,IAAI,SAAS,CAAC,4DAA4D,OAAO,cAAc,EAAE,CAAC,CAAC;QAC7G,CAAC;QAED,UAAU,CAAC,KAAK,GAAG,UAAgB,GAAG,IAAW;;gBAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,iCAAiC;gBAC5E,MAAM,MAAM,GAAG,IAAI,SAAM,CAAC,SAAS,CAAC,CAAC,CAAC,gCAAgC;gBACtE,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC/B,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,KAAK,WAAW,iCAAiC,CAAC,CAAC;gBAE5E,IAAI,CAAC;oBACD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBACtD,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAClC,MAAM,sBAAsB,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;oBAC5D,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,KAAK,WAAW,gBAAgB,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;oBAC5G,OAAO,MAAM,CAAC;gBAClB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,MAAM,CAAC,KAAK,CAAC,IAAI,SAAS,KAAK,WAAW,2BAA2B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;oBACtF,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC;SAAA,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAnCD,kDAmCC","sourcesContent":["import { Logger } from \"./\";\r\n\r\nexport class ExecutionTimeLogger {\r\n /**\r\n * Wraps a method to log its execution time and errors.\r\n * @param target The target object.\r\n * @param propertyKey The name of the method.\r\n * @param descriptor The property descriptor of the method.\r\n * @description use ExecutionTimeLogger.apply on any method\r\n */\r\n static apply(target: any, propertyKey: string, descriptor: PropertyDescriptor) {\r\n const originalMethod = descriptor.value;\r\n\r\n if (typeof originalMethod !== \"function\") {\r\n throw new TypeError(`ExecutionTimeLogger can only be applied to methods, not: ${typeof originalMethod}`);\r\n }\r\n\r\n descriptor.value = async function (...args: any[]) {\r\n const className = target.constructor.name; // Get the class name dynamically\r\n const logger = new Logger(className); // Use the class name for logger\r\n const start = process.hrtime();\r\n logger.info(`[${className}] ${propertyKey} method execution started . . .`);\r\n \r\n try {\r\n const result = await originalMethod.apply(this, args);\r\n const end = process.hrtime(start);\r\n const durationInMilliseconds = end[0] * 1000 + end[1] / 1e6;\r\n logger.info(`[${className}] ${propertyKey} method took ${durationInMilliseconds.toFixed(2)} ms to execute`);\r\n return result;\r\n } catch (error) {\r\n logger.error(`[${className}] ${propertyKey} method threw an error: ${error.message}`);\r\n throw error;\r\n }\r\n };\r\n\r\n return descriptor;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,2CAA6B;AAC7B,2BAAoC;AACpC,yCAAoE;AAEpE,IAAY,SAOX;AAPD,WAAY,SAAS;IACjB,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,gCAAmB,CAAA;IACnB,4BAAe,CAAA;IACf,wBAAW,CAAA;IACX,kCAAqB,CAAA;AACzB,CAAC,EAPW,SAAS,yBAAT,SAAS,QAOpB;AAED,MAAa,MAAM;IAMf,YACI,GAAW,EACX,MAIC;QAED,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,YAAY,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,KAAI,MAAM,CAAC;QAEnD,qBAAqB;QACrB,IAAI,CAAC,SAAS;YACV,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY;gBACpB,iBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAA4C,EAAE,EAAE;wBAAhD,EAAE,SAAS,EAAE,IAAI,EAAE,KAA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,KAAK,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACxE,MAAM;QACd,CAAC;QAED,cAAc;QACd,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,GAAW,EAAE,MAAkC;QACtE,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;CACJ;AAtKD,wBAsKC","sourcesContent":["import winston from \"winston\";\nimport * as path from \"path\";\nimport { promises as fs } from \"fs\";\nimport { blue, red, magenta, green, cyan, yellow } from 'colorette';\n\nexport enum LogLevels {\n INFO = \"INFO\",\n ERROR = \"ERROR\",\n WARNING = \"WARNING\",\n DEBUG = \"DEBUG\",\n LOG = \"LOG\",\n DATABASE = \"DATABASE\",\n}\n\nexport class Logger {\n private readonly winstonLogger: winston.Logger;\n private readonly tag: string;\n private readonly logDirectory: string;\n private logFormat: winston.Logform.Format;\n\n constructor(\n tag: string,\n config?: {\n logDirectory?: string;\n customFormat?: winston.Logform.Format;\n transports?: winston.transport[];\n }\n ) {\n this.tag = tag || \"[UNTAGGED]\";\n this.logDirectory = config?.logDirectory || \"logs\";\n\n // Default log format\n this.logFormat =\n config?.customFormat ||\n winston.format.printf(({ timestamp, file, level, message, ...meta }) => {\n return JSON.stringify({\n timestamp: timestamp || new Date().toISOString(),\n tag: this.tag,\n file: this.replaceAll(file + \"\", \"\\\\\", \"/\"),\n level,\n message,\n ...meta,\n });\n });\n\n this.initializeDirectory();\n\n // Configure logger\n this.winstonLogger = winston.createLogger({\n format: winston.format.combine(winston.format.timestamp(), this.logFormat),\n transports: config?.transports || [\n new winston.transports.File({\n filename: path.join(this.logDirectory, this.getFileName() + \".json\"),\n }),\n ],\n levels: {\n error: 1,\n warning: 2,\n info: 3,\n http: 4,\n verbose: 5,\n debug: 6,\n silly: 7,\n database: 8,\n },\n });\n\n // Add colors for console logging\n winston.addColors({\n database: \"green\",\n error: \"red\",\n warning: \"yellow\",\n info: \"blue\",\n debug: \"magenta\",\n log: \"cyan\",\n });\n }\n\n private async initializeDirectory() {\n try {\n const exists = await fs.access(this.logDirectory).then(() => true).catch(() => false);\n if (!exists) {\n await fs.mkdir(this.logDirectory);\n }\n } catch (err) {\n console.error(\"Error initializing log directory:\", err);\n }\n }\n\n private getFileName(): string {\n const now = new Date();\n const dateString = now.toISOString().split(\"T\")[0]; // YYYY-MM-DD\n return dateString;\n }\n\n private replaceAll(string: string, match: string, replacer: string) {\n return string.split(match).join(replacer);\n }\n\n public execStart(prefix: string = \"\"): number {\n this.print(LogLevels.INFO, `${prefix} - Execution started`);\n return performance.now();\n }\n\n public execStop(prefix: string = \"\", startTime: number, error: boolean = false): void {\n const executionTime = performance.now() - startTime;\n const message = `${prefix} - Execution ended ${error ? \"due to an error\" : \"successfully\"\n }. Execution time: ${executionTime.toFixed(2)} ms`;\n this.print(error ? LogLevels.ERROR : LogLevels.INFO, message);\n }\n\n public info(...data: Object[]): void {\n this.print(LogLevels.INFO, ...data);\n }\n\n public dbLog(...data: Object[]): void {\n this.print(LogLevels.DATABASE, ...data);\n }\n\n public debug(...data: Object[]): void {\n this.print(LogLevels.DEBUG, ...data);\n }\n\n public warning(...data: Object[]): void {\n this.print(LogLevels.WARNING, ...data);\n }\n\n public log(...data: Object[]): void {\n this.print(LogLevels.LOG, ...data);\n }\n\n public error(...data: Object[]): void {\n this.print(LogLevels.ERROR, ...data);\n }\n\n private print(level: LogLevels, ...data: Object[]): void {\n const now: Date = new Date();\n const fileName = this.tag.split(\"\\\\\").pop() || this.tag;\n\n // Attach metadata to Winston logger\n this.winstonLogger.defaultMeta = {\n file: fileName,\n time: now,\n level,\n };\n\n const logEntry: winston.LogEntry = {\n level: level.toLowerCase(),\n message: [...data].join(\",\"),\n };\n\n // Log to console with colors\n switch (level) {\n case LogLevels.INFO:\n console.info(blue(`[INFO][${now}][${fileName}]`), logEntry.message);\n break;\n case LogLevels.ERROR:\n console.error(red(`[ERROR][${now}][${fileName}]`), logEntry.message);\n break;\n case LogLevels.DEBUG:\n console.debug(magenta(`[DEBUG][${now}][${fileName}]`), logEntry.message);\n break;\n case LogLevels.WARNING:\n console.debug(yellow(`[WARNING][${now}][${fileName}]`), logEntry.message);\n break;\n case LogLevels.LOG:\n console.log(cyan(`[LOG][${now}][${fileName}]`), logEntry.message);\n break;\n case LogLevels.DATABASE:\n console.log(green(`[DATABASE][${now}][${fileName}]`), logEntry.message);\n break;\n }\n\n // Log to file\n this.winstonLogger.log(logEntry);\n }\n\n public static createLogger(tag: string, config?: { logDirectory?: string }): Logger {\n return new Logger(tag, config);\n }\n}\n"]}
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,2CAA6B;AAC7B,2BAAoC;AACpC,yCAAoE;AAEpE,IAAY,SAOX;AAPD,WAAY,SAAS;IACjB,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,gCAAmB,CAAA;IACnB,4BAAe,CAAA;IACf,wBAAW,CAAA;IACX,kCAAqB,CAAA;AACzB,CAAC,EAPW,SAAS,yBAAT,SAAS,QAOpB;AAED,MAAa,MAAM;IAMf,YACI,GAAW,EACX,MAIC;QAED,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,YAAY,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,KAAI,MAAM,CAAC;QAEnD,qBAAqB;QACrB,IAAI,CAAC,SAAS;YACV,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY;gBACpB,iBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAA4C,EAAE,EAAE;wBAAhD,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,O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AQ,GAAG,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACxE,MAAM;QACd,CAAC;QAED,cAAc;QACd,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,GAAW,EAAE,MAAkC;QACtE,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;CACJ;AAtKD,wBAsKC","sourcesContent":["import winston from \"winston\";\r\nimport * as path from \"path\";\r\nimport { promises as fs } from \"fs\";\r\nimport { blue, red, magenta, green, cyan, yellow } from 'colorette';\r\n\r\nexport enum LogLevels {\r\n INFO = \"INFO\",\r\n ERROR = \"ERROR\",\r\n WARNING = \"WARNING\",\r\n DEBUG = \"DEBUG\",\r\n LOG = \"LOG\",\r\n DATABASE = \"DATABASE\",\r\n}\r\n\r\nexport class Logger {\r\n private readonly winstonLogger: winston.Logger;\r\n private readonly tag: string;\r\n private readonly logDirectory: string;\r\n private logFormat: winston.Logform.Format;\r\n\r\n constructor(\r\n tag: string,\r\n config?: {\r\n logDirectory?: string;\r\n customFormat?: winston.Logform.Format;\r\n transports?: winston.transport[];\r\n }\r\n ) {\r\n this.tag = tag || \"[UNTAGGED]\";\r\n this.logDirectory = config?.logDirectory || \"logs\";\r\n\r\n // Default log format\r\n this.logFormat =\r\n config?.customFormat ||\r\n winston.format.printf(({ timestamp, file, level, message, ...meta }) => {\r\n return JSON.stringify({\r\n timestamp: timestamp || new Date().toISOString(),\r\n tag: this.tag,\r\n file: this.replaceAll(file + \"\", \"\\\\\", \"/\"),\r\n level,\r\n message,\r\n ...meta,\r\n });\r\n });\r\n\r\n this.initializeDirectory();\r\n\r\n // Configure logger\r\n this.winstonLogger = winston.createLogger({\r\n format: winston.format.combine(winston.format.timestamp(), this.logFormat),\r\n transports: config?.transports || [\r\n new winston.transports.File({\r\n filename: path.join(this.logDirectory, this.getFileName() + \".json\"),\r\n }),\r\n ],\r\n levels: {\r\n error: 1,\r\n warning: 2,\r\n info: 3,\r\n http: 4,\r\n verbose: 5,\r\n debug: 6,\r\n silly: 7,\r\n database: 8,\r\n },\r\n });\r\n\r\n // Add colors for console logging\r\n winston.addColors({\r\n database: \"green\",\r\n error: \"red\",\r\n warning: \"yellow\",\r\n info: \"blue\",\r\n debug: \"magenta\",\r\n log: \"cyan\",\r\n });\r\n }\r\n\r\n private async initializeDirectory() {\r\n try {\r\n const exists = await fs.access(this.logDirectory).then(() => true).catch(() => false);\r\n if (!exists) {\r\n await fs.mkdir(this.logDirectory);\r\n }\r\n } catch (err) {\r\n console.error(\"Error initializing log directory:\", err);\r\n }\r\n }\r\n\r\n private getFileName(): string {\r\n const now = new Date();\r\n const dateString = now.toISOString().split(\"T\")[0]; // YYYY-MM-DD\r\n return dateString;\r\n }\r\n\r\n private replaceAll(string: string, match: string, replacer: string) {\r\n return string.split(match).join(replacer);\r\n }\r\n\r\n public execStart(prefix: string = \"\"): number {\r\n this.print(LogLevels.INFO, `${prefix} - Execution started`);\r\n return performance.now();\r\n }\r\n\r\n public execStop(prefix: string = \"\", startTime: number, error: boolean = false): void {\r\n const executionTime = performance.now() - startTime;\r\n const message = `${prefix} - Execution ended ${error ? \"due to an error\" : \"successfully\"\r\n }. Execution time: ${executionTime.toFixed(2)} ms`;\r\n this.print(error ? LogLevels.ERROR : LogLevels.INFO, message);\r\n }\r\n\r\n public info(...data: Object[]): void {\r\n this.print(LogLevels.INFO, ...data);\r\n }\r\n\r\n public dbLog(...data: Object[]): void {\r\n this.print(LogLevels.DATABASE, ...data);\r\n }\r\n\r\n public debug(...data: Object[]): void {\r\n this.print(LogLevels.DEBUG, ...data);\r\n }\r\n\r\n public warning(...data: Object[]): void {\r\n this.print(LogLevels.WARNING, ...data);\r\n }\r\n\r\n public log(...data: Object[]): void {\r\n this.print(LogLevels.LOG, ...data);\r\n }\r\n\r\n public error(...data: Object[]): void {\r\n this.print(LogLevels.ERROR, ...data);\r\n }\r\n\r\n private print(level: LogLevels, ...data: Object[]): void {\r\n const now: Date = new Date();\r\n const fileName = this.tag.split(\"\\\\\").pop() || this.tag;\r\n\r\n // Attach metadata to Winston logger\r\n this.winstonLogger.defaultMeta = {\r\n file: fileName,\r\n time: now,\r\n level,\r\n };\r\n\r\n const logEntry: winston.LogEntry = {\r\n level: level.toLowerCase(),\r\n message: [...data].join(\",\"),\r\n };\r\n\r\n // Log to console with colors\r\n switch (level) {\r\n case LogLevels.INFO:\r\n console.info(blue(`[INFO][${now}][${fileName}]`), logEntry.message);\r\n break;\r\n case LogLevels.ERROR:\r\n console.error(red(`[ERROR][${now}][${fileName}]`), logEntry.message);\r\n break;\r\n case LogLevels.DEBUG:\r\n console.debug(magenta(`[DEBUG][${now}][${fileName}]`), logEntry.message);\r\n break;\r\n case LogLevels.WARNING:\r\n console.debug(yellow(`[WARNING][${now}][${fileName}]`), logEntry.message);\r\n break;\r\n case LogLevels.LOG:\r\n console.log(cyan(`[LOG][${now}][${fileName}]`), logEntry.message);\r\n break;\r\n case LogLevels.DATABASE:\r\n console.log(green(`[DATABASE][${now}][${fileName}]`), logEntry.message);\r\n break;\r\n }\r\n\r\n // Log to file\r\n this.winstonLogger.log(logEntry);\r\n }\r\n\r\n public static createLogger(tag: string, config?: { logDirectory?: string }): Logger {\r\n return new Logger(tag, config);\r\n }\r\n}\r\n"]}
package/dist/Orm.d.ts CHANGED
@@ -2,6 +2,11 @@ import { Database, Options, Transaction } from "es-node-firebird";
2
2
  export declare class Orm {
3
3
  private static logger;
4
4
  static quote(value: string): string;
5
+ private static getTimeoutMs;
6
+ private static createTimeoutError;
7
+ private static detachQuietly;
8
+ private static attachOnceWithTimeout;
9
+ private static attachWithTimeout;
5
10
  static testConnection(options: Options): Promise<boolean>;
6
11
  static query(options: Options, query: string, parameters?: any[], logQuery?: boolean): Promise<any>;
7
12
  static execute(options: Options, query: string, parameters?: any, logQuery?: boolean): Promise<any>;