padlocal-client-ts
Version:
Padlocal ts client
41 lines • 1.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.genUUID = exports.genIdempotentId = exports.stringifyPB = exports._stringifyPB = void 0;
const google_protobuf_1 = require("google-protobuf");
const uuid_1 = require("uuid");
function _stringifyPB(obj) {
if (obj instanceof google_protobuf_1.Message) {
return _stringifyPB(obj.toObject());
}
else {
return JSON.stringify(obj, (key, value) => {
if (value instanceof google_protobuf_1.Message) {
return _stringifyPB(value);
}
if (value instanceof Uint8Array) {
return Buffer.from(value).toString("hex");
}
return value;
});
}
}
exports._stringifyPB = _stringifyPB;
function stringifyPB(obj, maxLen) {
let ret = _stringifyPB(obj);
if (maxLen !== undefined && ret.length > maxLen) {
return `${ret.substr(0, maxLen)}[TRUNCATED:${ret.length - maxLen}]`;
}
else {
return ret;
}
}
exports.stringifyPB = stringifyPB;
function genIdempotentId() {
return uuid_1.v4().replace(/-/g, "");
}
exports.genIdempotentId = genIdempotentId;
function genUUID() {
return uuid_1.v4().replace(/-/g, "");
}
exports.genUUID = genUUID;
//# sourceMappingURL=Utils.js.map
;