@@ -23,10 +23,14 @@ import {
2323 CaptureInterval ,
2424 ConfigureDatabaseUserRequest ,
2525 ConfigureDatabaseUserResponse ,
26+ CreateIndexRequest ,
27+ CreateIndexResponse ,
2628 DataRequest ,
2729 DeleteBinaryDataByFilterRequest ,
2830 DeleteBinaryDataByFilterResponse ,
2931 DeleteBinaryDataByIDsResponse ,
32+ DeleteIndexRequest ,
33+ DeleteIndexResponse ,
3034 DeleteTabularDataResponse ,
3135 ExportTabularDataRequest ,
3236 ExportTabularDataResponse ,
@@ -35,6 +39,11 @@ import {
3539 GetDatabaseConnectionResponse ,
3640 GetLatestTabularDataRequest ,
3741 GetLatestTabularDataResponse ,
42+ Index ,
43+ IndexableCollection ,
44+ IndexCreator ,
45+ ListIndexesRequest ,
46+ ListIndexesResponse ,
3847 RemoveBinaryDataFromDatasetByIDsRequest ,
3948 RemoveBinaryDataFromDatasetByIDsResponse ,
4049 RemoveBoundingBoxFromImageByIDRequest ,
@@ -46,6 +55,7 @@ import {
4655 TabularData ,
4756 TabularDataByFilterRequest ,
4857 TabularDataByFilterResponse ,
58+ TabularDataByMQLRequest ,
4959 TabularDataByMQLResponse ,
5060 TabularDataBySQLResponse ,
5161 TabularDataSourceType ,
@@ -325,6 +335,36 @@ describe('DataClient tests', () => {
325335 expect ( result [ 0 ] ?. key1 ) . toBeInstanceOf ( Date ) ;
326336 expect ( promise ) . toEqual ( data ) ;
327337 } ) ;
338+
339+ it ( 'get tabular data from MQL with queryPrefixName' , async ( ) => {
340+ const expectedRequest = new TabularDataByMQLRequest ( {
341+ organizationId : 'some_org_id' ,
342+ mqlBinary : [ BSON . serialize ( { query : 'some_mql_query' } ) ] ,
343+ queryPrefixName : 'my_prefix' ,
344+ } ) ;
345+ let capReq : TabularDataByMQLRequest | undefined = undefined ;
346+ mockTransport = createRouterTransport ( ( { service } ) => {
347+ service ( DataService , {
348+ tabularDataByMQL : ( req ) => {
349+ capReq = req ;
350+ return new TabularDataByMQLResponse ( {
351+ rawData : data . map ( ( x ) => BSON . serialize ( x ) ) ,
352+ } ) ;
353+ } ,
354+ } ) ;
355+ } ) ;
356+ const promise = await subject ( ) . tabularDataByMQL (
357+ 'some_org_id' ,
358+ [ { query : 'some_mql_query' } ] ,
359+ false ,
360+ undefined ,
361+ 'my_prefix'
362+ ) ;
363+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
364+ const result = promise as typeof data ;
365+ expect ( result [ 0 ] ?. key1 ) . toBeInstanceOf ( Date ) ;
366+ expect ( promise ) . toEqual ( data ) ;
367+ } ) ;
328368 } ) ;
329369
330370 describe ( 'tabularDataByFilter tests' , ( ) => {
@@ -1040,6 +1080,155 @@ describe('DataClient tests', () => {
10401080 } ) ;
10411081 } ) ;
10421082
1083+ describe ( 'createIndex tests' , ( ) => {
1084+ let capReq : CreateIndexRequest ;
1085+ beforeEach ( ( ) => {
1086+ mockTransport = createRouterTransport ( ( { service } ) => {
1087+ service ( DataService , {
1088+ createIndex : ( req ) => {
1089+ capReq = req ;
1090+ return new CreateIndexResponse ( ) ;
1091+ } ,
1092+ } ) ;
1093+ } ) ;
1094+ } ) ;
1095+ it ( 'creates an index' , async ( ) => {
1096+ const organizationId = 'orgId' ;
1097+ const collectionType = IndexableCollection . PIPELINE_SINK ;
1098+ const indexSpec = { keys : { field : 1 } , options : { priority : 1 } } ;
1099+ const pipelineName = 'pipeline1' ;
1100+ await subject ( ) . createIndex (
1101+ organizationId ,
1102+ collectionType ,
1103+ indexSpec ,
1104+ pipelineName
1105+ ) ;
1106+ expect ( capReq . organizationId ) . toBe ( organizationId ) ;
1107+ expect ( capReq . collectionType ) . toBe ( collectionType ) ;
1108+ expect (
1109+ capReq . indexSpec . map ( ( spec ) => BSON . deserialize ( spec ) ) [ 0 ]
1110+ ) . toStrictEqual ( indexSpec ) ;
1111+ expect ( capReq . pipelineName ) . toBe ( pipelineName ) ;
1112+ } ) ;
1113+ it ( 'creates an index without pipeline name' , async ( ) => {
1114+ const organizationId = 'orgId' ;
1115+ const collectionType = IndexableCollection . HOT_STORE ;
1116+ const indexSpec = { keys : { field : 2 } , options : { priority : 2 } } ;
1117+ await subject ( ) . createIndex ( organizationId , collectionType , indexSpec ) ;
1118+ expect ( capReq . organizationId ) . toBe ( organizationId ) ;
1119+ expect ( capReq . collectionType ) . toBe ( collectionType ) ;
1120+ expect (
1121+ capReq . indexSpec . map ( ( spec ) => BSON . deserialize ( spec ) ) [ 0 ]
1122+ ) . toStrictEqual ( indexSpec ) ;
1123+ } ) ;
1124+ } ) ;
1125+ describe ( 'listIndexes tests' , ( ) => {
1126+ let capReq : ListIndexesRequest ;
1127+ const index1 = new Index ( {
1128+ collectionType : IndexableCollection . HOT_STORE ,
1129+ indexName : 'index1' ,
1130+ indexSpec : [ new TextEncoder ( ) . encode ( JSON . stringify ( { field : 1 } ) ) ] ,
1131+ createdBy : IndexCreator . CUSTOMER ,
1132+ } ) ;
1133+ const index2 = new Index ( {
1134+ collectionType : IndexableCollection . PIPELINE_SINK ,
1135+ pipelineName : 'pipeline1' ,
1136+ indexName : 'index2' ,
1137+ indexSpec : [
1138+ new TextEncoder ( ) . encode ( JSON . stringify ( { another_field : - 1 } ) ) ,
1139+ ] ,
1140+ createdBy : IndexCreator . VIAM ,
1141+ } ) ;
1142+ const indexes = [ index1 , index2 ] ;
1143+ beforeEach ( ( ) => {
1144+ mockTransport = createRouterTransport ( ( { service } ) => {
1145+ service ( DataService , {
1146+ listIndexes : ( req ) => {
1147+ capReq = req ;
1148+ return new ListIndexesResponse ( {
1149+ indexes,
1150+ } ) ;
1151+ } ,
1152+ } ) ;
1153+ } ) ;
1154+ } ) ;
1155+ it ( 'lists indexes' , async ( ) => {
1156+ const organizationId = 'orgId' ;
1157+ const collectionType = IndexableCollection . HOT_STORE ;
1158+ const pipelineName = 'pipeline1' ;
1159+ const expectedRequest = new ListIndexesRequest ( {
1160+ organizationId,
1161+ collectionType,
1162+ pipelineName,
1163+ } ) ;
1164+ const result = await subject ( ) . listIndexes (
1165+ organizationId ,
1166+ collectionType ,
1167+ pipelineName
1168+ ) ;
1169+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1170+ expect ( result ) . toEqual ( indexes ) ;
1171+ } ) ;
1172+ it ( 'lists indexes without pipeline name' , async ( ) => {
1173+ const organizationId = 'orgId' ;
1174+ const collectionType = IndexableCollection . HOT_STORE ;
1175+ const expectedRequest = new ListIndexesRequest ( {
1176+ organizationId,
1177+ collectionType,
1178+ } ) ;
1179+ const result = await subject ( ) . listIndexes (
1180+ organizationId ,
1181+ collectionType
1182+ ) ;
1183+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1184+ expect ( result ) . toEqual ( indexes ) ;
1185+ } ) ;
1186+ } ) ;
1187+ describe ( 'deleteIndex tests' , ( ) => {
1188+ let capReq : DeleteIndexRequest ;
1189+ beforeEach ( ( ) => {
1190+ mockTransport = createRouterTransport ( ( { service } ) => {
1191+ service ( DataService , {
1192+ deleteIndex : ( req ) => {
1193+ capReq = req ;
1194+ return new DeleteIndexResponse ( ) ;
1195+ } ,
1196+ } ) ;
1197+ } ) ;
1198+ } ) ;
1199+ it ( 'deletes an index' , async ( ) => {
1200+ const organizationId = 'orgId' ;
1201+ const collectionType = IndexableCollection . HOT_STORE ;
1202+ const indexName = 'my_index' ;
1203+ const pipelineName = 'pipeline1' ;
1204+ const expectedRequest = new DeleteIndexRequest ( {
1205+ organizationId,
1206+ collectionType,
1207+ indexName,
1208+ pipelineName,
1209+ } ) ;
1210+ await subject ( ) . deleteIndex (
1211+ organizationId ,
1212+ collectionType ,
1213+ indexName ,
1214+ pipelineName
1215+ ) ;
1216+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1217+ } ) ;
1218+ it ( 'deletes an index without pipeline name' , async ( ) => {
1219+ const organizationId = 'orgId' ;
1220+ const collectionType = IndexableCollection . HOT_STORE ;
1221+ const indexName = 'my_index' ;
1222+ const expectedRequest = new DeleteIndexRequest ( {
1223+ organizationId,
1224+ collectionType,
1225+ indexName,
1226+ } ) ;
1227+ await subject ( ) . deleteIndex ( organizationId , collectionType , indexName ) ;
1228+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1229+ } ) ;
1230+ } ) ;
1231+
10431232 describe ( 'createFilter tests' , ( ) => {
10441233 it ( 'create empty filter' , ( ) => {
10451234 const testFilter = DataClient . createFilter ( { } ) ;
0 commit comments