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,208 +1,761 @@
1
1
  /**
2
- * Git Reference Storage
2
+ * @fileoverview Git Reference Storage System
3
3
  *
4
- * Handles storage and resolution of Git refs (branches, tags, HEAD).
5
- * Supports both loose refs and packed refs formats.
4
+ * This module provides a complete implementation of Git reference management,
5
+ * including branches, tags, HEAD, and symbolic refs. It supports both loose refs
6
+ * (individual files) and packed refs (consolidated file).
7
+ *
8
+ * **Key Concepts**:
9
+ * - **Direct refs**: Point directly to a SHA-1 hash (e.g., branch pointing to commit)
10
+ * - **Symbolic refs**: Point to another ref (e.g., HEAD -> refs/heads/main)
11
+ * - **Loose refs**: Individual ref files in .git/refs/
12
+ * - **Packed refs**: Consolidated refs in .git/packed-refs for efficiency
13
+ *
14
+ * @module refs/storage
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { RefStorage, isValidRefName, isValidSha } from './refs/storage'
19
+ *
20
+ * // Create storage with backend
21
+ * const storage = new RefStorage(backend)
22
+ *
23
+ * // Resolve HEAD to get current commit
24
+ * const resolved = await storage.resolveRef('HEAD')
25
+ * console.log(`Current commit: ${resolved.sha}`)
26
+ *
27
+ * // Update a branch
28
+ * await storage.updateRef('refs/heads/feature', newCommitSha, { create: true })
29
+ *
30
+ * // List all branches
31
+ * const branches = await storage.listBranches()
32
+ * ```
33
+ */
34
+ /**
35
+ * Type discriminator for reference types.
36
+ *
37
+ * @description
38
+ * - `direct`: Points directly to a SHA-1 hash
39
+ * - `symbolic`: Points to another ref name (follows chain on resolution)
6
40
  */
7
41
  export type RefType = 'direct' | 'symbolic';
8
42
  /**
9
- * Represents a Git reference (branch, tag, HEAD, etc.)
43
+ * Represents a Git reference (branch, tag, HEAD, etc.).
44
+ *
45
+ * @description
46
+ * References are named pointers in Git. They can point directly to objects
47
+ * (like commits) or symbolically to other refs.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Direct ref (branch pointing to commit)
52
+ * const branch: Ref = {
53
+ * name: 'refs/heads/main',
54
+ * target: 'abc123def456...',
55
+ * type: 'direct'
56
+ * }
57
+ *
58
+ * // Symbolic ref (HEAD pointing to branch)
59
+ * const head: Ref = {
60
+ * name: 'HEAD',
61
+ * target: 'refs/heads/main',
62
+ * type: 'symbolic'
63
+ * }
64
+ * ```
10
65
  */
11
66
  export interface Ref {
12
67
  /** Full ref name (e.g., 'refs/heads/main', 'HEAD') */
13
68
  name: string;
14
- /** Target - either a SHA-1 hash (direct) or another ref name (symbolic) */
69
+ /** Target - SHA-1 hash for direct refs, ref name for symbolic refs */
15
70
  target: string;
16
- /** Type of reference */
71
+ /** Whether this is a direct or symbolic reference */
17
72
  type: RefType;
18
73
  }
19
74
  /**
20
- * Options for updating a ref
75
+ * Options for updating a reference.
76
+ *
77
+ * @description
78
+ * Provides control over ref update behavior including atomic operations
79
+ * (compare-and-swap), creation, and force updates.
21
80
  */
22
81
  export interface UpdateRefOptions {
23
- /** If true, create the ref if it doesn't exist */
82
+ /** If true, create the ref if it doesn't exist (default: false) */
24
83
  create?: boolean;
25
- /** Expected old value for CAS (compare-and-swap) */
84
+ /**
85
+ * Expected old value for compare-and-swap (CAS) operation.
86
+ * - `null`: Expect ref to NOT exist (atomic create)
87
+ * - SHA string: Expect ref to have this exact value
88
+ * - undefined: No CAS check
89
+ */
26
90
  oldValue?: string | null;
27
- /** Force update even if not a fast-forward */
91
+ /** Force update even if not a fast-forward (for branch updates) */
28
92
  force?: boolean;
29
- /** Reason for the update (for reflog) */
93
+ /** Reason for the update (stored in reflog if implemented) */
30
94
  reason?: string;
31
- /** If provided, use this lock instead of acquiring a new one */
95
+ /** Use an existing lock instead of acquiring a new one */
32
96
  lock?: RefLock;
33
97
  }
34
98
  /**
35
- * Options for listing refs
99
+ * Options for listing references.
100
+ *
101
+ * @description
102
+ * Controls which refs are included in listing operations.
36
103
  */
37
104
  export interface ListRefsOptions {
38
- /** Pattern to filter refs (e.g., 'refs/heads/*') */
105
+ /** Glob pattern to filter refs (e.g., 'refs/heads/*', 'refs/tags/v*') */
39
106
  pattern?: string;
40
- /** Include HEAD in the listing */
107
+ /** Include HEAD in the listing (default: false) */
41
108
  includeHead?: boolean;
42
- /** Include symbolic refs */
109
+ /** Include symbolic refs in the listing (default: false) */
43
110
  includeSymbolic?: boolean;
44
111
  }
45
112
  /**
46
- * Options for resolving refs
113
+ * Options for resolving references.
47
114
  */
48
115
  export interface ResolveRefOptions {
49
- /** Maximum depth for following symbolic refs (default: 10) */
116
+ /**
117
+ * Maximum depth for following symbolic refs (default: 10).
118
+ * Prevents infinite loops from circular refs.
119
+ */
50
120
  maxDepth?: number;
51
121
  }
52
122
  /**
53
- * Result of a ref resolution
123
+ * Result of resolving a reference.
124
+ *
125
+ * @description
126
+ * Contains the resolved SHA and the chain of refs followed during resolution.
127
+ * Useful for understanding ref structure and debugging.
54
128
  */
55
129
  export interface ResolvedRef {
56
130
  /** The original ref that was resolved */
57
131
  ref: Ref;
58
132
  /** The final SHA-1 target after following all symbolic refs */
59
133
  sha: string;
60
- /** Chain of refs followed during resolution */
134
+ /** Chain of refs followed during resolution (for debugging/display) */
61
135
  chain: Ref[];
62
136
  }
63
137
  /**
64
- * Error thrown when a ref operation fails
138
+ * Error thrown when a ref operation fails.
139
+ *
140
+ * @description
141
+ * Provides structured error information including error code
142
+ * and the ref name that caused the error.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * try {
147
+ * await storage.updateRef('refs/heads/main', sha)
148
+ * } catch (e) {
149
+ * if (e instanceof RefError) {
150
+ * switch (e.code) {
151
+ * case 'NOT_FOUND': // Ref doesn't exist
152
+ * case 'CONFLICT': // CAS failed
153
+ * case 'LOCKED': // Ref is locked
154
+ * }
155
+ * }
156
+ * }
157
+ * ```
65
158
  */
66
159
  export declare class RefError extends Error {
67
160
  readonly code: RefErrorCode;
68
161
  readonly refName?: string | undefined;
162
+ /**
163
+ * Create a new RefError.
164
+ *
165
+ * @param message - Human-readable error message
166
+ * @param code - Error code for programmatic handling
167
+ * @param refName - The ref that caused the error (optional)
168
+ */
69
169
  constructor(message: string, code: RefErrorCode, refName?: string | undefined);
70
170
  }
171
+ /**
172
+ * Error codes for ref operations.
173
+ *
174
+ * @description
175
+ * - `NOT_FOUND`: Ref doesn't exist
176
+ * - `ALREADY_EXISTS`: Ref already exists (when creating)
177
+ * - `INVALID_NAME`: Ref name fails validation
178
+ * - `LOCKED`: Another process holds the ref lock
179
+ * - `CONFLICT`: CAS operation failed (value changed)
180
+ * - `CIRCULAR_REF`: Symbolic ref chain loops back on itself
181
+ * - `MAX_DEPTH_EXCEEDED`: Too many symbolic ref redirects
182
+ * - `INVALID_SHA`: SHA format is invalid
183
+ */
71
184
  export type RefErrorCode = 'NOT_FOUND' | 'ALREADY_EXISTS' | 'INVALID_NAME' | 'LOCKED' | 'CONFLICT' | 'CIRCULAR_REF' | 'MAX_DEPTH_EXCEEDED' | 'INVALID_SHA';
72
185
  /**
73
- * Lock handle for ref updates
186
+ * Lock handle for atomic ref updates.
187
+ *
188
+ * @description
189
+ * Ref locks prevent concurrent modifications to the same ref.
190
+ * Always release locks when done, preferably in a finally block.
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * const lock = await storage.acquireLock('refs/heads/main')
195
+ * try {
196
+ * const ref = await storage.getRef('refs/heads/main')
197
+ * // ... modify and write ref ...
198
+ * } finally {
199
+ * await lock.release()
200
+ * }
201
+ * ```
74
202
  */
75
203
  export interface RefLock {
76
204
  /** The ref being locked */
77
205
  refName: string;
78
- /** Release the lock */
206
+ /** Release the lock - should be idempotent */
79
207
  release(): Promise<void>;
80
- /** Check if lock is still held */
208
+ /** Check if this lock is still held by us */
81
209
  isHeld(): boolean;
82
210
  }
83
211
  /**
84
- * Storage backend interface for refs
212
+ * Storage backend interface for refs.
213
+ *
214
+ * @description
215
+ * Implement this interface to provide ref storage.
216
+ * The backend is responsible for persistence, locking, and packed refs.
85
217
  */
86
218
  export interface RefStorageBackend {
87
- /** Read a single ref */
219
+ /**
220
+ * Read a single ref from storage.
221
+ *
222
+ * @param name - Full ref name
223
+ * @returns The ref or null if not found
224
+ */
88
225
  readRef(name: string): Promise<Ref | null>;
89
- /** Write a ref */
226
+ /**
227
+ * Write a ref to storage.
228
+ *
229
+ * @param ref - The ref to write
230
+ */
90
231
  writeRef(ref: Ref): Promise<void>;
91
- /** Delete a ref */
232
+ /**
233
+ * Delete a ref from storage.
234
+ *
235
+ * @param name - Full ref name
236
+ * @returns True if deleted, false if not found
237
+ */
92
238
  deleteRef(name: string): Promise<boolean>;
93
- /** List all refs matching a pattern */
239
+ /**
240
+ * List all refs matching a pattern.
241
+ *
242
+ * @param pattern - Optional glob pattern
243
+ * @returns Array of matching refs
244
+ */
94
245
  listRefs(pattern?: string): Promise<Ref[]>;
95
- /** Acquire a lock on a ref */
246
+ /**
247
+ * Acquire an exclusive lock on a ref.
248
+ *
249
+ * @param name - Full ref name
250
+ * @param timeout - Lock acquisition timeout in ms
251
+ * @returns Lock handle
252
+ * @throws RefError with code 'LOCKED' if lock cannot be acquired
253
+ */
96
254
  acquireLock(name: string, timeout?: number): Promise<RefLock>;
97
- /** Read packed refs */
255
+ /**
256
+ * Read packed refs file.
257
+ *
258
+ * @returns Map of ref names to SHA values
259
+ */
98
260
  readPackedRefs(): Promise<Map<string, string>>;
99
- /** Write packed refs */
261
+ /**
262
+ * Write packed refs file.
263
+ *
264
+ * @param refs - Map of ref names to SHA values
265
+ */
100
266
  writePackedRefs(refs: Map<string, string>): Promise<void>;
101
267
  }
102
268
  /**
103
- * Validate a ref name according to Git rules
104
- * See: https://git-scm.com/docs/git-check-ref-format
269
+ * Validate a ref name according to Git rules.
270
+ *
271
+ * @description
272
+ * Git has specific rules for valid ref names. This function implements
273
+ * the validation from `git check-ref-format`.
274
+ *
275
+ * **Rules**:
276
+ * - Cannot be empty or just '@'
277
+ * - Cannot end with '/' or '.lock'
278
+ * - Cannot contain '..', '@{', control chars, space, ~, ^, :, ?, *, [, \
279
+ * - Components cannot start or end with '.'
280
+ * - HEAD is always valid
281
+ *
282
+ * @param name - Ref name to validate
283
+ * @returns True if the name is valid
284
+ *
285
+ * @see https://git-scm.com/docs/git-check-ref-format
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * isValidRefName('refs/heads/main') // true
290
+ * isValidRefName('refs/heads/feature/x') // true
291
+ * isValidRefName('HEAD') // true
292
+ * isValidRefName('refs/heads/../main') // false (contains ..)
293
+ * isValidRefName('refs/heads/.hidden') // false (component starts with .)
294
+ * isValidRefName('refs/heads/foo.lock') // false (ends with .lock)
295
+ * ```
105
296
  */
106
297
  export declare function isValidRefName(name: string): boolean;
107
298
  /**
108
- * Validate a SHA-1 hash
299
+ * Validate a SHA-1 hash string.
300
+ *
301
+ * @description
302
+ * SHA-1 hashes must be exactly 40 hexadecimal characters.
303
+ * This validates the format, not whether the object exists.
304
+ *
305
+ * @param sha - SHA string to validate
306
+ * @returns True if the string is a valid SHA-1 format
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * isValidSha('abc123def456789...') // true (if 40 hex chars)
311
+ * isValidSha('abc123') // false (too short)
312
+ * isValidSha('xyz...') // false (invalid hex)
313
+ * isValidSha(null) // false
314
+ * ```
109
315
  */
110
316
  export declare function isValidSha(sha: string): boolean;
111
317
  /**
112
- * Parse a ref file content
318
+ * Parse ref file content into type and target.
319
+ *
320
+ * @description
321
+ * Ref files either contain a SHA directly or "ref: <target>" for symbolic refs.
322
+ *
323
+ * @param content - Raw ref file content
324
+ * @returns Parsed type and target
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * // Direct ref
329
+ * parseRefContent('abc123def456...\n')
330
+ * // => { type: 'direct', target: 'abc123def456...' }
331
+ *
332
+ * // Symbolic ref
333
+ * parseRefContent('ref: refs/heads/main\n')
334
+ * // => { type: 'symbolic', target: 'refs/heads/main' }
335
+ * ```
113
336
  */
114
337
  export declare function parseRefContent(content: string): {
115
338
  type: RefType;
116
339
  target: string;
117
340
  };
118
341
  /**
119
- * Serialize a ref to file content
342
+ * Serialize a ref to file content format.
343
+ *
344
+ * @description
345
+ * Converts a Ref object to the string format stored in ref files.
346
+ *
347
+ * @param ref - Ref to serialize
348
+ * @returns File content string (with trailing newline)
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * serializeRefContent({ name: 'HEAD', target: 'refs/heads/main', type: 'symbolic' })
353
+ * // => 'ref: refs/heads/main\n'
354
+ *
355
+ * serializeRefContent({ name: 'refs/heads/main', target: 'abc123...', type: 'direct' })
356
+ * // => 'abc123...\n'
357
+ * ```
120
358
  */
121
359
  export declare function serializeRefContent(ref: Ref): string;
122
360
  /**
123
- * Parse packed-refs file content
361
+ * Parse packed-refs file content.
362
+ *
363
+ * @description
364
+ * The packed-refs file contains multiple refs in a space-efficient format.
365
+ * Format: "<sha> <refname>" on each line, with optional comments (#) and
366
+ * peeled entries (^sha for annotated tags).
367
+ *
368
+ * @param content - Raw packed-refs file content
369
+ * @returns Map of ref names to SHA values
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * const content = `# pack-refs with: peeled fully-peeled sorted
374
+ * abc123 refs/heads/main
375
+ * def456 refs/tags/v1.0.0
376
+ * ^aaa111
377
+ * `
378
+ * const refs = parsePackedRefs(content)
379
+ * // Map { 'refs/heads/main' => 'abc123', 'refs/tags/v1.0.0' => 'def456' }
380
+ * ```
124
381
  */
125
382
  export declare function parsePackedRefs(content: string): Map<string, string>;
126
383
  /**
127
- * Serialize refs to packed-refs format
384
+ * Serialize refs to packed-refs file format.
385
+ *
386
+ * @description
387
+ * Creates the content for a packed-refs file from a map of refs.
388
+ * Refs are sorted alphabetically for consistency.
389
+ *
390
+ * @param refs - Map of ref names to SHA values
391
+ * @returns Packed-refs file content
392
+ *
393
+ * @example
394
+ * ```typescript
395
+ * const refs = new Map([
396
+ * ['refs/heads/main', 'abc123...'],
397
+ * ['refs/tags/v1.0.0', 'def456...']
398
+ * ])
399
+ * const content = serializePackedRefs(refs)
400
+ * // '# pack-refs with: peeled fully-peeled sorted\nabc123... refs/heads/main\n...'
401
+ * ```
128
402
  */
129
403
  export declare function serializePackedRefs(refs: Map<string, string>): string;
130
404
  /**
131
- * Ref storage implementation
405
+ * Reference storage manager.
406
+ *
407
+ * @description
408
+ * Provides a high-level API for managing Git references. Handles ref
409
+ * resolution, updates with locking, symbolic refs, and packed refs.
410
+ *
411
+ * @example
412
+ * ```typescript
413
+ * const storage = new RefStorage(myBackend)
414
+ *
415
+ * // Get current branch
416
+ * const head = await storage.getHead()
417
+ * if (head.type === 'symbolic') {
418
+ * console.log(`On branch: ${head.target}`)
419
+ * }
420
+ *
421
+ * // Resolve to SHA
422
+ * const resolved = await storage.resolveRef('HEAD')
423
+ * console.log(`Current commit: ${resolved.sha}`)
424
+ *
425
+ * // Create a branch
426
+ * await storage.updateRef('refs/heads/feature', commitSha, { create: true })
427
+ * ```
132
428
  */
133
429
  export declare class RefStorage {
134
430
  private backend;
431
+ /**
432
+ * Create a new RefStorage instance.
433
+ *
434
+ * @param backend - Storage backend for persistence
435
+ */
135
436
  constructor(backend: RefStorageBackend);
136
437
  /**
137
- * Get a ref by name
438
+ * Get a ref by name.
439
+ *
440
+ * @description
441
+ * Retrieves a ref without resolving symbolic refs.
442
+ * Use `resolveRef` to follow symbolic refs to their final target.
443
+ *
444
+ * @param name - Full ref name
445
+ * @returns The ref or null if not found
446
+ * @throws Error if backend doesn't support readRef
447
+ *
448
+ * @example
449
+ * ```typescript
450
+ * const head = await storage.getRef('HEAD')
451
+ * if (head && head.type === 'symbolic') {
452
+ * console.log(`HEAD points to ${head.target}`)
453
+ * }
454
+ * ```
138
455
  */
139
456
  getRef(name: string): Promise<Ref | null>;
140
457
  /**
141
- * Resolve a ref to its final SHA target
458
+ * Resolve a ref to its final SHA target.
459
+ *
460
+ * @description
461
+ * Follows symbolic refs until reaching a direct ref, then returns
462
+ * the SHA and the chain of refs followed.
463
+ *
464
+ * @param name - Ref name to resolve
465
+ * @param options - Resolution options (maxDepth)
466
+ * @returns Resolved ref with SHA and chain
467
+ * @throws RefError with code 'NOT_FOUND' if ref doesn't exist
468
+ * @throws RefError with code 'CIRCULAR_REF' if circular reference detected
469
+ * @throws RefError with code 'MAX_DEPTH_EXCEEDED' if too many redirects
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * const resolved = await storage.resolveRef('HEAD')
474
+ * console.log(`SHA: ${resolved.sha}`)
475
+ * console.log(`Chain: ${resolved.chain.map(r => r.name).join(' -> ')}`)
476
+ * // Chain: HEAD -> refs/heads/main
477
+ * ```
142
478
  */
143
479
  resolveRef(name: string, options?: ResolveRefOptions): Promise<ResolvedRef>;
144
480
  /**
145
- * Update or create a ref
481
+ * Update or create a ref.
482
+ *
483
+ * @description
484
+ * Creates a new ref or updates an existing one. Supports atomic
485
+ * compare-and-swap operations via oldValue option.
146
486
  *
147
487
  * Note: For atomic operations, callers can acquire a lock via acquireLock()
148
488
  * and pass it via options.lock to avoid double-locking.
489
+ *
490
+ * @param name - Full ref name
491
+ * @param target - SHA-1 hash to point to
492
+ * @param options - Update options (create, oldValue, force, lock)
493
+ * @returns The updated/created ref
494
+ * @throws RefError with code 'INVALID_NAME' if ref name is invalid
495
+ * @throws RefError with code 'INVALID_SHA' if SHA format is invalid
496
+ * @throws RefError with code 'ALREADY_EXISTS' if creating and ref exists
497
+ * @throws RefError with code 'CONFLICT' if oldValue doesn't match
498
+ * @throws RefError with code 'NOT_FOUND' if ref doesn't exist and not creating
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * // Create a new branch
503
+ * await storage.updateRef('refs/heads/feature', sha, { create: true })
504
+ *
505
+ * // Atomic update (fails if someone else modified)
506
+ * await storage.updateRef('refs/heads/main', newSha, { oldValue: currentSha })
507
+ *
508
+ * // Force update (skips fast-forward check)
509
+ * await storage.updateRef('refs/heads/main', sha, { force: true })
510
+ * ```
149
511
  */
150
512
  updateRef(name: string, target: string, options?: UpdateRefOptions): Promise<Ref>;
151
513
  /**
152
- * Delete a ref
514
+ * Delete a ref.
515
+ *
516
+ * @description
517
+ * Removes a ref from storage. HEAD cannot be deleted.
518
+ *
519
+ * @param name - Full ref name to delete
520
+ * @param options - Delete options (oldValue for CAS)
521
+ * @returns True if deleted, false if ref didn't exist
522
+ * @throws RefError with code 'INVALID_NAME' for HEAD or invalid names
523
+ * @throws RefError with code 'CONFLICT' if oldValue doesn't match
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * // Simple delete
528
+ * const deleted = await storage.deleteRef('refs/heads/old-branch')
529
+ *
530
+ * // Atomic delete (only if value matches)
531
+ * await storage.deleteRef('refs/heads/feature', { oldValue: expectedSha })
532
+ * ```
153
533
  */
154
534
  deleteRef(name: string, options?: UpdateRefOptions): Promise<boolean>;
155
535
  /**
156
- * List refs matching a pattern
536
+ * List refs matching a pattern.
537
+ *
538
+ * @description
539
+ * Returns refs filtered by pattern and options.
540
+ * By default, excludes HEAD and symbolic refs.
541
+ *
542
+ * @param options - Listing options (pattern, includeHead, includeSymbolic)
543
+ * @returns Array of matching refs
544
+ *
545
+ * @example
546
+ * ```typescript
547
+ * // List all refs
548
+ * const all = await storage.listRefs()
549
+ *
550
+ * // List branches only
551
+ * const branches = await storage.listRefs({ pattern: 'refs/heads/*' })
552
+ *
553
+ * // Include HEAD
554
+ * const withHead = await storage.listRefs({ includeHead: true })
555
+ * ```
157
556
  */
158
557
  listRefs(options?: ListRefsOptions): Promise<Ref[]>;
159
558
  /**
160
- * List all branches
559
+ * List all branches.
560
+ *
561
+ * @description
562
+ * Convenience method to list refs under refs/heads/.
563
+ *
564
+ * @returns Array of branch refs
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * const branches = await storage.listBranches()
569
+ * for (const branch of branches) {
570
+ * console.log(branch.name.replace('refs/heads/', ''))
571
+ * }
572
+ * ```
161
573
  */
162
574
  listBranches(): Promise<Ref[]>;
163
575
  /**
164
- * List all tags
576
+ * List all tags.
577
+ *
578
+ * @description
579
+ * Convenience method to list refs under refs/tags/.
580
+ *
581
+ * @returns Array of tag refs
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * const tags = await storage.listTags()
586
+ * for (const tag of tags) {
587
+ * console.log(tag.name.replace('refs/tags/', ''))
588
+ * }
589
+ * ```
165
590
  */
166
591
  listTags(): Promise<Ref[]>;
167
592
  /**
168
- * Get HEAD ref
593
+ * Get HEAD ref.
594
+ *
595
+ * @description
596
+ * Returns the HEAD ref. Every repository should have HEAD.
597
+ *
598
+ * @returns The HEAD ref
599
+ * @throws RefError with code 'NOT_FOUND' if HEAD doesn't exist
600
+ *
601
+ * @example
602
+ * ```typescript
603
+ * const head = await storage.getHead()
604
+ * if (head.type === 'symbolic') {
605
+ * console.log(`On branch: ${head.target}`)
606
+ * } else {
607
+ * console.log(`Detached at: ${head.target}`)
608
+ * }
609
+ * ```
169
610
  */
170
611
  getHead(): Promise<Ref>;
171
612
  /**
172
- * Update HEAD (can be symbolic or detached)
613
+ * Update HEAD (can be symbolic or detached).
614
+ *
615
+ * @description
616
+ * Sets HEAD to point to a branch (symbolic) or commit (detached).
617
+ *
618
+ * @param target - Branch ref name (symbolic) or SHA (detached)
619
+ * @param symbolic - If true, create symbolic ref; if false, direct ref
620
+ * @returns The updated HEAD ref
621
+ *
622
+ * @example
623
+ * ```typescript
624
+ * // Switch to branch
625
+ * await storage.updateHead('refs/heads/main', true)
626
+ *
627
+ * // Detach HEAD at commit
628
+ * await storage.updateHead(commitSha, false)
629
+ * ```
173
630
  */
174
631
  updateHead(target: string, symbolic?: boolean): Promise<Ref>;
175
632
  /**
176
- * Check if HEAD is detached
633
+ * Check if HEAD is detached.
634
+ *
635
+ * @description
636
+ * HEAD is detached when it points directly to a commit SHA
637
+ * rather than symbolically to a branch.
638
+ *
639
+ * @returns True if HEAD is detached (points to SHA directly)
640
+ *
641
+ * @example
642
+ * ```typescript
643
+ * if (await storage.isHeadDetached()) {
644
+ * console.log('You are in detached HEAD state')
645
+ * }
646
+ * ```
177
647
  */
178
648
  isHeadDetached(): Promise<boolean>;
179
649
  /**
180
- * Create a symbolic ref
650
+ * Create a symbolic ref.
651
+ *
652
+ * @description
653
+ * Creates a ref that points to another ref name (not a SHA).
654
+ * Used primarily for HEAD pointing to a branch.
655
+ *
656
+ * @param name - Name for the new symbolic ref
657
+ * @param target - Target ref name (not SHA)
658
+ * @returns The created symbolic ref
659
+ * @throws RefError with code 'INVALID_NAME' if name is invalid
660
+ * @throws RefError with code 'CIRCULAR_REF' if name equals target
661
+ *
662
+ * @example
663
+ * ```typescript
664
+ * // Make HEAD point to main branch
665
+ * await storage.createSymbolicRef('HEAD', 'refs/heads/main')
666
+ * ```
181
667
  */
182
668
  createSymbolicRef(name: string, target: string): Promise<Ref>;
183
669
  /**
184
- * Acquire a lock for updating a ref
670
+ * Acquire a lock for updating a ref.
671
+ *
672
+ * @description
673
+ * Acquires an exclusive lock on a ref. Use this for complex operations
674
+ * that need to read-modify-write atomically.
675
+ *
676
+ * @param name - Full ref name to lock
677
+ * @param timeout - Lock acquisition timeout in milliseconds
678
+ * @returns Lock handle - must be released when done
679
+ *
680
+ * @example
681
+ * ```typescript
682
+ * const lock = await storage.acquireLock('refs/heads/main', 5000)
683
+ * try {
684
+ * // Perform atomic operations
685
+ * await storage.updateRef('refs/heads/main', sha, { lock })
686
+ * } finally {
687
+ * await lock.release()
688
+ * }
689
+ * ```
185
690
  */
186
691
  acquireLock(name: string, timeout?: number): Promise<RefLock>;
187
692
  /**
188
- * Pack loose refs into packed-refs file
693
+ * Pack loose refs into packed-refs file.
694
+ *
695
+ * @description
696
+ * Consolidates loose ref files into a single packed-refs file.
697
+ * This improves performance for repositories with many refs.
698
+ * HEAD and symbolic refs are not packed.
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * // After creating many branches/tags
703
+ * await storage.packRefs()
704
+ * ```
189
705
  */
190
706
  packRefs(): Promise<void>;
191
707
  }
192
708
  /**
193
- * Resolve a ref to its final SHA target (convenience function)
709
+ * Resolve a ref to its final SHA target.
710
+ *
711
+ * @description
712
+ * Convenience function that wraps RefStorage.resolveRef.
713
+ *
714
+ * @param storage - RefStorage instance
715
+ * @param name - Ref name to resolve
716
+ * @param options - Resolution options
717
+ * @returns The final SHA target
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * const sha = await resolveRef(storage, 'HEAD')
722
+ * ```
194
723
  */
195
724
  export declare function resolveRef(storage: RefStorage, name: string, options?: ResolveRefOptions): Promise<string>;
196
725
  /**
197
- * Update a ref (convenience function)
726
+ * Update a ref.
727
+ *
728
+ * @description
729
+ * Convenience function that wraps RefStorage.updateRef.
730
+ *
731
+ * @param storage - RefStorage instance
732
+ * @param name - Full ref name
733
+ * @param target - SHA target
734
+ * @param options - Update options
735
+ * @returns The updated ref
198
736
  */
199
737
  export declare function updateRef(storage: RefStorage, name: string, target: string, options?: UpdateRefOptions): Promise<Ref>;
200
738
  /**
201
- * Delete a ref (convenience function)
739
+ * Delete a ref.
740
+ *
741
+ * @description
742
+ * Convenience function that wraps RefStorage.deleteRef.
743
+ *
744
+ * @param storage - RefStorage instance
745
+ * @param name - Full ref name to delete
746
+ * @param options - Delete options
747
+ * @returns True if deleted
202
748
  */
203
749
  export declare function deleteRef(storage: RefStorage, name: string, options?: UpdateRefOptions): Promise<boolean>;
204
750
  /**
205
- * List refs (convenience function)
751
+ * List refs.
752
+ *
753
+ * @description
754
+ * Convenience function that wraps RefStorage.listRefs.
755
+ *
756
+ * @param storage - RefStorage instance
757
+ * @param options - Listing options
758
+ * @returns Array of refs
206
759
  */
207
760
  export declare function listRefs(storage: RefStorage, options?: ListRefsOptions): Promise<Ref[]>;
208
761
  //# sourceMappingURL=storage.d.ts.map