@git-stunts/git-cas 5.3.2 → 6.0.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/ADVANCED_GUIDE.md +1027 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +449 -5
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +926 -0
- package/README.md +106 -366
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +70 -21
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +595 -449
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +1255 -212
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +367 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2254 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +273 -80
- package/index.js +220 -59
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +153 -53
- package/src/domain/services/CasService.js +322 -837
- package/src/domain/services/ChunkRepository.js +268 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +180 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +10 -6
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import ChunkingPort from '../../ports/ChunkingPort.js';
|
|
19
|
+
import { copyBytes, normalizeByteChunk } from '../../domain/bytes/ByteLayout.js';
|
|
19
20
|
|
|
20
21
|
// ---------------------------------------------------------------------------
|
|
21
22
|
// Buzhash byte-table (256 entries, deterministic)
|
|
@@ -73,11 +74,15 @@ const WINDOW_MASK = WINDOW_SIZE - 1; // 63, for fast modulo
|
|
|
73
74
|
* @property {Uint8Array} win - Sliding window ring buffer.
|
|
74
75
|
* @property {number} winPos - Current write position in `win`.
|
|
75
76
|
* @property {number} hashFed - Bytes fed since last reset.
|
|
76
|
-
* @property {
|
|
77
|
+
* @property {Uint8Array} chunkBuf - Pre-allocated chunk output buffer.
|
|
77
78
|
* @property {number} chunkLen - Bytes written to chunkBuf so far.
|
|
78
79
|
* @property {number} minSize - Minimum chunk size.
|
|
79
80
|
* @property {number} maxSize - Maximum chunk size.
|
|
80
|
-
* @property {number} mask - Boundary detection mask.
|
|
81
|
+
* @property {number} mask - Boundary detection mask (single-mask mode).
|
|
82
|
+
* @property {number} hardMask - Stricter mask for below-target (normalized mode).
|
|
83
|
+
* @property {number} easyMask - Looser mask for above-target (normalized mode).
|
|
84
|
+
* @property {number} targetSize - Target chunk size (normalized mode).
|
|
85
|
+
* @property {boolean} normalized - Whether dual-mask normalization is active.
|
|
81
86
|
*/
|
|
82
87
|
|
|
83
88
|
/**
|
|
@@ -101,7 +106,7 @@ function resetState(st) {
|
|
|
101
106
|
* Uses a simplified hash update (no outgoing-byte removal).
|
|
102
107
|
*
|
|
103
108
|
* @param {ChunkState} st
|
|
104
|
-
* @param {
|
|
109
|
+
* @param {Uint8Array} buf - Source bytes being processed.
|
|
105
110
|
* @param {number} srcPos - Current read offset in `buf`.
|
|
106
111
|
* @returns {number} Updated srcPos.
|
|
107
112
|
*/
|
|
@@ -129,7 +134,7 @@ function fillWindow(st, buf, srcPos) {
|
|
|
129
134
|
* Bulk-copies bytes into the chunk buffer while updating the hash.
|
|
130
135
|
*
|
|
131
136
|
* @param {ChunkState} st
|
|
132
|
-
* @param {
|
|
137
|
+
* @param {Uint8Array} buf
|
|
133
138
|
* @param {number} srcPos
|
|
134
139
|
* @returns {number} Updated srcPos.
|
|
135
140
|
*/
|
|
@@ -140,8 +145,13 @@ function feedPreMin(st, buf, srcPos) {
|
|
|
140
145
|
const end = srcPos + n;
|
|
141
146
|
const table = BUZ_TABLE;
|
|
142
147
|
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
copyBytes({
|
|
149
|
+
source: buf,
|
|
150
|
+
target: st.chunkBuf,
|
|
151
|
+
targetOffset: st.chunkLen,
|
|
152
|
+
sourceStart: srcPos,
|
|
153
|
+
sourceEnd: end,
|
|
154
|
+
});
|
|
145
155
|
|
|
146
156
|
// Feed bytes into rolling hash (window is full)
|
|
147
157
|
while (srcPos < end) {
|
|
@@ -159,12 +169,12 @@ function feedPreMin(st, buf, srcPos) {
|
|
|
159
169
|
* Phase 3 — scan for a content-defined boundary in [minSize, maxSize).
|
|
160
170
|
*
|
|
161
171
|
* @param {ChunkState} st
|
|
162
|
-
* @param {
|
|
172
|
+
* @param {Uint8Array} buf
|
|
163
173
|
* @param {number} srcPos
|
|
164
174
|
* @returns {{ srcPos: number, found: boolean }}
|
|
165
175
|
*/
|
|
166
176
|
function scanBoundary(st, buf, srcPos) {
|
|
167
|
-
const {
|
|
177
|
+
const { maxSize, normalized, hardMask, easyMask, targetSize, mask } = st;
|
|
168
178
|
const table = BUZ_TABLE;
|
|
169
179
|
const limit = buf.length < (srcPos + maxSize - st.chunkLen)
|
|
170
180
|
? buf.length
|
|
@@ -183,7 +193,8 @@ function scanBoundary(st, buf, srcPos) {
|
|
|
183
193
|
chunkBuf[cl++] = byte;
|
|
184
194
|
srcPos++;
|
|
185
195
|
|
|
186
|
-
|
|
196
|
+
const m = normalized ? (cl < targetSize ? hardMask : easyMask) : mask;
|
|
197
|
+
if ((h & m) === 0) {
|
|
187
198
|
st.hash = h;
|
|
188
199
|
st.winPos = wp;
|
|
189
200
|
st.chunkLen = cl;
|
|
@@ -204,11 +215,11 @@ function scanBoundary(st, buf, srcPos) {
|
|
|
204
215
|
* was found within this buffer).
|
|
205
216
|
*
|
|
206
217
|
* @param {ChunkState} st
|
|
207
|
-
* @param {
|
|
208
|
-
* @returns {
|
|
218
|
+
* @param {Uint8Array} buf
|
|
219
|
+
* @returns {Uint8Array[]} Completed chunks ready to yield.
|
|
209
220
|
*/
|
|
210
221
|
function processBuf(st, buf) {
|
|
211
|
-
/** @type {
|
|
222
|
+
/** @type {Uint8Array[]} */
|
|
212
223
|
const completed = [];
|
|
213
224
|
let srcPos = 0;
|
|
214
225
|
|
|
@@ -229,7 +240,7 @@ function processBuf(st, buf) {
|
|
|
229
240
|
srcPos = result.srcPos;
|
|
230
241
|
|
|
231
242
|
if (result.found || st.chunkLen >= st.maxSize) {
|
|
232
|
-
completed.push(
|
|
243
|
+
completed.push(new Uint8Array(st.chunkBuf.subarray(0, st.chunkLen)));
|
|
233
244
|
resetState(st);
|
|
234
245
|
}
|
|
235
246
|
}
|
|
@@ -246,17 +257,26 @@ function processBuf(st, buf) {
|
|
|
246
257
|
* @property {number} [minChunkSize=65536] - Minimum chunk size in bytes (64 KiB).
|
|
247
258
|
* @property {number} [maxChunkSize=1048576] - Maximum chunk size in bytes (1 MiB).
|
|
248
259
|
* @property {number} [targetChunkSize=262144] - Target (average) chunk size in bytes (256 KiB).
|
|
260
|
+
* @property {boolean} [normalized=true] - Enable FastCDC dual-mask normalization.
|
|
249
261
|
*/
|
|
250
262
|
|
|
251
263
|
/**
|
|
252
264
|
* CDC chunker that uses a Buzhash rolling hash to find content-defined
|
|
253
265
|
* chunk boundaries within an async byte stream.
|
|
266
|
+
*
|
|
267
|
+
* When `normalized` is true (the default), a dual-mask strategy is used:
|
|
268
|
+
* a stricter mask below the target size and a looser mask above it. This
|
|
269
|
+
* concentrates the chunk size distribution around the target, improving
|
|
270
|
+
* deduplication efficiency.
|
|
254
271
|
*/
|
|
255
272
|
export default class CdcChunker extends ChunkingPort {
|
|
256
273
|
/** @type {number} */ #minChunkSize;
|
|
257
274
|
/** @type {number} */ #maxChunkSize;
|
|
258
275
|
/** @type {number} */ #targetChunkSize;
|
|
259
276
|
/** @type {number} */ #mask;
|
|
277
|
+
/** @type {number} */ #hardMask;
|
|
278
|
+
/** @type {number} */ #easyMask;
|
|
279
|
+
/** @type {boolean} */ #normalized;
|
|
260
280
|
|
|
261
281
|
/**
|
|
262
282
|
* @param {CdcChunkerOptions} [options]
|
|
@@ -265,6 +285,7 @@ export default class CdcChunker extends ChunkingPort {
|
|
|
265
285
|
minChunkSize = 65_536,
|
|
266
286
|
maxChunkSize = 1_048_576,
|
|
267
287
|
targetChunkSize = 262_144,
|
|
288
|
+
normalized = true,
|
|
268
289
|
} = {}) {
|
|
269
290
|
super();
|
|
270
291
|
if (minChunkSize > maxChunkSize) {
|
|
@@ -286,11 +307,18 @@ export default class CdcChunker extends ChunkingPort {
|
|
|
286
307
|
this.#minChunkSize = minChunkSize;
|
|
287
308
|
this.#maxChunkSize = maxChunkSize;
|
|
288
309
|
this.#targetChunkSize = targetChunkSize;
|
|
310
|
+
this.#normalized = normalized;
|
|
289
311
|
|
|
290
312
|
// Mask: nearest power-of-2 minus 1 that is <= targetChunkSize.
|
|
291
313
|
// E.g. target 262144 (2^18) -> mask 0x3FFFF (2^18 - 1).
|
|
292
314
|
const bits = Math.floor(Math.log2(targetChunkSize));
|
|
293
315
|
this.#mask = ((1 << bits) - 1) >>> 0;
|
|
316
|
+
|
|
317
|
+
// Dual-mask for normalized mode (FastCDC):
|
|
318
|
+
// hardMask: more bits → less likely to match (below target)
|
|
319
|
+
// easyMask: fewer bits → more likely to match (above target)
|
|
320
|
+
this.#hardMask = ((1 << Math.min(bits + 1, 31)) - 1) >>> 0;
|
|
321
|
+
this.#easyMask = ((1 << Math.max(bits - 1, 1)) - 1) >>> 0;
|
|
294
322
|
}
|
|
295
323
|
|
|
296
324
|
/** @override */
|
|
@@ -304,18 +332,19 @@ export default class CdcChunker extends ChunkingPort {
|
|
|
304
332
|
target: this.#targetChunkSize,
|
|
305
333
|
min: this.#minChunkSize,
|
|
306
334
|
max: this.#maxChunkSize,
|
|
335
|
+
normalized: this.#normalized,
|
|
307
336
|
};
|
|
308
337
|
}
|
|
309
338
|
|
|
310
339
|
/**
|
|
311
340
|
* Splits an async byte stream into content-defined chunks.
|
|
312
341
|
*
|
|
313
|
-
* Yields `
|
|
342
|
+
* Yields `Uint8Array` instances. The caller may concatenate them or write
|
|
314
343
|
* each one directly to storage.
|
|
315
344
|
*
|
|
316
345
|
* @override
|
|
317
|
-
* @param {AsyncIterable<
|
|
318
|
-
* @yields {
|
|
346
|
+
* @param {AsyncIterable<Uint8Array>} source - Incoming byte stream.
|
|
347
|
+
* @yields {Uint8Array} Content-defined chunks.
|
|
319
348
|
*/
|
|
320
349
|
async *chunk(source) {
|
|
321
350
|
/** @type {ChunkState} */
|
|
@@ -324,21 +353,26 @@ export default class CdcChunker extends ChunkingPort {
|
|
|
324
353
|
win: new Uint8Array(WINDOW_SIZE),
|
|
325
354
|
winPos: 0,
|
|
326
355
|
hashFed: 0,
|
|
327
|
-
chunkBuf:
|
|
356
|
+
chunkBuf: new Uint8Array(this.#maxChunkSize),
|
|
328
357
|
chunkLen: 0,
|
|
329
358
|
minSize: this.#minChunkSize,
|
|
330
359
|
maxSize: this.#maxChunkSize,
|
|
331
360
|
mask: this.#mask,
|
|
361
|
+
hardMask: this.#hardMask,
|
|
362
|
+
easyMask: this.#easyMask,
|
|
363
|
+
targetSize: this.#targetChunkSize,
|
|
364
|
+
normalized: this.#normalized,
|
|
332
365
|
};
|
|
333
366
|
|
|
334
|
-
for await (const
|
|
367
|
+
for await (const chunk of source) {
|
|
368
|
+
const buf = normalizeByteChunk(chunk);
|
|
335
369
|
const chunks = processBuf(st, buf);
|
|
336
370
|
for (const c of chunks) { yield c; }
|
|
337
371
|
}
|
|
338
372
|
|
|
339
373
|
// Flush final partial chunk (may be < minSize — allowed for EOF).
|
|
340
374
|
if (st.chunkLen > 0) {
|
|
341
|
-
yield
|
|
375
|
+
yield new Uint8Array(st.chunkBuf.subarray(0, st.chunkLen));
|
|
342
376
|
}
|
|
343
377
|
}
|
|
344
378
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ChunkingPort from '../../ports/ChunkingPort.js';
|
|
2
|
+
import { copyBytes, normalizeByteChunk } from '../../domain/bytes/ByteLayout.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* {@link ChunkingPort} implementation that splits data into fixed-size chunks.
|
|
@@ -40,30 +41,37 @@ export default class FixedChunker extends ChunkingPort {
|
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* @override
|
|
43
|
-
* @param {AsyncIterable<
|
|
44
|
-
* @yields {
|
|
44
|
+
* @param {AsyncIterable<Uint8Array>} source - The input byte stream.
|
|
45
|
+
* @yields {Uint8Array}
|
|
45
46
|
*/
|
|
46
47
|
async *chunk(source) {
|
|
47
48
|
const cs = this.#chunkSize;
|
|
48
|
-
const buf =
|
|
49
|
+
const buf = new Uint8Array(cs);
|
|
49
50
|
let offset = 0;
|
|
50
51
|
|
|
51
|
-
for await (const
|
|
52
|
+
for await (const chunk of source) {
|
|
53
|
+
const data = normalizeByteChunk(chunk);
|
|
52
54
|
let srcPos = 0;
|
|
53
55
|
while (srcPos < data.length) {
|
|
54
56
|
const n = Math.min(cs - offset, data.length - srcPos);
|
|
55
|
-
|
|
57
|
+
copyBytes({
|
|
58
|
+
source: data,
|
|
59
|
+
target: buf,
|
|
60
|
+
targetOffset: offset,
|
|
61
|
+
sourceStart: srcPos,
|
|
62
|
+
sourceEnd: srcPos + n,
|
|
63
|
+
});
|
|
56
64
|
offset += n;
|
|
57
65
|
srcPos += n;
|
|
58
66
|
if (offset === cs) {
|
|
59
|
-
yield
|
|
67
|
+
yield new Uint8Array(buf);
|
|
60
68
|
offset = 0;
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
if (offset > 0) {
|
|
66
|
-
yield
|
|
74
|
+
yield new Uint8Array(buf.subarray(0, offset));
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
}
|
|
@@ -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 } = {}) {
|
|
@@ -30,13 +30,17 @@ export default function resolveChunker({ chunker, chunking } = {}) {
|
|
|
30
30
|
targetChunkSize: chunking.targetChunkSize,
|
|
31
31
|
minChunkSize: chunking.minChunkSize,
|
|
32
32
|
maxChunkSize: chunking.maxChunkSize,
|
|
33
|
+
normalized: chunking.normalized,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
|
-
// 'fixed'
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
// 'fixed' with valid chunkSize → FixedChunker; otherwise fall through
|
|
37
|
+
// to CasService's built-in FixedChunker default.
|
|
38
|
+
if (
|
|
39
|
+
chunking.strategy === 'fixed' &&
|
|
40
|
+
typeof chunking.chunkSize === 'number' &&
|
|
41
|
+
Number.isFinite(chunking.chunkSize) &&
|
|
42
|
+
chunking.chunkSize > 0
|
|
43
|
+
) {
|
|
40
44
|
return new FixedChunker({ chunkSize: chunking.chunkSize });
|
|
41
45
|
}
|
|
42
46
|
}
|
|
@@ -8,7 +8,7 @@ export default class CborCodec extends CodecPort {
|
|
|
8
8
|
/**
|
|
9
9
|
* @override
|
|
10
10
|
* @param {Record<string, unknown>} data - Data to encode.
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {Uint8Array}
|
|
12
12
|
*/
|
|
13
13
|
encode(data) {
|
|
14
14
|
return encode(data);
|
|
@@ -16,11 +16,11 @@ export default class CborCodec extends CodecPort {
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @override
|
|
19
|
-
* @param {
|
|
19
|
+
* @param {Uint8Array} buffer - CBOR-encoded data.
|
|
20
20
|
* @returns {Record<string, unknown>}
|
|
21
21
|
*/
|
|
22
22
|
decode(buffer) {
|
|
23
|
-
return decode(
|
|
23
|
+
return decode(buffer);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** @override */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import CodecPort from '../../ports/CodecPort.js';
|
|
2
|
+
import { utf8Decode, utf8Encode } from '../../domain/encoding/utf8.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* {@link CodecPort} implementation that serializes manifests as pretty-printed JSON.
|
|
@@ -7,21 +8,20 @@ export default class JsonCodec extends CodecPort {
|
|
|
7
8
|
/**
|
|
8
9
|
* @override
|
|
9
10
|
* @param {Record<string, unknown>} data - Data to encode.
|
|
10
|
-
* @returns {
|
|
11
|
+
* @returns {Uint8Array}
|
|
11
12
|
*/
|
|
12
13
|
encode(data) {
|
|
13
|
-
// Determine if we need to handle Buffers specially for JSON
|
|
14
14
|
// For now, we assume data is JSON-safe or uses toJSON() methods
|
|
15
|
-
return JSON.stringify(data, null, 2);
|
|
15
|
+
return utf8Encode(JSON.stringify(data, null, 2));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @override
|
|
20
|
-
* @param {
|
|
20
|
+
* @param {Uint8Array} buffer - JSON-encoded data.
|
|
21
21
|
* @returns {Record<string, unknown>}
|
|
22
22
|
*/
|
|
23
23
|
decode(buffer) {
|
|
24
|
-
return JSON.parse(buffer
|
|
24
|
+
return JSON.parse(utf8Decode(buffer));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/** @override */
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared GitPlumbing factory helpers for runtime-aware CLI and
|
|
3
|
+
* test wiring.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import GitPlumbingFactoryAdapter, {
|
|
7
|
+
resolveGitRunnerEnv,
|
|
8
|
+
} from './adapters/GitPlumbingFactoryAdapter.js';
|
|
9
|
+
|
|
10
|
+
const defaultFactory = new GitPlumbingFactoryAdapter();
|
|
11
|
+
|
|
12
|
+
export { resolveGitRunnerEnv };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Construct a GitPlumbing instance for the requested working tree.
|
|
16
|
+
*
|
|
17
|
+
* @param {{ cwd?: string, env?: string, factory?: GitPlumbingFactoryAdapter }} [options]
|
|
18
|
+
* @returns {Promise<import('@git-stunts/plumbing').default>}
|
|
19
|
+
*/
|
|
20
|
+
export async function createGitPlumbing({ cwd = '.', env, factory = defaultFactory } = {}) {
|
|
21
|
+
return await factory.create({ cwd, env });
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PACKAGE_VERSION = '6.0.1';
|
|
@@ -35,9 +35,9 @@ export default class ChunkingPort {
|
|
|
35
35
|
* Splits an async byte stream into chunks.
|
|
36
36
|
*
|
|
37
37
|
* @abstract
|
|
38
|
-
* @param {AsyncIterable<
|
|
39
|
-
* @yields {
|
|
40
|
-
* @returns {AsyncGenerator<
|
|
38
|
+
* @param {AsyncIterable<Uint8Array>} _source - The input byte stream.
|
|
39
|
+
* @yields {Uint8Array} Chunks of data whose size depends on the strategy.
|
|
40
|
+
* @returns {AsyncGenerator<Uint8Array>}
|
|
41
41
|
*/
|
|
42
42
|
async *chunk(_source) { // eslint-disable-line require-yield
|
|
43
43
|
throw new Error('Not implemented');
|
package/src/ports/CodecPort.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export default class CodecPort {
|
|
6
6
|
/**
|
|
7
|
-
* Encodes data to
|
|
7
|
+
* Encodes data to bytes.
|
|
8
8
|
* @param {Record<string, unknown>} _data - Data to encode.
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {Uint8Array}
|
|
10
10
|
*/
|
|
11
11
|
encode(_data) {
|
|
12
12
|
throw new Error('Not implemented');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Decodes data from
|
|
17
|
-
* @param {
|
|
16
|
+
* Decodes data from bytes.
|
|
17
|
+
* @param {Uint8Array} _buffer - Encoded data to decode.
|
|
18
18
|
* @returns {Record<string, unknown>}
|
|
19
19
|
*/
|
|
20
20
|
decode(_buffer) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract port for compression and decompression of buffers and streams.
|
|
3
|
+
*
|
|
4
|
+
* Implementations provide a specific compression algorithm (e.g. gzip)
|
|
5
|
+
* and expose both buffer and streaming interfaces.
|
|
6
|
+
*
|
|
7
|
+
* @abstract
|
|
8
|
+
*/
|
|
9
|
+
export default class CompressionPort {
|
|
10
|
+
constructor() {
|
|
11
|
+
if (new.target === CompressionPort) {
|
|
12
|
+
throw new Error('CompressionPort is abstract and cannot be instantiated directly');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Compresses a buffer.
|
|
18
|
+
* @abstract
|
|
19
|
+
* @param {Uint8Array} _buffer - Data to compress.
|
|
20
|
+
* @returns {Promise<Uint8Array>} Compressed data.
|
|
21
|
+
*/
|
|
22
|
+
async compressBuffer(_buffer) {
|
|
23
|
+
throw new Error('Not implemented');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Decompresses a buffer.
|
|
28
|
+
* @abstract
|
|
29
|
+
* @param {Uint8Array} _buffer - Compressed data to decompress.
|
|
30
|
+
* @returns {Promise<Uint8Array>} Decompressed data.
|
|
31
|
+
*/
|
|
32
|
+
async decompressBuffer(_buffer) {
|
|
33
|
+
throw new Error('Not implemented');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Compresses an async byte stream.
|
|
38
|
+
* @abstract
|
|
39
|
+
* @param {AsyncIterable<Uint8Array>} _source - The input byte stream.
|
|
40
|
+
* @yields {Uint8Array} Compressed chunks.
|
|
41
|
+
* @returns {AsyncGenerator<Uint8Array>}
|
|
42
|
+
*/
|
|
43
|
+
async *compressStream(_source) { // eslint-disable-line require-yield
|
|
44
|
+
throw new Error('Not implemented');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Decompresses an async byte stream.
|
|
49
|
+
* @abstract
|
|
50
|
+
* @param {AsyncIterable<Uint8Array>} _source - The compressed byte stream.
|
|
51
|
+
* @yields {Uint8Array} Decompressed chunks.
|
|
52
|
+
* @returns {AsyncGenerator<Uint8Array>}
|
|
53
|
+
*/
|
|
54
|
+
async *decompressStream(_source) { // eslint-disable-line require-yield
|
|
55
|
+
throw new Error('Not implemented');
|
|
56
|
+
}
|
|
57
|
+
}
|