@gl-life/gl-life-database 1.0.0
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/API.md +1486 -0
- package/LICENSE +190 -0
- package/README.md +480 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/invalidation.d.ts +156 -0
- package/dist/cache/invalidation.d.ts.map +1 -0
- package/dist/cache/kv-cache.d.ts +79 -0
- package/dist/cache/kv-cache.d.ts.map +1 -0
- package/dist/cache/memory-cache.d.ts +68 -0
- package/dist/cache/memory-cache.d.ts.map +1 -0
- package/dist/cloudforge/d1-adapter.d.ts +67 -0
- package/dist/cloudforge/d1-adapter.d.ts.map +1 -0
- package/dist/cloudforge/do-storage.d.ts +51 -0
- package/dist/cloudforge/do-storage.d.ts.map +1 -0
- package/dist/cloudforge/index.d.ts +4 -0
- package/dist/cloudforge/index.d.ts.map +1 -0
- package/dist/cloudforge/r2-backup.d.ts +38 -0
- package/dist/cloudforge/r2-backup.d.ts.map +1 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/manager.d.ts +54 -0
- package/dist/connection/manager.d.ts.map +1 -0
- package/dist/index.cjs +4762 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4701 -0
- package/dist/index.js.map +1 -0
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/loader.d.ts +88 -0
- package/dist/migration/loader.d.ts.map +1 -0
- package/dist/migration/runner.d.ts +91 -0
- package/dist/migration/runner.d.ts.map +1 -0
- package/dist/migration/seeder.d.ts +95 -0
- package/dist/migration/seeder.d.ts.map +1 -0
- package/dist/query/builder.d.ts +47 -0
- package/dist/query/builder.d.ts.map +1 -0
- package/dist/query/index.d.ts +3 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/raw.d.ts +92 -0
- package/dist/query/raw.d.ts.map +1 -0
- package/dist/tenant/context.d.ts +52 -0
- package/dist/tenant/context.d.ts.map +1 -0
- package/dist/tenant/index.d.ts +4 -0
- package/dist/tenant/index.d.ts.map +1 -0
- package/dist/tenant/query-wrapper.d.ts +96 -0
- package/dist/tenant/query-wrapper.d.ts.map +1 -0
- package/dist/tenant/schema-manager.d.ts +185 -0
- package/dist/tenant/schema-manager.d.ts.map +1 -0
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/transaction.d.ts +51 -0
- package/dist/transaction/transaction.d.ts.map +1 -0
- package/dist/types/cache.d.ts +214 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/cloudforge.d.ts +753 -0
- package/dist/types/cloudforge.d.ts.map +1 -0
- package/dist/types/connection.d.ts +91 -0
- package/dist/types/connection.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/migration.d.ts +225 -0
- package/dist/types/migration.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +432 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/query-builder.d.ts +217 -0
- package/dist/types/query-builder.d.ts.map +1 -0
- package/dist/types/seed.d.ts +187 -0
- package/dist/types/seed.d.ts.map +1 -0
- package/dist/types/tenant.d.ts +140 -0
- package/dist/types/tenant.d.ts.map +1 -0
- package/dist/types/transaction.d.ts +144 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Result, Logger, EventBus, type UnsubscribeFn } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { Cache } from '../types/cache.js';
|
|
3
|
+
/**
|
|
4
|
+
* Invalidation statistics
|
|
5
|
+
*/
|
|
6
|
+
export interface InvalidationStats {
|
|
7
|
+
/** Total number of invalidations performed */
|
|
8
|
+
totalInvalidations: number;
|
|
9
|
+
/** Number of tag-based invalidations */
|
|
10
|
+
tagInvalidations: number;
|
|
11
|
+
/** Number of pattern-based invalidations */
|
|
12
|
+
patternInvalidations: number;
|
|
13
|
+
/** Number of key-based invalidations */
|
|
14
|
+
keyInvalidations: number;
|
|
15
|
+
/** Number of expired entry invalidations */
|
|
16
|
+
expiredInvalidations: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Cache invalidation error types
|
|
20
|
+
*/
|
|
21
|
+
export type InvalidationError = {
|
|
22
|
+
type: 'INVALIDATION_FAILED';
|
|
23
|
+
message: string;
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'TAG_NOT_FOUND';
|
|
27
|
+
message: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'UNKNOWN';
|
|
30
|
+
message: string;
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Cache invalidation system
|
|
35
|
+
*
|
|
36
|
+
* Provides advanced cache invalidation strategies:
|
|
37
|
+
* - Tag-based invalidation (group entries by logical tags)
|
|
38
|
+
* - Time-based invalidation (TTL expiration scanning)
|
|
39
|
+
* - Event-based invalidation (integrate with EventBus)
|
|
40
|
+
* - Batch invalidation (efficient multi-entry invalidation)
|
|
41
|
+
* - Pattern-based invalidation (wildcard matching)
|
|
42
|
+
*
|
|
43
|
+
* Usage:
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const invalidator = new CacheInvalidator(cache, eventBus, logger);
|
|
46
|
+
*
|
|
47
|
+
* // Tag entries
|
|
48
|
+
* await invalidator.tagEntry('user:1', ['users', 'active']);
|
|
49
|
+
*
|
|
50
|
+
* // Invalidate by tag
|
|
51
|
+
* await invalidator.invalidateByTag('users');
|
|
52
|
+
*
|
|
53
|
+
* // Subscribe to data change events
|
|
54
|
+
* const unsubscribe = invalidator.subscribeToDataChanges();
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class CacheInvalidator {
|
|
58
|
+
private readonly cache;
|
|
59
|
+
private readonly eventBus;
|
|
60
|
+
private readonly logger;
|
|
61
|
+
private readonly tagIndex;
|
|
62
|
+
private readonly entryTags;
|
|
63
|
+
private stats;
|
|
64
|
+
constructor(cache: Cache, eventBus: EventBus, logger: Logger);
|
|
65
|
+
/**
|
|
66
|
+
* Tag a cache entry for group invalidation
|
|
67
|
+
*
|
|
68
|
+
* @param key - Cache key
|
|
69
|
+
* @param tags - Array of tags to associate with this entry
|
|
70
|
+
* @returns Result with void on success
|
|
71
|
+
*/
|
|
72
|
+
tagEntry(key: string, tags: string[]): Promise<Result<void, InvalidationError>>;
|
|
73
|
+
/**
|
|
74
|
+
* Remove a tag from a cache entry
|
|
75
|
+
*
|
|
76
|
+
* @param key - Cache key
|
|
77
|
+
* @param tag - Tag to remove
|
|
78
|
+
* @returns Result with void on success
|
|
79
|
+
*/
|
|
80
|
+
removeTag(key: string, tag: string): Promise<Result<void, InvalidationError>>;
|
|
81
|
+
/**
|
|
82
|
+
* Invalidate all entries with a specific tag
|
|
83
|
+
*
|
|
84
|
+
* @param tag - Tag to invalidate (supports wildcards)
|
|
85
|
+
* @returns Result with number of invalidated entries
|
|
86
|
+
*/
|
|
87
|
+
invalidateByTag(tag: string): Promise<Result<number, InvalidationError>>;
|
|
88
|
+
/**
|
|
89
|
+
* Invalidate entries by multiple tags
|
|
90
|
+
*
|
|
91
|
+
* @param tags - Array of tags to invalidate
|
|
92
|
+
* @returns Result with number of invalidated entries
|
|
93
|
+
*/
|
|
94
|
+
invalidateByTags(tags: string[]): Promise<Result<number, InvalidationError>>;
|
|
95
|
+
/**
|
|
96
|
+
* Invalidate specific cache keys
|
|
97
|
+
*
|
|
98
|
+
* @param keys - Array of keys to invalidate
|
|
99
|
+
* @returns Result with number of invalidated entries
|
|
100
|
+
*/
|
|
101
|
+
invalidateByKeys(keys: string[]): Promise<Result<number, InvalidationError>>;
|
|
102
|
+
/**
|
|
103
|
+
* Invalidate entries matching a pattern
|
|
104
|
+
*
|
|
105
|
+
* @param pattern - Pattern to match (supports wildcards)
|
|
106
|
+
* @returns Result with number of invalidated entries
|
|
107
|
+
*/
|
|
108
|
+
invalidateByPattern(pattern: string): Promise<Result<number, InvalidationError>>;
|
|
109
|
+
/**
|
|
110
|
+
* Scan and invalidate expired entries
|
|
111
|
+
*
|
|
112
|
+
* @returns Result with number of invalidated entries
|
|
113
|
+
*/
|
|
114
|
+
invalidateExpired(): Promise<Result<number, InvalidationError>>;
|
|
115
|
+
/**
|
|
116
|
+
* Subscribe to data change events for automatic invalidation
|
|
117
|
+
*
|
|
118
|
+
* @returns Unsubscribe function
|
|
119
|
+
*/
|
|
120
|
+
subscribeToDataChanges(): UnsubscribeFn;
|
|
121
|
+
/**
|
|
122
|
+
* Get all keys tagged with a specific tag
|
|
123
|
+
*
|
|
124
|
+
* @param tag - Tag name
|
|
125
|
+
* @returns Result with array of keys
|
|
126
|
+
*/
|
|
127
|
+
getTaggedKeys(tag: string): Promise<Result<string[], InvalidationError>>;
|
|
128
|
+
/**
|
|
129
|
+
* Get all tags for a cache entry
|
|
130
|
+
*
|
|
131
|
+
* @param key - Cache key
|
|
132
|
+
* @returns Result with array of tags
|
|
133
|
+
*/
|
|
134
|
+
getEntryTags(key: string): Promise<Result<string[], InvalidationError>>;
|
|
135
|
+
/**
|
|
136
|
+
* Get invalidation statistics
|
|
137
|
+
*
|
|
138
|
+
* @returns Result with statistics
|
|
139
|
+
*/
|
|
140
|
+
getStats(): Result<InvalidationStats, InvalidationError>;
|
|
141
|
+
/**
|
|
142
|
+
* Reset invalidation statistics
|
|
143
|
+
*
|
|
144
|
+
* @returns Result with void on success
|
|
145
|
+
*/
|
|
146
|
+
resetStats(): Result<void, InvalidationError>;
|
|
147
|
+
/**
|
|
148
|
+
* Clean up tag mappings for a deleted entry
|
|
149
|
+
*/
|
|
150
|
+
private cleanupEntryTags;
|
|
151
|
+
/**
|
|
152
|
+
* Convert glob pattern to regex
|
|
153
|
+
*/
|
|
154
|
+
private patternToRegex;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=invalidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidation.d.ts","sourceRoot":"","sources":["../../src/cache/invalidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,8CAA8C;IAC9C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,wCAAwC;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,wCAAwC;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAGhC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAGhE,OAAO,CAAC,QAAQ,CAAC,SAAS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C,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;IAkB7E;;;;OAIG;IACH,QAAQ,IAAI,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAYxD;;;;OAIG;IACH,UAAU,IAAI,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAoB7C;;OAEG;YACW,gBAAgB;IAmB9B;;OAEG;IACH,OAAO,CAAC,cAAc;CAQvB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Result, Option, Logger } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { Cache, CacheConfig, CacheEntry, CacheError, CacheStats } from '../types/cache.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cloudflare Workers KV namespace interface
|
|
5
|
+
*/
|
|
6
|
+
export interface KVNamespace {
|
|
7
|
+
get(key: string, options?: {
|
|
8
|
+
type?: 'text' | 'json';
|
|
9
|
+
}): Promise<any>;
|
|
10
|
+
put(key: string, value: string, options?: {
|
|
11
|
+
expirationTtl?: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
list(options?: {
|
|
15
|
+
prefix?: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
cursor?: string;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
keys: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
}>;
|
|
22
|
+
list_complete: boolean;
|
|
23
|
+
cursor?: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Cloudflare Workers KV cache implementation
|
|
28
|
+
*
|
|
29
|
+
* Features:
|
|
30
|
+
* - Distributed cache using Cloudflare KV
|
|
31
|
+
* - TTL-based expiration via KV expirationTtl
|
|
32
|
+
* - Cache-aside pattern
|
|
33
|
+
* - Pattern-based invalidation
|
|
34
|
+
* - Statistics tracking (hits/misses)
|
|
35
|
+
*
|
|
36
|
+
* Limitations:
|
|
37
|
+
* - No total item count (KV doesn't provide this efficiently)
|
|
38
|
+
* - No LRU eviction (KV handles this internally)
|
|
39
|
+
* - List operations are eventually consistent
|
|
40
|
+
*
|
|
41
|
+
* Usage:
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const cache = new KVCache(env.CACHE_KV, config, logger);
|
|
44
|
+
* await cache.set('user:1', { id: 1, name: 'John' }, 60);
|
|
45
|
+
* const result = await cache.get<User>('user:1');
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class KVCache implements Cache {
|
|
49
|
+
readonly config: CacheConfig;
|
|
50
|
+
private readonly kv;
|
|
51
|
+
private readonly logger;
|
|
52
|
+
private stats;
|
|
53
|
+
constructor(kv: KVNamespace, config: CacheConfig, logger: Logger);
|
|
54
|
+
get<T = unknown>(key: string): Promise<Result<Option<T>, CacheError>>;
|
|
55
|
+
getWithMetadata<T = unknown>(key: string): Promise<Result<Option<CacheEntry<T>>, CacheError>>;
|
|
56
|
+
set<T = unknown>(key: string, value: T, ttl?: number): Promise<Result<void, CacheError>>;
|
|
57
|
+
delete(key: string): Promise<Result<boolean, CacheError>>;
|
|
58
|
+
deleteMany(keys: string[]): Promise<Result<number, CacheError>>;
|
|
59
|
+
clear(): Promise<Result<void, CacheError>>;
|
|
60
|
+
has(key: string): Promise<Result<boolean, CacheError>>;
|
|
61
|
+
invalidate(pattern: string): Promise<Result<number, CacheError>>;
|
|
62
|
+
invalidateTable(table: string): Promise<Result<number, CacheError>>;
|
|
63
|
+
getStats(): Result<CacheStats, CacheError>;
|
|
64
|
+
resetStats(): Result<void, CacheError>;
|
|
65
|
+
generateKey(sql: string, params?: unknown[]): string;
|
|
66
|
+
/**
|
|
67
|
+
* Get full cache key with prefix
|
|
68
|
+
*/
|
|
69
|
+
private getFullKey;
|
|
70
|
+
/**
|
|
71
|
+
* Estimate size of value in bytes
|
|
72
|
+
*/
|
|
73
|
+
private estimateSize;
|
|
74
|
+
/**
|
|
75
|
+
* Convert glob pattern to regex
|
|
76
|
+
*/
|
|
77
|
+
private pattern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QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC;IAwB1C,UAAU,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC;IAetC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM;IAcpD;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,cAAc;CAQvB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Result, Option, Logger } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { Cache, CacheConfig, CacheEntry, CacheError, CacheStats } from '../types/cache.js';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory LRU cache implementation
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - TTL-based expiration
|
|
8
|
+
* - LRU eviction policy
|
|
9
|
+
* - Cache statistics tracking (hits/misses/evictions)
|
|
10
|
+
* - Pattern-based invalidation
|
|
11
|
+
* - Metadata tracking (access count, timestamps)
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const cache = new MemoryCache(config, logger);
|
|
16
|
+
* await cache.set('user:1', { id: 1, name: 'John' }, 60);
|
|
17
|
+
* const result = await cache.get<User>('user:1');
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class MemoryCache implements Cache {
|
|
21
|
+
readonly config: CacheConfig;
|
|
22
|
+
private readonly logger;
|
|
23
|
+
private readonly store;
|
|
24
|
+
private readonly lruList;
|
|
25
|
+
private stats;
|
|
26
|
+
constructor(config: CacheConfig, logger: Logger);
|
|
27
|
+
get<T = unknown>(key: string): Promise<Result<Option<T>, CacheError>>;
|
|
28
|
+
getWithMetadata<T = unknown>(key: string): Promise<Result<Option<CacheEntry<T>>, CacheError>>;
|
|
29
|
+
set<T = unknown>(key: string, value: T, ttl?: number): Promise<Result<void, CacheError>>;
|
|
30
|
+
delete(key: string): Promise<Result<boolean, CacheError>>;
|
|
31
|
+
deleteMany(keys: string[]): Promise<Result<number, CacheError>>;
|
|
32
|
+
clear(): Promise<Result<void, CacheError>>;
|
|
33
|
+
has(key: string): Promise<Result<boolean, CacheError>>;
|
|
34
|
+
invalidate(pattern: string): Promise<Result<number, CacheError>>;
|
|
35
|
+
invalidateTable(table: string): Promise<Result<number, CacheError>>;
|
|
36
|
+
getStats(): Result<CacheStats, CacheError>;
|
|
37
|
+
resetStats(): Result<void, CacheError>;
|
|
38
|
+
generateKey(sql: string, params?: unknown[]): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get full cache key with prefix
|
|
41
|
+
*/
|
|
42
|
+
private getFullKey;
|
|
43
|
+
/**
|
|
44
|
+
* Check if entry is expired
|
|
45
|
+
*/
|
|
46
|
+
private isExpired;
|
|
47
|
+
/**
|
|
48
|
+
* Update entry access metadata and LRU position
|
|
49
|
+
*/
|
|
50
|
+
private touchEntry;
|
|
51
|
+
/**
|
|
52
|
+
* Remove key from LRU list
|
|
53
|
+
*/
|
|
54
|
+
private removeLRU;
|
|
55
|
+
/**
|
|
56
|
+
* Evict least recently used entry
|
|
57
|
+
*/
|
|
58
|
+
private evictLRU;
|
|
59
|
+
/**
|
|
60
|
+
* Estimate size of value in bytes
|
|
61
|
+
*/
|
|
62
|
+
private estimateSize;
|
|
63
|
+
/**
|
|
64
|
+
* Convert glob pattern to regex
|
|
65
|
+
*/
|
|
66
|
+
private patternToRegex;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=memory-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-cache.d.ts","sourceRoot":"","sources":["../../src/cache/memory-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,UAAU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AAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IA4BhE,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAezE,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC;IA2B1C,UAAU,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC;IAgBtC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM;IAcpD;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,SAAS;IAQjB;;OAEG;IACH,OAAO,CAAC,UAAU;IASlB;;OAEG;IACH,OAAO,CAAC,SAAS;IAOjB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAahB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,cAAc;CAQvB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Result, Logger } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { D1Result, D1AdapterConfig, D1AdapterError, D1Adapter, D1ExecResult } from '../types/cloudforge.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cloudflare D1 database adapter
|
|
5
|
+
*
|
|
6
|
+
* Provides a standardized interface for interacting with Cloudflare D1 databases.
|
|
7
|
+
* Handles D1-specific quirks and optimizes for D1 performance.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const adapter = new D1DatabaseAdapter(config, logger);
|
|
12
|
+
*
|
|
13
|
+
* // Query data
|
|
14
|
+
* const result = await adapter.query('SELECT * FROM users WHERE id = ?', [1]);
|
|
15
|
+
*
|
|
16
|
+
* // Execute statement
|
|
17
|
+
* const execResult = await adapter.execute('INSERT INTO users (name) VALUES (?)', ['Alice']);
|
|
18
|
+
*
|
|
19
|
+
* // Batch operations
|
|
20
|
+
* const batchResult = await adapter.batch([
|
|
21
|
+
* { sql: 'INSERT INTO users (name) VALUES (?)', params: ['Alice'] },
|
|
22
|
+
* { sql: 'INSERT INTO users (name) VALUES (?)', params: ['Bob'] },
|
|
23
|
+
* ]);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class D1DatabaseAdapter implements D1Adapter {
|
|
27
|
+
readonly config: D1AdapterConfig;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private readonly db;
|
|
30
|
+
constructor(config: D1AdapterConfig, logger: Logger);
|
|
31
|
+
/**
|
|
32
|
+
* Execute a SQL query and return all results
|
|
33
|
+
*/
|
|
34
|
+
query<T = unknown>(sql: string, params?: unknown[]): Promise<Result<T[], D1AdapterError>>;
|
|
35
|
+
/**
|
|
36
|
+
* Execute a SQL query and return first result
|
|
37
|
+
*/
|
|
38
|
+
queryFirst<T = unknown>(sql: string, params?: unknown[]): Promise<Result<T | null, D1AdapterError>>;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a SQL statement (INSERT, UPDATE, DELETE)
|
|
41
|
+
*/
|
|
42
|
+
execute(sql: string, params?: unknown[]): Promise<Result<D1Result, D1AdapterError>>;
|
|
43
|
+
/**
|
|
44
|
+
* Execute multiple SQL statements in a batch
|
|
45
|
+
*/
|
|
46
|
+
batch(statements: Array<{
|
|
47
|
+
sql: string;
|
|
48
|
+
params?: unknown[];
|
|
49
|
+
}>): Promise<Result<D1Result[], D1AdapterError>>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute raw SQL (for migrations and schema changes)
|
|
52
|
+
*/
|
|
53
|
+
exec(sql: string): Promise<Result<D1ExecResult, D1AdapterError>>;
|
|
54
|
+
/**
|
|
55
|
+
* Begin a transaction
|
|
56
|
+
*
|
|
57
|
+
* Note: D1 doesn't support explicit transactions yet, so this wraps
|
|
58
|
+
* the callback execution and provides the same interface for compatibility.
|
|
59
|
+
* Consider using batch() for atomic multi-statement operations.
|
|
60
|
+
*/
|
|
61
|
+
transaction<T>(callback: (adapter: D1Adapter) => Promise<Result<T, D1AdapterError>>): Promise<Result<T, D1AdapterError>>;
|
|
62
|
+
/**
|
|
63
|
+
* Prepare a SQL statement with parameters
|
|
64
|
+
*/
|
|
65
|
+
private prepareStatement;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=d1-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"d1-adapter.d.ts","sourceRoot":"","sources":["../../src/cloudforge/d1-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAGV,QAAQ,EACR,eAAe,EACf,cAAc,EACd,SAAS,EACT,YAAY,EACb,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IACjD,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAa;gBAEpB,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM;IAMnD;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;IA6B/F;;OAEG;IACG,UAAU,CAAC,CAAC,GAAG,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,cAAc,CAAC,CAAC;IAqB5C;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IA6BzF;;OAEG;IACG,KAAK,CACT,UAAU,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,GACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,cAAc,CAAC,CAAC;IAyC9C;;OAEG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAmBtE;;;;;;OAMG;IACG,WAAW,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,GACnE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IAkBrC;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAUzB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Result, Logger } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { DurableObjectStorage, DurableObjectStorageConfig, DurableObjectStorageError, DurableObjectStorageAdapter as IDurableObjectStorageAdapter, StorageListOptions, StorageTransaction } from '../types/cloudforge.js';
|
|
3
|
+
/**
|
|
4
|
+
* Durable Objects storage adapter implementation
|
|
5
|
+
*
|
|
6
|
+
* Provides a type-safe interface for Cloudflare Durable Objects storage
|
|
7
|
+
* with Result-based error handling and logging support.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DurableObjectStorageAdapter implements IDurableObjectStorageAdapter {
|
|
10
|
+
readonly config: DurableObjectStorageConfig;
|
|
11
|
+
private readonly storage;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
constructor(storage: DurableObjectStorage, config: DurableObjectStorageConfig, logger: Logger);
|
|
14
|
+
/**
|
|
15
|
+
* Get a single value by key
|
|
16
|
+
*/
|
|
17
|
+
get<T>(key: string): Promise<Result<T | null, DurableObjectStorageError>>;
|
|
18
|
+
/**
|
|
19
|
+
* Get multiple values by keys
|
|
20
|
+
*/
|
|
21
|
+
getMultiple<T>(keys: string[]): Promise<Result<Map<string, T>, DurableObjectStorageError>>;
|
|
22
|
+
/**
|
|
23
|
+
* Put a single key-value pair
|
|
24
|
+
*/
|
|
25
|
+
put<T>(key: string, value: T): Promise<Result<void, DurableObjectStorageError>>;
|
|
26
|
+
/**
|
|
27
|
+
* Put multiple key-value pairs
|
|
28
|
+
*/
|
|
29
|
+
putMultiple<T>(entries: [string, T][]): Promise<Result<void, DurableObjectStorageError>>;
|
|
30
|
+
/**
|
|
31
|
+
* Delete a single key
|
|
32
|
+
*/
|
|
33
|
+
delete(key: string): Promise<Result<boolean, DurableObjectStorageError>>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete multiple keys
|
|
36
|
+
*/
|
|
37
|
+
deleteMultiple(keys: string[]): Promise<Result<number, DurableObjectStorageError>>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete all keys in storage
|
|
40
|
+
*/
|
|
41
|
+
deleteAll(): Promise<Result<void, DurableObjectStorageError>>;
|
|
42
|
+
/**
|
|
43
|
+
* List keys in storage
|
|
44
|
+
*/
|
|
45
|
+
list(options?: StorageListOptions): Promise<Result<Map<string, any>, DurableObjectStorageError>>;
|
|
46
|
+
/**
|
|
47
|
+
* Execute operations in a transaction
|
|
48
|
+
*/
|
|
49
|
+
transaction<T>(callback: (txn: StorageTransaction) => Promise<Result<T, DurableObjectStorageError>>): Promise<Result<T, DurableObjectStorageError>>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=do-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-storage.d.ts","sourceRoot":"","sources":["../../src/cloudforge/do-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACvD,OA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AC,CAAC;IAsBxF;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;IAmBnE;;OAEG;IACG,IAAI,CACR,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,yBAAyB,CAAC,CAAC;IAmB/D;;OAEG;IACG,WAAW,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAC,GACnF,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAC;CA4BjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudforge/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Result, Logger } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { R2BackupConfig, R2BackupError, R2BackupAdapter as IR2BackupAdapter, BackupInfo, BackupOptions, RestoreOptions } from '../types/cloudforge.js';
|
|
3
|
+
/**
|
|
4
|
+
* R2 backup adapter implementation
|
|
5
|
+
*
|
|
6
|
+
* Provides database backup and restore functionality using Cloudflare R2 storage
|
|
7
|
+
* with compression support and metadata tracking.
|
|
8
|
+
*/
|
|
9
|
+
export declare class R2BackupAdapter implements IR2BackupAdapter {
|
|
10
|
+
readonly config: R2BackupConfig;
|
|
11
|
+
private readonly bucket;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
constructor(config: R2BackupConfig, logger: Logger);
|
|
14
|
+
/**
|
|
15
|
+
* Create a backup with compression
|
|
16
|
+
*/
|
|
17
|
+
backup(data: ArrayBuffer | Buffer, options?: BackupOptions): Promise<Result<BackupInfo, R2BackupError>>;
|
|
18
|
+
/**
|
|
19
|
+
* Restore from a backup with decompression
|
|
20
|
+
*/
|
|
21
|
+
restore(key: string, options?: RestoreOptions): Promise<Result<ArrayBuffer, R2BackupError>>;
|
|
22
|
+
/**
|
|
23
|
+
* List all backups
|
|
24
|
+
*/
|
|
25
|
+
listBackups(options?: {
|
|
26
|
+
limit?: number;
|
|
27
|
+
cursor?: string;
|
|
28
|
+
}): Promise<Result<BackupInfo[], R2BackupError>>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete a single backup
|
|
31
|
+
*/
|
|
32
|
+
deleteBackup(key: string): Promise<Result<void, R2BackupError>>;
|
|
33
|
+
/**
|
|
34
|
+
* Delete multiple backups (batched for efficiency)
|
|
35
|
+
*/
|
|
36
|
+
deleteMultipleBackups(keys: string[]): Promise<Result<void, R2BackupError>>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=r2-backup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"r2-backup.d.ts","sourceRoot":"","sources":["../../src/cloudforge/r2-backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAEV,cAAc,EACd,aAAa,EACb,eAAe,IAAI,gBAAgB,EACnC,UAAU,EACV,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM;IAMlD;;OAEG;IACG,MAAM,CACV,IAAI,EAAE,WAAW,GAAG,MAAM,EAC1B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAmG7C;;OAEG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IA8D9C;;OAEG;IACG,WAAW,CAAC,OAAO,CAAC,EAAE;QAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,aAAa,CAAC,CAAC;IA6ChD;;OAEG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAmBrE;;OAEG;IACG,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;CAgClF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Result, Logger } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { DatabaseConnection, DatabaseConnectionConfig, DatabaseConnectionError } from '../types/connection.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extended configuration for connection manager
|
|
5
|
+
*/
|
|
6
|
+
interface ConnectionManagerConfig extends DatabaseConnectionConfig {
|
|
7
|
+
autoReconnect?: boolean;
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
retryDelay?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Database connection manager with pooling, health checks, and auto-reconnect
|
|
13
|
+
*/
|
|
14
|
+
export declare class DatabaseConnectionManager {
|
|
15
|
+
private config;
|
|
16
|
+
private logger;
|
|
17
|
+
private pool;
|
|
18
|
+
private available;
|
|
19
|
+
private active;
|
|
20
|
+
private initialized;
|
|
21
|
+
private destroyed;
|
|
22
|
+
private connectionIdCounter;
|
|
23
|
+
constructor(config: ConnectionManagerConfig, logger: Logger);
|
|
24
|
+
/**
|
|
25
|
+
* Get manager configuration
|
|
26
|
+
*/
|
|
27
|
+
getConfig(): ConnectionManagerConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Get number of active connections
|
|
30
|
+
*/
|
|
31
|
+
getActiveCount(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the connection manager
|
|
34
|
+
*/
|
|
35
|
+
initialize(): Promise<Result<void, DatabaseConnectionError>>;
|
|
36
|
+
/**
|
|
37
|
+
* Acquire a connection from the pool
|
|
38
|
+
*/
|
|
39
|
+
acquire(): Promise<Result<DatabaseConnection, DatabaseConnectionError>>;
|
|
40
|
+
/**
|
|
41
|
+
* Release a connection back to the pool
|
|
42
|
+
*/
|
|
43
|
+
release(connection: DatabaseConnection): Promise<Result<void, DatabaseConnectionError>>;
|
|
44
|
+
/**
|
|
45
|
+
* Perform health check on all connections
|
|
46
|
+
*/
|
|
47
|
+
healthCheck(): Promise<Result<boolean, DatabaseConnectionError>>;
|
|
48
|
+
/**
|
|
49
|
+
* Destroy the connection manager and close all connections
|
|
50
|
+
*/
|
|
51
|
+
destroy(): Promise<Result<void, DatabaseConnectionError>>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/connection/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,UAAU,uBAAwB,SAAQ,w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