UNPKG

@deepkit/bson

Version:
124 lines 5.78 kB
"use strict"; /* * Deepkit Framework * Copyright (C) 2021 Deepkit UG, Marc J. Schmidt * * This program is free software: you can redistribute it and/or modify * it under the terms of the MIT License. * * You should have received a copy of the MIT License along with this program. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isSerializable = exports.getEmbeddedAccessor = exports.getEmbeddedPropertyName = exports.digitByteSize = exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_COLUMN = exports.BSON_BINARY_SUBTYPE_ENCRYPT = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_UUID_OLD = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSONType = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_LONG = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_INT = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_CODE = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_REGEXP = exports.BSON_DATA_NULL = exports.BSON_DATA_DATE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_OID = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_DATA_OBJECT = exports.BSON_DATA_STRING = exports.BSON_DATA_NUMBER = exports.TWO_PWR_32_DBL_N = void 0; const type_1 = require("@deepkit/type"); exports.TWO_PWR_32_DBL_N = (1 << 16) * (1 << 16); exports.BSON_DATA_NUMBER = 1; exports.BSON_DATA_STRING = 2; exports.BSON_DATA_OBJECT = 3; exports.BSON_DATA_ARRAY = 4; exports.BSON_DATA_BINARY = 5; exports.BSON_DATA_UNDEFINED = 6; exports.BSON_DATA_OID = 7; exports.BSON_DATA_BOOLEAN = 8; exports.BSON_DATA_DATE = 9; exports.BSON_DATA_NULL = 10; exports.BSON_DATA_REGEXP = 11; exports.BSON_DATA_DBPOINTER = 12; exports.BSON_DATA_CODE = 13; exports.BSON_DATA_SYMBOL = 14; exports.BSON_DATA_CODE_W_SCOPE = 15; exports.BSON_DATA_INT = 16; exports.BSON_DATA_TIMESTAMP = 17; exports.BSON_DATA_LONG = 18; exports.BSON_DATA_DECIMAL128 = 19; exports.BSON_DATA_MIN_KEY = 0xff; exports.BSON_DATA_MAX_KEY = 0x7f; var BSONType; (function (BSONType) { BSONType[BSONType["NUMBER"] = 1] = "NUMBER"; BSONType[BSONType["STRING"] = 2] = "STRING"; BSONType[BSONType["OBJECT"] = 3] = "OBJECT"; BSONType[BSONType["ARRAY"] = 4] = "ARRAY"; BSONType[BSONType["BINARY"] = 5] = "BINARY"; BSONType[BSONType["UNDEFINED"] = 6] = "UNDEFINED"; BSONType[BSONType["OID"] = 7] = "OID"; BSONType[BSONType["BOOLEAN"] = 8] = "BOOLEAN"; BSONType[BSONType["DATE"] = 9] = "DATE"; BSONType[BSONType["NULL"] = 10] = "NULL"; BSONType[BSONType["REGEXP"] = 11] = "REGEXP"; BSONType[BSONType["DBPOINTER"] = 12] = "DBPOINTER"; BSONType[BSONType["CODE"] = 13] = "CODE"; BSONType[BSONType["SYMBOL"] = 14] = "SYMBOL"; BSONType[BSONType["CODE_W_SCOPE"] = 15] = "CODE_W_SCOPE"; BSONType[BSONType["INT"] = 16] = "INT"; BSONType[BSONType["TIMESTAMP"] = 17] = "TIMESTAMP"; BSONType[BSONType["LONG"] = 18] = "LONG"; BSONType[BSONType["DECIMAL128"] = 19] = "DECIMAL128"; BSONType[BSONType["MIN_KEY"] = 255] = "MIN_KEY"; BSONType[BSONType["MAX_KEY"] = 127] = "MAX_KEY"; })(BSONType = exports.BSONType || (exports.BSONType = {})); exports.BSON_BINARY_SUBTYPE_DEFAULT = 0; exports.BSON_BINARY_SUBTYPE_FUNCTION = 1; exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; exports.BSON_BINARY_SUBTYPE_UUID_OLD = 3; exports.BSON_BINARY_SUBTYPE_UUID = 4; exports.BSON_BINARY_SUBTYPE_MD5 = 5; exports.BSON_BINARY_SUBTYPE_ENCRYPT = 6; exports.BSON_BINARY_SUBTYPE_COLUMN = 7; exports.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; function digitByteSize(v) { if (v < 10) return 2; if (v < 100) return 3; if (v < 1000) return 4; if (v < 10000) return 5; if (v < 100000) return 6; if (v < 1000000) return 7; if (v < 10000000) return 8; if (v < 100000000) return 9; if (v < 1000000000) return 10; return 11; } exports.digitByteSize = digitByteSize; function getEmbeddedPropertyName(serializer, namingStrategy, property, embedded) { let embeddedPropertyName = String(namingStrategy.getPropertyName(property, serializer.name)); if (embedded.prefix !== undefined) { embeddedPropertyName = embedded.prefix + embeddedPropertyName; } return embeddedPropertyName; } exports.getEmbeddedPropertyName = getEmbeddedPropertyName; function getEmbeddedAccessor(type, autoPrefix, accessor, serializer, namingStrategy, property, embedded, container) { const containerProperty = (0, type_1.getEmbeddedProperty)(type); let embeddedPropertyName = String(namingStrategy.getPropertyName(property, serializer.name)); if (embedded.prefix !== undefined) { embeddedPropertyName = embedded.prefix + embeddedPropertyName; } else if (containerProperty) { embeddedPropertyName = String(containerProperty.name) + '_' + embeddedPropertyName; } if ((autoPrefix || embedded.prefix !== undefined)) { //if autoPrefix or a prefix is set the embeddedPropertyName is emitted in a container, either manually provided or from accessor. if (containerProperty) return embeddedPropertyName; if (container) return embeddedPropertyName; } if (containerProperty) return String(containerProperty.name); return accessor; } exports.getEmbeddedAccessor = getEmbeddedAccessor; function isSerializable(type) { return type.kind !== 33 /* methodSignature */ && type.kind !== 16 /* method */ && type.kind !== 17 /* function */; } exports.isSerializable = isSerializable; //# sourceMappingURL=utils.js.map