@metamask/ocap-kernel
Version:
OCap kernel core components
43 lines • 1.14 kB
JavaScript
import { getBaseMethods } from "./base.mjs";
/**
* Create a store for allocating IDs.
*
* @param ctx - The store context.
* @returns The ID store.
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getIdMethods(ctx) {
const { kv } = ctx;
const { incCounter } = getBaseMethods(kv);
/**
* Obtain an ID for a new vat.
*
* @returns The next VatID use.
*/
function getNextVatId() {
return `v${incCounter(ctx.nextVatId)}`;
}
/**
* Obtain an ID for a new remote connection.
*
* @returns The next remote ID use.
*/
function getNextRemoteId() {
return `r${incCounter(ctx.nextRemoteId)}`;
}
/**
* Initialize persistent state for a new endpoint.
*
* @param endpointId - The ID of the endpoint being added.
*/
function initEndpoint(endpointId) {
kv.set(`e.nextPromiseId.${endpointId}`, '1');
kv.set(`e.nextObjectId.${endpointId}`, '1');
}
return {
getNextVatId,
getNextRemoteId,
initEndpoint,
};
}
//# sourceMappingURL=id.mjs.map