@deepkit/bson
Version:
Deepkit BSON parser
117 lines • 4.59 kB
JavaScript
/*
* 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.
*/
import { getEmbeddedProperty } from '@deepkit/type';
export const TWO_PWR_32_DBL_N = (1 << 16) * (1 << 16);
export const BSON_DATA_NUMBER = 1;
export const BSON_DATA_STRING = 2;
export const BSON_DATA_OBJECT = 3;
export const BSON_DATA_ARRAY = 4;
export const BSON_DATA_BINARY = 5;
export const BSON_DATA_UNDEFINED = 6;
export const BSON_DATA_OID = 7;
export const BSON_DATA_BOOLEAN = 8;
export const BSON_DATA_DATE = 9;
export const BSON_DATA_NULL = 10;
export const BSON_DATA_REGEXP = 11;
export const BSON_DATA_DBPOINTER = 12;
export const BSON_DATA_CODE = 13;
export const BSON_DATA_SYMBOL = 14;
export const BSON_DATA_CODE_W_SCOPE = 15;
export const BSON_DATA_INT = 16;
export const BSON_DATA_TIMESTAMP = 17;
export const BSON_DATA_LONG = 18;
export const BSON_DATA_DECIMAL128 = 19;
export const BSON_DATA_MIN_KEY = 0xff;
export const BSON_DATA_MAX_KEY = 0x7f;
export 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 || (BSONType = {}));
export const BSON_BINARY_SUBTYPE_DEFAULT = 0;
export const BSON_BINARY_SUBTYPE_FUNCTION = 1;
export const BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
export const BSON_BINARY_SUBTYPE_UUID_OLD = 3;
export const BSON_BINARY_SUBTYPE_UUID = 4;
export const BSON_BINARY_SUBTYPE_MD5 = 5;
export const BSON_BINARY_SUBTYPE_ENCRYPT = 6;
export const BSON_BINARY_SUBTYPE_COLUMN = 7;
export const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
export 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;
}
export function getEmbeddedPropertyName(serializer, namingStrategy, property, embedded) {
let embeddedPropertyName = String(namingStrategy.getPropertyName(property, serializer.name));
if (embedded.prefix !== undefined) {
embeddedPropertyName = embedded.prefix + embeddedPropertyName;
}
return embeddedPropertyName;
}
export function getEmbeddedAccessor(type, autoPrefix, accessor, serializer, namingStrategy, property, embedded, container) {
const containerProperty = 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;
}
export function isSerializable(type) {
return type.kind !== 33 /* methodSignature */ && type.kind !== 16 /* method */ && type.kind !== 17 /* function */;
}
//# sourceMappingURL=utils.js.map