hadron-document
Version:
Hadron Document
45 lines • 2.32 kB
TypeScript
import { Binary } from 'bson';
import type { TypeCastMap, TypeCastTypes } from 'hadron-type-checker';
import type { Element } from './element';
export declare function fieldStringLen(value: unknown): number;
export type BSONObject = TypeCastMap['Object'];
export type BSONArray = TypeCastMap['Array'];
export type BSONValue = TypeCastMap[TypeCastTypes];
export interface HadronEJSONOptions {
indent?: number | string;
}
/**
* Turn a BSON value into what we consider idiomatic extended JSON.
*
* This differs from both the relaxed and strict mode of the 'bson'
* package's EJSON class: We preserve the type information for longs
* via $numberLong, but redact it for $numberInt and $numberDouble.
*
* This may seem inconsistent, but considering that the latter two
* types are exactly representable in JS and $numberLong is not,
* in addition to the fact that this has been historic behavior
* in Compass for a long time, this seems like a reasonable choice.
*
* Also turns $date.$numberLong into a date so that it will be
* displayed as an iso date string since this is what Compass did
* historically. Unless it is outside of the safe range.
*
* @param value Any BSON value.
* @returns A serialized, human-readable and human-editable string.
*/
export declare function objectToIdiomaticEJSON(value: any, options?: HadronEJSONOptions): string;
/**
* Returns a default value for the BSON type passed in.
*/
export declare function getDefaultValueForType(type: keyof TypeCastMap): string | boolean | Date | Record<string, unknown> | unknown[] | Binary | import("bson").Code | import("bson").Decimal128 | import("bson").Double | import("bson").Int32 | import("bson").Long | import("bson").MaxKey | import("bson").MinKey | import("bson").ObjectId | import("bson").BSONRegExp | import("bson").BSONSymbol | import("bson").Timestamp | null | undefined;
/**
* Gets the display type for an element, considering legacy UUID encoding
* preference.
*
* - For Binary subtype 3 (legacy UUID), returns the appropriate legacy UUID
* type based on context.
* - For Binary subtype 4 (UUID), returns 'UUID'.
* - For all other types, returns the element's currentType.
*/
export declare function getDisplayType(el: Element, legacyUUIDEncoding?: string): Element['type'];
//# sourceMappingURL=utils.d.ts.map