{"version":3,"file":"revocation.mjs","sourceRoot":"","sources":["../../../src/store/methods/revocation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAkB;AAC3C,OAAO,EAAE,YAAY,EAAE,iCAAgC;AAEvD;;;;;GAKG;AACH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAiB,EAAE,EAAE;IACxD,MAAM,EAAE,aAAa,EAAE,GAAG,cAAc,CAAC,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,YAAY,CAAC,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","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"]}