UNPKG

@ultipa-graph/ultipa-driver

Version:

NodeJS SDK for ultipa-server 5.2

178 lines 6.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NullUtils = void 0; const types_1 = require("../../types/types"); const ultipa_pb_1 = require("../../proto/ultipa_pb"); const commont_1 = require("./commont"); var NullUtils; (function (NullUtils) { function uint8ArrayEqual(buf1, buf2) { if (buf1.byteLength != buf2.byteLength) return false; var dv1 = new Int8Array(buf1); var dv2 = new Int8Array(buf2); for (var i = 0; i != buf1.byteLength; i++) { if (dv1[i] != dv2[i]) return false; } return true; } NullUtils.uint8ArrayEqual = uint8ArrayEqual; let getListNullValue = () => { let d = new ultipa_pb_1.ListData(); d.setIsNull(true); return d.serializeBinary(); }; let getMapNullValue = () => { let d = new ultipa_pb_1.MapData(); d.setIsNull(true); return d.serializeBinary(); }; let getSetNullValue = () => { let d = new ultipa_pb_1.SetData(); d.setIsNull(true); return d.serializeBinary(); }; NullUtils.AllNullValueUint8Array = { int32: new Uint8Array([ 0x7f, 0xff, 0xff, 0xff ]), datetime: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), uint32: new Uint8Array([ 0xff, 0xff, 0xff, 0xff ]), int64: new Uint8Array([ 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), timestamp: new Uint8Array([ 0xff, 0xff, 0xff, 0xff ]), uint64: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), float: new Uint8Array([ 0xff, 0xff, 0xff, 0xff ]), double: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), decimal: new Uint8Array([0]), string: new Uint8Array([0]), bool: new Uint8Array([2]), blob: new Uint8Array([0]), point: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), text: new Uint8Array([0]), list: getListNullValue(), map: getMapNullValue(), set: getSetNullValue(), local_datetime: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), zoned_datetime: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), date: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, ]), local_time: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), zoned_time: new Uint8Array([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]), year_to_month: new Uint8Array([ 0x7f, 0xff, 0xff, 0xff, ]), day_to_second: new Uint8Array([ 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]) }; NullUtils.nullValue = (type) => { const { INT32, BOOL, STRING, FLOAT, DOUBLE, UINT32, INT64, UINT64, DATETIME, TIMESTAMP, TEXT, BLOB, POINT, DECIMAL, LIST, SET, MAP, LOCAL_DATETIME, ZONED_DATETIME, YEAR_TO_MONTH, DAY_TO_SECOND, DATE, LOCAL_TIME, ZONED_TIME } = types_1.UltipaPropertyType; switch (type) { case STRING: return NullUtils.AllNullValueUint8Array.string; case DECIMAL: return NullUtils.AllNullValueUint8Array.decimal; case POINT: return NullUtils.AllNullValueUint8Array.point; case TEXT: return NullUtils.AllNullValueUint8Array.text; case INT32: return NullUtils.AllNullValueUint8Array.int32; case BOOL: return NullUtils.AllNullValueUint8Array.bool; case FLOAT: return NullUtils.AllNullValueUint8Array.float; case DOUBLE: return NullUtils.AllNullValueUint8Array.double; case TIMESTAMP: return NullUtils.AllNullValueUint8Array.timestamp; case UINT32: return NullUtils.AllNullValueUint8Array.uint32; case INT64: return NullUtils.AllNullValueUint8Array.int64; case DATETIME: return NullUtils.AllNullValueUint8Array.datetime; case UINT64: return NullUtils.AllNullValueUint8Array.uint64; case BLOB: return NullUtils.AllNullValueUint8Array.blob; case LOCAL_DATETIME: return NullUtils.AllNullValueUint8Array.local_datetime; case DATE: return NullUtils.AllNullValueUint8Array.date; case DAY_TO_SECOND: return NullUtils.AllNullValueUint8Array.day_to_second; case LOCAL_TIME: return NullUtils.AllNullValueUint8Array.local_time; case YEAR_TO_MONTH: return NullUtils.AllNullValueUint8Array.year_to_month; case ZONED_DATETIME: return NullUtils.AllNullValueUint8Array.zoned_datetime; case ZONED_TIME: return NullUtils.AllNullValueUint8Array.zoned_time; case LIST: if (commont_1.TypeSupport.list) { return NullUtils.AllNullValueUint8Array.list; } break; case MAP: if (commont_1.TypeSupport.map) { return NullUtils.AllNullValueUint8Array.map; } break; case SET: if (commont_1.TypeSupport.set) { return NullUtils.AllNullValueUint8Array.set; } } commont_1.TypeSupport.NotSupport(type); }; NullUtils.isNullValueByBytes = (v, type) => { if (type === types_1.UltipaPropertyType.NULL) { return true; } let nullV = NullUtils.nullValue(type); return uint8ArrayEqual(v, nullV); }; })(NullUtils = exports.NullUtils || (exports.NullUtils = {})); //# sourceMappingURL=null.js.map