@flight-framework/core 0.2.2 → 0.2.3
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/actions/index.d.ts +636 -1
- package/dist/actions/index.js +1 -1
- package/dist/cache/index.d.ts +119 -4
- package/dist/cache/index.js +1 -1
- package/dist/chunk-3QP3E7HS.js +667 -0
- package/dist/chunk-3QP3E7HS.js.map +1 -0
- package/dist/{chunk-3TPAA52K.js → chunk-IXMD5QH2.js} +5 -2
- package/dist/chunk-IXMD5QH2.js.map +1 -0
- package/dist/chunk-R7SQAREQ.js +310 -0
- package/dist/chunk-R7SQAREQ.js.map +1 -0
- package/dist/{chunk-6LYV4VQX.js → chunk-VOBQDQKX.js} +3 -3
- package/dist/{chunk-6LYV4VQX.js.map → chunk-VOBQDQKX.js.map} +1 -1
- package/dist/config/index.d.ts +27 -3
- package/dist/config/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/server/index.js +2 -2
- package/package.json +14 -2
- package/dist/chunk-3AIQVGTM.js +0 -120
- package/dist/chunk-3AIQVGTM.js.map +0 -1
- package/dist/chunk-3TPAA52K.js.map +0 -1
- package/dist/chunk-JIW55ZVD.js +0 -145
- package/dist/chunk-JIW55ZVD.js.map +0 -1
package/dist/cache/index.d.ts
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
* Flight Cache - Agnostic caching primitives
|
|
3
3
|
*
|
|
4
4
|
* Flight provides the interface, you choose the implementation.
|
|
5
|
-
* Use in-memory, Redis, Cloudflare KV, or anything else.
|
|
5
|
+
* Use in-memory, Redis, Cloudflare KV, Upstash, or anything else.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createCache } from '@flight-framework/core';
|
|
10
|
+
* import { redis } from '@flight-framework/cache-redis';
|
|
11
|
+
*
|
|
12
|
+
* const cache = createCache({
|
|
13
|
+
* adapter: redis({ url: process.env.REDIS_URL }),
|
|
14
|
+
* defaultTTL: 3600,
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* await cache.set('user:1', userData, { tags: ['users'] });
|
|
18
|
+
* await cache.invalidateTag('users');
|
|
19
|
+
* ```
|
|
6
20
|
*/
|
|
7
21
|
interface CacheOptions {
|
|
8
22
|
/** Time-to-live in seconds */
|
|
@@ -37,40 +51,141 @@ interface Cache {
|
|
|
37
51
|
clear(): Promise<void>;
|
|
38
52
|
/** Invalidate entries by tag */
|
|
39
53
|
invalidateTag(tag: string): Promise<void>;
|
|
54
|
+
/** Invalidate entries by multiple tags */
|
|
55
|
+
invalidateTags(tags: string[]): Promise<void>;
|
|
40
56
|
/** Get or set with a factory function */
|
|
41
57
|
getOrSet<T>(key: string, factory: () => Promise<T>, options?: CacheOptions): Promise<T>;
|
|
58
|
+
/** Get multiple values at once */
|
|
59
|
+
getMany<T>(keys: string[]): Promise<Map<string, T | undefined>>;
|
|
60
|
+
/** Set multiple values at once */
|
|
61
|
+
setMany<T>(entries: Map<string, T>, options?: CacheOptions): Promise<void>;
|
|
62
|
+
/** Get cache statistics (if tracking enabled) */
|
|
63
|
+
getStats?(): CacheStats | undefined;
|
|
64
|
+
}
|
|
65
|
+
interface CacheStats {
|
|
66
|
+
hits: number;
|
|
67
|
+
misses: number;
|
|
68
|
+
sets: number;
|
|
69
|
+
deletes: number;
|
|
42
70
|
}
|
|
43
71
|
/** Adapter interface for external cache providers */
|
|
44
72
|
interface CacheAdapter {
|
|
45
|
-
name
|
|
73
|
+
/** Adapter name for identification */
|
|
74
|
+
readonly name: string;
|
|
75
|
+
/** Get an entry from cache */
|
|
46
76
|
get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
77
|
+
/** Set an entry in cache */
|
|
47
78
|
set<T>(key: string, entry: CacheEntry<T>): Promise<void>;
|
|
79
|
+
/** Delete an entry from cache */
|
|
48
80
|
delete(key: string): Promise<boolean>;
|
|
81
|
+
/** Check if key exists */
|
|
49
82
|
has(key: string): Promise<boolean>;
|
|
83
|
+
/** Clear all entries */
|
|
50
84
|
clear(): Promise<void>;
|
|
85
|
+
/** Get keys matching pattern (optional) */
|
|
51
86
|
keys?(pattern?: string): Promise<string[]>;
|
|
87
|
+
/** Get multiple entries at once (optional, for performance) */
|
|
88
|
+
getMany?<T>(keys: string[]): Promise<Map<string, CacheEntry<T> | undefined>>;
|
|
89
|
+
/** Set multiple entries at once (optional, for performance) */
|
|
90
|
+
setMany?<T>(entries: Map<string, CacheEntry<T>>): Promise<void>;
|
|
91
|
+
/** Whether this adapter supports distributed tags natively */
|
|
92
|
+
readonly supportsDistributedTags?: boolean;
|
|
93
|
+
/** Add a key to a tag set (for distributed tag management) */
|
|
94
|
+
addToTag?(tag: string, key: string): Promise<void>;
|
|
95
|
+
/** Get all keys associated with a tag */
|
|
96
|
+
getTagMembers?(tag: string): Promise<string[]>;
|
|
97
|
+
/** Delete a tag and return its members */
|
|
98
|
+
deleteTag?(tag: string): Promise<string[]>;
|
|
99
|
+
/** Close connection (for cleanup) */
|
|
100
|
+
close?(): Promise<void>;
|
|
101
|
+
/** Check if adapter is healthy */
|
|
102
|
+
ping?(): Promise<boolean>;
|
|
103
|
+
}
|
|
104
|
+
interface Serializer {
|
|
105
|
+
serialize(value: unknown): string;
|
|
106
|
+
deserialize<T>(data: string): T;
|
|
52
107
|
}
|
|
108
|
+
/** Default JSON serializer */
|
|
109
|
+
declare const jsonSerializer: Serializer;
|
|
110
|
+
interface MemoryCacheAdapterOptions {
|
|
111
|
+
/** Maximum number of entries (0 = unlimited) */
|
|
112
|
+
maxSize?: number;
|
|
113
|
+
/** Cleanup interval in ms (default: 60000) */
|
|
114
|
+
cleanupInterval?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create in-memory cache adapter
|
|
118
|
+
*/
|
|
119
|
+
declare function memory(options?: MemoryCacheAdapterOptions): CacheAdapter;
|
|
53
120
|
interface CreateCacheOptions {
|
|
54
121
|
/** Custom cache adapter (defaults to in-memory) */
|
|
55
122
|
adapter?: CacheAdapter;
|
|
56
|
-
/** Default TTL for all entries */
|
|
123
|
+
/** Default TTL for all entries (seconds) */
|
|
57
124
|
defaultTTL?: number;
|
|
58
125
|
/** Key prefix for namespacing */
|
|
59
126
|
prefix?: string;
|
|
127
|
+
/** Custom serializer (for external adapters) */
|
|
128
|
+
serializer?: Serializer;
|
|
129
|
+
/** Track cache statistics */
|
|
130
|
+
trackStats?: boolean;
|
|
60
131
|
}
|
|
61
132
|
/**
|
|
62
133
|
* Create a new cache instance
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Simple in-memory cache
|
|
138
|
+
* const cache = createCache();
|
|
139
|
+
*
|
|
140
|
+
* // With Redis adapter
|
|
141
|
+
* import { redis } from '@flight-framework/cache-redis';
|
|
142
|
+
* const cache = createCache({
|
|
143
|
+
* adapter: redis({ url: 'redis://localhost:6379' }),
|
|
144
|
+
* defaultTTL: 3600,
|
|
145
|
+
* prefix: 'myapp',
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
63
148
|
*/
|
|
64
149
|
declare function createCache(options?: CreateCacheOptions): Cache;
|
|
65
150
|
/**
|
|
66
151
|
* Create a cache key from multiple parts
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* cacheKey('user', userId, 'profile'); // "user:123:profile"
|
|
156
|
+
* ```
|
|
67
157
|
*/
|
|
68
158
|
declare function cacheKey(...parts: (string | number | boolean | undefined)[]): string;
|
|
69
159
|
/**
|
|
70
160
|
* Wrap a function with caching
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const getCachedUser = cached(cache, getUser, {
|
|
165
|
+
* ttl: 300,
|
|
166
|
+
* keyFn: (userId) => `user:${userId}`,
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* const user = await getCachedUser(123);
|
|
170
|
+
* ```
|
|
71
171
|
*/
|
|
72
172
|
declare function cached<T extends (...args: unknown[]) => Promise<unknown>>(cache: Cache, fn: T, options?: CacheOptions & {
|
|
73
173
|
keyFn?: (...args: Parameters<T>) => string;
|
|
74
174
|
}): T;
|
|
175
|
+
/**
|
|
176
|
+
* Create a deduplication wrapper to prevent duplicate concurrent requests
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const dedupedFetch = dedupe(fetchUser);
|
|
181
|
+
*
|
|
182
|
+
* // These will share the same request
|
|
183
|
+
* const [user1, user2] = await Promise.all([
|
|
184
|
+
* dedupedFetch(123),
|
|
185
|
+
* dedupedFetch(123),
|
|
186
|
+
* ]);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function dedupe<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, keyFn?: (...args: Parameters<T>) => string): T;
|
|
75
190
|
|
|
76
|
-
export { type Cache, type CacheAdapter, type CacheEntry, type CacheOptions, type CreateCacheOptions, cacheKey, cached, createCache };
|
|
191
|
+
export { type Cache, type CacheAdapter, type CacheEntry, type CacheOptions, type CacheStats, type CreateCacheOptions, type MemoryCacheAdapterOptions, type Serializer, cacheKey, cached, createCache, dedupe, jsonSerializer, memory };
|
package/dist/cache/index.js
CHANGED