Skip to content

Commit

Permalink
feat: Angular client (#99)
Browse files Browse the repository at this point in the history
* add Angular package

* try to setup build

* Add package mappings

* Temporary remove additional mappings because rollup build is not working

* add ngx description

* feat: angular watch

* fix: ng watch example fixed

* Angular build fix

* working build

* don't commit other builds
  • Loading branch information
Timur Minulin authored and paveltiunov committed May 2, 2019
1 parent e026560 commit 640e6de
Show file tree
Hide file tree
Showing 18 changed files with 37,611 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ package-lock.json
examples/examples-gallery/build
yarn-error.log
.gh-token
.serverless/
.serverless/
.rpt2_cache/
100 changes: 100 additions & 0 deletions docs/Cube.js-Frontend/@cubejs-client-ngx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: '@cubejs-client/ngx'
permalink: /@cubejs-client-ngx
category: Cube.js Frontend
subCategory: Reference
menuOrder: 5
---

`@cubejs-client/ngx` provides Angular Module for easy integration Cube.js
into an Angular app.

## Installation

First, install `@cubejs-client/ngx` using npm or yarn:

```bash
$ npm install --save @cubejs-client/ngx
# or
$ yarn add @cubejs-client/ngx
```

Now you can add `CubejsClientModule` to your **app.module.ts** file:

```typescript
import { CubejsClientModule } from '@cubejs-client/ngx';
import { environment } from '../../environments/environment';

const cubejsOptions = {
token: environment.CUBEJS_API_TOKEN,
options: { apiUrl: environment.CUBEJS_API_URL }
};

@NgModule({
declarations: [
...
],
imports: [
...,
CubejsClientModule.forRoot(cubejsOptions)
],
providers: [...],
bootstrap: [...]
})
export class AppModule { }
```

The `options` object is passed directly to [@cubejs-client/core](/@cubejs-client-core).

`CubejsClientModule` provides `CubejsClient`, which you can inject into your components or services:

```typescript
import { CubejsClient } from '@cubejs-client/ngx';

export class AppComponent {
constructor(private cubejs:CubejsClient){}

ngOnInit(){
this.cubejs.load({
measures: ["some_measure"]
}).subscribe(
resultSet => {
this.data = resultSet.chartPivot();
},
err => console.log('HTTP Error', err)
);
}
}
```

## API

`CubejsClient` provides the same API methods as [@cubejs-client/core](/@cubejs-client-core#cubejs-api).
The difference is that instead of Promise it returns an [Observable](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html),
which passes [resultSet](/@cubejs-client-core#result-set) into callback function.

Also you can use [RxJS Subject](https://rxjs-dev.firebaseapp.com/guide/subject) with a query using `watch` method:

```typescript
private query;

ngOnInit() {
this.query = new Subject();
this.cubejs.watch(this.query).subscribe(
resultSet => {
console.log(resultSet.chartPivot()[0].x);
console.log(resultSet.seriesNames()[0]);
},
err => console.log('HTTP Error', err)
);
}

button1ClickHandler() {
this.query.next({ query_1 });
}

button2ClickHandler() {
this.query.next({ query_2 });
}
```

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
"babelrc-rollup": "^3.0.0",
"http-server": "^0.11.1",
"lerna": "^3.13.1",
"rollup": "^0.65.2",
"rollup": "^0.68",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^5.0.2"
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-uglify": "^5.0.2",
"tslib": "^1.9.3",
"typescript": "^3.4.5"
},
"repository": {
"type" : "git",
"url" : "https://github.com/statsbotco/cube.js.git"
"type": "git",
"url": "https://github.com/statsbotco/cube.js.git"
},
"license": "MIT"
}
21 changes: 21 additions & 0 deletions packages/cubejs-client-ngx/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Statsbot, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions packages/cubejs-client-ngx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cube.js Angular Client

Cube.js Angular is an Angular Module for Angular 6+.

[Learn more](https://github.com/statsbotco/cube.js#getting-started)

### License

Cube.js React is [MIT licensed](./LICENSE).
105 changes: 105 additions & 0 deletions packages/cubejs-client-ngx/dist/cubejs-client-ngx.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Injectable, Inject, NgModule } from '@angular/core';
import { from, Observable } from 'rxjs';
import cubejs from '@cubejs-client/core';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. 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
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}

function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}

function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}

function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}

let CubejsClient = class CubejsClient {
constructor(config) {
this.config = config;
}
apiInstace() {
if (!this.cubeJsApi) {
this.cubeJsApi = cubejs(this.config.token, this.config.options);
}
return this.cubeJsApi;
}
load(...params) {
return from(this.apiInstace().load(...params));
}
sql(...params) {
return from(this.apiInstace().sql(...params));
}
meta(...params) {
return from(this.apiInstace().meta(...params));
}
watch(query, params = {}) {
return Observable.create(observer => query.subscribe({
next: (query) => __awaiter(this, void 0, void 0, function* () {
const resultSet = yield this.apiInstace().load(query, params);
observer.next(resultSet);
})
}));
}
};
CubejsClient = __decorate([
Injectable(),
__param(0, Inject('config')),
__metadata("design:paramtypes", [Object])
], CubejsClient);

var CubejsClientModule_1;
let CubejsClientModule = CubejsClientModule_1 = class CubejsClientModule {
static forRoot(config) {
return {
ngModule: CubejsClientModule_1,
providers: [
CubejsClient,
{
provide: 'config',
useValue: config
}
]
};
}
};
CubejsClientModule = CubejsClientModule_1 = __decorate([
NgModule({
providers: [CubejsClient]
})
], CubejsClientModule);

/*
* Public API Surface of cubejs-client-ngx
*/

// This file is not used to build this module. It is only used during editing

export { CubejsClientModule, CubejsClient };
109 changes: 109 additions & 0 deletions packages/cubejs-client-ngx/dist/cubejs-client-ngx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var core = require('@angular/core');
var rxjs = require('rxjs');
var cubejs = _interopDefault(require('@cubejs-client/core'));

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. 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
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}

function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}

function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}

function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}

exports.CubejsClient = class CubejsClient {
constructor(config) {
this.config = config;
}
apiInstace() {
if (!this.cubeJsApi) {
this.cubeJsApi = cubejs(this.config.token, this.config.options);
}
return this.cubeJsApi;
}
load(...params) {
return rxjs.from(this.apiInstace().load(...params));
}
sql(...params) {
return rxjs.from(this.apiInstace().sql(...params));
}
meta(...params) {
return rxjs.from(this.apiInstace().meta(...params));
}
watch(query, params = {}) {
return rxjs.Observable.create(observer => query.subscribe({
next: (query) => __awaiter(this, void 0, void 0, function* () {
const resultSet = yield this.apiInstace().load(query, params);
observer.next(resultSet);
})
}));
}
};
exports.CubejsClient = __decorate([
core.Injectable(),
__param(0, core.Inject('config')),
__metadata("design:paramtypes", [Object])
], exports.CubejsClient);

var CubejsClientModule_1;
exports.CubejsClientModule = CubejsClientModule_1 = class CubejsClientModule {
static forRoot(config) {
return {
ngModule: CubejsClientModule_1,
providers: [
exports.CubejsClient,
{
provide: 'config',
useValue: config
}
]
};
}
};
exports.CubejsClientModule = CubejsClientModule_1 = __decorate([
core.NgModule({
providers: [exports.CubejsClient]
})
], exports.CubejsClientModule);

/*
* Public API Surface of cubejs-client-ngx
*/

// This file is not used to build this module. It is only used during editing

0 comments on commit 640e6de

Please sign in to comment.