Skip to content

Commit

Permalink
Merge pull request #13 from codenotary/1.0.10-rc.7
Browse files Browse the repository at this point in the history
Updated schemas, stabilized tests, added tests for state management
  • Loading branch information
Temii committed Sep 9, 2021
2 parents 7dee89c + 937325a commit 0829bfe
Show file tree
Hide file tree
Showing 15 changed files with 5,817 additions and 1,048 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ IMMUDB_TEST_PORT=56789
IMMUDB_USER=immudb
IMMUDB_PWD=immudb
IMMUDB_DEFAULT_DB=defaultdb
TAP_TS='1' # This is to enable the TypeScript support in tap testing library
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "immudb-node",
"version": "1.0.10-rc.6",
"description": "Node ts client for immudb",
"version": "1.0.10-rc.7",
"description": "Node.js SDK for immudb written in TypeScript",
"directories": {
"src": "src",
"test": "tests"
Expand All @@ -12,31 +12,34 @@
"prepare": "npm run build",
"build": "tsc",
"test": "tests/test.sh",
"test:dev": "tests/test.sh --dev"
"test:dev": "tests/test.sh --dev",
"tap": "tap --ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^14.14.13",
"@types/tap": "^14.10.2",
"@types/btoa": "^1.2.3",
"@types/google-protobuf": "^3.15.2",
"@types/lodash": "^4.14.170",
"@types/mocha": "^8.2.2",
"@types/node": "^14.17.3",
"@types/tap": "^14.10.3",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"crypto-ts": "^1.0.2",
"grpc": "^1.24.4",
"grpc": "^1.24.10",
"grpc-tools": "^1.11.1",
"grpc_tools_node_protoc_ts": "^5.0.1",
"grpc-tools": "^1.9.0",
"protobufjs": "6.10.1",
"tap": "14.10.8",
"tap": "15.0.9",
"typescript": "^3.9.7"
},
"dependencies": {
"@grpc/grpc-js": "1.2.0",
"@types/btoa": "^1.2.3",
"@types/google-protobuf": "^3.7.4",
"@types/mocha": "^8.2.0",
"btoa": "1.2.1",
"dotenv": "^8.2.0",
"dotenv": "^8.6.0",
"google-protobuf": "3.13.0",
"lodash": "^4.17.21",
"ts-node": "^9.1.1"
},
"repository": {
Expand Down
204 changes: 141 additions & 63 deletions proto/schema.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright 2019-2020 vChain, Inc.
Copyright 2021 CodeNotary, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -17,6 +14,7 @@ limitations under the License.
syntax = "proto3";

import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";

package immudb.schema;

Expand Down Expand Up @@ -109,6 +107,7 @@ message Op {

message ExecAllRequest {
repeated Op Operations = 1;
bool noWait = 2;
}

message Entries {
Expand Down Expand Up @@ -214,6 +213,7 @@ message InclusionProof {

message SetRequest {
repeated KeyValue KVs = 1;
bool noWait = 2;
}

message KeyRequest {
Expand Down Expand Up @@ -254,6 +254,7 @@ message ReferenceRequest {
bytes referencedKey = 2;
uint64 atTx = 3;
bool boundRef = 4;
bool noWait = 5;
}

message VerifiableReferenceRequest {
Expand All @@ -267,6 +268,7 @@ message ZAddRequest {
bytes key = 3;
uint64 atTx = 4;
bool boundRef = 5;
bool noWait = 6;
}

message Score {
Expand Down Expand Up @@ -320,7 +322,41 @@ message TxList {
}

message Database {
string databasename = 1;
string databaseName = 1;
}

message Table {
string tableName = 1;
}

message SQLGetRequest {
string table = 1;
SQLValue pkValue = 2;
uint64 atTx = 3;
uint64 sinceTx = 4;
}

message VerifiableSQLGetRequest {
SQLGetRequest sqlGetRequest = 1;
uint64 proveSinceTx = 2;
}

message SQLEntry {
uint64 tx = 1;
bytes key = 2;
bytes value = 3;
}

message VerifiableSQLEntry {
SQLEntry sqlEntry = 1;
VerifiableTx verifiableTx = 2;
InclusionProof inclusionProof = 3;
uint64 DatabaseId = 4;
uint64 TableId = 5;
string PKName = 6;
map<uint64, string> ColIdsById = 8;
map<string, uint64> ColIdsByName = 9;
map<uint64, string> ColTypesById = 10;
}

message UseDatabaseReply{
Expand Down Expand Up @@ -348,71 +384,113 @@ message DatabaseListResponse{
repeated Database databases = 1;
}

// immudb gRPC & REST service
// IMPORTANT: All get and safeget functions return base64-encoded keys and values, while all set and safeset functions expect base64-encoded inputs.
service ImmuService {
rpc ListUsers (google.protobuf.Empty) returns (UserList){};

rpc CreateUser (CreateUserRequest) returns (google.protobuf.Empty){};

rpc ChangePassword (ChangePasswordRequest) returns (google.protobuf.Empty){};

rpc UpdateAuthConfig (AuthConfig) returns (google.protobuf.Empty){}
rpc UpdateMTLSConfig (MTLSConfig) returns (google.protobuf.Empty){}

rpc Login (LoginRequest) returns (LoginResponse){};

rpc Logout (google.protobuf.Empty) returns (google.protobuf.Empty){};

rpc Set (SetRequest) returns (TxMetadata){};

rpc VerifiableSet (VerifiableSetRequest) returns (VerifiableTx){};

rpc Get (KeyRequest) returns (Entry){};

rpc VerifiableGet (VerifiableGetRequest) returns (VerifiableEntry){};

rpc GetAll (KeyListRequest) returns (Entries){};

rpc ExecAll (ExecAllRequest) returns (TxMetadata) {};

rpc Scan(ScanRequest) returns (Entries){};

rpc Count(KeyPrefix) returns (EntryCount){};

rpc CountAll(google.protobuf.Empty) returns (EntryCount){};

rpc TxById(TxRequest) returns (Tx){};

rpc VerifiableTxById(VerifiableTxRequest) returns (VerifiableTx){};

rpc TxScan(TxScanRequest) returns (TxList) {}

rpc History(HistoryRequest) returns (Entries){};

rpc Health (google.protobuf.Empty) returns (HealthResponse){};

rpc CurrentState (google.protobuf.Empty) returns (ImmutableState){};

rpc SetReference (ReferenceRequest) returns (TxMetadata){};

rpc VerifiableSetReference (VerifiableReferenceRequest) returns (VerifiableTx){};
message Chunk {
bytes content = 1;
}

rpc ZAdd (ZAddRequest) returns (TxMetadata){};
message UseSnapshotRequest {
uint64 sinceTx = 1;
uint64 asBeforeTx = 2;
}

rpc VerifiableZAdd (VerifiableZAddRequest) returns (VerifiableTx){};
message SQLExecRequest {
string sql = 1;
repeated NamedParam params = 2;
bool noWait = 3;
}

rpc ZScan (ZScanRequest) returns (ZEntries){};
message SQLQueryRequest {
string sql = 1;
repeated NamedParam params = 2;
bool reuseSnapshot = 3;
}

rpc CreateDatabase(Database) returns (google.protobuf.Empty) {}
message NamedParam {
string name = 1;
SQLValue value = 2;
}

rpc DatabaseList (google.protobuf.Empty) returns (DatabaseListResponse){};
message SQLExecResult {
repeated TxMetadata ctxs = 1;
repeated TxMetadata dtxs = 2;
}

rpc UseDatabase(Database) returns (UseDatabaseReply) {}
message SQLQueryResult {
repeated Column columns = 2;
repeated Row rows = 1;
}

rpc CleanIndex(google.protobuf.Empty) returns (google.protobuf.Empty) {}
message Column {
string name = 1;
string type = 2;
}

rpc ChangePermission(ChangePermissionRequest) returns (google.protobuf.Empty) {}
message Row {
repeated string columns = 1;
repeated SQLValue values = 2;
}

rpc SetActiveUser (SetActiveUserRequest) returns (google.protobuf.Empty){};
message SQLValue {
oneof value {
google.protobuf.NullValue null = 1;
uint64 n = 2;
string s = 3;
bool b = 4;
bytes bs = 5;
}
}

// immudb gRPC & REST service
// IMPORTANT: All get and safeget functions return base64-encoded keys and values, while all set and safeset functions expect base64-encoded inputs.
service ImmuService {
rpc ListUsers (google.protobuf.Empty) returns (UserList);
rpc CreateUser (CreateUserRequest) returns (google.protobuf.Empty);
rpc ChangePassword (ChangePasswordRequest) returns (google.protobuf.Empty);
rpc UpdateAuthConfig (AuthConfig) returns (google.protobuf.Empty);
rpc UpdateMTLSConfig (MTLSConfig) returns (google.protobuf.Empty);
rpc Login (LoginRequest) returns (LoginResponse);
rpc Logout (google.protobuf.Empty) returns (google.protobuf.Empty);
rpc Set (SetRequest) returns (TxMetadata);
rpc VerifiableSet (VerifiableSetRequest) returns (VerifiableTx);
rpc Get (KeyRequest) returns (Entry);
rpc VerifiableGet (VerifiableGetRequest) returns (VerifiableEntry);
rpc GetAll (KeyListRequest) returns (Entries);
rpc ExecAll (ExecAllRequest) returns (TxMetadata);
rpc Scan(ScanRequest) returns (Entries);
rpc Count(KeyPrefix) returns (EntryCount);
rpc CountAll(google.protobuf.Empty) returns (EntryCount);
rpc TxById(TxRequest) returns (Tx);
rpc VerifiableTxById(VerifiableTxRequest) returns (VerifiableTx);
rpc TxScan(TxScanRequest) returns (TxList);
rpc History(HistoryRequest) returns (Entries);
rpc Health (google.protobuf.Empty) returns (HealthResponse);
rpc CurrentState (google.protobuf.Empty) returns (ImmutableState);
rpc SetReference (ReferenceRequest) returns (TxMetadata);
rpc VerifiableSetReference (VerifiableReferenceRequest) returns (VerifiableTx);
rpc ZAdd (ZAddRequest) returns (TxMetadata);
rpc VerifiableZAdd (VerifiableZAddRequest) returns (VerifiableTx);
rpc ZScan (ZScanRequest) returns (ZEntries);
rpc CreateDatabase(Database) returns (google.protobuf.Empty);
rpc DatabaseList (google.protobuf.Empty) returns (DatabaseListResponse);
rpc UseDatabase(Database) returns (UseDatabaseReply);
rpc CleanIndex(google.protobuf.Empty) returns (google.protobuf.Empty);
rpc ChangePermission(ChangePermissionRequest) returns (google.protobuf.Empty);
rpc SetActiveUser (SetActiveUserRequest) returns (google.protobuf.Empty);
// Streams
rpc streamGet(KeyRequest) returns (stream Chunk);
rpc streamSet(stream Chunk) returns (TxMetadata);
rpc streamVerifiableGet(VerifiableGetRequest) returns (stream Chunk);
rpc streamVerifiableSet(stream Chunk) returns (VerifiableTx);
rpc streamScan(ScanRequest) returns (stream Chunk);
rpc streamZScan(ZScanRequest) returns (stream Chunk);
rpc streamHistory(HistoryRequest) returns (stream Chunk);
rpc streamExecAll(stream Chunk) returns (TxMetadata);

// SQL
rpc UseSnapshot(UseSnapshotRequest) returns (google.protobuf.Empty);
rpc SQLExec(SQLExecRequest) returns (SQLExecResult);
rpc SQLQuery(SQLQueryRequest) returns (SQLQueryResult);
rpc ListTables(google.protobuf.Empty) returns (SQLQueryResult);
rpc DescribeTable(Table) returns (SQLQueryResult);
rpc VerifiableSQLGet (VerifiableSQLGetRequest) returns (VerifiableSQLEntry);
}
10 changes: 5 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ class ImmudbClient {

req.setKey(util.utf8Encode(key));

return new Promise(resolve =>
return new Promise((resolve, reject) =>
this.client.get(req, this._metadata, (err, res) => {
if (err) {
console.error('Get error', err);
throw new Error(err.message);
reject(err.message);
} else {
resolve({
tx: res && res.getTx(),
Expand Down Expand Up @@ -352,7 +352,7 @@ class ImmudbClient {
this.client.listUsers(req, this._metadata, (err, res) => {
if (err) {
console.error('List users error', err);
throw new Error(err.message);
reject(err.message);
}

const ul = res && res.getUsersList();
Expand Down Expand Up @@ -443,7 +443,7 @@ class ImmudbClient {
this.client.logout(req, this._metadata, (err, res) => {
if (err) {
console.error('Logout error', err);
throw new Error(err.message);
reject(err.message);
}

resolve(res);
Expand Down Expand Up @@ -961,7 +961,7 @@ class ImmudbClient {
refReq.setBoundref(attx > 0)

req.setReferencerequest(refReq)
req.setProvesincetx(state.getTxid())
req.setProvesincetx(txid)

return new Promise((resolve, reject) => this.client.verifiableSetReference(req, this._metadata, (err, res) => {
if (err) {
Expand Down
Loading

0 comments on commit 0829bfe

Please sign in to comment.