UNPKG

@metamask/ocap-kernel

Version:
1 lines 2.91 kB
{"version":3,"file":"revocation.cjs","sourceRoot":"","sources":["../../../src/store/methods/revocation.ts"],"names":[],"mappings":";;;AAEA,wCAA2C;AAC3C,6DAAuD;AAEvD;;;;;GAKG;AACH,4EAA4E;AACrE,MAAM,oBAAoB,GAAG,CAAC,GAAiB,EAAE,EAAE;IACxD,MAAM,EAAE,aAAa,EAAE,GAAG,IAAA,wBAAc,EAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEjD;;;;;OAKG;IACH,SAAS,UAAU,CAAC,IAAU,EAAE,OAAgB;QAC9C,IAAI,OAAO,EAAE,CAAC;YACZ,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,SAAS,MAAM,CAAC,IAAU;QACxB,IAAI,IAAA,6BAAY,EAAC,IAAI,CAAC,EAAE,CAAC;YACvB,uCAAuC;YACvC,MAAM,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;QACD,gCAAgC;QAChC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACH,SAAS,SAAS,CAAC,IAAU;QAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,OAAO;QACL,UAAU;QACV,MAAM;QACN,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AAhDW,QAAA,oBAAoB,wBAgD/B","sourcesContent":["import type { KRef } from '../../types.ts';\nimport type { StoreContext } from '../types.ts';\nimport { getBaseMethods } from './base.ts';\nimport { isPromiseRef } from '../utils/promise-ref.ts';\n\n/**\n * Get the methods that provide functionality for managing object revocation.\n *\n * @param ctx - The store context.\n * @returns The revocation methods.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport const getRevocationMethods = (ctx: StoreContext) => {\n const { getRevokedKey } = getBaseMethods(ctx.kv);\n\n /**\n * Set the revoked flag for a kernel object.\n *\n * @param koId - The KRef of the kernel object to set the revoked flag for.\n * @param revoked - The value of the revoked flag.\n */\n function setRevoked(koId: KRef, revoked: boolean): void {\n if (revoked) {\n ctx.kv.set(getRevokedKey(koId), 'true');\n } else {\n ctx.kv.delete(getRevokedKey(koId));\n }\n }\n\n /**\n * Revoke a kernel object. Idempotent. Revoking promises is not supported.\n *\n * @param koId - The KRef of the kernel object to revoke.\n * @throws If the object is a promise or the koId is unknown.\n */\n function revoke(koId: KRef): void {\n if (isPromiseRef(koId)) {\n // Revoking a promise is not supported.\n throw Error(`cannot revoke promise ${koId}`);\n }\n // Set the revoked flag to true.\n setRevoked(koId, true);\n }\n\n /**\n * Check if a kernel object has been revoked.\n *\n * @param koId - The KRef of the kernel object of interest.\n * @returns True if the object is revoked, false otherwise.\n * @throws If the object is unknown and `throwIfUnknown` is true.\n */\n function isRevoked(koId: KRef): boolean {\n return Boolean(ctx.kv.get(getRevokedKey(koId)));\n }\n\n return {\n setRevoked,\n revoke,\n isRevoked,\n };\n};\n"]}