gitx.do 0.1.0 → 0.1.2

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 (344) hide show
  1. package/README.md +40 -353
  2. package/dist/do/logger.d.ts +50 -0
  3. package/dist/do/logger.d.ts.map +1 -0
  4. package/dist/do/logger.js +122 -0
  5. package/dist/do/logger.js.map +1 -0
  6. package/dist/{durable-object → do}/schema.d.ts +3 -3
  7. package/dist/do/schema.d.ts.map +1 -0
  8. package/dist/{durable-object → do}/schema.js +4 -3
  9. package/dist/do/schema.js.map +1 -0
  10. package/dist/do/types.d.ts +267 -0
  11. package/dist/do/types.d.ts.map +1 -0
  12. package/dist/do/types.js +62 -0
  13. package/dist/do/types.js.map +1 -0
  14. package/dist/index.d.ts +15 -415
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +31 -483
  17. package/dist/index.js.map +1 -1
  18. package/package.json +13 -21
  19. package/dist/cli/commands/add.d.ts +0 -174
  20. package/dist/cli/commands/add.d.ts.map +0 -1
  21. package/dist/cli/commands/add.js +0 -131
  22. package/dist/cli/commands/add.js.map +0 -1
  23. package/dist/cli/commands/blame.d.ts +0 -259
  24. package/dist/cli/commands/blame.d.ts.map +0 -1
  25. package/dist/cli/commands/blame.js +0 -609
  26. package/dist/cli/commands/blame.js.map +0 -1
  27. package/dist/cli/commands/branch.d.ts +0 -249
  28. package/dist/cli/commands/branch.d.ts.map +0 -1
  29. package/dist/cli/commands/branch.js +0 -693
  30. package/dist/cli/commands/branch.js.map +0 -1
  31. package/dist/cli/commands/commit.d.ts +0 -182
  32. package/dist/cli/commands/commit.d.ts.map +0 -1
  33. package/dist/cli/commands/commit.js +0 -437
  34. package/dist/cli/commands/commit.js.map +0 -1
  35. package/dist/cli/commands/diff.d.ts +0 -464
  36. package/dist/cli/commands/diff.d.ts.map +0 -1
  37. package/dist/cli/commands/diff.js +0 -958
  38. package/dist/cli/commands/diff.js.map +0 -1
  39. package/dist/cli/commands/log.d.ts +0 -239
  40. package/dist/cli/commands/log.d.ts.map +0 -1
  41. package/dist/cli/commands/log.js +0 -535
  42. package/dist/cli/commands/log.js.map +0 -1
  43. package/dist/cli/commands/merge.d.ts +0 -106
  44. package/dist/cli/commands/merge.d.ts.map +0 -1
  45. package/dist/cli/commands/merge.js +0 -55
  46. package/dist/cli/commands/merge.js.map +0 -1
  47. package/dist/cli/commands/review.d.ts +0 -457
  48. package/dist/cli/commands/review.d.ts.map +0 -1
  49. package/dist/cli/commands/review.js +0 -533
  50. package/dist/cli/commands/review.js.map +0 -1
  51. package/dist/cli/commands/status.d.ts +0 -269
  52. package/dist/cli/commands/status.d.ts.map +0 -1
  53. package/dist/cli/commands/status.js +0 -493
  54. package/dist/cli/commands/status.js.map +0 -1
  55. package/dist/cli/commands/web.d.ts +0 -199
  56. package/dist/cli/commands/web.d.ts.map +0 -1
  57. package/dist/cli/commands/web.js +0 -696
  58. package/dist/cli/commands/web.js.map +0 -1
  59. package/dist/cli/fs-adapter.d.ts +0 -656
  60. package/dist/cli/fs-adapter.d.ts.map +0 -1
  61. package/dist/cli/fs-adapter.js +0 -1179
  62. package/dist/cli/fs-adapter.js.map +0 -1
  63. package/dist/cli/fsx-cli-adapter.d.ts +0 -359
  64. package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
  65. package/dist/cli/fsx-cli-adapter.js +0 -619
  66. package/dist/cli/fsx-cli-adapter.js.map +0 -1
  67. package/dist/cli/index.d.ts +0 -387
  68. package/dist/cli/index.d.ts.map +0 -1
  69. package/dist/cli/index.js +0 -523
  70. package/dist/cli/index.js.map +0 -1
  71. package/dist/cli/ui/components/DiffView.d.ts +0 -7
  72. package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
  73. package/dist/cli/ui/components/DiffView.js +0 -11
  74. package/dist/cli/ui/components/DiffView.js.map +0 -1
  75. package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -6
  76. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
  77. package/dist/cli/ui/components/ErrorDisplay.js +0 -11
  78. package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
  79. package/dist/cli/ui/components/FuzzySearch.d.ts +0 -9
  80. package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
  81. package/dist/cli/ui/components/FuzzySearch.js +0 -12
  82. package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
  83. package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -6
  84. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
  85. package/dist/cli/ui/components/LoadingSpinner.js +0 -10
  86. package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
  87. package/dist/cli/ui/components/NavigationList.d.ts +0 -9
  88. package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
  89. package/dist/cli/ui/components/NavigationList.js +0 -11
  90. package/dist/cli/ui/components/NavigationList.js.map +0 -1
  91. package/dist/cli/ui/components/ScrollableContent.d.ts +0 -8
  92. package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
  93. package/dist/cli/ui/components/ScrollableContent.js +0 -11
  94. package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
  95. package/dist/cli/ui/components/index.d.ts +0 -7
  96. package/dist/cli/ui/components/index.d.ts.map +0 -1
  97. package/dist/cli/ui/components/index.js +0 -9
  98. package/dist/cli/ui/components/index.js.map +0 -1
  99. package/dist/cli/ui/terminal-ui.d.ts +0 -52
  100. package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
  101. package/dist/cli/ui/terminal-ui.js +0 -121
  102. package/dist/cli/ui/terminal-ui.js.map +0 -1
  103. package/dist/do/BashModule.d.ts +0 -871
  104. package/dist/do/BashModule.d.ts.map +0 -1
  105. package/dist/do/BashModule.js +0 -1143
  106. package/dist/do/BashModule.js.map +0 -1
  107. package/dist/do/FsModule.d.ts +0 -601
  108. package/dist/do/FsModule.d.ts.map +0 -1
  109. package/dist/do/FsModule.js +0 -1120
  110. package/dist/do/FsModule.js.map +0 -1
  111. package/dist/do/GitModule.d.ts +0 -635
  112. package/dist/do/GitModule.d.ts.map +0 -1
  113. package/dist/do/GitModule.js +0 -781
  114. package/dist/do/GitModule.js.map +0 -1
  115. package/dist/do/GitRepoDO.d.ts +0 -281
  116. package/dist/do/GitRepoDO.d.ts.map +0 -1
  117. package/dist/do/GitRepoDO.js +0 -479
  118. package/dist/do/GitRepoDO.js.map +0 -1
  119. package/dist/do/bash-ast.d.ts +0 -246
  120. package/dist/do/bash-ast.d.ts.map +0 -1
  121. package/dist/do/bash-ast.js +0 -888
  122. package/dist/do/bash-ast.js.map +0 -1
  123. package/dist/do/container-executor.d.ts +0 -491
  124. package/dist/do/container-executor.d.ts.map +0 -1
  125. package/dist/do/container-executor.js +0 -730
  126. package/dist/do/container-executor.js.map +0 -1
  127. package/dist/do/index.d.ts +0 -53
  128. package/dist/do/index.d.ts.map +0 -1
  129. package/dist/do/index.js +0 -91
  130. package/dist/do/index.js.map +0 -1
  131. package/dist/do/tiered-storage.d.ts +0 -403
  132. package/dist/do/tiered-storage.d.ts.map +0 -1
  133. package/dist/do/tiered-storage.js +0 -689
  134. package/dist/do/tiered-storage.js.map +0 -1
  135. package/dist/do/withBash.d.ts +0 -231
  136. package/dist/do/withBash.d.ts.map +0 -1
  137. package/dist/do/withBash.js +0 -244
  138. package/dist/do/withBash.js.map +0 -1
  139. package/dist/do/withFs.d.ts +0 -237
  140. package/dist/do/withFs.d.ts.map +0 -1
  141. package/dist/do/withFs.js +0 -387
  142. package/dist/do/withFs.js.map +0 -1
  143. package/dist/do/withGit.d.ts +0 -180
  144. package/dist/do/withGit.d.ts.map +0 -1
  145. package/dist/do/withGit.js +0 -271
  146. package/dist/do/withGit.js.map +0 -1
  147. package/dist/durable-object/object-store.d.ts +0 -633
  148. package/dist/durable-object/object-store.d.ts.map +0 -1
  149. package/dist/durable-object/object-store.js +0 -1161
  150. package/dist/durable-object/object-store.js.map +0 -1
  151. package/dist/durable-object/schema.d.ts.map +0 -1
  152. package/dist/durable-object/schema.js.map +0 -1
  153. package/dist/durable-object/wal.d.ts +0 -416
  154. package/dist/durable-object/wal.d.ts.map +0 -1
  155. package/dist/durable-object/wal.js +0 -445
  156. package/dist/durable-object/wal.js.map +0 -1
  157. package/dist/mcp/adapter.d.ts +0 -772
  158. package/dist/mcp/adapter.d.ts.map +0 -1
  159. package/dist/mcp/adapter.js +0 -895
  160. package/dist/mcp/adapter.js.map +0 -1
  161. package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
  162. package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
  163. package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
  164. package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
  165. package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
  166. package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
  167. package/dist/mcp/sandbox/object-store-proxy.js +0 -30
  168. package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
  169. package/dist/mcp/sandbox/template.d.ts +0 -17
  170. package/dist/mcp/sandbox/template.d.ts.map +0 -1
  171. package/dist/mcp/sandbox/template.js +0 -71
  172. package/dist/mcp/sandbox/template.js.map +0 -1
  173. package/dist/mcp/sandbox.d.ts +0 -764
  174. package/dist/mcp/sandbox.d.ts.map +0 -1
  175. package/dist/mcp/sandbox.js +0 -1362
  176. package/dist/mcp/sandbox.js.map +0 -1
  177. package/dist/mcp/sdk-adapter.d.ts +0 -835
  178. package/dist/mcp/sdk-adapter.d.ts.map +0 -1
  179. package/dist/mcp/sdk-adapter.js +0 -974
  180. package/dist/mcp/sdk-adapter.js.map +0 -1
  181. package/dist/mcp/tools/do.d.ts +0 -32
  182. package/dist/mcp/tools/do.d.ts.map +0 -1
  183. package/dist/mcp/tools/do.js +0 -115
  184. package/dist/mcp/tools/do.js.map +0 -1
  185. package/dist/mcp/tools.d.ts +0 -548
  186. package/dist/mcp/tools.d.ts.map +0 -1
  187. package/dist/mcp/tools.js +0 -1934
  188. package/dist/mcp/tools.js.map +0 -1
  189. package/dist/ops/blame.d.ts +0 -551
  190. package/dist/ops/blame.d.ts.map +0 -1
  191. package/dist/ops/blame.js +0 -1037
  192. package/dist/ops/blame.js.map +0 -1
  193. package/dist/ops/branch.d.ts +0 -766
  194. package/dist/ops/branch.d.ts.map +0 -1
  195. package/dist/ops/branch.js +0 -950
  196. package/dist/ops/branch.js.map +0 -1
  197. package/dist/ops/commit-traversal.d.ts +0 -349
  198. package/dist/ops/commit-traversal.d.ts.map +0 -1
  199. package/dist/ops/commit-traversal.js +0 -821
  200. package/dist/ops/commit-traversal.js.map +0 -1
  201. package/dist/ops/commit.d.ts +0 -555
  202. package/dist/ops/commit.d.ts.map +0 -1
  203. package/dist/ops/commit.js +0 -826
  204. package/dist/ops/commit.js.map +0 -1
  205. package/dist/ops/merge-base.d.ts +0 -397
  206. package/dist/ops/merge-base.d.ts.map +0 -1
  207. package/dist/ops/merge-base.js +0 -691
  208. package/dist/ops/merge-base.js.map +0 -1
  209. package/dist/ops/merge.d.ts +0 -855
  210. package/dist/ops/merge.d.ts.map +0 -1
  211. package/dist/ops/merge.js +0 -1551
  212. package/dist/ops/merge.js.map +0 -1
  213. package/dist/ops/tag.d.ts +0 -247
  214. package/dist/ops/tag.d.ts.map +0 -1
  215. package/dist/ops/tag.js +0 -649
  216. package/dist/ops/tag.js.map +0 -1
  217. package/dist/ops/tree-builder.d.ts +0 -178
  218. package/dist/ops/tree-builder.d.ts.map +0 -1
  219. package/dist/ops/tree-builder.js +0 -271
  220. package/dist/ops/tree-builder.js.map +0 -1
  221. package/dist/ops/tree-diff.d.ts +0 -291
  222. package/dist/ops/tree-diff.d.ts.map +0 -1
  223. package/dist/ops/tree-diff.js +0 -705
  224. package/dist/ops/tree-diff.js.map +0 -1
  225. package/dist/pack/delta.d.ts +0 -248
  226. package/dist/pack/delta.d.ts.map +0 -1
  227. package/dist/pack/delta.js +0 -736
  228. package/dist/pack/delta.js.map +0 -1
  229. package/dist/pack/format.d.ts +0 -446
  230. package/dist/pack/format.d.ts.map +0 -1
  231. package/dist/pack/format.js +0 -572
  232. package/dist/pack/format.js.map +0 -1
  233. package/dist/pack/full-generation.d.ts +0 -612
  234. package/dist/pack/full-generation.d.ts.map +0 -1
  235. package/dist/pack/full-generation.js +0 -1378
  236. package/dist/pack/full-generation.js.map +0 -1
  237. package/dist/pack/generation.d.ts +0 -441
  238. package/dist/pack/generation.d.ts.map +0 -1
  239. package/dist/pack/generation.js +0 -707
  240. package/dist/pack/generation.js.map +0 -1
  241. package/dist/pack/index.d.ts +0 -502
  242. package/dist/pack/index.d.ts.map +0 -1
  243. package/dist/pack/index.js +0 -833
  244. package/dist/pack/index.js.map +0 -1
  245. package/dist/refs/branch.d.ts +0 -668
  246. package/dist/refs/branch.d.ts.map +0 -1
  247. package/dist/refs/branch.js +0 -897
  248. package/dist/refs/branch.js.map +0 -1
  249. package/dist/refs/storage.d.ts +0 -833
  250. package/dist/refs/storage.d.ts.map +0 -1
  251. package/dist/refs/storage.js +0 -1023
  252. package/dist/refs/storage.js.map +0 -1
  253. package/dist/refs/tag.d.ts +0 -860
  254. package/dist/refs/tag.d.ts.map +0 -1
  255. package/dist/refs/tag.js +0 -996
  256. package/dist/refs/tag.js.map +0 -1
  257. package/dist/storage/backend.d.ts +0 -425
  258. package/dist/storage/backend.d.ts.map +0 -1
  259. package/dist/storage/backend.js +0 -41
  260. package/dist/storage/backend.js.map +0 -1
  261. package/dist/storage/fsx-adapter.d.ts +0 -204
  262. package/dist/storage/fsx-adapter.d.ts.map +0 -1
  263. package/dist/storage/fsx-adapter.js +0 -470
  264. package/dist/storage/fsx-adapter.js.map +0 -1
  265. package/dist/storage/lru-cache.d.ts +0 -691
  266. package/dist/storage/lru-cache.d.ts.map +0 -1
  267. package/dist/storage/lru-cache.js +0 -813
  268. package/dist/storage/lru-cache.js.map +0 -1
  269. package/dist/storage/object-index.d.ts +0 -585
  270. package/dist/storage/object-index.d.ts.map +0 -1
  271. package/dist/storage/object-index.js +0 -532
  272. package/dist/storage/object-index.js.map +0 -1
  273. package/dist/storage/r2-pack.d.ts +0 -1257
  274. package/dist/storage/r2-pack.d.ts.map +0 -1
  275. package/dist/storage/r2-pack.js +0 -1770
  276. package/dist/storage/r2-pack.js.map +0 -1
  277. package/dist/tiered/cdc-pipeline.d.ts +0 -1888
  278. package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
  279. package/dist/tiered/cdc-pipeline.js +0 -1880
  280. package/dist/tiered/cdc-pipeline.js.map +0 -1
  281. package/dist/tiered/migration.d.ts +0 -1104
  282. package/dist/tiered/migration.d.ts.map +0 -1
  283. package/dist/tiered/migration.js +0 -1214
  284. package/dist/tiered/migration.js.map +0 -1
  285. package/dist/tiered/parquet-writer.d.ts +0 -1145
  286. package/dist/tiered/parquet-writer.d.ts.map +0 -1
  287. package/dist/tiered/parquet-writer.js +0 -1183
  288. package/dist/tiered/parquet-writer.js.map +0 -1
  289. package/dist/tiered/read-path.d.ts +0 -835
  290. package/dist/tiered/read-path.d.ts.map +0 -1
  291. package/dist/tiered/read-path.js +0 -487
  292. package/dist/tiered/read-path.js.map +0 -1
  293. package/dist/types/capability.d.ts +0 -1385
  294. package/dist/types/capability.d.ts.map +0 -1
  295. package/dist/types/capability.js +0 -36
  296. package/dist/types/capability.js.map +0 -1
  297. package/dist/types/index.d.ts +0 -13
  298. package/dist/types/index.d.ts.map +0 -1
  299. package/dist/types/index.js +0 -18
  300. package/dist/types/index.js.map +0 -1
  301. package/dist/types/objects.d.ts +0 -692
  302. package/dist/types/objects.d.ts.map +0 -1
  303. package/dist/types/objects.js +0 -837
  304. package/dist/types/objects.js.map +0 -1
  305. package/dist/types/storage.d.ts +0 -603
  306. package/dist/types/storage.d.ts.map +0 -1
  307. package/dist/types/storage.js +0 -191
  308. package/dist/types/storage.js.map +0 -1
  309. package/dist/types/worker-loader.d.ts +0 -60
  310. package/dist/types/worker-loader.d.ts.map +0 -1
  311. package/dist/types/worker-loader.js +0 -62
  312. package/dist/types/worker-loader.js.map +0 -1
  313. package/dist/utils/hash.d.ts +0 -197
  314. package/dist/utils/hash.d.ts.map +0 -1
  315. package/dist/utils/hash.js +0 -268
  316. package/dist/utils/hash.js.map +0 -1
  317. package/dist/utils/sha1.d.ts +0 -290
  318. package/dist/utils/sha1.d.ts.map +0 -1
  319. package/dist/utils/sha1.js +0 -582
  320. package/dist/utils/sha1.js.map +0 -1
  321. package/dist/wire/capabilities.d.ts +0 -1044
  322. package/dist/wire/capabilities.d.ts.map +0 -1
  323. package/dist/wire/capabilities.js +0 -941
  324. package/dist/wire/capabilities.js.map +0 -1
  325. package/dist/wire/path-security.d.ts +0 -157
  326. package/dist/wire/path-security.d.ts.map +0 -1
  327. package/dist/wire/path-security.js +0 -307
  328. package/dist/wire/path-security.js.map +0 -1
  329. package/dist/wire/pkt-line.d.ts +0 -345
  330. package/dist/wire/pkt-line.d.ts.map +0 -1
  331. package/dist/wire/pkt-line.js +0 -381
  332. package/dist/wire/pkt-line.js.map +0 -1
  333. package/dist/wire/receive-pack.d.ts +0 -1059
  334. package/dist/wire/receive-pack.d.ts.map +0 -1
  335. package/dist/wire/receive-pack.js +0 -1414
  336. package/dist/wire/receive-pack.js.map +0 -1
  337. package/dist/wire/smart-http.d.ts +0 -799
  338. package/dist/wire/smart-http.d.ts.map +0 -1
  339. package/dist/wire/smart-http.js +0 -945
  340. package/dist/wire/smart-http.js.map +0 -1
  341. package/dist/wire/upload-pack.d.ts +0 -727
  342. package/dist/wire/upload-pack.d.ts.map +0 -1
  343. package/dist/wire/upload-pack.js +0 -1138
  344. package/dist/wire/upload-pack.js.map +0 -1
@@ -1,381 +0,0 @@
1
- /**
2
- * @fileoverview Git pkt-line Protocol Implementation
3
- *
4
- * This module implements the pkt-line format used in Git's wire protocol for
5
- * client-server communication. The pkt-line format provides a simple framing
6
- * mechanism for variable-length data.
7
- *
8
- * @module wire/pkt-line
9
- *
10
- * ## Format Overview
11
- *
12
- * Each packet consists of a 4-byte hex length prefix followed by the data:
13
- * - Length includes the 4-byte prefix itself
14
- * - Maximum packet size is 65520 bytes (65516 data + 4 prefix)
15
- *
16
- * ## Special Packets
17
- *
18
- * - **flush-pkt** (`0000`): Indicates end of a message section
19
- * - **delim-pkt** (`0001`): Delimiter used in protocol v2
20
- *
21
- * @see {@link https://git-scm.com/docs/protocol-common#_pkt_line_format} Git pkt-line Format
22
- *
23
- * @example Basic encoding and decoding
24
- * ```typescript
25
- * import { encodePktLine, decodePktLine, FLUSH_PKT } from './wire/pkt-line'
26
- *
27
- * // Encode a message
28
- * const encoded = encodePktLine('hello\n')
29
- * // Result: '000ahello\n'
30
- *
31
- * // Decode a message
32
- * const decoded = decodePktLine('000ahello\n')
33
- * // Result: { data: 'hello\n', bytesRead: 10 }
34
- *
35
- * // Use flush packet to end a section
36
- * const message = encodePktLine('line1\n') + encodePktLine('line2\n') + FLUSH_PKT
37
- * ```
38
- *
39
- * @example Streaming multiple packets
40
- * ```typescript
41
- * import { pktLineStream } from './wire/pkt-line'
42
- *
43
- * const stream = '0009line1\n0009line2\n0000'
44
- * const { packets, remaining } = pktLineStream(stream)
45
- *
46
- * for (const packet of packets) {
47
- * if (packet.type === 'flush') {
48
- * console.log('End of section')
49
- * } else {
50
- * console.log('Data:', packet.data)
51
- * }
52
- * }
53
- * ```
54
- */
55
- /**
56
- * Flush packet - indicates end of a message section.
57
- *
58
- * @description
59
- * The flush packet is a special 4-byte sequence `0000` that signals
60
- * the end of a logical section in the protocol. It's used to:
61
- * - End ref advertisements
62
- * - Separate negotiation phases
63
- * - Signal end of packfile transmission
64
- *
65
- * @example
66
- * ```typescript
67
- * // Build a complete ref advertisement
68
- * let response = encodePktLine('# service=git-upload-pack\n')
69
- * response += FLUSH_PKT // End service announcement
70
- * response += encodePktLine('abc123 refs/heads/main\n')
71
- * response += FLUSH_PKT // End ref list
72
- * ```
73
- */
74
- export const FLUSH_PKT = '0000';
75
- /**
76
- * Delimiter packet - used in protocol v2.
77
- *
78
- * @description
79
- * The delimiter packet `0001` is used in Git protocol v2 to separate
80
- * sections within a single message, such as between command parameters
81
- * and command arguments.
82
- *
83
- * @example
84
- * ```typescript
85
- * // Protocol v2 command format
86
- * let request = encodePktLine('command=fetch')
87
- * request += encodePktLine('agent=git/2.30.0')
88
- * request += DELIM_PKT // Separate metadata from arguments
89
- * request += encodePktLine('want abc123...')
90
- * request += FLUSH_PKT // End of request
91
- * ```
92
- */
93
- export const DELIM_PKT = '0001';
94
- /**
95
- * Maximum pkt-line data size in bytes.
96
- *
97
- * @description
98
- * The maximum data that can be included in a single pkt-line is 65516 bytes.
99
- * This is calculated as: 65520 (max packet) - 4 (length prefix) = 65516.
100
- *
101
- * Attempting to encode data larger than this will result in an error
102
- * or require splitting into multiple packets.
103
- */
104
- export const MAX_PKT_LINE_DATA = 65516;
105
- /**
106
- * Encode data into pkt-line format.
107
- *
108
- * @description
109
- * Encodes the given data with a 4-character hex length prefix. The length
110
- * includes the 4-byte prefix itself, so a 6-byte payload results in a
111
- * 10-byte packet with prefix "000a".
112
- *
113
- * For binary data containing non-printable characters, returns a Uint8Array.
114
- * For text data, returns a string for easier concatenation.
115
- *
116
- * @param data - The data to encode (string or Uint8Array)
117
- * @returns Encoded pkt-line as string (for text) or Uint8Array (for binary)
118
- *
119
- * @throws {Error} If data exceeds MAX_PKT_LINE_DATA bytes
120
- *
121
- * @example Encoding text data
122
- * ```typescript
123
- * const line = encodePktLine('hello\n')
124
- * // Result: '000ahello\n'
125
- * // Length: 4 (prefix) + 6 (data) = 10 = 0x000a
126
- * ```
127
- *
128
- * @example Encoding binary data
129
- * ```typescript
130
- * const binaryData = new Uint8Array([0x01, 0x02, 0x03])
131
- * const encoded = encodePktLine(binaryData)
132
- * // Result: Uint8Array with hex prefix + data
133
- * ```
134
- *
135
- * @example Building a multi-line message
136
- * ```typescript
137
- * let message = ''
138
- * message += encodePktLine('want abc123...\n') as string
139
- * message += encodePktLine('have def456...\n') as string
140
- * message += FLUSH_PKT
141
- * ```
142
- */
143
- export function encodePktLine(data) {
144
- if (typeof data === 'string') {
145
- // String encoding - simple case
146
- const length = 4 + data.length;
147
- const hexLength = length.toString(16).padStart(4, '0');
148
- return hexLength + data;
149
- }
150
- // Uint8Array encoding
151
- const length = 4 + data.length;
152
- const hexLength = length.toString(16).padStart(4, '0');
153
- // Check if data contains only printable ASCII
154
- const isPrintable = data.every(byte => byte >= 0x20 && byte <= 0x7e || byte === 0x0a || byte === 0x0d);
155
- if (isPrintable) {
156
- // Return as string for printable content
157
- return hexLength + new TextDecoder().decode(data);
158
- }
159
- // Return as Uint8Array for binary content
160
- const result = new Uint8Array(4 + data.length);
161
- const encoder = new TextEncoder();
162
- result.set(encoder.encode(hexLength), 0);
163
- result.set(data, 4);
164
- return result;
165
- }
166
- /**
167
- * Decode a pkt-line format message.
168
- *
169
- * @description
170
- * Parses a single pkt-line from the input and returns the decoded data
171
- * along with metadata about the packet. Handles special packets (flush,
172
- * delim) and incomplete data gracefully.
173
- *
174
- * The function validates packet size to prevent denial-of-service attacks
175
- * from maliciously large length values.
176
- *
177
- * @param input - The input to decode (string or Uint8Array)
178
- * @returns Object with decoded data, packet type (if special), and bytes consumed
179
- *
180
- * @throws {Error} If packet size exceeds MAX_PKT_LINE_DATA + 4
181
- *
182
- * @example Decoding a data packet
183
- * ```typescript
184
- * const result = decodePktLine('000ahello\n')
185
- * // result.data === 'hello\n'
186
- * // result.bytesRead === 10
187
- * // result.type === undefined (data packet)
188
- * ```
189
- *
190
- * @example Decoding a flush packet
191
- * ```typescript
192
- * const result = decodePktLine('0000remaining...')
193
- * // result.data === null
194
- * // result.type === 'flush'
195
- * // result.bytesRead === 4
196
- * ```
197
- *
198
- * @example Handling incomplete data
199
- * ```typescript
200
- * const result = decodePktLine('00') // Not enough for length prefix
201
- * // result.data === null
202
- * // result.type === 'incomplete'
203
- * // result.bytesRead === 0
204
- * ```
205
- */
206
- export function decodePktLine(input) {
207
- // Convert to string for easier parsing
208
- let str;
209
- if (typeof input === 'string') {
210
- str = input;
211
- }
212
- else {
213
- str = new TextDecoder().decode(input);
214
- }
215
- // Need at least 4 bytes for length prefix
216
- if (str.length < 4) {
217
- return { data: null, type: 'incomplete', bytesRead: 0 };
218
- }
219
- const hexLength = str.slice(0, 4);
220
- // Check for special packets
221
- if (hexLength === '0000') {
222
- return { data: null, type: 'flush', bytesRead: 4 };
223
- }
224
- if (hexLength === '0001') {
225
- return { data: null, type: 'delim', bytesRead: 4 };
226
- }
227
- // Parse the length
228
- const length = parseInt(hexLength, 16);
229
- if (isNaN(length) || length < 4) {
230
- return { data: null, type: 'incomplete', bytesRead: 0 };
231
- }
232
- // Validate packet size to prevent DoS attacks
233
- if (length > MAX_PKT_LINE_DATA + 4) {
234
- throw new Error(`Packet too large: ${length} bytes exceeds maximum ${MAX_PKT_LINE_DATA + 4}`);
235
- }
236
- // Check if we have enough data
237
- if (str.length < length) {
238
- return { data: null, type: 'incomplete', bytesRead: 0 };
239
- }
240
- // Extract data (length includes the 4-byte prefix)
241
- const data = str.slice(4, length);
242
- return { data, bytesRead: length };
243
- }
244
- /**
245
- * Create a flush-pkt (0000).
246
- *
247
- * @description
248
- * Returns the flush packet constant. Primarily useful for explicit intent
249
- * in code, as you can also use FLUSH_PKT directly.
250
- *
251
- * The flush packet signals the end of a logical section in the protocol.
252
- *
253
- * @returns The flush packet string '0000'
254
- *
255
- * @example
256
- * ```typescript
257
- * // These are equivalent:
258
- * const flush1 = encodeFlushPkt()
259
- * const flush2 = FLUSH_PKT
260
- *
261
- * // Using in a message
262
- * const message = encodePktLine('data\n') + encodeFlushPkt()
263
- * ```
264
- */
265
- export function encodeFlushPkt() {
266
- return FLUSH_PKT;
267
- }
268
- /**
269
- * Create a delim-pkt (0001).
270
- *
271
- * @description
272
- * Returns the delimiter packet constant. The delimiter packet is used
273
- * in Git protocol v2 to separate sections within a command.
274
- *
275
- * @returns The delimiter packet string '0001'
276
- *
277
- * @example
278
- * ```typescript
279
- * // Protocol v2 ls-refs command
280
- * let request = encodePktLine('command=ls-refs')
281
- * request += encodeDelimPkt() // Separator
282
- * request += encodePktLine('ref-prefix refs/heads/')
283
- * request += encodeFlushPkt() // End
284
- * ```
285
- */
286
- export function encodeDelimPkt() {
287
- return DELIM_PKT;
288
- }
289
- /**
290
- * Parse a stream of pkt-lines.
291
- *
292
- * @description
293
- * Parses multiple pkt-lines from an input stream, returning all complete
294
- * packets and any remaining unparsed data. This is useful for:
295
- * - Processing multi-packet messages
296
- * - Handling streaming data that arrives in chunks
297
- * - Parsing complete protocol exchanges
298
- *
299
- * The function continues parsing until it encounters incomplete data
300
- * or reaches the end of input.
301
- *
302
- * @param input - The input stream to parse (string or Uint8Array)
303
- * @returns Object with parsed packets and any remaining unparsed data
304
- *
305
- * @example Parsing a complete message
306
- * ```typescript
307
- * const stream = '0009line1\n0009line2\n0000'
308
- * const { packets, remaining } = pktLineStream(stream)
309
- *
310
- * // packets = [
311
- * // { data: 'line1\n', type: 'data' },
312
- * // { data: 'line2\n', type: 'data' },
313
- * // { data: null, type: 'flush' }
314
- * // ]
315
- * // remaining = ''
316
- * ```
317
- *
318
- * @example Handling chunked data
319
- * ```typescript
320
- * // First chunk arrives
321
- * let buffer = '0009line1\n00' // Incomplete second packet
322
- * let result = pktLineStream(buffer)
323
- * // result.packets = [{ data: 'line1\n', type: 'data' }]
324
- * // result.remaining = '00'
325
- *
326
- * // Second chunk arrives
327
- * buffer = result.remaining + '09line2\n0000'
328
- * result = pktLineStream(buffer)
329
- * // result.packets = [
330
- * // { data: 'line2\n', type: 'data' },
331
- * // { data: null, type: 'flush' }
332
- * // ]
333
- * ```
334
- *
335
- * @example Processing ref advertisement
336
- * ```typescript
337
- * const refAdvert = '001e# service=git-upload-pack\n0000' +
338
- * '003fabc123... refs/heads/main\x00side-band-64k\n0000'
339
- *
340
- * const { packets } = pktLineStream(refAdvert)
341
- * for (const pkt of packets) {
342
- * if (pkt.type === 'flush') {
343
- * console.log('--- Section end ---')
344
- * } else if (pkt.data) {
345
- * console.log('Line:', pkt.data.trim())
346
- * }
347
- * }
348
- * ```
349
- */
350
- export function pktLineStream(input) {
351
- const packets = [];
352
- // Convert to string for parsing
353
- let str;
354
- if (typeof input === 'string') {
355
- str = input;
356
- }
357
- else {
358
- str = new TextDecoder().decode(input);
359
- }
360
- let offset = 0;
361
- while (offset < str.length) {
362
- const remaining = str.slice(offset);
363
- const result = decodePktLine(remaining);
364
- if (result.type === 'incomplete') {
365
- // Return remaining unparsed data
366
- return { packets, remaining: remaining };
367
- }
368
- if (result.type === 'flush') {
369
- packets.push({ data: null, type: 'flush' });
370
- }
371
- else if (result.type === 'delim') {
372
- packets.push({ data: null, type: 'delim' });
373
- }
374
- else {
375
- packets.push({ data: result.data, type: 'data' });
376
- }
377
- offset += result.bytesRead;
378
- }
379
- return { packets, remaining: '' };
380
- }
381
- //# sourceMappingURL=pkt-line.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pkt-line.js","sourceRoot":"","sources":["../../src/wire/pkt-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAA;AAE/B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAA;AAE/B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AA8DtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,aAAa,CAAC,IAAkB;IAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,gCAAgC;QAChC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;QAC9B,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QA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