@deno/kv
Version:
A Deno KV client library optimized for Node.js.
84 lines (83 loc) • 3.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeBinary = exports.encodeBinary = exports.decodeJson = exports.encodeJson = exports.createValue = exports.getDefaultValue = void 0;
// @ts-nocheck
const KvEntry_js_1 = require("./KvEntry.js");
const scalar_js_1 = require("../../../../../runtime/json/scalar.js");
const index_js_1 = require("../../../../../runtime/wire/index.js");
const serialize_js_1 = __importDefault(require("../../../../../runtime/wire/serialize.js"));
const scalar_js_2 = require("../../../../../runtime/wire/scalar.js");
const deserialize_js_1 = __importDefault(require("../../../../../runtime/wire/deserialize.js"));
function getDefaultValue() {
return {
changed: false,
entryIfChanged: undefined,
};
}
exports.getDefaultValue = getDefaultValue;
function createValue(partialValue) {
return {
...getDefaultValue(),
...partialValue,
};
}
exports.createValue = createValue;
function encodeJson(value) {
const result = {};
if (value.changed !== undefined)
result.changed = scalar_js_1.tsValueToJsonValueFns.bool(value.changed);
if (value.entryIfChanged !== undefined)
result.entryIfChanged = (0, KvEntry_js_1.encodeJson)(value.entryIfChanged);
return result;
}
exports.encodeJson = encodeJson;
function decodeJson(value) {
const result = getDefaultValue();
if (value.changed !== undefined)
result.changed = scalar_js_1.jsonValueToTsValueFns.bool(value.changed);
if (value.entryIfChanged !== undefined)
result.entryIfChanged = (0, KvEntry_js_1.decodeJson)(value.entryIfChanged);
return result;
}
exports.decodeJson = decodeJson;
function encodeBinary(value) {
const result = [];
if (value.changed !== undefined) {
const tsValue = value.changed;
result.push([1, scalar_js_2.tsValueToWireValueFns.bool(tsValue)]);
}
if (value.entryIfChanged !== undefined) {
const tsValue = value.entryIfChanged;
result.push([2, { type: index_js_1.WireType.LengthDelimited, value: (0, KvEntry_js_1.encodeBinary)(tsValue) }]);
}
return (0, serialize_js_1.default)(result);
}
exports.encodeBinary = encodeBinary;
function decodeBinary(binary) {
const result = getDefaultValue();
const wireMessage = (0, deserialize_js_1.default)(binary);
const wireFields = new Map(wireMessage);
field: {
const wireValue = wireFields.get(1);
if (wireValue === undefined)
break field;
const value = scalar_js_2.wireValueToTsValueFns.bool(wireValue);
if (value === undefined)
break field;
result.changed = value;
}
field: {
const wireValue = wireFields.get(2);
if (wireValue === undefined)
break field;
const value = wireValue.type === index_js_1.WireType.LengthDelimited ? (0, KvEntry_js_1.decodeBinary)(wireValue.value) : undefined;
if (value === undefined)
break field;
result.entryIfChanged = value;
}
return result;
}
exports.decodeBinary = decodeBinary;