Skip to content

Commit e4492f3

Browse files
feat(NODE-7059, NODE-7008): add support for text queries for QE string fields (#4597)
1 parent fae8ac8 commit e4492f3

27 files changed

+3678
-25
lines changed

global.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ declare global {
2020
idmsMockServer?: true;
2121
nodejs?: string;
2222
predicate?: (test?: Mocha.Test) => true | string;
23-
crypt_shared?: 'enabled' | 'disabled'
23+
crypt_shared?: 'enabled' | 'disabled',
24+
libmongocrypt?: string;
2425
};
2526

2627
sessions?: {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"js-yaml": "^4.1.0",
9797
"mocha": "^11.7.1",
9898
"mocha-sinon": "^2.1.2",
99-
"mongodb-client-encryption": "^6.4.0",
99+
"mongodb-client-encryption": "^6.5.0",
100100
"mongodb-legacy": "^6.1.3",
101101
"nyc": "^15.1.0",
102102
"prettier": "^3.5.3",
@@ -175,4 +175,4 @@
175175
"moduleResolution": "node"
176176
}
177177
}
178-
}
178+
}

src/client-side-encryption/client_encryption.ts

Lines changed: 52 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,10 @@ export class ClientEncryption {
782783
contextOptions.rangeOptions = serialize(rangeOptions);
783784
}
784785

786+
if (typeof textOptions === 'object') {
787+
contextOptions.textOptions = serialize(textOptions);
788+
}
789+
785790
const valueBuffer = serialize({ v: value });
786791
const stateMachine = new StateMachine({
787792
proxyOptions: this._proxyOptions,
@@ -812,7 +817,8 @@ export interface ClientEncryptionEncryptOptions {
812817
| 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
813818
| 'Indexed'
814819
| 'Unindexed'
815-
| 'Range';
820+
| 'Range'
821+
| 'TextPreview';
816822

817823
/**
818824
* The id of the Binary dataKey to use for encryption
@@ -830,10 +836,53 @@ export interface ClientEncryptionEncryptOptions {
830836
/**
831837
* The query type.
832838
*/
833-
queryType?: 'equality' | 'range';
839+
queryType?: 'equality' | 'range' | 'prefixPreview' | 'suffixPreview' | 'substringPreview';
834840

835841
/** The index options for a Queryable Encryption field supporting "range" queries.*/
836842
rangeOptions?: RangeOptions;
843+
844+
/**
845+
* Options for a Queryable Encryption field supporting text queries. Only valid when `algorithm` is `TextPreview`.
846+
*
847+
* @experimental Public Technical Preview: `textPreview` is an experimental feature and may break at any time.
848+
*/
849+
textOptions?: TextQueryOptions;
850+
}
851+
852+
/**
853+
* Options for a Queryable Encryption field supporting text queries.
854+
*
855+
* @public
856+
* @experimental Public Technical Preview: `textPreview` is an experimental feature and may break at any time.
857+
*/
858+
export interface TextQueryOptions {
859+
/** Indicates that text indexes for this field are case sensitive */
860+
caseSensitive: boolean;
861+
/** Indicates that text indexes for this field are diacritic sensitive. */
862+
diacriticSensitive: boolean;
863+
864+
prefix?: {
865+
/** The maximum allowed query length. */
866+
strMaxQueryLength: Int32 | number;
867+
/** The minimum allowed query length. */
868+
strMinQueryLength: Int32 | number;
869+
};
870+
871+
suffix?: {
872+
/** The maximum allowed query length. */
873+
strMaxQueryLength: Int32 | number;
874+
/** The minimum allowed query length. */
875+
strMinQueryLength: Int32 | number;
876+
};
877+
878+
substring?: {
879+
/** The maximum allowed length to insert. */
880+
strMaxLength: Int32 | number;
881+
/** The maximum allowed query length. */
882+
strMaxQueryLength: Int32 | number;
883+
/** The minimum allowed query length. */
884+
strMinQueryLength: Int32 | number;
885+
};
837886
}
838887

839888
/**

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ export type {
242242
DataKey,
243243
GCPEncryptionKeyOptions,
244244
KMIPEncryptionKeyOptions,
245-
RangeOptions
245+
RangeOptions,
246+
TextQueryOptions
246247
} from './client-side-encryption/client_encryption';
247248
export {
248249
MongoCryptAzureKMSRequestError,

0 commit comments

Comments
 (0)