@fjell/cache 4.7.34 → 4.7.36
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/package.json +7 -7
- package/CACHE_EVENTS.md +0 -306
- package/CACHE_IMPLEMENTATIONS.md +0 -315
- package/CONFIGURATION_GUIDE.md +0 -209
- package/CRITICAL_FIXES.md +0 -68
- package/MEMORY_LEAK_FIXES.md +0 -270
- package/MIGRATION_v3.md +0 -249
package/MIGRATION_v3.md
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
# Migration Guide: v2.x to v3.0
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Version 3.0 of `@fjell/cache` adopts the centralized Operations interface from `@fjell/core`. This provides a consistent interface across all Fjell packages, better type safety, and shared validation logic.
|
|
6
|
-
|
|
7
|
-
## Breaking Changes
|
|
8
|
-
|
|
9
|
-
### 1. Operations Interface Now Extends Core
|
|
10
|
-
|
|
11
|
-
The `Operations` interface now extends from `@fjell/core/Operations`. This change is mostly transparent to users, but provides better type checking and consistency across the Fjell ecosystem.
|
|
12
|
-
|
|
13
|
-
### 2. Updated `create` Method Signature
|
|
14
|
-
|
|
15
|
-
The `create` operation now uses the `CreateOptions` type from `@fjell/core`:
|
|
16
|
-
|
|
17
|
-
#### Before (v2.x)
|
|
18
|
-
```typescript
|
|
19
|
-
// Create with locations
|
|
20
|
-
await cache.operations.create(itemData, locations);
|
|
21
|
-
|
|
22
|
-
// Create without locations
|
|
23
|
-
await cache.operations.create(itemData, []);
|
|
24
|
-
await cache.operations.create(itemData);
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
#### After (v3.0)
|
|
28
|
-
```typescript
|
|
29
|
-
// Create with locations
|
|
30
|
-
await cache.operations.create(itemData, { locations });
|
|
31
|
-
|
|
32
|
-
// Create without locations (unchanged)
|
|
33
|
-
await cache.operations.create(itemData);
|
|
34
|
-
|
|
35
|
-
// Create with specific key (new feature)
|
|
36
|
-
await cache.operations.create(itemData, { key: { kt: 'user', pk: 'user-123' } });
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### 3. New `upsert` Method
|
|
40
|
-
|
|
41
|
-
A new `upsert` method has been added to the Operations interface:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
// Update if exists, create if doesn't
|
|
45
|
-
const item = await cache.operations.upsert(
|
|
46
|
-
key,
|
|
47
|
-
itemData,
|
|
48
|
-
locations // Optional, used only for creation
|
|
49
|
-
);
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Migration Steps
|
|
53
|
-
|
|
54
|
-
### Step 1: Update Dependencies
|
|
55
|
-
|
|
56
|
-
Update to the latest versions:
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
npm install @fjell/core@latest @fjell/cache@latest
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Step 2: Update `create` Calls
|
|
63
|
-
|
|
64
|
-
Find all calls to `cache.operations.create` with a locations parameter and wrap the locations in an object:
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
// Search for patterns like:
|
|
68
|
-
cache.operations.create(item, locations)
|
|
69
|
-
cache.operations.create(item, loc)
|
|
70
|
-
cache.operations.create(itemData, [{kt: 'parent', lk: '...'}])
|
|
71
|
-
|
|
72
|
-
// Replace with:
|
|
73
|
-
cache.operations.create(item, { locations })
|
|
74
|
-
cache.operations.create(item, { locations: loc })
|
|
75
|
-
cache.operations.create(itemData, { locations: [{kt: 'parent', lk: '...'}] })
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Step 3: Optional - Use New `upsert` Method
|
|
79
|
-
|
|
80
|
-
If you have code that checks for existence before creating or updating:
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
// Before (v2.x)
|
|
84
|
-
const existing = await cache.operations.get(key);
|
|
85
|
-
if (existing) {
|
|
86
|
-
await cache.operations.update(key, updates);
|
|
87
|
-
} else {
|
|
88
|
-
await cache.operations.create(data, locations);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// After (v3.0) - simpler!
|
|
92
|
-
await cache.operations.upsert(key, data, locations);
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## What Stays The Same
|
|
96
|
-
|
|
97
|
-
- All other cache operations work identically (`get`, `all`, `one`, `update`, `remove`, `find`, `findOne`, `action`, `allAction`, `facet`, `allFacet`)
|
|
98
|
-
- Cache-specific methods unchanged (`retrieve`, `set`, `reset`)
|
|
99
|
-
- Cache events unchanged
|
|
100
|
-
- TTL/eviction unchanged
|
|
101
|
-
- Cache statistics unchanged
|
|
102
|
-
- All cache implementations work the same way
|
|
103
|
-
- Cache configuration options unchanged
|
|
104
|
-
|
|
105
|
-
## Type Imports
|
|
106
|
-
|
|
107
|
-
You can now import core types from either package:
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
// From core (recommended)
|
|
111
|
-
import { OperationParams, AffectedKeys } from '@fjell/core';
|
|
112
|
-
|
|
113
|
-
// From cache (re-exported for convenience)
|
|
114
|
-
import { OperationParams, AffectedKeys } from '@fjell/cache';
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Benefits
|
|
118
|
-
|
|
119
|
-
### Smaller Bundle Size
|
|
120
|
-
Shared types between packages reduce overall bundle size.
|
|
121
|
-
|
|
122
|
-
### Better Type Safety
|
|
123
|
-
Consistent types across packages provide better TypeScript support and catch more errors at compile time.
|
|
124
|
-
|
|
125
|
-
### Consistent Interface
|
|
126
|
-
The same Operations interface is used across `@fjell/cache`, `@fjell/lib`, `@fjell/providers`, and other packages.
|
|
127
|
-
|
|
128
|
-
### Enhanced Functionality
|
|
129
|
-
New `upsert` method simplifies common patterns.
|
|
130
|
-
|
|
131
|
-
## Examples
|
|
132
|
-
|
|
133
|
-
### Basic Migration Example
|
|
134
|
-
|
|
135
|
-
```typescript
|
|
136
|
-
import { createCache } from '@fjell/cache';
|
|
137
|
-
import { createCoordinate, createRegistry } from '@fjell/registry';
|
|
138
|
-
|
|
139
|
-
// Setup (unchanged)
|
|
140
|
-
const registry = createRegistry();
|
|
141
|
-
const cache = await createCache(api, createCoordinate('user'), registry);
|
|
142
|
-
|
|
143
|
-
// Operations (mostly unchanged)
|
|
144
|
-
await cache.operations.all(); // ✓ No change
|
|
145
|
-
await cache.operations.get(key); // ✓ No change
|
|
146
|
-
await cache.operations.update(key, data); // ✓ No change
|
|
147
|
-
|
|
148
|
-
// Create operation (requires update)
|
|
149
|
-
await cache.operations.create(data, locations); // ✗ v2.x
|
|
150
|
-
await cache.operations.create(data, { locations }); // ✓ v3.0
|
|
151
|
-
|
|
152
|
-
// New upsert method
|
|
153
|
-
await cache.operations.upsert(key, data); // ✓ New in v3.0
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Contained Items Migration
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
// Before (v2.x)
|
|
160
|
-
const commentData = { text: 'Great post!' };
|
|
161
|
-
const locations = [{ kt: 'post', lk: 'post-123' }];
|
|
162
|
-
await commentCache.operations.create(commentData, locations);
|
|
163
|
-
|
|
164
|
-
// After (v3.0)
|
|
165
|
-
const commentData = { text: 'Great post!' };
|
|
166
|
-
const locations = [{ kt: 'post', lk: 'post-123' }];
|
|
167
|
-
await commentCache.operations.create(commentData, { locations });
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Upsert Pattern
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
// Before (v2.x) - manual check
|
|
174
|
-
async function saveUser(key, userData) {
|
|
175
|
-
const existing = await cache.operations.get(key);
|
|
176
|
-
if (existing) {
|
|
177
|
-
return await cache.operations.update(key, userData);
|
|
178
|
-
} else {
|
|
179
|
-
return await cache.operations.create(userData, []);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// After (v3.0) - built-in upsert
|
|
184
|
-
async function saveUser(key, userData) {
|
|
185
|
-
return await cache.operations.upsert(key, userData);
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Troubleshooting
|
|
190
|
-
|
|
191
|
-
### TypeScript Errors
|
|
192
|
-
|
|
193
|
-
If you see TypeScript errors after upgrading:
|
|
194
|
-
|
|
195
|
-
1. **"Argument of type 'LocKeyArray' is not assignable to parameter"**
|
|
196
|
-
- Wrap the locations array in `{ locations: ... }`
|
|
197
|
-
|
|
198
|
-
2. **"Type X is not assignable to type CreateOptions"**
|
|
199
|
-
- Update create calls to use the object syntax
|
|
200
|
-
|
|
201
|
-
3. **"Property 'upsert' does not exist"**
|
|
202
|
-
- Ensure you've updated `@fjell/core` and `@fjell/cache` to the latest versions
|
|
203
|
-
|
|
204
|
-
### Runtime Issues
|
|
205
|
-
|
|
206
|
-
If the cache still works but you see warnings:
|
|
207
|
-
|
|
208
|
-
- Check that all `create` calls are using the new signature
|
|
209
|
-
- Verify that dependency versions are compatible
|
|
210
|
-
|
|
211
|
-
## Testing Your Migration
|
|
212
|
-
|
|
213
|
-
After migration, verify:
|
|
214
|
-
|
|
215
|
-
1. All create operations work correctly
|
|
216
|
-
2. No TypeScript compilation errors
|
|
217
|
-
3. Existing tests pass
|
|
218
|
-
4. Cache operations function as expected
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
// Test create with locations
|
|
222
|
-
const item = await cache.operations.create(data, { locations: [loc1] });
|
|
223
|
-
expect(item).toBeDefined();
|
|
224
|
-
|
|
225
|
-
// Test upsert
|
|
226
|
-
const upserted = await cache.operations.upsert(key, updates);
|
|
227
|
-
expect(upserted).toBeDefined();
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Getting Help
|
|
231
|
-
|
|
232
|
-
If you encounter issues during migration:
|
|
233
|
-
|
|
234
|
-
1. Check this guide for common patterns
|
|
235
|
-
2. Review the [PHASE_3_CACHE_MIGRATION.md](../PHASE_3_CACHE_MIGRATION.md) for implementation details
|
|
236
|
-
3. Open an issue on GitHub with your specific use case
|
|
237
|
-
|
|
238
|
-
## Summary
|
|
239
|
-
|
|
240
|
-
The migration from v2.x to v3.0 requires minimal changes:
|
|
241
|
-
|
|
242
|
-
- ✅ Update `create(item, locations)` to `create(item, { locations })`
|
|
243
|
-
- ✅ Optionally use new `upsert` method for update-or-create patterns
|
|
244
|
-
- ✅ All other operations remain unchanged
|
|
245
|
-
- ✅ Cache behavior and performance unchanged
|
|
246
|
-
- ✅ Better type safety and consistency across packages
|
|
247
|
-
|
|
248
|
-
The migration should take less than an hour for most codebases, with the majority of time spent finding and updating `create` calls.
|
|
249
|
-
|