Skip to content

Commit 0829bfe

Browse files
authored
Merge pull request #13 from codenotary/1.0.10-rc.7
Updated schemas, stabilized tests, added tests for state management
2 parents 7dee89c + 937325a commit 0829bfe

File tree

15 files changed

+5817
-1048
lines changed

15 files changed

+5817
-1048
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ IMMUDB_TEST_PORT=56789
55
IMMUDB_USER=immudb
66
IMMUDB_PWD=immudb
77
IMMUDB_DEFAULT_DB=defaultdb
8+
TAP_TS='1' # This is to enable the TypeScript support in tap testing library

package.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "immudb-node",
3-
"version": "1.0.10-rc.6",
4-
"description": "Node ts client for immudb",
3+
"version": "1.0.10-rc.7",
4+
"description": "Node.js SDK for immudb written in TypeScript",
55
"directories": {
66
"src": "src",
77
"test": "tests"
@@ -12,31 +12,34 @@
1212
"prepare": "npm run build",
1313
"build": "tsc",
1414
"test": "tests/test.sh",
15-
"test:dev": "tests/test.sh --dev"
15+
"test:dev": "tests/test.sh --dev",
16+
"tap": "tap --ts"
1617
},
1718
"author": "",
1819
"license": "ISC",
1920
"devDependencies": {
20-
"@types/node": "^14.14.13",
21-
"@types/tap": "^14.10.2",
21+
"@types/btoa": "^1.2.3",
22+
"@types/google-protobuf": "^3.15.2",
23+
"@types/lodash": "^4.14.170",
24+
"@types/mocha": "^8.2.2",
25+
"@types/node": "^14.17.3",
26+
"@types/tap": "^14.10.3",
2227
"@typescript-eslint/eslint-plugin": "^3.9.0",
2328
"@typescript-eslint/parser": "^3.9.0",
2429
"crypto-ts": "^1.0.2",
25-
"grpc": "^1.24.4",
30+
"grpc": "^1.24.10",
31+
"grpc-tools": "^1.11.1",
2632
"grpc_tools_node_protoc_ts": "^5.0.1",
27-
"grpc-tools": "^1.9.0",
2833
"protobufjs": "6.10.1",
29-
"tap": "14.10.8",
34+
"tap": "15.0.9",
3035
"typescript": "^3.9.7"
3136
},
3237
"dependencies": {
3338
"@grpc/grpc-js": "1.2.0",
34-
"@types/btoa": "^1.2.3",
35-
"@types/google-protobuf": "^3.7.4",
36-
"@types/mocha": "^8.2.0",
3739
"btoa": "1.2.1",
38-
"dotenv": "^8.2.0",
40+
"dotenv": "^8.6.0",
3941
"google-protobuf": "3.13.0",
42+
"lodash": "^4.17.21",
4043
"ts-node": "^9.1.1"
4144
},
4245
"repository": {

proto/schema.proto

Lines changed: 141 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/*
2-
Copyright 2019-2020 vChain, Inc.
3-
2+
Copyright 2021 CodeNotary, Inc. All rights reserved.
43
Licensed under the Apache License, Version 2.0 (the "License");
54
you may not use this file except in compliance with the License.
65
You may obtain a copy of the License at
7-
86
http://www.apache.org/licenses/LICENSE-2.0
9-
107
Unless required by applicable law or agreed to in writing, software
118
distributed under the License is distributed on an "AS IS" BASIS,
129
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,6 +14,7 @@ limitations under the License.
1714
syntax = "proto3";
1815

1916
import "google/protobuf/empty.proto";
17+
import "google/protobuf/struct.proto";
2018

2119
package immudb.schema;
2220

@@ -109,6 +107,7 @@ message Op {
109107

110108
message ExecAllRequest {
111109
repeated Op Operations = 1;
110+
bool noWait = 2;
112111
}
113112

114113
message Entries {
@@ -214,6 +213,7 @@ message InclusionProof {
214213

215214
message SetRequest {
216215
repeated KeyValue KVs = 1;
216+
bool noWait = 2;
217217
}
218218

219219
message KeyRequest {
@@ -254,6 +254,7 @@ message ReferenceRequest {
254254
bytes referencedKey = 2;
255255
uint64 atTx = 3;
256256
bool boundRef = 4;
257+
bool noWait = 5;
257258
}
258259

259260
message VerifiableReferenceRequest {
@@ -267,6 +268,7 @@ message ZAddRequest {
267268
bytes key = 3;
268269
uint64 atTx = 4;
269270
bool boundRef = 5;
271+
bool noWait = 6;
270272
}
271273

272274
message Score {
@@ -320,7 +322,41 @@ message TxList {
320322
}
321323

322324
message Database {
323-
string databasename = 1;
325+
string databaseName = 1;
326+
}
327+
328+
message Table {
329+
string tableName = 1;
330+
}
331+
332+
message SQLGetRequest {
333+
string table = 1;
334+
SQLValue pkValue = 2;
335+
uint64 atTx = 3;
336+
uint64 sinceTx = 4;
337+
}
338+
339+
message VerifiableSQLGetRequest {
340+
SQLGetRequest sqlGetRequest = 1;
341+
uint64 proveSinceTx = 2;
342+
}
343+
344+
message SQLEntry {
345+
uint64 tx = 1;
346+
bytes key = 2;
347+
bytes value = 3;
348+
}
349+
350+
message VerifiableSQLEntry {
351+
SQLEntry sqlEntry = 1;
352+
VerifiableTx verifiableTx = 2;
353+
InclusionProof inclusionProof = 3;
354+
uint64 DatabaseId = 4;
355+
uint64 TableId = 5;
356+
string PKName = 6;
357+
map<uint64, string> ColIdsById = 8;
358+
map<string, uint64> ColIdsByName = 9;
359+
map<uint64, string> ColTypesById = 10;
324360
}
325361

326362
message UseDatabaseReply{
@@ -348,71 +384,113 @@ message DatabaseListResponse{
348384
repeated Database databases = 1;
349385
}
350386

351-
// immudb gRPC & REST service
352-
// IMPORTANT: All get and safeget functions return base64-encoded keys and values, while all set and safeset functions expect base64-encoded inputs.
353-
service ImmuService {
354-
rpc ListUsers (google.protobuf.Empty) returns (UserList){};
355-
356-
rpc CreateUser (CreateUserRequest) returns (google.protobuf.Empty){};
357-
358-
rpc ChangePassword (ChangePasswordRequest) returns (google.protobuf.Empty){};
359-
360-
rpc UpdateAuthConfig (AuthConfig) returns (google.protobuf.Empty){}
361-
rpc UpdateMTLSConfig (MTLSConfig) returns (google.protobuf.Empty){}
362-
363-
rpc Login (LoginRequest) returns (LoginResponse){};
364-
365-
rpc Logout (google.protobuf.Empty) returns (google.protobuf.Empty){};
366-
367-
rpc Set (SetRequest) returns (TxMetadata){};
368-
369-
rpc VerifiableSet (VerifiableSetRequest) returns (VerifiableTx){};
370-
371-
rpc Get (KeyRequest) returns (Entry){};
372-
373-
rpc VerifiableGet (VerifiableGetRequest) returns (VerifiableEntry){};
374-
375-
rpc GetAll (KeyListRequest) returns (Entries){};
376-
377-
rpc ExecAll (ExecAllRequest) returns (TxMetadata) {};
378-
379-
rpc Scan(ScanRequest) returns (Entries){};
380-
381-
rpc Count(KeyPrefix) returns (EntryCount){};
382-
383-
rpc CountAll(google.protobuf.Empty) returns (EntryCount){};
384-
385-
rpc TxById(TxRequest) returns (Tx){};
386-
387-
rpc VerifiableTxById(VerifiableTxRequest) returns (VerifiableTx){};
388-
389-
rpc TxScan(TxScanRequest) returns (TxList) {}
390-
391-
rpc History(HistoryRequest) returns (Entries){};
392-
393-
rpc Health (google.protobuf.Empty) returns (HealthResponse){};
394-
395-
rpc CurrentState (google.protobuf.Empty) returns (ImmutableState){};
396-
397-
rpc SetReference (ReferenceRequest) returns (TxMetadata){};
398-
399-
rpc VerifiableSetReference (VerifiableReferenceRequest) returns (VerifiableTx){};
387+
message Chunk {
388+
bytes content = 1;
389+
}
400390

401-
rpc ZAdd (ZAddRequest) returns (TxMetadata){};
391+
message UseSnapshotRequest {
392+
uint64 sinceTx = 1;
393+
uint64 asBeforeTx = 2;
394+
}
402395

403-
rpc VerifiableZAdd (VerifiableZAddRequest) returns (VerifiableTx){};
396+
message SQLExecRequest {
397+
string sql = 1;
398+
repeated NamedParam params = 2;
399+
bool noWait = 3;
400+
}
404401

405-
rpc ZScan (ZScanRequest) returns (ZEntries){};
402+
message SQLQueryRequest {
403+
string sql = 1;
404+
repeated NamedParam params = 2;
405+
bool reuseSnapshot = 3;
406+
}
406407

407-
rpc CreateDatabase(Database) returns (google.protobuf.Empty) {}
408+
message NamedParam {
409+
string name = 1;
410+
SQLValue value = 2;
411+
}
408412

409-
rpc DatabaseList (google.protobuf.Empty) returns (DatabaseListResponse){};
413+
message SQLExecResult {
414+
repeated TxMetadata ctxs = 1;
415+
repeated TxMetadata dtxs = 2;
416+
}
410417

411-
rpc UseDatabase(Database) returns (UseDatabaseReply) {}
418+
message SQLQueryResult {
419+
repeated Column columns = 2;
420+
repeated Row rows = 1;
421+
}
412422

413-
rpc CleanIndex(google.protobuf.Empty) returns (google.protobuf.Empty) {}
423+
message Column {
424+
string name = 1;
425+
string type = 2;
426+
}
414427

415-
rpc ChangePermission(ChangePermissionRequest) returns (google.protobuf.Empty) {}
428+
message Row {
429+
repeated string columns = 1;
430+
repeated SQLValue values = 2;
431+
}
416432

417-
rpc SetActiveUser (SetActiveUserRequest) returns (google.protobuf.Empty){};
433+
message SQLValue {
434+
oneof value {
435+
google.protobuf.NullValue null = 1;
436+
uint64 n = 2;
437+
string s = 3;
438+
bool b = 4;
439+
bytes bs = 5;
440+
}
418441
}
442+
443+
// immudb gRPC & REST service
444+
// IMPORTANT: All get and safeget functions return base64-encoded keys and values, while all set and safeset functions expect base64-encoded inputs.
445+
service ImmuService {
446+
rpc ListUsers (google.protobuf.Empty) returns (UserList);
447+
rpc CreateUser (CreateUserRequest) returns (google.protobuf.Empty);
448+
rpc ChangePassword (ChangePasswordRequest) returns (google.protobuf.Empty);
449+
rpc UpdateAuthConfig (AuthConfig) returns (google.protobuf.Empty);
450+
rpc UpdateMTLSConfig (MTLSConfig) returns (google.protobuf.Empty);
451+
rpc Login (LoginRequest) returns (LoginResponse);
452+
rpc Logout (google.protobuf.Empty) returns (google.protobuf.Empty);
453+
rpc Set (SetRequest) returns (TxMetadata);
454+
rpc VerifiableSet (VerifiableSetRequest) returns (VerifiableTx);
455+
rpc Get (KeyRequest) returns (Entry);
456+
rpc VerifiableGet (VerifiableGetRequest) returns (VerifiableEntry);
457+
rpc GetAll (KeyListRequest) returns (Entries);
458+
rpc ExecAll (ExecAllRequest) returns (TxMetadata);
459+
rpc Scan(ScanRequest) returns (Entries);
460+
rpc Count(KeyPrefix) returns (EntryCount);
461+
rpc CountAll(google.protobuf.Empty) returns (EntryCount);
462+
rpc TxById(TxRequest) returns (Tx);
463+
rpc VerifiableTxById(VerifiableTxRequest) returns (VerifiableTx);
464+
rpc TxScan(TxScanRequest) returns (TxList);
465+
rpc History(HistoryRequest) returns (Entries);
466+
rpc Health (google.protobuf.Empty) returns (HealthResponse);
467+
rpc CurrentState (google.protobuf.Empty) returns (ImmutableState);
468+
rpc SetReference (ReferenceRequest) returns (TxMetadata);
469+
rpc VerifiableSetReference (VerifiableReferenceRequest) returns (VerifiableTx);
470+
rpc ZAdd (ZAddRequest) returns (TxMetadata);
471+
rpc VerifiableZAdd (VerifiableZAddRequest) returns (VerifiableTx);
472+
rpc ZScan (ZScanRequest) returns (ZEntries);
473+
rpc CreateDatabase(Database) returns (google.protobuf.Empty);
474+
rpc DatabaseList (google.protobuf.Empty) returns (DatabaseListResponse);
475+
rpc UseDatabase(Database) returns (UseDatabaseReply);
476+
rpc CleanIndex(google.protobuf.Empty) returns (google.protobuf.Empty);
477+
rpc ChangePermission(ChangePermissionRequest) returns (google.protobuf.Empty);
478+
rpc SetActiveUser (SetActiveUserRequest) returns (google.protobuf.Empty);
479+
// Streams
480+
rpc streamGet(KeyRequest) returns (stream Chunk);
481+
rpc streamSet(stream Chunk) returns (TxMetadata);
482+
rpc streamVerifiableGet(VerifiableGetRequest) returns (stream Chunk);
483+
rpc streamVerifiableSet(stream Chunk) returns (VerifiableTx);
484+
rpc streamScan(ScanRequest) returns (stream Chunk);
485+
rpc streamZScan(ZScanRequest) returns (stream Chunk);
486+
rpc streamHistory(HistoryRequest) returns (stream Chunk);
487+
rpc streamExecAll(stream Chunk) returns (TxMetadata);
488+
489+
// SQL
490+
rpc UseSnapshot(UseSnapshotRequest) returns (google.protobuf.Empty);
491+
rpc SQLExec(SQLExecRequest) returns (SQLExecResult);
492+
rpc SQLQuery(SQLQueryRequest) returns (SQLQueryResult);
493+
rpc ListTables(google.protobuf.Empty) returns (SQLQueryResult);
494+
rpc DescribeTable(Table) returns (SQLQueryResult);
495+
rpc VerifiableSQLGet (VerifiableSQLGetRequest) returns (VerifiableSQLEntry);
496+
}

src/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ class ImmudbClient {
271271

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

274-
return new Promise(resolve =>
274+
return new Promise((resolve, reject) =>
275275
this.client.get(req, this._metadata, (err, res) => {
276276
if (err) {
277277
console.error('Get error', err);
278-
throw new Error(err.message);
278+
reject(err.message);
279279
} else {
280280
resolve({
281281
tx: res && res.getTx(),
@@ -352,7 +352,7 @@ class ImmudbClient {
352352
this.client.listUsers(req, this._metadata, (err, res) => {
353353
if (err) {
354354
console.error('List users error', err);
355-
throw new Error(err.message);
355+
reject(err.message);
356356
}
357357

358358
const ul = res && res.getUsersList();
@@ -443,7 +443,7 @@ class ImmudbClient {
443443
this.client.logout(req, this._metadata, (err, res) => {
444444
if (err) {
445445
console.error('Logout error', err);
446-
throw new Error(err.message);
446+
reject(err.message);
447447
}
448448

449449
resolve(res);
@@ -961,7 +961,7 @@ class ImmudbClient {
961961
refReq.setBoundref(attx > 0)
962962

963963
req.setReferencerequest(refReq)
964-
req.setProvesincetx(state.getTxid())
964+
req.setProvesincetx(txid)
965965

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

0 commit comments

Comments
 (0)