@katlux/providers 0.1.0-beta.0 → 0.1.0-beta.2

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 (30) hide show
  1. package/dist/index.cjs +5260 -0
  2. package/dist/index.d.cts +1861 -0
  3. package/dist/index.d.mts +1861 -0
  4. package/dist/index.d.ts +1861 -0
  5. package/dist/index.mjs +5239 -0
  6. package/package.json +7 -2
  7. package/build.config.ts +0 -4
  8. package/services/CacheProvider/ACacheProvider.ts +0 -13
  9. package/services/CacheProvider/CApplicationCache.ts +0 -123
  10. package/services/CacheProvider/CCookieCache.ts +0 -212
  11. package/services/CacheProvider/CIndexedDBCache.ts +0 -312
  12. package/services/CacheProvider/CLocalStorageCache.ts +0 -232
  13. package/services/CacheProvider/CMemoryCache.ts +0 -185
  14. package/services/CacheProvider/CSessionCache.ts +0 -378
  15. package/services/CacheProvider/CacheProviderFactory.ts +0 -22
  16. package/services/DataProvider/AAPIDataProvider.ts +0 -24
  17. package/services/DataProvider/ADataProvider.ts +0 -126
  18. package/services/DataProvider/CAPIFlatClientDataProvider.ts +0 -199
  19. package/services/DataProvider/CAPIFlatServerDataProvider.ts +0 -77
  20. package/services/DataProvider/CAPITreeClientDataProvider.ts +0 -205
  21. package/services/DataProvider/CAPITreeServerDataProvider.ts +0 -98
  22. package/services/DataProvider/CFlatClientDataProvider.ts +0 -52
  23. package/services/DataProvider/CFlatServerDataProvider.ts +0 -104
  24. package/services/DataProvider/CTreeClientDataProvider.ts +0 -335
  25. package/services/DataProvider/CTreeServerDataProvider.ts +0 -207
  26. package/services/RequestProvider/RequestProvider.ts +0 -165
  27. package/services/RequestProvider/serverCache.ts +0 -24
  28. package/services/index.ts +0 -19
  29. package/services/types.ts +0 -172
  30. package/src/index.ts +0 -1
@@ -1,232 +0,0 @@
1
- import { ACacheProvider } from './ACacheProvider'
2
- import type { ICacheEntry } from '../types'
3
-
4
- export class CLocalStorageCache extends ACacheProvider {
5
- private static instance: CLocalStorageCache | null = null
6
-
7
- public static getInstance(): CLocalStorageCache {
8
- if (!this.instance) {
9
- this.instance = new CLocalStorageCache()
10
- }
11
- return this.instance
12
- }
13
-
14
- public type = 'LocalStorage'
15
-
16
- private constructor() {
17
- super()
18
- if (import.meta.client) {
19
- this._hydrateFromPayload()
20
- }
21
- }
22
-
23
- private _hydrateFromPayload() {
24
- try {
25
- const nuxtApp = typeof useNuxtApp === 'function' ? useNuxtApp() : null
26
- const payloadData = nuxtApp?.payload?.data || (window as any).__NUXT__?.payload?.data
27
- if (!payloadData) return
28
-
29
- const prefix = 'cache:'
30
- let count = 0
31
- for (const key in payloadData) {
32
- if (key.startsWith(prefix)) {
33
- const value = payloadData[key]
34
- if (value && typeof value === 'object' && 'data' in value && 'timestamp' in value && 'lifetime' in value) {
35
- try {
36
- localStorage.setItem(key, JSON.stringify(value))
37
- count++
38
- } catch (e) {
39
- // Ignore quota errors
40
- }
41
- }
42
- }
43
- }
44
- if (count > 0) console.log(`[CLocalStorageCache] Hydrated ${count} entries from payload`)
45
- } catch (e) {
46
- // Silent fail
47
- }
48
- }
49
-
50
- async getKeyList(nuxtApp?: any): Promise<Array<string>> {
51
- if (!import.meta.client) return []
52
- const prefix = 'cache:'
53
- return Object.keys(localStorage)
54
- .filter(key => key.startsWith(prefix))
55
- .map(key => key.substring(prefix.length))
56
- }
57
-
58
- async get<T>(key: string, nuxtApp?: any): Promise<T | null> {
59
- const prefixedKey = 'cache:' + key
60
-
61
- if (import.meta.client) {
62
- try {
63
- // 1. Check LocalStorage
64
- const stored = localStorage.getItem(prefixedKey)
65
- if (stored) {
66
- const entry: ICacheEntry<T> = JSON.parse(stored)
67
- if (Date.now() - entry.timestamp <= entry.lifetime) {
68
- console.log(`[CLocalStorageCache] GET SUCCESS: ${key}`)
69
- return entry.data
70
- } else {
71
- console.log(`[CLocalStorageCache] EXPIRED: ${key}`)
72
- localStorage.removeItem(prefixedKey)
73
- }
74
- } else {
75
- console.log(`[CLocalStorageCache] NOT IN STORAGE: ${key}`)
76
- }
77
- } catch (e) {
78
- // Serialisation error
79
- }
80
- }
81
-
82
- // 2. Check SSR Payload (Hydration/Request Scoped Reuse)
83
- // On server, payload is in nuxtApp. On client, it's also in nuxtApp if passed, or window.__NUXT__
84
- try {
85
- let payloadData: any = null
86
- if (import.meta.client) {
87
- payloadData = (window as any).__NUXT__?.payload?.data
88
- } else if (nuxtApp) {
89
- payloadData = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
90
- }
91
-
92
- if (payloadData && payloadData[prefixedKey]) {
93
- const entry = payloadData[prefixedKey] as ICacheEntry<T>
94
- if (Date.now() - entry.timestamp <= entry.lifetime) {
95
- if (import.meta.client) {
96
- localStorage.setItem(prefixedKey, JSON.stringify(entry))
97
- }
98
- return entry.data
99
- }
100
- }
101
- } catch (e) {
102
- // Silent fail
103
- }
104
-
105
- return null
106
- }
107
-
108
- async set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void> {
109
- const prefixedKey = 'cache:' + key
110
- const entry: ICacheEntry<T> = {
111
- data,
112
- timestamp: Date.now(),
113
- lifetime
114
- }
115
-
116
- if (import.meta.server && nuxtApp) {
117
- // Write to Payload for hydration
118
- try {
119
- const payload = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
120
- if (payload) {
121
- payload[prefixedKey] = entry
122
- }
123
- } catch (e) {
124
- // Serialisation error
125
- }
126
- }
127
-
128
- if (import.meta.client) {
129
- try {
130
- localStorage.setItem(prefixedKey, JSON.stringify(entry))
131
- } catch (e) {
132
- // Quota exceeded
133
- }
134
- }
135
- }
136
-
137
- async remove(key: string, nuxtApp?: any): Promise<void> {
138
- const prefixedKey = 'cache:' + key
139
- if (import.meta.client) {
140
- localStorage.removeItem(prefixedKey)
141
- }
142
- if (import.meta.server && nuxtApp) {
143
- try {
144
- const payload = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
145
- if (payload && payload[prefixedKey]) {
146
- delete payload[prefixedKey]
147
- }
148
- } catch (e) {
149
- // Silent fail
150
- }
151
- }
152
- }
153
-
154
- async removeByPrefix(prefix: string, nuxtApp?: any): Promise<void> {
155
- const fullPrefix = 'cache:' + prefix
156
- if (import.meta.client) {
157
- const keysToDelete: string[] = []
158
- for (let i = 0; i < localStorage.length; i++) {
159
- const key = localStorage.key(i)
160
- if (key && key.startsWith(fullPrefix)) {
161
- keysToDelete.push(key)
162
- }
163
- }
164
- for (const key of keysToDelete) {
165
- localStorage.removeItem(key)
166
- }
167
- }
168
- if (import.meta.server && nuxtApp) {
169
- try {
170
- const payload = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
171
- if (payload) {
172
- for (const key in payload) {
173
- if (key.startsWith(fullPrefix)) {
174
- delete payload[key]
175
- }
176
- }
177
- }
178
- } catch (e) {
179
- // Silent fail
180
- }
181
- }
182
- }
183
-
184
- async getRemainingTime(key: string, nuxtApp?: any): Promise<number | null> {
185
- if (import.meta.client) {
186
- const prefixedKey = 'cache:' + key
187
- const entryStr = localStorage.getItem(prefixedKey)
188
- if (!entryStr) return null
189
-
190
- try {
191
- const entry: ICacheEntry<any> = JSON.parse(entryStr)
192
- return Math.max(0, (entry.timestamp + entry.lifetime) - Date.now())
193
- } catch (e) {
194
- return null
195
- }
196
- }
197
- return null
198
- }
199
-
200
- async cleanupExpired(): Promise<void> {
201
- if (import.meta.client) {
202
- try {
203
- const prefix = 'cache:'
204
- const now = Date.now()
205
- const keysToDelete: string[] = []
206
-
207
- for (let i = 0; i < localStorage.length; i++) {
208
- const key = localStorage.key(i)
209
- if (key && key.startsWith(prefix)) {
210
- const stored = localStorage.getItem(key)
211
- if (stored) {
212
- try {
213
- const entry: ICacheEntry<any> = JSON.parse(stored)
214
- if (now - entry.timestamp > entry.lifetime) {
215
- keysToDelete.push(key)
216
- }
217
- } catch (e) {
218
- keysToDelete.push(key)
219
- }
220
- }
221
- }
222
- }
223
-
224
- for (const key of keysToDelete) {
225
- localStorage.removeItem(key)
226
- }
227
- } catch (e) {
228
- // Silent fail
229
- }
230
- }
231
- }
232
- }
@@ -1,185 +0,0 @@
1
- import { ACacheProvider } from './ACacheProvider'
2
- import type { ICacheEntry } from '../types'
3
-
4
- export class CMemoryCache extends ACacheProvider {
5
- private static instance: CMemoryCache | null = null
6
- private static _storage: Map<string, ICacheEntry<any>> | null = null
7
-
8
- private static get storage(): Map<string, ICacheEntry<any>> {
9
- if (!this._storage) this._storage = new Map()
10
- return this._storage
11
- }
12
-
13
- public static getInstance(): CMemoryCache {
14
- if (!this.instance) {
15
- this.instance = new CMemoryCache()
16
- }
17
- return this.instance
18
- }
19
-
20
- private constructor() {
21
- super()
22
- if (import.meta.client && CMemoryCache.storage.size === 0) {
23
- this._hydrateFromPayload()
24
- }
25
- }
26
-
27
- private _hydrateFromPayload() {
28
- try {
29
- const nuxtApp = typeof useNuxtApp === 'function' ? useNuxtApp() : null
30
- const payloadData = nuxtApp?.payload?.data || (globalThis as any).__NUXT__?.payload?.data
31
- if (!payloadData) return
32
-
33
- for (const key in payloadData) {
34
- const value = payloadData[key]
35
- if (value && typeof value === 'object' && 'data' in value && 'timestamp' in value && 'lifetime' in value) {
36
- if (typeof (value as any).lifetime === 'number') {
37
- CMemoryCache.storage.set(key, value as ICacheEntry<any>)
38
- }
39
- }
40
- }
41
- } catch (e) {
42
- // Silent fail
43
- }
44
- }
45
-
46
- async getKeyList(nuxtApp?: any): Promise<Array<string>> {
47
- const prefix = 'cache:'
48
- return Array.from(CMemoryCache.storage.keys())
49
- .filter(key => key.startsWith(prefix))
50
- .map(key => key.substring(prefix.length))
51
- }
52
-
53
- async get<T>(key: string, nuxtApp?: any): Promise<T | null> {
54
- const prefixedKey = 'cache:' + key
55
-
56
- if (import.meta.client) {
57
- const entry = CMemoryCache.storage.get(prefixedKey)
58
- if (entry) {
59
- if (Date.now() - entry.timestamp <= entry.lifetime) {
60
- return entry.data as T
61
- } else {
62
- CMemoryCache.storage.delete(prefixedKey)
63
- }
64
- }
65
- }
66
-
67
- // Check SSR Payload
68
- try {
69
- let payloadData: any = null
70
- if (import.meta.client) {
71
- payloadData = (globalThis as any).__NUXT__?.payload?.data
72
- } else if (nuxtApp) {
73
- payloadData = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
74
- }
75
-
76
- if (payloadData && payloadData[prefixedKey]) {
77
- const entry = payloadData[prefixedKey] as ICacheEntry<T>
78
- if (Date.now() - entry.timestamp <= entry.lifetime) {
79
- if (import.meta.client) {
80
- CMemoryCache.storage.set(prefixedKey, entry)
81
- }
82
- return entry.data
83
- }
84
- }
85
- } catch (e) {
86
- // Silent fail
87
- }
88
-
89
- return null
90
- }
91
-
92
- async set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void> {
93
- const prefixedKey = 'cache:' + key
94
- const entry: ICacheEntry<T> = {
95
- data,
96
- timestamp: Date.now(),
97
- lifetime
98
- }
99
-
100
- if (import.meta.server && nuxtApp) {
101
- try {
102
- const payload = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
103
- if (payload) {
104
- payload[prefixedKey] = entry
105
- }
106
- } catch (e) {
107
- // Silent fail
108
- }
109
- }
110
-
111
- if (import.meta.client) {
112
- CMemoryCache.storage.set(prefixedKey, entry)
113
- }
114
- }
115
-
116
- async remove(key: string, nuxtApp?: any): Promise<void> {
117
- const prefixedKey = 'cache:' + key
118
- CMemoryCache.storage.delete(prefixedKey)
119
-
120
- if (import.meta.server && nuxtApp) {
121
- try {
122
- const payload = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
123
- if (payload && payload[prefixedKey]) {
124
- delete payload[prefixedKey]
125
- }
126
- } catch (e) {
127
- // Silent fail
128
- }
129
- }
130
- }
131
-
132
- async removeByPrefix(prefix: string, nuxtApp?: any): Promise<void> {
133
- const fullPrefix = 'cache:' + prefix
134
-
135
- const keysToDelete: string[] = []
136
- for (const key of CMemoryCache.storage.keys()) {
137
- if (key.startsWith(fullPrefix)) {
138
- keysToDelete.push(key)
139
- }
140
- }
141
- for (const key of keysToDelete) {
142
- CMemoryCache.storage.delete(key)
143
- }
144
-
145
- if (import.meta.server && nuxtApp) {
146
- try {
147
- const payload = (nuxtApp as any).payload?.data || (nuxtApp as any).ssrContext?.payload?.data
148
- if (payload) {
149
- for (const key in payload) {
150
- if (key.startsWith(fullPrefix)) {
151
- delete payload[key]
152
- }
153
- }
154
- }
155
- } catch (e) {
156
- // Silent fail
157
- }
158
- }
159
- }
160
-
161
- async getRemainingTime(key: string, nuxtApp?: any): Promise<number | null> {
162
- const prefixedKey = 'cache:' + key
163
- const entry = CMemoryCache.storage.get(prefixedKey)
164
- if (!entry) return null
165
- return Math.max(0, (entry.timestamp + entry.lifetime) - Date.now())
166
- }
167
-
168
- async cleanupExpired(): Promise<void> {
169
- const prefix = 'cache:'
170
- const now = Date.now()
171
- const keysToDelete: string[] = []
172
-
173
- for (const [key, entry] of CMemoryCache.storage.entries()) {
174
- if (key.startsWith(prefix)) {
175
- if (now - entry.timestamp > entry.lifetime) {
176
- keysToDelete.push(key)
177
- }
178
- }
179
- }
180
-
181
- for (const key of keysToDelete) {
182
- CMemoryCache.storage.delete(key)
183
- }
184
- }
185
- }