@git-stunts/git-cas 6.5.0 → 6.5.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/CHANGELOG.md +10 -0
- package/GUIDE.md +6 -0
- package/README.md +3 -1
- package/UPGRADING.md +22 -0
- package/build-info.json +2 -2
- package/docs/API.md +15 -0
- package/docs/releases/v6.5.1.md +44 -0
- package/index.d.ts +4 -0
- package/index.js +18 -1
- package/package.json +2 -1
- package/src/domain/services/PageService.js +56 -2
- package/src/helpers/boundedPromiseCache.js +43 -35
- package/src/package-version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.5.1] — 2026-07-18
|
|
11
|
+
|
|
12
|
+
### Performance
|
|
13
|
+
|
|
14
|
+
- **Bounded immutable page payload reuse** - repeated `pages.get()` calls now
|
|
15
|
+
share successful in-flight and completed payload reads through an LRU bounded
|
|
16
|
+
by both entry count and aggregate bytes. Callers receive copies, failures
|
|
17
|
+
remain retryable, oversized values do not displace unrelated residents, and
|
|
18
|
+
`pages.open()` remains uncached and streaming.
|
|
19
|
+
|
|
10
20
|
## [6.5.0] — 2026-07-18
|
|
11
21
|
|
|
12
22
|
### Added
|
package/GUIDE.md
CHANGED
|
@@ -163,6 +163,12 @@ lookup reads only the descriptor path and selected payload; retention and
|
|
|
163
163
|
publication perform full bounded graph validation. Identical page bytes and
|
|
164
164
|
identically constructed bundles produce identical handles.
|
|
165
165
|
|
|
166
|
+
Repeated `pages.get()` calls reuse immutable payload reads within the store's
|
|
167
|
+
bounded page cache. The defaults retain at most 128 payloads and 8 MiB; use
|
|
168
|
+
`pageCacheEntries` and `pageCacheBytes` to tune that ceiling. Every result is a
|
|
169
|
+
caller-owned copy. `pages.open()` remains uncached and streaming, and neither
|
|
170
|
+
form of access establishes retention.
|
|
171
|
+
|
|
166
172
|
### Generic Application Publication
|
|
167
173
|
|
|
168
174
|
Publication is disabled until the facade receives an explicit application-ref
|
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.5.
|
|
47
|
+
[v6.5.1 Release Notes](./docs/releases/v6.5.1.md).
|
|
48
48
|
|
|
49
49
|
### 1. CLI Usage
|
|
50
50
|
|
|
@@ -204,6 +204,8 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
|
|
|
204
204
|
workspaces for temporary multi-object reachability, promotion, and cleanup.
|
|
205
205
|
- **[v6.5.0 Release Notes](./docs/releases/v6.5.0.md)**: Bounded direct bundle
|
|
206
206
|
references, immutable metadata reuse, and corrected concurrency settlement.
|
|
207
|
+
- **[v6.5.1 Release Notes](./docs/releases/v6.5.1.md)**: Bounded immutable page
|
|
208
|
+
payload reuse with zero-command warm reads.
|
|
207
209
|
- **[Upgrading](./UPGRADING.md)**: Migration guide for v5 → v6.
|
|
208
210
|
- **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
|
|
209
211
|
|
package/UPGRADING.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
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.0 To v6.5.1
|
|
6
|
+
|
|
7
|
+
v6.5.1 is API-additive and does not require stored-data migration. Repeated
|
|
8
|
+
`pages.get()` calls now reuse immutable payload bytes through a process-local
|
|
9
|
+
LRU bounded by entry count and aggregate bytes. Applications may tune the
|
|
10
|
+
defaults with `pageCacheEntries` and `pageCacheBytes` when constructing the
|
|
11
|
+
store.
|
|
12
|
+
|
|
13
|
+
Every caller still receives an independent `Uint8Array`, and each call's
|
|
14
|
+
`maxBytes` limit remains authoritative on cold, resident, and shared in-flight
|
|
15
|
+
reads. Rejected work remains retryable, and an individually oversized payload
|
|
16
|
+
does not displace unrelated residents.
|
|
17
|
+
|
|
18
|
+
`pages.open()` remains the streaming API and never enters the payload cache.
|
|
19
|
+
Cache residence is an optimization, not retention evidence; keep each handle
|
|
20
|
+
reachable through a workspace, RootSet, cache acquisition, publication, or
|
|
21
|
+
other documented lifetime while consuming it.
|
|
22
|
+
|
|
23
|
+
See [v6.5.1 Release Notes](./docs/releases/v6.5.1.md) and
|
|
24
|
+
[Application Storage](./docs/API.md#application-storage) for the complete
|
|
25
|
+
residency and lifetime contract.
|
|
26
|
+
|
|
5
27
|
## v6.4.0 To v6.5.0
|
|
6
28
|
|
|
7
29
|
v6.5.0 is API-additive and does not require stored-data migration. It adds
|
package/build-info.json
CHANGED
package/docs/API.md
CHANGED
|
@@ -80,6 +80,8 @@ new ContentAddressableStore(options);
|
|
|
80
80
|
- `options.maxRestoreBufferSize` (optional): Max bytes for buffered encrypted/compressed restore (default: 536870912 / 512 MiB)
|
|
81
81
|
- `options.maxBlobSize` (optional): Max bytes for metadata blob reads (default: 10485760 / 10 MiB)
|
|
82
82
|
- `options.maxPageSize` (optional): Maximum immutable page bytes (default: 16777216 / 16 MiB)
|
|
83
|
+
- `options.pageCacheEntries` (optional): Maximum immutable page payloads retained in memory (default: 128)
|
|
84
|
+
- `options.pageCacheBytes` (optional): Maximum immutable page payload bytes retained in memory (default: 8388608 / 8 MiB)
|
|
83
85
|
- `options.bundleLimits` (optional): Repository maximums for bundle members, path bytes, descriptor bytes, fanout entries, and fanout depth
|
|
84
86
|
- `options.maxBundleNestingDepth` (optional): Maximum nested bundle depth (default: 32)
|
|
85
87
|
- `options.compressionAdapter` (optional): CompressionPort implementation (default: NodeCompressionAdapter)
|
|
@@ -1025,6 +1027,19 @@ metadata before streaming it. `get()` additionally collects the page under its
|
|
|
1025
1027
|
effective byte bound. An imported handle above the configured maximum fails
|
|
1026
1028
|
with `PAGE_TOO_LARGE` without materializing the blob.
|
|
1027
1029
|
|
|
1030
|
+
Successful `get()` payloads share in-flight and completed immutable reads inside
|
|
1031
|
+
one store instance. The default LRU retains at most 128 payloads and 8 MiB of
|
|
1032
|
+
payload bytes; `pageCacheEntries` and `pageCacheBytes` may lower or raise those
|
|
1033
|
+
bounds. Every result is copied for its caller, failed reads remain retryable,
|
|
1034
|
+
and a payload larger than the byte budget is returned without remaining
|
|
1035
|
+
resident. Cold misses validate object type and size before reading. Resident or
|
|
1036
|
+
in-flight hits reuse that immutable OID validation and still enforce the current
|
|
1037
|
+
caller's `maxBytes`. In-flight work is coalesced separately from completed LRU
|
|
1038
|
+
residence, so its transient memory follows caller concurrency and the per-page
|
|
1039
|
+
size bound. `open()` remains streaming and does not enter the payload cache.
|
|
1040
|
+
This reuse is not retention evidence; callers must keep the page reachable for
|
|
1041
|
+
the duration of use.
|
|
1042
|
+
|
|
1028
1043
|
The canonical page token is:
|
|
1029
1044
|
|
|
1030
1045
|
```text
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# git-cas v6.5.1 Release Notes
|
|
2
|
+
|
|
3
|
+
v6.5.1 completes the bounded immutable read path introduced in v6.5.0 by
|
|
4
|
+
coalescing repeated `pages.get()` payload reads. Exact application reads no
|
|
5
|
+
longer start another Git blob process when the same retained page is already
|
|
6
|
+
resident in the store's bounded payload cache.
|
|
7
|
+
|
|
8
|
+
## Bounded Payload Reuse
|
|
9
|
+
|
|
10
|
+
The page cache defaults to at most 128 entries and 8 MiB of payload bytes. It
|
|
11
|
+
allocates no fixed arena. Applications can configure the limits with
|
|
12
|
+
`pageCacheEntries` and `pageCacheBytes` when constructing the store.
|
|
13
|
+
|
|
14
|
+
Every `get()` result is a caller-owned copy. Concurrent reads share in-flight
|
|
15
|
+
work, rejected reads are immediately retryable, and values larger than the byte
|
|
16
|
+
budget are returned to the current caller without remaining resident or
|
|
17
|
+
evicting unrelated entries. In-flight work is tracked separately from completed
|
|
18
|
+
LRU residence, so capacity pressure cannot break coalescing; transient memory
|
|
19
|
+
still follows caller concurrency and the configured per-page size bound.
|
|
20
|
+
|
|
21
|
+
`pages.open()` is unchanged: it remains a streaming operation and never enters
|
|
22
|
+
the payload cache. Cache residence is not a retention witness, so applications
|
|
23
|
+
must continue to keep handles reachable through the documented lifecycle APIs.
|
|
24
|
+
|
|
25
|
+
## Performance Evidence
|
|
26
|
+
|
|
27
|
+
The real-Git command-count integration contract proves that an identical warm
|
|
28
|
+
`pages.get()` performs zero additional Git commands. git-warp will publish its
|
|
29
|
+
end-to-end CPU, wall-clock, Git-command, and bounded-memory deltas after adopting
|
|
30
|
+
this release.
|
|
31
|
+
|
|
32
|
+
## Verification
|
|
33
|
+
|
|
34
|
+
The versioned candidate passed all 14 release-verifier steps with 6,676 observed
|
|
35
|
+
tests: 2,036 Node unit tests, 2,035 Bun unit tests, 2,026 Deno unit tests, and
|
|
36
|
+
193 real-Git integration tests on each runtime. Lint, examples, public type
|
|
37
|
+
compatibility, build stamping, npm packaging dry-run, and JSR publication
|
|
38
|
+
dry-run also passed.
|
|
39
|
+
|
|
40
|
+
## Compatibility
|
|
41
|
+
|
|
42
|
+
This release does not require stored-data migration. It changes no persisted
|
|
43
|
+
formats, handles, refs, witnesses, or existing method signatures. The two
|
|
44
|
+
constructor options are additive and optional.
|
package/index.d.ts
CHANGED
|
@@ -706,6 +706,10 @@ export interface ContentAddressableStoreOptions {
|
|
|
706
706
|
maxBlobSize?: number;
|
|
707
707
|
/** Maximum immutable page size in bytes. @default 16777216 (16 MiB) */
|
|
708
708
|
maxPageSize?: number;
|
|
709
|
+
/** Maximum immutable page payloads retained in memory. @default 128 */
|
|
710
|
+
pageCacheEntries?: number;
|
|
711
|
+
/** Maximum immutable page payload bytes retained in memory. @default 8388608 (8 MiB) */
|
|
712
|
+
pageCacheBytes?: number;
|
|
709
713
|
/** Repository-wide maximum bundle admission limits. */
|
|
710
714
|
bundleLimits?: Partial<BundleLimits>;
|
|
711
715
|
/** Maximum nested bundle depth. @default 32 */
|
package/index.js
CHANGED
|
@@ -133,6 +133,8 @@ export default class ContentAddressableStore {
|
|
|
133
133
|
* @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes for encrypted/compressed restores (default 512 MiB).
|
|
134
134
|
* @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes (default 10 MiB).
|
|
135
135
|
* @param {number} [options.maxPageSize=16777216] - Maximum immutable page size in bytes (default 16 MiB).
|
|
136
|
+
* @param {number} [options.pageCacheEntries=128] - Maximum immutable page payloads retained in memory.
|
|
137
|
+
* @param {number} [options.pageCacheBytes=8388608] - Maximum immutable page payload bytes retained in memory.
|
|
136
138
|
* @param {object} [options.bundleLimits] - Repository-wide maximum bundle admission limits.
|
|
137
139
|
* @param {number} [options.maxBundleNestingDepth=32] - Maximum nested bundle depth.
|
|
138
140
|
* @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter (default NodeCompressionAdapter).
|
|
@@ -153,6 +155,8 @@ export default class ContentAddressableStore {
|
|
|
153
155
|
maxRestoreBufferSize,
|
|
154
156
|
maxBlobSize,
|
|
155
157
|
maxPageSize,
|
|
158
|
+
pageCacheEntries,
|
|
159
|
+
pageCacheBytes,
|
|
156
160
|
bundleLimits,
|
|
157
161
|
maxBundleNestingDepth,
|
|
158
162
|
compressionAdapter,
|
|
@@ -173,6 +177,8 @@ export default class ContentAddressableStore {
|
|
|
173
177
|
maxRestoreBufferSize,
|
|
174
178
|
maxBlobSize,
|
|
175
179
|
maxPageSize,
|
|
180
|
+
pageCacheEntries,
|
|
181
|
+
pageCacheBytes,
|
|
176
182
|
bundleLimits,
|
|
177
183
|
maxBundleNestingDepth,
|
|
178
184
|
compressionAdapter,
|
|
@@ -231,7 +237,7 @@ export default class ContentAddressableStore {
|
|
|
231
237
|
});
|
|
232
238
|
}
|
|
233
239
|
|
|
234
|
-
/** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number, maxBlobSize?: number, maxPageSize?: number, bundleLimits?: object, maxBundleNestingDepth?: number, compressionAdapter?: *, applicationRefPrefixes?: string[], clock?: { now(): Date } }} */
|
|
240
|
+
/** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number, maxBlobSize?: number, maxPageSize?: number, pageCacheEntries?: number, pageCacheBytes?: number, bundleLimits?: object, maxBundleNestingDepth?: number, compressionAdapter?: *, applicationRefPrefixes?: string[], clock?: { now(): Date } }} */
|
|
235
241
|
#config;
|
|
236
242
|
/** @type {AssetService|null} */
|
|
237
243
|
#assetService = null;
|
|
@@ -369,6 +375,8 @@ export default class ContentAddressableStore {
|
|
|
369
375
|
this.#pageService = new PageService({
|
|
370
376
|
persistence: this.service.persistence,
|
|
371
377
|
maxPageSize: cfg.maxPageSize,
|
|
378
|
+
pageCacheEntries: cfg.pageCacheEntries,
|
|
379
|
+
pageCacheBytes: cfg.pageCacheBytes,
|
|
372
380
|
clock: cfg.clock,
|
|
373
381
|
});
|
|
374
382
|
this.#bundleService = new BundleService({
|
|
@@ -620,6 +628,9 @@ export default class ContentAddressableStore {
|
|
|
620
628
|
* @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
|
|
621
629
|
* @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
|
|
622
630
|
* @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
|
|
631
|
+
* @param {number} [options.maxPageSize=16777216] - Maximum immutable page size in bytes.
|
|
632
|
+
* @param {number} [options.pageCacheEntries=128] - Maximum immutable page payloads retained in memory.
|
|
633
|
+
* @param {number} [options.pageCacheBytes=8388608] - Maximum immutable page payload bytes retained in memory.
|
|
623
634
|
* @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
|
|
624
635
|
* @returns {Promise<ContentAddressableStore>}
|
|
625
636
|
*/
|
|
@@ -644,6 +655,9 @@ export default class ContentAddressableStore {
|
|
|
644
655
|
* @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
|
|
645
656
|
* @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
|
|
646
657
|
* @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
|
|
658
|
+
* @param {number} [options.maxPageSize=16777216] - Maximum immutable page size in bytes.
|
|
659
|
+
* @param {number} [options.pageCacheEntries=128] - Maximum immutable page payloads retained in memory.
|
|
660
|
+
* @param {number} [options.pageCacheBytes=8388608] - Maximum immutable page payload bytes retained in memory.
|
|
647
661
|
* @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
|
|
648
662
|
* @returns {ContentAddressableStore}
|
|
649
663
|
*/
|
|
@@ -665,6 +679,9 @@ export default class ContentAddressableStore {
|
|
|
665
679
|
* @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
|
|
666
680
|
* @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
|
|
667
681
|
* @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
|
|
682
|
+
* @param {number} [options.maxPageSize=16777216] - Maximum immutable page size in bytes.
|
|
683
|
+
* @param {number} [options.pageCacheEntries=128] - Maximum immutable page payloads retained in memory.
|
|
684
|
+
* @param {number} [options.pageCacheBytes=8388608] - Maximum immutable page payload bytes retained in memory.
|
|
668
685
|
* @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
|
|
669
686
|
* @returns {ContentAddressableStore}
|
|
670
687
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@git-stunts/git-cas",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.1",
|
|
4
4
|
"description": "Content-addressed storage backed by Git's object database, with optional encryption and pluggable codecs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"docs/releases/v6.3.0.md",
|
|
38
38
|
"docs/releases/v6.4.0.md",
|
|
39
39
|
"docs/releases/v6.5.0.md",
|
|
40
|
+
"docs/releases/v6.5.1.md",
|
|
40
41
|
"docs/THREAT_MODEL.md",
|
|
41
42
|
"docs/VAULT_INTERNALS.md",
|
|
42
43
|
"docs/WALKTHROUGH.md",
|
|
@@ -4,8 +4,11 @@ import { ErrorCodes } from '../errors/index.js';
|
|
|
4
4
|
import { assertHandleObjectType, mapHandleTargetError } from '../helpers/handleTarget.js';
|
|
5
5
|
import PageHandle from '../value-objects/PageHandle.js';
|
|
6
6
|
import StagedPage from '../value-objects/StagedPage.js';
|
|
7
|
+
import BoundedPromiseCache from '../../helpers/boundedPromiseCache.js';
|
|
7
8
|
|
|
8
9
|
export const DEFAULT_MAX_PAGE_SIZE = 16 * 1024 * 1024;
|
|
10
|
+
const DEFAULT_PAGE_CACHE_ENTRIES = 128;
|
|
11
|
+
const DEFAULT_PAGE_CACHE_BYTES = 8 * 1024 * 1024;
|
|
9
12
|
const DEFAULT_CLOCK = Object.freeze({ now: () => new Date() });
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -14,19 +17,34 @@ const DEFAULT_CLOCK = Object.freeze({ now: () => new Date() });
|
|
|
14
17
|
export default class PageService {
|
|
15
18
|
#clock;
|
|
16
19
|
#maxPageSize;
|
|
20
|
+
#payloads;
|
|
17
21
|
#persistence;
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* @param {object} options
|
|
21
25
|
* @param {import('../../ports/GitPersistencePort.js').default} options.persistence
|
|
22
26
|
* @param {number} [options.maxPageSize]
|
|
27
|
+
* @param {number} [options.pageCacheEntries]
|
|
28
|
+
* @param {number} [options.pageCacheBytes]
|
|
23
29
|
* @param {{ now(): Date }} [options.clock]
|
|
24
30
|
*/
|
|
25
|
-
constructor({
|
|
31
|
+
constructor({
|
|
32
|
+
persistence,
|
|
33
|
+
maxPageSize = DEFAULT_MAX_PAGE_SIZE,
|
|
34
|
+
pageCacheEntries = DEFAULT_PAGE_CACHE_ENTRIES,
|
|
35
|
+
pageCacheBytes = DEFAULT_PAGE_CACHE_BYTES,
|
|
36
|
+
clock = DEFAULT_CLOCK,
|
|
37
|
+
}) {
|
|
26
38
|
PageService.#assertDependencies(persistence, clock);
|
|
27
39
|
PageService.#assertLimit(maxPageSize, 'Configured max page size');
|
|
40
|
+
PageService.#assertPositiveLimit(pageCacheEntries, 'Page cache entries');
|
|
41
|
+
PageService.#assertLimit(pageCacheBytes, 'Page cache bytes');
|
|
28
42
|
this.#persistence = persistence;
|
|
29
43
|
this.#maxPageSize = maxPageSize;
|
|
44
|
+
this.#payloads = new BoundedPromiseCache(pageCacheEntries, {
|
|
45
|
+
maxWeight: pageCacheBytes,
|
|
46
|
+
weightOf: (value) => value.byteLength,
|
|
47
|
+
});
|
|
30
48
|
this.#clock = clock;
|
|
31
49
|
}
|
|
32
50
|
|
|
@@ -64,7 +82,24 @@ export default class PageService {
|
|
|
64
82
|
* @returns {Promise<Uint8Array>}
|
|
65
83
|
*/
|
|
66
84
|
async get({ handle, maxBytes }) {
|
|
67
|
-
|
|
85
|
+
const limit = this.#effectiveLimit(maxBytes);
|
|
86
|
+
const pageHandle = PageHandle.from(handle);
|
|
87
|
+
let payload = this.#payloads.get(pageHandle.oid);
|
|
88
|
+
if (payload === undefined) {
|
|
89
|
+
const root = await this.resolveRoot(pageHandle);
|
|
90
|
+
if (root.size > limit) {
|
|
91
|
+
throw PageService.#tooLarge(root.size, limit);
|
|
92
|
+
}
|
|
93
|
+
payload = this.#payloads.getOrCreate(
|
|
94
|
+
root.oid,
|
|
95
|
+
async () => await this.#readRoot(root),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const bytes = await payload;
|
|
99
|
+
if (bytes.byteLength > limit) {
|
|
100
|
+
throw PageService.#tooLarge(bytes.byteLength, limit);
|
|
101
|
+
}
|
|
102
|
+
return new Uint8Array(bytes);
|
|
68
103
|
}
|
|
69
104
|
|
|
70
105
|
/**
|
|
@@ -106,6 +141,17 @@ export default class PageService {
|
|
|
106
141
|
return value;
|
|
107
142
|
}
|
|
108
143
|
|
|
144
|
+
async #readRoot(root) {
|
|
145
|
+
try {
|
|
146
|
+
return await PageService.#collect(
|
|
147
|
+
await this.#persistence.readBlobStream(root.oid),
|
|
148
|
+
this.#maxPageSize,
|
|
149
|
+
);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
throw mapHandleTargetError(error, root.handle);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
109
155
|
#observedAt() {
|
|
110
156
|
const now = this.#clock.now();
|
|
111
157
|
if (!(now instanceof Date) || Number.isNaN(now.getTime())) {
|
|
@@ -163,6 +209,14 @@ export default class PageService {
|
|
|
163
209
|
}
|
|
164
210
|
}
|
|
165
211
|
|
|
212
|
+
static #assertPositiveLimit(value, label) {
|
|
213
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
214
|
+
throw createCasError(`${label} must be a positive safe integer`, ErrorCodes.INVALID_OPTIONS, {
|
|
215
|
+
value,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
166
220
|
static #assertDependencies(persistence, clock) {
|
|
167
221
|
const methods = ['writeBlob', 'readBlobStream', 'readObjectType', 'readObjectSize'];
|
|
168
222
|
if (!persistence || methods.some((method) => typeof persistence[method] !== 'function')) {
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export default class BoundedPromiseCache {
|
|
6
6
|
/** @type {Map<string, { promise: Promise<unknown>, weight: number }>} */
|
|
7
|
-
#
|
|
7
|
+
#completed = new Map();
|
|
8
|
+
/** @type {Map<string, Promise<unknown>>} */
|
|
9
|
+
#inFlight = new Map();
|
|
8
10
|
#maxEntries;
|
|
9
11
|
#maxWeight;
|
|
10
12
|
#totalWeight = 0;
|
|
@@ -34,6 +36,21 @@ export default class BoundedPromiseCache {
|
|
|
34
36
|
this.#weightOf = weightOf;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @template T
|
|
41
|
+
* @param {string} key
|
|
42
|
+
* @returns {Promise<T>|undefined}
|
|
43
|
+
*/
|
|
44
|
+
get(key) {
|
|
45
|
+
const cached = this.#completed.get(key);
|
|
46
|
+
if (cached !== undefined) {
|
|
47
|
+
this.#completed.delete(key);
|
|
48
|
+
this.#completed.set(key, cached);
|
|
49
|
+
return cached.promise;
|
|
50
|
+
}
|
|
51
|
+
return this.#inFlight.get(key);
|
|
52
|
+
}
|
|
53
|
+
|
|
37
54
|
/**
|
|
38
55
|
* @template T
|
|
39
56
|
* @param {string} key
|
|
@@ -41,45 +58,30 @@ export default class BoundedPromiseCache {
|
|
|
41
58
|
* @returns {Promise<T>}
|
|
42
59
|
*/
|
|
43
60
|
getOrCreate(key, factory) {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
this.#entries.set(key, cached);
|
|
48
|
-
return cached.promise;
|
|
61
|
+
const present = this.get(key);
|
|
62
|
+
if (present !== undefined) {
|
|
63
|
+
return present;
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
const source = Promise.resolve().then(factory);
|
|
52
|
-
const entry = { promise: source, weight: 0 };
|
|
53
67
|
const tracked = source.then(
|
|
54
68
|
(value) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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();
|
|
69
|
+
this.#removeInFlight(key, tracked);
|
|
70
|
+
const weight = this.#resolvedWeight(value);
|
|
71
|
+
if (weight <= this.#maxWeight) {
|
|
72
|
+
const entry = { promise: Promise.resolve(value), weight };
|
|
73
|
+
this.#completed.set(key, entry);
|
|
74
|
+
this.#totalWeight += weight;
|
|
75
|
+
this.#evictCompleted();
|
|
70
76
|
}
|
|
71
77
|
return value;
|
|
72
78
|
},
|
|
73
79
|
(error) => {
|
|
74
|
-
|
|
75
|
-
this.#remove(key, entry);
|
|
76
|
-
}
|
|
80
|
+
this.#removeInFlight(key, tracked);
|
|
77
81
|
throw error;
|
|
78
82
|
},
|
|
79
83
|
);
|
|
80
|
-
|
|
81
|
-
this.#entries.set(key, entry);
|
|
82
|
-
this.#evict();
|
|
84
|
+
this.#inFlight.set(key, tracked);
|
|
83
85
|
return tracked;
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -91,18 +93,24 @@ export default class BoundedPromiseCache {
|
|
|
91
93
|
return weight;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
#
|
|
95
|
-
while (this.#
|
|
96
|
-
const oldestKey = this.#
|
|
97
|
-
const oldest = this.#
|
|
98
|
-
this.#
|
|
96
|
+
#evictCompleted() {
|
|
97
|
+
while (this.#completed.size > this.#maxEntries || this.#totalWeight > this.#maxWeight) {
|
|
98
|
+
const oldestKey = this.#completed.keys().next().value;
|
|
99
|
+
const oldest = this.#completed.get(oldestKey);
|
|
100
|
+
this.#removeCompleted(oldestKey, oldest);
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
#
|
|
103
|
-
if (entry === undefined || !this.#
|
|
104
|
+
#removeCompleted(key, entry) {
|
|
105
|
+
if (entry === undefined || !this.#completed.delete(key)) {
|
|
104
106
|
return;
|
|
105
107
|
}
|
|
106
108
|
this.#totalWeight -= entry.weight;
|
|
107
109
|
}
|
|
110
|
+
|
|
111
|
+
#removeInFlight(key, promise) {
|
|
112
|
+
if (this.#inFlight.get(key) === promise) {
|
|
113
|
+
this.#inFlight.delete(key);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
108
116
|
}
|
package/src/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '6.5.
|
|
1
|
+
export const PACKAGE_VERSION = '6.5.1';
|