@fjell/cache 4.6.14 โ†’ 4.6.16

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 (90) hide show
  1. package/dist/Aggregator.d.ts +3 -3
  2. package/dist/Cache.d.ts +5 -5
  3. package/dist/CacheMap.d.ts +1 -1
  4. package/dist/Instance.d.ts +4 -4
  5. package/dist/InstanceFactory.d.ts +3 -3
  6. package/dist/Operations.d.ts +4 -4
  7. package/dist/index.js +715 -0
  8. package/dist/index.js.map +7 -0
  9. package/dist/logger.d.ts +1 -1
  10. package/dist/ops/action.d.ts +3 -3
  11. package/dist/ops/all.d.ts +3 -3
  12. package/dist/ops/allAction.d.ts +3 -3
  13. package/dist/ops/allFacet.d.ts +3 -3
  14. package/dist/ops/create.d.ts +3 -3
  15. package/dist/ops/facet.d.ts +3 -3
  16. package/dist/ops/find.d.ts +3 -3
  17. package/dist/ops/findOne.d.ts +3 -3
  18. package/dist/ops/get.d.ts +3 -3
  19. package/dist/ops/one.d.ts +3 -3
  20. package/dist/ops/remove.d.ts +3 -3
  21. package/dist/ops/reset.d.ts +3 -3
  22. package/dist/ops/retrieve.d.ts +3 -3
  23. package/dist/ops/set.d.ts +2 -2
  24. package/dist/ops/update.d.ts +3 -3
  25. package/package.json +14 -18
  26. package/dist/Aggregator.cjs.js +0 -322
  27. package/dist/Aggregator.es.js +0 -317
  28. package/dist/Cache.cjs.js +0 -35
  29. package/dist/Cache.es.js +0 -30
  30. package/dist/CacheMap.cjs.js +0 -170
  31. package/dist/CacheMap.es.js +0 -166
  32. package/dist/Instance.cjs.js +0 -23
  33. package/dist/Instance.es.js +0 -18
  34. package/dist/InstanceFactory.cjs.js +0 -35
  35. package/dist/InstanceFactory.es.js +0 -31
  36. package/dist/Operations.cjs.js +0 -43
  37. package/dist/Operations.es.js +0 -39
  38. package/dist/Registry.cjs.js +0 -36
  39. package/dist/Registry.es.js +0 -31
  40. package/dist/index.cjs +0 -940
  41. package/dist/index.cjs.js +0 -26
  42. package/dist/index.cjs.map +0 -1
  43. package/dist/index.es.js +0 -8
  44. package/dist/logger.cjs.js +0 -10
  45. package/dist/logger.es.js +0 -6
  46. package/dist/ops/action.cjs.js +0 -28
  47. package/dist/ops/action.es.js +0 -24
  48. package/dist/ops/all.cjs.js +0 -33
  49. package/dist/ops/all.es.js +0 -29
  50. package/dist/ops/allAction.cjs.js +0 -35
  51. package/dist/ops/allAction.es.js +0 -31
  52. package/dist/ops/allFacet.cjs.js +0 -22
  53. package/dist/ops/allFacet.es.js +0 -18
  54. package/dist/ops/create.cjs.js +0 -23
  55. package/dist/ops/create.es.js +0 -19
  56. package/dist/ops/facet.cjs.js +0 -21
  57. package/dist/ops/facet.es.js +0 -17
  58. package/dist/ops/find.cjs.js +0 -26
  59. package/dist/ops/find.es.js +0 -22
  60. package/dist/ops/findOne.cjs.js +0 -24
  61. package/dist/ops/findOne.es.js +0 -20
  62. package/dist/ops/get.cjs.js +0 -38
  63. package/dist/ops/get.es.js +0 -34
  64. package/dist/ops/one.cjs.js +0 -33
  65. package/dist/ops/one.es.js +0 -29
  66. package/dist/ops/remove.cjs.js +0 -30
  67. package/dist/ops/remove.es.js +0 -26
  68. package/dist/ops/reset.cjs.js +0 -15
  69. package/dist/ops/reset.es.js +0 -11
  70. package/dist/ops/retrieve.cjs.js +0 -37
  71. package/dist/ops/retrieve.es.js +0 -33
  72. package/dist/ops/set.cjs.js +0 -71
  73. package/dist/ops/set.es.js +0 -67
  74. package/dist/ops/update.cjs.js +0 -34
  75. package/dist/ops/update.es.js +0 -30
  76. package/docs/docs.config.ts +0 -75
  77. package/docs/index.html +0 -18
  78. package/docs/package.json +0 -34
  79. package/docs/public/README.md +0 -96
  80. package/docs/public/examples-README.md +0 -302
  81. package/docs/public/test.txt +0 -0
  82. package/docs/src/index.css +0 -3
  83. package/docs/src/main.tsx +0 -12
  84. package/docs/src/test/setup.ts +0 -1
  85. package/docs/tsconfig.node.json +0 -15
  86. package/examples/README.md +0 -302
  87. package/examples/aggregator-example.ts +0 -329
  88. package/examples/basic-cache-example.ts +0 -270
  89. package/examples/cache-map-example.ts +0 -265
  90. package/vitest.config.ts +0 -44
@@ -1,265 +0,0 @@
1
- /**
2
- * Cache Map Example
3
- *
4
- * This example demonstrates the lower-level CacheMap functionality of fjell-cache.
5
- * CacheMap provides direct key-value storage and retrieval with support for
6
- * complex fjell keys and efficient item management.
7
- *
8
- * Shows how to:
9
- * - Create and manage CacheMap instances directly
10
- * - Store and retrieve items with complex keys
11
- * - Use basic operations and key management
12
- * - Handle key normalization and comparison
13
- * - Manage cache lifecycle and cleanup
14
- */
15
-
16
- import { CacheMap } from '../src/CacheMap';
17
- import { ComKey, Item, PriKey } from '@fjell/core';
18
-
19
- // Define test data models
20
- interface Document extends Item<'document'> {
21
- id: string;
22
- title: string;
23
- content: string;
24
- author: string;
25
- tags: string[];
26
- createdAt: Date;
27
- }
28
-
29
- interface Comment extends Item<'comment', 'document'> {
30
- id: string;
31
- documentId: string;
32
- content: string;
33
- author: string;
34
- createdAt: Date;
35
- }
36
-
37
- // Helper to create test data
38
- const createDocument = (id: string, title: string, content: string, author: string, tags: string[]): Document => ({
39
- id, title, content, author, tags, createdAt: new Date(),
40
- key: { kt: 'document', pk: id },
41
- events: { created: { at: new Date() }, updated: { at: new Date() }, deleted: { at: null } }
42
- });
43
-
44
- const createComment = (id: string, documentId: string, content: string, author: string): Comment => ({
45
- id, documentId, content, author, createdAt: new Date(),
46
- key: { kt: 'comment', pk: id, loc: [{ kt: 'document', lk: documentId }] },
47
- events: { created: { at: new Date() }, updated: { at: new Date() }, deleted: { at: null } }
48
- });
49
-
50
- export const runCacheMapExample = async (): Promise<void> => {
51
- console.log('\n๐Ÿš€ Fjell-Cache CacheMap Example');
52
- console.log('==============================\n');
53
-
54
- console.log('This example demonstrates direct CacheMap operations for low-level cache management.\n');
55
-
56
- // Step 1: Create CacheMap instances
57
- console.log('Step 1: Creating CacheMap instances');
58
- console.log('-----------------------------------');
59
-
60
- // Create CacheMaps for different item types
61
- const documentCacheMap = new CacheMap<Document, 'document'>(['document']);
62
- const commentCacheMap = new CacheMap<Comment, 'comment', 'document'>(['comment', 'document']);
63
-
64
- console.log('โœ… Created CacheMap instances for documents and comments');
65
- console.log(` ๐Ÿ“„ Document CacheMap: supports primary keys only`);
66
- console.log(` ๐Ÿ’ฌ Comment CacheMap: supports contained items with location hierarchy\n`);
67
-
68
- // Step 2: Create test data
69
- console.log('Step 2: Creating test data');
70
- console.log('-------------------------');
71
-
72
- const doc1 = createDocument('doc-1', 'Getting Started with Fjell', 'This is a comprehensive guide...', 'Alice', ['guide', 'tutorial']);
73
- const doc2 = createDocument('doc-2', 'Advanced Caching Patterns', 'Learn advanced techniques...', 'Bob', ['advanced', 'caching']);
74
- const doc3 = createDocument('doc-3', 'Performance Optimization', 'Tips for better performance...', 'Charlie', ['performance', 'optimization']);
75
-
76
- const comment1 = createComment('comment-1', doc1.id, 'Great tutorial! Very helpful.', 'David');
77
- const comment2 = createComment('comment-2', doc1.id, 'Thanks for sharing this.', 'Eve');
78
- const comment3 = createComment('comment-3', doc2.id, 'Excellent advanced techniques.', 'Frank');
79
-
80
- console.log('โœ… Created test documents and comments\n');
81
-
82
- // Step 3: Basic CacheMap operations
83
- console.log('Step 3: Basic CacheMap operations');
84
- console.log('---------------------------------');
85
-
86
- // Set items in cache
87
- documentCacheMap.set(doc1.key, doc1);
88
- documentCacheMap.set(doc2.key, doc2);
89
- documentCacheMap.set(doc3.key, doc3);
90
-
91
- commentCacheMap.set(comment1.key, comment1);
92
- commentCacheMap.set(comment2.key, comment2);
93
- commentCacheMap.set(comment3.key, comment3);
94
-
95
- console.log('๐Ÿ“ฅ Stored all items in CacheMaps');
96
- console.log(` ๐Ÿ“„ Documents cached: ${documentCacheMap.values().length}`);
97
- console.log(` ๐Ÿ’ฌ Comments cached: ${commentCacheMap.values().length}`);
98
-
99
- // Get individual items
100
- const retrievedDoc1 = documentCacheMap.get(doc1.key);
101
- const retrievedComment1 = commentCacheMap.get(comment1.key);
102
-
103
- console.log(`\n๐Ÿ” Retrieved items by key:`);
104
- console.log(` ๐Ÿ“„ Document: "${retrievedDoc1?.title}" by ${retrievedDoc1?.author}`);
105
- console.log(` ๐Ÿ’ฌ Comment: "${retrievedComment1?.content}" by ${retrievedComment1?.author}`);
106
-
107
- // Step 4: Key operations and checking
108
- console.log('\n\nStep 4: Key operations and checking');
109
- console.log('----------------------------------');
110
-
111
- // Check if keys exist
112
- const hasDoc1 = documentCacheMap.includesKey(doc1.key);
113
- const hasDoc4 = documentCacheMap.includesKey({ kt: 'document', pk: 'doc-4' });
114
-
115
- console.log(`๐Ÿ”‘ Key existence checks:`);
116
- console.log(` ๐Ÿ“„ Document 1 exists: ${hasDoc1}`);
117
- console.log(` ๐Ÿ“„ Document 4 exists: ${hasDoc4}`);
118
-
119
- // Get all keys
120
- const allDocKeys = documentCacheMap.keys();
121
- const allCommentKeys = commentCacheMap.keys();
122
-
123
- console.log(`\n๐Ÿ—‚๏ธ All cached keys:`);
124
- console.log(` ๐Ÿ“„ Document keys: ${allDocKeys.length} items`);
125
- allDocKeys.forEach(key => console.log(` - ${(key as PriKey<'document'>).pk}`));
126
-
127
- console.log(` ๐Ÿ’ฌ Comment keys: ${allCommentKeys.length} items`);
128
- allCommentKeys.forEach(key => console.log(` - ${(key as ComKey<'comment', 'document'>).pk} in document ${(key as ComKey<'comment', 'document'>).loc?.[0]?.lk}`));
129
-
130
- // Step 5: Bulk operations
131
- console.log('\n\nStep 5: Bulk operations');
132
- console.log('----------------------');
133
-
134
- // Get all items
135
- const allDocuments = documentCacheMap.allIn([]);
136
- const allComments = commentCacheMap.allIn([]);
137
-
138
- console.log(`๐Ÿ“‹ Retrieved all items:`);
139
- console.log(` ๐Ÿ“„ Documents: ${allDocuments.length} items`);
140
- allDocuments.forEach(doc => console.log(` - "${doc.title}" (${doc.tags.join(', ')})`));
141
-
142
- console.log(` ๐Ÿ’ฌ Comments: ${allComments.length} items`);
143
- allComments.forEach(comment => console.log(` - "${comment.content}" on doc ${comment.documentId}`));
144
-
145
- // Get all values (another way to access items)
146
- const allDocumentValues = documentCacheMap.values();
147
- console.log(`\n๐Ÿ“ฆ Document values count: ${allDocumentValues.length}`);
148
-
149
- // Step 6: Location-based operations for contained items
150
- console.log('\n\nStep 6: Location-based operations');
151
- console.log('---------------------------------');
152
-
153
- // Get comments for specific document (using location filtering)
154
- const doc1Comments = commentCacheMap.allIn([{ kt: 'document' as const, lk: doc1.id }] as any);
155
-
156
- console.log(`๐Ÿ” Location-based retrieval:`);
157
- console.log(` ๐Ÿ’ฌ Comments in document "${doc1.title}": ${doc1Comments.length} found`);
158
- doc1Comments.forEach(comment => console.log(` - "${comment.content}" by ${comment.author}`));
159
-
160
- // Step 7: Update operations
161
- console.log('\n\nStep 7: Update operations');
162
- console.log('------------------------');
163
-
164
- // Update an existing document
165
- const updatedDoc1 = {
166
- ...doc1,
167
- title: 'Getting Started with Fjell - Updated',
168
- tags: [...doc1.tags, 'updated'],
169
- events: { ...doc1.events, updated: { at: new Date() } }
170
- };
171
-
172
- documentCacheMap.set(updatedDoc1.key, updatedDoc1);
173
- const retrievedUpdatedDoc = documentCacheMap.get(updatedDoc1.key);
174
-
175
- console.log(`๐Ÿ”„ Updated document:`);
176
- console.log(` ๐Ÿ“„ New title: "${retrievedUpdatedDoc?.title}"`);
177
- console.log(` ๐Ÿท๏ธ New tags: ${retrievedUpdatedDoc?.tags.join(', ')}`);
178
-
179
- // Step 8: Deletion operations
180
- console.log('\n\nStep 8: Deletion operations');
181
- console.log('--------------------------');
182
-
183
- // Delete a specific item
184
- documentCacheMap.delete(doc3.key);
185
- console.log(`๐Ÿ—‘๏ธ Deleted document: doc-3`);
186
- console.log(` ๐Ÿ“„ Documents remaining: ${documentCacheMap.values().length}`);
187
-
188
- // Try to get deleted item
189
- const deletedDocCheck = documentCacheMap.get(doc3.key);
190
- console.log(` ๐Ÿ” Deleted document still exists: ${deletedDocCheck !== null}`);
191
-
192
- // Step 9: Performance and statistics
193
- console.log('\n\nStep 9: Performance and statistics');
194
- console.log('---------------------------------');
195
-
196
- console.log(`๐Ÿ“Š CacheMap Statistics:`);
197
- console.log(` ๐Ÿ“„ Document CacheMap:`);
198
- console.log(` - Items: ${documentCacheMap.values().length}`);
199
- console.log(` - Keys: ${documentCacheMap.keys().length}`);
200
- console.log(` - Values: ${documentCacheMap.values().length}`);
201
-
202
- console.log(` ๐Ÿ’ฌ Comment CacheMap:`);
203
- console.log(` - Items: ${commentCacheMap.values().length}`);
204
- console.log(` - Keys: ${commentCacheMap.keys().length}`);
205
- console.log(` - Values: ${commentCacheMap.values().length}`);
206
-
207
- // Performance test - bulk operations
208
- const startTime = Date.now();
209
- for (let i = 0; i < 1000; i++) {
210
- const tempDoc = createDocument(`temp-${i}`, `Temp Doc ${i}`, 'Content', 'Author', ['temp']);
211
- documentCacheMap.set(tempDoc.key, tempDoc);
212
- }
213
- const insertTime = Date.now() - startTime;
214
-
215
- console.log(`\nโšก Performance test:`);
216
- console.log(` ๐Ÿ“ฅ Inserted 1000 items in ${insertTime}ms`);
217
- console.log(` ๐Ÿ“Š Total documents: ${documentCacheMap.values().length}`);
218
-
219
- // Clean up performance test data
220
- const cleanupStart = Date.now();
221
- for (let i = 0; i < 1000; i++) {
222
- documentCacheMap.delete({ kt: 'document', pk: `temp-${i}` });
223
- }
224
- const cleanupTime = Date.now() - cleanupStart;
225
-
226
- console.log(` ๐Ÿงน Cleaned up 1000 items in ${cleanupTime}ms`);
227
- console.log(` ๐Ÿ“Š Documents after cleanup: ${documentCacheMap.values().length}`);
228
-
229
- // Step 10: Clone operations
230
- console.log('\n\nStep 10: Clone operations');
231
- console.log('------------------------');
232
-
233
- // Clone the cache map
234
- const clonedDocumentCache = documentCacheMap.clone();
235
- console.log(`๐Ÿ“‹ Cloned document cache:`);
236
- console.log(` ๐Ÿ“„ Original cache: ${documentCacheMap.values().length} items`);
237
- console.log(` ๐Ÿ“„ Cloned cache: ${clonedDocumentCache.values().length} items`);
238
-
239
- // Modify original to show independence
240
- const newDoc = createDocument('doc-clone-test', 'Clone Test Doc', 'Testing cloning', 'Test Author', ['test']);
241
- documentCacheMap.set(newDoc.key, newDoc);
242
-
243
- console.log(`\n๐Ÿ“Š After adding to original:`);
244
- console.log(` ๐Ÿ“„ Original cache: ${documentCacheMap.values().length} items`);
245
- console.log(` ๐Ÿ“„ Cloned cache: ${clonedDocumentCache.values().length} items`);
246
- console.log(` โœ… Clones are independent`);
247
-
248
- console.log('\n๐ŸŽ‰ CacheMap Example Complete!');
249
- console.log('=============================\n');
250
-
251
- console.log('Key concepts demonstrated:');
252
- console.log('โ€ข Direct CacheMap instantiation and management');
253
- console.log('โ€ข Primary key and composite key operations');
254
- console.log('โ€ข Bulk operations (allIn, values, keys)');
255
- console.log('โ€ข Location-based filtering for contained items');
256
- console.log('โ€ข Update and delete operations');
257
- console.log('โ€ข Performance characteristics');
258
- console.log('โ€ข Key normalization and comparison');
259
- console.log('โ€ข Cache cloning and independence\n');
260
- };
261
-
262
- // Run the example if this file is executed directly
263
- if (import.meta.url === `file://${process.argv[1]}`) {
264
- runCacheMapExample().catch(console.error);
265
- }
package/vitest.config.ts DELETED
@@ -1,44 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
- import * as path from 'path'
3
-
4
- export default defineConfig({
5
- test: {
6
- globals: true,
7
- environment: 'node',
8
- include: ['tests/**/*.test.ts'],
9
- coverage: {
10
- provider: 'v8',
11
- reporter: ['text', 'json', 'html'],
12
- exclude: [
13
- 'node_modules/',
14
- 'tests/',
15
- 'src/index.ts',
16
- 'eslint.config.mjs',
17
- 'vite.config.ts',
18
- 'vitest.config.ts',
19
- 'dist',
20
- ],
21
- thresholds: {
22
- lines: 89,
23
- functions: 85,
24
- branches: 92,
25
- statements: 89,
26
- },
27
- },
28
- setupFiles: ['./tests/setup.ts'],
29
- deps: {
30
- inline: [/@fjell/],
31
- },
32
- testTimeout: 10000,
33
- hookTimeout: 10000,
34
- teardownTimeout: 10000,
35
- },
36
- resolve: {
37
- alias: {
38
- '@': path.resolve(__dirname, './src'),
39
- },
40
- },
41
- build: {
42
- sourcemap: true,
43
- },
44
- })