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/types/storage.js
CHANGED
|
@@ -28,5 +28,164 @@
|
|
|
28
28
|
* }
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
import { isValidSha, isValidObjectType } from './objects';
|
|
32
|
+
/**
|
|
33
|
+
* Validate a ref name.
|
|
34
|
+
*
|
|
35
|
+
* @description
|
|
36
|
+
* Checks if a ref name follows Git ref naming conventions:
|
|
37
|
+
* - Cannot start with '.' or end with '/'
|
|
38
|
+
* - Cannot contain '..' or '//'
|
|
39
|
+
* - Cannot contain control characters, spaces, or special chars
|
|
40
|
+
* - Cannot end with '.lock'
|
|
41
|
+
*
|
|
42
|
+
* @param refName - The ref name to validate
|
|
43
|
+
* @returns Validation result
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* validateRefName('refs/heads/main') // { isValid: true }
|
|
48
|
+
* validateRefName('refs/heads/../foo') // { isValid: false, error: '...' }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function validateRefName(refName) {
|
|
52
|
+
if (!refName || typeof refName !== 'string') {
|
|
53
|
+
return { isValid: false, error: 'Ref name is required and must be a string' };
|
|
54
|
+
}
|
|
55
|
+
if (refName.startsWith('.') || refName.startsWith('/')) {
|
|
56
|
+
return { isValid: false, error: 'Ref name cannot start with "." or "/"' };
|
|
57
|
+
}
|
|
58
|
+
if (refName.endsWith('/') || refName.endsWith('.')) {
|
|
59
|
+
return { isValid: false, error: 'Ref name cannot end with "/" or "."' };
|
|
60
|
+
}
|
|
61
|
+
if (refName.includes('..')) {
|
|
62
|
+
return { isValid: false, error: 'Ref name cannot contain ".."' };
|
|
63
|
+
}
|
|
64
|
+
if (refName.includes('//')) {
|
|
65
|
+
return { isValid: false, error: 'Ref name cannot contain "//"' };
|
|
66
|
+
}
|
|
67
|
+
if (refName.endsWith('.lock')) {
|
|
68
|
+
return { isValid: false, error: 'Ref name cannot end with ".lock"' };
|
|
69
|
+
}
|
|
70
|
+
// Check for control characters and special chars
|
|
71
|
+
if (/[\x00-\x1f\x7f ~^:?*\[\\]/.test(refName)) {
|
|
72
|
+
return { isValid: false, error: 'Ref name contains invalid characters (control chars, space, ~, ^, :, ?, *, [, or \\)' };
|
|
73
|
+
}
|
|
74
|
+
return { isValid: true };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validate a ref update operation.
|
|
78
|
+
*
|
|
79
|
+
* @description
|
|
80
|
+
* Validates a reference update operation including:
|
|
81
|
+
* - Ref name format
|
|
82
|
+
* - Old and new SHA validity (or zero SHA for create/delete)
|
|
83
|
+
*
|
|
84
|
+
* @param refName - The ref name to update
|
|
85
|
+
* @param oldSha - The expected current SHA (or zero SHA if creating)
|
|
86
|
+
* @param newSha - The new SHA to set (or zero SHA if deleting)
|
|
87
|
+
* @returns Validation result
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Creating a new ref
|
|
92
|
+
* validateRefUpdate('refs/heads/feature', ZERO_SHA, 'abc123...')
|
|
93
|
+
*
|
|
94
|
+
* // Updating a ref
|
|
95
|
+
* validateRefUpdate('refs/heads/main', 'old123...', 'new456...')
|
|
96
|
+
*
|
|
97
|
+
* // Deleting a ref
|
|
98
|
+
* validateRefUpdate('refs/heads/old', 'abc123...', ZERO_SHA)
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function validateRefUpdate(refName, oldSha, newSha) {
|
|
102
|
+
const refResult = validateRefName(refName);
|
|
103
|
+
if (!refResult.isValid) {
|
|
104
|
+
return refResult;
|
|
105
|
+
}
|
|
106
|
+
const ZERO_SHA = '0000000000000000000000000000000000000000';
|
|
107
|
+
if (oldSha !== ZERO_SHA && !isValidSha(oldSha)) {
|
|
108
|
+
return { isValid: false, error: `Invalid old SHA: ${oldSha}. Must be 40 hex chars or zero SHA` };
|
|
109
|
+
}
|
|
110
|
+
if (newSha !== ZERO_SHA && !isValidSha(newSha)) {
|
|
111
|
+
return { isValid: false, error: `Invalid new SHA: ${newSha}. Must be 40 hex chars or zero SHA` };
|
|
112
|
+
}
|
|
113
|
+
if (oldSha === ZERO_SHA && newSha === ZERO_SHA) {
|
|
114
|
+
return { isValid: false, error: 'Cannot have both old and new SHA as zero (no-op)' };
|
|
115
|
+
}
|
|
116
|
+
return { isValid: true };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Validate object storage parameters.
|
|
120
|
+
*
|
|
121
|
+
* @description
|
|
122
|
+
* Validates parameters for storeObject operations:
|
|
123
|
+
* - Object type must be valid
|
|
124
|
+
* - Data must be a Uint8Array
|
|
125
|
+
*
|
|
126
|
+
* @param type - The object type
|
|
127
|
+
* @param data - The object data
|
|
128
|
+
* @returns Validation result
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const result = validateStoreParams('blob', new Uint8Array([1, 2, 3]))
|
|
133
|
+
* if (!result.isValid) {
|
|
134
|
+
* throw new Error(result.error)
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function validateStoreParams(type, data) {
|
|
139
|
+
if (!isValidObjectType(type)) {
|
|
140
|
+
return { isValid: false, error: `Invalid object type: ${type}. Must be blob, tree, commit, or tag` };
|
|
141
|
+
}
|
|
142
|
+
if (!(data instanceof Uint8Array)) {
|
|
143
|
+
return { isValid: false, error: 'Data must be a Uint8Array' };
|
|
144
|
+
}
|
|
145
|
+
return { isValid: true };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Assert that a SHA is valid, throwing if not.
|
|
149
|
+
*
|
|
150
|
+
* @description
|
|
151
|
+
* Throws a descriptive error if the SHA is invalid.
|
|
152
|
+
* Use this for input validation in API boundaries.
|
|
153
|
+
*
|
|
154
|
+
* @param sha - The SHA to validate
|
|
155
|
+
* @param context - Optional context for the error message (e.g., 'tree', 'parent')
|
|
156
|
+
* @throws Error if SHA is invalid
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* assertValidSha(treeSha, 'tree') // Throws: "Invalid tree SHA: ..."
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export function assertValidSha(sha, context) {
|
|
164
|
+
if (!isValidSha(sha)) {
|
|
165
|
+
const prefix = context ? `Invalid ${context} SHA` : 'Invalid SHA';
|
|
166
|
+
throw new Error(`${prefix}: ${sha}. Must be 40 lowercase hexadecimal characters`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Assert that a ref name is valid, throwing if not.
|
|
171
|
+
*
|
|
172
|
+
* @description
|
|
173
|
+
* Throws a descriptive error if the ref name is invalid.
|
|
174
|
+
* Use this for input validation in API boundaries.
|
|
175
|
+
*
|
|
176
|
+
* @param refName - The ref name to validate
|
|
177
|
+
* @throws Error if ref name is invalid
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* assertValidRefName('refs/heads/main') // OK
|
|
182
|
+
* assertValidRefName('refs/../bad') // Throws
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export function assertValidRefName(refName) {
|
|
186
|
+
const result = validateRefName(refName);
|
|
187
|
+
if (!result.isValid) {
|
|
188
|
+
throw new Error(result.error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
32
191
|
//# sourceMappingURL=storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG"}
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAoBzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,2CAA2C,EAAE,CAAA;IAC/E,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAA;IAC3E,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,qCAAqC,EAAE,CAAA;IACzE,CA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AE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Worker Loader Types
|
|
3
|
+
*
|
|
4
|
+
* This module defines types for loading and interacting with Cloudflare Workers
|
|
5
|
+
* in the gitdo environment. Based on patterns from mongo.do research.
|
|
6
|
+
*
|
|
7
|
+
* @module types/worker-loader
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* WorkerLoader interface for managing worker instances.
|
|
11
|
+
*/
|
|
12
|
+
export interface WorkerLoader {
|
|
13
|
+
get(id: string, getCode: () => Promise<WorkerCode>): WorkerStub;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* WorkerCode defines the configuration and modules for a worker.
|
|
17
|
+
*/
|
|
18
|
+
export interface WorkerCode {
|
|
19
|
+
compatibilityDate: string;
|
|
20
|
+
compatibilityFlags?: string[];
|
|
21
|
+
mainModule: string;
|
|
22
|
+
modules: Record<string, string | {
|
|
23
|
+
js: string;
|
|
24
|
+
} | {
|
|
25
|
+
text: string;
|
|
26
|
+
}>;
|
|
27
|
+
globalOutbound?: null;
|
|
28
|
+
env?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* WorkerStub provides methods to interact with a worker instance.
|
|
32
|
+
*/
|
|
33
|
+
export interface WorkerStub {
|
|
34
|
+
fetch?(request: Request): Promise<Response>;
|
|
35
|
+
getEntrypoint?(name?: string): WorkerEntrypoint;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* WorkerEntrypoint represents a worker's entrypoint.
|
|
39
|
+
*/
|
|
40
|
+
export interface WorkerEntrypoint {
|
|
41
|
+
fetch(request: Request): Promise<Response>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* MockWorkerLoader provides a mock implementation of the WorkerLoader interface
|
|
45
|
+
* for testing purposes. It caches WorkerStubs by ID.
|
|
46
|
+
*/
|
|
47
|
+
export declare class MockWorkerLoader implements WorkerLoader {
|
|
48
|
+
private cache;
|
|
49
|
+
get(id: string, _getCode: () => Promise<WorkerCode>): WorkerStub;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Type guard to check if a loader is a real Cloudflare worker loader.
|
|
53
|
+
* Returns false for MockWorkerLoader instances, null, undefined, or non-WorkerLoader objects.
|
|
54
|
+
* Returns true only for real Cloudflare worker_loaders that have the internal marker.
|
|
55
|
+
*
|
|
56
|
+
* @param loader - The loader to check
|
|
57
|
+
* @returns true if the loader is a real Cloudflare worker loader
|
|
58
|
+
*/
|
|
59
|
+
export declare function isRealWorkerLoader(loader: unknown): loader is WorkerLoader;
|
|
60
|
+
//# sourceMappingURL=worker-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-loader.d.ts","sourceRoot":"","sources":["../../src/types/worker-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAA;CAChE;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACnE,cAAc,CAAC,EAAE,IAAI,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC3C,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C;AAOD;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,OAAO,CAAC,KAAK,CAAgC;IAE7C,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU;CAsBjE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAgB1E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Worker Loader Types
|
|
3
|
+
*
|
|
4
|
+
* This module defines types for loading and interacting with Cloudflare Workers
|
|
5
|
+
* in the gitdo environment. Based on patterns from mongo.do research.
|
|
6
|
+
*
|
|
7
|
+
* @module types/worker-loader
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Internal marker symbol for identifying real Cloudflare worker loaders.
|
|
11
|
+
*/
|
|
12
|
+
const REAL_WORKER_LOADER_MARKER = Symbol.for('cloudflare.worker_loader');
|
|
13
|
+
/**
|
|
14
|
+
* MockWorkerLoader provides a mock implementation of the WorkerLoader interface
|
|
15
|
+
* for testing purposes. It caches WorkerStubs by ID.
|
|
16
|
+
*/
|
|
17
|
+
export class MockWorkerLoader {
|
|
18
|
+
cache = new Map();
|
|
19
|
+
get(id, _getCode) {
|
|
20
|
+
const cached = this.cache.get(id);
|
|
21
|
+
if (cached) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
const stub = {
|
|
25
|
+
fetch: async (_request) => {
|
|
26
|
+
return new Response('MockWorkerLoader response');
|
|
27
|
+
},
|
|
28
|
+
getEntrypoint: (_name) => {
|
|
29
|
+
return {
|
|
30
|
+
fetch: async (_request) => {
|
|
31
|
+
return new Response('MockWorkerLoader entrypoint response');
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.cache.set(id, stub);
|
|
37
|
+
return stub;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Type guard to check if a loader is a real Cloudflare worker loader.
|
|
42
|
+
* Returns false for MockWorkerLoader instances, null, undefined, or non-WorkerLoader objects.
|
|
43
|
+
* Returns true only for real Cloudflare worker_loaders that have the internal marker.
|
|
44
|
+
*
|
|
45
|
+
* @param loader - The loader to check
|
|
46
|
+
* @returns true if the loader is a real Cloudflare worker loader
|
|
47
|
+
*/
|
|
48
|
+
export function isRealWorkerLoader(loader) {
|
|
49
|
+
if (loader === null || loader === undefined) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (loader instanceof MockWorkerLoader) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (typeof loader !== 'object') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// Check for the internal marker that real Cloudflare worker loaders would have
|
|
59
|
+
const obj = loader;
|
|
60
|
+
return obj[REAL_WORKER_LOADER_MARKER] === true;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=worker-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-loader.js","sourceRoot":"","sources":["../../src/types/worker-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoCH;;GAEG;AACH,MAAM,yBAAyB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;AAExE;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;IAE7C,GAAG,CAAC,EAAU,EAAE,QAAmC;QACjD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACjC,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAA;QACf,CAAC;QAED,MAAM,IAAI,GAAe;YACvB,KAAK,EAAE,KAAK,EAAE,QAAiB,EAAqB,EAAE;gBACpD,OAAO,IAAI,QAAQ,CAAC,2BAA2B,CAAC,CAAA;YAClD,CAAC;YACD,aAAa,EAAE,CAAC,KAAc,EAAoB,EAAE;gBAClD,OAAO;oBACL,KAAK,EAAE,KAAK,EAAE,QAAiB,EAAqB,EAAE;wBACpD,OAAO,IAAI,QAAQ,CAAC,sCAAsC,CAAC,CAAA;oBAC7D,CAAC;iBACF,CAAA;YACH,CAAC;SACF,CAAA;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QACxB,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAe;IAChD,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,MAAM,YAAY,gBAAgB,EAAE,CAAC;QACvC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,+EAA+E;IAC/E,MAAM,GAAG,GAAG,MAA0C,CAAA;IACtD,OAAO,GAAG,CAAC,yBAAyB,CAAC,KAAK,IAAI,CAAA;AAChD,CAAC"}
|
package/dist/utils/hash.d.ts
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,55 +23,8 @@
|
|
|
23
23
|
* console.log(`blob ${blobSha}`)
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @description
|
|
30
|
-
* Computes a SHA-1 digest of the input data using the Web Crypto API.
|
|
31
|
-
* This is the standard hash algorithm used by Git for object identification.
|
|
32
|
-
*
|
|
33
|
-
* **Note**: SHA-1 is considered cryptographically weak. Git uses it for
|
|
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 declare function sha1(data: Uint8Array | string): Promise<string>;
|
|
52
|
-
/**
|
|
53
|
-
* Compute the SHA-256 hash of data.
|
|
54
|
-
*
|
|
55
|
-
* @description
|
|
56
|
-
* Computes a SHA-256 digest of the input data using the Web Crypto API.
|
|
57
|
-
* SHA-256 is the newer, more secure hash algorithm supported by Git v2.29+
|
|
58
|
-
* as an alternative to SHA-1.
|
|
59
|
-
*
|
|
60
|
-
* @param data - Input data as Uint8Array or string (UTF-8 encoded)
|
|
61
|
-
* @returns 64-character lowercase hexadecimal hash string
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* // Hash a string
|
|
66
|
-
* const hash = await sha256('Hello, World!')
|
|
67
|
-
* console.log(hash) // 'dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f'
|
|
68
|
-
*
|
|
69
|
-
* // Hash binary data
|
|
70
|
-
* const data = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f])
|
|
71
|
-
* const hash2 = await sha256(data)
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export declare function sha256(data: Uint8Array | string): Promise<string>;
|
|
26
|
+
export { sha1, sha256, bytesToHex, hexToBytes } from 'fsx.do';
|
|
27
|
+
export { sha1Hex } from './sha1';
|
|
75
28
|
/**
|
|
76
29
|
* Hash a Git object with its type header.
|
|
77
30
|
*
|
|
@@ -100,53 +53,146 @@ export declare function sha256(data: Uint8Array | string): Promise<string>;
|
|
|
100
53
|
*/
|
|
101
54
|
export declare function hashObject(type: string, data: Uint8Array): Promise<string>;
|
|
102
55
|
/**
|
|
103
|
-
*
|
|
56
|
+
* LRU cache for storing computed hashes.
|
|
104
57
|
*
|
|
105
58
|
* @description
|
|
106
|
-
*
|
|
107
|
-
*
|
|
59
|
+
* A Least Recently Used (LRU) cache implementation for caching SHA-1 hashes.
|
|
60
|
+
* This is useful when the same data is hashed multiple times, such as during
|
|
61
|
+
* pack file operations or object store lookups.
|
|
62
|
+
*
|
|
63
|
+
* **Key Strategy**: The cache key is derived from the first few bytes of the
|
|
64
|
+
* data combined with its length, which provides a fast key generation while
|
|
65
|
+
* avoiding collisions for different data.
|
|
108
66
|
*
|
|
109
|
-
* **
|
|
110
|
-
*
|
|
111
|
-
* - Hex string should have even length (odd length may produce unexpected results)
|
|
67
|
+
* **Thread Safety**: This implementation is NOT thread-safe. In multi-threaded
|
|
68
|
+
* environments, external synchronization is required.
|
|
112
69
|
*
|
|
113
|
-
* @
|
|
114
|
-
* @returns Binary data as Uint8Array
|
|
70
|
+
* @class HashCache
|
|
115
71
|
*
|
|
116
72
|
* @example
|
|
117
73
|
* ```typescript
|
|
118
|
-
* const
|
|
119
|
-
* console.log(new TextDecoder().decode(bytes)) // 'Hello'
|
|
74
|
+
* const cache = new HashCache(1000) // Cache up to 1000 hashes
|
|
120
75
|
*
|
|
121
|
-
* //
|
|
122
|
-
* const
|
|
123
|
-
* const
|
|
76
|
+
* // Use with getOrCompute for automatic caching
|
|
77
|
+
* const hash1 = await cache.getOrCompute(data, async () => sha1(data))
|
|
78
|
+
* const hash2 = await cache.getOrCompute(data, async () => sha1(data)) // Returns cached
|
|
79
|
+
*
|
|
80
|
+
* // Check stats
|
|
81
|
+
* console.log(`Hit rate: ${cache.hitRate}%`)
|
|
124
82
|
* ```
|
|
125
83
|
*/
|
|
126
|
-
export declare
|
|
84
|
+
export declare class HashCache {
|
|
85
|
+
private cache;
|
|
86
|
+
private maxSize;
|
|
87
|
+
private hits;
|
|
88
|
+
private misses;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new HashCache with the specified maximum size.
|
|
91
|
+
*
|
|
92
|
+
* @param {number} maxSize - Maximum number of hashes to cache (default: 10000)
|
|
93
|
+
*/
|
|
94
|
+
constructor(maxSize?: number);
|
|
95
|
+
/**
|
|
96
|
+
* Generates a cache key for the given data.
|
|
97
|
+
*
|
|
98
|
+
* @description Uses length + first 32 bytes (if available) to create a unique key.
|
|
99
|
+
* This is fast while providing good collision resistance.
|
|
100
|
+
*
|
|
101
|
+
* @param {Uint8Array} data - Data to generate key for
|
|
102
|
+
* @returns {string} Cache key
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
private generateKey;
|
|
106
|
+
/**
|
|
107
|
+
* Gets a cached hash if available.
|
|
108
|
+
*
|
|
109
|
+
* @param {Uint8Array} data - Data to look up
|
|
110
|
+
* @returns {string | undefined} Cached hash or undefined if not cached
|
|
111
|
+
*/
|
|
112
|
+
get(data: Uint8Array): string | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Stores a hash in the cache.
|
|
115
|
+
*
|
|
116
|
+
* @param {Uint8Array} data - Original data
|
|
117
|
+
* @param {string} hash - Computed hash to cache
|
|
118
|
+
*/
|
|
119
|
+
set(data: Uint8Array, hash: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* Gets a hash from cache or computes and caches it.
|
|
122
|
+
*
|
|
123
|
+
* @description This is the recommended way to use the cache. It automatically
|
|
124
|
+
* handles cache lookup, computation, and storage.
|
|
125
|
+
*
|
|
126
|
+
* @param {Uint8Array} data - Data to hash
|
|
127
|
+
* @param {() => Promise<string> | string} compute - Function to compute hash if not cached
|
|
128
|
+
* @returns {Promise<string>} The hash (from cache or newly computed)
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const hash = await cache.getOrCompute(data, () => sha1(data))
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
getOrCompute(data: Uint8Array, compute: () => Promise<string> | string): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Synchronous version of getOrCompute for use with synchronous hash functions.
|
|
138
|
+
*
|
|
139
|
+
* @param {Uint8Array} data - Data to hash
|
|
140
|
+
* @param {() => string} compute - Function to compute hash if not cached
|
|
141
|
+
* @returns {string} The hash (from cache or newly computed)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { sha1Hex } from './sha1'
|
|
146
|
+
* const hash = cache.getOrComputeSync(data, () => sha1Hex(data))
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
getOrComputeSync(data: Uint8Array, compute: () => string): string;
|
|
150
|
+
/**
|
|
151
|
+
* Clears all entries from the cache.
|
|
152
|
+
*/
|
|
153
|
+
clear(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Gets the current number of cached entries.
|
|
156
|
+
*/
|
|
157
|
+
get size(): number;
|
|
158
|
+
/**
|
|
159
|
+
* Gets the cache hit rate as a percentage.
|
|
160
|
+
*/
|
|
161
|
+
get hitRate(): number;
|
|
162
|
+
/**
|
|
163
|
+
* Gets cache statistics.
|
|
164
|
+
*
|
|
165
|
+
* @returns {{ hits: number; misses: number; size: number; hitRate: number }}
|
|
166
|
+
*/
|
|
167
|
+
getStats(): {
|
|
168
|
+
hits: number;
|
|
169
|
+
misses: number;
|
|
170
|
+
size: number;
|
|
171
|
+
hitRate: number;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
127
174
|
/**
|
|
128
|
-
*
|
|
175
|
+
* Global hash cache instance for common use cases.
|
|
129
176
|
*
|
|
130
177
|
* @description
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* **Edge Cases**:
|
|
135
|
-
* - Empty Uint8Array returns empty string
|
|
178
|
+
* A shared cache instance that can be used across the application for
|
|
179
|
+
* caching object hashes. This is particularly useful for pack file
|
|
180
|
+
* operations where the same objects are hashed multiple times.
|
|
136
181
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
182
|
+
* **Memory Management**: The cache has a default limit of 10,000 entries.
|
|
183
|
+
* For applications with different requirements, create a custom HashCache
|
|
184
|
+
* instance with appropriate size.
|
|
139
185
|
*
|
|
140
186
|
* @example
|
|
141
187
|
* ```typescript
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
188
|
+
* import { globalHashCache, sha1 } from './utils/hash'
|
|
189
|
+
*
|
|
190
|
+
* // Use the global cache
|
|
191
|
+
* const hash = await globalHashCache.getOrCompute(data, () => sha1(data))
|
|
145
192
|
*
|
|
146
|
-
* //
|
|
147
|
-
*
|
|
148
|
-
* const sha = bytesToHex(hashBytes) // 40-char hex string
|
|
193
|
+
* // Check cache stats
|
|
194
|
+
* console.log(globalHashCache.getStats())
|
|
149
195
|
* ```
|
|
150
196
|
*/
|
|
151
|
-
export declare
|
|
197
|
+
export declare const globalHashCache: HashCache;
|
|
152
198
|
//# sourceMappingURL=hash.d.ts.map
|
package/dist/utils/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAG7D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAOhC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAOhF;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,MAAM,CAAY;IAE1B;;;;OAIG;gBACS,OAAO,GAAE,MAAc;IAKnC;;;;;;;;;OASG;IACH,OAAO,CAAC,WAAW;IAQnB;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS;IAgBzC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAczC;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAChB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GACtC,OAAO,CAAC,MAAM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