cache.js 816 B

1234567891011121314151617181920212223242526272829303132
  1. import { entityKind } from "../../entity.js";
  2. class Cache {
  3. static [entityKind] = "Cache";
  4. }
  5. class NoopCache extends Cache {
  6. strategy() {
  7. return "all";
  8. }
  9. static [entityKind] = "NoopCache";
  10. async get(_key) {
  11. return void 0;
  12. }
  13. async put(_hashedQuery, _response, _tables, _config) {
  14. }
  15. async onMutate(_params) {
  16. }
  17. }
  18. async function hashQuery(sql, params) {
  19. const dataToHash = `${sql}-${JSON.stringify(params)}`;
  20. const encoder = new TextEncoder();
  21. const data = encoder.encode(dataToHash);
  22. const hashBuffer = await crypto.subtle.digest("SHA-256", data);
  23. const hashArray = [...new Uint8Array(hashBuffer)];
  24. const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
  25. return hashHex;
  26. }
  27. export {
  28. Cache,
  29. NoopCache,
  30. hashQuery
  31. };
  32. //# sourceMappingURL=cache.js.map