@holo-js/cache 0.1.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.
@@ -0,0 +1,199 @@
1
+ import { CacheFacade, CacheRepository, CacheFlexibleTtlInput, CacheFallback, CacheValueResolver, CacheDriverContract, CacheOptionalPackageError, CacheDependencyIndex, CacheQueryBridge, CacheKeyInput, CacheDependencyDescriptor, CacheRuntimeBindings, CacheKey, CacheTtlInput, CacheLockContract, defineCacheKey, normalizeCacheTtl, serializeCacheValue, deserializeCacheValue } from './contracts.js';
2
+ export { CacheConfigError, CacheDriverGetResult, CacheDriverPutInput, CacheDriverResolutionError, CacheError, CacheErrorCode, CacheFallbackResolver, CacheInvalidNumericMutationError, CacheInvalidTtlError, CacheLockAcquisitionError, CacheQueryIntegrationError, CacheRuntimeNotConfiguredError, CacheSerializationError, NormalizedCacheTtl, cacheContractsInternals, isCacheKey, resolveCacheKey } from './contracts.js';
3
+ import { HoloDatabaseConfig, NormalizedHoloDatabaseConfig, HoloDatabaseConnectionConfig, HoloRedisConfig, NormalizedHoloRedisConfig, NormalizedHoloRedisConnectionConfig, NormalizedHoloCacheConfig, HoloCacheConfig } from '@holo-js/config';
4
+ export { CacheDatabaseDriverConfig, CacheDriver, CacheDriverConfig, CacheFileDriverConfig, CacheMemoryDriverConfig, CacheRedisDriverConfig, HoloCacheConfig, NormalizedCacheDatabaseDriverConfig, NormalizedCacheDriverConfig, NormalizedCacheFileDriverConfig, NormalizedCacheMemoryDriverConfig, NormalizedCacheRedisDriverConfig, NormalizedHoloCacheConfig, defineCacheConfig } from '@holo-js/config';
5
+
6
+ type FlexibleEnvelope<TValue> = {
7
+ readonly __holo_cache_flexible: true;
8
+ readonly value: TValue;
9
+ readonly freshUntil: number;
10
+ readonly staleUntil: number;
11
+ };
12
+ type NormalizedFlexibleTtl = {
13
+ readonly freshSeconds: number;
14
+ readonly staleSeconds: number;
15
+ };
16
+ declare function resolveFallback<TValue>(fallback: CacheFallback<TValue>): Promise<TValue> | TValue;
17
+ declare function resolveValue<TValue>(callback: CacheValueResolver<TValue>): Promise<Awaited<TValue>>;
18
+ declare function resolveDriverKey(driverName?: string): string;
19
+ declare function normalizeFlexibleTtl(ttl: CacheFlexibleTtlInput): NormalizedFlexibleTtl;
20
+ declare function isFlexibleEnvelope<TValue>(value: unknown): value is FlexibleEnvelope<TValue>;
21
+ declare function getOrCreateRepository(driverName?: string): CacheRepository;
22
+ declare const cacheFacade: CacheFacade;
23
+ declare const cacheFacadeInternals: {
24
+ createRefreshLockName(key: string): string;
25
+ getOrCreateRepository: typeof getOrCreateRepository;
26
+ isFlexibleEnvelope: typeof isFlexibleEnvelope;
27
+ normalizeFlexibleTtl: typeof normalizeFlexibleTtl;
28
+ resolveDriverKey: typeof resolveDriverKey;
29
+ resolveFallback: typeof resolveFallback;
30
+ resolveValue: typeof resolveValue;
31
+ };
32
+
33
+ type DatabaseCacheDriverOptions = {
34
+ readonly name: string;
35
+ readonly connectionName: string;
36
+ readonly table: string;
37
+ readonly lockTable: string;
38
+ readonly prefix?: string;
39
+ readonly connection: HoloDatabaseConnectionConfig | string;
40
+ };
41
+ type DatabaseCacheDriverModule = {
42
+ createDatabaseCacheDriver(options: DatabaseCacheDriverOptions): CacheDriverContract;
43
+ };
44
+ type DatabaseDriverModuleLoader = () => Promise<DatabaseCacheDriverModule>;
45
+ declare function isNormalizedDatabaseConfig(config: HoloDatabaseConfig | NormalizedHoloDatabaseConfig): config is NormalizedHoloDatabaseConfig;
46
+ declare function normalizeRuntimeDatabaseConfig(config: HoloDatabaseConfig | NormalizedHoloDatabaseConfig | undefined): NormalizedHoloDatabaseConfig | undefined;
47
+ declare function resolveSharedDatabaseConnection(databaseConfig: NormalizedHoloDatabaseConfig | undefined, connectionName: string): HoloDatabaseConnectionConfig | string;
48
+ declare function isModuleNotFoundError$1(error: unknown, expectedSpecifier?: string): boolean;
49
+ declare function normalizeDatabaseModuleLoadError(error: unknown, expectedSpecifier?: string): CacheOptionalPackageError | unknown;
50
+ declare function loadDatabaseDriverModule(): Promise<DatabaseCacheDriverModule>;
51
+ declare function setDatabaseDriverModuleLoader(loader: DatabaseDriverModuleLoader): void;
52
+ declare function resetDatabaseDriverModuleLoader(): void;
53
+ declare const cacheDbInternals: {
54
+ isModuleNotFoundError: typeof isModuleNotFoundError$1;
55
+ isNormalizedDatabaseConfig: typeof isNormalizedDatabaseConfig;
56
+ loadDatabaseDriverModule: typeof loadDatabaseDriverModule;
57
+ normalizeDatabaseModuleLoadError: typeof normalizeDatabaseModuleLoadError;
58
+ normalizeRuntimeDatabaseConfig: typeof normalizeRuntimeDatabaseConfig;
59
+ resolveSharedDatabaseConnection: typeof resolveSharedDatabaseConnection;
60
+ resetDatabaseDriverModuleLoader: typeof resetDatabaseDriverModuleLoader;
61
+ setDatabaseDriverModuleLoader: typeof setDatabaseDriverModuleLoader;
62
+ };
63
+
64
+ type FileCacheEntryEnvelope = {
65
+ key: string;
66
+ payload: string;
67
+ expiresAt?: number;
68
+ };
69
+ type FileCacheLockEnvelope = {
70
+ name: string;
71
+ owner: string;
72
+ expiresAt: number;
73
+ };
74
+ declare function hashCacheKey(key: string): string;
75
+ declare function resolveDriverRoot(path: string): string;
76
+ declare function resolveEntryFilePath(rootPath: string, key: string): string;
77
+ declare function resolveLockFilePath(rootPath: string, name: string): string;
78
+ declare function isFileCacheEntryEnvelope(value: unknown): value is FileCacheEntryEnvelope;
79
+ declare function isFileCacheLockEnvelope(value: unknown): value is FileCacheLockEnvelope;
80
+ declare const fileDriverInternals: {
81
+ hashCacheKey: typeof hashCacheKey;
82
+ isFileCacheEntryEnvelope: typeof isFileCacheEntryEnvelope;
83
+ isFileCacheLockEnvelope: typeof isFileCacheLockEnvelope;
84
+ resolveDriverRoot: typeof resolveDriverRoot;
85
+ resolveEntryFilePath: typeof resolveEntryFilePath;
86
+ resolveLockFilePath: typeof resolveLockFilePath;
87
+ };
88
+
89
+ type DependencyIndexState = {
90
+ readonly keyToDependencies: Map<string, Set<CacheDependencyDescriptor>>;
91
+ readonly dependencyToKeys: Map<CacheDependencyDescriptor, Set<string>>;
92
+ };
93
+ declare function createMemoryDependencyIndex(state?: DependencyIndexState): CacheDependencyIndex;
94
+ declare function getOrCreateDependencyIndex(): CacheDependencyIndex;
95
+ declare function resetDefaultDependencyIndex(): void;
96
+ declare function createIndexedKey(key: CacheKeyInput<unknown>, driverName?: string): string;
97
+ declare function parseIndexedKey(indexedKey: string): {
98
+ readonly driverName: string;
99
+ readonly normalizedKey: string;
100
+ };
101
+ declare function setGlobalDatabaseQueryCacheBridge(bridge?: CacheQueryBridge): void;
102
+ declare function createCacheQueryBridge(dependencyIndex?: CacheDependencyIndex): CacheQueryBridge;
103
+ declare const cacheQueryBridgeInternals: {
104
+ createCacheQueryBridge: typeof createCacheQueryBridge;
105
+ createIndexedKey: typeof createIndexedKey;
106
+ createMemoryDependencyIndex: typeof createMemoryDependencyIndex;
107
+ getOrCreateDependencyIndex: typeof getOrCreateDependencyIndex;
108
+ parseIndexedKey: typeof parseIndexedKey;
109
+ resetDefaultDependencyIndex: typeof resetDefaultDependencyIndex;
110
+ setGlobalDatabaseQueryCacheBridge: typeof setGlobalDatabaseQueryCacheBridge;
111
+ };
112
+
113
+ type RedisCacheDriverOptions = {
114
+ readonly name: string;
115
+ readonly connectionName: string;
116
+ readonly prefix: string;
117
+ readonly redis: NormalizedHoloRedisConnectionConfig;
118
+ };
119
+ type RedisCacheDriverModule = {
120
+ createRedisCacheDriver(options: RedisCacheDriverOptions): CacheDriverContract;
121
+ };
122
+ type RedisDriverModuleLoader = () => Promise<RedisCacheDriverModule>;
123
+ declare function isNormalizedRedisConfig(config: HoloRedisConfig | NormalizedHoloRedisConfig): config is NormalizedHoloRedisConfig;
124
+ declare function normalizeRuntimeRedisConfig(config: HoloRedisConfig | NormalizedHoloRedisConfig | undefined): NormalizedHoloRedisConfig | undefined;
125
+ declare function resolveSharedRedisConnection(redisConfig: NormalizedHoloRedisConfig | undefined, connectionName: string): NormalizedHoloRedisConnectionConfig;
126
+ declare function isModuleNotFoundError(error: unknown): boolean;
127
+ declare function normalizeRedisModuleLoadError(error: unknown): CacheOptionalPackageError | unknown;
128
+ declare function loadRedisDriverModule(): Promise<RedisCacheDriverModule>;
129
+ declare function setRedisDriverModuleLoader(loader: RedisDriverModuleLoader): void;
130
+ declare function resetRedisDriverModuleLoader(): void;
131
+ declare const cacheRedisInternals: {
132
+ isModuleNotFoundError: typeof isModuleNotFoundError;
133
+ isNormalizedRedisConfig: typeof isNormalizedRedisConfig;
134
+ loadRedisDriverModule: typeof loadRedisDriverModule;
135
+ normalizeRedisModuleLoadError: typeof normalizeRedisModuleLoadError;
136
+ normalizeRuntimeRedisConfig: typeof normalizeRuntimeRedisConfig;
137
+ resolveSharedRedisConnection: typeof resolveSharedRedisConnection;
138
+ resetRedisDriverModuleLoader: typeof resetRedisDriverModuleLoader;
139
+ setRedisDriverModuleLoader: typeof setRedisDriverModuleLoader;
140
+ };
141
+
142
+ type CacheRuntimeFacade = {
143
+ readonly config: NormalizedHoloCacheConfig;
144
+ readonly databaseConfig?: NormalizedHoloDatabaseConfig;
145
+ readonly redisConfig?: NormalizedHoloRedisConfig;
146
+ readonly drivers: Map<string, CacheDriverContract>;
147
+ readonly dependencyIndex?: CacheRuntimeBindings['dependencyIndex'];
148
+ readonly queryBridge?: CacheRuntimeBindings['queryBridge'];
149
+ };
150
+ type RuntimeCacheState = {
151
+ bindings?: CacheRuntimeFacade;
152
+ };
153
+ declare function isNormalizedCacheConfig(config: HoloCacheConfig | NormalizedHoloCacheConfig): config is NormalizedHoloCacheConfig;
154
+ declare function normalizeRuntimeConfig(config: HoloCacheConfig | NormalizedHoloCacheConfig | undefined): NormalizedHoloCacheConfig;
155
+ declare function getCacheRuntimeState(): RuntimeCacheState;
156
+ declare function getCacheRuntimeBindings(): CacheRuntimeFacade | undefined;
157
+ declare function getCacheRuntime(): CacheRuntimeFacade;
158
+ declare function resolveConfiguredDriver(facade: CacheRuntimeFacade, requestedName?: string): CacheDriverContract;
159
+
160
+ declare function configureCacheRuntime$1(bindings?: CacheRuntimeBindings): void;
161
+ declare const cacheRuntimeInternals: {
162
+ getCacheRuntimeState: typeof getCacheRuntimeState;
163
+ isNormalizedCacheConfig: typeof isNormalizedCacheConfig;
164
+ normalizeRuntimeConfig: typeof normalizeRuntimeConfig;
165
+ resolveConfiguredDriver: typeof resolveConfiguredDriver;
166
+ };
167
+
168
+ declare function configureCacheRuntime(...parameters: Parameters<typeof configureCacheRuntime$1>): void;
169
+ declare function resetCacheRuntime(): void;
170
+ declare const cache: Readonly<{
171
+ driver(name?: string): CacheRepository;
172
+ get<TValue>(key: CacheKey<TValue>): Promise<TValue | null>;
173
+ get<TValue>(key: CacheKeyInput<TValue>, fallback: CacheFallback<TValue>): Promise<TValue>;
174
+ get<TValue>(key: string, fallback: CacheFallback<TValue>): Promise<TValue>;
175
+ get(key: string): Promise<unknown | null>;
176
+ put<TValue>(key: CacheKeyInput<TValue>, value: TValue, ttl: CacheTtlInput): Promise<boolean>;
177
+ add<TValue>(key: CacheKeyInput<TValue>, value: TValue, ttl: CacheTtlInput): Promise<boolean>;
178
+ forever<TValue>(key: CacheKeyInput<TValue>, value: TValue): Promise<boolean>;
179
+ has(key: CacheKeyInput<unknown>): Promise<boolean>;
180
+ missing(key: CacheKeyInput<unknown>): Promise<boolean>;
181
+ forget(key: CacheKeyInput<unknown>): Promise<boolean>;
182
+ flush(): Promise<void>;
183
+ increment(key: CacheKeyInput<number>, amount?: number): Promise<number>;
184
+ decrement(key: CacheKeyInput<number>, amount?: number): Promise<number>;
185
+ remember<TValue>(key: CacheKeyInput<Awaited<TValue>>, ttl: CacheTtlInput, callback: CacheValueResolver<TValue>): Promise<Awaited<TValue>>;
186
+ rememberForever<TValue>(key: CacheKeyInput<Awaited<TValue>>, callback: CacheValueResolver<TValue>): Promise<Awaited<TValue>>;
187
+ flexible<TValue>(key: CacheKeyInput<Awaited<TValue>>, ttl: CacheFlexibleTtlInput, callback: CacheValueResolver<TValue>): Promise<Awaited<TValue>>;
188
+ lock(name: string, seconds: number): CacheLockContract;
189
+ defineCacheKey: typeof defineCacheKey;
190
+ normalizeCacheTtl: typeof normalizeCacheTtl;
191
+ serializeCacheValue: typeof serializeCacheValue;
192
+ deserializeCacheValue: typeof deserializeCacheValue;
193
+ configureCacheRuntime: typeof configureCacheRuntime;
194
+ getCacheRuntime: typeof getCacheRuntime;
195
+ getCacheRuntimeBindings: typeof getCacheRuntimeBindings;
196
+ resetCacheRuntime: typeof resetCacheRuntime;
197
+ }>;
198
+
199
+ export { CacheDependencyDescriptor, CacheDependencyIndex, CacheDriverContract, CacheFacade, CacheFallback, CacheFlexibleTtlInput, CacheKey, CacheKeyInput, CacheLockContract, CacheOptionalPackageError, CacheQueryBridge, CacheRepository, CacheRuntimeBindings, CacheTtlInput, CacheValueResolver, cacheDbInternals, cacheFacade, cacheFacadeInternals, cacheQueryBridgeInternals, cacheRedisInternals, cacheRuntimeInternals, configureCacheRuntime, cache as default, defineCacheKey, deserializeCacheValue, fileDriverInternals, getCacheRuntime, getCacheRuntimeBindings, normalizeCacheTtl, resetCacheRuntime, serializeCacheValue };