( lease: StorageRootLease<K, 'write'>, compositionId: string, )
| 33 | } |
| 34 | |
| 35 | export 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 | |
| 68 | export async function readStateRootCompositionBinding( |
| 69 | root: string, |
no test coverage detected