gitx.do 0.0.1 → 0.0.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.
Files changed (237) hide show
  1. package/dist/cli/commands/blame.d.ts +259 -0
  2. package/dist/cli/commands/blame.d.ts.map +1 -0
  3. package/dist/cli/commands/blame.js +609 -0
  4. package/dist/cli/commands/blame.js.map +1 -0
  5. package/dist/cli/commands/branch.d.ts +249 -0
  6. package/dist/cli/commands/branch.d.ts.map +1 -0
  7. package/dist/cli/commands/branch.js +693 -0
  8. package/dist/cli/commands/branch.js.map +1 -0
  9. package/dist/cli/commands/commit.d.ts +182 -0
  10. package/dist/cli/commands/commit.d.ts.map +1 -0
  11. package/dist/cli/commands/commit.js +437 -0
  12. package/dist/cli/commands/commit.js.map +1 -0
  13. package/dist/cli/commands/diff.d.ts +464 -0
  14. package/dist/cli/commands/diff.d.ts.map +1 -0
  15. package/dist/cli/commands/diff.js +958 -0
  16. package/dist/cli/commands/diff.js.map +1 -0
  17. package/dist/cli/commands/log.d.ts +239 -0
  18. package/dist/cli/commands/log.d.ts.map +1 -0
  19. package/dist/cli/commands/log.js +535 -0
  20. package/dist/cli/commands/log.js.map +1 -0
  21. package/dist/cli/commands/review.d.ts +457 -0
  22. package/dist/cli/commands/review.d.ts.map +1 -0
  23. package/dist/cli/commands/review.js +533 -0
  24. package/dist/cli/commands/review.js.map +1 -0
  25. package/dist/cli/commands/status.d.ts +269 -0
  26. package/dist/cli/commands/status.d.ts.map +1 -0
  27. package/dist/cli/commands/status.js +493 -0
  28. package/dist/cli/commands/status.js.map +1 -0
  29. package/dist/cli/commands/web.d.ts +199 -0
  30. package/dist/cli/commands/web.d.ts.map +1 -0
  31. package/dist/cli/commands/web.js +696 -0
  32. package/dist/cli/commands/web.js.map +1 -0
  33. package/dist/cli/fs-adapter.d.ts +656 -0
  34. package/dist/cli/fs-adapter.d.ts.map +1 -0
  35. package/dist/cli/fs-adapter.js +1179 -0
  36. package/dist/cli/fs-adapter.js.map +1 -0
  37. package/dist/cli/index.d.ts +387 -0
  38. package/dist/cli/index.d.ts.map +1 -0
  39. package/dist/cli/index.js +523 -0
  40. package/dist/cli/index.js.map +1 -0
  41. package/dist/cli/ui/components/DiffView.d.ts +7 -0
  42. package/dist/cli/ui/components/DiffView.d.ts.map +1 -0
  43. package/dist/cli/ui/components/DiffView.js +11 -0
  44. package/dist/cli/ui/components/DiffView.js.map +1 -0
  45. package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -0
  46. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -0
  47. package/dist/cli/ui/components/ErrorDisplay.js +11 -0
  48. package/dist/cli/ui/components/ErrorDisplay.js.map +1 -0
  49. package/dist/cli/ui/components/FuzzySearch.d.ts +9 -0
  50. package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -0
  51. package/dist/cli/ui/components/FuzzySearch.js +12 -0
  52. package/dist/cli/ui/components/FuzzySearch.js.map +1 -0
  53. package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -0
  54. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -0
  55. package/dist/cli/ui/components/LoadingSpinner.js +10 -0
  56. package/dist/cli/ui/components/LoadingSpinner.js.map +1 -0
  57. package/dist/cli/ui/components/NavigationList.d.ts +9 -0
  58. package/dist/cli/ui/components/NavigationList.d.ts.map +1 -0
  59. package/dist/cli/ui/components/NavigationList.js +11 -0
  60. package/dist/cli/ui/components/NavigationList.js.map +1 -0
  61. package/dist/cli/ui/components/ScrollableContent.d.ts +8 -0
  62. package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -0
  63. package/dist/cli/ui/components/ScrollableContent.js +11 -0
  64. package/dist/cli/ui/components/ScrollableContent.js.map +1 -0
  65. package/dist/cli/ui/components/index.d.ts +7 -0
  66. package/dist/cli/ui/components/index.d.ts.map +1 -0
  67. package/dist/cli/ui/components/index.js +9 -0
  68. package/dist/cli/ui/components/index.js.map +1 -0
  69. package/dist/cli/ui/terminal-ui.d.ts +52 -0
  70. package/dist/cli/ui/terminal-ui.d.ts.map +1 -0
  71. package/dist/cli/ui/terminal-ui.js +121 -0
  72. package/dist/cli/ui/terminal-ui.js.map +1 -0
  73. package/dist/durable-object/object-store.d.ts +401 -23
  74. package/dist/durable-object/object-store.d.ts.map +1 -1
  75. package/dist/durable-object/object-store.js +414 -25
  76. package/dist/durable-object/object-store.js.map +1 -1
  77. package/dist/durable-object/schema.d.ts +188 -0
  78. package/dist/durable-object/schema.d.ts.map +1 -1
  79. package/dist/durable-object/schema.js +160 -0
  80. package/dist/durable-object/schema.js.map +1 -1
  81. package/dist/durable-object/wal.d.ts +336 -31
  82. package/dist/durable-object/wal.d.ts.map +1 -1
  83. package/dist/durable-object/wal.js +272 -27
  84. package/dist/durable-object/wal.js.map +1 -1
  85. package/dist/index.d.ts +379 -3
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +379 -7
  88. package/dist/index.js.map +1 -1
  89. package/dist/mcp/adapter.d.ts +579 -38
  90. package/dist/mcp/adapter.d.ts.map +1 -1
  91. package/dist/mcp/adapter.js +426 -33
  92. package/dist/mcp/adapter.js.map +1 -1
  93. package/dist/mcp/sandbox.d.ts +532 -29
  94. package/dist/mcp/sandbox.d.ts.map +1 -1
  95. package/dist/mcp/sandbox.js +389 -22
  96. package/dist/mcp/sandbox.js.map +1 -1
  97. package/dist/mcp/sdk-adapter.d.ts +478 -56
  98. package/dist/mcp/sdk-adapter.d.ts.map +1 -1
  99. package/dist/mcp/sdk-adapter.js +346 -44
  100. package/dist/mcp/sdk-adapter.js.map +1 -1
  101. package/dist/mcp/tools.d.ts +445 -30
  102. package/dist/mcp/tools.d.ts.map +1 -1
  103. package/dist/mcp/tools.js +363 -33
  104. package/dist/mcp/tools.js.map +1 -1
  105. package/dist/ops/blame.d.ts +424 -21
  106. package/dist/ops/blame.d.ts.map +1 -1
  107. package/dist/ops/blame.js +303 -20
  108. package/dist/ops/blame.js.map +1 -1
  109. package/dist/ops/branch.d.ts +583 -32
  110. package/dist/ops/branch.d.ts.map +1 -1
  111. package/dist/ops/branch.js +365 -23
  112. package/dist/ops/branch.js.map +1 -1
  113. package/dist/ops/commit-traversal.d.ts +164 -24
  114. package/dist/ops/commit-traversal.d.ts.map +1 -1
  115. package/dist/ops/commit-traversal.js +68 -2
  116. package/dist/ops/commit-traversal.js.map +1 -1
  117. package/dist/ops/commit.d.ts +387 -53
  118. package/dist/ops/commit.d.ts.map +1 -1
  119. package/dist/ops/commit.js +249 -29
  120. package/dist/ops/commit.js.map +1 -1
  121. package/dist/ops/merge-base.d.ts +195 -21
  122. package/dist/ops/merge-base.d.ts.map +1 -1
  123. package/dist/ops/merge-base.js +122 -12
  124. package/dist/ops/merge-base.js.map +1 -1
  125. package/dist/ops/merge.d.ts +600 -130
  126. package/dist/ops/merge.d.ts.map +1 -1
  127. package/dist/ops/merge.js +408 -60
  128. package/dist/ops/merge.js.map +1 -1
  129. package/dist/ops/tag.d.ts +67 -2
  130. package/dist/ops/tag.d.ts.map +1 -1
  131. package/dist/ops/tag.js +42 -1
  132. package/dist/ops/tag.js.map +1 -1
  133. package/dist/ops/tree-builder.d.ts +102 -6
  134. package/dist/ops/tree-builder.d.ts.map +1 -1
  135. package/dist/ops/tree-builder.js +30 -5
  136. package/dist/ops/tree-builder.js.map +1 -1
  137. package/dist/ops/tree-diff.d.ts +50 -2
  138. package/dist/ops/tree-diff.d.ts.map +1 -1
  139. package/dist/ops/tree-diff.js +50 -2
  140. package/dist/ops/tree-diff.js.map +1 -1
  141. package/dist/pack/delta.d.ts +211 -39
  142. package/dist/pack/delta.d.ts.map +1 -1
  143. package/dist/pack/delta.js +232 -46
  144. package/dist/pack/delta.js.map +1 -1
  145. package/dist/pack/format.d.ts +390 -28
  146. package/dist/pack/format.d.ts.map +1 -1
  147. package/dist/pack/format.js +344 -33
  148. package/dist/pack/format.js.map +1 -1
  149. package/dist/pack/full-generation.d.ts +313 -28
  150. package/dist/pack/full-generation.d.ts.map +1 -1
  151. package/dist/pack/full-generation.js +238 -19
  152. package/dist/pack/full-generation.js.map +1 -1
  153. package/dist/pack/generation.d.ts +346 -23
  154. package/dist/pack/generation.d.ts.map +1 -1
  155. package/dist/pack/generation.js +269 -21
  156. package/dist/pack/generation.js.map +1 -1
  157. package/dist/pack/index.d.ts +407 -86
  158. package/dist/pack/index.d.ts.map +1 -1
  159. package/dist/pack/index.js +351 -70
  160. package/dist/pack/index.js.map +1 -1
  161. package/dist/refs/branch.d.ts +517 -71
  162. package/dist/refs/branch.d.ts.map +1 -1
  163. package/dist/refs/branch.js +410 -26
  164. package/dist/refs/branch.js.map +1 -1
  165. package/dist/refs/storage.d.ts +610 -57
  166. package/dist/refs/storage.d.ts.map +1 -1
  167. package/dist/refs/storage.js +481 -29
  168. package/dist/refs/storage.js.map +1 -1
  169. package/dist/refs/tag.d.ts +677 -67
  170. package/dist/refs/tag.d.ts.map +1 -1
  171. package/dist/refs/tag.js +497 -30
  172. package/dist/refs/tag.js.map +1 -1
  173. package/dist/storage/lru-cache.d.ts +556 -53
  174. package/dist/storage/lru-cache.d.ts.map +1 -1
  175. package/dist/storage/lru-cache.js +439 -36
  176. package/dist/storage/lru-cache.js.map +1 -1
  177. package/dist/storage/object-index.d.ts +483 -38
  178. package/dist/storage/object-index.d.ts.map +1 -1
  179. package/dist/storage/object-index.js +388 -22
  180. package/dist/storage/object-index.js.map +1 -1
  181. package/dist/storage/r2-pack.d.ts +957 -94
  182. package/dist/storage/r2-pack.d.ts.map +1 -1
  183. package/dist/storage/r2-pack.js +756 -48
  184. package/dist/storage/r2-pack.js.map +1 -1
  185. package/dist/tiered/cdc-pipeline.d.ts +1610 -38
  186. package/dist/tiered/cdc-pipeline.d.ts.map +1 -1
  187. package/dist/tiered/cdc-pipeline.js +1131 -22
  188. package/dist/tiered/cdc-pipeline.js.map +1 -1
  189. package/dist/tiered/migration.d.ts +903 -41
  190. package/dist/tiered/migration.d.ts.map +1 -1
  191. package/dist/tiered/migration.js +646 -24
  192. package/dist/tiered/migration.js.map +1 -1
  193. package/dist/tiered/parquet-writer.d.ts +944 -47
  194. package/dist/tiered/parquet-writer.d.ts.map +1 -1
  195. package/dist/tiered/parquet-writer.js +667 -39
  196. package/dist/tiered/parquet-writer.js.map +1 -1
  197. package/dist/tiered/read-path.d.ts +728 -34
  198. package/dist/tiered/read-path.d.ts.map +1 -1
  199. package/dist/tiered/read-path.js +310 -27
  200. package/dist/tiered/read-path.js.map +1 -1
  201. package/dist/types/objects.d.ts +457 -0
  202. package/dist/types/objects.d.ts.map +1 -1
  203. package/dist/types/objects.js +305 -4
  204. package/dist/types/objects.js.map +1 -1
  205. package/dist/types/storage.d.ts +407 -35
  206. package/dist/types/storage.d.ts.map +1 -1
  207. package/dist/types/storage.js +27 -3
  208. package/dist/types/storage.js.map +1 -1
  209. package/dist/utils/hash.d.ts +133 -12
  210. package/dist/utils/hash.d.ts.map +1 -1
  211. package/dist/utils/hash.js +133 -12
  212. package/dist/utils/hash.js.map +1 -1
  213. package/dist/utils/sha1.d.ts +102 -9
  214. package/dist/utils/sha1.d.ts.map +1 -1
  215. package/dist/utils/sha1.js +114 -11
  216. package/dist/utils/sha1.js.map +1 -1
  217. package/dist/wire/capabilities.d.ts +896 -88
  218. package/dist/wire/capabilities.d.ts.map +1 -1
  219. package/dist/wire/capabilities.js +566 -62
  220. package/dist/wire/capabilities.js.map +1 -1
  221. package/dist/wire/pkt-line.d.ts +293 -15
  222. package/dist/wire/pkt-line.d.ts.map +1 -1
  223. package/dist/wire/pkt-line.js +251 -15
  224. package/dist/wire/pkt-line.js.map +1 -1
  225. package/dist/wire/receive-pack.d.ts +814 -64
  226. package/dist/wire/receive-pack.d.ts.map +1 -1
  227. package/dist/wire/receive-pack.js +542 -41
  228. package/dist/wire/receive-pack.js.map +1 -1
  229. package/dist/wire/smart-http.d.ts +575 -97
  230. package/dist/wire/smart-http.d.ts.map +1 -1
  231. package/dist/wire/smart-http.js +337 -46
  232. package/dist/wire/smart-http.js.map +1 -1
  233. package/dist/wire/upload-pack.d.ts +492 -98
  234. package/dist/wire/upload-pack.d.ts.map +1 -1
  235. package/dist/wire/upload-pack.js +347 -59
  236. package/dist/wire/upload-pack.js.map +1 -1
  237. package/package.json +10 -2
@@ -1,110 +1,415 @@
1
+ /**
2
+ * @fileoverview Write-Ahead Log (WAL) Manager for Transaction Durability
3
+ *
4
+ * This module provides a Write-Ahead Log implementation for ensuring durability
5
+ * and crash recovery in the Git object storage. All operations are logged before
6
+ * being applied, allowing recovery after failures.
7
+ *
8
+ * **Key Features**:
9
+ * - Transaction support with begin/commit/rollback semantics
10
+ * - Checkpoint creation for efficient recovery
11
+ * - WAL truncation after successful checkpoints
12
+ * - Unflushed entry recovery for crash recovery
13
+ *
14
+ * @module durable-object/wal
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { WALManager } from './durable-object/wal'
19
+ *
20
+ * const wal = new WALManager(storage)
21
+ *
22
+ * // Simple operation logging
23
+ * const entryId = await wal.append('PUT', payload)
24
+ *
25
+ * // Transaction support
26
+ * const txId = await wal.beginTransaction()
27
+ * await wal.append('PUT', payload1, txId)
28
+ * await wal.append('PUT', payload2, txId)
29
+ * await wal.commitTransaction(txId)
30
+ *
31
+ * // Create checkpoint for recovery point
32
+ * const checkpoint = await wal.createCheckpoint()
33
+ * ```
34
+ */
1
35
  import { DurableObjectStorage } from './schema';
2
36
  /**
3
- * WAL Operation Types
37
+ * Types of operations that can be logged to the WAL.
38
+ *
39
+ * @description
40
+ * - `PUT`: Object creation or update
41
+ * - `DELETE`: Object deletion
42
+ * - `UPDATE`: Object modification
43
+ * - `BATCH`: Multiple operations grouped together
44
+ * - `TX_BEGIN`: Transaction start marker
45
+ * - `TX_COMMIT`: Transaction commit marker
46
+ * - `TX_ROLLBACK`: Transaction rollback marker
4
47
  */
5
48
  export type WALOperationType = 'PUT' | 'DELETE' | 'UPDATE' | 'BATCH' | 'TX_BEGIN' | 'TX_COMMIT' | 'TX_ROLLBACK';
6
49
  /**
7
- * Transaction States
50
+ * Possible states for a transaction.
51
+ *
52
+ * @description
53
+ * - `ACTIVE`: Transaction is in progress
54
+ * - `COMMITTED`: Transaction has been committed successfully
55
+ * - `ROLLED_BACK`: Transaction has been rolled back
8
56
  */
9
57
  export type TransactionState = 'ACTIVE' | 'COMMITTED' | 'ROLLED_BACK';
10
58
  /**
11
- * WAL Entry representing a single logged operation
59
+ * A single entry in the Write-Ahead Log.
60
+ *
61
+ * @description
62
+ * Represents one logged operation with its metadata.
63
+ * Entries are ordered by ID for replay during recovery.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const entry: WALEntry = {
68
+ * id: 42,
69
+ * operation: 'PUT',
70
+ * payload: new Uint8Array([...]),
71
+ * transactionId: 'tx-abc123',
72
+ * createdAt: 1704067200000,
73
+ * flushed: false
74
+ * }
75
+ * ```
12
76
  */
13
77
  export interface WALEntry {
78
+ /** Unique sequential ID for ordering */
14
79
  id: number;
80
+ /** Type of operation logged */
15
81
  operation: WALOperationType;
82
+ /** Binary payload containing operation details */
16
83
  payload: Uint8Array;
84
+ /** Transaction ID if part of a transaction, null otherwise */
17
85
  transactionId: string | null;
86
+ /** Unix timestamp (milliseconds) when entry was created */
18
87
  createdAt: number;
88
+ /** Whether this entry has been flushed (persisted durably) */
19
89
  flushed: boolean;
20
90
  }
21
91
  /**
22
- * Transaction metadata
92
+ * Transaction metadata tracking state and operations.
93
+ *
94
+ * @description
95
+ * Tracks the state of a transaction and all operations performed within it.
96
+ * Used for commit/rollback logic and recovery.
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const tx: Transaction = {
101
+ * id: 'tx-abc123',
102
+ * state: 'ACTIVE',
103
+ * startedAt: 1704067200000,
104
+ * operations: [42, 43, 44] // WAL entry IDs
105
+ * }
106
+ * ```
23
107
  */
24
108
  export interface Transaction {
109
+ /** Unique transaction identifier */
25
110
  id: string;
111
+ /** Current state of the transaction */
26
112
  state: TransactionState;
113
+ /** Unix timestamp (milliseconds) when transaction started */
27
114
  startedAt: number;
115
+ /** Array of WAL entry IDs belonging to this transaction */
28
116
  operations: number[];
29
117
  }
30
118
  /**
31
- * Checkpoint representing a consistent point in the WAL
119
+ * A checkpoint representing a consistent point in the WAL.
120
+ *
121
+ * @description
122
+ * Checkpoints mark points where all prior operations have been
123
+ * successfully applied. They enable efficient recovery by allowing
124
+ * truncation of old WAL entries.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const checkpoint: Checkpoint = {
129
+ * id: 5,
130
+ * walPosition: 150, // All entries up to 150 are committed
131
+ * createdAt: 1704067200000,
132
+ * metadata: 'Daily checkpoint'
133
+ * }
134
+ * ```
32
135
  */
33
136
  export interface Checkpoint {
137
+ /** Unique checkpoint ID */
34
138
  id: number;
139
+ /** WAL position (entry ID) at checkpoint creation */
35
140
  walPosition: number;
141
+ /** Unix timestamp (milliseconds) when checkpoint was created */
36
142
  createdAt: number;
143
+ /** Optional descriptive metadata */
37
144
  metadata: string | null;
38
145
  }
39
146
  /**
40
- * WALManager - Write-Ahead Log Manager for transaction durability
147
+ * Write-Ahead Log Manager for transaction durability.
41
148
  *
149
+ * @description
42
150
  * Provides durability guarantees by logging all operations before they are applied.
43
151
  * Supports transactions with begin/commit/rollback semantics and checkpoint management.
152
+ *
153
+ * **Usage Pattern**:
154
+ * 1. Log operations using `append()` before applying them
155
+ * 2. Use transactions for atomic multi-operation changes
156
+ * 3. Create checkpoints periodically for efficient recovery
157
+ * 4. Truncate WAL after successful checkpoints
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const wal = new WALManager(storage)
162
+ *
163
+ * // Single operation
164
+ * const payload = new TextEncoder().encode(JSON.stringify({ sha: 'abc123' }))
165
+ * const id = await wal.append('PUT', payload)
166
+ *
167
+ * // Transaction
168
+ * const txId = await wal.beginTransaction()
169
+ * try {
170
+ * await wal.append('PUT', payload1, txId)
171
+ * await wal.append('PUT', payload2, txId)
172
+ * await wal.commitTransaction(txId)
173
+ * } catch (e) {
174
+ * await wal.rollbackTransaction(txId)
175
+ * throw e
176
+ * }
177
+ *
178
+ * // Checkpoint and cleanup
179
+ * const checkpoint = await wal.createCheckpoint()
180
+ * await wal.truncateBeforeCheckpoint(checkpoint)
181
+ * ```
44
182
  */
45
183
  export declare class WALManager {
184
+ /** Durable Object storage interface */
46
185
  private storage;
186
+ /** In-memory transaction tracking */
47
187
  private transactions;
188
+ /** Current WAL position for entry ID assignment */
48
189
  private currentWalPosition;
190
+ /**
191
+ * Create a new WALManager.
192
+ *
193
+ * @param storage - Durable Object storage interface with SQL support
194
+ */
49
195
  constructor(storage: DurableObjectStorage);
50
196
  /**
51
- * Append an operation to the WAL
52
- * @param operation The type of operation
53
- * @param payload The operation payload as binary data
54
- * @param transactionId Optional transaction ID to associate with this operation
197
+ * Append an operation to the WAL.
198
+ *
199
+ * @description
200
+ * Logs an operation to the WAL before it is applied. Operations can
201
+ * optionally be associated with a transaction for atomic commit/rollback.
202
+ *
203
+ * @param operation - The type of operation being logged
204
+ * @param payload - Binary data describing the operation (usually JSON-encoded)
205
+ * @param transactionId - Optional transaction ID to associate with this operation
55
206
  * @returns The ID of the appended WAL entry
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * // Simple append
211
+ * const payload = new TextEncoder().encode(JSON.stringify({
212
+ * sha: 'abc123',
213
+ * type: 'blob',
214
+ * timestamp: Date.now()
215
+ * }))
216
+ * const entryId = await wal.append('PUT', payload)
217
+ *
218
+ * // Append within transaction
219
+ * const txId = await wal.beginTransaction()
220
+ * await wal.append('PUT', payload, txId)
221
+ * ```
56
222
  */
57
223
  append(operation: WALOperationType, payload: Uint8Array, transactionId?: string): Promise<number>;
58
224
  /**
59
- * Flush all unflushed WAL entries
60
- * @returns The number of entries flushed
225
+ * Flush all unflushed WAL entries.
226
+ *
227
+ * @description
228
+ * Marks all unflushed entries as flushed, indicating they have been
229
+ * durably persisted. This is typically called before creating a checkpoint.
230
+ *
231
+ * @returns The number of entries that were flushed
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const count = await wal.flush()
236
+ * console.log(`Flushed ${count} entries`)
237
+ * ```
61
238
  */
62
239
  flush(): Promise<number>;
63
240
  /**
64
- * Recover unflushed WAL entries for replay
65
- * @returns Array of unflushed WAL entries in order
241
+ * Recover unflushed WAL entries for replay.
242
+ *
243
+ * @description
244
+ * Returns all unflushed WAL entries in order for replay during
245
+ * crash recovery. Entries should be replayed in order by ID.
246
+ *
247
+ * @returns Array of unflushed WAL entries sorted by ID
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const entries = await wal.recover()
252
+ * for (const entry of entries) {
253
+ * console.log(`Replaying ${entry.operation} ${entry.id}`)
254
+ * // Apply the operation...
255
+ * }
256
+ * ```
66
257
  */
67
258
  recover(): Promise<WALEntry[]>;
68
259
  /**
69
- * Begin a new transaction
70
- * @returns The transaction ID
260
+ * Begin a new transaction.
261
+ *
262
+ * @description
263
+ * Starts a new transaction and returns its ID. Operations appended
264
+ * with this transaction ID will be atomically committed or rolled back.
265
+ *
266
+ * @returns The unique transaction ID
267
+ *
268
+ * @example
269
+ * ```typescript
270
+ * const txId = await wal.beginTransaction()
271
+ * try {
272
+ * await wal.append('PUT', payload1, txId)
273
+ * await wal.append('DELETE', payload2, txId)
274
+ * await wal.commitTransaction(txId)
275
+ * } catch (e) {
276
+ * await wal.rollbackTransaction(txId)
277
+ * }
278
+ * ```
71
279
  */
72
280
  beginTransaction(): Promise<string>;
73
281
  /**
74
- * Commit a transaction
75
- * @param transactionId The transaction ID to commit
282
+ * Commit a transaction.
283
+ *
284
+ * @description
285
+ * Commits all operations in the transaction, making them permanent.
286
+ * After commit, the transaction cannot be rolled back.
287
+ *
288
+ * @param transactionId - The transaction ID to commit
289
+ * @throws Error if transaction not found or not active
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * const txId = await wal.beginTransaction()
294
+ * await wal.append('PUT', payload, txId)
295
+ * await wal.commitTransaction(txId)
296
+ * // Transaction is now committed
297
+ * ```
76
298
  */
77
299
  commitTransaction(transactionId: string): Promise<void>;
78
300
  /**
79
- * Rollback a transaction
80
- * @param transactionId The transaction ID to rollback
301
+ * Rollback a transaction.
302
+ *
303
+ * @description
304
+ * Rolls back all operations in the transaction, undoing their effects.
305
+ * After rollback, the transaction is marked as rolled back.
306
+ *
307
+ * @param transactionId - The transaction ID to rollback
308
+ * @throws Error if transaction not found or not active
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * const txId = await wal.beginTransaction()
313
+ * try {
314
+ * await wal.append('PUT', payload, txId)
315
+ * throw new Error('Something went wrong')
316
+ * } catch (e) {
317
+ * await wal.rollbackTransaction(txId)
318
+ * // All operations in transaction are undone
319
+ * }
320
+ * ```
81
321
  */
82
322
  rollbackTransaction(transactionId: string): Promise<void>;
83
323
  /**
84
- * Get the state of a transaction
85
- * @param transactionId The transaction ID
86
- * @returns The transaction state or null if not found
324
+ * Get the state of a transaction.
325
+ *
326
+ * @description
327
+ * Returns the current state of a transaction, checking both in-memory
328
+ * cache and persistent storage.
329
+ *
330
+ * @param transactionId - The transaction ID to check
331
+ * @returns Transaction state or null if not found
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * const state = await wal.getTransactionState(txId)
336
+ * if (state === 'COMMITTED') {
337
+ * console.log('Transaction was committed')
338
+ * }
339
+ * ```
87
340
  */
88
341
  getTransactionState(transactionId: string): Promise<TransactionState | null>;
89
342
  /**
90
- * Create a checkpoint at the current WAL position
91
- * @param metadata Optional metadata to associate with the checkpoint
343
+ * Create a checkpoint at the current WAL position.
344
+ *
345
+ * @description
346
+ * Creates a checkpoint marking a consistent point where all prior
347
+ * operations have been successfully applied. Flushes pending entries first.
348
+ *
349
+ * @param metadata - Optional descriptive metadata for the checkpoint
92
350
  * @returns The created checkpoint
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * // Create checkpoint after batch of operations
355
+ * const checkpoint = await wal.createCheckpoint('Post-push checkpoint')
356
+ * console.log(`Checkpoint at position ${checkpoint.walPosition}`)
357
+ * ```
93
358
  */
94
359
  createCheckpoint(metadata?: string): Promise<Checkpoint>;
95
360
  /**
96
- * Get the most recent checkpoint
97
- * @returns The last checkpoint or null if none exist
361
+ * Get the most recent checkpoint.
362
+ *
363
+ * @description
364
+ * Returns the last checkpoint created, or null if none exist.
365
+ * Useful for determining where to start recovery.
366
+ *
367
+ * @returns The last checkpoint or null
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const lastCheckpoint = await wal.getLastCheckpoint()
372
+ * if (lastCheckpoint) {
373
+ * console.log(`Last checkpoint at position ${lastCheckpoint.walPosition}`)
374
+ * }
375
+ * ```
98
376
  */
99
377
  getLastCheckpoint(): Promise<Checkpoint | null>;
100
378
  /**
101
- * Truncate WAL entries before a checkpoint
102
- * @param checkpoint The checkpoint to truncate before
379
+ * Truncate WAL entries before a checkpoint.
380
+ *
381
+ * @description
382
+ * Removes all WAL entries before (and including) the checkpoint position
383
+ * that have been flushed. This reclaims space after a successful checkpoint.
384
+ *
385
+ * **Note**: Only truncates flushed entries to avoid data loss.
386
+ *
387
+ * @param checkpoint - The checkpoint to truncate before
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * const checkpoint = await wal.createCheckpoint()
392
+ * // After verifying all operations are applied...
393
+ * await wal.truncateBeforeCheckpoint(checkpoint)
394
+ * ```
103
395
  */
104
396
  truncateBeforeCheckpoint(checkpoint: Checkpoint): Promise<void>;
105
397
  /**
106
- * Get the count of unflushed WAL entries
107
- * @returns The number of unflushed entries
398
+ * Get the count of unflushed WAL entries.
399
+ *
400
+ * @description
401
+ * Returns the number of WAL entries that have not yet been flushed.
402
+ * Useful for monitoring WAL growth and deciding when to flush.
403
+ *
404
+ * @returns Number of unflushed entries
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * const count = await wal.getUnflushedCount()
409
+ * if (count > 1000) {
410
+ * await wal.flush()
411
+ * }
412
+ * ```
108
413
  */
109
414
  getUnflushedCount(): Promise<number>;
110
415
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wal.d.ts","sourceRoot":"","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