UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

36 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.structHashSchema = void 0; const insertion_1 = require("@jsonjoy.com/util/lib/sort/insertion"); const schema_1 = require("../json-crdt-patch/schema"); const hash_1 = require("./hash"); const structHash_1 = require("./structHash"); const structHashSchema = (node) => { if (node instanceof schema_1.nodes.con || node instanceof schema_1.nodes.str || node instanceof schema_1.nodes.bin) return (0, structHash_1.structHash)(node.raw); else if (node instanceof schema_1.nodes.val) return (0, exports.structHashSchema)(node.value); else if (node instanceof schema_1.nodes.obj) { let res = '{'; const fields = { ...node.obj, ...node.opt }; const keys = Object.keys(fields); (0, insertion_1.sort)(keys); const length = keys.length; for (let i = 0; i < length; i++) { const key = keys[i]; const value = fields[key]; res += (0, hash_1.hash)(key).toString(36) + ':' + (0, exports.structHashSchema)(value) + ','; } return res + '}'; } else if (node instanceof schema_1.nodes.arr || node instanceof schema_1.nodes.vec) { let res = '['; const children = node instanceof schema_1.nodes.arr ? node.arr : node.value; for (const child of children) res += (0, exports.structHashSchema)(child) + ';'; return res + ']'; } return (0, structHash_1.structHash)(node); }; exports.structHashSchema = structHashSchema; //# sourceMappingURL=structHashSchema.js.map