hadron-document
Version:
Hadron Document
33 lines • 1.85 kB
TypeScript
import type { TypeCastMap, TypeCastTypes } from 'hadron-type-checker';
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[] | import("bson").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;
//# sourceMappingURL=utils.d.ts.map