Skip to content

Commit a9ca0a4

Browse files
explicit encryption support
1 parent b78e3b7 commit a9ca0a4

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/client-side-encryption/client_encryption.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ export class ClientEncryption {
749749
expressionMode: boolean,
750750
options: ClientEncryptionEncryptOptions
751751
): Promise<Binary> {
752-
const { algorithm, keyId, keyAltName, contentionFactor, queryType, rangeOptions } = options;
752+
const { algorithm, keyId, keyAltName, contentionFactor, queryType, rangeOptions, textOptions } =
753+
options;
753754
const contextOptions: ExplicitEncryptionContextOptions = {
754755
expressionMode,
755756
algorithm
@@ -782,6 +783,11 @@ export class ClientEncryption {
782783
contextOptions.rangeOptions = serialize(rangeOptions);
783784
}
784785

786+
if (typeof textOptions === 'object') {
787+
// @ts-expect-error errors until mongodb-client-encryption release
788+
contextOptions.textOptions = serialize(textOptions);
789+
}
790+
785791
const valueBuffer = serialize({ v: value });
786792
const stateMachine = new StateMachine({
787793
proxyOptions: this._proxyOptions,
@@ -812,7 +818,8 @@ export interface ClientEncryptionEncryptOptions {
812818
| 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
813819
| 'Indexed'
814820
| 'Unindexed'
815-
| 'Range';
821+
| 'Range'
822+
| 'TextPreview';
816823

817824
/**
818825
* The id of the Binary dataKey to use for encryption
@@ -830,10 +837,33 @@ export interface ClientEncryptionEncryptOptions {
830837
/**
831838
* The query type.
832839
*/
833-
queryType?: 'equality' | 'range';
840+
queryType?: 'equality' | 'range' | 'prefixPreview' | 'suffixPreview' | 'substringPreview';
834841

835842
/** The index options for a Queryable Encryption field supporting "range" queries.*/
836843
rangeOptions?: RangeOptions;
844+
845+
textOptions?: TextQueryOptions;
846+
}
847+
848+
interface TextQueryOptions {
849+
caseSensitive: boolean;
850+
diacraticSensitive: boolean;
851+
852+
prefix?: {
853+
strMaxQueryLength: Int32 | number;
854+
strMinQueryLength: Int32 | number;
855+
};
856+
857+
suffix?: {
858+
strMaxQueryLength: Int32 | number;
859+
strMinQueryLength: Int32 | number;
860+
};
861+
862+
substring?: {
863+
strMaxLength: Int32 | number;
864+
strMaxQueryLength: Int32 | number;
865+
strMinQueryLength: Int32 | number;
866+
};
837867
}
838868

839869
/**

0 commit comments

Comments
 (0)