@envelop/response-cache
Version:
- Skip the execution phase and reduce server load by caching execution results in-memory. - Customize cache entry time to live based on fields and types within the execution result. - Automatically invalidate the cache based on mutation selection sets. -
13 lines (12 loc) • 532 B
JavaScript
import { crypto, TextEncoder } from '@whatwg-node/fetch';
export const hashSHA256 = async (text) => {
const inputUint8Array = new TextEncoder().encode(text);
const arrayBuf = await crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array);
const outputUint8Array = new Uint8Array(arrayBuf);
let hash = '';
for (let i = 0, l = outputUint8Array.length; i < l; i++) {
const hex = outputUint8Array[i].toString(16);
hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
}
return hash;
};