Skip to content

Commit 60f3028

Browse files
authored
Merge pull request #9 from codenotary/1.0.10-rc.4
1.0.10 rc.4
2 parents 9be81b0 + fe79d02 commit 60f3028

File tree

7 files changed

+63
-59
lines changed

7 files changed

+63
-59
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "immudb-node",
3-
"version": "1.0.10-rc.3",
3+
"version": "1.0.10-rc.4",
44
"description": "Node ts client for immudb",
55
"directories": {
66
"src": "src",

src/client.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ class ImmudbClient {
604604
const req = new schemaTypes.HistoryRequest();
605605

606606
req.setKey(util.utf8Encode(key));
607-
req.setOffset(offset);
608-
req.setLimit(limit);
609-
req.setDesc(desc);
610-
req.setSincetx(sincetx);
607+
offset && req.setOffset(offset);
608+
limit && req.setLimit(limit);
609+
desc && req.setDesc(desc);
610+
sincetx && req.setSincetx(sincetx);
611611

612612
return new Promise((resolve, reject) =>
613613
this.client.history(req, this._metadata, (err, res) => {
@@ -643,14 +643,14 @@ class ImmudbClient {
643643
const req = new schemaTypes.ZScanRequest();
644644

645645
req.setSet(util.utf8Encode(set));
646-
req.setSeekkey(util.utf8Encode(seekkey));
647-
req.setSeekscore(seekscore);
648-
req.setSeekattx(seekattx);
649-
req.setInclusiveseek(inclusiveseek);
650-
req.setLimit(limit);
651-
req.setDesc(desc);
652-
req.setSincetx(sincetx);
653-
req.setNowait(nowait);
646+
seekkey && req.setSeekkey(util.utf8Encode(seekkey));
647+
seekscore && req.setSeekscore(seekscore);
648+
seekattx && req.setSeekattx(seekattx);
649+
inclusiveseek && req.setInclusiveseek(inclusiveseek);
650+
limit && req.setLimit(limit);
651+
desc && req.setDesc(desc);
652+
sincetx && req.setSincetx(sincetx);
653+
nowait && req.setNowait(nowait);
654654

655655
if (minscore) {
656656
const minScore = new schemaTypes.Score()

tests/client.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import tap from 'tap';
22

3-
import * as schemaTypes from '../src/proto/schema_pb';
43
import ImmudbClient from '../src/client';
54

65
import { 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

99
const {
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
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
],
2121
"include": [
2222
"src/**/*",
23-
"examples/**/*",
2423
"types/**/*",
2524
],
2625
"exclude": [

types/parameters.d.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as schemaTypes from '../src/proto/schema_pb';
2-
import { USER_PERMISSION } from './user'
2+
import { USER_PERMISSION, USER_ACTION } from './user'
33
import * as interfaces from '../src/interfaces';
44

55
export namespace Parameters {
@@ -50,26 +50,27 @@ export namespace Parameters {
5050
}
5151
export type History = {
5252
key: string
53-
offset: number
54-
limit: number
55-
desc: boolean
56-
sincetx: number
53+
offset?: number
54+
limit?: number
55+
desc?: boolean
56+
sincetx?: number
5757
}
5858
export type ZScan = {
5959
set: string,
60-
seekkey: string,
61-
seekscore: number,
62-
seekattx: number,
63-
inclusiveseek: boolean,
64-
limit: number,
65-
desc: boolean,
60+
seekkey?: string,
61+
seekscore?: number,
62+
seekattx?: number,
63+
inclusiveseek?: boolean,
64+
desc?: boolean,
65+
sincetx?: number,
66+
nowait?: boolean,
6667
minscore?: schemaTypes.Score.AsObject,
6768
maxscore?: schemaTypes.Score.AsObject,
68-
sincetx: number,
69-
nowait: boolean,
69+
limit?: number,
7070
}
71-
export type ChangePermission = Omit<schemaTypes.ChangePermissionRequest.AsObject, 'permission'> & {
71+
export type ChangePermission = Omit<schemaTypes.ChangePermissionRequest.AsObject, 'permission' | 'action'> & {
7272
permission: USER_PERMISSION
73+
action: USER_ACTION | schemaTypes.PermissionAction
7374
}
7475
export type CreateDatabase = schemaTypes.Database.AsObject
7576
export type UseDatabase = schemaTypes.Database.AsObject

types/user.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { PermissionAction } from '../src/proto/schema_pb'
2-
31
export enum USER_PERMISSION {
42
NONE = 0,
53
READ_ONLY = 1,
64
READ_WRITE = 2,
75
}
8-
export const USER_ACTION = PermissionAction
6+
7+
export { PermissionAction as USER_ACTION } from '../src/proto/schema_pb'

types/user.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export enum USER_PERMISSION {
2+
NONE = 0,
3+
READ_ONLY = 1,
4+
READ_WRITE = 2,
5+
}
6+
7+
export { PermissionAction as USER_ACTION } from '../src/proto/schema_pb'

0 commit comments

Comments
 (0)