@git-stunts/git-cas 6.4.0 → 6.5.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.
- package/ARCHITECTURE.md +2 -0
- package/CHANGELOG.md +31 -0
- package/README.md +20 -18
- package/UPGRADING.md +64 -19
- package/build-info.json +2 -2
- package/docs/API.md +41 -0
- package/docs/releases/v6.5.0.md +140 -0
- package/index.d.ts +14 -2
- package/index.js +10 -0
- package/package.json +2 -1
- package/src/domain/services/BundleService.js +32 -3
- package/src/domain/services/RootSetPersistence.js +61 -13
- package/src/helpers/boundedPromiseCache.js +108 -0
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +58 -27
- package/src/package-version.js +1 -1
package/ARCHITECTURE.md
CHANGED
|
@@ -374,6 +374,8 @@ Pure utility functions with no domain or infrastructure coupling:
|
|
|
374
374
|
- **`kdfPolicy.js`** — KDF parameter validation and sensible defaults.
|
|
375
375
|
- **`aesGcmMeta.js`** — AES-GCM metadata validation (IV length, tag length).
|
|
376
376
|
- **`canonicalBase64.js`** — base64 encoding round-trip integrity check.
|
|
377
|
+
- **`boundedPromiseCache.js`** — fixed-residency LRU coalescing for immutable
|
|
378
|
+
async reads; rejected work is never retained.
|
|
377
379
|
|
|
378
380
|
## Storage Model
|
|
379
381
|
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.5.0] — 2026-07-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Direct bundle references** - `bundles.getMemberReference()` and
|
|
15
|
+
`bundles.iterateMemberReferences()` validate bundle structure, canonical
|
|
16
|
+
descriptors, direct Git edges, and direct target object types without
|
|
17
|
+
recursively resolving each member's support graph. Existing member and root
|
|
18
|
+
methods retain complete-validation semantics.
|
|
19
|
+
|
|
20
|
+
### Performance
|
|
21
|
+
|
|
22
|
+
- **Bounded immutable Git metadata coalescing** - repeated exact tree-entry and
|
|
23
|
+
object-info reads now share successful in-flight and completed work through a
|
|
24
|
+
fixed-residency LRU. BundleService separately retains only structural
|
|
25
|
+
descriptor bytes under both entry and byte bounds. Rejected work is evicted,
|
|
26
|
+
mutable records are cloned for callers, and no application payloads or ref
|
|
27
|
+
state enter either cache.
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- **Observed RootSet compare-and-swap races** - exact failed
|
|
32
|
+
`update-ref --no-deref` commands with an independently observed head advance
|
|
33
|
+
now normalize to `ROOT_SET_CONFLICT` even when Git emits no diagnostic text.
|
|
34
|
+
OIDs are compared canonically so case-only differences do not create false
|
|
35
|
+
conflicts.
|
|
36
|
+
- **Bounded cache settlement** - rejected work is removed before its returned
|
|
37
|
+
promise settles, and a resolved value larger than its weight budget is
|
|
38
|
+
discarded before eviction runs, preserving retryability and unrelated
|
|
39
|
+
residents.
|
|
40
|
+
|
|
10
41
|
## [6.4.0] — 2026-07-17
|
|
11
42
|
|
|
12
43
|
### Added
|
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
|
|
|
44
44
|
Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
|
|
45
45
|
`npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
|
|
46
46
|
For the release overview, see the
|
|
47
|
-
[v6.
|
|
47
|
+
[v6.5.0 Release Notes](./docs/releases/v6.5.0.md).
|
|
48
48
|
|
|
49
49
|
### 1. CLI Usage
|
|
50
50
|
|
|
@@ -94,21 +94,21 @@ the asset reachable.
|
|
|
94
94
|
|
|
95
95
|
The README is the front door. Detailed mechanics live in the guide set:
|
|
96
96
|
|
|
97
|
-
| Need | Start Here
|
|
98
|
-
| ------------------------------------------------------- |
|
|
99
|
-
| Productive library and CLI workflows | [Developer Guide](./GUIDE.md)
|
|
100
|
-
| Restore memory behavior | [Streaming and restore matrix](./GUIDE.md#streaming-surface)
|
|
101
|
-
| Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md)
|
|
102
|
-
| CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md)
|
|
103
|
-
| Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md)
|
|
104
|
-
| Assets, pages, bundles, retention, and publication | [Application storage](./docs/API.md#application-storage)
|
|
105
|
-
| Temporary retention during multi-step composition
|
|
106
|
-
| GC retention for caches and derived state | [Root Sets](./docs/API.md#root-sets)
|
|
107
|
-
| Managed TTL and capacity caches | [Cache Sets](./docs/API.md#cache-sets)
|
|
108
|
-
| Scoped protection while consuming a cache hit | [Cache acquisitions](./docs/API.md#acquire-and-release)
|
|
109
|
-
| Durable replay markers with expiry-only release | [Expiring Sets](./docs/API.md#expiring-sets)
|
|
110
|
-
| Repository reachability and git-cas usage evidence | [Repository Diagnostics](./docs/API.md#repository-diagnostics)
|
|
111
|
-
| v5 to v6 migration | [Upgrading](./UPGRADING.md)
|
|
97
|
+
| Need | Start Here |
|
|
98
|
+
| ------------------------------------------------------- | -------------------------------------------------------------------- |
|
|
99
|
+
| Productive library and CLI workflows | [Developer Guide](./GUIDE.md) |
|
|
100
|
+
| Restore memory behavior | [Streaming and restore matrix](./GUIDE.md#streaming-surface) |
|
|
101
|
+
| Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md) |
|
|
102
|
+
| CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
|
|
103
|
+
| Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
|
|
104
|
+
| Assets, pages, bundles, retention, and publication | [Application storage](./docs/API.md#application-storage) |
|
|
105
|
+
| Temporary retention during multi-step composition | [Scoped staging workspaces](./docs/API.md#scoped-staging-workspaces) |
|
|
106
|
+
| GC retention for caches and derived state | [Root Sets](./docs/API.md#root-sets) |
|
|
107
|
+
| Managed TTL and capacity caches | [Cache Sets](./docs/API.md#cache-sets) |
|
|
108
|
+
| Scoped protection while consuming a cache hit | [Cache acquisitions](./docs/API.md#acquire-and-release) |
|
|
109
|
+
| Durable replay markers with expiry-only release | [Expiring Sets](./docs/API.md#expiring-sets) |
|
|
110
|
+
| Repository reachability and git-cas usage evidence | [Repository Diagnostics](./docs/API.md#repository-diagnostics) |
|
|
111
|
+
| v5 to v6 migration | [Upgrading](./UPGRADING.md) |
|
|
112
112
|
|
|
113
113
|
Core capabilities:
|
|
114
114
|
|
|
@@ -138,8 +138,8 @@ Core capabilities:
|
|
|
138
138
|
read-only, and `sweep()` can release only markers whose expiry has passed.
|
|
139
139
|
- **Application storage**: `assets`, `pages`, `bundles`, `retention`, and
|
|
140
140
|
`publications` compose streaming CAS writes, bounded structured
|
|
141
|
-
materializations,
|
|
142
|
-
compare-and-swap refs, and immutable lifecycle evidence.
|
|
141
|
+
materializations, direct-reference or complete-validation member reads,
|
|
142
|
+
reachability roots, compare-and-swap refs, and immutable lifecycle evidence.
|
|
143
143
|
- **Scoped staging workspaces**: `workspaces.open()` mirrors application writes
|
|
144
144
|
behind one renewable temporary RootSet, returns only after each handle is
|
|
145
145
|
anchored, promotes destination-first, and exposes bounded age, expiry,
|
|
@@ -202,6 +202,8 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
|
|
|
202
202
|
reference-only cache acquisitions with explicit release and doctor evidence.
|
|
203
203
|
- **[v6.4.0 Release Notes](./docs/releases/v6.4.0.md)**: Scoped staging
|
|
204
204
|
workspaces for temporary multi-object reachability, promotion, and cleanup.
|
|
205
|
+
- **[v6.5.0 Release Notes](./docs/releases/v6.5.0.md)**: Bounded direct bundle
|
|
206
|
+
references, immutable metadata reuse, and corrected concurrency settlement.
|
|
205
207
|
- **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
|
|
206
208
|
- **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
|
|
207
209
|
|
package/UPGRADING.md
CHANGED
|
@@ -2,6 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
v6.0.0 is a major release that simplifies the encryption model, hardens security defaults, and cleans up the architecture. This guide covers every breaking change and what you need to do.
|
|
4
4
|
|
|
5
|
+
## v6.4.0 To v6.5.0
|
|
6
|
+
|
|
7
|
+
v6.5.0 is API-additive and does not require stored-data migration. It adds
|
|
8
|
+
bounded reference reads for callers that need a member handle without
|
|
9
|
+
recursively resolving that member's complete support graph.
|
|
10
|
+
|
|
11
|
+
Use `getMemberReference()` for one exact path:
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const reference = await cas.bundles.getMemberReference({
|
|
15
|
+
handle: materializationBundle,
|
|
16
|
+
path: 'nodes/user-alice.cbor',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (reference) {
|
|
20
|
+
await consumeRetainedHandle(reference.handle);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use `iterateMemberReferences()` for a streaming structural scan:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
for await (const reference of cas.bundles.iterateMemberReferences({
|
|
28
|
+
handle: materializationBundle,
|
|
29
|
+
})) {
|
|
30
|
+
await indexReference(reference);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
These APIs validate the bundle root, every traversed descriptor summary, the
|
|
35
|
+
selected or enumerated Git tree edges, and each direct target object type. They
|
|
36
|
+
do not recursively validate nested page, asset, or bundle support graphs. Keep
|
|
37
|
+
using `getMember()` or `iterateMembers()` when the operation requires complete
|
|
38
|
+
recursive validation and computed `logicalBytes`.
|
|
39
|
+
|
|
40
|
+
Reference results are observations, not retention claims. Keep the containing
|
|
41
|
+
bundle reachable through a workspace, cache acquisition, RootSet, or other
|
|
42
|
+
documented lifetime while consuming them. The immutable metadata and
|
|
43
|
+
descriptor caches introduced in v6.5.0 are bounded internal implementation
|
|
44
|
+
details; callers do not manage or invalidate them.
|
|
45
|
+
|
|
46
|
+
See [v6.5.0 Release Notes](./docs/releases/v6.5.0.md) and
|
|
47
|
+
[Application Storage](./docs/API.md#application-storage) for the
|
|
48
|
+
complete integrity and lifetime contract.
|
|
49
|
+
|
|
5
50
|
## v6.3.0 To v6.4.0
|
|
6
51
|
|
|
7
52
|
v6.4.0 is API-additive and does not require stored-data migration. It adds
|
|
@@ -198,13 +243,13 @@ for example a job workspace or tenant-scoped artifact directory.
|
|
|
198
243
|
|
|
199
244
|
v5 had 5 encryption scheme identifiers. v6 has 3:
|
|
200
245
|
|
|
201
|
-
| v5 Scheme
|
|
202
|
-
|
|
203
|
-
| `whole-v1`
|
|
204
|
-
| `whole-v2`
|
|
205
|
-
| `framed-v1`
|
|
206
|
-
| `framed-v2`
|
|
207
|
-
| `convergent-v1` | `convergent` | Rename only
|
|
246
|
+
| v5 Scheme | v6 Scheme | Migration |
|
|
247
|
+
| --------------- | ------------ | ------------------------------------------ |
|
|
248
|
+
| `whole-v1` | `whole` | **Re-encryption required** (v1 had no AAD) |
|
|
249
|
+
| `whole-v2` | `whole` | Rename only (already had AAD) |
|
|
250
|
+
| `framed-v1` | `framed` | **Re-encryption required** (v1 had no AAD) |
|
|
251
|
+
| `framed-v2` | `framed` | Rename only (already had AAD) |
|
|
252
|
+
| `convergent-v1` | `convergent` | Rename only |
|
|
208
253
|
|
|
209
254
|
### Why
|
|
210
255
|
|
|
@@ -285,11 +330,11 @@ verifier and the next keyed vault write will add it.
|
|
|
285
330
|
|
|
286
331
|
### What Changed
|
|
287
332
|
|
|
288
|
-
| Scenario
|
|
289
|
-
|
|
290
|
-
| CDC chunking + encryption
|
|
291
|
-
| Fixed chunking + encryption | `framed-v1` | `framed`
|
|
292
|
-
| Explicit `whole`
|
|
333
|
+
| Scenario | v5 Default | v6 Default |
|
|
334
|
+
| --------------------------- | ----------- | ------------ |
|
|
335
|
+
| CDC chunking + encryption | `framed-v1` | `convergent` |
|
|
336
|
+
| Fixed chunking + encryption | `framed-v1` | `framed` |
|
|
337
|
+
| Explicit `whole` | `whole-v1` | `whole` |
|
|
293
338
|
|
|
294
339
|
### What This Means
|
|
295
340
|
|
|
@@ -382,14 +427,14 @@ import { SCHEME_WHOLE, SCHEME_FRAMED, SCHEME_CONVERGENT } from '@git-stunts/git-
|
|
|
382
427
|
|
|
383
428
|
### Behavioral Changes
|
|
384
429
|
|
|
385
|
-
| Change
|
|
386
|
-
|
|
387
|
-
| Plaintext + gzip restore now streams
|
|
388
|
-
| AAD always on for `whole` and `framed`
|
|
430
|
+
| Change | Impact |
|
|
431
|
+
| ---------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
432
|
+
| Plaintext + gzip restore now streams | This lowers memory usage and should be transparent. |
|
|
433
|
+
| AAD always on for `whole` and `framed` | Cannot opt out. v1-style no-AAD is gone. |
|
|
389
434
|
| Manifest integrity hash verified on read | Corrupted manifests that previously loaded will now throw `MANIFEST_INTEGRITY_ERROR`. |
|
|
390
|
-
| KDF policy enforced in `deriveKey()`
|
|
391
|
-
| Concurrency capped at 64
|
|
392
|
-
| frameBytes capped at 64 MiB
|
|
435
|
+
| KDF policy enforced in `deriveKey()` | Dangerously weak params (e.g., 1 PBKDF2 iteration) now throw `KDF_POLICY_VIOLATION`. |
|
|
436
|
+
| Concurrency capped at 64 | Was unbounded. Unlikely to affect real usage. |
|
|
437
|
+
| frameBytes capped at 64 MiB | Was unbounded. Unlikely to affect real usage. |
|
|
393
438
|
|
|
394
439
|
---
|
|
395
440
|
|
package/build-info.json
CHANGED
package/docs/API.md
CHANGED
|
@@ -1077,6 +1077,47 @@ The canonical bundle token is:
|
|
|
1077
1077
|
git-cas:1:bundle:fanout-tree:<codec>:<sha1|sha256>:<oid>
|
|
1078
1078
|
```
|
|
1079
1079
|
|
|
1080
|
+
### Direct bundle references
|
|
1081
|
+
|
|
1082
|
+
```javascript
|
|
1083
|
+
const reference = await cas.bundles.getMemberReference({
|
|
1084
|
+
handle: materializationHandle,
|
|
1085
|
+
path: 'nodes/root',
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
for await (const reference of cas.bundles.iterateMemberReferences({
|
|
1089
|
+
handle: materializationHandle,
|
|
1090
|
+
})) {
|
|
1091
|
+
indexHandle(reference.path, reference.handle);
|
|
1092
|
+
}
|
|
1093
|
+
```
|
|
1094
|
+
|
|
1095
|
+
`getMemberReference()` and `iterateMemberReferences()` are the explicit lazy
|
|
1096
|
+
integrity surfaces. They validate the bundle root, persisted limits, fanout
|
|
1097
|
+
summaries, canonical member descriptor, direct Git tree edge, and direct target
|
|
1098
|
+
object type. They do not recursively resolve the referenced member's complete
|
|
1099
|
+
support graph. Use them for indexes and manifests that dereference only selected
|
|
1100
|
+
members.
|
|
1101
|
+
|
|
1102
|
+
Each immutable `BundleMemberReference` contains `version`, `path`, `handle`,
|
|
1103
|
+
`type`, and declared `size`. Missing paths return `null`; malformed bundle
|
|
1104
|
+
structure, mismatched edges, and missing or mistyped direct targets fail closed.
|
|
1105
|
+
Completing reference iteration still validates root and fanout summaries.
|
|
1106
|
+
|
|
1107
|
+
The Git persistence adapter coalesces successful exact tree-entry and
|
|
1108
|
+
object-info reads in one process-local LRU with a fixed 2,048-entry default.
|
|
1109
|
+
Bundle traversal separately retains immutable structural descriptor bytes under
|
|
1110
|
+
a 1,024-entry and 16 MiB total bound. Rejected work is removed, returned
|
|
1111
|
+
tree-entry records are cloned, and application payloads, refs, and collection
|
|
1112
|
+
state are never cached. Advanced direct adapter construction may set
|
|
1113
|
+
`metadataCacheEntries` to another positive safe integer.
|
|
1114
|
+
|
|
1115
|
+
Object identity is immutable, but external pruning can change whether an
|
|
1116
|
+
unretained object remains available. Keep roots retained for the adapter's
|
|
1117
|
+
operation lifetime and do not race active reads with destructive repository
|
|
1118
|
+
maintenance. Payload access performs authoritative Git I/O if availability
|
|
1119
|
+
changes despite that precondition.
|
|
1120
|
+
|
|
1080
1121
|
### `bundles.getMember()`, `bundles.iterateMembers()`, and `bundles.openMember()`
|
|
1081
1122
|
|
|
1082
1123
|
```javascript
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# git-cas v6.5.0 Release Notes
|
|
2
|
+
|
|
3
|
+
v6.5.0 adds bounded direct bundle-reference reads for applications that need to
|
|
4
|
+
locate or enumerate retained materialization handles without recursively
|
|
5
|
+
hydrating every referenced support graph. It also adds bounded reuse for
|
|
6
|
+
immutable Git metadata and bundle descriptors, and repairs two concurrency
|
|
7
|
+
edge cases found while proving the new path under stress.
|
|
8
|
+
|
|
9
|
+
This release is API-additive. It does not change persisted bundle formats and
|
|
10
|
+
does not require stored-data migration.
|
|
11
|
+
|
|
12
|
+
## Direct Bundle References
|
|
13
|
+
|
|
14
|
+
Read one exact member descriptor without opening its payload or recursively
|
|
15
|
+
resolving the member's complete support graph:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const reference = await cas.bundles.getMemberReference({
|
|
19
|
+
handle: materializationBundle,
|
|
20
|
+
path: 'nodes/user-alice.cbor',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (reference) {
|
|
24
|
+
console.log(reference.handle);
|
|
25
|
+
console.log(reference.type);
|
|
26
|
+
console.log(reference.size);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Stream canonical member descriptors without collecting the whole bundle:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
for await (const reference of cas.bundles.iterateMemberReferences({
|
|
34
|
+
handle: materializationBundle,
|
|
35
|
+
})) {
|
|
36
|
+
await indexReference(reference);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each `BundleMemberReference` contains:
|
|
41
|
+
|
|
42
|
+
- `version: 1`;
|
|
43
|
+
- the canonical member `path`;
|
|
44
|
+
- the typed application `handle`;
|
|
45
|
+
- the direct Git object `type`; and
|
|
46
|
+
- the declared byte `size`, or `null` for structured tree members.
|
|
47
|
+
|
|
48
|
+
The existing `getMember()` and `iterateMembers()` APIs retain complete recursive
|
|
49
|
+
validation semantics and include computed `logicalBytes`.
|
|
50
|
+
|
|
51
|
+
## Integrity Boundary
|
|
52
|
+
|
|
53
|
+
The direct path validates:
|
|
54
|
+
|
|
55
|
+
- the bundle handle codec and root tree type;
|
|
56
|
+
- the root descriptor and persisted read limits;
|
|
57
|
+
- every descriptor and summary along the selected path, or across the streamed
|
|
58
|
+
structural traversal;
|
|
59
|
+
- every traversed fanout tree edge;
|
|
60
|
+
- the selected or enumerated leaf edge; and
|
|
61
|
+
- each direct target Git object type.
|
|
62
|
+
|
|
63
|
+
It does not recursively validate a selected page, asset, or nested bundle's
|
|
64
|
+
complete support graph. Callers that require that stronger proof must continue
|
|
65
|
+
to use `getMember()` or `iterateMembers()`.
|
|
66
|
+
|
|
67
|
+
A reference is also not a retention witness. The containing bundle must remain
|
|
68
|
+
reachable through a workspace, RootSet, cache acquisition, publication, or
|
|
69
|
+
other documented lifetime while the reference is consumed.
|
|
70
|
+
|
|
71
|
+
## Bounded Immutable Reuse
|
|
72
|
+
|
|
73
|
+
Repeated exact tree-entry and object-info reads now share successful in-flight
|
|
74
|
+
and completed work inside each Git persistence adapter. The default metadata
|
|
75
|
+
cache retains at most 2,048 immutable entries and can be lowered with the
|
|
76
|
+
`metadataCacheEntries` constructor option.
|
|
77
|
+
|
|
78
|
+
Bundle descriptors use a separate cache bounded by both 1,024 entries and 16
|
|
79
|
+
MiB. Returned byte arrays and mutable metadata records are copied for callers.
|
|
80
|
+
Rejected work removes itself so a later read can retry. Values larger than the
|
|
81
|
+
descriptor byte budget are returned to the current caller but are not retained
|
|
82
|
+
and do not evict unrelated residents.
|
|
83
|
+
|
|
84
|
+
These caches contain immutable Git metadata and structural descriptors only.
|
|
85
|
+
They do not retain application payload bytes, mutable refs, cache indexes, or
|
|
86
|
+
root-set state.
|
|
87
|
+
|
|
88
|
+
## Concurrency Repairs
|
|
89
|
+
|
|
90
|
+
The RootSet compare-and-swap classifier now recovers exact failed
|
|
91
|
+
`git update-ref --no-deref` races when Git exits fatally without diagnostic
|
|
92
|
+
text, provided an independent ref read proves that the managed head advanced.
|
|
93
|
+
OID comparisons use canonical lowercase values, avoiding false conflicts from
|
|
94
|
+
case-only differences. A checked-in real-Git diagnostic passed 500/500
|
|
95
|
+
two-writer replacement races after the repair.
|
|
96
|
+
|
|
97
|
+
The bounded promise cache now removes rejected work before the returned promise
|
|
98
|
+
settles, preserving immediate retry semantics. Individually oversized resolved
|
|
99
|
+
values are discarded before weight-based eviction runs, preserving unrelated
|
|
100
|
+
residents.
|
|
101
|
+
|
|
102
|
+
## Performance Evidence
|
|
103
|
+
|
|
104
|
+
The stable regression contract counts real Git commands rather than asserting
|
|
105
|
+
portable wall-clock latency:
|
|
106
|
+
|
|
107
|
+
- a cold direct read must perform metadata work;
|
|
108
|
+
- an identical warm direct read must perform zero additional Git metadata
|
|
109
|
+
commands; and
|
|
110
|
+
- direct reference iteration must issue fewer total and object-inspection
|
|
111
|
+
commands than complete recursive validation.
|
|
112
|
+
|
|
113
|
+
On the recorded four-node git-warp fixture, the final direct-reference and
|
|
114
|
+
descriptor-cache path reduced one selected read from 192 Git commands to 69,
|
|
115
|
+
approximately 64 percent. The same host sample reduced the observed wall time
|
|
116
|
+
from approximately 3-5 seconds to 1.291 seconds. These timings are diagnostic,
|
|
117
|
+
not cross-machine promises; command-count integration is the merge gate.
|
|
118
|
+
|
|
119
|
+
## Verification
|
|
120
|
+
|
|
121
|
+
The final release candidate passed 14/14 verifier steps with 6,625 observed
|
|
122
|
+
tests:
|
|
123
|
+
|
|
124
|
+
- Node.js: 2,020 unit tests and 192 real-Git integration tests;
|
|
125
|
+
- Bun: 2,019 unit tests and 192 real-Git integration tests; and
|
|
126
|
+
- Deno: 2,010 unit tests and 192 real-Git integration tests.
|
|
127
|
+
|
|
128
|
+
The verifier also passed lint, examples, public type compatibility, build
|
|
129
|
+
stamping, npm package inspection, and the JSR publish dry-run. The checked-in
|
|
130
|
+
RootSet race diagnostic passed 500/500 two-writer replacement races.
|
|
131
|
+
|
|
132
|
+
## Upgrade Notes
|
|
133
|
+
|
|
134
|
+
No stored-data migration is required. Existing complete-validation calls keep
|
|
135
|
+
their behavior. Applications may adopt the new reference APIs selectively where
|
|
136
|
+
their own retained lifetime already guarantees that recursive support remains
|
|
137
|
+
available.
|
|
138
|
+
|
|
139
|
+
See [UPGRADING.md](../../UPGRADING.md) for the adoption decision and
|
|
140
|
+
[Application Storage](../API.md#application-storage) for the full API contract.
|
package/index.d.ts
CHANGED
|
@@ -564,7 +564,11 @@ export declare class GitRefPortBase {
|
|
|
564
564
|
|
|
565
565
|
/** Git-backed implementation of the persistence port. */
|
|
566
566
|
export declare class GitPersistenceAdapter extends GitPersistencePortBase {
|
|
567
|
-
constructor(options: {
|
|
567
|
+
constructor(options: {
|
|
568
|
+
plumbing: unknown;
|
|
569
|
+
policy?: unknown;
|
|
570
|
+
metadataCacheEntries?: number;
|
|
571
|
+
});
|
|
568
572
|
setMaxBlobSize(maxBlobSize: number): void;
|
|
569
573
|
}
|
|
570
574
|
|
|
@@ -1456,12 +1460,15 @@ export type BundleMemberInput =
|
|
|
1456
1460
|
| PageSource
|
|
1457
1461
|
| { source: PageSource; maxBytes?: number };
|
|
1458
1462
|
|
|
1459
|
-
export interface
|
|
1463
|
+
export interface BundleMemberReference {
|
|
1460
1464
|
readonly version: 1;
|
|
1461
1465
|
readonly path: string;
|
|
1462
1466
|
readonly handle: ApplicationHandle;
|
|
1463
1467
|
readonly type: 'blob' | 'tree';
|
|
1464
1468
|
readonly size: number | null;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
export interface BundleMember extends BundleMemberReference {
|
|
1465
1472
|
readonly logicalBytes: number;
|
|
1466
1473
|
}
|
|
1467
1474
|
|
|
@@ -1483,6 +1490,11 @@ export interface BundleCapability {
|
|
|
1483
1490
|
handle: BundleHandleInput;
|
|
1484
1491
|
path: string;
|
|
1485
1492
|
}): Promise<BundleMember | null>;
|
|
1493
|
+
getMemberReference(options: {
|
|
1494
|
+
handle: BundleHandleInput;
|
|
1495
|
+
path: string;
|
|
1496
|
+
}): Promise<BundleMemberReference | null>;
|
|
1497
|
+
iterateMemberReferences(options: { handle: BundleHandleInput }): AsyncIterable<BundleMemberReference>;
|
|
1486
1498
|
iterateMembers(options: { handle: BundleHandleInput }): AsyncIterable<BundleMember>;
|
|
1487
1499
|
openMember(options: { handle: BundleHandleInput; path: string }): AsyncIterable<Uint8Array>;
|
|
1488
1500
|
}
|
package/index.js
CHANGED
|
@@ -216,7 +216,11 @@ export default class ContentAddressableStore {
|
|
|
216
216
|
put: async (options) => (await this.#getBundleService()).put(options),
|
|
217
217
|
putOrdered: async (options) => (await this.#getBundleService()).putOrdered(options),
|
|
218
218
|
getMember: async (options) => (await this.#getBundleService()).getMember(options),
|
|
219
|
+
getMemberReference: async (options) => (
|
|
220
|
+
await this.#getBundleService()
|
|
221
|
+
).getMemberReference(options),
|
|
219
222
|
iterateMembers: (options) => this.#iterateBundleMembers(options),
|
|
223
|
+
iterateMemberReferences: (options) => this.#iterateBundleMemberReferences(options),
|
|
220
224
|
openMember: (options) => this.#openBundleMember(options),
|
|
221
225
|
});
|
|
222
226
|
this.retention = Object.freeze({
|
|
@@ -486,6 +490,12 @@ export default class ContentAddressableStore {
|
|
|
486
490
|
yield* bundles.openMember(options);
|
|
487
491
|
}
|
|
488
492
|
|
|
493
|
+
/** @returns {AsyncIterable<object>} */
|
|
494
|
+
async *#iterateBundleMemberReferences(options) {
|
|
495
|
+
const bundles = await this.#getBundleService();
|
|
496
|
+
yield* bundles.iterateMemberReferences(options);
|
|
497
|
+
}
|
|
498
|
+
|
|
489
499
|
/** @returns {AsyncIterable<object>} */
|
|
490
500
|
async *#iterateBundleMembers(options) {
|
|
491
501
|
const bundles = await this.#getBundleService();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@git-stunts/git-cas",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
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",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"docs/releases/v6.2.0.md",
|
|
37
37
|
"docs/releases/v6.3.0.md",
|
|
38
38
|
"docs/releases/v6.4.0.md",
|
|
39
|
+
"docs/releases/v6.5.0.md",
|
|
39
40
|
"docs/THREAT_MODEL.md",
|
|
40
41
|
"docs/VAULT_INTERNALS.md",
|
|
41
42
|
"docs/WALKTHROUGH.md",
|
|
@@ -7,12 +7,15 @@ import BundleHandle from '../value-objects/BundleHandle.js';
|
|
|
7
7
|
import BundleLimits from '../value-objects/BundleLimits.js';
|
|
8
8
|
import normalizeBundlePath from '../value-objects/BundlePath.js';
|
|
9
9
|
import StagedBundle from '../value-objects/StagedBundle.js';
|
|
10
|
+
import BoundedPromiseCache from '../../helpers/boundedPromiseCache.js';
|
|
10
11
|
import BundleDescriptorCodec, { BUNDLE_INDEX_ENTRY } from './BundleDescriptorCodec.js';
|
|
11
12
|
import BundleFanoutBuilder from './BundleFanoutBuilder.js';
|
|
12
13
|
import StagingEvidence from './StagingEvidence.js';
|
|
13
14
|
|
|
14
15
|
const DEFAULT_CLOCK = Object.freeze({ now: () => new Date() });
|
|
15
16
|
const DEFAULT_MAX_NESTING_DEPTH = 32;
|
|
17
|
+
const DESCRIPTOR_CACHE_ENTRIES = 1_024;
|
|
18
|
+
const DESCRIPTOR_CACHE_BYTES = 16 * 1024 * 1024;
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* Builds and traverses deterministic, targeted structured bundle trees.
|
|
@@ -20,6 +23,10 @@ const DEFAULT_MAX_NESTING_DEPTH = 32;
|
|
|
20
23
|
export default class BundleService {
|
|
21
24
|
#clock;
|
|
22
25
|
#codec;
|
|
26
|
+
#descriptorBlobs = new BoundedPromiseCache(DESCRIPTOR_CACHE_ENTRIES, {
|
|
27
|
+
maxWeight: DESCRIPTOR_CACHE_BYTES,
|
|
28
|
+
weightOf: (value) => value.byteLength,
|
|
29
|
+
});
|
|
23
30
|
#limits;
|
|
24
31
|
#maxNestingDepth;
|
|
25
32
|
#openHandle;
|
|
@@ -104,14 +111,30 @@ export default class BundleService {
|
|
|
104
111
|
return member === null ? null : await this.#resolveMemberReference(member, BundleHandle.from(value));
|
|
105
112
|
}
|
|
106
113
|
|
|
107
|
-
/**
|
|
114
|
+
/** Returns one descriptor after validating the bundle structure and direct Git edge. */
|
|
108
115
|
async getMemberReference({ handle: value, path: rawPath }) {
|
|
109
116
|
const handle = BundleHandle.from(value);
|
|
110
117
|
const path = normalizeBundlePath(rawPath, this.#limits.maxMemberPathBytes);
|
|
111
118
|
const root = await this.#readRoot(handle);
|
|
112
119
|
let nodeOid = root.index.oid;
|
|
120
|
+
let expectedSummary = null;
|
|
121
|
+
let parentTreeOid = handle.oid;
|
|
122
|
+
let descriptorBytes = root.descriptorBytes;
|
|
113
123
|
while (true) {
|
|
114
124
|
const node = await this.#readNode(nodeOid, root.descriptor.limits);
|
|
125
|
+
descriptorBytes += node.descriptorBytes;
|
|
126
|
+
if (descriptorBytes > root.descriptor.limits.maxDescriptorBytes) {
|
|
127
|
+
throw corrupt('Bundle descriptors exceed their persisted byte limit', {
|
|
128
|
+
descriptorBytes,
|
|
129
|
+
maxDescriptorBytes: root.descriptor.limits.maxDescriptorBytes,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const actualSummary = summaryOf(node.descriptor, nodeOid);
|
|
133
|
+
if (expectedSummary === null) {
|
|
134
|
+
assertSummary(root.descriptor, actualSummary);
|
|
135
|
+
} else {
|
|
136
|
+
assertChildSummary(expectedSummary, actualSummary, parentTreeOid);
|
|
137
|
+
}
|
|
115
138
|
if (node.descriptor.kind === 'leaf') {
|
|
116
139
|
return await this.#referenceFromLeaf({
|
|
117
140
|
bundleHandle: handle,
|
|
@@ -125,6 +148,8 @@ export default class BundleService {
|
|
|
125
148
|
return null;
|
|
126
149
|
}
|
|
127
150
|
const edge = await this.#requiredEdge(nodeOid, child.slot, 'tree');
|
|
151
|
+
expectedSummary = child;
|
|
152
|
+
parentTreeOid = nodeOid;
|
|
128
153
|
nodeOid = edge.oid;
|
|
129
154
|
}
|
|
130
155
|
}
|
|
@@ -206,7 +231,7 @@ export default class BundleService {
|
|
|
206
231
|
yield* this.#iterateMemberReferences(value, { validateTargets: true });
|
|
207
232
|
}
|
|
208
233
|
|
|
209
|
-
/**
|
|
234
|
+
/** Streams descriptors after validating bundle structure and direct Git edges. */
|
|
210
235
|
async *iterateMemberReferences({ handle: value }) {
|
|
211
236
|
yield* this.#iterateMemberReferences(value, { validateTargets: false });
|
|
212
237
|
}
|
|
@@ -587,7 +612,11 @@ export default class BundleService {
|
|
|
587
612
|
|
|
588
613
|
async #readDescriptorBlob(oid, meta, maxBytes) {
|
|
589
614
|
try {
|
|
590
|
-
|
|
615
|
+
const bytes = await this.#descriptorBlobs.getOrCreate(
|
|
616
|
+
`${oid}\0${maxBytes}`,
|
|
617
|
+
() => this.#persistence.readBlob(oid, maxBytes),
|
|
618
|
+
);
|
|
619
|
+
return Uint8Array.from(bytes);
|
|
591
620
|
} catch (error) {
|
|
592
621
|
throw corrupt('Bundle descriptor blob is missing or unreadable', { ...meta, oid, originalError: error });
|
|
593
622
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import CasError from '../errors/CasError.js';
|
|
2
2
|
import { ErrorCodes } from '../errors/index.js';
|
|
3
3
|
import { errorDetailsText, isGitMissingRefError } from '../helpers/gitRefErrors.js';
|
|
4
|
+
import Oid from '../value-objects/Oid.js';
|
|
4
5
|
import RootSetRef from '../value-objects/RootSetRef.js';
|
|
5
6
|
import RootSetMetadataCodec, { ROOT_SET_METADATA_ENTRY } from './RootSetMetadataCodec.js';
|
|
6
7
|
import RootSetTreeCodec from './RootSetTreeCodec.js';
|
|
@@ -11,16 +12,14 @@ const UPDATE_REF_CONFLICT_MARKERS = Object.freeze({
|
|
|
11
12
|
referenceAlreadyExists: 'reference already exists',
|
|
12
13
|
});
|
|
13
14
|
const GIT_REPOSITORY_LOCKED = 'GIT_REPOSITORY_LOCKED';
|
|
15
|
+
const GIT_FATAL_EXIT_CODE = 128;
|
|
14
16
|
|
|
15
|
-
function
|
|
17
|
+
function hasExactUpdateRefArgs(err, {
|
|
16
18
|
rootSetRef,
|
|
17
19
|
newCommit,
|
|
18
20
|
expectedHeadOid,
|
|
19
21
|
}) {
|
|
20
22
|
const details = err?.details && typeof err.details === 'object' ? err.details : {};
|
|
21
|
-
if (details.code !== GIT_REPOSITORY_LOCKED) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
23
|
if (!Array.isArray(details.args)) {
|
|
25
24
|
return false;
|
|
26
25
|
}
|
|
@@ -35,6 +34,48 @@ function classifyStructuredUpdateRefConflict(err, {
|
|
|
35
34
|
expectedArgs.every((arg, index) => details.args[index] === arg);
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
function classifyStructuredUpdateRefConflict(err, {
|
|
38
|
+
rootSetRef,
|
|
39
|
+
newCommit,
|
|
40
|
+
expectedHeadOid,
|
|
41
|
+
}) {
|
|
42
|
+
const details = err?.details && typeof err.details === 'object' ? err.details : {};
|
|
43
|
+
if (details.code !== GIT_REPOSITORY_LOCKED) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return hasExactUpdateRefArgs(err, { rootSetRef, newCommit, expectedHeadOid });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isObservedUpdateRefConflict(err, {
|
|
50
|
+
rootSetRef,
|
|
51
|
+
newCommit,
|
|
52
|
+
expectedHeadOid,
|
|
53
|
+
actualHeadOid,
|
|
54
|
+
}) {
|
|
55
|
+
const details = err?.details && typeof err.details === 'object' ? err.details : {};
|
|
56
|
+
if (!Oid.isValid(actualHeadOid)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const canonicalActualHeadOid = Oid.from(actualHeadOid).toString();
|
|
60
|
+
const canonicalExpectedHeadOid = Oid.isValid(expectedHeadOid)
|
|
61
|
+
? Oid.from(expectedHeadOid).toString()
|
|
62
|
+
: expectedHeadOid;
|
|
63
|
+
return details.code === GIT_FATAL_EXIT_CODE &&
|
|
64
|
+
canonicalActualHeadOid !== canonicalExpectedHeadOid &&
|
|
65
|
+
hasExactUpdateRefArgs(err, { rootSetRef, newCommit, expectedHeadOid });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hasTextualUpdateRefConflict(err, rootSetRef) {
|
|
69
|
+
const normalized = errorDetailsText(err).toLowerCase();
|
|
70
|
+
if (!normalized.includes(rootSetRef.toLowerCase())) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return normalized.includes(UPDATE_REF_CONFLICT_MARKERS.cannotLockRef) && (
|
|
74
|
+
normalized.includes(UPDATE_REF_CONFLICT_MARKERS.butExpected) ||
|
|
75
|
+
normalized.includes(UPDATE_REF_CONFLICT_MARKERS.referenceAlreadyExists)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
38
79
|
/**
|
|
39
80
|
* Stateless persistence boundary for one root-set ref and snapshot format.
|
|
40
81
|
*/
|
|
@@ -238,7 +279,11 @@ export default class RootSetPersistence {
|
|
|
238
279
|
});
|
|
239
280
|
} catch (err) {
|
|
240
281
|
const meta = await this.#updateFailureMeta(err, commitOid, expectedHeadOid);
|
|
241
|
-
if (this.#isConflict(err,
|
|
282
|
+
if (this.#isConflict(err, {
|
|
283
|
+
newCommit: commitOid,
|
|
284
|
+
expectedHeadOid,
|
|
285
|
+
actualHeadOid: meta.actualHeadOid,
|
|
286
|
+
})) {
|
|
242
287
|
throw new CasError(
|
|
243
288
|
'Concurrent root-set update detected',
|
|
244
289
|
ErrorCodes.ROOT_SET_CONFLICT,
|
|
@@ -272,7 +317,7 @@ export default class RootSetPersistence {
|
|
|
272
317
|
};
|
|
273
318
|
}
|
|
274
319
|
|
|
275
|
-
#isConflict(err, newCommit, expectedHeadOid) {
|
|
320
|
+
#isConflict(err, { newCommit, expectedHeadOid, actualHeadOid }) {
|
|
276
321
|
const meta = err?.meta && typeof err.meta === 'object' ? err.meta : {};
|
|
277
322
|
if (Object.hasOwn(meta, 'expectedOldOid') && Object.hasOwn(meta, 'actualOldOid')) {
|
|
278
323
|
return true;
|
|
@@ -285,14 +330,17 @@ export default class RootSetPersistence {
|
|
|
285
330
|
if (structuredConflict !== null) {
|
|
286
331
|
return structuredConflict;
|
|
287
332
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
333
|
+
// A failed exact CAS command plus an independently observed head advance
|
|
334
|
+
// remains sufficient conflict evidence when Git emits no diagnostic text.
|
|
335
|
+
if (isObservedUpdateRefConflict(err, {
|
|
336
|
+
rootSetRef: this.rootSetRef,
|
|
337
|
+
newCommit,
|
|
338
|
+
expectedHeadOid,
|
|
339
|
+
actualHeadOid,
|
|
340
|
+
})) {
|
|
341
|
+
return true;
|
|
291
342
|
}
|
|
292
|
-
return
|
|
293
|
-
normalized.includes(UPDATE_REF_CONFLICT_MARKERS.butExpected) ||
|
|
294
|
-
normalized.includes(UPDATE_REF_CONFLICT_MARKERS.referenceAlreadyExists)
|
|
295
|
-
);
|
|
343
|
+
return hasTextualUpdateRefConflict(err, this.rootSetRef);
|
|
296
344
|
}
|
|
297
345
|
|
|
298
346
|
#isMissingRefError(err) {
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-residency LRU for in-flight and completed immutable reads.
|
|
3
|
+
* Rejected promises remove themselves so transient failures remain retryable.
|
|
4
|
+
*/
|
|
5
|
+
export default class BoundedPromiseCache {
|
|
6
|
+
/** @type {Map<string, { promise: Promise<unknown>, weight: number }>} */
|
|
7
|
+
#entries = new Map();
|
|
8
|
+
#maxEntries;
|
|
9
|
+
#maxWeight;
|
|
10
|
+
#totalWeight = 0;
|
|
11
|
+
#weightOf;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} maxEntries
|
|
15
|
+
* @param {object} [options]
|
|
16
|
+
* @param {number} [options.maxWeight=Infinity]
|
|
17
|
+
* @param {(value: unknown) => number} [options.weightOf]
|
|
18
|
+
*/
|
|
19
|
+
constructor(maxEntries, { maxWeight = Number.POSITIVE_INFINITY, weightOf = () => 0 } = {}) {
|
|
20
|
+
if (!Number.isSafeInteger(maxEntries) || maxEntries < 1) {
|
|
21
|
+
throw new TypeError('maxEntries must be a positive safe integer');
|
|
22
|
+
}
|
|
23
|
+
if (
|
|
24
|
+
maxWeight !== Number.POSITIVE_INFINITY &&
|
|
25
|
+
(!Number.isSafeInteger(maxWeight) || maxWeight < 0)
|
|
26
|
+
) {
|
|
27
|
+
throw new TypeError('maxWeight must be a non-negative safe integer or Infinity');
|
|
28
|
+
}
|
|
29
|
+
if (typeof weightOf !== 'function') {
|
|
30
|
+
throw new TypeError('weightOf must be a function');
|
|
31
|
+
}
|
|
32
|
+
this.#maxEntries = maxEntries;
|
|
33
|
+
this.#maxWeight = maxWeight;
|
|
34
|
+
this.#weightOf = weightOf;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @template T
|
|
39
|
+
* @param {string} key
|
|
40
|
+
* @param {() => Promise<T>|T} factory
|
|
41
|
+
* @returns {Promise<T>}
|
|
42
|
+
*/
|
|
43
|
+
getOrCreate(key, factory) {
|
|
44
|
+
const cached = this.#entries.get(key);
|
|
45
|
+
if (cached !== undefined) {
|
|
46
|
+
this.#entries.delete(key);
|
|
47
|
+
this.#entries.set(key, cached);
|
|
48
|
+
return cached.promise;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const source = Promise.resolve().then(factory);
|
|
52
|
+
const entry = { promise: source, weight: 0 };
|
|
53
|
+
const tracked = source.then(
|
|
54
|
+
(value) => {
|
|
55
|
+
if (this.#entries.get(key) === entry) {
|
|
56
|
+
let weight;
|
|
57
|
+
try {
|
|
58
|
+
weight = this.#resolvedWeight(value);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
this.#remove(key, entry);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (weight > this.#maxWeight) {
|
|
64
|
+
this.#remove(key, entry);
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
entry.weight = weight;
|
|
68
|
+
this.#totalWeight += entry.weight;
|
|
69
|
+
this.#evict();
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
},
|
|
73
|
+
(error) => {
|
|
74
|
+
if (this.#entries.get(key) === entry) {
|
|
75
|
+
this.#remove(key, entry);
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
entry.promise = tracked;
|
|
81
|
+
this.#entries.set(key, entry);
|
|
82
|
+
this.#evict();
|
|
83
|
+
return tracked;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#resolvedWeight(value) {
|
|
87
|
+
const weight = this.#weightOf(value);
|
|
88
|
+
if (!Number.isSafeInteger(weight) || weight < 0) {
|
|
89
|
+
throw new TypeError('weightOf must return a non-negative safe integer');
|
|
90
|
+
}
|
|
91
|
+
return weight;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#evict() {
|
|
95
|
+
while (this.#entries.size > this.#maxEntries || this.#totalWeight > this.#maxWeight) {
|
|
96
|
+
const oldestKey = this.#entries.keys().next().value;
|
|
97
|
+
const oldest = this.#entries.get(oldestKey);
|
|
98
|
+
this.#remove(oldestKey, oldest);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#remove(key, entry) {
|
|
103
|
+
if (entry === undefined || !this.#entries.delete(key)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.#totalWeight -= entry.weight;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -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 BoundedPromiseCache from '../../helpers/boundedPromiseCache.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Default resilience policy: 30 s timeout (no retry).
|
|
@@ -15,8 +16,10 @@ import { CasError, createCasError, ErrorCodes } from '../../domain/errors/index.
|
|
|
15
16
|
*/
|
|
16
17
|
const DEFAULT_POLICY = Policy.timeout(30_000);
|
|
17
18
|
export const DEFAULT_MAX_BLOB_SIZE = 10 * 1024 * 1024;
|
|
19
|
+
const DEFAULT_METADATA_CACHE_ENTRIES = 2_048;
|
|
18
20
|
const MIN_READ_BLOB_LIMIT = 1;
|
|
19
21
|
const MIN_MAX_BLOB_SIZE = 1024;
|
|
22
|
+
const MIN_METADATA_CACHE_ENTRIES = 1;
|
|
20
23
|
const MAX_BLOB_SIZE_LIMIT = Number.MAX_SAFE_INTEGER;
|
|
21
24
|
const OBJECT_INFO_ARGUMENT = '--batch-check=%(objectname) %(objecttype) %(objectsize)';
|
|
22
25
|
const GIT_OBJECT_TYPES = new Set(['blob', 'tree', 'commit', 'tag']);
|
|
@@ -25,19 +28,25 @@ const GIT_OBJECT_TYPES = new Set(['blob', 'tree', 'commit', 'tag']);
|
|
|
25
28
|
* {@link GitPersistencePort} implementation backed by `@git-stunts/plumbing`.
|
|
26
29
|
*
|
|
27
30
|
* All Git I/O is wrapped with a configurable resilience {@link Policy}
|
|
28
|
-
* (30 s timeout by default).
|
|
31
|
+
* (30 s timeout by default). Successful metadata reads assume referenced roots
|
|
32
|
+
* remain retained while this adapter is in use; destructive external pruning
|
|
33
|
+
* must not race active operations.
|
|
29
34
|
*/
|
|
30
35
|
export default class GitPersistenceAdapter extends GitPersistencePort {
|
|
31
36
|
#maxBlobSize = DEFAULT_MAX_BLOB_SIZE;
|
|
37
|
+
#metadataCache;
|
|
32
38
|
/**
|
|
33
39
|
* @param {Object} options
|
|
34
40
|
* @param {import('@git-stunts/plumbing').default} options.plumbing - GitPlumbing instance.
|
|
35
41
|
* @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy (defaults to 30 s timeout, no retry).
|
|
42
|
+
* @param {number} [options.metadataCacheEntries=2048] - Maximum immutable metadata entries retained by this adapter.
|
|
36
43
|
*/
|
|
37
|
-
constructor({ plumbing, policy }) {
|
|
44
|
+
constructor({ plumbing, policy, metadataCacheEntries = DEFAULT_METADATA_CACHE_ENTRIES }) {
|
|
38
45
|
super();
|
|
46
|
+
GitPersistenceAdapter.#assertMetadataCacheEntries(metadataCacheEntries);
|
|
39
47
|
this.plumbing = plumbing;
|
|
40
48
|
this.policy = policy ?? DEFAULT_POLICY;
|
|
49
|
+
this.#metadataCache = new BoundedPromiseCache(metadataCacheEntries);
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
/**
|
|
@@ -145,12 +154,15 @@ export default class GitPersistenceAdapter extends GitPersistencePort {
|
|
|
145
154
|
* @returns {Promise<{ mode: string, type: string, oid: string, name: string }|null>}
|
|
146
155
|
*/
|
|
147
156
|
async readTreeEntry(treeOid, treePath) {
|
|
148
|
-
|
|
157
|
+
const key = `tree\0${treeOid}\0${treePath}`;
|
|
158
|
+
const entry = await this.#metadataCache.getOrCreate(key, () => this.policy.execute(async () => {
|
|
149
159
|
const output = await this.plumbing.execute({
|
|
150
160
|
args: ['ls-tree', '-z', treeOid, '--', treePath],
|
|
151
161
|
});
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
const found = GitPersistenceAdapter.#parseTreeOutput(output)[0] || null;
|
|
163
|
+
return found === null ? null : Object.freeze(found);
|
|
164
|
+
}));
|
|
165
|
+
return entry === null ? null : { ...entry };
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
/**
|
|
@@ -209,32 +221,51 @@ export default class GitPersistenceAdapter extends GitPersistencePort {
|
|
|
209
221
|
* @returns {Promise<{ oid: string, type: string, size: number }>} Object metadata.
|
|
210
222
|
*/
|
|
211
223
|
async #readObjectInfo(oid) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
oid,
|
|
220
|
-
|
|
221
|
-
|
|
224
|
+
return this.#metadataCache.getOrCreate(`object\0${oid}`, async () => {
|
|
225
|
+
const rawOutput = await this.policy.execute(() => this.plumbing.execute({
|
|
226
|
+
args: ['cat-file', OBJECT_INFO_ARGUMENT],
|
|
227
|
+
input: `${oid}\n`,
|
|
228
|
+
}));
|
|
229
|
+
const output = typeof rawOutput === 'string' ? rawOutput.trim() : '';
|
|
230
|
+
if (output === `${oid} missing`) {
|
|
231
|
+
throw new CasError(`Git object not found: ${oid}`, ErrorCodes.GIT_OBJECT_NOT_FOUND, {
|
|
232
|
+
oid,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
222
235
|
|
|
223
|
-
|
|
224
|
-
|
|
236
|
+
const fields = output.split(' ');
|
|
237
|
+
const size = Number(fields[2]);
|
|
238
|
+
if (
|
|
239
|
+
fields.length !== 3 ||
|
|
240
|
+
fields[0] !== oid ||
|
|
241
|
+
!GIT_OBJECT_TYPES.has(fields[1]) ||
|
|
242
|
+
!Number.isSafeInteger(size) ||
|
|
243
|
+
size < 0
|
|
244
|
+
) {
|
|
245
|
+
throw new CasError(`Git object has invalid metadata: ${oid}`, ErrorCodes.GIT_ERROR, {
|
|
246
|
+
oid,
|
|
247
|
+
output: rawOutput,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return Object.freeze({ oid: fields[0], type: fields[1], size });
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @param {number} metadataCacheEntries
|
|
256
|
+
*/
|
|
257
|
+
static #assertMetadataCacheEntries(metadataCacheEntries) {
|
|
225
258
|
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
!GIT_OBJECT_TYPES.has(fields[1]) ||
|
|
229
|
-
!Number.isSafeInteger(size) ||
|
|
230
|
-
size < 0
|
|
259
|
+
Number.isSafeInteger(metadataCacheEntries) &&
|
|
260
|
+
metadataCacheEntries >= MIN_METADATA_CACHE_ENTRIES
|
|
231
261
|
) {
|
|
232
|
-
|
|
233
|
-
oid,
|
|
234
|
-
output: rawOutput,
|
|
235
|
-
});
|
|
262
|
+
return;
|
|
236
263
|
}
|
|
237
|
-
|
|
264
|
+
throw createCasError(
|
|
265
|
+
'Git metadata cache entries must be a positive safe integer',
|
|
266
|
+
ErrorCodes.INVALID_OPTIONS,
|
|
267
|
+
{ option: 'metadataCacheEntries', metadataCacheEntries },
|
|
268
|
+
);
|
|
238
269
|
}
|
|
239
270
|
|
|
240
271
|
/**
|
package/src/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '6.
|
|
1
|
+
export const PACKAGE_VERSION = '6.5.0';
|