Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function decodeValue_(decoded, type) {
if (is.null(decoded)) {
return null;
}
switch (type.code) {
case 'BYTES':
decoded = Buffer.from(decoded, 'base64');
break;
case 'FLOAT64':
decoded = new codec.Float(decoded);
break;
case 'INT64':
decoded = new codec.Int(decoded);
break;
case 'TIMESTAMP': // falls through
case 'DATE':
decoded = new Date(decoded);
break;
static merge(type, head, tail) {
const code = type.code;
head = RowBuilder.getValue(head);
tail = RowBuilder.getValue(tail);
const isMergeable = !is.null(head) && !is.null(tail) && code !== 'FLOAT64';
const merged: Array<{}> = [];
let mergedItems;
if (code === 'ARRAY') {
const arrayType = type.arrayElementType;
mergedItems = RowBuilder.merge(arrayType, head.pop(), tail.shift());
merged.push(head.concat(mergedItems).concat(tail));
} else if (code === 'STRUCT') {
const structType = type.structType.fields[head.length - 1].type;
mergedItems = RowBuilder.merge(structType, head.pop(), tail.shift());
merged.push(head.concat(mergedItems).concat(tail));
} else if (isMergeable) {
merged.push(head + tail);
} else {
merged.push(head, tail);
}
// Filter out empty strings.
export function encodeValue(value?: any): ValueProto {
const valueProto: ValueProto = {};
if (is.boolean(value)) {
valueProto.booleanValue = value;
return valueProto;
}
if (is.null(value)) {
valueProto.nullValue = 0;
return valueProto;
}
if (typeof value === 'number') {
if (value % 1 === 0) {
value = new entity.Int(value);
} else {
value = new entity.Double(value);
}
}
if (isDsInt(value)) {
valueProto.integerValue = (value as Int).value;
return valueProto;
}
function attrsToString(attrs) {
var output = '', value;
for (var key in attrs) {
value = attrs[key];
if (is.undefined(value) || is.null(value)) {
continue;
}
if (is.string(value) && !value) {
output += ' ' + key;
} else {
output += ' ' + key + '=' + JSON.stringify(value);
}
}
return output;
}
};
});
return {
type: 'struct',
fields,
};
}
if (is.array(field)) {
let child;
for (let i = 0; i < field.length; i++) {
child = field[i];
if (!is.null(child)) {
break;
}
}
return {
type: 'array',
child: getType(child),
};
}
return 'unspecified';
}
encodeValue_(value: {}) {
let convertedValue;
if (is.null(value)) {
convertedValue = {
nullValue: 0,
};
} else if (is.number(value)) {
convertedValue = {
numberValue: value,
};
} else if (is.string(value)) {
convertedValue = {
stringValue: value,
};
} else if (is.boolean(value)) {
convertedValue = {
boolValue: value,
};
} else if (Buffer.isBuffer(value)) {