Skip to content

Commit

Permalink
Merge pull request #41 from bigchaindb/updates
Browse files Browse the repository at this point in the history
Expose driver, models moved to models object
  • Loading branch information
jernejpregelj authored Apr 17, 2018
2 parents 0ebf1fb + d55e571 commit 8bd9e06
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 55 deletions.
9 changes: 9 additions & 0 deletions .ci/travis-before-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

sudo apt-get update
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

sudo rm /usr/local/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
chmod +x docker-compose
sudo mv docker-compose /usr/local/bin
5 changes: 5 additions & 0 deletions .ci/travis-before-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e -x

docker-compose up -d bigchaindb
5 changes: 5 additions & 0 deletions .ci/travis-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e -x

docker-compose build --no-cache bigchaindb
5 changes: 5 additions & 0 deletions .ci/travis_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e -x

docker-compose run --rm js-driver-orm npm run test
23 changes: 13 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ cache:
directories:
- node_modules

env:
global:
- DOCKER_COMPOSE_VERSION=1.19.0

before_install:
- docker run -d -p 27017:27017 mongo:3.4 --replSet=bigchain-rs
- docker run -d -p 9984:9984
-e BIGCHAINDB_KEYPAIR_PUBLIC=8wHUvvraRo5yEoJAt66UTZaFq9YZ9tFFwcauKPDtjkGw
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
-e BIGCHAINDB_DATABASE_BACKEND=mongodb
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1
bigchaindb/bigchaindb:1.0.0
start
- gem install cowsay
- npm install -g codecov
- .ci/travis-before-install.sh

install:
- .ci/travis-install.sh

before_script:
- .ci/travis-before-script.sh
- gem install cowsay
- npm install -g codecov

script: npm run test

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const bdbOrm = new Orm(
// note: cannot be changed once set!
bdbOrm.define("myModel", "https://schema.org/v1/myModel")
// create a public and private key for Alice
const aliceKeypair = new driver.Ed25519Keypair()
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
```

## Examples
Expand All @@ -64,7 +64,7 @@ All examples need bdbOrm initialized as described in usage

```javascript
// from the defined models in our bdbOrm we create an asset with Alice as owner
bdbOrm.myModel
bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
Expand All @@ -87,7 +87,7 @@ bdbOrm.myModel
```javascript
// get all objects with retrieve()
// or get a specific object with retrieve(object.id)
bdbOrm.myModel
bdbOrm.models.myModel
.retrieve()
.then(assets => {
// assets is an array of myModel
Expand All @@ -100,7 +100,7 @@ bdbOrm.myModel
```javascript
// create an asset with Alice as owner
bdbOrm.myModel
bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
Expand All @@ -127,7 +127,7 @@ bdbOrm.myModel
```javascript
// create an asset with Alice as owner
bdbOrm.myModel
bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
Expand All @@ -148,7 +148,7 @@ bdbOrm.myModel
## License

```
Copyright 2017 BigchainDB GmbH
Copyright 2018 BigchainDB GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
12 changes: 12 additions & 0 deletions compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.6

RUN apt-get update && apt-get install -y vim

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN pip install --upgrade pip ipdb ipython

COPY . /usr/src/app/

RUN pip install git+https://github.com/bigchaindb/bigchaindb.git
17 changes: 17 additions & 0 deletions compose/tendermint/tmdata/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml

proxy_app = "tcp://bigchaindb:46658"
moniker = "anonymous"
fast_sync = true
db_backend = "leveldb"
log_level = "state:debug,*:error"

[consensus]
create_empty_blocks = false

[rpc]
laddr = "tcp://0.0.0.0:46657"

[p2p]
laddr = "tcp://0.0.0.0:46656"
4 changes: 2 additions & 2 deletions dist/browser/bigchaindb-orm.amd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/bigchaindb-orm.amd.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/browser/bigchaindb-orm.cjs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/bigchaindb-orm.cjs.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/browser/bigchaindb-orm.cjs2.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/bigchaindb-orm.cjs2.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/browser/bigchaindb-orm.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/bigchaindb-orm.umd.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/browser/bigchaindb-orm.window.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/bigchaindb-orm.window.min.js.map

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions dist/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // eslint-disable-next-line import/no-namespace


var _bigchaindbDriver = require('bigchaindb-driver');

var driver = _interopRequireWildcard(_bigchaindbDriver);

var _connection = require('./connection');

Expand All @@ -16,6 +21,8 @@ var _ormobject2 = _interopRequireDefault(_ormobject);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Orm = function () {
Expand All @@ -27,12 +34,14 @@ var Orm = function () {
if (headers && headers.app_id) {
this.appId = headers.app_id;
}
this.models = [];
this.driver = driver;
}

_createClass(Orm, [{
key: 'define',
value: function define(modelName, modelSchema) {
this[modelName] = new _ormobject2.default(modelName, modelSchema, this.connection, this.appId);
this.models[modelName] = new _ormobject2.default(modelName, modelSchema, this.connection, this.appId);
}
}]);

Expand Down
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '2.1'

services:
mongodb:
image: mongo:3.4.13
ports:
- "27017"
command: mongod
bigchaindb:
depends_on:
- mongodb
- tendermint
image: bigchaindb/bigchaindb:master
environment:
BIGCHAINDB_DATABASE_HOST: mongodb
BIGCHAINDB_DATABASE_PORT: 27017
BIGCHAINDB_SERVER_BIND: 0.0.0.0:9984
BIGCHAINDB_WSSERVER_HOST: 0.0.0.0
BIGCHAINDB_TENDERMINT_HOST: tendermint
BIGCHAINDB_TENDERMINT_PORT: 46657
ports:
- "9984:9984"
- "9985:9985"
- "46658"
healthcheck:
test: ["CMD", "bash", "-c", "curl http://bigchaindb:9984 && curl http://tendermint:46657/abci_query"]
interval: 3s
timeout: 5s
retries: 3
command: -l DEBUG start
tendermint:
image: tendermint/tendermint:0.12
volumes:
- ./compose/tendermint/tmdata/config.toml:/tendermint/config.toml
entrypoint: ''
ports:
- "46656"
- "46657"
command: bash -c "tendermint init && tendermint node"
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"ava": "^0.25.0",
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-eslint": "^8.2.3",
"babel-loader": "^7.1.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
Expand All @@ -33,18 +33,18 @@
"cross-env": "^5.1.4",
"eslint": "^4.19.1",
"eslint-config-ascribe": "^3.0.5",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-import": "^2.11.0",
"nyc": "^11.6.0",
"release-it": "^7.2.1",
"release-it": "^7.4.0",
"rimraf": "^2.6.2",
"sinon": "^4.4.9",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13"
"sinon": "^4.5.0",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14"
},
"scripts": {
"lint": "./node_modules/eslint/bin/eslint.js ./{src,test}",
"build": "npm run clean && npm run build:cjs && npm run build:dist",
"build:bundle": "webpack",
"build:bundle": "cross-env NODE_ENV=production webpack -p",
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
"build:dist": "cross-env NODE_ENV=production webpack -p",
"clean": "rimraf dist/bundle dist/node",
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line import/no-namespace
import * as driver from 'bigchaindb-driver'
import Connection from './connection'
import OrmObject from './ormobject'

Expand All @@ -8,9 +10,11 @@ export default class Orm {
if (headers && headers.app_id) {
this.appId = headers.app_id
}
this.models = []
this.driver = driver
}
define(modelName, modelSchema) {
this[modelName] = new OrmObject(
this.models[modelName] = new OrmObject(
modelName,
modelSchema,
this.connection,
Expand Down
27 changes: 13 additions & 14 deletions test/test_orm.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import test from 'ava'

import * as driver from 'bigchaindb-driver' // eslint-disable-line import/no-namespace
import Orm from '../src/index'


test('Create asset with data', t => {
const expected = { key: 'dataValue' }

const bdbOrm = new Orm('http://127.0.0.1:9984/api/v1/', {
const bdbOrm = new Orm('http://localhost:9984/api/v1/', {
app_id: '',
app_key: ''
})
bdbOrm.define('myModel', 'https://schema.org/v1/myModel')
// create a public and private key for Alice
const aliceKeypair = new driver.Ed25519Keypair()
return bdbOrm.myModel
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
return bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: expected
Expand All @@ -26,19 +25,19 @@ test('Create asset with data', t => {
test('Retrieve asset', t => {
const expected = { key: 'dataValue' }

const bdbOrm = new Orm('http://127.0.0.1:9984/api/v1/', {
const bdbOrm = new Orm('http://localhost:9984/api/v1/', {
app_id: '',
app_key: ''
})
bdbOrm.define('myModel', 'https://schema.org/v1/myModel')
// create a public and private key for Alice
const aliceKeypair = new driver.Ed25519Keypair()
return bdbOrm.myModel
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
return bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: expected
})
.then(asset => bdbOrm.myModel.retrieve(asset.id))
.then(asset => bdbOrm.models.myModel.retrieve(asset.id))
.then(res => t.deepEqual(res[0].data, expected))
})

Expand All @@ -49,14 +48,14 @@ test('Append asset', t => {
newKey: 'newDataValue'
}

const bdbOrm = new Orm('http://127.0.0.1:9984/api/v1/', {
const bdbOrm = new Orm('http://localhost:9984/api/v1/', {
app_id: '',
app_key: ''
})
bdbOrm.define('myModel', 'https://schema.org/v1/myModel')
// create a public and private key for Alice
const aliceKeypair = new driver.Ed25519Keypair()
return bdbOrm.myModel
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
return bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue', keyToUpdate: 'dataUpdatableValue' }
Expand All @@ -75,14 +74,14 @@ test('Append asset', t => {
test('Burn asset', t => {
const expected = { key: 'dataValue', status: 'BURNED' }

const bdbOrm = new Orm('http://127.0.0.1:9984/api/v1/', {
const bdbOrm = new Orm('http://localhost:9984/api/v1/', {
app_id: '',
app_key: ''
})
bdbOrm.define('myModel', 'https://schema.org/v1/myModel')
// create a public and private key for Alice
const aliceKeypair = new driver.Ed25519Keypair()
return bdbOrm.myModel
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
return bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
Expand Down

0 comments on commit 8bd9e06

Please sign in to comment.