|
| 1 | +import type { Manifest } from "@sap-ux/project-access"; |
| 2 | +import type { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; |
| 3 | + |
| 4 | +import type { App, Project, YamlDetails } from "./types"; |
| 5 | + |
| 6 | +type AbsoluteAppRoot = string; |
| 7 | +type AbsoluteProjectRoot = string; |
| 8 | + |
| 9 | +class Cache { |
| 10 | + private manifest: Map<AbsoluteAppRoot, Manifest>; |
| 11 | + private app: Map<AbsoluteAppRoot, App>; |
| 12 | + private project: Map<AbsoluteAppRoot, Project>; |
| 13 | + private CAPServices: Map<AbsoluteProjectRoot, Map<string, string>>; |
| 14 | + private ui5YamlDetails: Map<string, YamlDetails>; |
| 15 | + private ui5Model: Map<string, UI5SemanticModel>; |
| 16 | + constructor() { |
| 17 | + this.project = new Map(); |
| 18 | + this.manifest = new Map(); |
| 19 | + this.app = new Map(); |
| 20 | + this.CAPServices = new Map(); |
| 21 | + this.ui5YamlDetails = new Map(); |
| 22 | + this.ui5Model = new Map(); |
| 23 | + } |
| 24 | + reset() { |
| 25 | + this.project = new Map(); |
| 26 | + this.manifest = new Map(); |
| 27 | + this.app = new Map(); |
| 28 | + this.CAPServices = new Map(); |
| 29 | + this.ui5YamlDetails = new Map(); |
| 30 | + this.ui5Model = new Map(); |
| 31 | + } |
| 32 | + /** |
| 33 | + * Get entries of cached project |
| 34 | + */ |
| 35 | + getProjectEntries(): string[] { |
| 36 | + return [...this.project.keys()]; |
| 37 | + } |
| 38 | + getProject(projectRoot: AbsoluteProjectRoot): Project | undefined { |
| 39 | + return this.project.get(projectRoot); |
| 40 | + } |
| 41 | + setProject(projectRoot: AbsoluteProjectRoot, data: Project): void { |
| 42 | + this.project.set(projectRoot, data); |
| 43 | + } |
| 44 | + deleteProject(projectRoot: AbsoluteProjectRoot): boolean { |
| 45 | + return this.project.delete(projectRoot); |
| 46 | + } |
| 47 | + /** |
| 48 | + * Get entries of cached manifest |
| 49 | + */ |
| 50 | + getManifestEntries(): string[] { |
| 51 | + return [...this.manifest.keys()]; |
| 52 | + } |
| 53 | + getManifest(manifestRoot: string): Manifest | undefined { |
| 54 | + return this.manifest.get(manifestRoot); |
| 55 | + } |
| 56 | + setManifest(manifestRoot: string, data: Manifest): void { |
| 57 | + this.manifest.set(manifestRoot, data); |
| 58 | + } |
| 59 | + deleteManifest(manifestRoot: string): boolean { |
| 60 | + return this.manifest.delete(manifestRoot); |
| 61 | + } |
| 62 | + /** |
| 63 | + * Get entries of cached app |
| 64 | + */ |
| 65 | + getAppEntries(): string[] { |
| 66 | + return [...this.app.keys()]; |
| 67 | + } |
| 68 | + getApp(appRoot: string): App | undefined { |
| 69 | + return this.app.get(appRoot); |
| 70 | + } |
| 71 | + setApp(appRoot: string, data: App): void { |
| 72 | + this.app.set(appRoot, data); |
| 73 | + } |
| 74 | + deleteApp(appRoot: string): boolean { |
| 75 | + return this.app.delete(appRoot); |
| 76 | + } |
| 77 | + /** |
| 78 | + * Get entries of cached CAP services |
| 79 | + */ |
| 80 | + getCAPServiceEntries(): string[] { |
| 81 | + return [...this.CAPServices.keys()]; |
| 82 | + } |
| 83 | + getCAPServices( |
| 84 | + projectRoot: AbsoluteProjectRoot |
| 85 | + ): Map<string, string> | undefined { |
| 86 | + return this.CAPServices.get(projectRoot); |
| 87 | + } |
| 88 | + setCAPServices( |
| 89 | + projectRoot: AbsoluteProjectRoot, |
| 90 | + data: Map<string, string> |
| 91 | + ): void { |
| 92 | + this.CAPServices.set(projectRoot, data); |
| 93 | + } |
| 94 | + deleteCAPServices(projectRoot: AbsoluteProjectRoot): boolean { |
| 95 | + return this.CAPServices.delete(projectRoot); |
| 96 | + } |
| 97 | + /** |
| 98 | + * Get entries of cached yaml details |
| 99 | + */ |
| 100 | + getYamlDetailsEntries(): string[] { |
| 101 | + return [...this.ui5YamlDetails.keys()]; |
| 102 | + } |
| 103 | + getYamlDetails(documentPath: string): YamlDetails | undefined { |
| 104 | + return this.ui5YamlDetails.get(documentPath); |
| 105 | + } |
| 106 | + setYamlDetails(documentPath: string, data: YamlDetails): void { |
| 107 | + this.ui5YamlDetails.set(documentPath, data); |
| 108 | + } |
| 109 | + deleteYamlDetails(documentPath: string): boolean { |
| 110 | + return this.ui5YamlDetails.delete(documentPath); |
| 111 | + } |
| 112 | + /** |
| 113 | + * Get entries of cached UI5 model |
| 114 | + */ |
| 115 | + getUI5ModelEntries(): string[] { |
| 116 | + return [...this.ui5Model.keys()]; |
| 117 | + } |
| 118 | + getUI5Model(key: string): UI5SemanticModel | undefined { |
| 119 | + return this.ui5Model.get(key); |
| 120 | + } |
| 121 | + setUI5Model(key: string, data: UI5SemanticModel): void { |
| 122 | + this.ui5Model.set(key, data); |
| 123 | + } |
| 124 | + deleteUI5Model(key: string): boolean { |
| 125 | + return this.ui5Model.delete(key); |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +/** |
| 130 | + * Create singleton instance of Cache |
| 131 | + */ |
| 132 | +const cache = new Cache(); |
| 133 | +export { cache }; |
0 commit comments