@@ -464,6 +464,76 @@ operations.set('rename', async ({ entities, operation }) => {
464
464
return collection . rename ( to , options ) ;
465
465
} ) ;
466
466
467
+ operations . set ( 'createDataKey' , async ( { entities, operation } ) => {
468
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
469
+ const { kmsProvider, opts } = operation . arguments ?? { } ;
470
+
471
+ return clientEncryption . createDataKey ( kmsProvider , opts ) ;
472
+ } ) ;
473
+
474
+ operations . set ( 'rewrapManyDataKey' , async ( { entities, operation } ) => {
475
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
476
+ const { filter, opts } = operation . arguments ?? { } ;
477
+
478
+ const rewrapManyDataKeyResult = await clientEncryption . rewrapManyDataKey ( filter , opts ) ;
479
+
480
+ if ( rewrapManyDataKeyResult . bulkWriteResult != null ) {
481
+ // TODO(NODE-4393): refactor BulkWriteResult to not have a 'result' property
482
+ //
483
+ // The unified spec runner match function will assert that documents have no extra
484
+ // keys. For `rewrapManyDataKey` operations, our unifed tests will fail because
485
+ // our BulkWriteResult class has an extra property - "result". We explicitly make it
486
+ // non-enumerable for the purposes of testing so that the tests can pass.
487
+ const { bulkWriteResult } = rewrapManyDataKeyResult ;
488
+ Object . defineProperty ( bulkWriteResult , 'result' , {
489
+ value : bulkWriteResult . result ,
490
+ enumerable : false
491
+ } ) ;
492
+ }
493
+ return rewrapManyDataKeyResult ;
494
+ } ) ;
495
+
496
+ operations . set ( 'deleteKey' , async ( { entities, operation } ) => {
497
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
498
+ const { id } = operation . arguments ?? { } ;
499
+
500
+ return clientEncryption . deleteKey ( id ) ;
501
+ } ) ;
502
+
503
+ operations . set ( 'getKey' , async ( { entities, operation } ) => {
504
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
505
+ const { id } = operation . arguments ?? { } ;
506
+
507
+ return clientEncryption . getKey ( id ) ;
508
+ } ) ;
509
+
510
+ operations . set ( 'getKeys' , async ( { entities, operation } ) => {
511
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
512
+
513
+ return clientEncryption . getKeys ( ) ;
514
+ } ) ;
515
+
516
+ operations . set ( 'addKeyAltName' , async ( { entities, operation } ) => {
517
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
518
+ const { id, keyAltName } = operation . arguments ?? { } ;
519
+
520
+ return clientEncryption . addKeyAltName ( id , keyAltName ) ;
521
+ } ) ;
522
+
523
+ operations . set ( 'removeKeyAltName' , async ( { entities, operation } ) => {
524
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
525
+ const { id, keyAltName } = operation . arguments ?? { } ;
526
+
527
+ return clientEncryption . removeKeyAltName ( id , keyAltName ) ;
528
+ } ) ;
529
+
530
+ operations . set ( 'getKeyByAltName' , async ( { entities, operation } ) => {
531
+ const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
532
+ const { keyAltName } = operation . arguments ?? { } ;
533
+
534
+ return clientEncryption . getKeyByAltName ( keyAltName ) ;
535
+ } ) ;
536
+
467
537
export async function executeOperationAndCheck (
468
538
operation : OperationDescription ,
469
539
entities : EntitiesMap ,
0 commit comments