Skip to content

Commit 6b95301

Browse files
chore: type definition improvements for driver internal usage (#675)
1 parent 593ff24 commit 6b95301

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [6.0.0-alpha.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.9.0...node-v6.0.0-alpha.1) (2023-07-27)
6+
57
## [6.0.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.9.0...node-v6.0.0-alpha.0) (2023-07-13)
68

79
## [2.9.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.8.0...node-v2.9.0) (2023-07-12)

package-lock.json

Lines changed: 2 additions & 2 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
@@ -1,9 +1,9 @@
11
{
22
"name": "mongodb-client-encryption",
3-
"version": "6.0.0-alpha.0",
3+
"version": "6.0.0-alpha.1",
44
"description": "Official client encryption module for the MongoDB Node.js driver",
55
"main": "lib/index.js",
6-
"types": "index.d.ts",
6+
"types": "lib/index.d.ts",
77
"files": [
88
"README.md",
99
"CHANGELOG.md",

src/index.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import bindings = require('bindings');
22

33
const mc = bindings('mongocrypt');
44

5-
interface MongoCryptKMSRequest {
5+
export interface MongoCryptKMSRequest {
66
addResponse(response: Buffer): void;
77
readonly status: MongoCryptStatus;
88
readonly bytesNeeded: number;
@@ -11,18 +11,18 @@ interface MongoCryptKMSRequest {
1111
readonly message: Buffer;
1212
}
1313

14-
interface MongoCryptStatus {
14+
export interface MongoCryptStatus {
1515
type: number;
1616
code: number;
1717
message?: string;
1818
}
1919

20-
interface MongoCryptContext {
20+
export interface MongoCryptContext {
2121
nextMongoOperation(): Buffer;
22-
addMongoOperationResponse(response: Buffer): void;
22+
addMongoOperationResponse(response: Uint8Array): void;
2323
finishMongoOperation(): void;
2424
nextKMSRequest(): MongoCryptKMSRequest | null;
25-
provideKMSProviders(providers: Buffer): void;
25+
provideKMSProviders(providers: Uint8Array): void;
2626
finishKMSRequests(): void;
2727
finalize(): Buffer;
2828

@@ -31,19 +31,28 @@ interface MongoCryptContext {
3131
}
3232

3333
export interface MongoCryptConstructor {
34-
new (): MongoCrypt;
34+
new (options: {
35+
kmsProviders?: Buffer;
36+
schemaMap?: Buffer;
37+
encryptedFieldsMap?: Buffer;
38+
logger?: unknown;
39+
cryptoCallbacks?: Record<string, unknown>;
40+
cryptSharedLibSearchPaths?: string[];
41+
cryptSharedLibPath?: string;
42+
bypassQueryAnalysis?: boolean;
43+
}): MongoCrypt;
3544
libmongocryptVersion: string;
3645
}
3746

3847
export interface MongoCrypt {
39-
makeEncryptionContext(ns: string, command: Buffer): MongoCryptContext;
48+
makeEncryptionContext(ns: string, command: Uint8Array): MongoCryptContext;
4049
makeExplicitEncryptionContext(
41-
value: Buffer,
50+
value: Uint8Array,
4251
options?: {
43-
keyId?: Buffer;
44-
keyAltName?: Buffer;
52+
keyId?: Uint8Array;
53+
keyAltName?: Uint8Array;
4554
algorithm?: string;
46-
rangeOptions?: Buffer;
55+
rangeOptions?: Uint8Array;
4756
contentionFactor?: bigint | number;
4857
queryType?: string;
4958

@@ -56,21 +65,33 @@ export interface MongoCrypt {
5665
expressionMode: boolean;
5766
}
5867
): MongoCryptContext;
59-
makeDecryptionContext(buffer: Buffer): MongoCryptContext;
60-
makeExplicitDecryptionContext(buffer: Buffer): MongoCryptContext;
68+
makeDecryptionContext(buffer: Uint8Array): MongoCryptContext;
69+
makeExplicitDecryptionContext(buffer: Uint8Array): MongoCryptContext;
6170
makeDataKeyContext(
62-
optionsBuffer: Buffer,
71+
optionsBuffer: Uint8Array,
6372
options: {
64-
keyAltNames: Buffer[];
65-
keyMaterial: Buffer;
73+
keyAltNames?: Uint8Array[];
74+
keyMaterial?: Uint8Array;
6675
}
67-
): void;
68-
makeRewrapManyDataKeyContext(filter: Buffer, encryptionKey: Buffer): void;
76+
): MongoCryptContext;
77+
makeRewrapManyDataKeyContext(filter: Uint8Array, encryptionKey?: Uint8Array): MongoCryptContext;
6978
readonly status: MongoCryptStatus;
7079
readonly cryptSharedLibVersionInfo: {
7180
version: bigint;
7281
versionStr: string;
7382
} | null;
7483
}
7584

85+
export type ExplicitEncryptionContextOptions = NonNullable<
86+
Parameters<MongoCrypt['makeExplicitEncryptionContext']>[1]
87+
>;
88+
export type DataKeyContextOptions = NonNullable<Parameters<MongoCrypt['makeDataKeyContext']>[1]>;
89+
export type MongoCryptOptions = NonNullable<ConstructorParameters<MongoCryptConstructor>[0]>;
90+
7691
export const MongoCrypt: MongoCryptConstructor = mc.MongoCrypt;
92+
93+
/** exported for testing only. */
94+
interface MongoCryptContextCtor {
95+
new (): MongoCryptContext;
96+
}
97+
export const MongoCryptContextCtor: MongoCryptContextCtor = mc.MongoCryptContextCtor;

0 commit comments

Comments
 (0)