@cachemap/map
Version:
The Cachemap Map module.
1 lines • 3.89 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../map/src//main/index.ts"],"sourcesContent":["import { type Store, type StoreInit, type StoreOptions } from '@cachemap/types';\nimport { isNumber, isPlainObject } from 'lodash-es';\nimport { type ConstructorOptions, type InitOptions, type Options } from '../types.ts';\n\nexport class MapStore implements Store {\n public static init(options: InitOptions): Promise<MapStore> {\n return Promise.resolve(new MapStore(options));\n }\n\n public readonly type = 'map';\n private _map = new Map<string, string>();\n private readonly _maxHeapSize: number = 5_242_880;\n private readonly _name: string;\n\n constructor(options: ConstructorOptions) {\n if (isNumber(options.maxHeapSize)) {\n this._maxHeapSize = options.maxHeapSize;\n }\n\n this._name = options.name;\n }\n\n public clear(): Promise<void> {\n this._map.clear();\n return Promise.resolve();\n }\n\n public delete(key: string): Promise<boolean> {\n return Promise.resolve(this._map.delete(key));\n }\n\n public entries(keys?: string[]): Promise<[string, string][]> {\n const entries = this._map.entries();\n\n if (!keys) {\n return Promise.resolve([...entries]);\n }\n\n const filtered: [string, string][] = [];\n\n for (const [key, value] of entries) {\n if (keys.includes(key)) {\n filtered.push([key, value]);\n }\n }\n\n return Promise.resolve(filtered);\n }\n\n public get(key: string): Promise<string | undefined> {\n return Promise.resolve(this._map.get(key));\n }\n\n public has(key: string): Promise<boolean> {\n return Promise.resolve(this._map.get(key) !== undefined);\n }\n\n public import(entries: [string, string][]): Promise<void> {\n this._map = new Map([...this._map, ...entries]);\n return Promise.resolve();\n }\n\n get maxHeapSize(): number {\n return this._maxHeapSize;\n }\n\n get name(): string {\n return this._name;\n }\n\n public set(key: string, value: string): Promise<void> {\n this._map.set(key, value);\n return Promise.resolve();\n }\n\n public size(): Promise<number> {\n return Promise.resolve(this._map.size);\n }\n}\n\nexport const init = (options: Options = {}): StoreInit => {\n if (!isPlainObject(options)) {\n throw new TypeError('@cachemap/map expected options to be a plain object.');\n }\n\n return (storeOptions: StoreOptions) => MapStore.init({ ...options, ...storeOptions });\n};\n"],"names":["MapStore","init","options","Promise","resolve","constructor","type","_map","Map","_maxHeapSize","isNumber","maxHeapSize","this","_name","name","clear","delete","key","entries","keys","filtered","value","includes","push","get","has","undefined","import","set","size","isPlainObject","TypeError","storeOptions"],"mappings":"oFAIO,MAAMA,EACX,WAAcC,CAAKC,GACjB,OAAOC,QAAQC,QAAQ,IAAIJ,EAASE,GACtC,CAOA,WAAAG,CAAYH,QALII,KAAO,MACfC,KAAAA,KAAO,IAAIC,SACFC,aAAuB,QAIlCC,EAAAA,SAASR,EAAQS,eACnBC,KAAKH,aAAeP,EAAQS,aAG9BC,KAAKC,MAAQX,EAAQY,IACvB,CAEOC,KAAAA,GAEL,OADAH,KAAKL,KAAKQ,QACHZ,QAAQC,SACjB,CAEOY,OAAOC,GACZ,OAAOd,QAAQC,QAAQQ,KAAKL,KAAKS,OAAOC,GAC1C,CAEOC,OAAAA,CAAQC,GACb,MAAMD,EAAUN,KAAKL,KAAKW,UAE1B,IAAKC,EACH,OAAOhB,QAAQC,QAAQ,IAAIc,IAG7B,MAAME,EAA+B,GAErC,IAAK,MAAOH,EAAKI,KAAUH,EACrBC,EAAKG,SAASL,IAChBG,EAASG,KAAK,CAACN,EAAKI,IAIxB,OAAOlB,QAAQC,QAAQgB,EACzB,CAEOI,GAAAA,CAAIP,GACT,OAAOd,QAAQC,QAAQQ,KAAKL,KAAKiB,IAAIP,GACvC,CAEOQ,GAAAA,CAAIR,GACT,OAAOd,QAAQC,aAA+BsB,IAAvBd,KAAKL,KAAKiB,IAAIP,GACvC,CAEOU,MAAAA,CAAOT,GAEZ,OADAN,KAAKL,KAAO,IAAIC,IAAI,IAAII,KAAKL,QAASW,IAC/Bf,QAAQC,SACjB,CAEA,eAAIO,GACF,OAAOC,KAAKH,YACd,CAEA,QAAIK,GACF,OAAOF,KAAKC,KACd,CAEOe,GAAAA,CAAIX,EAAaI,GAEtB,OADAT,KAAKL,KAAKqB,IAAIX,EAAKI,GACZlB,QAAQC,SACjB,CAEOyB,IAAAA,GACL,OAAO1B,QAAQC,QAAQQ,KAAKL,KAAKsB,KACnC,kCAGkB,CAAC3B,EAAmB,MACtC,IAAK4B,EAAAA,cAAc5B,GACjB,MAAM,IAAI6B,UAAU,wDAGtB,OAAQC,GAA+BhC,EAASC,KAAK,IAAKC,KAAY8B,GAAa"}