@git-stunts/git-cas 6.5.8 → 6.5.9

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 CHANGED
@@ -182,6 +182,15 @@ The facade is orchestration glue. It is not the storage engine itself.
182
182
  bundles build deterministic bounded-fanout trees and support targeted member
183
183
  traversal without hydrating the complete structure.
184
184
 
185
+ - **`StagingWorkspaceRegistry` and `StagingWorkspace`** — own renewable
186
+ temporary RootSet generations for multi-step application construction.
187
+ `WorkspaceCompoundAdmission` and `WorkspaceCompoundScope` serialize an
188
+ explicitly bounded sequence of provisional page and bundle batches through
189
+ one operation-owned persistence view, then install the union of prior and new
190
+ targets in one exact generation. Existing workspace methods retain each
191
+ result independently and remain the boundary when a handle leaves private
192
+ construction code before later writes begin.
193
+
185
194
  - **`RetentionService` and `PublicationService`** — validate complete handle
186
195
  graphs, then either retain them in a RootSet with generation-scoped evidence
187
196
  or publish them atomically under an allowlisted application ref.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.5.9] — 2026-08-24
11
+
12
+ ### Added
13
+
14
+ - **Compound staging-workspace admission** - `workspace.batch()` runs an
15
+ explicitly operation-bounded sequence of dependent page and ordered-bundle
16
+ batches through one private persistence scope, then returns the callback
17
+ value only after one exact workspace generation retains every staged handle.
18
+ Scope calls serialize by invocation order, return frozen handle arrays, stop
19
+ queued work after failure, and preserve the prior generation on refusal.
20
+
21
+ ### Performance
22
+
23
+ - **One retained generation for dependent write waves** - a clean five-sample
24
+ SHA-1/SHA-256 witness reduced a 33-operation, 81-handle graph from 200 to 23
25
+ Git child processes and from 33 workspace commits and checked ref updates to
26
+ one, with identical application-handle digests. Median wall time fell by
27
+ 80.5% on the measured host. Compound admission changes workspace-ref update
28
+ frequency, while object bytes, handle identity, ref layout and namespaces,
29
+ readers, and existing independently retained workspace methods remain
30
+ compatible.
31
+
10
32
  ## [6.5.8] — 2026-08-23
11
33
 
12
34
  ### Added
package/GUIDE.md CHANGED
@@ -202,6 +202,31 @@ no partial result array on failure. Higher `maxBatchAssets` values can reduce
202
202
  protocol round trips when the caller can afford more simultaneously live
203
203
  source pipelines; the default remains four.
204
204
 
205
+ When later bundle waves depend on handles created by earlier waves, keep the
206
+ intermediate handles inside one compound staging-workspace operation:
207
+
208
+ ```js
209
+ const admitted = await workspace.batch({
210
+ maxOperations: 3,
211
+ operation: async (scope) => {
212
+ const pages = await scope.pages.putBatch({ pages: pageRequests });
213
+ const leaves = await scope.bundles.putOrderedBatch({
214
+ bundles: leafRequests(pages),
215
+ });
216
+ return (await scope.bundles.putOrderedBatch({
217
+ bundles: [rootRequest(leaves)],
218
+ }))[0];
219
+ },
220
+ });
221
+ ```
222
+
223
+ `admitted.value` becomes caller-visible only with `admitted.retention`, after
224
+ one exact workspace generation anchors every staged handle. The default
225
+ operation ceiling is 64 and the hard ceiling is 1,024; each scope call also
226
+ preserves its ordinary page or bundle batch bounds. Use the existing
227
+ independently retained workspace methods when intermediate handles must leave
228
+ the private callback.
229
+
205
230
  Repeated `pages.get()` calls reuse immutable payload reads within the store's
206
231
  bounded page cache. The defaults retain at most 128 payloads and 8 MiB; use
207
232
  `pageCacheEntries` and `pageCacheBytes` to tune that ceiling. Every result is a
package/README.md CHANGED
@@ -41,8 +41,9 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
41
41
  blob reads at or below a fixed 10 MiB ceiling use one bounded session read;
42
42
  larger payloads retain the genuine one-shot streaming path. Explicitly
43
43
  bounded page, asset, and ordered-bundle batches pipeline independent Git
44
- writes and retain each successful workspace batch under one exact generation
45
- without changing content identity.
44
+ writes. `workspace.batch()` can compose dependent page and bundle waves in
45
+ one private persistence scope and retain their union under one exact final
46
+ generation without changing content identity.
46
47
  - **Key Lifecycle**: Envelope encryption separates DEKs from KEKs. Rotate passphrases across an entire vault without re-encrypting data blobs. Privacy mode HMAC-hashes slug names to prevent metadata discovery.
47
48
  - **Runtime-Adaptive**: A single core supports Node.js 22+, Bun, and Deno through a strict hexagonal port architecture with runtime-specific crypto adapters.
48
49
 
@@ -51,7 +52,7 @@ Unlike traditional LFS which moves files to external servers, `git-cas` treats t
51
52
  Existing v5 users should read [UPGRADING.md](./UPGRADING.md) and run
52
53
  `npm run upgrade` in dry-run mode before restoring old encrypted vault entries.
53
54
  For the release overview, see the
54
- [v6.5.8 Release Notes](./docs/releases/v6.5.8.md).
55
+ [v6.5.9 Release Notes](./docs/releases/v6.5.9.md).
55
56
 
56
57
  ### 1. CLI Usage
57
58
 
@@ -157,9 +158,10 @@ Core capabilities:
157
158
  compare-and-swap refs, and immutable lifecycle evidence.
158
159
  - **Scoped staging workspaces**: `workspaces.open()` mirrors application writes
159
160
  behind one renewable temporary RootSet, supports one-generation bounded
160
- asset/page/bundle batches, returns only after each handle is anchored, promotes
161
- destination-first, and exposes bounded age, expiry, logical-content, and
162
- direct-root diagnostics with opaque cleanup pagination.
161
+ asset/page/bundle batches plus compound dependent page/bundle admission,
162
+ returns only after each public result is anchored, promotes destination-first,
163
+ and exposes bounded age, expiry, logical-content, and direct-root diagnostics
164
+ with opaque cleanup pagination.
163
165
  - **Envelope recipients**: multi-recipient key wrapping and recipient rotation
164
166
  avoid re-encrypting data blobs.
165
167
  - **Operational diagnostics**: `cas.diagnostics.doctor()` streams repository
@@ -236,6 +238,8 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
236
238
  sessions for small streaming blob reads while large payloads remain streamed.
237
239
  - **[v6.5.8 Release Notes](./docs/releases/v6.5.8.md)**: Bounded application
238
240
  write waves, one-generation workspace batches, and reusable ref sessions.
241
+ - **[v6.5.9 Release Notes](./docs/releases/v6.5.9.md)**: Compound dependent
242
+ write waves retained under one exact staging-workspace generation.
239
243
  - **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
240
244
  - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
241
245
 
package/UPGRADING.md CHANGED
@@ -2,6 +2,45 @@
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.5.8 To v6.5.9
6
+
7
+ v6.5.9 adds `workspace.batch()` and requires no application or stored-data
8
+ migration. Existing handles, object bytes, workspace descriptors, ref
9
+ namespaces, retention witnesses, read paths, and independently retained
10
+ workspace methods remain compatible. Existing repositories open in place.
11
+
12
+ Use the new method only when intermediate page and bundle handles remain
13
+ private to one bounded construction:
14
+
15
+ ```js
16
+ const admitted = await workspace.batch({
17
+ maxOperations: 3,
18
+ operation: async (scope) => {
19
+ const pages = await scope.pages.putBatch({ pages: pageRequests });
20
+ const leaves = await scope.bundles.putOrderedBatch({
21
+ bundles: buildLeafRequests(pages),
22
+ });
23
+ return (await scope.bundles.putOrderedBatch({
24
+ bundles: [buildRootRequest(leaves)],
25
+ }))[0];
26
+ },
27
+ });
28
+
29
+ admitted.value; // retained root BundleHandle
30
+ admitted.retention; // exact final workspace generation and witnesses
31
+ ```
32
+
33
+ The operation defaults to at most 64 scope calls and cannot exceed 1,024.
34
+ Every page or bundle call retains its existing count, object, member, and byte
35
+ bounds. A callback or staged-write failure publishes no compound generation;
36
+ immutable objects written before failure remain unreachable for Git's normal
37
+ reclamation. Use the existing workspace methods when a handle must become
38
+ independently retained before arbitrary caller code observes it.
39
+
40
+ The release changes physical admission cost only. It does not introduce a new
41
+ transaction format, migration command, authority cutover, or mixed-version
42
+ rewrite.
43
+
5
44
  ## v6.5.7 To v6.5.8
6
45
 
7
46
  v6.5.8 adds bounded application-write batches and requires no application or
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "57b4055",
3
- "timestamp": "2026-08-24T04:37:19.926Z"
2
+ "sha": "a16e31a",
3
+ "timestamp": "2026-08-24T19:12:20.728Z"
4
4
  }
package/docs/API.md CHANGED
@@ -1436,6 +1436,55 @@ await workspace.bundles.putOrdered(options);
1436
1436
  await workspace.bundles.putOrderedBatch(options);
1437
1437
  ```
1438
1438
 
1439
+ Dependent page and bundle waves can instead share one bounded compound
1440
+ admission:
1441
+
1442
+ ```javascript
1443
+ const admitted = await workspace.batch({
1444
+ maxOperations: 3,
1445
+ operation: async (scope) => {
1446
+ const pages = await scope.pages.putBatch({ pages: pageRequests });
1447
+ const leaves = await scope.bundles.putOrderedBatch({
1448
+ bundles: buildLeafRequests(pages),
1449
+ });
1450
+ return (await scope.bundles.putOrderedBatch({
1451
+ bundles: [buildRootRequest(leaves)],
1452
+ }))[0];
1453
+ },
1454
+ });
1455
+
1456
+ admitted.value; // BundleHandle returned by the callback
1457
+ admitted.retention; // exact WorkspaceCheckpointResult
1458
+ ```
1459
+
1460
+ `batch({ operation, maxOperations })` calls `operation` exactly once. Its scope
1461
+ exposes only `pages.putBatch()` and `bundles.putOrderedBatch()`. Both methods
1462
+ retain their existing per-call limits and validation, serialize by invocation
1463
+ order, and return frozen arrays of provisional handles rather than staged
1464
+ result objects. The operation defaults to at most 64 scope calls and rejects a
1465
+ limit above the exported hard maximum of 1,024.
1466
+
1467
+ Success installs the union of previously retained targets and every compound
1468
+ target in one exact workspace generation. The returned `value` is the callback
1469
+ value; it becomes caller-visible only after scoped Git resources close and the
1470
+ paired `retention` result proves the final generation. The scope closes before
1471
+ the outer promise settles. Calling an escaped scope later fails with
1472
+ `WORKSPACE_STATE_INVALID`.
1473
+
1474
+ The callback is trusted application code, not a JavaScript capability sandbox.
1475
+ The API cannot prevent a callback from assigning a provisional handle into
1476
+ external state as a side effect. Such a handle has no compound retention
1477
+ witness and must not be used outside the callback. Only the settled outer
1478
+ result carries the admission guarantee.
1479
+
1480
+ An empty operation, invalid bound, callback failure, staged-write failure,
1481
+ session-close failure, or final checked-ref failure returns no admitted value.
1482
+ Queued work stops after the first failure, the prior workspace generation does
1483
+ not move, and distinct callback/write or operation/close failures remain
1484
+ available through `AggregateError`. Immutable objects written before refusal
1485
+ may remain unreachable for Git's ordinary reclamation. Compound admission is
1486
+ not a cross-workspace, cross-ref, or arbitrary application transaction.
1487
+
1439
1488
  Each method returns only after a direct workspace generation reaches the
1440
1489
  returned typed handle. The result is otherwise the ordinary staged result plus
1441
1490
  a workspace `RetentionWitness`. Calls on one workspace serialize their ref
@@ -0,0 +1,119 @@
1
+ # git-cas v6.5.9 Release Notes
2
+
3
+ v6.5.9 adds bounded compound staging-workspace admission for applications that
4
+ construct dependency-ordered page and bundle graphs. It replaces one temporary
5
+ retention publication per construction wave with one exact final workspace
6
+ generation, without changing application handles, stored object bytes,
7
+ workspace descriptors, ref layout or namespaces, readers, or existing
8
+ workspace methods. Successful compound admission deliberately reduces
9
+ workspace-ref update frequency.
10
+
11
+ ## Compound Workspace Admission
12
+
13
+ `workspace.batch()` owns one bounded callback and one operation-scoped Git
14
+ persistence view:
15
+
16
+ ```js
17
+ const admitted = await workspace.batch({
18
+ maxOperations: 3,
19
+ operation: async (scope) => {
20
+ const pages = await scope.pages.putBatch({ pages: pageRequests });
21
+ const leaves = await scope.bundles.putOrderedBatch({
22
+ bundles: buildLeafRequests(pages),
23
+ });
24
+ return (
25
+ await scope.bundles.putOrderedBatch({
26
+ bundles: [buildRootRequest(leaves)],
27
+ })
28
+ )[0];
29
+ },
30
+ });
31
+
32
+ admitted.value;
33
+ admitted.retention;
34
+ ```
35
+
36
+ The scope exposes only the existing bounded page-batch and ordered-bundle-batch
37
+ operations. Calls serialize by invocation order and return frozen handle
38
+ arrays for later dependency waves. The default scope limit is 64 operations;
39
+ the exported hard limit is 1,024. Every call also retains its existing page,
40
+ bundle, member, object, and byte ceilings.
41
+
42
+ Success installs the union of previously retained workspace targets and every
43
+ new compound target exactly once. The callback value becomes caller-visible
44
+ only after scoped Git resources close and the paired retention result names the
45
+ exact final generation. Existing staging methods continue to retain their
46
+ result independently and remain appropriate when an intermediate handle must
47
+ leave private construction code.
48
+
49
+ ## Failure and Trust Boundary
50
+
51
+ Invalid bounds, empty operations, callback failure, staged-write failure,
52
+ session-close failure, and checked final-retention failure return no admitted
53
+ value and do not move the prior workspace generation. The first failure stops
54
+ later queued work. Distinct callback/write and operation/close failures remain
55
+ available through `AggregateError`. Immutable objects written before refusal
56
+ may remain unreachable for Git's ordinary reclamation.
57
+
58
+ The callback is trusted JavaScript. git-cas closes an escaped scope and never
59
+ returns the callback value before retention, but it cannot prevent callback
60
+ code from assigning a provisional handle into external state as a side effect.
61
+ Such a leaked handle has no compound retention witness and is outside the
62
+ contract.
63
+
64
+ ## Process-Topology Witness
65
+
66
+ The committed five-sample witness compares the same 33-operation graph under
67
+ independent per-wave retention and compound admission. Each mode produces 64
68
+ pages, 16 leaf bundles, one root bundle, and the same ordered sequence of 81
69
+ application handles in fresh SHA-1 and SHA-256 bare repositories.
70
+
71
+ | Format | Mode | Git children | Git interactions | Median wall ms | Worker CPU ms |
72
+ | ------- | -------- | -----------: | ---------------: | -------------: | ------------: |
73
+ | SHA-1 | per-wave | 200 | 380 | 3763.820 | 370.336 |
74
+ | SHA-1 | compound | 23 | 238 | 733.116 | 113.672 |
75
+ | SHA-256 | per-wave | 200 | 380 | 3709.930 | 373.898 |
76
+ | SHA-256 | compound | 23 | 238 | 726.976 | 114.407 |
77
+
78
+ Both formats reduced Git child creation by 88.5% and median wall time by about
79
+ 80.5% on the measured host: 200 to 23 Git children and 33 retained generations
80
+ to one. `fast-import`, `commit-tree`, symbolic-ref containment checks, and
81
+ checked ref updates fell from one per wave to one per compound admission. The
82
+ semantic handle digests matched exactly.
83
+
84
+ The remaining 18 `mktree` children preserve validation across interdependent
85
+ descriptor-pack visibility boundaries. Further reduction requires a separately
86
+ proved typed tree-writing protocol or equivalent deterministic construction;
87
+ this release does not bypass Git's object validation.
88
+
89
+ See the [machine witness](https://github.com/git-stunts/git-cas/blob/main/docs/design/0060-compound-workspace-admission/witness/compound-workspace-admission.json)
90
+ and [verification narrative](https://github.com/git-stunts/git-cas/blob/main/docs/design/0060-compound-workspace-admission/witness/verification.md)
91
+ for the exact source, environment, counts, digests, and method.
92
+
93
+ ## Reachability Proof
94
+
95
+ Real-Git integration tests cover SHA-1 and SHA-256 success and refusal. They
96
+ verify one checked publication, zero active scoped fast-import sessions after
97
+ settlement, immediate-prune readability while retained, reclamation after
98
+ checked release, and no workspace generation after a dependent wave fails.
99
+
100
+ ## Verification
101
+
102
+ Implementation review #124 merged normally as
103
+ `eb8d617620fa8f401fb887f5b1bbc341d4746b0a`; its exact reviewed head
104
+ `29ba6e88c787a5e54c95a554e9166fd21aae31c0` passed all 14 release-verifier
105
+ stages with 7,141 observed tests across Node, Bun, Deno, and all three real-Git
106
+ integration suites. Exact versioned candidate
107
+ `5512acd477bc5e5a11339d6027a03631d1a3544a` then passed the same 14-stage
108
+ method with 7,147 observed tests: 2,179 Node, 2,178 Bun, 2,169 Deno, and 207
109
+ integration tests in each runtime. No tag, npm artifact, or GitHub Release is
110
+ claimed by this candidate.
111
+
112
+ ## Compatibility
113
+
114
+ This release is additive and requires no application or stored-data migration.
115
+ Existing repositories open in place. It introduces no new object format,
116
+ descriptor version, ref namespace, reader, transaction log, authority cutover,
117
+ or mixed-version rewrite. Applications may leave every existing workspace call
118
+ unchanged and adopt `workspace.batch()` only where intermediate handles remain
119
+ private to one bounded construction.
package/index.d.ts CHANGED
@@ -1614,6 +1614,27 @@ export interface WorkspaceCheckpointResult {
1614
1614
  readonly witnesses: ReadonlyArray<RetentionWitness>;
1615
1615
  }
1616
1616
 
1617
+ export const DEFAULT_WORKSPACE_COMPOUND_OPERATIONS: 64;
1618
+ export const MAX_WORKSPACE_COMPOUND_OPERATIONS: 1024;
1619
+
1620
+ export interface WorkspaceCompoundScope {
1621
+ readonly pages: {
1622
+ putBatch(
1623
+ options: Parameters<PageCapability['putBatch']>[0],
1624
+ ): Promise<ReadonlyArray<PageHandle>>;
1625
+ };
1626
+ readonly bundles: {
1627
+ putOrderedBatch(
1628
+ options: Parameters<BundleCapability['putOrderedBatch']>[0],
1629
+ ): Promise<ReadonlyArray<BundleHandle>>;
1630
+ };
1631
+ }
1632
+
1633
+ export interface WorkspaceCompoundResult<T> {
1634
+ readonly value: T;
1635
+ readonly retention: WorkspaceCheckpointResult;
1636
+ }
1637
+
1617
1638
  export interface WorkspaceReleaseResult {
1618
1639
  readonly changed: boolean;
1619
1640
  readonly ref: string;
@@ -1691,6 +1712,10 @@ export declare class StagingWorkspace {
1691
1712
  options: Parameters<BundleCapability['putOrderedBatch']>[0],
1692
1713
  ): Promise<ReadonlyArray<WorkspaceRetainedBundle>>;
1693
1714
  };
1715
+ batch<T>(options: {
1716
+ operation(scope: WorkspaceCompoundScope): T | Promise<T>;
1717
+ maxOperations?: number;
1718
+ }): Promise<Readonly<WorkspaceCompoundResult<T>>>;
1694
1719
  checkpoint(options: { handles: Iterable<ApplicationHandleInput> }): Promise<WorkspaceCheckpointResult>;
1695
1720
  renew(): Promise<WorkspaceCheckpointResult>;
1696
1721
  promoteToCache(options: {
package/index.js CHANGED
@@ -110,6 +110,10 @@ export { default as RepositoryInspectionPort } from './src/ports/RepositoryInspe
110
110
  export { default as NodeCompressionAdapter } from './src/infrastructure/adapters/NodeCompressionAdapter.js';
111
111
  export { default as diffManifests } from './src/domain/services/ManifestDiff.js';
112
112
  export { SCHEME_WHOLE, SCHEME_FRAMED, SCHEME_CONVERGENT } from './src/domain/encryption/schemes.js';
113
+ export {
114
+ DEFAULT_WORKSPACE_COMPOUND_OPERATIONS,
115
+ MAX_WORKSPACE_COMPOUND_OPERATIONS,
116
+ } from './src/domain/services/WorkspaceCompoundScope.js';
113
117
 
114
118
  /**
115
119
  * High-level facade for the Content Addressable Store library.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@git-stunts/git-cas",
3
- "version": "6.5.8",
3
+ "version": "6.5.9",
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",
@@ -45,6 +45,7 @@
45
45
  "docs/releases/v6.5.6.md",
46
46
  "docs/releases/v6.5.7.md",
47
47
  "docs/releases/v6.5.8.md",
48
+ "docs/releases/v6.5.9.md",
48
49
  "docs/THREAT_MODEL.md",
49
50
  "docs/VAULT_INTERNALS.md",
50
51
  "docs/WALKTHROUGH.md",
@@ -103,6 +103,14 @@ export default class BundleService {
103
103
  * descriptor and tree dependency waves.
104
104
  */
105
105
  async putOrderedBatch(options = {}) {
106
+ return await withWriteScope(
107
+ this.#persistence,
108
+ async (persistence) => await this.putOrderedBatchWithPersistence(options, persistence),
109
+ );
110
+ }
111
+
112
+ /** @internal Builds a bounded bundle group through an operation-owned persistence view. */
113
+ async putOrderedBatchWithPersistence(options = {}, persistence) {
106
114
  const batch = BundleService.#batchOptions(options);
107
115
  const staging = new StagingEvidence();
108
116
  try {
@@ -110,15 +118,7 @@ export default class BundleService {
110
118
  if (admitted.length === 0) {
111
119
  return Object.freeze([]);
112
120
  }
113
- return await withWriteScope(
114
- this.#persistence,
115
- async (persistence) => await this.#writeAdmittedBatch({
116
- admitted,
117
- batch,
118
- persistence,
119
- staging,
120
- }),
121
- );
121
+ return await this.#writeAdmittedBatch({ admitted, batch, persistence, staging });
122
122
  } catch (error) {
123
123
  throw augmentError(error, { staging: staging.snapshot() });
124
124
  }
@@ -56,10 +56,19 @@ export default class PageService {
56
56
  * @returns {Promise<StagedPage>}
57
57
  */
58
58
  async put({ source, maxBytes }) {
59
+ return await this.#put({ source, maxBytes }, this.#persistence);
60
+ }
61
+
62
+ /** @internal Stores one page through an operation-owned persistence view. */
63
+ async putWithPersistence({ source, maxBytes }, persistence) {
64
+ return await this.#put({ source, maxBytes }, persistence);
65
+ }
66
+
67
+ async #put({ source, maxBytes }, persistence) {
59
68
  const limit = this.#effectiveLimit(maxBytes);
60
69
  const observedAt = this.#observedAt();
61
70
  const bytes = await PageService.#collect(source, limit);
62
- const oid = await this.#persistence.writeBlob(bytes);
71
+ const oid = await persistence.writeBlob(bytes);
63
72
  return recordStagedTarget(new StagedPage({
64
73
  handle: new PageHandle({ oid }),
65
74
  size: bytes.length,
@@ -18,6 +18,7 @@ export default class StagingWorkspace {
18
18
  #assets;
19
19
  #bundles;
20
20
  #clock;
21
+ #compound;
21
22
  #descriptorCodec;
22
23
  #expiresAt = null;
23
24
  #generation = null;
@@ -27,26 +28,30 @@ export default class StagingWorkspace {
27
28
  #released = false;
28
29
  #resolveHandle;
29
30
  #rootSet;
31
+ #rootSetForPersistence;
30
32
  #tail = Promise.resolve();
31
33
  #targets = new Map();
32
34
  #ttlMs;
33
35
  #workspaceRef;
34
36
 
35
- constructor({ workspaceRef, ttlMs, rootSet, refs, assets, pages, bundles, publications,
36
- resolveHandle, descriptorCodec, clock = DEFAULT_CLOCK }) {
37
+ constructor({ workspaceRef, ttlMs, rootSet, rootSetForPersistence, refs, assets, pages,
38
+ bundles, publications, resolveHandle, descriptorCodec, compound, clock = DEFAULT_CLOCK }) {
37
39
  StagingWorkspace.#assertDependencies({
38
40
  rootSet,
41
+ rootSetForPersistence,
39
42
  refs,
40
43
  assets,
41
44
  pages,
42
45
  bundles,
43
46
  resolveHandle,
44
47
  descriptorCodec,
48
+ compound,
45
49
  clock,
46
50
  });
47
51
  this.#workspaceRef = WorkspaceRef.from(workspaceRef);
48
52
  this.#ttlMs = ttlMs;
49
53
  this.#rootSet = rootSet;
54
+ this.#rootSetForPersistence = rootSetForPersistence;
50
55
  this.#refs = refs;
51
56
  this.#assets = assets;
52
57
  this.#pages = pages;
@@ -54,8 +59,13 @@ export default class StagingWorkspace {
54
59
  this.#publications = publications;
55
60
  this.#resolveHandle = resolveHandle;
56
61
  this.#descriptorCodec = descriptorCodec;
62
+ this.#compound = compound;
57
63
  this.#clock = clock;
64
+ this.#initializeCapabilities();
65
+ Object.freeze(this);
66
+ }
58
67
 
68
+ #initializeCapabilities() {
59
69
  this.assets = Object.freeze({
60
70
  put: (options) => this.#enqueue(() => this.#stage(this.#assets, 'put', options)),
61
71
  putBatch: (options) => (
@@ -76,7 +86,6 @@ export default class StagingWorkspace {
76
86
  this.#enqueue(() => this.#stageBatch(this.#bundles, 'putOrderedBatch', options))
77
87
  ),
78
88
  });
79
- Object.freeze(this);
80
89
  }
81
90
 
82
91
  get id() {
@@ -95,6 +104,18 @@ export default class StagingWorkspace {
95
104
  return this.#expiresAt;
96
105
  }
97
106
 
107
+ batch(options = {}) {
108
+ return this.#enqueue(async () => {
109
+ this.#assertActive();
110
+ return await this.#compound.admit({
111
+ ...options,
112
+ install: async (staged, persistence) => (
113
+ await this.#retainCompound(staged, persistence)
114
+ ),
115
+ });
116
+ });
117
+ }
118
+
98
119
  checkpoint({ handles }) {
99
120
  return this.#enqueue(async () => {
100
121
  this.#assertActive();
@@ -282,7 +303,31 @@ export default class StagingWorkspace {
282
303
  }));
283
304
  }
284
305
 
285
- async #install(targets) {
306
+ async #retainCompound(staged, persistence) {
307
+ const targets = new Map(this.#targets);
308
+ for (const artifact of staged) {
309
+ const target = stagedTargetOf(artifact) ?? await this.#resolveTarget(artifact.handle);
310
+ targets.set(target.handle.toString(), target);
311
+ }
312
+ try {
313
+ return await this.#install([...targets.values()], persistence);
314
+ } catch (error) {
315
+ if (error?.code === ErrorCodes.WORKSPACE_TTL_INVALID) {
316
+ throw error;
317
+ }
318
+ throw createCasError(
319
+ 'Workspace compound admission could not establish retention',
320
+ ErrorCodes.WORKSPACE_RETENTION_FAILED,
321
+ {
322
+ workspaceId: this.id,
323
+ stagedCount: staged.length,
324
+ originalError: error,
325
+ },
326
+ );
327
+ }
328
+ }
329
+
330
+ async #install(targets, persistence = null) {
286
331
  if (targets.length > MAX_WORKSPACE_TARGETS) {
287
332
  throw createCasError(
288
333
  'Workspace target count exceeds the supported maximum',
@@ -292,13 +337,10 @@ export default class StagingWorkspace {
292
337
  }
293
338
  const observedAt = this.#observedAt();
294
339
  const expiresAt = this.#expiryFrom(observedAt);
295
- const descriptor = await this.#pages.put({
296
- source: this.#descriptorCodec.encode({
297
- ref: this.#workspaceRef.toString(),
298
- createdAt: this.#workspaceRef.createdAt,
299
- expiresAt,
300
- targetCount: targets.length,
301
- }),
340
+ const descriptor = await this.#writeDescriptor({
341
+ expiresAt,
342
+ targetCount: targets.length,
343
+ persistence,
302
344
  });
303
345
  const entries = [
304
346
  {
@@ -309,7 +351,10 @@ export default class StagingWorkspace {
309
351
  },
310
352
  ...targets.map(StagingWorkspace.#targetEntry),
311
353
  ];
312
- const mutation = await this.#rootSet.replaceExact({
354
+ const rootSet = persistence === null
355
+ ? this.#rootSet
356
+ : this.#rootSetForPersistence(persistence);
357
+ const mutation = await rootSet.replaceExact({
313
358
  entries,
314
359
  expectedHeadOid: this.#generation,
315
360
  });
@@ -331,6 +376,20 @@ export default class StagingWorkspace {
331
376
  });
332
377
  }
333
378
 
379
+ async #writeDescriptor({ expiresAt, targetCount, persistence }) {
380
+ const options = {
381
+ source: this.#descriptorCodec.encode({
382
+ ref: this.#workspaceRef.toString(),
383
+ createdAt: this.#workspaceRef.createdAt,
384
+ expiresAt,
385
+ targetCount,
386
+ }),
387
+ };
388
+ return persistence === null
389
+ ? await this.#pages.put(options)
390
+ : await this.#pages.putWithPersistence(options, persistence);
391
+ }
392
+
334
393
  #witness({ target, entries, observedAt }) {
335
394
  const name = StagingWorkspace.#targetName(target.handle);
336
395
  const index = entries.findIndex((entry) => entry.name === name);
@@ -580,16 +639,18 @@ export default class StagingWorkspace {
580
639
  });
581
640
  }
582
641
 
583
- static #assertDependencies({ rootSet, refs, assets, pages, bundles, resolveHandle,
584
- descriptorCodec, clock }) {
642
+ static #assertDependencies({ rootSet, rootSetForPersistence, refs, assets, pages, bundles,
643
+ resolveHandle, descriptorCodec, compound, clock }) {
585
644
  const missing = [
586
645
  ['rootSet', StagingWorkspace.#hasMethods(rootSet, ['replaceExact'])],
646
+ ['rootSetForPersistence', typeof rootSetForPersistence === 'function'],
587
647
  ['refs', StagingWorkspace.#hasMethods(refs, ['deleteRef'])],
588
648
  ['assets', StagingWorkspace.#hasMethods(assets, ['put', 'adopt'])],
589
649
  ['pages', StagingWorkspace.#hasMethods(pages, ['put', 'putBatch'])],
590
650
  ['bundles', StagingWorkspace.#hasMethods(bundles, ['put', 'putOrdered'])],
591
651
  ['resolveHandle', typeof resolveHandle === 'function'],
592
652
  ['descriptorCodec', StagingWorkspace.#hasMethods(descriptorCodec, ['encode'])],
653
+ ['compound', StagingWorkspace.#hasMethods(compound, ['admit'])],
593
654
  ['clock', StagingWorkspace.#hasMethods(clock, ['now'])],
594
655
  ].filter(([, valid]) => !valid).map(([name]) => name);
595
656
  if (missing.length > 0) {
@@ -8,6 +8,7 @@ import RootSet from './RootSet.js';
8
8
  import RootSetMetadataCodec from './RootSetMetadataCodec.js';
9
9
  import RootSetPersistence from './RootSetPersistence.js';
10
10
  import StagingWorkspace from './StagingWorkspace.js';
11
+ import WorkspaceCompoundAdmission from './WorkspaceCompoundAdmission.js';
11
12
  import WorkspaceDescriptorCodec, {
12
13
  WORKSPACE_DESCRIPTOR_ENTRY,
13
14
  } from './WorkspaceDescriptorCodec.js';
@@ -37,6 +38,7 @@ export default class StagingWorkspaceRegistry {
37
38
  #assets;
38
39
  #bundles;
39
40
  #clock;
41
+ #compound;
40
42
  #crypto;
41
43
  #descriptorCodec;
42
44
  #pages;
@@ -68,6 +70,7 @@ export default class StagingWorkspaceRegistry {
68
70
  this.#crypto = crypto;
69
71
  this.#clock = clock;
70
72
  this.#descriptorCodec = descriptorCodec;
73
+ this.#compound = new WorkspaceCompoundAdmission({ persistence, pages, bundles });
71
74
  Object.freeze(this);
72
75
  }
73
76
 
@@ -81,6 +84,7 @@ export default class StagingWorkspaceRegistry {
81
84
  workspaceRef,
82
85
  ttlMs,
83
86
  rootSet: this.#rootSet(workspaceRef),
87
+ rootSetForPersistence: (persistence) => this.#rootSet(workspaceRef, persistence),
84
88
  refs: this.#ref,
85
89
  assets: this.#assets,
86
90
  pages: this.#pages,
@@ -88,6 +92,7 @@ export default class StagingWorkspaceRegistry {
88
92
  publications: this.#publications,
89
93
  resolveHandle: this.#resolveHandle,
90
94
  descriptorCodec: this.#descriptorCodec,
95
+ compound: this.#compound,
91
96
  clock: this.#clock,
92
97
  });
93
98
  }
@@ -271,19 +276,19 @@ export default class StagingWorkspaceRegistry {
271
276
  return logicalBytes;
272
277
  }
273
278
 
274
- #rootSet(workspaceRef) {
279
+ #rootSet(workspaceRef, persistence = this.#persistence) {
275
280
  const ref = WorkspaceRef.from(workspaceRef).toString();
276
281
  const metadataCodec = new RootSetMetadataCodec({ refType: WorkspaceRef });
277
- const persistence = new RootSetPersistence({
282
+ const rootSetPersistence = new RootSetPersistence({
278
283
  rootSetRef: ref,
279
- persistence: this.#persistence,
284
+ persistence,
280
285
  ref: this.#ref,
281
286
  refType: WorkspaceRef,
282
287
  metadataCodec,
283
288
  });
284
289
  return new RootSet({
285
290
  ref,
286
- persistence,
291
+ persistence: rootSetPersistence,
287
292
  refType: WorkspaceRef,
288
293
  metadataCodec,
289
294
  });
@@ -0,0 +1,61 @@
1
+ import createCasError from '../errors/createCasError.js';
2
+ import { ErrorCodes } from '../errors/index.js';
3
+ import WorkspaceCompoundScope from './WorkspaceCompoundScope.js';
4
+
5
+ /** Executes one bounded provisional graph build before exact workspace retention. */
6
+ export default class WorkspaceCompoundAdmission {
7
+ #bundles;
8
+ #pages;
9
+ #persistence;
10
+
11
+ constructor({ persistence, pages, bundles }) {
12
+ WorkspaceCompoundAdmission.#assertDependencies({ persistence, pages, bundles });
13
+ this.#persistence = persistence;
14
+ this.#pages = pages;
15
+ this.#bundles = bundles;
16
+ Object.freeze(this);
17
+ }
18
+
19
+ async admit({ operation, maxOperations, install } = {}) {
20
+ if (typeof install !== 'function') {
21
+ throw createCasError(
22
+ 'Workspace compound admission requires an installation callback',
23
+ ErrorCodes.INVALID_OPTIONS
24
+ );
25
+ }
26
+ return await withWriteScope(this.#persistence, async (persistence) => {
27
+ const scope = new WorkspaceCompoundScope({
28
+ pages: this.#pages,
29
+ bundles: this.#bundles,
30
+ persistence,
31
+ maxOperations,
32
+ });
33
+ const prepared = await scope.execute(operation);
34
+ const retention = await install(prepared.staged, persistence);
35
+ return Object.freeze({ value: prepared.value, retention });
36
+ });
37
+ }
38
+
39
+ static #assertDependencies({ persistence, pages, bundles }) {
40
+ const missing = [
41
+ ['persistence', persistence === null || typeof persistence !== 'object'],
42
+ ['pages.putBatch', typeof pages?.putBatch !== 'function'],
43
+ ['bundles', bundles === null || typeof bundles !== 'object'],
44
+ ]
45
+ .filter(([, absent]) => absent)
46
+ .map(([name]) => name);
47
+ if (missing.length > 0) {
48
+ throw createCasError(
49
+ 'Workspace compound admission requires complete dependencies',
50
+ ErrorCodes.INVALID_OPTIONS,
51
+ { missing }
52
+ );
53
+ }
54
+ }
55
+ }
56
+
57
+ async function withWriteScope(persistence, operation) {
58
+ return typeof persistence.withWriteScope === 'function'
59
+ ? await persistence.withWriteScope(operation)
60
+ : await operation(persistence);
61
+ }
@@ -0,0 +1,193 @@
1
+ import createCasError from '../errors/createCasError.js';
2
+ import { ErrorCodes } from '../errors/index.js';
3
+
4
+ export const DEFAULT_WORKSPACE_COMPOUND_OPERATIONS = 64;
5
+ export const MAX_WORKSPACE_COMPOUND_OPERATIONS = 1_024;
6
+
7
+ /** Bounded provisional page and bundle writes owned by one compound admission. */
8
+ export default class WorkspaceCompoundScope {
9
+ #active = true;
10
+ #abortFailure;
11
+ #aborted = false;
12
+ #bundles;
13
+ #failed = false;
14
+ #failure;
15
+ #maxOperations;
16
+ #operationCount = 0;
17
+ #overflowFailure = null;
18
+ #pages;
19
+ #persistence;
20
+ #staged = [];
21
+ #tail = Promise.resolve();
22
+
23
+ constructor({ pages, bundles, persistence, maxOperations }) {
24
+ WorkspaceCompoundScope.#assertDependencies({ pages, bundles, persistence });
25
+ this.#pages = pages;
26
+ this.#bundles = bundles;
27
+ this.#persistence = persistence;
28
+ this.#maxOperations = WorkspaceCompoundScope.#operationLimit(maxOperations);
29
+ this.api = Object.freeze({
30
+ pages: Object.freeze({
31
+ putBatch: (options) =>
32
+ this.#enqueue('pages.putBatch', async () => await this.#putPages(options)),
33
+ }),
34
+ bundles: Object.freeze({
35
+ putOrderedBatch: (options) =>
36
+ this.#enqueue('bundles.putOrderedBatch', async () => await this.#putBundles(options)),
37
+ }),
38
+ });
39
+ Object.freeze(this);
40
+ }
41
+
42
+ async execute(operation) {
43
+ if (typeof operation !== 'function') {
44
+ throw createCasError(
45
+ 'Workspace compound admission requires an operation callback',
46
+ ErrorCodes.INVALID_OPTIONS
47
+ );
48
+ }
49
+ let value;
50
+ let callbackError;
51
+ let callbackFailed = false;
52
+ try {
53
+ value = await operation(this.api);
54
+ } catch (error) {
55
+ callbackFailed = true;
56
+ callbackError = error;
57
+ this.#aborted = true;
58
+ this.#abortFailure = error;
59
+ }
60
+ this.#active = false;
61
+ await this.#tail;
62
+ if (callbackFailed && this.#failed && callbackError !== this.#failure) {
63
+ throw new AggregateError(
64
+ [callbackError, this.#failure],
65
+ 'Workspace compound callback and staged operation both failed'
66
+ );
67
+ }
68
+ if (callbackFailed) {
69
+ throw callbackError;
70
+ }
71
+ if (this.#failed) {
72
+ throw this.#failure;
73
+ }
74
+ if (this.#staged.length === 0) {
75
+ throw createCasError(
76
+ 'Workspace compound admission staged no handles',
77
+ ErrorCodes.INVALID_OPTIONS
78
+ );
79
+ }
80
+ return Object.freeze({
81
+ value,
82
+ staged: Object.freeze([...this.#staged]),
83
+ operationCount: this.#operationCount,
84
+ });
85
+ }
86
+
87
+ #enqueue(method, operation) {
88
+ if (!this.#active) {
89
+ return Promise.reject(
90
+ createCasError('Workspace compound scope is closed', ErrorCodes.WORKSPACE_STATE_INVALID, {
91
+ method,
92
+ })
93
+ );
94
+ }
95
+ if (this.#overflowFailure !== null) {
96
+ return Promise.reject(this.#overflowFailure);
97
+ }
98
+ this.#operationCount += 1;
99
+ if (this.#operationCount > this.#maxOperations) {
100
+ this.#overflowFailure = createCasError(
101
+ 'Workspace compound operation count exceeds the configured maximum',
102
+ ErrorCodes.INVALID_OPTIONS,
103
+ {
104
+ operationCount: this.#operationCount,
105
+ maxOperations: this.#maxOperations,
106
+ method,
107
+ }
108
+ );
109
+ this.#recordFailure(this.#overflowFailure);
110
+ return Promise.reject(this.#overflowFailure);
111
+ }
112
+ const result = this.#tail.then(async () => {
113
+ if (this.#failed) {
114
+ throw this.#failure;
115
+ }
116
+ if (this.#aborted) {
117
+ throw this.#abortFailure;
118
+ }
119
+ try {
120
+ return await operation();
121
+ } catch (error) {
122
+ this.#recordFailure(error);
123
+ throw error;
124
+ }
125
+ });
126
+ this.#tail = result.then(
127
+ () => undefined,
128
+ () => undefined,
129
+ );
130
+ return result;
131
+ }
132
+
133
+ #recordFailure(error) {
134
+ if (!this.#failed) {
135
+ this.#failed = true;
136
+ this.#failure = error;
137
+ }
138
+ }
139
+
140
+ async #putPages(options) {
141
+ const staged = await this.#pages.putBatchWithPersistence(options, this.#persistence);
142
+ return this.#record(staged, 'page');
143
+ }
144
+
145
+ async #putBundles(options) {
146
+ const staged = await this.#bundles.putOrderedBatchWithPersistence(options, this.#persistence);
147
+ return this.#record(staged, 'bundle');
148
+ }
149
+
150
+ #record(staged, kind) {
151
+ if (!Array.isArray(staged) || staged.some((artifact) => !artifact?.handle)) {
152
+ throw createCasError(
153
+ `Workspace compound ${kind} batch did not return staged handles`,
154
+ ErrorCodes.WORKSPACE_STATE_INVALID,
155
+ { kind }
156
+ );
157
+ }
158
+ this.#staged.push(...staged);
159
+ return Object.freeze(staged.map((artifact) => artifact.handle));
160
+ }
161
+
162
+ static #operationLimit(value) {
163
+ const limit = value ?? DEFAULT_WORKSPACE_COMPOUND_OPERATIONS;
164
+ if (!Number.isSafeInteger(limit) || limit <= 0 || limit > MAX_WORKSPACE_COMPOUND_OPERATIONS) {
165
+ throw createCasError(
166
+ 'Workspace compound operation limit is outside the supported range',
167
+ ErrorCodes.INVALID_OPTIONS,
168
+ { maxOperations: value, hardMaximum: MAX_WORKSPACE_COMPOUND_OPERATIONS }
169
+ );
170
+ }
171
+ return limit;
172
+ }
173
+
174
+ static #assertDependencies({ pages, bundles, persistence }) {
175
+ const missing = [
176
+ ['pages.putBatchWithPersistence', typeof pages?.putBatchWithPersistence !== 'function'],
177
+ [
178
+ 'bundles.putOrderedBatchWithPersistence',
179
+ typeof bundles?.putOrderedBatchWithPersistence !== 'function',
180
+ ],
181
+ ['persistence', persistence === null || typeof persistence !== 'object'],
182
+ ]
183
+ .filter(([, absent]) => absent)
184
+ .map(([name]) => name);
185
+ if (missing.length > 0) {
186
+ throw createCasError(
187
+ 'Workspace compound scope requires complete dependencies',
188
+ ErrorCodes.INVALID_OPTIONS,
189
+ { missing }
190
+ );
191
+ }
192
+ }
193
+ }
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = '6.5.8';
1
+ export const PACKAGE_VERSION = '6.5.9';