UNPKG

@metamask/ocap-kernel

Version:
1 lines 1.99 kB
{"version":3,"file":"id.cjs","sourceRoot":"","sources":["../../../src/store/methods/id.ts"],"names":[],"mappings":";;AAWA,oCAqCC;AAhDD,wCAA2C;AAI3C;;;;;GAKG;AACH,4EAA4E;AAC5E,SAAgB,YAAY,CAAC,GAAiB;IAC5C,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC;IACnB,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,wBAAc,EAAC,EAAE,CAAC,CAAC;IAE1C;;;;OAIG;IACH,SAAS,YAAY;QACnB,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,SAAS,eAAe;QACtB,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,SAAS,YAAY,CAAC,UAAsB;QAC1C,EAAE,CAAC,GAAG,CAAC,mBAAmB,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;QAC7C,EAAE,CAAC,GAAG,CAAC,kBAAkB,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO;QACL,YAAY;QACZ,eAAe;QACf,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import { getBaseMethods } from './base.ts';\nimport type { VatId, RemoteId, EndpointId } from '../../types.ts';\nimport type { StoreContext } from '../types.ts';\n\n/**\n * Create a store for allocating IDs.\n *\n * @param ctx - The store context.\n * @returns The ID store.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function getIdMethods(ctx: StoreContext) {\n const { kv } = ctx;\n const { incCounter } = getBaseMethods(kv);\n\n /**\n * Obtain an ID for a new vat.\n *\n * @returns The next VatID use.\n */\n function getNextVatId(): VatId {\n return `v${incCounter(ctx.nextVatId)}`;\n }\n\n /**\n * Obtain an ID for a new remote connection.\n *\n * @returns The next remote ID use.\n */\n function getNextRemoteId(): RemoteId {\n return `r${incCounter(ctx.nextRemoteId)}`;\n }\n\n /**\n * Initialize persistent state for a new endpoint.\n *\n * @param endpointId - The ID of the endpoint being added.\n */\n function initEndpoint(endpointId: EndpointId): void {\n kv.set(`e.nextPromiseId.${endpointId}`, '1');\n kv.set(`e.nextObjectId.${endpointId}`, '1');\n }\n\n return {\n getNextVatId,\n getNextRemoteId,\n initEndpoint,\n };\n}\n"]}