UNPKG

@metamask/ocap-kernel

Version:
46 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getIdMethods = getIdMethods; const base_ts_1 = require("./base.cjs"); /** * 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 function getIdMethods(ctx) { const { kv } = ctx; const { incCounter } = (0, base_ts_1.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.cjs.map