@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.
- package/dist/Aggregator.d.ts +3 -3
- package/dist/Cache.d.ts +5 -5
- package/dist/CacheMap.d.ts +1 -1
- package/dist/Instance.d.ts +4 -4
- package/dist/InstanceFactory.d.ts +3 -3
- package/dist/Operations.d.ts +4 -4
- package/dist/index.js +715 -0
- package/dist/index.js.map +7 -0
- package/dist/logger.d.ts +1 -1
- package/dist/ops/action.d.ts +3 -3
- package/dist/ops/all.d.ts +3 -3
- package/dist/ops/allAction.d.ts +3 -3
- package/dist/ops/allFacet.d.ts +3 -3
- package/dist/ops/create.d.ts +3 -3
- package/dist/ops/facet.d.ts +3 -3
- package/dist/ops/find.d.ts +3 -3
- package/dist/ops/findOne.d.ts +3 -3
- package/dist/ops/get.d.ts +3 -3
- package/dist/ops/one.d.ts +3 -3
- package/dist/ops/remove.d.ts +3 -3
- package/dist/ops/reset.d.ts +3 -3
- package/dist/ops/retrieve.d.ts +3 -3
- package/dist/ops/set.d.ts +2 -2
- package/dist/ops/update.d.ts +3 -3
- package/package.json +14 -18
- package/dist/Aggregator.cjs.js +0 -322
- package/dist/Aggregator.es.js +0 -317
- package/dist/Cache.cjs.js +0 -35
- package/dist/Cache.es.js +0 -30
- package/dist/CacheMap.cjs.js +0 -170
- package/dist/CacheMap.es.js +0 -166
- package/dist/Instance.cjs.js +0 -23
- package/dist/Instance.es.js +0 -18
- package/dist/InstanceFactory.cjs.js +0 -35
- package/dist/InstanceFactory.es.js +0 -31
- package/dist/Operations.cjs.js +0 -43
- package/dist/Operations.es.js +0 -39
- package/dist/Registry.cjs.js +0 -36
- package/dist/Registry.es.js +0 -31
- package/dist/index.cjs +0 -940
- package/dist/index.cjs.js +0 -26
- package/dist/index.cjs.map +0 -1
- package/dist/index.es.js +0 -8
- package/dist/logger.cjs.js +0 -10
- package/dist/logger.es.js +0 -6
- package/dist/ops/action.cjs.js +0 -28
- package/dist/ops/action.es.js +0 -24
- package/dist/ops/all.cjs.js +0 -33
- package/dist/ops/all.es.js +0 -29
- package/dist/ops/allAction.cjs.js +0 -35
- package/dist/ops/allAction.es.js +0 -31
- package/dist/ops/allFacet.cjs.js +0 -22
- package/dist/ops/allFacet.es.js +0 -18
- package/dist/ops/create.cjs.js +0 -23
- package/dist/ops/create.es.js +0 -19
- package/dist/ops/facet.cjs.js +0 -21
- package/dist/ops/facet.es.js +0 -17
- package/dist/ops/find.cjs.js +0 -26
- package/dist/ops/find.es.js +0 -22
- package/dist/ops/findOne.cjs.js +0 -24
- package/dist/ops/findOne.es.js +0 -20
- package/dist/ops/get.cjs.js +0 -38
- package/dist/ops/get.es.js +0 -34
- package/dist/ops/one.cjs.js +0 -33
- package/dist/ops/one.es.js +0 -29
- package/dist/ops/remove.cjs.js +0 -30
- package/dist/ops/remove.es.js +0 -26
- package/dist/ops/reset.cjs.js +0 -15
- package/dist/ops/reset.es.js +0 -11
- package/dist/ops/retrieve.cjs.js +0 -37
- package/dist/ops/retrieve.es.js +0 -33
- package/dist/ops/set.cjs.js +0 -71
- package/dist/ops/set.es.js +0 -67
- package/dist/ops/update.cjs.js +0 -34
- package/dist/ops/update.es.js +0 -30
- package/docs/docs.config.ts +0 -75
- package/docs/index.html +0 -18
- package/docs/package.json +0 -34
- package/docs/public/README.md +0 -96
- package/docs/public/examples-README.md +0 -302
- package/docs/public/test.txt +0 -0
- package/docs/src/index.css +0 -3
- package/docs/src/main.tsx +0 -12
- package/docs/src/test/setup.ts +0 -1
- package/docs/tsconfig.node.json +0 -15
- package/examples/README.md +0 -302
- package/examples/aggregator-example.ts +0 -329
- package/examples/basic-cache-example.ts +0 -270
- package/examples/cache-map-example.ts +0 -265
- 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
|
-
})
|