@classic-homes/offline-svelte 0.1.2 → 0.1.4
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.
package/dist/__tests__/setup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vitest setup file for Svelte tests
|
|
3
3
|
*/
|
|
4
|
-
import { vi } from 'vitest';
|
|
4
|
+
import { vi, beforeEach } from 'vitest';
|
|
5
5
|
import 'fake-indexeddb/auto';
|
|
6
6
|
// Mock URL.createObjectURL and revokeObjectURL
|
|
7
7
|
global.URL.createObjectURL = vi.fn((blob) => `blob:mock-${blob.size}`);
|
|
@@ -16,3 +16,33 @@ Object.defineProperty(navigator, 'storage', {
|
|
|
16
16
|
},
|
|
17
17
|
writable: true,
|
|
18
18
|
});
|
|
19
|
+
// Mock localStorage for tests
|
|
20
|
+
const localStorageStore = {};
|
|
21
|
+
const localStorageMock = {
|
|
22
|
+
getItem: vi.fn((key) => localStorageStore[key] ?? null),
|
|
23
|
+
setItem: vi.fn((key, value) => {
|
|
24
|
+
localStorageStore[key] = value;
|
|
25
|
+
}),
|
|
26
|
+
removeItem: vi.fn((key) => {
|
|
27
|
+
delete localStorageStore[key];
|
|
28
|
+
}),
|
|
29
|
+
clear: vi.fn(() => {
|
|
30
|
+
for (const key of Object.keys(localStorageStore)) {
|
|
31
|
+
delete localStorageStore[key];
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
get length() {
|
|
35
|
+
return Object.keys(localStorageStore).length;
|
|
36
|
+
},
|
|
37
|
+
key: vi.fn((index) => Object.keys(localStorageStore)[index] ?? null),
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(globalThis, 'localStorage', {
|
|
40
|
+
value: localStorageMock,
|
|
41
|
+
writable: true,
|
|
42
|
+
});
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
for (const key of Object.keys(localStorageStore)) {
|
|
45
|
+
delete localStorageStore[key];
|
|
46
|
+
}
|
|
47
|
+
vi.clearAllMocks();
|
|
48
|
+
});
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* {/if}
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
+
import { invalidateCacheByTag, invalidateAllCache } from '@classic-homes/offline-core';
|
|
32
33
|
export interface UseOfflineCacheOptions<T = unknown> {
|
|
33
34
|
/** Cache key */
|
|
34
35
|
key: string;
|
|
@@ -73,11 +74,4 @@ export interface UseOfflineCacheReturn<T> {
|
|
|
73
74
|
* Create a cache composable for a specific key
|
|
74
75
|
*/
|
|
75
76
|
export declare function useOfflineCache<T>(options: UseOfflineCacheOptions<T>): UseOfflineCacheReturn<T>;
|
|
76
|
-
|
|
77
|
-
* Invalidate cache entries by tag
|
|
78
|
-
*/
|
|
79
|
-
export declare function invalidateCacheByTag(tag: string): Promise<number>;
|
|
80
|
-
/**
|
|
81
|
-
* Invalidate all cache entries
|
|
82
|
-
*/
|
|
83
|
-
export declare function invalidateAllCache(): Promise<number>;
|
|
77
|
+
export { invalidateCacheByTag, invalidateAllCache };
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* {/if}
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
import { getOfflineStorage, isOfflineStorageInitialized, } from '@classic-homes/offline-core';
|
|
32
|
+
import { getOfflineStorage, isOfflineStorageInitialized, invalidateCacheByTag, invalidateAllCache, } from '@classic-homes/offline-core';
|
|
33
33
|
/**
|
|
34
34
|
* Create a cache composable for a specific key
|
|
35
35
|
*/
|
|
@@ -207,23 +207,4 @@ export function useOfflineCache(options) {
|
|
|
207
207
|
has,
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
|
|
211
|
-
* Invalidate cache entries by tag
|
|
212
|
-
*/
|
|
213
|
-
export async function invalidateCacheByTag(tag) {
|
|
214
|
-
if (!isOfflineStorageInitialized()) {
|
|
215
|
-
return 0;
|
|
216
|
-
}
|
|
217
|
-
const storage = getOfflineStorage();
|
|
218
|
-
return storage.cache.invalidateByTag(tag);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Invalidate all cache entries
|
|
222
|
-
*/
|
|
223
|
-
export async function invalidateAllCache() {
|
|
224
|
-
if (!isOfflineStorageInitialized()) {
|
|
225
|
-
return 0;
|
|
226
|
-
}
|
|
227
|
-
const storage = getOfflineStorage();
|
|
228
|
-
return storage.cache.invalidateAll();
|
|
229
|
-
}
|
|
210
|
+
export { invalidateCacheByTag, invalidateAllCache };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/offline-svelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Svelte bindings for offline persistence and caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "svelte-package -i src",
|
|
36
36
|
"dev": "svelte-package -i src --watch",
|
|
37
|
-
"clean": "rm
|
|
38
|
-
"typecheck": "
|
|
37
|
+
"clean": "node ../../scripts/rm.mjs dist",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
39
|
"test": "vitest run",
|
|
40
40
|
"test:watch": "vitest",
|
|
41
41
|
"test:coverage": "vitest run --coverage"
|
|
@@ -71,15 +71,15 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@sveltejs/package": "^2.3.0",
|
|
74
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
74
|
+
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
75
75
|
"@testing-library/svelte": "^5.0.0",
|
|
76
|
-
"@vitest/coverage-v8": "^
|
|
76
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
77
77
|
"fake-indexeddb": "^6.0.0",
|
|
78
78
|
"jsdom": "^25.0.0",
|
|
79
79
|
"svelte": "^5.0.0",
|
|
80
80
|
"svelte-check": "^4.0.0",
|
|
81
81
|
"typescript": "^5.3.0",
|
|
82
|
-
"vitest": "^
|
|
82
|
+
"vitest": "^4.1.10",
|
|
83
83
|
"zod": "^3.23.0"
|
|
84
84
|
}
|
|
85
85
|
}
|