1+ import { NodeCache } from '@cacheable/node-cache'
12import { minutesToSeconds , secondsToMillis } from '@cityssm/to-millis'
23import type { config as MSSQLConfig } from 'mssql'
3- import NodeCache from 'node-cache'
44
55import _extendGpInvoice from './diamond/extendGpInvoice.js'
66import _getCashReceiptByDocumentNumber from './diamond/getCashReceiptByDocumentNumber.js'
@@ -55,17 +55,17 @@ export class DynamicsGP {
5555 readonly #mssqlConfig: MSSQLConfig
5656 readonly #options: DynamicsGPOptions
5757
58- readonly #accountCache: NodeCache
59- readonly #customerCache: NodeCache
60- readonly #invoiceCache: NodeCache
61- readonly #itemCache: NodeCache
62- readonly #vendorCache: NodeCache
58+ readonly #accountCache: NodeCache < GPAccount | undefined >
59+ readonly #customerCache: NodeCache < GPCustomer | undefined >
60+ readonly #invoiceCache: NodeCache < GPInvoice | undefined >
61+ readonly #itemCache: NodeCache < GPItemWithQuantities | undefined >
62+ readonly #vendorCache: NodeCache < GPVendor | undefined >
6363
6464 #invoiceDocumentTypesCache: GPInvoiceDocumentType [ ] = [ ]
6565 #invoiceDocumentTypesCacheExpiryMillis = 0
6666
67- readonly #diamondCashReceiptCache: NodeCache
68- readonly #diamondInvoiceCache: NodeCache
67+ readonly #diamondCashReceiptCache: NodeCache < DiamondCashReceipt | undefined >
68+ readonly #diamondInvoiceCache: NodeCache < DiamondExtendedGPInvoice | undefined >
6969
7070 constructor ( mssqlConfig : MSSQLConfig , options ?: Partial < DynamicsGPOptions > ) {
7171 this . #mssqlConfig = mssqlConfig
@@ -107,8 +107,7 @@ export class DynamicsGP {
107107 async getAccountByAccountIndex (
108108 accountIndex : number | string
109109 ) : Promise < GPAccount | undefined > {
110- let account : GPAccount | undefined =
111- this . #accountCache. get ( accountIndex ) ?? undefined
110+ let account = this . #accountCache. get ( accountIndex ) ?? undefined
112111
113112 if ( account === undefined ) {
114113 account = await _getAccountByAccountIndex ( this . #mssqlConfig, accountIndex )
@@ -121,8 +120,7 @@ export class DynamicsGP {
121120 async getCustomerByCustomerNumber (
122121 customerNumber : string
123122 ) : Promise < GPCustomer | undefined > {
124- let customer : GPCustomer | undefined =
125- this . #customerCache. get ( customerNumber ) ?? undefined
123+ let customer = this . #customerCache. get ( customerNumber ) ?? undefined
126124
127125 if ( customer === undefined ) {
128126 customer = await _getCustomerByCustomerNumber (
@@ -145,8 +143,7 @@ export class DynamicsGP {
145143 invoiceDocumentTypeOrAbbreviationOrName
146144 )
147145
148- let invoice : GPInvoice | undefined =
149- this . #invoiceCache. get ( cacheKey ) ?? undefined
146+ let invoice = this . #invoiceCache. get ( cacheKey ) ?? undefined
150147
151148 if ( invoice === undefined || skipCache ) {
152149 invoice = await _getInvoiceByInvoiceNumber (
@@ -189,8 +186,7 @@ export class DynamicsGP {
189186 async getItemByItemNumber (
190187 itemNumber : string
191188 ) : Promise < GPItemWithQuantities | undefined > {
192- let item : GPItemWithQuantities | undefined =
193- this . #itemCache. get ( itemNumber ) ?? undefined
189+ let item = this . #itemCache. get ( itemNumber ) ?? undefined
194190
195191 if ( item === undefined ) {
196192 item = await _getItemByItemNumber ( this . #mssqlConfig, itemNumber )
@@ -207,8 +203,7 @@ export class DynamicsGP {
207203 }
208204
209205 async getVendorByVendorId ( vendorId : string ) : Promise < GPVendor | undefined > {
210- let vendor : GPVendor | undefined =
211- this . #vendorCache. get ( vendorId ) ?? undefined
206+ let vendor = this . #vendorCache. get ( vendorId ) ?? undefined
212207
213208 if ( vendor === undefined ) {
214209 const vendors = await this . getVendors ( { vendorId } )
@@ -228,8 +223,7 @@ export class DynamicsGP {
228223 async getDiamondCashReceiptByDocumentNumber (
229224 documentNumber : number | string
230225 ) : Promise < DiamondCashReceipt | undefined > {
231- let receipt : DiamondCashReceipt | undefined =
232- this . #diamondCashReceiptCache. get ( documentNumber )
226+ let receipt = this . #diamondCashReceiptCache. get ( documentNumber )
233227
234228 if ( receipt === undefined ) {
235229 receipt = await _getCashReceiptByDocumentNumber (
@@ -251,8 +245,7 @@ export class DynamicsGP {
251245 invoiceDocumentTypeOrAbbreviationOrName
252246 )
253247
254- let diamondInvoice : DiamondExtendedGPInvoice | undefined =
255- this . #diamondInvoiceCache. get ( cacheKey ) ?? undefined
248+ let diamondInvoice = this . #diamondInvoiceCache. get ( cacheKey ) ?? undefined
256249
257250 if ( diamondInvoice === undefined ) {
258251 const gpInvoice = await this . #getInvoiceByInvoiceNumber(
0 commit comments