11import tap from 'tap' ;
22
3- import * as schemaTypes from '../src/proto/schema_pb' ;
43import ImmudbClient from '../src/client' ;
54
65import { Config } from '../src/interfaces' ;
7- import { USER_PERMISSION } from '../types/user' ;
6+ import { USER_PERMISSION , USER_ACTION } from '../types/user' ;
7+ import Parameters from '../types/parameters' ;
88
99const {
1010 IMMUDB_HOST = '127.0.0.1' ,
@@ -34,7 +34,7 @@ tap.test('database management', async t => {
3434 }
3535
3636 // test: create database
37- const secondRequestData : schemaTypes . Database . AsObject = { databasename : 'db1' } ;
37+ const secondRequestData : Parameters . CreateDatabase = { databasename : 'db1' } ;
3838 try {
3939 await immudbClient . createDatabase ( secondRequestData ) ;
4040 t . pass ( 'Successfully created database' ) ;
@@ -43,7 +43,7 @@ tap.test('database management', async t => {
4343 }
4444
4545 // test: use database just created
46- const thirdRequestData : schemaTypes . Database . AsObject = { databasename : 'db1' } ;
46+ const thirdRequestData : Parameters . UseDatabase = { databasename : 'db1' } ;
4747 const secondResponse = await immudbClient . useDatabase ( thirdRequestData ) ;
4848 // if (secondResponse) {
4949 // t.type(secondResponse.token, 'string')
@@ -64,9 +64,7 @@ tap.test('database management', async t => {
6464 }
6565
6666 // test: list all databases available
67- const fifthResponse :
68- | schemaTypes . DatabaseListResponse . AsObject
69- | undefined = await immudbClient . listDatabases ( ) ;
67+ const fifthResponse = await immudbClient . listDatabases ( ) ;
7068 if ( fifthResponse ) {
7169 t . equal ( fifthResponse . databasesList [ 0 ] . databasename , 'defaultdb' ) ;
7270 t . equal ( fifthResponse . databasesList [ 1 ] . databasename , 'db1' ) ;
@@ -102,7 +100,7 @@ tap.test('user management', async t => {
102100 const rand = `${ Math . floor ( Math . random ( ) * Math . floor ( 100000 ) ) } ` ;
103101
104102 // test: login using the specified username and password
105- const loginRequest = {
103+ const loginRequest : Parameters . Login = {
106104 user : IMMUDB_USER ,
107105 password : IMMUDB_PWD ,
108106 } ;
@@ -128,8 +126,8 @@ tap.test('user management', async t => {
128126 const listUsersResponse = await immudbClient . listUsers ( ) ;
129127
130128 // test: change user permission
131- const changeUserPermissionRequest : schemaTypes . ChangePermissionRequest . AsObject = {
132- action : schemaTypes . PermissionAction . GRANT ,
129+ const changeUserPermissionRequest : Parameters . ChangePermission = {
130+ action : USER_ACTION . GRANT ,
133131 username : rand ,
134132 database : rand ,
135133 permission : USER_PERMISSION . READ_ONLY ,
@@ -145,7 +143,7 @@ tap.test('user management', async t => {
145143 await immudbClient . changePassword ( changePasswordRequest ) ;
146144
147145 // test: set active user
148- const setActiveUserRequest : schemaTypes . SetActiveUserRequest . AsObject = {
146+ const setActiveUserRequest : Parameters . SetActiveUser = {
149147 username : rand ,
150148 active : true ,
151149 } ;
@@ -175,11 +173,11 @@ tap.test('operations', async t => {
175173 const testDB = 'testdb' ;
176174
177175 // test: login using the specified username and password
178- const loginRequest = {
176+ const loginRequest : Parameters . Login = {
179177 user : IMMUDB_USER ,
180178 password : IMMUDB_PWD ,
181179 } ;
182- const loginResponse : schemaTypes . LoginResponse . AsObject | undefined = await immudbClient . login (
180+ const loginResponse = await immudbClient . login (
183181 loginRequest
184182 ) ;
185183
@@ -197,13 +195,13 @@ tap.test('operations', async t => {
197195
198196 if ( ! dbExists ) {
199197 // test: create database
200- const createDatabaseRequest : schemaTypes . Database . AsObject = { databasename : testDB } ;
198+ const createDatabaseRequest : Parameters . CreateDatabase = { databasename : testDB } ;
201199 const createDatabaseResponse = await immudbClient . createDatabase ( createDatabaseRequest ) ;
202200 }
203201 }
204202
205203 // test: use database just created
206- const useDatabaseRequest : schemaTypes . Database . AsObject = { databasename : testDB } ;
204+ const useDatabaseRequest : Parameters . UseDatabase = { databasename : testDB } ;
207205 const useDatabaseResponse = await immudbClient . useDatabase ( useDatabaseRequest ) ;
208206
209207 // test: add new item having the specified key
@@ -253,7 +251,7 @@ tap.test('operations', async t => {
253251
254252 // test: iterate over keys having the specified
255253 // prefix
256- const scanRequest : schemaTypes . ScanRequest . AsObject = {
254+ const scanRequest : Parameters . Scan = {
257255 seekkey : key ,
258256 prefix : 'test' ,
259257 desc : true ,
@@ -264,21 +262,21 @@ tap.test('operations', async t => {
264262 const seventhResponse = await immudbClient . scan ( scanRequest ) ;
265263
266264 // test: return an element by txId
267- const txByIdRequest : schemaTypes . TxRequest . AsObject = { tx : id as number }
265+ const txByIdRequest : Parameters . TxById = { tx : id as number }
268266 const txByIdResponse = await immudbClient . txById ( txByIdRequest ) ;
269267
270268 // test: safely get an element by txId
271- const verifiedTxByIdRequest : schemaTypes . TxRequest . AsObject = { tx : id as number }
269+ const verifiedTxByIdRequest : Parameters . VerifiedTxById = { tx : id as number }
272270 const verifiedTxByIdResponse = await immudbClient . verifiedTxById ( verifiedTxByIdRequest ) ;
273271
274272 // history: fetch history for the item having the
275273 // specified key
276274 const historyRequest = {
277275 key,
278- offset : 10 ,
279- limit : 5 ,
280- desc : false ,
281- sincetx : rand
276+ // offset: 10,
277+ // limit: 5,
278+ // desc: false,
279+ // sincetx: rand
282280 } ;
283281 const historyResponse = await immudbClient . history ( historyRequest ) ;
284282
@@ -297,7 +295,7 @@ tap.test('operations', async t => {
297295 const tenthResponse = await immudbClient . zScan ( zScanRequest ) ;
298296
299297 // test: execute a getAll read
300- const getAllRequest : schemaTypes . KeyListRequest . AsObject = {
298+ const getAllRequest : Parameters . GetAll = {
301299 keysList : [ key ] ,
302300 sincetx : 1
303301 } ;
@@ -316,7 +314,7 @@ tap.test('operations', async t => {
316314
317315 // test: safely add new item having the specified key
318316 // and value
319- let verifiedSetRequest : schemaTypes . KeyValue . AsObject = {
317+ let verifiedSetRequest : Parameters . VerifiedSet = {
320318 key : `${ key } ${ key } ` ,
321319 value : `${ value } ${ value } ` ,
322320 } ;
@@ -424,20 +422,20 @@ tap.test('batches', async t => {
424422 const res = await immudbClient . login ( loginRequest ) ;
425423
426424 // test: use default database
427- const useDatabaseRequest : schemaTypes . Database . AsObject = { databasename : 'defaultdb' } ;
425+ const useDatabaseRequest : Parameters . UseDatabase = { databasename : 'defaultdb' } ;
428426 const useDatabaseResponse = await immudbClient . useDatabase ( useDatabaseRequest ) ;
429427
430428 // test: execute setAll
431- const setAllRequest : schemaTypes . SetRequest . AsObject = { kvsList : [ ] } ;
429+ const setAllRequest : Parameters . SetAll = { kvsList : [ ] } ;
432430 for ( let i = 0 ; i < 2 ; i ++ ) {
433- const kv : schemaTypes . KeyValue . AsObject = { key : `test${ i } ` , value : `world${ i } ` }
431+ const kv = { key : `test${ i } ` , value : `world${ i } ` }
434432
435433 setAllRequest . kvsList . push ( kv ) ;
436434 }
437435 const setAllResponse = await immudbClient . setAll ( setAllRequest ) ;
438436
439437 // test: execute a batch read
440- const getAllRequest : schemaTypes . KeyListRequest . AsObject = { keysList : [ ] , sincetx : 0 } ;
438+ const getAllRequest : Parameters . GetAll = { keysList : [ ] , sincetx : 0 } ;
441439 for ( let i = 0 ; i < 2 ; i ++ ) {
442440 getAllRequest . keysList . push ( `test${ i } ` ) ;
443441 }
0 commit comments