@git-stunts/git-cas 6.0.0 → 6.1.0

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.
@@ -31,20 +31,25 @@ const FILE_NOT_FOUND_CODE = 'ENOENT';
31
31
  * @param {{ algorithm: 'gzip' }} [options.compression] - Enable compression.
32
32
  * @param {Array<{label: string, key: Uint8Array}>} [options.recipients] - Envelope recipients.
33
33
  * @param {number} [options.merkleThreshold] - Per-operation chunk count threshold for Merkle manifests.
34
+ * @param {import('../../ports/ChunkingPort.js').default} [options.chunker] - Per-operation chunker override.
34
35
  * @returns {Promise<Manifest>} The resulting manifest.
35
36
  */
36
- export async function storeFile(service, {
37
- filePath,
38
- slug,
39
- filename,
40
- encryptionKey,
41
- passphrase,
42
- encryption,
43
- kdfOptions,
44
- compression,
45
- recipients,
46
- merkleThreshold,
47
- }) {
37
+ export async function storeFile(
38
+ service,
39
+ {
40
+ filePath,
41
+ slug,
42
+ filename,
43
+ encryptionKey,
44
+ passphrase,
45
+ encryption,
46
+ kdfOptions,
47
+ compression,
48
+ recipients,
49
+ merkleThreshold,
50
+ chunker,
51
+ }
52
+ ) {
48
53
  const source = createReadStream(filePath);
49
54
  return await service.store({
50
55
  source,
@@ -57,6 +62,7 @@ export async function storeFile(service, {
57
62
  compression,
58
63
  recipients,
59
64
  merkleThreshold,
65
+ chunker,
60
66
  });
61
67
  }
62
68
 
@@ -73,9 +79,15 @@ export async function storeFile(service, {
73
79
  * @param {string} options.baseDirectory - The permitted base directory for restoration (e.g. repo root).
74
80
  * @returns {Promise<{ bytesWritten: number }>}
75
81
  */
76
- export async function restoreFile(service, { manifest, encryptionKey, passphrase, outputPath, baseDirectory }) {
82
+ export async function restoreFile(
83
+ service,
84
+ { manifest, encryptionKey, passphrase, outputPath, baseDirectory }
85
+ ) {
77
86
  if (!baseDirectory) {
78
- throw new CasError('baseDirectory is required for safe restoration', ErrorCodes.INVALID_OPTIONS);
87
+ throw new CasError(
88
+ 'baseDirectory is required for safe restoration',
89
+ ErrorCodes.INVALID_OPTIONS
90
+ );
79
91
  }
80
92
 
81
93
  const safeOutputPath = await resolveSafeRestorePath({ baseDirectory, outputPath });
@@ -119,7 +131,7 @@ async function resolveSafeRestorePath({ baseDirectory, outputPath }) {
119
131
  throw new CasError(
120
132
  `Restoration path "${outputPath}" escapes base directory "${baseDirectory}"`,
121
133
  ErrorCodes.SECURITY_BOUNDARY_VIOLATION,
122
- { outputPath, baseDirectory },
134
+ { outputPath, baseDirectory }
123
135
  );
124
136
  }
125
137
  return canonicalPath;
@@ -160,25 +172,18 @@ async function canonicalizeTargetPath(targetPath) {
160
172
  * @param {{ manifest: Manifest, outputPath: string, source: AsyncIterable<Uint8Array>, encryptionMeta?: EncryptionMeta }} options
161
173
  * @returns {Promise<{ bytesWritten: number }>}
162
174
  */
163
- async function restoreBufferedFile(service, {
164
- manifest,
165
- outputPath,
166
- source,
167
- encryptionMeta,
168
- }) {
175
+ async function restoreBufferedFile(service, { manifest, outputPath, source, encryptionMeta }) {
169
176
  let bytesWritten = 0;
170
177
  const outputDir = path.dirname(outputPath);
171
178
  const tempDir = await mkdtemp(path.join(outputDir, '.git-cas-restore-'));
172
179
  const tempPath = path.join(tempDir, path.basename(outputPath));
173
180
 
174
181
  try {
175
- const counter = createByteCounter((n) => { bytesWritten += n; });
182
+ const counter = createByteCounter((n) => {
183
+ bytesWritten += n;
184
+ });
176
185
 
177
- await pipeline(
178
- Readable.from(source),
179
- counter,
180
- createWriteStream(tempPath),
181
- );
186
+ await pipeline(Readable.from(source), counter, createWriteStream(tempPath));
182
187
 
183
188
  await rename(tempPath, outputPath);
184
189
  service.observability.metric('file', {
@@ -205,10 +210,7 @@ async function restoreBufferedFile(service, {
205
210
  */
206
211
  function isInsideBaseDirectory(resolvedPath, resolvedBase) {
207
212
  const relativePath = path.relative(resolvedBase, resolvedPath);
208
- return (
209
- relativePath === '' ||
210
- (!relativePath.startsWith('..') && !path.isAbsolute(relativePath))
211
- );
213
+ return relativePath === '' || (!relativePath.startsWith('..') && !path.isAbsolute(relativePath));
212
214
  }
213
215
 
214
216
  /**
@@ -4,6 +4,7 @@ import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import GitPersistencePort from '../../ports/GitPersistencePort.js';
6
6
  import { CasError, createCasError, ErrorCodes } from '../../domain/errors/index.js';
7
+ import { errorDetailsText } from '../../domain/helpers/gitRefErrors.js';
7
8
 
8
9
  /**
9
10
  * Default resilience policy: 30 s timeout (no retry).
@@ -180,6 +181,27 @@ export default class GitPersistenceAdapter extends GitPersistencePort {
180
181
  }
181
182
  }
182
183
 
184
+ /**
185
+ * @override
186
+ * @param {string} oid - Git object ID.
187
+ * @returns {Promise<string>} Git object type.
188
+ */
189
+ async readObjectType(oid) {
190
+ try {
191
+ return await this.policy.execute(() =>
192
+ this.plumbing.execute({ args: ['cat-file', '-t', oid] }),
193
+ );
194
+ } catch (err) {
195
+ if (isMissingGitObjectError(err)) {
196
+ throw new CasError(`Git object not found: ${oid}`, ErrorCodes.GIT_OBJECT_NOT_FOUND, {
197
+ oid,
198
+ originalError: err,
199
+ });
200
+ }
201
+ throw err;
202
+ }
203
+ }
204
+
183
205
  /**
184
206
  * Bun can surface unhandled EPIPE writes when large buffers are fed through
185
207
  * `git hash-object --stdin`. Write the blob to a temp file and hash the file
@@ -310,3 +332,10 @@ export default class GitPersistenceAdapter extends GitPersistencePort {
310
332
  };
311
333
  }
312
334
  }
335
+
336
+ function isMissingGitObjectError(err) {
337
+ const message = errorDetailsText(err).toLowerCase();
338
+ return message.includes('could not get object info') ||
339
+ message.includes('not a valid object name') ||
340
+ message.includes('bad object');
341
+ }
@@ -64,6 +64,26 @@ export default class GitRefAdapter extends GitRefPort {
64
64
  );
65
65
  }
66
66
 
67
+ /**
68
+ * @override
69
+ * @param {string} commitOid - Git commit OID.
70
+ * @returns {Promise<string[]>} Direct parent OIDs.
71
+ */
72
+ async resolveParents(commitOid) {
73
+ const line = await this.policy.execute(() =>
74
+ this.plumbing.execute({ args: ['rev-list', '--parents', '-n', '1', commitOid] }),
75
+ );
76
+ const [resolvedCommit, ...parents] = line.trim().split(/\s+/u);
77
+ if (!resolvedCommit) {
78
+ throw new CasError(
79
+ `Git commit not found: ${commitOid}`,
80
+ ErrorCodes.GIT_ERROR,
81
+ { commitOid },
82
+ );
83
+ }
84
+ return parents;
85
+ }
86
+
67
87
  /**
68
88
  * @override
69
89
  * @param {Object} options
@@ -15,7 +15,7 @@ import CdcChunker from './CdcChunker.js';
15
15
  *
16
16
  * @param {Object} options
17
17
  * @param {import('../../ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance (advanced).
18
- * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Declarative chunking strategy config.
18
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Declarative chunking strategy config.
19
19
  * @returns {import('../../ports/ChunkingPort.js').default|undefined}
20
20
  */
21
21
  export default function resolveChunker({ chunker, chunking } = {}) {
@@ -35,10 +35,12 @@ export default function resolveChunker({ chunker, chunking } = {}) {
35
35
  }
36
36
  // 'fixed' with valid chunkSize → FixedChunker; otherwise fall through
37
37
  // to CasService's built-in FixedChunker default.
38
- if (chunking.strategy === 'fixed'
39
- && typeof chunking.chunkSize === 'number'
40
- && Number.isFinite(chunking.chunkSize)
41
- && chunking.chunkSize > 0) {
38
+ if (
39
+ chunking.strategy === 'fixed' &&
40
+ typeof chunking.chunkSize === 'number' &&
41
+ Number.isFinite(chunking.chunkSize) &&
42
+ chunking.chunkSize > 0
43
+ ) {
42
44
  return new FixedChunker({ chunkSize: chunking.chunkSize });
43
45
  }
44
46
  }
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = '6.0.0';
1
+ export const PACKAGE_VERSION = '6.1.0';
@@ -68,4 +68,13 @@ export default class GitPersistencePort {
68
68
  iterateTree(_treeOid) {
69
69
  throw new Error('Not implemented');
70
70
  }
71
+
72
+ /**
73
+ * Reads the Git object type without materializing object content.
74
+ * @param {string} _oid - Git object ID.
75
+ * @returns {Promise<string>} Git object type such as `blob`, `tree`, or `commit`.
76
+ */
77
+ async readObjectType(_oid) {
78
+ throw new Error('Not implemented');
79
+ }
71
80
  }
@@ -22,6 +22,15 @@ export default class GitRefPort {
22
22
  throw new Error('Not implemented');
23
23
  }
24
24
 
25
+ /**
26
+ * Resolves the direct parent OIDs from a commit OID.
27
+ * @param {string} _commitOid - Git commit OID.
28
+ * @returns {Promise<string[]>} Direct parent OIDs; empty for a root commit.
29
+ */
30
+ async resolveParents(_commitOid) {
31
+ throw new Error('Not implemented');
32
+ }
33
+
25
34
  /**
26
35
  * Creates a Git commit object.
27
36
  * @param {Object} _options