@earth-app/collegedb 1.0.8 → 1.1.1
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/README.md +590 -132
- package/dist/durable.d.ts +8 -4
- package/dist/durable.d.ts.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +10 -9
- package/dist/kvmap.d.ts +68 -5
- package/dist/kvmap.d.ts.map +1 -1
- package/dist/migrations.d.ts +22 -19
- package/dist/migrations.d.ts.map +1 -1
- package/dist/providers.d.ts +284 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/router.d.ts +10 -10
- package/dist/router.d.ts.map +1 -1
- package/dist/types.d.ts +143 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +40 -16
package/dist/router.d.ts
CHANGED
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
* @author CollegeDB Team
|
|
40
40
|
* @since 1.0.0
|
|
41
41
|
*/
|
|
42
|
-
import type {
|
|
43
|
-
import type { CollegeDBConfig, D1Region, ShardStats } from './types
|
|
42
|
+
import type { Request } from '@cloudflare/workers-types';
|
|
43
|
+
import type { CollegeDBConfig, D1Region, PreparedStatement, QueryResult, SQLDatabase, ShardStats } from './types';
|
|
44
44
|
/**
|
|
45
45
|
* Sets up the global configuration for the CollegeDB system. This must be called
|
|
46
46
|
* before any other operations can be performed. The configuration includes KV
|
|
@@ -198,7 +198,7 @@ export declare function getClosestRegionFromIP(request: Request): D1Region;
|
|
|
198
198
|
* await createSchema(env.DB_NEW_SHARD, userSchema);
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
|
-
export declare function createSchema(d1:
|
|
201
|
+
export declare function createSchema(d1: SQLDatabase, schema: string): Promise<void>;
|
|
202
202
|
/**
|
|
203
203
|
* Prepares a SQL statement for execution with operation-aware routing.
|
|
204
204
|
*
|
|
@@ -207,7 +207,7 @@ export declare function createSchema(d1: D1Database, schema: string): Promise<vo
|
|
|
207
207
|
* @returns Promise that resolves to a prepared statement
|
|
208
208
|
* @throws {Error} If preparation fails
|
|
209
209
|
*/
|
|
210
|
-
export declare function prepare(key: string, sql: string): Promise<
|
|
210
|
+
export declare function prepare(key: string, sql: string): Promise<PreparedStatement>;
|
|
211
211
|
/**
|
|
212
212
|
* Executes a statement on the appropriate shard based on the primary key.
|
|
213
213
|
* The primary key is used to determine which shard should store the record,
|
|
@@ -270,7 +270,7 @@ export declare function prepare(key: string, sql: string): Promise<D1PreparedSta
|
|
|
270
270
|
* );
|
|
271
271
|
* ```
|
|
272
272
|
*/
|
|
273
|
-
export declare function run<T = Record<string, unknown>>(key: string, sql: string, bindings?: any[]): Promise<
|
|
273
|
+
export declare function run<T = Record<string, unknown>>(key: string, sql: string, bindings?: any[]): Promise<QueryResult<T>>;
|
|
274
274
|
/**
|
|
275
275
|
* Retrieves all records matching the query for a given primary key.
|
|
276
276
|
*
|
|
@@ -302,7 +302,7 @@ export declare function run<T = Record<string, unknown>>(key: string, sql: strin
|
|
|
302
302
|
* console.log(`User has ${postsResult.meta.count} posts`);
|
|
303
303
|
* ```
|
|
304
304
|
*/
|
|
305
|
-
export declare function all<T = Record<string, unknown>>(key: string, sql: string, bindings?: any[]): Promise<
|
|
305
|
+
export declare function all<T = Record<string, unknown>>(key: string, sql: string, bindings?: any[]): Promise<QueryResult<T>>;
|
|
306
306
|
/**
|
|
307
307
|
* Retrieves the first record matching the query for a given primary key.
|
|
308
308
|
*
|
|
@@ -448,7 +448,7 @@ export declare function getShardStats(): Promise<ShardStats[]>;
|
|
|
448
448
|
* console.log(`Inserted user with ID: ${result.lastInsertId}`);
|
|
449
449
|
* ```
|
|
450
450
|
*/
|
|
451
|
-
export declare function runShard<T = Record<string, unknown>>(shardBinding: string, sql: string, bindings?: any[]): Promise<
|
|
451
|
+
export declare function runShard<T = Record<string, unknown>>(shardBinding: string, sql: string, bindings?: any[]): Promise<QueryResult<T>>;
|
|
452
452
|
/**
|
|
453
453
|
* Bypasses the normal routing logic to execute a query directly on a specified
|
|
454
454
|
* shard. This is useful for administrative operations, cross-shard queries,
|
|
@@ -482,7 +482,7 @@ export declare function runShard<T = Record<string, unknown>>(shardBinding: stri
|
|
|
482
482
|
* );
|
|
483
483
|
* ```
|
|
484
484
|
*/
|
|
485
|
-
export declare function allShard<T = Record<string, unknown>>(shardBinding: string, sql: string, bindings?: any[]): Promise<
|
|
485
|
+
export declare function allShard<T = Record<string, unknown>>(shardBinding: string, sql: string, bindings?: any[]): Promise<QueryResult<T>>;
|
|
486
486
|
/**
|
|
487
487
|
* Bypasses the normal routing logic to execute a query directly on a specified
|
|
488
488
|
* shard. This is useful for administrative operations, cross-shard queries,
|
|
@@ -522,7 +522,7 @@ export declare function firstShard<T = Record<string, unknown>>(shardBinding: st
|
|
|
522
522
|
* @returns Promise resolving to an array of results from each shard
|
|
523
523
|
* @since 1.0.4
|
|
524
524
|
*/
|
|
525
|
-
export declare function runAllShards<T = Record<string, unknown>>(sql: string, bindings?: any[], batchSize?: number): Promise<
|
|
525
|
+
export declare function runAllShards<T = Record<string, unknown>>(sql: string, bindings?: any[], batchSize?: number): Promise<QueryResult<T>[]>;
|
|
526
526
|
/**
|
|
527
527
|
* Executes a query on all shards and returns all matching records from each shard.
|
|
528
528
|
*
|
|
@@ -535,7 +535,7 @@ export declare function runAllShards<T = Record<string, unknown>>(sql: string, b
|
|
|
535
535
|
* @returns Promise resolving to an array of results from each shard
|
|
536
536
|
* @since 1.0.4
|
|
537
537
|
*/
|
|
538
|
-
export declare function allAllShards<T = Record<string, unknown>>(sql: string, bindings?: any[], batchSize?: number): Promise<
|
|
538
|
+
export declare function allAllShards<T = Record<string, unknown>>(sql: string, bindings?: any[], batchSize?: number): Promise<QueryResult<T>[]>;
|
|
539
539
|
/**
|
|
540
540
|
* Executes a query on all shards and returns the first matching record from each shard.
|
|
541
541
|
*
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,KAAK,EACX,eAAe,EACf,QAAQ,EAER,iBAAiB,EACjB,WAAW,EACX,WAAW,EAEX,UAAU,EAEV,MAAM,SAAS,CAAC;AA6CjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,QA0BjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,eAAe,iBAuB5D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,CAAC,cAG5E;AA8DD;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAIlC;AAkGD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAkIjE;AAkVD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjF;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,i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B,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,GAAG,EAAO,EACpB,SAAS,GAAE,MAAW,GACpB,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CA6BvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB3C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASnF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* @fileoverview TypeScript type definitions for CollegeDB
|
|
3
3
|
*
|
|
4
4
|
* This module contains all the TypeScript interfaces and types used throughout
|
|
5
|
-
* the CollegeDB library. These types provide compile-time safety
|
|
6
|
-
* better developer experience with IDE
|
|
5
|
+
* the CollegeDB library. These types provide compile-time safety, provider-
|
|
6
|
+
* agnostic storage abstractions, and a better developer experience with IDE
|
|
7
|
+
* autocompletion and error checking.
|
|
7
8
|
*
|
|
8
9
|
* The types are organized into several categories:
|
|
9
10
|
* - Environment and configuration types
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
15
16
|
* ```typescript
|
|
16
|
-
* import type { CollegeDBConfig, QueryResult, ShardStats } from './types
|
|
17
|
+
* import type { CollegeDBConfig, QueryResult, ShardStats } from './types';
|
|
17
18
|
*
|
|
18
19
|
* const config: CollegeDBConfig = {
|
|
19
20
|
* kv: env.KV,
|
|
@@ -25,7 +26,104 @@
|
|
|
25
26
|
* @author Gregory Mitchell
|
|
26
27
|
* @since 1.0.0
|
|
27
28
|
*/
|
|
28
|
-
import type {
|
|
29
|
+
import type { DurableObjectNamespace } from '@cloudflare/workers-types';
|
|
30
|
+
/**
|
|
31
|
+
* Result item returned by a key-value store list operation.
|
|
32
|
+
*/
|
|
33
|
+
export interface KVListKey {
|
|
34
|
+
/** Full key name */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Optional absolute expiration timestamp */
|
|
37
|
+
expiration?: number;
|
|
38
|
+
/** Optional backend-specific metadata */
|
|
39
|
+
metadata?: unknown;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result payload returned by key-value store list operations.
|
|
43
|
+
*/
|
|
44
|
+
export interface KVListResult {
|
|
45
|
+
/** The keys that matched the provided list filter */
|
|
46
|
+
keys: KVListKey[];
|
|
47
|
+
/** Cursor for paginated list operations (backend-specific) */
|
|
48
|
+
cursor?: string;
|
|
49
|
+
/** Whether the list is complete (backend-specific) */
|
|
50
|
+
list_complete?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Provider-agnostic key-value storage contract.
|
|
54
|
+
*
|
|
55
|
+
* This interface is implemented by Cloudflare KV, Redis/Valkey adapters,
|
|
56
|
+
* and any custom KV backend supported by CollegeDB.
|
|
57
|
+
*/
|
|
58
|
+
export interface KVStorage {
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves a value by key. When `type` is `json`, the value should be parsed.
|
|
61
|
+
*/
|
|
62
|
+
get<T = unknown>(key: string, type: 'json'): Promise<T | null>;
|
|
63
|
+
get(key: string, type?: 'text'): Promise<string | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Stores a value by key.
|
|
66
|
+
*/
|
|
67
|
+
put(key: string, value: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Deletes a key.
|
|
70
|
+
*/
|
|
71
|
+
delete(key: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Lists keys, optionally filtered by prefix.
|
|
74
|
+
*/
|
|
75
|
+
list(options?: {
|
|
76
|
+
prefix?: string;
|
|
77
|
+
cursor?: string;
|
|
78
|
+
limit?: number;
|
|
79
|
+
}): Promise<KVListResult>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Metadata for SQL query execution results.
|
|
83
|
+
*/
|
|
84
|
+
export interface QueryResultMeta {
|
|
85
|
+
/** Query duration in milliseconds */
|
|
86
|
+
duration: number;
|
|
87
|
+
/** Number of changed rows (when available) */
|
|
88
|
+
changes?: number;
|
|
89
|
+
/** Last inserted row id (when available) */
|
|
90
|
+
last_row_id?: number | string;
|
|
91
|
+
/** Additional provider-specific metadata */
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Provider-agnostic query result payload.
|
|
96
|
+
*/
|
|
97
|
+
export interface QueryResult<T = Record<string, unknown>> {
|
|
98
|
+
/** Whether the statement executed successfully */
|
|
99
|
+
success: boolean;
|
|
100
|
+
/** Returned rows for the statement */
|
|
101
|
+
results: T[];
|
|
102
|
+
/** Execution metadata */
|
|
103
|
+
meta: QueryResultMeta;
|
|
104
|
+
/** Optional backend-specific error detail */
|
|
105
|
+
error?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Provider-agnostic prepared statement contract.
|
|
109
|
+
*/
|
|
110
|
+
export interface PreparedStatement {
|
|
111
|
+
/** Binds positional parameters */
|
|
112
|
+
bind(...bindings: any[]): PreparedStatement;
|
|
113
|
+
/** Executes a write-oriented statement */
|
|
114
|
+
run<T = Record<string, unknown>>(): Promise<QueryResult<T>>;
|
|
115
|
+
/** Executes a query and returns all matching rows */
|
|
116
|
+
all<T = Record<string, unknown>>(): Promise<QueryResult<T>>;
|
|
117
|
+
/** Executes a query and returns the first row */
|
|
118
|
+
first<T = Record<string, unknown>>(): Promise<T | null>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Provider-agnostic SQL database contract.
|
|
122
|
+
*/
|
|
123
|
+
export interface SQLDatabase {
|
|
124
|
+
/** Creates a prepared statement */
|
|
125
|
+
prepare(sql: string): PreparedStatement;
|
|
126
|
+
}
|
|
29
127
|
/**
|
|
30
128
|
* Available Cloudflare D1 regions for geographic optimization
|
|
31
129
|
*/
|
|
@@ -66,23 +164,28 @@ export type OperationType = 'read' | 'write';
|
|
|
66
164
|
* Environment bindings for the Cloudflare Worker
|
|
67
165
|
*/
|
|
68
166
|
export interface Env {
|
|
69
|
-
/**
|
|
70
|
-
KV:
|
|
167
|
+
/** Key-value namespace for storing primary key to shard mappings */
|
|
168
|
+
KV: KVStorage;
|
|
71
169
|
/** Durable Object binding for shard coordination */
|
|
72
170
|
ShardCoordinator: DurableObjectNamespace;
|
|
73
|
-
/**
|
|
171
|
+
/** Optional Hyperdrive binding for external SQL connectivity */
|
|
172
|
+
HYPERDRIVE?: {
|
|
173
|
+
connectionString: string;
|
|
174
|
+
localConnectionString?: string;
|
|
175
|
+
};
|
|
176
|
+
/** D1 database bindings - dynamic based on Wrangler configuration */
|
|
74
177
|
[key: string]: any;
|
|
75
178
|
}
|
|
76
179
|
/**
|
|
77
180
|
* Configuration for the collegedb sharded database
|
|
78
181
|
*/
|
|
79
182
|
export interface CollegeDBConfig {
|
|
80
|
-
/**
|
|
81
|
-
kv:
|
|
183
|
+
/** Key-value provider for storing shard mappings */
|
|
184
|
+
kv: KVStorage;
|
|
82
185
|
/** Shard coordinator Durable Object */
|
|
83
186
|
coordinator?: DurableObjectNamespace;
|
|
84
|
-
/** Available
|
|
85
|
-
shards: Record<string,
|
|
187
|
+
/** Available SQL shard providers */
|
|
188
|
+
shards: Record<string, SQLDatabase>;
|
|
86
189
|
/** Default shard allocation strategy (can be single strategy or mixed strategy object) */
|
|
87
190
|
strategy?: ShardingStrategy | MixedShardingStrategy;
|
|
88
191
|
/** Target region for location-based sharding */
|
|
@@ -109,12 +212,38 @@ export interface CollegeDBConfig {
|
|
|
109
212
|
*/
|
|
110
213
|
debug?: boolean;
|
|
111
214
|
/**
|
|
112
|
-
* Maximum database size in bytes.
|
|
113
|
-
* from new allocations (existing mappings remain intact).
|
|
114
|
-
*
|
|
215
|
+
* Maximum database size in bytes. When set, shards that exceed this size are
|
|
216
|
+
* excluded from new allocations (existing mappings remain intact).
|
|
217
|
+
*
|
|
218
|
+
* When omitted, size-based filtering is disabled to avoid extra sizing queries.
|
|
219
|
+
* This significantly reduces routing latency for write-heavy workloads.
|
|
115
220
|
* @since 1.0.8
|
|
116
221
|
*/
|
|
117
222
|
maxDatabaseSize?: number;
|
|
223
|
+
/**
|
|
224
|
+
* In-memory TTL for primary key to shard mapping cache.
|
|
225
|
+
* @default 30000
|
|
226
|
+
* @since 1.1.0
|
|
227
|
+
*/
|
|
228
|
+
mappingCacheTtlMs?: number;
|
|
229
|
+
/**
|
|
230
|
+
* In-memory TTL for known shard list cache.
|
|
231
|
+
* @default 10000
|
|
232
|
+
* @since 1.1.0
|
|
233
|
+
*/
|
|
234
|
+
knownShardsCacheTtlMs?: number;
|
|
235
|
+
/**
|
|
236
|
+
* In-memory TTL for shard size checks when `maxDatabaseSize` is enabled.
|
|
237
|
+
* @default 30000
|
|
238
|
+
* @since 1.1.0
|
|
239
|
+
*/
|
|
240
|
+
sizeCacheTtlMs?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Concurrency limit for migration mapping operations.
|
|
243
|
+
* @default 25
|
|
244
|
+
* @since 1.1.0
|
|
245
|
+
*/
|
|
246
|
+
migrationConcurrency?: number;
|
|
118
247
|
}
|
|
119
248
|
/**
|
|
120
249
|
* Shard statistics for monitoring and load balancing
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb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,gBAAgB,GAAG,qBAAqB,CAAC;IACnD,yCAAyC;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,YAAY,CAAC,EAAE,QAAQ,CAAC;IACxB,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC/C"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.1.1",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist/**/*",
|
|
10
10
|
"README.md",
|
|
@@ -21,30 +21,54 @@
|
|
|
21
21
|
"test": "vitest run",
|
|
22
22
|
"test:watch": "vitest",
|
|
23
23
|
"test:coverage": "vitest run --coverage",
|
|
24
|
+
"test:sandbox": "bun scripts/sandbox/run.ts --db=all --kv=all --include-cloudflare",
|
|
25
|
+
"test:sandbox:all": "bun scripts/sandbox/run.ts --db=all --kv=all",
|
|
26
|
+
"test:sandbox:cloudflare": "bun scripts/sandbox/run.ts --cloudflare-only",
|
|
27
|
+
"test:sandbox:postgres": "bun scripts/sandbox/run.ts --db=postgres --kv=all",
|
|
28
|
+
"test:sandbox:mysql": "bun scripts/sandbox/run.ts --db=mysql --kv=all",
|
|
29
|
+
"test:sandbox:mariadb": "bun scripts/sandbox/run.ts --db=mariadb --kv=all",
|
|
30
|
+
"test:sandbox:sqlite": "bun scripts/sandbox/run.ts --db=sqlite --kv=all",
|
|
31
|
+
"test:sandbox:drizzle": "bun scripts/sandbox/run.ts --db=all --kv=all --profile=drizzle",
|
|
32
|
+
"test:sandbox:nuxthub": "bun scripts/sandbox/run.ts --db=all --kv=all --profile=nuxthub",
|
|
33
|
+
"test:sandbox:hyperdrive": "bun scripts/sandbox/run.ts --db=all --kv=all --profile=hyperdrive",
|
|
34
|
+
"test:sandbox:redis": "bun scripts/sandbox/run.ts --db=all --kv=redis",
|
|
35
|
+
"test:sandbox:valkey": "bun scripts/sandbox/run.ts --db=all --kv=valkey",
|
|
36
|
+
"test:sandbox:postgres+redis": "bun scripts/sandbox/run.ts --db=postgres --kv=redis",
|
|
37
|
+
"test:sandbox:postgres+valkey": "bun scripts/sandbox/run.ts --db=postgres --kv=valkey",
|
|
38
|
+
"test:sandbox:mysql+redis": "bun scripts/sandbox/run.ts --db=mysql --kv=redis",
|
|
39
|
+
"test:sandbox:mysql+valkey": "bun scripts/sandbox/run.ts --db=mysql --kv=valkey",
|
|
40
|
+
"test:sandbox:mariadb+redis": "bun scripts/sandbox/run.ts --db=mariadb --kv=redis",
|
|
41
|
+
"test:sandbox:mariadb+valkey": "bun scripts/sandbox/run.ts --db=mariadb --kv=valkey",
|
|
42
|
+
"test:sandbox:sqlite+redis": "bun scripts/sandbox/run.ts --db=sqlite --kv=redis",
|
|
43
|
+
"test:sandbox:sqlite+valkey": "bun scripts/sandbox/run.ts --db=sqlite --kv=valkey",
|
|
24
44
|
"prepare": "husky install"
|
|
25
45
|
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@cloudflare/workers-types": "^4.20250726.0"
|
|
28
|
-
},
|
|
29
46
|
"devDependencies": {
|
|
30
|
-
"@babel/cli": "^7.28.
|
|
31
|
-
"@babel/core": "^7.
|
|
32
|
-
"@babel/preset-env": "^7.
|
|
33
|
-
"@babel/preset-typescript": "^7.
|
|
47
|
+
"@babel/cli": "^7.28.6",
|
|
48
|
+
"@babel/core": "^7.29.0",
|
|
49
|
+
"@babel/preset-env": "^7.29.2",
|
|
50
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
51
|
+
"@cloudflare/workers-types": "^4.20260415.1",
|
|
34
52
|
"@types/bun": "latest",
|
|
35
|
-
"@
|
|
53
|
+
"@types/pg": "^8.15.6",
|
|
54
|
+
"@vitest/coverage-v8": "^4.1.4",
|
|
55
|
+
"drizzle-orm": "^0.45.2",
|
|
36
56
|
"husky": "^9.1.7",
|
|
37
57
|
"jsdoc-babel": "^0.5.0",
|
|
38
|
-
"lint-staged": "^16.
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
58
|
+
"lint-staged": "^16.4.0",
|
|
59
|
+
"mysql2": "^3.15.3",
|
|
60
|
+
"pg": "^8.16.3",
|
|
61
|
+
"prettier": "^3.8.3",
|
|
62
|
+
"prettier-plugin-organize-imports": "4.3.0",
|
|
63
|
+
"redis": "^5.8.2",
|
|
64
|
+
"typedoc": "^0.28.19",
|
|
65
|
+
"vitest": "^4.1.4",
|
|
66
|
+
"wrangler": "^4.64.0"
|
|
43
67
|
},
|
|
44
68
|
"peerDependencies": {
|
|
45
|
-
"typescript": "^5"
|
|
69
|
+
"typescript": "^5.8.3"
|
|
46
70
|
},
|
|
47
71
|
"lint-staged": {
|
|
48
|
-
"*.{js,ts,css,md}": "prettier --write"
|
|
72
|
+
"*.{js,ts,css,md,json,yml,jsonc}": "prettier --write"
|
|
49
73
|
}
|
|
50
74
|
}
|