mongodb-data-service
Version:
MongoDB Data Service
99 lines • 4.66 kB
TypeScript
import type { MongoClient, Document } from 'mongodb';
import type { DataService } from './data-service';
import type { CollectionInfo, CollectionInfoNameOnly } from './run-command';
import parseNamespace from 'mongodb-ns';
import type { UnboundDataServiceImplLogger } from './logger';
/**
* A list of field paths for a document.
* For example, ['a', 'b'] refers to the field b of the nested document a.
* This is used rather than dot-style `a.b` notation to disambiguate
* cases in which field names contain a literal `.` character.
*/
type FieldPath = string[];
/**
* A description of the list of encrypted fields for a given collection.
* Equality-searchable fields are handled separately since they require
* special treatments in some cases.
*/
export interface CSFLEEncryptedFieldsSet {
readonly encryptedFields: FieldPath[];
readonly equalityQueryableEncryptedFields: FieldPath[];
}
/**
* Helper for ensuring that all fields that were decrypted when
* they were read from the server are also written back as encrypted.
*/
export interface CSFLECollectionTracker {
/**
* Returns whether performing an update (or replacement) of
* `originalDocument` from the collection `ns` is allowable
* with regards to re-encrypting fields that were originally
* decrypted.
*
* The original documents **must** have been received from the
* server or generated from a HadronDocument instance that
* was created based on a document received from the server.
* This is required for ensuring that the tracker properly
* recognizes fields that were read as decrypted fields.
*
* @param ns A MongoDB `database.collection` namespace.
* @param originalDocument The original document that was received from the server.
*/
isUpdateAllowed(ns: string, originalDocument: Document): Promise<boolean>;
/**
* Returns whether a collection is known to have a schema
* description that would prevent unintentional inserts
* of unencrypted data.
*
* This includes the case in which any server schema is
* present, not just one that indicates that there are fields
* which should be encrypted.
*
* @param ns A MongoDB `database.collection` namespace.
*/
knownSchemaForCollection(ns: string): Promise<{
hasSchema: boolean;
encryptedFields: CSFLEEncryptedFieldsSet;
}>;
updateCollectionInfo(namespace: string, result: CollectionInfoNameOnly & Partial<CollectionInfo>): void;
}
declare class CSFLEEncryptedFieldsSetImpl implements CSFLEEncryptedFieldsSet {
_encryptedFields: {
path: FieldPath;
equalityQueryable: boolean;
}[];
get encryptedFields(): FieldPath[];
get equalityQueryableEncryptedFields(): FieldPath[];
addField(path: Readonly<FieldPath>, equalityQueryable: boolean): this;
withPathPrefix(prefix: string): CSFLEEncryptedFieldsSetImpl;
static isEncryptedField(set: CSFLEEncryptedFieldsSet, path: FieldPath): boolean;
static isEqualityQueryableEncryptedField(set: CSFLEEncryptedFieldsSet, path: FieldPath): boolean;
static merge(...sets: (CSFLEEncryptedFieldsSet | undefined)[]): CSFLEEncryptedFieldsSetImpl;
}
interface CSFLECollectionInfo {
serverEnforcedEncryptedFields?: CSFLEEncryptedFieldsSetImpl;
clientEnforcedEncryptedFields?: CSFLEEncryptedFieldsSetImpl;
hasServerSchema?: boolean;
lastUpdated?: Date;
}
export declare class CSFLECollectionTrackerImpl implements CSFLECollectionTracker {
private _dataService;
private _crudClient;
private _logger?;
_nsToInfo: Map<string, CSFLECollectionInfo>;
constructor(_dataService: Pick<DataService, 'on' | 'listCollections'>, _crudClient: MongoClient, _logger?: UnboundDataServiceImplLogger | undefined);
isUpdateAllowed(ns: string, originalDocument: Document): Promise<boolean>;
knownSchemaForCollection(ns: string): Promise<{
hasSchema: boolean;
encryptedFields: CSFLEEncryptedFieldsSetImpl;
}>;
_processClientSchemaDefinitions(): void;
_fetchCSFLECollectionInfo(ns: string): Promise<CSFLECollectionInfo>;
_getCSFLECollectionInfo(ns: string): CSFLECollectionInfo;
_getCSFLECollectionNames(): Iterable<ReturnType<typeof parseNamespace>>;
updateCollectionInfo(ns: string, result: CollectionInfoNameOnly & Partial<CollectionInfo>): void;
_createHookedMetadataClient(wrappedClient: MongoClient): MongoClient;
_checkListCollectionsForLibmongocryptResult(dbName: string, filter: Document, collectionInfos: CollectionInfo[]): Error | undefined;
}
export {};
//# sourceMappingURL=csfle-collection-tracker.d.ts.map