gitx.do 0.0.3 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +319 -92
- package/dist/cli/commands/add.d.ts +176 -0
- package/dist/cli/commands/add.d.ts.map +1 -0
- package/dist/cli/commands/add.js +979 -0
- package/dist/cli/commands/add.js.map +1 -0
- package/dist/cli/commands/blame.d.ts +1 -1
- package/dist/cli/commands/blame.d.ts.map +1 -1
- package/dist/cli/commands/blame.js +1 -1
- package/dist/cli/commands/blame.js.map +1 -1
- package/dist/cli/commands/branch.d.ts +1 -1
- package/dist/cli/commands/branch.d.ts.map +1 -1
- package/dist/cli/commands/branch.js +2 -2
- package/dist/cli/commands/branch.js.map +1 -1
- package/dist/cli/commands/checkout.d.ts +73 -0
- package/dist/cli/commands/checkout.d.ts.map +1 -0
- package/dist/cli/commands/checkout.js +725 -0
- package/dist/cli/commands/checkout.js.map +1 -0
- package/dist/cli/commands/commit.d.ts.map +1 -1
- package/dist/cli/commands/commit.js +22 -2
- package/dist/cli/commands/commit.js.map +1 -1
- package/dist/cli/commands/diff.d.ts +4 -4
- package/dist/cli/commands/diff.d.ts.map +1 -1
- package/dist/cli/commands/diff.js +9 -8
- package/dist/cli/commands/diff.js.map +1 -1
- package/dist/cli/commands/log.d.ts +1 -1
- package/dist/cli/commands/log.d.ts.map +1 -1
- package/dist/cli/commands/log.js +1 -1
- package/dist/cli/commands/log.js.map +1 -1
- package/dist/cli/commands/merge.d.ts +106 -0
- package/dist/cli/commands/merge.d.ts.map +1 -0
- package/dist/cli/commands/merge.js +852 -0
- package/dist/cli/commands/merge.js.map +1 -0
- package/dist/cli/commands/review.d.ts +1 -1
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +26 -1
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/stash.d.ts +157 -0
- package/dist/cli/commands/stash.d.ts.map +1 -0
- package/dist/cli/commands/stash.js +655 -0
- package/dist/cli/commands/stash.js.map +1 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +1 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/web.d.ts.map +1 -1
- package/dist/cli/commands/web.js +3 -2
- package/dist/cli/commands/web.js.map +1 -1
- package/dist/cli/fs-adapter.d.ts.map +1 -1
- package/dist/cli/fs-adapter.js +3 -5
- package/dist/cli/fs-adapter.js.map +1 -1
- package/dist/cli/fsx-cli-adapter.d.ts +359 -0
- package/dist/cli/fsx-cli-adapter.d.ts.map +1 -0
- package/dist/cli/fsx-cli-adapter.js +619 -0
- package/dist/cli/fsx-cli-adapter.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +68 -12
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/ui/components/DiffView.d.ts +7 -2
- package/dist/cli/ui/components/DiffView.d.ts.map +1 -1
- package/dist/cli/ui/components/DiffView.js.map +1 -1
- package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -2
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -1
- package/dist/cli/ui/components/ErrorDisplay.js.map +1 -1
- package/dist/cli/ui/components/FuzzySearch.d.ts +8 -2
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -1
- package/dist/cli/ui/components/FuzzySearch.js.map +1 -1
- package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -2
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -1
- package/dist/cli/ui/components/LoadingSpinner.js.map +1 -1
- package/dist/cli/ui/components/NavigationList.d.ts +7 -2
- package/dist/cli/ui/components/NavigationList.d.ts.map +1 -1
- package/dist/cli/ui/components/NavigationList.js.map +1 -1
- package/dist/cli/ui/components/ScrollableContent.d.ts +7 -2
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -1
- package/dist/cli/ui/components/ScrollableContent.js.map +1 -1
- package/dist/cli/ui/terminal-ui.d.ts +42 -9
- package/dist/cli/ui/terminal-ui.d.ts.map +1 -1
- package/dist/cli/ui/terminal-ui.js.map +1 -1
- package/dist/do/BashModule.d.ts +871 -0
- package/dist/do/BashModule.d.ts.map +1 -0
- package/dist/do/BashModule.js +1143 -0
- package/dist/do/BashModule.js.map +1 -0
- package/dist/do/FsModule.d.ts +612 -0
- package/dist/do/FsModule.d.ts.map +1 -0
- package/dist/do/FsModule.js +1120 -0
- package/dist/do/FsModule.js.map +1 -0
- package/dist/do/GitModule.d.ts +635 -0
- package/dist/do/GitModule.d.ts.map +1 -0
- package/dist/do/GitModule.js +784 -0
- package/dist/do/GitModule.js.map +1 -0
- package/dist/do/GitRepoDO.d.ts +281 -0
- package/dist/do/GitRepoDO.d.ts.map +1 -0
- package/dist/do/GitRepoDO.js +479 -0
- package/dist/do/GitRepoDO.js.map +1 -0
- package/dist/do/bash-ast.d.ts +246 -0
- package/dist/do/bash-ast.d.ts.map +1 -0
- package/dist/do/bash-ast.js +888 -0
- package/dist/do/bash-ast.js.map +1 -0
- package/dist/do/container-executor.d.ts +491 -0
- package/dist/do/container-executor.d.ts.map +1 -0
- package/dist/do/container-executor.js +731 -0
- package/dist/do/container-executor.js.map +1 -0
- package/dist/do/index.d.ts +53 -0
- package/dist/do/index.d.ts.map +1 -0
- package/dist/do/index.js +91 -0
- package/dist/do/index.js.map +1 -0
- package/dist/do/tiered-storage.d.ts +403 -0
- package/dist/do/tiered-storage.d.ts.map +1 -0
- package/dist/do/tiered-storage.js +689 -0
- package/dist/do/tiered-storage.js.map +1 -0
- package/dist/do/withBash.d.ts +231 -0
- package/dist/do/withBash.d.ts.map +1 -0
- package/dist/do/withBash.js +244 -0
- package/dist/do/withBash.js.map +1 -0
- package/dist/do/withFs.d.ts +237 -0
- package/dist/do/withFs.d.ts.map +1 -0
- package/dist/do/withFs.js +387 -0
- package/dist/do/withFs.js.map +1 -0
- package/dist/do/withGit.d.ts +180 -0
- package/dist/do/withGit.d.ts.map +1 -0
- package/dist/do/withGit.js +271 -0
- package/dist/do/withGit.js.map +1 -0
- package/dist/durable-object/object-store.d.ts +157 -15
- package/dist/durable-object/object-store.d.ts.map +1 -1
- package/dist/durable-object/object-store.js +435 -47
- package/dist/durable-object/object-store.js.map +1 -1
- package/dist/durable-object/schema.d.ts +12 -1
- package/dist/durable-object/schema.d.ts.map +1 -1
- package/dist/durable-object/schema.js +87 -2
- package/dist/durable-object/schema.js.map +1 -1
- package/dist/index.d.ts +84 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts +22 -0
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +1 -0
- package/dist/mcp/sandbox/miniflare-evaluator.js +140 -0
- package/dist/mcp/sandbox/miniflare-evaluator.js.map +1 -0
- package/dist/mcp/sandbox/object-store-proxy.d.ts +32 -0
- package/dist/mcp/sandbox/object-store-proxy.d.ts.map +1 -0
- package/dist/mcp/sandbox/object-store-proxy.js +30 -0
- package/dist/mcp/sandbox/object-store-proxy.js.map +1 -0
- package/dist/mcp/sandbox/template.d.ts +17 -0
- package/dist/mcp/sandbox/template.d.ts.map +1 -0
- package/dist/mcp/sandbox/template.js +71 -0
- package/dist/mcp/sandbox/template.js.map +1 -0
- package/dist/mcp/sandbox.d.ts.map +1 -1
- package/dist/mcp/sandbox.js +16 -4
- package/dist/mcp/sandbox.js.map +1 -1
- package/dist/mcp/tools/do.d.ts +32 -0
- package/dist/mcp/tools/do.d.ts.map +1 -0
- package/dist/mcp/tools/do.js +117 -0
- package/dist/mcp/tools/do.js.map +1 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +1258 -22
- package/dist/mcp/tools.js.map +1 -1
- package/dist/pack/delta.d.ts +8 -0
- package/dist/pack/delta.d.ts.map +1 -1
- package/dist/pack/delta.js +241 -30
- package/dist/pack/delta.js.map +1 -1
- package/dist/refs/branch.d.ts +38 -25
- package/dist/refs/branch.d.ts.map +1 -1
- package/dist/refs/branch.js +421 -94
- package/dist/refs/branch.js.map +1 -1
- package/dist/refs/storage.d.ts +77 -5
- package/dist/refs/storage.d.ts.map +1 -1
- package/dist/refs/storage.js +193 -43
- package/dist/refs/storage.js.map +1 -1
- package/dist/refs/tag.d.ts +44 -24
- package/dist/refs/tag.d.ts.map +1 -1
- package/dist/refs/tag.js +411 -70
- package/dist/refs/tag.js.map +1 -1
- package/dist/storage/backend.d.ts +425 -0
- package/dist/storage/backend.d.ts.map +1 -0
- package/dist/storage/backend.js +41 -0
- package/dist/storage/backend.js.map +1 -0
- package/dist/storage/fsx-adapter.d.ts +204 -0
- package/dist/storage/fsx-adapter.d.ts.map +1 -0
- package/dist/storage/fsx-adapter.js +518 -0
- package/dist/storage/fsx-adapter.js.map +1 -0
- package/dist/storage/r2-pack.d.ts.map +1 -1
- package/dist/storage/r2-pack.js +4 -1
- package/dist/storage/r2-pack.js.map +1 -1
- package/dist/tiered/cdc-pipeline.js +3 -3
- package/dist/tiered/cdc-pipeline.js.map +1 -1
- package/dist/tiered/migration.d.ts.map +1 -1
- package/dist/tiered/migration.js +4 -1
- package/dist/tiered/migration.js.map +1 -1
- package/dist/types/capability.d.ts +1385 -0
- package/dist/types/capability.d.ts.map +1 -0
- package/dist/types/capability.js +36 -0
- package/dist/types/capability.js.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/interfaces.d.ts +673 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/interfaces.js +26 -0
- package/dist/types/interfaces.js.map +1 -0
- package/dist/types/objects.d.ts +182 -0
- package/dist/types/objects.d.ts.map +1 -1
- package/dist/types/objects.js +249 -4
- package/dist/types/objects.js.map +1 -1
- package/dist/types/storage.d.ts +114 -0
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types/storage.js +160 -1
- package/dist/types/storage.js.map +1 -1
- package/dist/types/worker-loader.d.ts +60 -0
- package/dist/types/worker-loader.d.ts.map +1 -0
- package/dist/types/worker-loader.js +62 -0
- package/dist/types/worker-loader.js.map +1 -0
- package/dist/utils/hash.d.ts +126 -80
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +191 -100
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/sha1.d.ts +206 -0
- package/dist/utils/sha1.d.ts.map +1 -1
- package/dist/utils/sha1.js +405 -0
- package/dist/utils/sha1.js.map +1 -1
- package/dist/wire/path-security.d.ts +157 -0
- package/dist/wire/path-security.d.ts.map +1 -0
- package/dist/wire/path-security.js +307 -0
- package/dist/wire/path-security.js.map +1 -0
- package/dist/wire/receive-pack.d.ts +7 -0
- package/dist/wire/receive-pack.d.ts.map +1 -1
- package/dist/wire/receive-pack.js +29 -1
- package/dist/wire/receive-pack.js.map +1 -1
- package/dist/wire/upload-pack.d.ts.map +1 -1
- package/dist/wire/upload-pack.js +4 -1
- package/dist/wire/upload-pack.js.map +1 -1
- package/package.json +10 -1
package/dist/utils/hash.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* identification and verification. Git uses SHA-1 as its primary hash algorithm,
|
|
6
6
|
* with SHA-256 available as an optional newer algorithm (Git v2.29+).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Core hash primitives are imported from fsx.do which uses the Web Crypto API.
|
|
9
|
+
* Sync primitives are kept local for pack operations that need streaming SHA1.
|
|
10
10
|
*
|
|
11
11
|
* @module utils/hash
|
|
12
12
|
*
|
|
@@ -23,63 +23,14 @@
|
|
|
23
23
|
* console.log(`blob ${blobSha}`)
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* content addressing, not security. For new security-sensitive applications,
|
|
35
|
-
* use SHA-256.
|
|
36
|
-
*
|
|
37
|
-
* @param data - Input data as Uint8Array or string (UTF-8 encoded)
|
|
38
|
-
* @returns 40-character lowercase hexadecimal hash string
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* // Hash a string
|
|
43
|
-
* const hash1 = await sha1('Hello, World!')
|
|
44
|
-
* console.log(hash1) // '0a0a9f2a6772942557ab5355d76af442f8f65e01'
|
|
45
|
-
*
|
|
46
|
-
* // Hash binary data
|
|
47
|
-
* const data = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f])
|
|
48
|
-
* const hash2 = await sha1(data)
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export async function sha1(data) {
|
|
52
|
-
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
53
|
-
const hashBuffer = await crypto.subtle.digest('SHA-1', bytes);
|
|
54
|
-
return bytesToHex(new Uint8Array(hashBuffer));
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Compute the SHA-256 hash of data.
|
|
58
|
-
*
|
|
59
|
-
* @description
|
|
60
|
-
* Computes a SHA-256 digest of the input data using the Web Crypto API.
|
|
61
|
-
* SHA-256 is the newer, more secure hash algorithm supported by Git v2.29+
|
|
62
|
-
* as an alternative to SHA-1.
|
|
63
|
-
*
|
|
64
|
-
* @param data - Input data as Uint8Array or string (UTF-8 encoded)
|
|
65
|
-
* @returns 64-character lowercase hexadecimal hash string
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* // Hash a string
|
|
70
|
-
* const hash = await sha256('Hello, World!')
|
|
71
|
-
* console.log(hash) // 'dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f'
|
|
72
|
-
*
|
|
73
|
-
* // Hash binary data
|
|
74
|
-
* const data = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f])
|
|
75
|
-
* const hash2 = await sha256(data)
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export async function sha256(data) {
|
|
79
|
-
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
80
|
-
const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
|
|
81
|
-
return bytesToHex(new Uint8Array(hashBuffer));
|
|
82
|
-
}
|
|
26
|
+
// Re-export hash functions from fsx.do - now works in Workers environment
|
|
27
|
+
export { sha1, sha256, bytesToHex, hexToBytes } from 'fsx.do';
|
|
28
|
+
// Keep local sync implementations for pack operations that need streaming SHA1
|
|
29
|
+
export { sha1Hex } from './sha1';
|
|
30
|
+
// Import local bytesToHex for cache key generation (synchronous)
|
|
31
|
+
import { bytesToHex as localBytesToHex } from './sha1';
|
|
32
|
+
// Import sha1 from fsx.do for the hashObject function
|
|
33
|
+
import { sha1 } from 'fsx.do';
|
|
83
34
|
/**
|
|
84
35
|
* Hash a Git object with its type header.
|
|
85
36
|
*
|
|
@@ -114,68 +65,208 @@ export async function hashObject(type, data) {
|
|
|
114
65
|
combined.set(data, headerBytes.length);
|
|
115
66
|
return sha1(combined);
|
|
116
67
|
}
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// Hash Caching
|
|
70
|
+
// ============================================================================
|
|
117
71
|
/**
|
|
118
|
-
*
|
|
72
|
+
* LRU cache for storing computed hashes.
|
|
119
73
|
*
|
|
120
74
|
* @description
|
|
121
|
-
*
|
|
122
|
-
*
|
|
75
|
+
* A Least Recently Used (LRU) cache implementation for caching SHA-1 hashes.
|
|
76
|
+
* This is useful when the same data is hashed multiple times, such as during
|
|
77
|
+
* pack file operations or object store lookups.
|
|
78
|
+
*
|
|
79
|
+
* **Key Strategy**: The cache key is derived from the first few bytes of the
|
|
80
|
+
* data combined with its length, which provides a fast key generation while
|
|
81
|
+
* avoiding collisions for different data.
|
|
123
82
|
*
|
|
124
|
-
* **
|
|
125
|
-
*
|
|
126
|
-
* - Hex string should have even length (odd length may produce unexpected results)
|
|
83
|
+
* **Thread Safety**: This implementation is NOT thread-safe. In multi-threaded
|
|
84
|
+
* environments, external synchronization is required.
|
|
127
85
|
*
|
|
128
|
-
* @
|
|
129
|
-
* @returns Binary data as Uint8Array
|
|
86
|
+
* @class HashCache
|
|
130
87
|
*
|
|
131
88
|
* @example
|
|
132
89
|
* ```typescript
|
|
133
|
-
* const
|
|
134
|
-
* console.log(new TextDecoder().decode(bytes)) // 'Hello'
|
|
90
|
+
* const cache = new HashCache(1000) // Cache up to 1000 hashes
|
|
135
91
|
*
|
|
136
|
-
* //
|
|
137
|
-
* const
|
|
138
|
-
* const
|
|
92
|
+
* // Use with getOrCompute for automatic caching
|
|
93
|
+
* const hash1 = await cache.getOrCompute(data, async () => sha1(data))
|
|
94
|
+
* const hash2 = await cache.getOrCompute(data, async () => sha1(data)) // Returns cached
|
|
95
|
+
*
|
|
96
|
+
* // Check stats
|
|
97
|
+
* console.log(`Hit rate: ${cache.hitRate}%`)
|
|
139
98
|
* ```
|
|
140
99
|
*/
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
100
|
+
export class HashCache {
|
|
101
|
+
cache;
|
|
102
|
+
maxSize;
|
|
103
|
+
hits = 0;
|
|
104
|
+
misses = 0;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new HashCache with the specified maximum size.
|
|
107
|
+
*
|
|
108
|
+
* @param {number} maxSize - Maximum number of hashes to cache (default: 10000)
|
|
109
|
+
*/
|
|
110
|
+
constructor(maxSize = 10000) {
|
|
111
|
+
this.cache = new Map();
|
|
112
|
+
this.maxSize = maxSize;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generates a cache key for the given data.
|
|
116
|
+
*
|
|
117
|
+
* @description Uses length + first 32 bytes (if available) to create a unique key.
|
|
118
|
+
* This is fast while providing good collision resistance.
|
|
119
|
+
*
|
|
120
|
+
* @param {Uint8Array} data - Data to generate key for
|
|
121
|
+
* @returns {string} Cache key
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
generateKey(data) {
|
|
125
|
+
// Use length + first 32 bytes as key (fast and reasonably unique)
|
|
126
|
+
const prefix = data.length <= 32
|
|
127
|
+
? localBytesToHex(data)
|
|
128
|
+
: localBytesToHex(data.subarray(0, 32));
|
|
129
|
+
return `${data.length}:${prefix}`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets a cached hash if available.
|
|
133
|
+
*
|
|
134
|
+
* @param {Uint8Array} data - Data to look up
|
|
135
|
+
* @returns {string | undefined} Cached hash or undefined if not cached
|
|
136
|
+
*/
|
|
137
|
+
get(data) {
|
|
138
|
+
const key = this.generateKey(data);
|
|
139
|
+
const value = this.cache.get(key);
|
|
140
|
+
if (value !== undefined) {
|
|
141
|
+
this.hits++;
|
|
142
|
+
// Move to end (most recently used)
|
|
143
|
+
this.cache.delete(key);
|
|
144
|
+
this.cache.set(key, value);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
this.misses++;
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Stores a hash in the cache.
|
|
152
|
+
*
|
|
153
|
+
* @param {Uint8Array} data - Original data
|
|
154
|
+
* @param {string} hash - Computed hash to cache
|
|
155
|
+
*/
|
|
156
|
+
set(data, hash) {
|
|
157
|
+
const key = this.generateKey(data);
|
|
158
|
+
// Remove oldest entry if at capacity
|
|
159
|
+
if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
160
|
+
const firstKey = this.cache.keys().next().value;
|
|
161
|
+
if (firstKey !== undefined) {
|
|
162
|
+
this.cache.delete(firstKey);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this.cache.set(key, hash);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets a hash from cache or computes and caches it.
|
|
169
|
+
*
|
|
170
|
+
* @description This is the recommended way to use the cache. It automatically
|
|
171
|
+
* handles cache lookup, computation, and storage.
|
|
172
|
+
*
|
|
173
|
+
* @param {Uint8Array} data - Data to hash
|
|
174
|
+
* @param {() => Promise<string> | string} compute - Function to compute hash if not cached
|
|
175
|
+
* @returns {Promise<string>} The hash (from cache or newly computed)
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const hash = await cache.getOrCompute(data, () => sha1(data))
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
async getOrCompute(data, compute) {
|
|
183
|
+
const cached = this.get(data);
|
|
184
|
+
if (cached !== undefined) {
|
|
185
|
+
return cached;
|
|
186
|
+
}
|
|
187
|
+
const hash = await compute();
|
|
188
|
+
this.set(data, hash);
|
|
189
|
+
return hash;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Synchronous version of getOrCompute for use with synchronous hash functions.
|
|
193
|
+
*
|
|
194
|
+
* @param {Uint8Array} data - Data to hash
|
|
195
|
+
* @param {() => string} compute - Function to compute hash if not cached
|
|
196
|
+
* @returns {string} The hash (from cache or newly computed)
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* import { sha1Hex } from './sha1'
|
|
201
|
+
* const hash = cache.getOrComputeSync(data, () => sha1Hex(data))
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
getOrComputeSync(data, compute) {
|
|
205
|
+
const cached = this.get(data);
|
|
206
|
+
if (cached !== undefined) {
|
|
207
|
+
return cached;
|
|
208
|
+
}
|
|
209
|
+
const hash = compute();
|
|
210
|
+
this.set(data, hash);
|
|
211
|
+
return hash;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Clears all entries from the cache.
|
|
215
|
+
*/
|
|
216
|
+
clear() {
|
|
217
|
+
this.cache.clear();
|
|
218
|
+
this.hits = 0;
|
|
219
|
+
this.misses = 0;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the current number of cached entries.
|
|
223
|
+
*/
|
|
224
|
+
get size() {
|
|
225
|
+
return this.cache.size;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets the cache hit rate as a percentage.
|
|
229
|
+
*/
|
|
230
|
+
get hitRate() {
|
|
231
|
+
const total = this.hits + this.misses;
|
|
232
|
+
return total === 0 ? 0 : (this.hits / total) * 100;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Gets cache statistics.
|
|
236
|
+
*
|
|
237
|
+
* @returns {{ hits: number; misses: number; size: number; hitRate: number }}
|
|
238
|
+
*/
|
|
239
|
+
getStats() {
|
|
240
|
+
return {
|
|
241
|
+
hits: this.hits,
|
|
242
|
+
misses: this.misses,
|
|
243
|
+
size: this.cache.size,
|
|
244
|
+
hitRate: this.hitRate
|
|
245
|
+
};
|
|
147
246
|
}
|
|
148
|
-
return bytes;
|
|
149
247
|
}
|
|
150
248
|
/**
|
|
151
|
-
*
|
|
249
|
+
* Global hash cache instance for common use cases.
|
|
152
250
|
*
|
|
153
251
|
* @description
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* **Edge Cases**:
|
|
158
|
-
* - Empty Uint8Array returns empty string
|
|
252
|
+
* A shared cache instance that can be used across the application for
|
|
253
|
+
* caching object hashes. This is particularly useful for pack file
|
|
254
|
+
* operations where the same objects are hashed multiple times.
|
|
159
255
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
256
|
+
* **Memory Management**: The cache has a default limit of 10,000 entries.
|
|
257
|
+
* For applications with different requirements, create a custom HashCache
|
|
258
|
+
* instance with appropriate size.
|
|
162
259
|
*
|
|
163
260
|
* @example
|
|
164
261
|
* ```typescript
|
|
165
|
-
*
|
|
166
|
-
* const hex = bytesToHex(hello)
|
|
167
|
-
* console.log(hex) // '48656c6c6f'
|
|
262
|
+
* import { globalHashCache, sha1 } from './utils/hash'
|
|
168
263
|
*
|
|
169
|
-
* //
|
|
170
|
-
* const
|
|
171
|
-
*
|
|
264
|
+
* // Use the global cache
|
|
265
|
+
* const hash = await globalHashCache.getOrCompute(data, () => sha1(data))
|
|
266
|
+
*
|
|
267
|
+
* // Check cache stats
|
|
268
|
+
* console.log(globalHashCache.getStats())
|
|
172
269
|
* ```
|
|
173
270
|
*/
|
|
174
|
-
export
|
|
175
|
-
if (bytes.length === 0)
|
|
176
|
-
return '';
|
|
177
|
-
return Array.from(bytes)
|
|
178
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
179
|
-
.join('');
|
|
180
|
-
}
|
|
271
|
+
export const globalHashCache = new HashCache();
|
|
181
272
|
//# sourceMappingURL=hash.js.map
|
package/dist/utils/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,0EAA0E;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAE7D,+EAA+E;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEhC,iEAAiE;AACjE,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,QAAQ,CAAA;AACtD,sDAAsD;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,IAAgB;IAC7D,MAAM,MAAM,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,CAAA;IACzC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACpD,MAAM,QA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118
|
export declare function sha1Verify(data: Uint8Array, expected: Uint8Array): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Convert bytes to hexadecimal string.
|
|
121
|
+
*
|
|
122
|
+
* @description Efficiently converts a Uint8Array to its hexadecimal
|
|
123
|
+
* representation. Each byte becomes two hex characters (00-ff).
|
|
124
|
+
*
|
|
125
|
+
* @param bytes - Input bytes to convert
|
|
126
|
+
* @returns Lowercase hexadecimal string (2 chars per byte)
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f])
|
|
131
|
+
* const hex = bytesToHex(bytes)
|
|
132
|
+
* console.log(hex) // '48656c6c6f'
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
136
|
+
/**
|
|
137
|
+
* Convert hexadecimal string to bytes.
|
|
138
|
+
*
|
|
139
|
+
* @description Converts a hexadecimal string back to its binary representation.
|
|
140
|
+
* Each pair of hex characters becomes one byte.
|
|
141
|
+
*
|
|
142
|
+
* @param hex - Hexadecimal string (case-insensitive)
|
|
143
|
+
* @returns Uint8Array of bytes
|
|
144
|
+
* @throws {Error} If hex string has odd length
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const hex = '48656c6c6f'
|
|
149
|
+
* const bytes = hexToBytes(hex)
|
|
150
|
+
* console.log(new TextDecoder().decode(bytes)) // 'Hello'
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
154
|
+
/**
|
|
155
|
+
* Streaming SHA-1 hasher for processing large data incrementally.
|
|
156
|
+
*
|
|
157
|
+
* @description
|
|
158
|
+
* This class allows hashing data in chunks, which is essential for:
|
|
159
|
+
* - Processing large files without loading everything into memory
|
|
160
|
+
* - Computing hashes of data streams
|
|
161
|
+
* - Pack file generation and verification
|
|
162
|
+
*
|
|
163
|
+
* The hasher maintains internal state and can accept data through the
|
|
164
|
+
* `update()` method before finalizing with `digest()` or `digestHex()`.
|
|
165
|
+
*
|
|
166
|
+
* **Performance Note**: For small data (< 64 bytes), the non-streaming
|
|
167
|
+
* `sha1()` function may be slightly faster due to lower overhead.
|
|
168
|
+
*
|
|
169
|
+
* @class StreamingSHA1
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // Hash a large file in chunks
|
|
174
|
+
* const hasher = new StreamingSHA1()
|
|
175
|
+
*
|
|
176
|
+
* for await (const chunk of fileStream) {
|
|
177
|
+
* hasher.update(chunk)
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* const hash = hasher.digestHex()
|
|
181
|
+
* console.log(`File hash: ${hash}`)
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* // Hash Git object with header
|
|
187
|
+
* const hasher = new StreamingSHA1()
|
|
188
|
+
* hasher.update(new TextEncoder().encode(`blob ${size}\0`))
|
|
189
|
+
* hasher.update(content)
|
|
190
|
+
* const objectId = hasher.digestHex()
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export declare class StreamingSHA1 {
|
|
194
|
+
/** Hash state */
|
|
195
|
+
private h;
|
|
196
|
+
/** Working array for chunk processing */
|
|
197
|
+
private w;
|
|
198
|
+
/** Buffer for incomplete chunks */
|
|
199
|
+
private buffer;
|
|
200
|
+
/** Current position in buffer */
|
|
201
|
+
private bufferLength;
|
|
202
|
+
/** Total bytes processed */
|
|
203
|
+
private totalLength;
|
|
204
|
+
/** Whether digest has been called */
|
|
205
|
+
private finalized;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a new StreamingSHA1 hasher instance.
|
|
208
|
+
*/
|
|
209
|
+
constructor();
|
|
210
|
+
/**
|
|
211
|
+
* Resets the hasher to its initial state.
|
|
212
|
+
*
|
|
213
|
+
* @description Allows reusing the same hasher instance for a new hash
|
|
214
|
+
* computation without creating a new object.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const hasher = new StreamingSHA1()
|
|
219
|
+
* hasher.update(data1)
|
|
220
|
+
* const hash1 = hasher.digestHex()
|
|
221
|
+
*
|
|
222
|
+
* hasher.reset()
|
|
223
|
+
* hasher.update(data2)
|
|
224
|
+
* const hash2 = hasher.digestHex()
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
reset(): void;
|
|
228
|
+
/**
|
|
229
|
+
* Updates the hash with additional data.
|
|
230
|
+
*
|
|
231
|
+
* @description Processes the input data, updating the internal hash state.
|
|
232
|
+
* Data is buffered internally until a complete 64-byte chunk is available,
|
|
233
|
+
* then processed immediately.
|
|
234
|
+
*
|
|
235
|
+
* This method can be called multiple times before finalizing with `digest()`.
|
|
236
|
+
*
|
|
237
|
+
* @param {Uint8Array} data - Data to add to the hash computation
|
|
238
|
+
* @returns {this} The hasher instance for method chaining
|
|
239
|
+
* @throws {Error} If called after digest() without reset()
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const hasher = new StreamingSHA1()
|
|
244
|
+
* .update(header)
|
|
245
|
+
* .update(content)
|
|
246
|
+
* .update(footer)
|
|
247
|
+
* const hash = hasher.digestHex()
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
update(data: Uint8Array): this;
|
|
251
|
+
/**
|
|
252
|
+
* Finalizes the hash computation and returns the 20-byte digest.
|
|
253
|
+
*
|
|
254
|
+
* @description Applies SHA-1 padding to the remaining data and computes
|
|
255
|
+
* the final hash. After calling this method, the hasher cannot be updated
|
|
256
|
+
* unless `reset()` is called.
|
|
257
|
+
*
|
|
258
|
+
* @returns {Uint8Array} 20-byte SHA-1 hash
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const hasher = new StreamingSHA1()
|
|
263
|
+
* hasher.update(data)
|
|
264
|
+
* const hashBytes = hasher.digest()
|
|
265
|
+
* console.log(hashBytes.length) // 20
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
digest(): Uint8Array;
|
|
269
|
+
/**
|
|
270
|
+
* Finalizes the hash computation and returns the hex string digest.
|
|
271
|
+
*
|
|
272
|
+
* @description Convenience method that calls `digest()` and converts
|
|
273
|
+
* the result to a 40-character lowercase hexadecimal string.
|
|
274
|
+
*
|
|
275
|
+
* @returns {string} 40-character lowercase hexadecimal hash string
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const hasher = new StreamingSHA1()
|
|
280
|
+
* hasher.update(data)
|
|
281
|
+
* const hash = hasher.digestHex()
|
|
282
|
+
* console.log(hash) // 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
digestHex(): string;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Hash a Git object with streaming support for large objects.
|
|
289
|
+
*
|
|
290
|
+
* @description
|
|
291
|
+
* Uses the streaming hasher to compute the SHA-1 of a Git object with its header.
|
|
292
|
+
* This is more memory-efficient than `hashObject` in `hash.ts` for large objects
|
|
293
|
+
* as it doesn't require concatenating header and data.
|
|
294
|
+
*
|
|
295
|
+
* @param type - Object type ('blob', 'tree', 'commit', 'tag')
|
|
296
|
+
* @param data - Object content as binary data
|
|
297
|
+
* @returns 20-byte SHA-1 hash as Uint8Array
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const content = new TextEncoder().encode('hello')
|
|
302
|
+
* const hashBytes = hashObjectStreaming('blob', content)
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
export declare function hashObjectStreaming(type: string, data: Uint8Array): Uint8Array;
|
|
306
|
+
/**
|
|
307
|
+
* Hash a Git object with streaming support, returning hex string.
|
|
308
|
+
*
|
|
309
|
+
* @description
|
|
310
|
+
* Convenience wrapper that returns the hash as a 40-character hex string
|
|
311
|
+
* instead of raw bytes.
|
|
312
|
+
*
|
|
313
|
+
* @param type - Object type ('blob', 'tree', 'commit', 'tag')
|
|
314
|
+
* @param data - Object content as binary data
|
|
315
|
+
* @returns 40-character lowercase hexadecimal SHA-1 hash
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const content = new TextEncoder().encode('hello')
|
|
320
|
+
* const sha = hashObjectStreamingHex('blob', content)
|
|
321
|
+
* console.log(sha) // 'b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0'
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
export declare function hashObjectStreamingHex(type: string, data: Uint8Array): string;
|
|
119
325
|
//# sourceMappingURL=sha1.d.ts.map
|
package/dist/utils/sha1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../../src/utils/sha1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAwGjD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAOhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAgB1E"}
|
|
1
|
+
{"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../../src/utils/sha1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;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