UNPKG

hadron-document

Version:
122 lines 5.27 kB
import type { Element } from './element'; import type { Document } from './document'; import type { BSONArray, BSONObject } from './utils'; export interface ObjectGeneratorOptions { excludeInternalFields?: boolean; } export interface KeyInclusionOptions { /** * An array whose entries are used as keys that are always included * in lists for queried keys (e.g. as part of the `find` portion of * an update). * * A nested field for `{ a: { b: 42 } }` would be described by the * field path `['a', 'b']`. */ alwaysIncludeKeys?: string[][]; /** * An array whose entries are used as keys that are included in lists * for queried keys (e.g. as part of the `find` portion of * an update), even when the value of that field has originally been * an encrypted value in the sense of CSFLE/QE. * * A nested field for `{ a: { b: 42 } }` would be described by the * field path `['a', 'b']`. */ includableEncryptedKeys?: string[][]; } /** * Generates javascript objects from elements. */ export declare class ObjectGenerator { /** * Generate a javascript object from the elements. * * @param {Array} elements - The elements. * * @returns {Object} The javascript object. */ static generate(elements: Iterable<Element>, options?: ObjectGeneratorOptions): Record<string, unknown>; /** * Generate a javascript object from the elements with their original keys * and values. This can be used in a query with an update to * ensure the values on the document to edit are still up to date. * * @param {Array} elements - The elements. * * @returns {Object} The javascript object. */ static generateOriginal(elements: Iterable<Element>, options?: ObjectGeneratorOptions): Record<string, unknown>; /** * Generate an array from the elements. * * @param {Array} elements - The elements. * * @returns {Array} The array. */ static generateArray(elements: Iterable<Element>, options?: ObjectGeneratorOptions): unknown[]; /** * Generate an array from the elements using their original values. * * @param {Array} elements - The elements. * * @returns {Array} The array. */ static generateOriginalArray(elements: Iterable<Element>, options?: ObjectGeneratorOptions): unknown[]; /** * As the first step in generating query and update documents for updated * fields in a document, gather the original and new paths and values * for those updated fields. * * @param target The target document, or, when recursing, element. * @param keyInclusionOptions Specify which fields to include in the * originalFields list. * @param includeUpdatedFields Whether to include original and new values * of updated fields. If set to `false`, only fields included in * @see alwaysIncludeOriginalKeys are included. * @returns A pair `{ originalFields, newFields }`, each listing the * original and new paths and values for updated fields, respectively. */ private static recursivelyGatherFieldsAndValuesForUpdate; private static createGetFieldExpr; private static createSetFieldExpr; /** * Generate the query javascript object reflecting original * values of specific elements in this documents. This can include * elements that were updated in this document. In that case, the * values of this object are the original values, this can be used * when querying for an update to see if the original document was * changed in the background while it was being updated elsewhere. * * NOTE: `alwaysIncludeKeys` is currently used for sharding, since * updates on sharded setups need to include the shard key in their * find part. https://jira.mongodb.org/browse/SPM-1632 will make * this requirement go away for future MongoDB versions! * * @param target The target (sub-)document. * @param keyInclusionOptions Specify which fields to include in the * originalFields list. * @param includeUpdatedFields Whether to include the original values for * updated fields. * * @returns A pair of lists, one containing the original values for updated fields * or those specified in the always-include list, and one containing new values * of the updated fields. If includeUpdatedFields is not set, the second * list will be empty. */ static getQueryForOriginalKeysAndValuesForSpecifiedFields(target: Document | Element, keyInclusionOptions: Readonly<KeyInclusionOptions>, includeUpdatedFields: boolean): BSONObject; /** * Generate an update document or pipeline which reflects the updates * that have taken place for this document. A pipeline will be returned * if the updates require changes to fields containing dots or prefixed * with $. * * @param target The target (sub-)document. */ static generateUpdateDoc(target: Document | Element): { $set?: BSONObject; $unset?: BSONObject; } | BSONArray; } export default ObjectGenerator; //# sourceMappingURL=object-generator.d.ts.map