@git-stunts/git-cas 5.2.4 → 5.3.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/bin/git-cas.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { readFileSync } from 'node:fs';
4
- import { program } from 'commander';
4
+ import { program, Option } from 'commander';
5
5
  import GitPlumbing, { ShellRunnerFactory } from '@git-stunts/plumbing';
6
- import ContentAddressableStore, { EventEmitterObserver } from '../index.js';
6
+ import ContentAddressableStore, { EventEmitterObserver, CborCodec } from '../index.js';
7
7
  import Manifest from '../src/domain/value-objects/Manifest.js';
8
8
  import { createStoreProgress, createRestoreProgress } from './ui/progress.js';
9
9
  import { renderEncryptionCard } from './ui/encryption-card.js';
@@ -12,6 +12,8 @@ import { renderManifestView } from './ui/manifest-view.js';
12
12
  import { renderHeatmap } from './ui/heatmap.js';
13
13
  import { runAction } from './actions.js';
14
14
  import { filterEntries, formatTable, formatTabSeparated } from './ui/vault-list.js';
15
+ import { readPassphraseFile, promptPassphrase } from './ui/passphrase-prompt.js';
16
+ import { loadConfig, mergeConfig } from './config.js';
15
17
 
16
18
  const getJson = () => program.opts().json;
17
19
 
@@ -37,16 +39,21 @@ function readKeyFile(keyFilePath) {
37
39
  }
38
40
 
39
41
  /**
40
- * Create a CAS instance for the given working directory with an optional observability adapter.
42
+ * Create a CAS instance for the given working directory.
41
43
  *
42
44
  * @param {string} cwd
43
- * @param {{ observability?: import('../index.js').ObservabilityPort }} [opts]
45
+ * @param {Record<string, any>} [opts]
44
46
  * @returns {ContentAddressableStore}
45
47
  */
46
48
  function createCas(cwd, opts = {}) {
47
49
  const runner = ShellRunnerFactory.create();
48
50
  const plumbing = new GitPlumbing({ runner, cwd });
49
- return new ContentAddressableStore({ plumbing, observability: opts.observability });
51
+ /** @type {Record<string, any>} */
52
+ const casOpts = { plumbing, ...opts };
53
+ if (casOpts.codec === 'cbor') {
54
+ casOpts.codec = new CborCodec();
55
+ }
56
+ return new ContentAddressableStore(casOpts);
50
57
  }
51
58
 
52
59
  /**
@@ -75,13 +82,43 @@ async function deriveVaultKey(cas, metadata, passphrase) {
75
82
  }
76
83
 
77
84
  /**
78
- * Resolve passphrase from --vault-passphrase flag or GIT_CAS_PASSPHRASE env var.
85
+ * Returns true when a non-interactive passphrase source exists (flag or env).
86
+ * Does NOT trigger prompts or consume stdin.
79
87
  *
80
88
  * @param {Record<string, any>} opts
81
- * @returns {string | undefined}
89
+ * @returns {boolean}
82
90
  */
83
- function resolvePassphrase(opts) {
84
- return opts.vaultPassphrase ?? process.env.GIT_CAS_PASSPHRASE;
91
+ function hasPassphraseSource(opts) {
92
+ return Boolean(opts.vaultPassphraseFile || opts.vaultPassphrase || process.env.GIT_CAS_PASSPHRASE);
93
+ }
94
+
95
+ /**
96
+ * Resolve passphrase from (in priority order):
97
+ * 1. --vault-passphrase-file <path>
98
+ * 2. --vault-passphrase <pass>
99
+ * 3. GIT_CAS_PASSPHRASE env var
100
+ * 4. Interactive TTY prompt (if stdin is a TTY)
101
+ *
102
+ * @param {Record<string, any>} opts
103
+ * @param {{ confirm?: boolean }} [extra]
104
+ * @returns {Promise<string | undefined>}
105
+ */
106
+ async function resolvePassphrase(opts, extra = {}) {
107
+ if (opts.vaultPassphraseFile) {
108
+ return await readPassphraseFile(opts.vaultPassphraseFile);
109
+ }
110
+ if (opts.vaultPassphrase) {
111
+ if (!opts.vaultPassphrase.trim()) { throw new Error('Passphrase must not be empty'); }
112
+ return opts.vaultPassphrase;
113
+ }
114
+ if (process.env.GIT_CAS_PASSPHRASE) {
115
+ if (!process.env.GIT_CAS_PASSPHRASE.trim()) { throw new Error('Passphrase must not be empty'); }
116
+ return process.env.GIT_CAS_PASSPHRASE;
117
+ }
118
+ if (process.stdin.isTTY) {
119
+ return await promptPassphrase({ confirm: extra.confirm || false });
120
+ }
121
+ return undefined;
85
122
  }
86
123
 
87
124
  /**
@@ -95,16 +132,18 @@ async function resolveEncryptionKey(cas, opts) {
95
132
  if (opts.keyFile) {
96
133
  return readKeyFile(opts.keyFile);
97
134
  }
98
- const passphrase = resolvePassphrase(opts);
99
- if (!passphrase) {
135
+ const metadata = await cas.getVaultMetadata();
136
+ if (!metadata?.encryption) {
137
+ if (hasPassphraseSource(opts)) {
138
+ process.stderr.write('warning: passphrase ignored (vault is not encrypted)\n');
139
+ }
100
140
  return undefined;
101
141
  }
102
- const metadata = await cas.getVaultMetadata();
103
- if (metadata?.encryption) {
104
- return deriveVaultKey(cas, metadata, passphrase);
142
+ const passphrase = await resolvePassphrase(opts);
143
+ if (!passphrase) {
144
+ return undefined;
105
145
  }
106
- process.stderr.write('warning: passphrase ignored (vault is not encrypted)\n');
107
- return undefined;
146
+ return deriveVaultKey(cas, metadata, passphrase);
108
147
  }
109
148
 
110
149
  /**
@@ -177,6 +216,14 @@ function parseRecipient(value, previous) {
177
216
  return list;
178
217
  }
179
218
 
219
+ /** @param {string} v */
220
+ const parseIntFlag = (v) => {
221
+ if (!/^-?\d+$/.test(v)) { throw new Error(`Expected an integer, got "${v}"`); }
222
+ const n = Number(v);
223
+ if (!Number.isSafeInteger(n)) { throw new Error(`Expected a safe integer, got "${v}"`); }
224
+ return n;
225
+ };
226
+
180
227
  program
181
228
  .command('store <file>')
182
229
  .description('Store a file into Git CAS')
@@ -186,10 +233,20 @@ program
186
233
  .option('--tree', 'Also create a Git tree and print its OID')
187
234
  .option('--force', 'Overwrite existing vault entry')
188
235
  .option('--vault-passphrase <pass>', 'Vault-level passphrase for encryption (prefer GIT_CAS_PASSPHRASE env var)')
236
+ .option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
237
+ .option('--gzip', 'Enable gzip compression')
238
+ .addOption(new Option('--strategy <type>', 'Chunking strategy').choices(['fixed', 'cdc']))
239
+ .option('--chunk-size <n>', 'Chunk size in bytes', parseIntFlag)
240
+ .option('--concurrency <n>', 'Parallel chunk I/O operations', parseIntFlag)
241
+ .addOption(new Option('--codec <type>', 'Manifest codec').choices(['json', 'cbor']))
242
+ .option('--target-chunk-size <n>', 'CDC target chunk size', parseIntFlag)
243
+ .option('--min-chunk-size <n>', 'CDC minimum chunk size', parseIntFlag)
244
+ .option('--max-chunk-size <n>', 'CDC maximum chunk size', parseIntFlag)
245
+ .option('--merkle-threshold <n>', 'Chunk count threshold for Merkle sub-manifests', parseIntFlag)
189
246
  .option('--cwd <dir>', 'Git working directory', '.')
190
247
  .action(runAction(async (/** @type {string} */ file, /** @type {Record<string, any>} */ opts) => {
191
- if (opts.recipient && (opts.keyFile || resolvePassphrase(opts))) {
192
- throw new Error('Provide --key-file/--vault-passphrase or --recipient, not both');
248
+ if (opts.recipient && (opts.keyFile || hasPassphraseSource(opts))) {
249
+ throw new Error('Provide --key-file or a vault passphrase source (--vault-passphrase, --vault-passphrase-file, GIT_CAS_PASSPHRASE), or --recipient — not both');
193
250
  }
194
251
  if (opts.force && !opts.tree) {
195
252
  throw new Error('--force requires --tree');
@@ -197,9 +254,13 @@ program
197
254
  const json = program.opts().json;
198
255
  const quiet = program.opts().quiet || json;
199
256
  const observer = new EventEmitterObserver();
200
- const cas = createCas(opts.cwd, { observability: observer });
257
+
258
+ const config = loadConfig(opts.cwd);
259
+ const { casConfig, storeExtras } = mergeConfig(opts, config);
260
+ const cas = createCas(opts.cwd, { observability: observer, ...casConfig });
201
261
 
202
262
  const storeOpts = await buildStoreOpts(cas, file, opts);
263
+ Object.assign(storeOpts, storeExtras);
203
264
  const progress = createStoreProgress({ filePath: file, chunkSize: cas.chunkSize, quiet });
204
265
  progress.attach(observer);
205
266
  let manifest;
@@ -275,12 +336,24 @@ program
275
336
  .option('--oid <tree-oid>', 'Direct tree OID')
276
337
  .option('--key-file <path>', 'Path to 32-byte raw encryption key file')
277
338
  .option('--vault-passphrase <pass>', 'Vault-level passphrase for decryption (prefer GIT_CAS_PASSPHRASE env var)')
339
+ .option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
340
+ .option('--concurrency <n>', 'Parallel chunk I/O operations', parseIntFlag)
341
+ .option('--max-restore-buffer <n>', 'Max bytes for buffered encrypted/compressed restore', parseIntFlag)
278
342
  .option('--cwd <dir>', 'Git working directory', '.')
279
343
  .action(runAction(async (/** @type {Record<string, any>} */ opts) => {
280
344
  validateRestoreFlags(opts);
281
345
  const quiet = program.opts().quiet || program.opts().json;
282
346
  const observer = new EventEmitterObserver();
283
- const cas = createCas(opts.cwd, { observability: observer });
347
+
348
+ const config = loadConfig(opts.cwd);
349
+ /** @type {Record<string, any>} */
350
+ const casConfig = {};
351
+ const concurrency = opts.concurrency ?? config.concurrency;
352
+ const maxRestoreBufferSize = opts.maxRestoreBuffer ?? config.maxRestoreBufferSize;
353
+ if (concurrency !== undefined) { casConfig.concurrency = concurrency; }
354
+ if (maxRestoreBufferSize !== undefined) { casConfig.maxRestoreBufferSize = maxRestoreBufferSize; }
355
+
356
+ const cas = createCas(opts.cwd, { observability: observer, ...casConfig });
284
357
  const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
285
358
  const manifest = await cas.readManifest({ treeOid });
286
359
 
@@ -345,13 +418,14 @@ vault
345
418
  .command('init')
346
419
  .description('Initialize the vault')
347
420
  .option('--vault-passphrase <pass>', 'Passphrase for vault-level encryption (prefer GIT_CAS_PASSPHRASE env var)')
348
- .option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)', 'pbkdf2')
421
+ .option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
422
+ .addOption(new Option('--algorithm <alg>', 'KDF algorithm').choices(['pbkdf2', 'scrypt']).default('pbkdf2'))
349
423
  .option('--cwd <dir>', 'Git working directory', '.')
350
424
  .action(runAction(async (/** @type {Record<string, any>} */ opts) => {
351
425
  const cas = createCas(opts.cwd);
352
426
  /** @type {{ passphrase?: string, kdfOptions?: { algorithm: 'pbkdf2' | 'scrypt' } }} */
353
427
  const initOpts = {};
354
- const passphrase = resolvePassphrase(opts);
428
+ const passphrase = await resolvePassphrase(opts, { confirm: true });
355
429
  if (passphrase) {
356
430
  initOpts.passphrase = passphrase;
357
431
  initOpts.kdfOptions = { algorithm: /** @type {'pbkdf2' | 'scrypt'} */ (opts.algorithm) };
@@ -478,19 +552,43 @@ vault
478
552
  // ---------------------------------------------------------------------------
479
553
  // vault rotate
480
554
  // ---------------------------------------------------------------------------
555
+ /**
556
+ * Resolve old and new passphrases for vault rotate from flags/files.
557
+ *
558
+ * @param {Record<string, any>} opts
559
+ * @returns {Promise<{ oldPassphrase: string, newPassphrase: string }>}
560
+ */
561
+ async function resolveRotatePassphrases(opts) {
562
+ if (opts.oldPassphraseFile === '-' && opts.newPassphraseFile === '-') {
563
+ throw new Error('Cannot read both old and new passphrase from stdin');
564
+ }
565
+ const oldPassphrase = opts.oldPassphraseFile
566
+ ? await readPassphraseFile(opts.oldPassphraseFile)
567
+ : opts.oldPassphrase;
568
+ const newPassphrase = opts.newPassphraseFile
569
+ ? await readPassphraseFile(opts.newPassphraseFile)
570
+ : opts.newPassphrase;
571
+ if (!oldPassphrase) { throw new Error('Old passphrase required (--old-passphrase or --old-passphrase-file)'); }
572
+ if (!newPassphrase) { throw new Error('New passphrase required (--new-passphrase or --new-passphrase-file)'); }
573
+ return { oldPassphrase, newPassphrase };
574
+ }
575
+
481
576
  vault
482
577
  .command('rotate')
483
578
  .description('Rotate vault-level encryption passphrase')
484
- .requiredOption('--old-passphrase <pass>', 'Current vault passphrase')
485
- .requiredOption('--new-passphrase <pass>', 'New vault passphrase')
486
- .option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)')
579
+ .option('--old-passphrase <pass>', 'Current vault passphrase')
580
+ .option('--new-passphrase <pass>', 'New vault passphrase')
581
+ .option('--old-passphrase-file <path>', 'Read old passphrase from file (- for stdin)')
582
+ .option('--new-passphrase-file <path>', 'Read new passphrase from file (- for stdin)')
583
+ .addOption(new Option('--algorithm <alg>', 'KDF algorithm').choices(['pbkdf2', 'scrypt']))
487
584
  .option('--cwd <dir>', 'Git working directory', '.')
488
585
  .action(runAction(async (/** @type {Record<string, any>} */ opts) => {
586
+ const { oldPassphrase, newPassphrase } = await resolveRotatePassphrases(opts);
489
587
  const cas = createCas(opts.cwd);
490
588
  /** @type {{ oldPassphrase: string, newPassphrase: string, kdfOptions?: { algorithm: 'pbkdf2' | 'scrypt' } }} */
491
589
  const rotateOpts = {
492
- oldPassphrase: opts.oldPassphrase,
493
- newPassphrase: opts.newPassphrase,
590
+ oldPassphrase,
591
+ newPassphrase,
494
592
  };
495
593
  if (opts.algorithm) {
496
594
  rotateOpts.kdfOptions = { algorithm: /** @type {'pbkdf2' | 'scrypt'} */ (opts.algorithm) };
@@ -0,0 +1,100 @@
1
+ import { createInterface } from 'node:readline';
2
+ import { readFile, stat } from 'node:fs/promises';
3
+
4
+ /**
5
+ * Prompts for a passphrase on stderr with echo disabled.
6
+ *
7
+ * @param {Object} [options]
8
+ * @param {boolean} [options.confirm=false] - Require confirmation (ask twice).
9
+ * @returns {Promise<string>}
10
+ */
11
+ export async function promptPassphrase({ confirm = false } = {}) {
12
+ if (!process.stdin.isTTY) {
13
+ throw new Error(
14
+ 'Cannot prompt for passphrase: stdin is not a TTY. ' +
15
+ 'Use --vault-passphrase-file or GIT_CAS_PASSPHRASE.',
16
+ );
17
+ }
18
+ const pass = await readHidden('Passphrase: ');
19
+ if (!pass) {
20
+ throw new Error('Passphrase must not be empty');
21
+ }
22
+ if (confirm) {
23
+ const pass2 = await readHidden('Confirm passphrase: ');
24
+ if (pass !== pass2) {
25
+ throw new Error('Passphrases do not match');
26
+ }
27
+ }
28
+ return pass;
29
+ }
30
+
31
+ /**
32
+ * Warns to stderr if the file at `filePath` is group- or world-readable.
33
+ *
34
+ * @param {string} filePath
35
+ */
36
+ async function warnInsecurePermissions(filePath) {
37
+ try {
38
+ const st = await stat(filePath);
39
+ if (st.mode & 0o077) {
40
+ process.stderr.write(
41
+ `warning: ${filePath} has insecure permissions — consider chmod 600\n`,
42
+ );
43
+ }
44
+ } catch {
45
+ // stat may fail on non-Unix or non-existent paths; silently skip.
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Reads a passphrase from a file path, or from stdin when path is '-'.
51
+ *
52
+ * @param {string} filePath - File path, or '-' for stdin.
53
+ * @returns {Promise<string>}
54
+ */
55
+ export async function readPassphraseFile(filePath) {
56
+ if (filePath === '-') {
57
+ const chunks = [];
58
+ for await (const chunk of process.stdin) {
59
+ chunks.push(chunk);
60
+ }
61
+ const stdinResult = Buffer.concat(chunks).toString('utf8').replace(/\r?\n$/, '');
62
+ if (!stdinResult) { throw new Error('Passphrase must not be empty'); }
63
+ return stdinResult;
64
+ }
65
+ await warnInsecurePermissions(filePath);
66
+ const content = await readFile(filePath, 'utf8');
67
+ const trimmed = content.replace(/\r?\n$/, '');
68
+ if (!trimmed) { throw new Error('Passphrase must not be empty'); }
69
+ return trimmed;
70
+ }
71
+
72
+ /**
73
+ * Reads a line with echo disabled.
74
+ *
75
+ * Uses Node.js private API `rl._writeToOutput` to suppress echo —
76
+ * this is an intentional access to an undocumented API for password
77
+ * input, as there is no public readline API for hidden input.
78
+ *
79
+ * @param {string} prompt - Prompt text.
80
+ * @returns {Promise<string>}
81
+ */
82
+ function readHidden(prompt) {
83
+ return new Promise((resolve, reject) => {
84
+ const rl = createInterface({
85
+ input: process.stdin,
86
+ output: process.stderr,
87
+ terminal: true,
88
+ });
89
+ process.stderr.write(prompt);
90
+ rl.on('error', reject);
91
+ rl.on('close', () => reject(new Error('readline closed without input')));
92
+ rl.question('', (answer) => {
93
+ rl.removeAllListeners('close');
94
+ rl.close();
95
+ process.stderr.write('\n');
96
+ resolve(answer);
97
+ });
98
+ rl._writeToOutput = () => {};
99
+ });
100
+ }
package/index.d.ts CHANGED
@@ -171,6 +171,8 @@ export interface ContentAddressableStoreOptions {
171
171
  concurrency?: number;
172
172
  chunking?: ChunkingConfig;
173
173
  chunker?: ChunkingPort;
174
+ /** Maximum bytes to buffer during encrypted/compressed restore. @default 536870912 (512 MiB) */
175
+ maxRestoreBufferSize?: number;
174
176
  }
175
177
 
176
178
  /** A single vault entry. */
@@ -182,6 +184,8 @@ export interface VaultEntry {
182
184
  /** Vault metadata stored in .vault.json. */
183
185
  export interface VaultMetadata {
184
186
  version: number;
187
+ /** Number of encrypted store operations performed with this vault key. */
188
+ encryptionCount?: number;
185
189
  encryption?: {
186
190
  cipher: string;
187
191
  kdf: {
@@ -213,6 +217,7 @@ export declare class VaultService {
213
217
  persistence: GitPersistencePortBase;
214
218
  ref: GitRefPortBase;
215
219
  crypto: CryptoPortBase;
220
+ observability?: ObservabilityPort;
216
221
  });
217
222
 
218
223
  /** Validates a vault slug. Throws CasError with code INVALID_SLUG on failure. */
@@ -341,10 +346,20 @@ export default class ContentAddressableStore {
341
346
 
342
347
  readManifest(options: { treeOid: string }): Promise<Manifest>;
343
348
 
349
+ inspectAsset(options: {
350
+ treeOid: string;
351
+ }): Promise<{ slug: string; chunksOrphaned: number }>;
352
+
353
+ /** @deprecated Use {@link inspectAsset} instead. */
344
354
  deleteAsset(options: {
345
355
  treeOid: string;
346
356
  }): Promise<{ slug: string; chunksOrphaned: number }>;
347
357
 
358
+ collectReferencedChunks(options: {
359
+ treeOids: string[];
360
+ }): Promise<{ referenced: Set<string>; total: number }>;
361
+
362
+ /** @deprecated Use {@link collectReferencedChunks} instead. */
348
363
  findOrphanedChunks(options: {
349
364
  treeOids: string[];
350
365
  }): Promise<{ referenced: Set<string>; total: number }>;
package/index.js CHANGED
@@ -64,14 +64,15 @@ export default class ContentAddressableStore {
64
64
  * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
65
65
  * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Chunking strategy config.
66
66
  * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance (advanced).
67
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes for encrypted/compressed restores (default 512 MiB).
67
68
  */
68
- constructor({ plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker }) {
69
- this.#config = { plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker };
69
+ constructor({ plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker, maxRestoreBufferSize }) {
70
+ this.#config = { plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker, maxRestoreBufferSize };
70
71
  this.service = null;
71
72
  this.#servicePromise = null;
72
73
  }
73
74
 
74
- /** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: * }} */
75
+ /** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number }} */
75
76
  #config;
76
77
  /** @type {VaultService|null} */
77
78
  #vault = null;
@@ -111,13 +112,14 @@ export default class ContentAddressableStore {
111
112
  merkleThreshold: cfg.merkleThreshold,
112
113
  concurrency: cfg.concurrency,
113
114
  chunker,
115
+ maxRestoreBufferSize: cfg.maxRestoreBufferSize,
114
116
  });
115
117
 
116
118
  const ref = new GitRefAdapter({
117
119
  plumbing: cfg.plumbing,
118
120
  policy: cfg.policy,
119
121
  });
120
- this.#vault = new VaultService({ persistence, ref, crypto });
122
+ this.#vault = new VaultService({ persistence, ref, crypto, observability: this.service.observability });
121
123
 
122
124
  return this.service;
123
125
  }
@@ -314,7 +316,18 @@ export default class ContentAddressableStore {
314
316
  }
315
317
 
316
318
  /**
317
- * Returns deletion metadata for an asset stored in a Git tree.
319
+ * Reads a manifest from a Git tree and returns inspection metadata.
320
+ * @param {Object} options
321
+ * @param {string} options.treeOid - Git tree OID of the asset.
322
+ * @returns {Promise<{ slug: string, chunksOrphaned: number }>}
323
+ */
324
+ async inspectAsset(options) {
325
+ const service = await this.#getService();
326
+ return await service.inspectAsset(options);
327
+ }
328
+
329
+ /**
330
+ * @deprecated Use {@link inspectAsset} instead.
318
331
  * @param {Object} options
319
332
  * @param {string} options.treeOid - Git tree OID of the asset.
320
333
  * @returns {Promise<{ slug: string, chunksOrphaned: number }>}
@@ -330,6 +343,17 @@ export default class ContentAddressableStore {
330
343
  * @param {string[]} options.treeOids - Git tree OIDs to analyze.
331
344
  * @returns {Promise<{ referenced: Set<string>, total: number }>}
332
345
  */
346
+ async collectReferencedChunks(options) {
347
+ const service = await this.#getService();
348
+ return await service.collectReferencedChunks(options);
349
+ }
350
+
351
+ /**
352
+ * @deprecated Use {@link collectReferencedChunks} instead.
353
+ * @param {Object} options
354
+ * @param {string[]} options.treeOids - Git tree OIDs to analyze.
355
+ * @returns {Promise<{ referenced: Set<string>, total: number }>}
356
+ */
333
357
  async findOrphanedChunks(options) {
334
358
  const service = await this.#getService();
335
359
  return await service.findOrphanedChunks(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@git-stunts/git-cas",
3
- "version": "5.2.4",
3
+ "version": "5.3.1",
4
4
  "description": "Content-addressed storage backed by Git's object database, with optional encryption and pluggable codecs",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -15,6 +15,8 @@ export default class CasError extends Error {
15
15
  this.name = this.constructor.name;
16
16
  this.code = code;
17
17
  this.meta = meta;
18
- Error.captureStackTrace(this, this.constructor);
18
+ if (Error.captureStackTrace) {
19
+ Error.captureStackTrace(this, this.constructor);
20
+ }
19
21
  }
20
22
  }
@@ -46,6 +46,13 @@ export interface ObservabilityPort {
46
46
  span(name: string): { end(meta?: Record<string, unknown>): void };
47
47
  }
48
48
 
49
+ /** Port interface for chunking strategies (fixed, CDC, etc.). */
50
+ export interface ChunkingPort {
51
+ chunk(source: AsyncIterable<Buffer>): AsyncIterable<Buffer>;
52
+ readonly strategy: string;
53
+ readonly params: Record<string, unknown>;
54
+ }
55
+
49
56
  /** Constructor options for {@link CasService}. */
50
57
  export interface CasServiceOptions {
51
58
  persistence: GitPersistencePort;
@@ -55,6 +62,8 @@ export interface CasServiceOptions {
55
62
  chunkSize?: number;
56
63
  merkleThreshold?: number;
57
64
  concurrency?: number;
65
+ chunker?: ChunkingPort;
66
+ maxRestoreBufferSize?: number;
58
67
  }
59
68
 
60
69
  /** Options for key derivation. */
@@ -90,6 +99,7 @@ export default class CasService {
90
99
  readonly chunkSize: number;
91
100
  readonly merkleThreshold: number;
92
101
  readonly concurrency: number;
102
+ readonly maxRestoreBufferSize: number;
93
103
 
94
104
  constructor(options: CasServiceOptions);
95
105
 
@@ -131,10 +141,20 @@ export default class CasService {
131
141
 
132
142
  readManifest(options: { treeOid: string }): Promise<Manifest>;
133
143
 
144
+ inspectAsset(options: {
145
+ treeOid: string;
146
+ }): Promise<{ slug: string; chunksOrphaned: number }>;
147
+
148
+ /** @deprecated Use {@link inspectAsset} instead. */
134
149
  deleteAsset(options: {
135
150
  treeOid: string;
136
151
  }): Promise<{ slug: string; chunksOrphaned: number }>;
137
152
 
153
+ collectReferencedChunks(options: {
154
+ treeOids: string[];
155
+ }): Promise<{ referenced: Set<string>; total: number }>;
156
+
157
+ /** @deprecated Use {@link collectReferencedChunks} instead. */
138
158
  findOrphanedChunks(options: {
139
159
  treeOids: string[];
140
160
  }): Promise<{ referenced: Set<string>; total: number }>;