@dataql/node
Version:
DataQL core SDK for unified data management with MongoDB and GraphQL - Production Multi-Cloud Ready
21 lines (20 loc) • 739 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashSchema = hashSchema;
// Utility to hash a schema object using SHA-256
async function hashSchema(schema) {
const str = JSON.stringify(schema);
if (typeof window !== "undefined" && window.crypto?.subtle) {
// Browser
const buf = new TextEncoder().encode(str);
const hashBuf = await window.crypto.subtle.digest("SHA-256", buf);
return Array.from(new Uint8Array(hashBuf))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}
else {
// Node.js
const { createHash } = await import("crypto");
return createHash("sha256").update(str).digest("hex");
}
}