MCPcopy Create free account
hub / github.com/apache/maka / bindStateRootComposition

Function bindStateRootComposition

packages/storage/src/state-root-composition.ts:35–66  ·  view source on GitHub ↗
(
  lease: StorageRootLease<K, 'write'>,
  compositionId: string,
)

Source from the content-addressed store, hash-verified

33}
34
35export async function bindStateRootComposition<K extends StorageRootKind>(
36 lease: StorageRootLease<K, 'write'>,
37 compositionId: string,
38): Promise<void> {
39 requireCompositionId(compositionId);
40 const assertCurrentRoot = createStorageRootLeaseIdentityGuard(lease, lease.kind, 'write');
41 await runWithStorageRootLease(lease, lease.kind, 'write', async (root) => {
42 const existing = await readStateRootCompositionIfPresent(root);
43 if (existing) {
44 assertMatchingComposition(existing, compositionId);
45 return;
46 }
47 const record: StateRootCompositionRecord = {
48 schemaVersion: STATE_ROOT_COMPOSITION_SCHEMA_VERSION,
49 compositionId,
50 };
51 const publication = await withCompositionIoFailure(() =>
52 publishMarkerFile({
53 root,
54 markerFile: STATE_ROOT_COMPOSITION_FILE,
55 contents: `${JSON.stringify(record)}\n`,
56 maxBytes: MAX_STATE_ROOT_COMPOSITION_BYTES,
57 publication: 'create',
58 beforePublish: assertCurrentRoot,
59 invalidFile,
60 }),
61 );
62 if (publication === 'published') return;
63 const winner = await readStateRootComposition(root);
64 assertMatchingComposition(winner, compositionId);
65 });
66}
67
68export async function readStateRootCompositionBinding(
69 root: string,

Callers 3

#startMethod · 0.90

Calls 8

requireCompositionIdFunction · 0.85
runWithStorageRootLeaseFunction · 0.85
withCompositionIoFailureFunction · 0.85
publishMarkerFileFunction · 0.85
readStateRootCompositionFunction · 0.85

Tested by

no test coverage detected