@earth-app/collegedb 1.1.4 → 1.2.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/README.md +259 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +6 -5
- package/dist/providers-memory.d.ts +111 -0
- package/dist/providers-memory.d.ts.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview In-memory mock providers for testing and development.
|
|
3
|
+
*
|
|
4
|
+
* This module provides lightweight, zero-dependency in-memory implementations of
|
|
5
|
+
* CollegeDB's KVStorage and SQLDatabase interfaces, perfect for:
|
|
6
|
+
*
|
|
7
|
+
* - Unit testing without external dependencies
|
|
8
|
+
* - Integration testing with multiple shard combinations
|
|
9
|
+
* - Local development and rapid iteration
|
|
10
|
+
* - Sandboxed playtesting of routing logic
|
|
11
|
+
*
|
|
12
|
+
* Both providers are suitable for Cloudflare Workers, Node.js, and Deno environments.
|
|
13
|
+
*
|
|
14
|
+
* @author CollegeDB Team
|
|
15
|
+
* @since 1.2.0
|
|
16
|
+
*/
|
|
17
|
+
import type { KVListResult, KVStorage, PreparedStatement, QueryResult, SQLDatabase } from './types';
|
|
18
|
+
/**
|
|
19
|
+
* In-memory implementation of SQLDatabase for testing.
|
|
20
|
+
*
|
|
21
|
+
* Supports basic CRUD operations without external dependencies.
|
|
22
|
+
* Suitable for unit tests, integration tests, and development.
|
|
23
|
+
*/
|
|
24
|
+
export declare class InMemorySQLDatabase implements SQLDatabase {
|
|
25
|
+
private tables;
|
|
26
|
+
private schemas;
|
|
27
|
+
private autoIncrementCounters;
|
|
28
|
+
private lastInsertRowId;
|
|
29
|
+
prepare(sql: string): PreparedStatement;
|
|
30
|
+
/**
|
|
31
|
+
* Internal method to execute a statement.
|
|
32
|
+
*/
|
|
33
|
+
executeStatement(sql: string, bindings: any[]): Promise<QueryResult<Record<string, any>>>;
|
|
34
|
+
/**
|
|
35
|
+
* Internal method to execute a query.
|
|
36
|
+
*/
|
|
37
|
+
executeQuery(sql: string, bindings: any[]): Promise<QueryResult<Record<string, any>>>;
|
|
38
|
+
private handleCreateTable;
|
|
39
|
+
private handleDropTable;
|
|
40
|
+
private handleInsert;
|
|
41
|
+
private handleUpdate;
|
|
42
|
+
private extractSetColumnName;
|
|
43
|
+
private handleDelete;
|
|
44
|
+
private handleSelect;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* In-memory implementation of KVStorage for testing.
|
|
48
|
+
*
|
|
49
|
+
* Simple key-value store with support for prefix listing and cursor-based pagination.
|
|
50
|
+
* Suitable for unit tests, integration tests, and development.
|
|
51
|
+
*/
|
|
52
|
+
export declare class InMemoryKVStorage implements KVStorage {
|
|
53
|
+
private store;
|
|
54
|
+
private expirations;
|
|
55
|
+
get<T = unknown>(key: string, type?: 'text' | 'json'): Promise<T | string | null>;
|
|
56
|
+
put(key: string, value: string, options?: {
|
|
57
|
+
expirationTtl?: number;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
delete(key: string): Promise<void>;
|
|
60
|
+
list(options?: {
|
|
61
|
+
prefix?: string;
|
|
62
|
+
cursor?: string;
|
|
63
|
+
limit?: number;
|
|
64
|
+
}): Promise<KVListResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Clear all data from the store.
|
|
67
|
+
*/
|
|
68
|
+
clear(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the current size of the store.
|
|
71
|
+
*/
|
|
72
|
+
size(): number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Factory function to create an in-memory SQL database provider.
|
|
76
|
+
*
|
|
77
|
+
* @returns InMemorySQLDatabase instance
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { createInMemorySQLProvider } from '@earth-app/collegedb';
|
|
82
|
+
*
|
|
83
|
+
* const db = createInMemorySQLProvider();
|
|
84
|
+
* initialize({
|
|
85
|
+
* kv: new InMemoryKVStorage(),
|
|
86
|
+
* shards: {
|
|
87
|
+
* 'shard-1': db,
|
|
88
|
+
* 'shard-2': db
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function createInMemorySQLProvider(): SQLDatabase;
|
|
94
|
+
/**
|
|
95
|
+
* Factory function to create an in-memory KV storage provider.
|
|
96
|
+
*
|
|
97
|
+
* @returns InMemoryKVStorage instance
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { createInMemoryKVProvider } from '@earth-app/collegedb';
|
|
102
|
+
*
|
|
103
|
+
* const kv = createInMemoryKVProvider();
|
|
104
|
+
* initialize({
|
|
105
|
+
* kv,
|
|
106
|
+
* shards: { / * ... * / }
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function createInMemoryKVProvider(): KVStorage;
|
|
111
|
+
//# sourceMappingURL=providers-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers-memory.d.ts","sourceRoot":"","sources":["../src/providers-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAsIpG;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,WAAW;IACtD,OAAO,CAAC,MAAM,CAAuD;IACrE,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,qBAAqB,CAA6B;IAC1D,OAAO,CAAC,eAAe,CAAgC;IAEvD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB;IAIvC;;OAEG;IACG,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,E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B,wBAAwB,IAAI,SAAS,CAEpD"}
|
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.2.0",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist/**/*",
|
|
10
10
|
"README.md",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"test:sandbox:mariadb+valkey": "bun scripts/sandbox/run.ts --db=mariadb --kv=valkey",
|
|
42
42
|
"test:sandbox:sqlite+redis": "bun scripts/sandbox/run.ts --db=sqlite --kv=redis",
|
|
43
43
|
"test:sandbox:sqlite+valkey": "bun scripts/sandbox/run.ts --db=sqlite --kv=valkey",
|
|
44
|
+
"test:memory": "bun sandbox/memory-example.ts",
|
|
44
45
|
"prepare": "husky install"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"drizzle-orm": "^0.45.2",
|
|
56
57
|
"husky": "^9.1.7",
|
|
57
58
|
"jsdoc-babel": "^0.5.0",
|
|
58
|
-
"lint-staged": "^
|
|
59
|
+
"lint-staged": "^17.0.0",
|
|
59
60
|
"mysql2": "^3.22.3",
|
|
60
61
|
"pg": "^8.20.0",
|
|
61
62
|
"prettier": "^3.8.3",
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"wrangler": "^4.90.0"
|
|
67
68
|
},
|
|
68
69
|
"peerDependencies": {
|
|
69
|
-
"typescript": "^5.8.3"
|
|
70
|
+
"typescript": "^5.8.3 || ^6.0.0"
|
|
70
71
|
},
|
|
71
72
|
"lint-staged": {
|
|
72
73
|
"*.{js,ts,css,md,json,yml,jsonc}": "prettier --write"
|