Skip to content

Commit

Permalink
Merge pull request #9 from codenotary/1.0.10-rc.4
Browse files Browse the repository at this point in the history
1.0.10 rc.4
  • Loading branch information
Temii committed Mar 30, 2021
2 parents 9be81b0 + fe79d02 commit 60f3028
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 59 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "immudb-node",
"version": "1.0.10-rc.3",
"version": "1.0.10-rc.4",
"description": "Node ts client for immudb",
"directories": {
"src": "src",
Expand Down
24 changes: 12 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ class ImmudbClient {
const req = new schemaTypes.HistoryRequest();

req.setKey(util.utf8Encode(key));
req.setOffset(offset);
req.setLimit(limit);
req.setDesc(desc);
req.setSincetx(sincetx);
offset && req.setOffset(offset);
limit && req.setLimit(limit);
desc && req.setDesc(desc);
sincetx && req.setSincetx(sincetx);

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

req.setSet(util.utf8Encode(set));
req.setSeekkey(util.utf8Encode(seekkey));
req.setSeekscore(seekscore);
req.setSeekattx(seekattx);
req.setInclusiveseek(inclusiveseek);
req.setLimit(limit);
req.setDesc(desc);
req.setSincetx(sincetx);
req.setNowait(nowait);
seekkey && req.setSeekkey(util.utf8Encode(seekkey));
seekscore && req.setSeekscore(seekscore);
seekattx && req.setSeekattx(seekattx);
inclusiveseek && req.setInclusiveseek(inclusiveseek);
limit && req.setLimit(limit);
desc && req.setDesc(desc);
sincetx && req.setSincetx(sincetx);
nowait && req.setNowait(nowait);

if (minscore) {
const minScore = new schemaTypes.Score()
Expand Down
54 changes: 26 additions & 28 deletions tests/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import tap from 'tap';

import * as schemaTypes from '../src/proto/schema_pb';
import ImmudbClient from '../src/client';

import { Config } from '../src/interfaces';
import { USER_PERMISSION } from '../types/user';
import { USER_PERMISSION, USER_ACTION } from '../types/user';
import Parameters from '../types/parameters';

const {
IMMUDB_HOST = '127.0.0.1',
Expand Down Expand Up @@ -34,7 +34,7 @@ tap.test('database management', async t => {
}

// test: create database
const secondRequestData: schemaTypes.Database.AsObject = { databasename: 'db1' };
const secondRequestData: Parameters.CreateDatabase = { databasename: 'db1' };
try {
await immudbClient.createDatabase(secondRequestData);
t.pass('Successfully created database');
Expand All @@ -43,7 +43,7 @@ tap.test('database management', async t => {
}

// test: use database just created
const thirdRequestData: schemaTypes.Database.AsObject = { databasename: 'db1' };
const thirdRequestData: Parameters.UseDatabase = { databasename: 'db1' };
const secondResponse = await immudbClient.useDatabase(thirdRequestData);
// if (secondResponse) {
// t.type(secondResponse.token, 'string')
Expand All @@ -64,9 +64,7 @@ tap.test('database management', async t => {
}

// test: list all databases available
const fifthResponse:
| schemaTypes.DatabaseListResponse.AsObject
| undefined = await immudbClient.listDatabases();
const fifthResponse = await immudbClient.listDatabases();
if (fifthResponse) {
t.equal(fifthResponse.databasesList[0].databasename, 'defaultdb');
t.equal(fifthResponse.databasesList[1].databasename, 'db1');
Expand Down Expand Up @@ -102,7 +100,7 @@ tap.test('user management', async t => {
const rand = `${Math.floor(Math.random() * Math.floor(100000))}`;

// test: login using the specified username and password
const loginRequest = {
const loginRequest: Parameters.Login = {
user: IMMUDB_USER,
password: IMMUDB_PWD,
};
Expand All @@ -128,8 +126,8 @@ tap.test('user management', async t => {
const listUsersResponse = await immudbClient.listUsers();

// test: change user permission
const changeUserPermissionRequest: schemaTypes.ChangePermissionRequest.AsObject = {
action: schemaTypes.PermissionAction.GRANT,
const changeUserPermissionRequest: Parameters.ChangePermission = {
action: USER_ACTION.GRANT,
username: rand,
database: rand,
permission: USER_PERMISSION.READ_ONLY,
Expand All @@ -145,7 +143,7 @@ tap.test('user management', async t => {
await immudbClient.changePassword(changePasswordRequest);

// test: set active user
const setActiveUserRequest: schemaTypes.SetActiveUserRequest.AsObject = {
const setActiveUserRequest: Parameters.SetActiveUser = {
username: rand,
active: true,
};
Expand Down Expand Up @@ -175,11 +173,11 @@ tap.test('operations', async t => {
const testDB = 'testdb';

// test: login using the specified username and password
const loginRequest = {
const loginRequest: Parameters.Login = {
user: IMMUDB_USER,
password: IMMUDB_PWD,
};
const loginResponse: schemaTypes.LoginResponse.AsObject | undefined = await immudbClient.login(
const loginResponse = await immudbClient.login(
loginRequest
);

Expand All @@ -197,13 +195,13 @@ tap.test('operations', async t => {

if (!dbExists) {
// test: create database
const createDatabaseRequest: schemaTypes.Database.AsObject = { databasename: testDB };
const createDatabaseRequest: Parameters.CreateDatabase = { databasename: testDB };
const createDatabaseResponse = await immudbClient.createDatabase(createDatabaseRequest);
}
}

// test: use database just created
const useDatabaseRequest: schemaTypes.Database.AsObject = { databasename: testDB };
const useDatabaseRequest: Parameters.UseDatabase = { databasename: testDB };
const useDatabaseResponse = await immudbClient.useDatabase(useDatabaseRequest);

// test: add new item having the specified key
Expand Down Expand Up @@ -253,7 +251,7 @@ tap.test('operations', async t => {

// test: iterate over keys having the specified
// prefix
const scanRequest: schemaTypes.ScanRequest.AsObject = {
const scanRequest: Parameters.Scan = {
seekkey: key,
prefix: 'test',
desc: true,
Expand All @@ -264,21 +262,21 @@ tap.test('operations', async t => {
const seventhResponse = await immudbClient.scan(scanRequest);

// test: return an element by txId
const txByIdRequest: schemaTypes.TxRequest.AsObject = { tx: id as number }
const txByIdRequest: Parameters.TxById = { tx: id as number }
const txByIdResponse = await immudbClient.txById(txByIdRequest);

// test: safely get an element by txId
const verifiedTxByIdRequest: schemaTypes.TxRequest.AsObject = { tx: id as number }
const verifiedTxByIdRequest: Parameters.VerifiedTxById = { tx: id as number }
const verifiedTxByIdResponse = await immudbClient.verifiedTxById(verifiedTxByIdRequest);

// history: fetch history for the item having the
// specified key
const historyRequest = {
key,
offset: 10,
limit: 5,
desc: false,
sincetx: rand
// offset: 10,
// limit: 5,
// desc: false,
// sincetx: rand
};
const historyResponse = await immudbClient.history(historyRequest);

Expand All @@ -297,7 +295,7 @@ tap.test('operations', async t => {
const tenthResponse = await immudbClient.zScan(zScanRequest);

// test: execute a getAll read
const getAllRequest: schemaTypes.KeyListRequest.AsObject = {
const getAllRequest: Parameters.GetAll = {
keysList: [key],
sincetx: 1
};
Expand All @@ -316,7 +314,7 @@ tap.test('operations', async t => {

// test: safely add new item having the specified key
// and value
let verifiedSetRequest: schemaTypes.KeyValue.AsObject = {
let verifiedSetRequest: Parameters.VerifiedSet = {
key: `${key}${key}`,
value: `${value}${value}`,
};
Expand Down Expand Up @@ -424,20 +422,20 @@ tap.test('batches', async t => {
const res = await immudbClient.login(loginRequest);

// test: use default database
const useDatabaseRequest: schemaTypes.Database.AsObject = { databasename: 'defaultdb' };
const useDatabaseRequest: Parameters.UseDatabase = { databasename: 'defaultdb' };
const useDatabaseResponse = await immudbClient.useDatabase(useDatabaseRequest);

// test: execute setAll
const setAllRequest: schemaTypes.SetRequest.AsObject = { kvsList: [] };
const setAllRequest: Parameters.SetAll = { kvsList: [] };
for (let i = 0; i < 2; i++) {
const kv: schemaTypes.KeyValue.AsObject = { key: `test${i}`, value: `world${i}` }
const kv = { key: `test${i}`, value: `world${i}` }

setAllRequest.kvsList.push(kv);
}
const setAllResponse = await immudbClient.setAll(setAllRequest);

// test: execute a batch read
const getAllRequest: schemaTypes.KeyListRequest.AsObject = { keysList: [], sincetx: 0 };
const getAllRequest: Parameters.GetAll = { keysList: [], sincetx: 0 };
for (let i = 0; i < 2; i++) {
getAllRequest.keysList.push(`test${i}`);
}
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
],
"include": [
"src/**/*",
"examples/**/*",
"types/**/*",
],
"exclude": [
Expand Down
29 changes: 15 additions & 14 deletions types/parameters.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as schemaTypes from '../src/proto/schema_pb';
import { USER_PERMISSION } from './user'
import { USER_PERMISSION, USER_ACTION } from './user'
import * as interfaces from '../src/interfaces';

export namespace Parameters {
Expand Down Expand Up @@ -50,26 +50,27 @@ export namespace Parameters {
}
export type History = {
key: string
offset: number
limit: number
desc: boolean
sincetx: number
offset?: number
limit?: number
desc?: boolean
sincetx?: number
}
export type ZScan = {
set: string,
seekkey: string,
seekscore: number,
seekattx: number,
inclusiveseek: boolean,
limit: number,
desc: boolean,
seekkey?: string,
seekscore?: number,
seekattx?: number,
inclusiveseek?: boolean,
desc?: boolean,
sincetx?: number,
nowait?: boolean,
minscore?: schemaTypes.Score.AsObject,
maxscore?: schemaTypes.Score.AsObject,
sincetx: number,
nowait: boolean,
limit?: number,
}
export type ChangePermission = Omit<schemaTypes.ChangePermissionRequest.AsObject, 'permission'> & {
export type ChangePermission = Omit<schemaTypes.ChangePermissionRequest.AsObject, 'permission' | 'action'> & {
permission: USER_PERMISSION
action: USER_ACTION | schemaTypes.PermissionAction
}
export type CreateDatabase = schemaTypes.Database.AsObject
export type UseDatabase = schemaTypes.Database.AsObject
Expand Down
5 changes: 2 additions & 3 deletions types/user.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { PermissionAction } from '../src/proto/schema_pb'

export enum USER_PERMISSION {
NONE = 0,
READ_ONLY = 1,
READ_WRITE = 2,
}
export const USER_ACTION = PermissionAction

export { PermissionAction as USER_ACTION } from '../src/proto/schema_pb'
7 changes: 7 additions & 0 deletions types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum USER_PERMISSION {
NONE = 0,
READ_ONLY = 1,
READ_WRITE = 2,
}

export { PermissionAction as USER_ACTION } from '../src/proto/schema_pb'

0 comments on commit 60f3028

Please sign in to comment.