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

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 +16 -0
  2. package/dist/index.d.cts +1 -0
  3. package/dist/index.d.mts +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.mjs +35 -0
  6. package/package.json +5 -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
package/dist/index.cjs ADDED
@@ -0,0 +1,16 @@
1
+ const { createJiti } = require("../../../node_modules/jiti/lib/jiti.cjs")
2
+
3
+ const jiti = createJiti(__filename, {
4
+ "interopDefault": true,
5
+ "alias": {
6
+ "@katlux/providers": "/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers"
7
+ },
8
+ "transformOptions": {
9
+ "babel": {
10
+ "plugins": []
11
+ }
12
+ }
13
+ })
14
+
15
+ /** @type {import("/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index")} */
16
+ module.exports = jiti("/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index.ts")
@@ -0,0 +1 @@
1
+ export * from "/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index";
@@ -0,0 +1 @@
1
+ export * from "/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index";
@@ -0,0 +1 @@
1
+ export * from "/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index";
package/dist/index.mjs ADDED
@@ -0,0 +1,35 @@
1
+ import { createJiti } from "../../../node_modules/jiti/lib/jiti.mjs";
2
+
3
+ const jiti = createJiti(import.meta.url, {
4
+ "interopDefault": true,
5
+ "alias": {
6
+ "@katlux/providers": "/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers"
7
+ },
8
+ "transformOptions": {
9
+ "babel": {
10
+ "plugins": []
11
+ }
12
+ }
13
+ })
14
+
15
+ /** @type {import("/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index")} */
16
+ const _module = await jiti.import("/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-providers/src/index.ts");
17
+
18
+ export const ECacheStrategy = _module.ECacheStrategy;
19
+ export const EDataFilterOperator = _module.EDataFilterOperator;
20
+ export const CFlatClientDataProvider = _module.CFlatClientDataProvider;
21
+ export const CAPIFlatClientDataProvider = _module.CAPIFlatClientDataProvider;
22
+ export const CAPIFlatServerDataProvider = _module.CAPIFlatServerDataProvider;
23
+ export const CFlatServerDataProvider = _module.CFlatServerDataProvider;
24
+ export const CTreeClientDataProvider = _module.CTreeClientDataProvider;
25
+ export const CAPITreeClientDataProvider = _module.CAPITreeClientDataProvider;
26
+ export const CTreeServerDataProvider = _module.CTreeServerDataProvider;
27
+ export const CAPITreeServerDataProvider = _module.CAPITreeServerDataProvider;
28
+ export const CacheProviderFactory = _module.CacheProviderFactory;
29
+ export const CSessionCache = _module.CSessionCache;
30
+ export const CCookieCache = _module.CCookieCache;
31
+ export const CLocalStorageCache = _module.CLocalStorageCache;
32
+ export const CIndexedDBCache = _module.CIndexedDBCache;
33
+ export const CMemoryCache = _module.CMemoryCache;
34
+ export const CApplicationCache = _module.CApplicationCache;
35
+ export const RequestProvider = _module.RequestProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@katlux/providers",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "Core data calculation and caching providers for the Katlux ecosystem",
5
5
  "author": "Katlux",
6
6
  "license": "MIT",
@@ -20,5 +20,8 @@
20
20
  "require": "./dist/index.cjs"
21
21
  }
22
22
  },
23
- "dependencies": {}
23
+ "dependencies": {},
24
+ "files": [
25
+ "dist"
26
+ ]
24
27
  }
package/build.config.ts DELETED
@@ -1,4 +0,0 @@
1
- export default {
2
- failOnWarn: false,
3
- externals: ['#app', '@katlux/toolkit']
4
- }
@@ -1,13 +0,0 @@
1
- export abstract class ACacheProvider {
2
- constructor() {
3
- // Cleanup expired entries on initialization
4
- this.cleanupExpired()
5
- }
6
- abstract getKeyList(nuxtApp?: any): Array<string> | Promise<Array<string>>
7
- abstract get<T>(key: string, nuxtApp?: any): Promise<T | null>
8
- abstract set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void>
9
- abstract remove(key: string, nuxtApp?: any): Promise<void>
10
- abstract removeByPrefix(prefix: string, nuxtApp?: any): Promise<void>
11
- abstract getRemainingTime(key: string, nuxtApp?: any): Promise<number | null>
12
- abstract cleanupExpired(): Promise<void>
13
- }
@@ -1,123 +0,0 @@
1
- import { ACacheProvider } from './ACacheProvider'
2
- import type { ICacheEntry } from '../types'
3
-
4
- export class CApplicationCache extends ACacheProvider {
5
- private static instance: CApplicationCache | 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) {
10
- this._storage = new Map<string, ICacheEntry<any>>()
11
- }
12
- return this._storage
13
- }
14
-
15
- public static getInstance(): CApplicationCache {
16
- if (!this.instance) {
17
- this.instance = new CApplicationCache()
18
- }
19
- return this.instance
20
- }
21
-
22
- public static getSnapshot(): Map<string, ICacheEntry<any>> {
23
- return this.storage
24
- }
25
-
26
- private constructor() {
27
- super()
28
- }
29
-
30
- async getKeyList(nuxtApp?: any): Promise<Array<string>> {
31
- const prefix = 'cache:'
32
- const storage = CApplicationCache.storage
33
- return Array.from(storage.keys())
34
- .filter(key => key.startsWith(prefix))
35
- .map(key => key.substring(prefix.length))
36
- }
37
-
38
- async get<T>(key: string, nuxtApp?: any): Promise<T | null> {
39
- if (import.meta.server) {
40
- const prefixedKey = 'cache:' + key
41
- const storage = CApplicationCache.storage
42
- const entry = storage.get(prefixedKey)
43
- if (!entry) return null
44
-
45
- if (Date.now() - entry.timestamp > entry.lifetime) {
46
- storage.delete(prefixedKey)
47
- return null
48
- }
49
-
50
- return entry.data as T
51
- }
52
- return null
53
- }
54
-
55
- async set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void> {
56
- if (import.meta.server) {
57
- const prefixedKey = 'cache:' + key
58
- const storage = CApplicationCache.storage
59
- storage.set(prefixedKey, {
60
- data,
61
- timestamp: Date.now(),
62
- lifetime
63
- })
64
- }
65
- }
66
-
67
- async remove(key: string, nuxtApp?: any): Promise<void> {
68
- if (import.meta.server) {
69
- const prefixedKey = 'cache:' + key
70
- CApplicationCache.storage.delete(prefixedKey)
71
- }
72
- }
73
-
74
- async removeByPrefix(prefix: string, nuxtApp?: any): Promise<void> {
75
- if (import.meta.server) {
76
- const fullPrefix = 'cache:' + prefix
77
- const storage = CApplicationCache.storage
78
- const keysToDelete: string[] = []
79
-
80
- for (const key of storage.keys()) {
81
- if (key.startsWith(fullPrefix)) {
82
- keysToDelete.push(key)
83
- }
84
- }
85
-
86
- for (const key of keysToDelete) {
87
- storage.delete(key)
88
- }
89
- }
90
- }
91
-
92
- async getRemainingTime(key: string, nuxtApp?: any): Promise<number | null> {
93
- if (import.meta.server) {
94
- const prefixedKey = 'cache:' + key
95
- const storage = CApplicationCache.storage
96
- const entry = storage.get(prefixedKey)
97
- if (!entry) return null
98
- return Math.max(0, (entry.timestamp + entry.lifetime) - Date.now())
99
- }
100
- return null
101
- }
102
-
103
- async cleanupExpired(): Promise<void> {
104
- if (import.meta.server) {
105
- const prefix = 'cache:'
106
- const now = Date.now()
107
- const storage = CApplicationCache.storage
108
- const keysToDelete: string[] = []
109
-
110
- for (const [key, entry] of storage.entries()) {
111
- if (key.startsWith(prefix)) {
112
- if (now - entry.timestamp > entry.lifetime) {
113
- keysToDelete.push(key)
114
- }
115
- }
116
- }
117
-
118
- for (const key of keysToDelete) {
119
- storage.delete(key)
120
- }
121
- }
122
- }
123
- }
@@ -1,212 +0,0 @@
1
- import { ACacheProvider } from './ACacheProvider'
2
- import type { ICacheEntry } from '../types'
3
-
4
- export class CCookieCache extends ACacheProvider {
5
- private static instance: CCookieCache | null = null
6
-
7
- public static getInstance(): CCookieCache {
8
- if (!this.instance) {
9
- this.instance = new CCookieCache()
10
- }
11
- return this.instance
12
- }
13
-
14
- public type = 'Cookie'
15
-
16
- private constructor() {
17
- super()
18
- }
19
-
20
- async getKeyList(nuxtApp?: any): Promise<Array<string>> {
21
- const prefix = 'cache:'
22
- let cookieStr = ''
23
-
24
- if (import.meta.client) {
25
- cookieStr = document.cookie
26
- } else if (nuxtApp) {
27
- // Extract from H3Event or SSR Context
28
- const headers = (nuxtApp as any).node?.req?.headers || (nuxtApp as any).ssrContext?.event?.node?.req?.headers
29
- cookieStr = headers?.['cookie'] || ''
30
- }
31
-
32
- if (!cookieStr) return []
33
-
34
- const keys: string[] = []
35
- const cookies = cookieStr.split(';')
36
- for (let i = 0; i < cookies.length; i++) {
37
- const cookie = cookies[i].trim()
38
- const eqPos = cookie.indexOf('=')
39
- if (eqPos > 0) {
40
- const name = decodeURIComponent(cookie.substring(0, eqPos))
41
- if (name.startsWith(prefix)) {
42
- keys.push(name.substring(prefix.length))
43
- }
44
- }
45
- }
46
- return keys
47
- }
48
-
49
- async get<T>(key: string, nuxtApp?: any): Promise<T | null> {
50
- const prefixedKey = 'cache:' + key
51
- let cookieValue: string | null = null
52
-
53
- if (import.meta.client) {
54
- const name = prefixedKey + '='
55
- const ca = document.cookie.split(';')
56
- for (let i = 0; i < ca.length; i++) {
57
- let c = ca[i].trim()
58
- if (c.indexOf(name) === 0) {
59
- cookieValue = c.substring(name.length, c.length)
60
- break
61
- }
62
- }
63
- } else if (nuxtApp) {
64
- const headers = (nuxtApp as any).node?.req?.headers || (nuxtApp as any).ssrContext?.event?.node?.req?.headers
65
- const cookieStr = headers?.['cookie'] || ''
66
- const name = prefixedKey + '='
67
- const ca = cookieStr.split(';')
68
- for (let i = 0; i < ca.length; i++) {
69
- let c = ca[i].trim()
70
- if (c.indexOf(name) === 0) {
71
- cookieValue = c.substring(name.length, c.length)
72
- break
73
- }
74
- }
75
- }
76
-
77
- if (!cookieValue) return null
78
-
79
- try {
80
- const val = JSON.parse(decodeURIComponent(cookieValue)) as ICacheEntry<T>
81
- if (val && val.timestamp && val.lifetime) {
82
- if (Date.now() - val.timestamp <= val.lifetime) {
83
- return val.data
84
- } else {
85
- // Expired
86
- await this.set(key, null as any, 0, nuxtApp)
87
- }
88
- }
89
- return null
90
- } catch (e) {
91
- return null
92
- }
93
- }
94
-
95
- async set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void> {
96
- const prefixedKey = 'cache:' + key
97
- const entry: ICacheEntry<T> = {
98
- data,
99
- timestamp: Date.now(),
100
- lifetime
101
- }
102
-
103
- const cookieValue = encodeURIComponent(JSON.stringify(entry))
104
- const maxAge = Math.floor(lifetime / 1000)
105
- const expires = new Date(Date.now() + lifetime).toUTCString()
106
- const cookieStr = `${prefixedKey}=${cookieValue}; Max-Age=${maxAge}; Path=/; SameSite=Lax${import.meta.server ? '; HttpOnly' : ''}`
107
-
108
- if (import.meta.client) {
109
- document.cookie = cookieStr
110
- } else if (nuxtApp) {
111
- const res = (nuxtApp as any).node?.res || (nuxtApp as any).ssrContext?.event?.node?.res
112
- if (res) {
113
- const existing = res.getHeader('Set-Cookie')
114
- if (!existing) {
115
- res.setHeader('Set-Cookie', cookieStr)
116
- } else if (Array.isArray(existing)) {
117
- res.setHeader('Set-Cookie', [...existing, cookieStr])
118
- } else {
119
- res.setHeader('Set-Cookie', [existing as string, cookieStr])
120
- }
121
- }
122
- }
123
- }
124
-
125
- async remove(key: string, nuxtApp?: any): Promise<void> {
126
- const prefixedKey = 'cache:' + key
127
- const cookieStr = `${prefixedKey}=; Max-Age=0; Path=/; SameSite=Lax${import.meta.server ? '; HttpOnly' : ''}`
128
-
129
- if (import.meta.client) {
130
- document.cookie = cookieStr
131
- } else if (nuxtApp) {
132
- const res = (nuxtApp as any).node?.res || (nuxtApp as any).ssrContext?.event?.node?.res
133
- if (res) {
134
- const existing = res.getHeader('Set-Cookie')
135
- if (!existing) {
136
- res.setHeader('Set-Cookie', cookieStr)
137
- } else if (Array.isArray(existing)) {
138
- res.setHeader('Set-Cookie', [...existing, cookieStr])
139
- } else {
140
- res.setHeader('Set-Cookie', [existing as string, cookieStr])
141
- }
142
- }
143
- }
144
- }
145
-
146
- async getRemainingTime(key: string, nuxtApp?: any): Promise<number | null> {
147
- const prefixedKey = 'cache:' + key
148
- let cookieValue: string | null = null
149
-
150
- if (import.meta.client) {
151
- const name = prefixedKey + '='
152
- const ca = document.cookie.split(';')
153
- for (let i = 0; i < ca.length; i++) {
154
- let c = ca[i].trim()
155
- if (c.indexOf(name) === 0) {
156
- cookieValue = c.substring(name.length, c.length)
157
- break
158
- }
159
- }
160
- } else if (nuxtApp) {
161
- const headers = (nuxtApp as any).node?.req?.headers || (nuxtApp as any).ssrContext?.event?.node?.req?.headers
162
- const cookieStr = headers?.['cookie'] || ''
163
- const name = prefixedKey + '='
164
- const ca = cookieStr.split(';')
165
- for (let i = 0; i < ca.length; i++) {
166
- let c = ca[i].trim()
167
- if (c.indexOf(name) === 0) {
168
- cookieValue = c.substring(name.length, c.length)
169
- break
170
- }
171
- }
172
- }
173
-
174
- if (!cookieValue) return null
175
-
176
- try {
177
- const val = JSON.parse(decodeURIComponent(cookieValue)) as ICacheEntry<any>
178
- if (val && val.timestamp && val.lifetime) {
179
- return Math.max(0, (val.timestamp + val.lifetime) - Date.now())
180
- }
181
- return null
182
- } catch (e) {
183
- return null
184
- }
185
- }
186
-
187
- async cleanupExpired(): Promise<void> {
188
- if (import.meta.client) {
189
- const prefix = 'cache:'
190
- const now = Date.now()
191
- const cookies = document.cookie.split(';')
192
- for (let i = 0; i < cookies.length; i++) {
193
- const cookie = cookies[i].trim()
194
- const eqPos = cookie.indexOf('=')
195
- if (eqPos > 0) {
196
- const name = decodeURIComponent(cookie.substring(0, eqPos))
197
- if (name.startsWith(prefix)) {
198
- const value = decodeURIComponent(cookie.substring(eqPos + 1))
199
- try {
200
- const entry: ICacheEntry<any> = JSON.parse(value)
201
- if (now - entry.timestamp > entry.lifetime) {
202
- document.cookie = `${encodeURIComponent(name)}=; max-age=0; path=/`
203
- }
204
- } catch (e) {
205
- document.cookie = `${encodeURIComponent(name)}=; max-age=0; path=/`
206
- }
207
- }
208
- }
209
- }
210
- }
211
- }
212
- }