@git-stunts/git-cas 6.5.6 → 6.5.8

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/GUIDE.md +29 -0
  3. package/README.md +16 -10
  4. package/UPGRADING.md +48 -0
  5. package/build-info.json +2 -2
  6. package/docs/API.md +66 -12
  7. package/docs/releases/v6.5.7.md +56 -0
  8. package/docs/releases/v6.5.8.md +89 -0
  9. package/index.d.ts +50 -0
  10. package/index.js +15 -1
  11. package/package.json +4 -2
  12. package/src/domain/services/AssetService.js +201 -10
  13. package/src/domain/services/BoundedWriteWavePersistence.js +235 -0
  14. package/src/domain/services/BundleBatchPlanner.js +349 -0
  15. package/src/domain/services/BundleService.js +225 -2
  16. package/src/domain/services/CasService.d.ts +16 -0
  17. package/src/domain/services/CasService.js +9 -18
  18. package/src/domain/services/ManifestRepository.js +129 -50
  19. package/src/domain/services/ManifestTreeService.js +47 -0
  20. package/src/domain/services/PageService.js +26 -9
  21. package/src/domain/services/RootSet.js +32 -0
  22. package/src/domain/services/RootSetPersistence.js +58 -1
  23. package/src/domain/services/StagedTarget.js +19 -0
  24. package/src/domain/services/StagingWorkspace.js +21 -7
  25. package/src/domain/services/forkCasPersistence.js +20 -0
  26. package/src/infrastructure/adapters/GitObjectSessionPool.js +47 -5
  27. package/src/infrastructure/adapters/GitPersistenceAdapter.js +217 -16
  28. package/src/infrastructure/adapters/GitPersistenceWriteScope.js +154 -0
  29. package/src/infrastructure/adapters/GitRefAdapter.js +38 -3
  30. package/src/infrastructure/adapters/GitUpdateRefSessionPool.js +115 -0
  31. package/src/package-version.js +1 -1
  32. package/src/ports/GitPersistencePort.js +43 -0
  33. package/src/ports/GitRefPort.js +8 -0
@@ -0,0 +1,115 @@
1
+ import createCasError from '../../domain/errors/createCasError.js';
2
+ import { ErrorCodes } from '../../domain/errors/index.js';
3
+
4
+ const EXECUTE_DIRECTLY = (operation) => operation();
5
+
6
+ /**
7
+ * Lazily owns one reusable typed update-ref process.
8
+ *
9
+ * A failed ref transaction is never replayed. Plumbing's typed session poisons
10
+ * and terminates itself on protocol or Git failure; this owner only discards
11
+ * the failed instance so a later, separately authorized mutation can open a
12
+ * fresh process.
13
+ */
14
+ export default class GitUpdateRefSessionPool {
15
+ #active = new Set();
16
+ #closed = false;
17
+ #closePromise = null;
18
+ #opening = null;
19
+ #plumbing;
20
+
21
+ constructor({ plumbing }) {
22
+ this.#plumbing = plumbing;
23
+ }
24
+
25
+ supports() {
26
+ return typeof this.#plumbing?.openUpdateRefSession === 'function';
27
+ }
28
+
29
+ async update(options, execute = EXECUTE_DIRECTLY) {
30
+ this.#assertOpen();
31
+ const operation = (async () => {
32
+ let session;
33
+ try {
34
+ session = await this.#session();
35
+ return await execute(() => session.update(options));
36
+ } catch (error) {
37
+ if (session !== undefined) {
38
+ await this.#discard(session);
39
+ }
40
+ throw error;
41
+ }
42
+ })();
43
+ this.#active.add(operation);
44
+ try {
45
+ return await operation;
46
+ } finally {
47
+ this.#active.delete(operation);
48
+ }
49
+ }
50
+
51
+ async close() {
52
+ if (this.#closePromise !== null) {
53
+ return await this.#closePromise;
54
+ }
55
+ this.#closed = true;
56
+ this.#closePromise = (async () => {
57
+ await Promise.allSettled([...this.#active]);
58
+ const opening = this.#opening;
59
+ this.#opening = null;
60
+ if (opening !== null) {
61
+ const session = await opening.catch(() => null);
62
+ if (session !== null) {
63
+ await session.close();
64
+ }
65
+ }
66
+ })();
67
+ return await this.#closePromise;
68
+ }
69
+
70
+ async #discard(expectedSession) {
71
+ const opening = this.#opening;
72
+ if (opening === null) {
73
+ return;
74
+ }
75
+ const session = await opening.catch(() => undefined);
76
+ if (session === expectedSession && this.#opening === opening) {
77
+ this.#opening = null;
78
+ await releaseDiscardedSession(session);
79
+ }
80
+ }
81
+
82
+ async #session() {
83
+ this.#assertOpen();
84
+ if (this.#opening === null) {
85
+ const opening = Promise.resolve().then(() => this.#plumbing.openUpdateRefSession());
86
+ this.#opening = opening;
87
+ opening.catch(() => {
88
+ if (this.#opening === opening) {
89
+ this.#opening = null;
90
+ }
91
+ });
92
+ }
93
+ return await this.#opening;
94
+ }
95
+
96
+ #assertOpen() {
97
+ if (this.#closed) {
98
+ throw createCasError('Git ref session pool is closed', ErrorCodes.RESOURCE_CLOSED);
99
+ }
100
+ }
101
+ }
102
+
103
+ async function releaseDiscardedSession(session) {
104
+ try {
105
+ if (typeof session.terminate === 'function') {
106
+ await session.terminate();
107
+ } else if (typeof session.abort === 'function') {
108
+ await session.abort();
109
+ } else if (typeof session.close === 'function') {
110
+ await session.close();
111
+ }
112
+ } catch {
113
+ // Preserve the mutation failure that caused this best-effort teardown.
114
+ }
115
+ }
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = '6.5.6';
1
+ export const PACKAGE_VERSION = '6.5.8';
@@ -35,6 +35,20 @@ export default class GitPersistencePort {
35
35
  throw new Error('Not implemented');
36
36
  }
37
37
 
38
+ /**
39
+ * Creates a bounded group of independent Git tree objects in input order.
40
+ * Adapters may override this to pipeline one typed protocol request.
41
+ * @param {Iterable<string[]>} trees
42
+ * @returns {Promise<string[]>} Git OIDs in input order.
43
+ */
44
+ async writeTrees(trees) {
45
+ const oids = [];
46
+ for (const entries of trees) {
47
+ oids.push(await this.writeTree(entries));
48
+ }
49
+ return oids;
50
+ }
51
+
38
52
  /**
39
53
  * Reads a Git blob by its OID.
40
54
  * @param {string} _oid - Git object ID.
@@ -102,6 +116,35 @@ export default class GitPersistencePort {
102
116
  throw new Error('Not implemented');
103
117
  }
104
118
 
119
+ /**
120
+ * Reads metadata for a bounded group of Git objects in input order.
121
+ * @param {Iterable<string>} oids - Git object IDs.
122
+ * @returns {Promise<Array<{oid: string, type: string, size: number}>>}
123
+ */
124
+ async readObjectInfos(oids) {
125
+ const infos = [];
126
+ for (const oid of oids) {
127
+ infos.push({
128
+ oid,
129
+ type: await this.readObjectType(oid),
130
+ size: await this.readObjectSize(oid),
131
+ });
132
+ }
133
+ return infos;
134
+ }
135
+
136
+ /**
137
+ * Runs one bounded operation against an operation-owned write scope.
138
+ * Adapters may override this to retain protocol processes until the callback
139
+ * settles. The default preserves compatibility for custom persistence ports.
140
+ * @template T
141
+ * @param {(persistence: GitPersistencePort) => Promise<T>} operation
142
+ * @returns {Promise<T>}
143
+ */
144
+ async withWriteScope(operation) {
145
+ return await operation(this);
146
+ }
147
+
105
148
  /**
106
149
  * Releases adapter-owned local resources. The default implementation is a
107
150
  * no-op so persistence adapters without long-lived resources remain valid.
@@ -99,6 +99,14 @@ export default class GitRefPort {
99
99
  iterateRefs(_options) {
100
100
  throw unsupportedAcquisitionCapability('iterateRefs');
101
101
  }
102
+
103
+ /** Releases adapter-owned local resources. */
104
+ async close() {}
105
+
106
+ /** @returns {Promise<void>} */
107
+ async [Symbol.asyncDispose]() {
108
+ await this.close();
109
+ }
102
110
  }
103
111
 
104
112
  function unsupportedAcquisitionCapability(capability) {