@yydb/light-db 0.0.0 → 0.0.10

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.
Files changed (230) hide show
  1. package/dist/api/database.d.ts +48 -0
  2. package/dist/api/database.d.ts.map +1 -0
  3. package/dist/api/database.js +120 -0
  4. package/dist/api/database.js.map +1 -0
  5. package/dist/api/index.d.ts +7 -22
  6. package/dist/api/index.d.ts.map +1 -1
  7. package/dist/api/index.js +5 -52
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/api/schema.d.ts +33 -0
  10. package/dist/api/schema.d.ts.map +1 -0
  11. package/dist/api/schema.js +80 -0
  12. package/dist/api/schema.js.map +1 -0
  13. package/dist/api/transaction.d.ts +26 -0
  14. package/dist/api/transaction.d.ts.map +1 -0
  15. package/dist/api/transaction.js +52 -0
  16. package/dist/api/transaction.js.map +1 -0
  17. package/dist/api/types.d.ts +55 -148
  18. package/dist/api/types.d.ts.map +1 -1
  19. package/dist/api/types.js +6 -5
  20. package/dist/api/types.js.map +1 -1
  21. package/dist/codec/binary.d.ts +196 -0
  22. package/dist/codec/binary.d.ts.map +1 -0
  23. package/dist/codec/binary.js +342 -0
  24. package/dist/codec/binary.js.map +1 -0
  25. package/dist/codec/checksum.d.ts +21 -0
  26. package/dist/codec/checksum.d.ts.map +1 -0
  27. package/dist/codec/checksum.js +46 -0
  28. package/dist/codec/checksum.js.map +1 -0
  29. package/dist/codec/index.d.ts +12 -0
  30. package/dist/codec/index.d.ts.map +1 -0
  31. package/dist/codec/index.js +10 -0
  32. package/dist/codec/index.js.map +1 -0
  33. package/dist/codec/page.d.ts +114 -0
  34. package/dist/codec/page.d.ts.map +1 -0
  35. package/dist/codec/page.js +225 -0
  36. package/dist/codec/page.js.map +1 -0
  37. package/dist/codec/record.d.ts +62 -0
  38. package/dist/codec/record.d.ts.map +1 -0
  39. package/dist/codec/record.js +82 -0
  40. package/dist/codec/record.js.map +1 -0
  41. package/dist/core/broadcast.d.ts +39 -0
  42. package/dist/core/broadcast.d.ts.map +1 -0
  43. package/dist/core/broadcast.js +54 -0
  44. package/dist/core/broadcast.js.map +1 -0
  45. package/dist/core/checkpoint.d.ts +23 -0
  46. package/dist/core/checkpoint.d.ts.map +1 -0
  47. package/dist/core/checkpoint.js +49 -0
  48. package/dist/core/checkpoint.js.map +1 -0
  49. package/dist/core/engine.d.ts +142 -0
  50. package/dist/core/engine.d.ts.map +1 -0
  51. package/dist/core/engine.js +304 -0
  52. package/dist/core/engine.js.map +1 -0
  53. package/dist/core/index.d.ts +17 -0
  54. package/dist/core/index.d.ts.map +1 -0
  55. package/dist/core/index.js +13 -0
  56. package/dist/core/index.js.map +1 -0
  57. package/dist/core/lease.d.ts +32 -0
  58. package/dist/core/lease.d.ts.map +1 -0
  59. package/dist/core/lease.js +81 -0
  60. package/dist/core/lease.js.map +1 -0
  61. package/dist/core/records.d.ts +49 -0
  62. package/dist/core/records.d.ts.map +1 -0
  63. package/dist/core/records.js +70 -0
  64. package/dist/core/records.js.map +1 -0
  65. package/dist/core/recovery.d.ts +43 -0
  66. package/dist/core/recovery.d.ts.map +1 -0
  67. package/dist/core/recovery.js +99 -0
  68. package/dist/core/recovery.js.map +1 -0
  69. package/dist/core/wal.d.ts +50 -0
  70. package/dist/core/wal.d.ts.map +1 -0
  71. package/dist/core/wal.js +114 -0
  72. package/dist/core/wal.js.map +1 -0
  73. package/dist/errors/index.d.ts +44 -66
  74. package/dist/errors/index.d.ts.map +1 -1
  75. package/dist/errors/index.js +43 -128
  76. package/dist/errors/index.js.map +1 -1
  77. package/dist/index.d.ts +14 -215
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +14 -724
  80. package/dist/index.js.map +1 -1
  81. package/dist/storage/StorageAdapter.d.ts +97 -0
  82. package/dist/storage/StorageAdapter.d.ts.map +1 -0
  83. package/dist/storage/StorageAdapter.js +9 -0
  84. package/dist/storage/StorageAdapter.js.map +1 -0
  85. package/dist/storage/index.d.ts +9 -8
  86. package/dist/storage/index.d.ts.map +1 -1
  87. package/dist/storage/index.js +8 -151
  88. package/dist/storage/index.js.map +1 -1
  89. package/dist/storage/indexeddb/IndexedDbStorageAdapter.d.ts +140 -0
  90. package/dist/storage/indexeddb/IndexedDbStorageAdapter.d.ts.map +1 -0
  91. package/dist/storage/indexeddb/IndexedDbStorageAdapter.js +403 -0
  92. package/dist/storage/indexeddb/IndexedDbStorageAdapter.js.map +1 -0
  93. package/dist/storage/memory/MemoryStorageAdapter.d.ts +76 -0
  94. package/dist/storage/memory/MemoryStorageAdapter.d.ts.map +1 -0
  95. package/dist/storage/memory/MemoryStorageAdapter.js +212 -0
  96. package/dist/storage/memory/MemoryStorageAdapter.js.map +1 -0
  97. package/dist/storage/opfs/OpfsStorageAdapter.d.ts +141 -0
  98. package/dist/storage/opfs/OpfsStorageAdapter.d.ts.map +1 -0
  99. package/dist/storage/opfs/OpfsStorageAdapter.js +400 -0
  100. package/dist/storage/opfs/OpfsStorageAdapter.js.map +1 -0
  101. package/package.json +48 -36
  102. package/readme.md +80 -94
  103. package/dist/api/LightDB.d.ts +0 -194
  104. package/dist/api/LightDB.d.ts.map +0 -1
  105. package/dist/api/LightDB.js +0 -299
  106. package/dist/api/LightDB.js.map +0 -1
  107. package/dist/api/Transaction.d.ts +0 -100
  108. package/dist/api/Transaction.d.ts.map +0 -1
  109. package/dist/api/Transaction.js +0 -263
  110. package/dist/api/Transaction.js.map +0 -1
  111. package/dist/collection/Collection.d.ts +0 -235
  112. package/dist/collection/Collection.d.ts.map +0 -1
  113. package/dist/collection/Collection.js +0 -671
  114. package/dist/collection/Collection.js.map +0 -1
  115. package/dist/collection/QueryBuilder.d.ts +0 -225
  116. package/dist/collection/QueryBuilder.d.ts.map +0 -1
  117. package/dist/collection/QueryBuilder.js +0 -475
  118. package/dist/collection/QueryBuilder.js.map +0 -1
  119. package/dist/collection/QueryParser.d.ts +0 -117
  120. package/dist/collection/QueryParser.d.ts.map +0 -1
  121. package/dist/collection/QueryParser.js +0 -438
  122. package/dist/collection/QueryParser.js.map +0 -1
  123. package/dist/collection/index.d.ts +0 -42
  124. package/dist/collection/index.d.ts.map +0 -1
  125. package/dist/collection/index.js +0 -41
  126. package/dist/collection/index.js.map +0 -1
  127. package/dist/collection/types.d.ts +0 -365
  128. package/dist/collection/types.d.ts.map +0 -1
  129. package/dist/collection/types.js +0 -7
  130. package/dist/collection/types.js.map +0 -1
  131. package/dist/constants/index.d.ts +0 -51
  132. package/dist/constants/index.d.ts.map +0 -1
  133. package/dist/constants/index.js +0 -68
  134. package/dist/constants/index.js.map +0 -1
  135. package/dist/indexes/BPlusTree.d.ts +0 -181
  136. package/dist/indexes/BPlusTree.d.ts.map +0 -1
  137. package/dist/indexes/BPlusTree.js +0 -528
  138. package/dist/indexes/BPlusTree.js.map +0 -1
  139. package/dist/indexes/IndexManager.d.ts +0 -236
  140. package/dist/indexes/IndexManager.d.ts.map +0 -1
  141. package/dist/indexes/IndexManager.js +0 -502
  142. package/dist/indexes/IndexManager.js.map +0 -1
  143. package/dist/indexes/PrimaryIndex.d.ts +0 -240
  144. package/dist/indexes/PrimaryIndex.d.ts.map +0 -1
  145. package/dist/indexes/PrimaryIndex.js +0 -354
  146. package/dist/indexes/PrimaryIndex.js.map +0 -1
  147. package/dist/indexes/SecondaryIndex.d.ts +0 -204
  148. package/dist/indexes/SecondaryIndex.d.ts.map +0 -1
  149. package/dist/indexes/SecondaryIndex.js +0 -480
  150. package/dist/indexes/SecondaryIndex.js.map +0 -1
  151. package/dist/indexes/errors.d.ts +0 -66
  152. package/dist/indexes/errors.d.ts.map +0 -1
  153. package/dist/indexes/errors.js +0 -117
  154. package/dist/indexes/errors.js.map +0 -1
  155. package/dist/indexes/index.d.ts +0 -52
  156. package/dist/indexes/index.d.ts.map +0 -1
  157. package/dist/indexes/index.js +0 -131
  158. package/dist/indexes/index.js.map +0 -1
  159. package/dist/indexes/types.d.ts +0 -246
  160. package/dist/indexes/types.d.ts.map +0 -1
  161. package/dist/indexes/types.js +0 -30
  162. package/dist/indexes/types.js.map +0 -1
  163. package/dist/performance/BatchWALWriter.d.ts +0 -185
  164. package/dist/performance/BatchWALWriter.d.ts.map +0 -1
  165. package/dist/performance/BatchWALWriter.js +0 -490
  166. package/dist/performance/BatchWALWriter.js.map +0 -1
  167. package/dist/performance/ColumnarStorage.d.ts +0 -138
  168. package/dist/performance/ColumnarStorage.d.ts.map +0 -1
  169. package/dist/performance/ColumnarStorage.js +0 -875
  170. package/dist/performance/ColumnarStorage.js.map +0 -1
  171. package/dist/performance/LazyQuery.d.ts +0 -307
  172. package/dist/performance/LazyQuery.d.ts.map +0 -1
  173. package/dist/performance/LazyQuery.js +0 -588
  174. package/dist/performance/LazyQuery.js.map +0 -1
  175. package/dist/performance/OptimizedBuffer.d.ts +0 -375
  176. package/dist/performance/OptimizedBuffer.d.ts.map +0 -1
  177. package/dist/performance/OptimizedBuffer.js +0 -730
  178. package/dist/performance/OptimizedBuffer.js.map +0 -1
  179. package/dist/performance/RWLock.d.ts +0 -260
  180. package/dist/performance/RWLock.d.ts.map +0 -1
  181. package/dist/performance/RWLock.js +0 -570
  182. package/dist/performance/RWLock.js.map +0 -1
  183. package/dist/performance/index.d.ts +0 -41
  184. package/dist/performance/index.d.ts.map +0 -1
  185. package/dist/performance/index.js +0 -162
  186. package/dist/performance/index.js.map +0 -1
  187. package/dist/performance/types.d.ts +0 -247
  188. package/dist/performance/types.d.ts.map +0 -1
  189. package/dist/performance/types.js +0 -26
  190. package/dist/performance/types.js.map +0 -1
  191. package/dist/storage/Checkpoint.d.ts +0 -128
  192. package/dist/storage/Checkpoint.d.ts.map +0 -1
  193. package/dist/storage/Checkpoint.js +0 -251
  194. package/dist/storage/Checkpoint.js.map +0 -1
  195. package/dist/storage/LightFile.d.ts +0 -227
  196. package/dist/storage/LightFile.d.ts.map +0 -1
  197. package/dist/storage/LightFile.js +0 -526
  198. package/dist/storage/LightFile.js.map +0 -1
  199. package/dist/storage/Recovery.d.ts +0 -172
  200. package/dist/storage/Recovery.d.ts.map +0 -1
  201. package/dist/storage/Recovery.js +0 -399
  202. package/dist/storage/Recovery.js.map +0 -1
  203. package/dist/storage/SHMFile.d.ts +0 -243
  204. package/dist/storage/SHMFile.d.ts.map +0 -1
  205. package/dist/storage/SHMFile.js +0 -436
  206. package/dist/storage/SHMFile.js.map +0 -1
  207. package/dist/storage/StorageEngine.d.ts +0 -146
  208. package/dist/storage/StorageEngine.d.ts.map +0 -1
  209. package/dist/storage/StorageEngine.js +0 -353
  210. package/dist/storage/StorageEngine.js.map +0 -1
  211. package/dist/storage/WALFile.d.ts +0 -248
  212. package/dist/storage/WALFile.d.ts.map +0 -1
  213. package/dist/storage/WALFile.js +0 -597
  214. package/dist/storage/WALFile.js.map +0 -1
  215. package/dist/types/index.d.ts +0 -220
  216. package/dist/types/index.d.ts.map +0 -1
  217. package/dist/types/index.js +0 -7
  218. package/dist/types/index.js.map +0 -1
  219. package/dist/utils/binary.d.ts +0 -271
  220. package/dist/utils/binary.d.ts.map +0 -1
  221. package/dist/utils/binary.js +0 -454
  222. package/dist/utils/binary.js.map +0 -1
  223. package/dist/utils/file.d.ts +0 -166
  224. package/dist/utils/file.d.ts.map +0 -1
  225. package/dist/utils/file.js +0 -346
  226. package/dist/utils/file.js.map +0 -1
  227. package/dist/utils/index.d.ts +0 -6
  228. package/dist/utils/index.d.ts.map +0 -1
  229. package/dist/utils/index.js +0 -39
  230. package/dist/utils/index.js.map +0 -1
package/readme.md CHANGED
@@ -1,124 +1,110 @@
1
- # LightDB Storage Engine 🚀
1
+ # `@yydb/light-db`
2
2
 
3
- A high-performance TypeScript database storage layer with WAL (Write-Ahead Logging), indexes, and transaction support.
3
+ **Light DB** is the browser edition of YYDB: a database written in pure TypeScript that stores `.yydb`-style
4
+ snapshots, WAL records and checkpoints in browser storage. It has no Node built-ins, no N-API bindings and no WASM in
5
+ its runtime path.
4
6
 
5
- ## Features ✨
7
+ ## Product relationship
6
8
 
7
- - **High Performance**: Optimized for speed with batch writing and columnar storage
8
- - **Transaction Support**: ACID-compliant operations
9
- - **Indexing**: B+ tree indexes for fast querying
10
- - **Write-Ahead Logging**: Ensures data durability
11
- - **Recovery**: Automatic recovery from crashes
12
- - **Memory-Mapped Files**: Efficient I/O operations
13
- - **TypeScript Ready**: Full TypeScript support with type definitions
9
+ | Package | Role |
10
+ |---------|------|
11
+ | `@yydb/yydb` | Node product: native Rust engine, N-API, local `.yydb` / `.yydx` files and CLI |
12
+ | `@yydb/light-db` | Browser product: pure TypeScript, OPFS / IndexedDB storage, Web APIs, same author surface |
13
+ | `@yydb/yydb-client` | Remote wire client for a running `yydb serve` |
14
14
 
15
- ## Installation 📦
15
+ ## Status
16
16
 
17
- ```bash
18
- pnpm add @yydb/light-db
19
- ```
20
-
21
- ## Quick Start 🚀
22
-
23
- ```typescript
24
- import { LightDB } from '@yydb/light-db';
17
+ Light DB is a migration of the original `LightDB.ts` engine, rebuilt around a browser-native architecture. The package
18
+ ships as a pre-1.0 release of the browser product, so the author surface may still change between patch releases.
25
19
 
26
- // Initialize the database
27
- const db = await LightDB.open('./mydb');
20
+ Current coverage:
28
21
 
29
- // Create a collection
30
- const users = db.collection('users');
22
+ - `pnpm test` runs the Node-side runner over codec, adapter and database logic (29 cases).
23
+ - `pnpm test:browser` runs the conformance suite in an installed Chrome (16 cases): OPFS persistence across reopen, WAL
24
+ recovery, checkpoint truncation, corruption detection, single-writer exclusion, transaction rollback and commit,
25
+ schema and close notifications, and two-tab lease and broadcast behaviour.
31
26
 
32
- // Insert a document
33
- await users.insert({ id: 1, name: 'John Doe', email: 'john@example.com' });
27
+ ## Usage
34
28
 
35
- // Find a document
36
- const user = await users.findOne({ id: 1 });
37
- console.log(user); // { id: 1, name: 'John Doe', email: 'john@example.com' }
29
+ ```ts
30
+ import { LightDbError, openLightDatabase } from '@yydb/light-db';
38
31
 
39
- // Update a document
40
- await users.update({ id: 1 }, { $set: { name: 'John Smith' } });
32
+ const db = await openLightDatabase('app');
41
33
 
42
- // Delete a document
43
- await users.delete({ id: 1 });
34
+ await db.ensureSchema('// @yydb-schema-version: 1\nkv users');
35
+ await db.put('user:1', new TextEncoder().encode('Ada'));
44
36
 
45
- // Close the database
37
+ const value = await db.get('user:1');
38
+ await db.checkpoint();
46
39
  await db.close();
47
40
  ```
48
41
 
49
- ## API Reference 📚
50
-
51
- ### LightDB Class
52
-
53
- #### `open(path: string): Promise<LightDB>`
54
- Opens an existing database or creates a new one at the specified path.
55
-
56
- #### `collection(name: string): Collection`
57
- Returns a collection with the given name. Creates it if it doesn't exist.
58
-
59
- #### `transaction(): Promise<Transaction>`
60
- Starts a new transaction.
61
-
62
- #### `close(): Promise<void>`
63
- Closes the database connection.
64
-
65
- ### Collection Class
42
+ Public data types are browser-native: keys and values use `Uint8Array`, databases are addressed by name rather than by
43
+ file path, and every lifecycle call is asynchronous.
66
44
 
67
- #### `insert(document: Document): Promise<void>`
68
- Inserts a new document into the collection.
45
+ ## Author surface
69
46
 
70
- #### `find(query: Query): Promise<Document[]>`
71
- Finds all documents matching the query.
47
+ ```ts
48
+ const db: LightDatabase = await openLightDatabase('app', options);
72
49
 
73
- #### `findOne(query: Query): Promise<Document | null>`
74
- Finds the first document matching the query.
75
-
76
- #### `update(query: Query, update: Update): Promise<number>`
77
- Updates documents matching the query and returns the number of updated documents.
78
-
79
- #### `delete(query: Query): Promise<number>`
80
- Deletes documents matching the query and returns the number of deleted documents.
81
-
82
- #### `createIndex(field: string): Promise<void>`
83
- Creates an index on the specified field for faster queries.
84
-
85
- ### Transaction Class
86
-
87
- #### `commit(): Promise<void>`
88
- Commits the transaction.
89
-
90
- #### `rollback(): Promise<void>`
91
- Rolls back the transaction.
92
-
93
- ## Performance Features ⚡
50
+ await db.schema();
51
+ await db.ensureSchema(document);
52
+ await db.get(key);
53
+ await db.put(key, value);
54
+ await db.delete(key);
55
+ await db.begin();
56
+ await db.commit();
57
+ await db.rollback();
58
+ await db.checkpoint();
59
+ db.stats();
60
+ await db.close();
61
+ ```
94
62
 
95
- ### Batch Writing
96
- LightDB uses batch writing to optimize disk I/O operations, significantly improving write performance for bulk operations.
63
+ `schema()` returns the persisted schema version and document. The document is the single source of truth: a second
64
+ `ensureSchema` call must pass the identical document, otherwise it fails with `yydb.schema.conflict`. Keys starting with
65
+ `__yydb__/` are reserved for the database.
97
66
 
98
- ### Columnar Storage
99
- For certain data types, LightDB uses columnar storage to reduce disk space and improve query performance.
67
+ ## Storage backends
100
68
 
101
- ### Memory-Mapped Files
102
- LightDB uses memory-mapped files for efficient I/O operations, reducing the overhead of traditional file I/O.
69
+ | Adapter | Use |
70
+ |---------|-----|
71
+ | `OpfsStorageAdapterFactory` | Default. Origin Private File System, positional reads and writes, atomic snapshot publication |
72
+ | `IndexedDbStorageAdapterFactory` | Compatibility backend for hosts without OPFS |
73
+ | `MemoryStorageBackend` | Tests and throwaway sessions |
103
74
 
104
- ## Architecture 🏗️
75
+ `StorageAdapter` is the only platform boundary. Transactions, recovery and checkpoint semantics live in `core`, so
76
+ backends implement files, not database behaviour.
105
77
 
106
- LightDB consists of several key components:
78
+ ## Concurrency
107
79
 
108
- 1. **Storage Engine**: Manages the physical storage of data
109
- 2. **WAL (Write-Ahead Log)**: Ensures data durability and supports recovery
110
- 3. **Index Manager**: Manages B+ tree indexes for fast querying
111
- 4. **Collection Layer**: Provides a document-oriented API
112
- 5. **Transaction Manager**: Handles ACID-compliant transactions
80
+ A writer holds a session-scoped `Web Locks` lease. A second tab that opens the same database fails with
81
+ `yydb.lease.unavailable` and `retryable: true` instead of silently writing alongside the first one. When a lock manager
82
+ is missing the call fails the same way; it never degrades to multiple writers.
113
83
 
114
- ## Recovery 🔄
84
+ `BroadcastChannel` carries `commit`, `schema` and `close` events so other same-origin contexts can discard stale views
85
+ and retry after the lease is released. `listenDatabaseEvents(name, handler)` subscribes without opening the database.
115
86
 
116
- LightDB automatically recovers from crashes using the WAL. When the database is opened after a crash, it replays the WAL to restore the database to a consistent state.
87
+ ## Layout
117
88
 
118
- ## Contributing 🤝
89
+ | Path | Role |
90
+ |------|------|
91
+ | `src/api/` | Public database, transaction, schema and shared types |
92
+ | `src/core/` | Records, WAL, checkpoint, recovery, writer lease and broadcast |
93
+ | `src/storage/` | `StorageAdapter` plus OPFS, IndexedDB and memory backends |
94
+ | `src/codec/` | Page, snapshot and WAL record encoding over `Uint8Array` |
95
+ | `src/errors/` | Stable `yydb.*` error codes |
119
96
 
120
- Contributions are welcome! Please feel free to submit a Pull Request.
97
+ ## Errors
121
98
 
122
- ## License 📄
99
+ | Code | Meaning |
100
+ |------|---------|
101
+ | `yydb.io` | Storage operation failed |
102
+ | `yydb.corrupt` | Persisted bytes failed validation |
103
+ | `yydb.schema.conflict` | Schema document differs from the stored one |
104
+ | `yydb.schema.invalid` | Schema document is not usable |
105
+ | `yydb.unsupported` | Host or operation is not supported |
106
+ | `yydb.session.closed` | Database or handle is closed |
107
+ | `yydb.lease.unavailable` | Writer lease is held elsewhere or Web Locks is missing (retryable) |
108
+ | `yydb.quota.exceeded` | Browser storage quota is exhausted |
123
109
 
124
- LightDB is licensed under the MPL-2.0 License. See the [LICENSE](LICENSE) file for details.
110
+ [YYDB overview](https://github.com/yy-database/yydb.rs)
@@ -1,194 +0,0 @@
1
- /**
2
- * LightDB 主类
3
- * 提供用户直接使用的接口层
4
- */
5
- import { StorageEngine } from "../storage";
6
- import { Collection } from "../collection";
7
- import type {
8
- LightDBOptions,
9
- CollectionCreateOptions,
10
- TransactionCallback,
11
- TransactionOptions,
12
- TransactionResult,
13
- DatabaseStats,
14
- DatabaseConfig,
15
- ILightDB,
16
- CollectionSchema,
17
- } from "./types";
18
- import type { CheckpointResult } from "../types";
19
- /**
20
- * LightDB 数据库实例
21
- * 提供完整的数据库操作 API
22
- */
23
- export declare class LightDB implements ILightDB {
24
- private readonly storageEngine;
25
- private readonly collections;
26
- private readonly transactionManager;
27
- private readonly options;
28
- private closed;
29
- /**
30
- * 创建 LightDB 实例
31
- * @param storageEngine 已初始化的存储引擎
32
- * @param options 配置选项
33
- */
34
- private constructor();
35
- /**
36
- * 打开数据库
37
- * 创建或打开指定路径的数据库
38
- *
39
- * @param path 数据库文件存储路径
40
- * @param options 配置选项
41
- * @returns 初始化完成的 LightDB 实例
42
- *
43
- * @example
44
- * ```typescript
45
- * const db = await LightDB.open('./data/mydb', {
46
- * dbName: 'mydb',
47
- * autoCheckpoint: true,
48
- * pageSize: 4096
49
- * });
50
- * ```
51
- */
52
- static open(path: string, options?: LightDBOptions): Promise<LightDB>;
53
- /**
54
- * 获取数据库名称
55
- */
56
- get dbName(): string;
57
- /**
58
- * 获取数据库路径
59
- */
60
- get path(): string;
61
- /**
62
- * 检查数据库是否已打开
63
- */
64
- get isOpen(): boolean;
65
- /**
66
- * 获取或创建集合
67
- * 返回类型安全的集合实例
68
- *
69
- * @param name 集合名称
70
- * @param options 集合配置选项
71
- * @returns 集合实例
72
- *
73
- * @example
74
- * ```typescript
75
- * interface User {
76
- * id: number;
77
- * name: string;
78
- * age: number;
79
- * }
80
- *
81
- * const users = db.collection<User>('users', {
82
- * name: 'users',
83
- * primaryKey: 'id',
84
- * indexes: [
85
- * { name: 'name_idx', fieldName: 'name' }
86
- * ]
87
- * });
88
- * ```
89
- */
90
- collection<T extends Record<string, unknown>>(name: string, options: CollectionCreateOptions<T>): Collection<T>;
91
- /**
92
- * 检查集合是否存在
93
- *
94
- * @param name 集合名称
95
- * @returns 集合是否存在
96
- */
97
- hasCollection(name: string): boolean;
98
- /**
99
- * 删除集合
100
- *
101
- * @param name 集合名称
102
- * @returns 是否删除成功
103
- */
104
- dropCollection(name: string): boolean;
105
- /**
106
- * 获取所有集合名称
107
- *
108
- * @returns 集合名称数组
109
- */
110
- getCollectionNames(): string[];
111
- /**
112
- * 执行事务
113
- * 支持 ACID 事务特性
114
- *
115
- * @param callback 事务回调函数
116
- * @param options 事务选项
117
- * @returns 事务执行结果
118
- *
119
- * @example
120
- * ```typescript
121
- * await db.transaction(async (tx) => {
122
- * const users = tx.collection<User>('users');
123
- * const user = await users.findOne({ id: 1 });
124
- * await users.update({ id: 1 }, { balance: user.balance - 100 });
125
- * });
126
- * ```
127
- */
128
- transaction(callback: TransactionCallback, options?: TransactionOptions): Promise<TransactionResult>;
129
- /**
130
- * 执行检查点
131
- * 将内存中的数据持久化到磁盘
132
- *
133
- * @returns 检查点执行结果
134
- */
135
- checkpoint(): Promise<CheckpointResult>;
136
- /**
137
- * 获取数据库统计信息
138
- *
139
- * @returns 数据库统计信息
140
- */
141
- getStats(): Promise<DatabaseStats>;
142
- /**
143
- * 获取数据库配置
144
- *
145
- * @returns 数据库配置信息
146
- */
147
- getConfig(): DatabaseConfig;
148
- /**
149
- * 同步数据到磁盘
150
- * 确保所有数据都已持久化
151
- */
152
- sync(): Promise<void>;
153
- /**
154
- * 关闭数据库
155
- * 释放所有资源并确保数据持久化
156
- */
157
- close(): Promise<void>;
158
- /**
159
- * 确保数据库处于打开状态
160
- */
161
- private ensureOpen;
162
- /**
163
- * 获取存储引擎(内部使用)
164
- */
165
- getStorageEngine(): StorageEngine;
166
- }
167
- /**
168
- * 定义集合 Schema 的辅助函数
169
- * 提供类型推断和 IDE 支持
170
- *
171
- * @param schema Schema 定义
172
- * @returns Schema 对象
173
- *
174
- * @example
175
- * ```typescript
176
- * const UserSchema = defineCollectionSchema({
177
- * schema: {} as User,
178
- * primaryKey: 'id',
179
- * indexes: [
180
- * { name: 'name_idx', fieldName: 'name' }
181
- * ]
182
- * });
183
- * ```
184
- */
185
- export declare function defineCollectionSchema<T extends Record<string, unknown>>(schema: CollectionSchema<T>): CollectionSchema<T>;
186
- /**
187
- * 打开数据库的便捷函数
188
- *
189
- * @param path 数据库文件存储路径
190
- * @param options 配置选项
191
- * @returns 初始化完成的 LightDB 实例
192
- */
193
- export declare function openDatabase(path: string, options?: LightDBOptions): Promise<LightDB>;
194
- //# sourceMappingURL=LightDB.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LightDB.d.ts","sourceRoot":"","sources":["../../src/api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