Skip to content

Commit 640e6de

Browse files
Timur Minulinpaveltiunov
authored andcommitted
feat: Angular client (#99)
* 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
1 parent e026560 commit 640e6de

18 files changed

Lines changed: 37611 additions & 16 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ package-lock.json
88
examples/examples-gallery/build
99
yarn-error.log
1010
.gh-token
11-
.serverless/
11+
.serverless/
12+
.rpt2_cache/
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: '@cubejs-client/ngx'
3+
permalink: /@cubejs-client-ngx
4+
category: Cube.js Frontend
5+
subCategory: Reference
6+
menuOrder: 5
7+
---
8+
9+
`@cubejs-client/ngx` provides Angular Module for easy integration Cube.js
10+
into an Angular app.
11+
12+
## Installation
13+
14+
First, install `@cubejs-client/ngx` using npm or yarn:
15+
16+
```bash
17+
$ npm install --save @cubejs-client/ngx
18+
# or
19+
$ yarn add @cubejs-client/ngx
20+
```
21+
22+
Now you can add `CubejsClientModule` to your **app.module.ts** file:
23+
24+
```typescript
25+
import { CubejsClientModule } from '@cubejs-client/ngx';
26+
import { environment } from '../../environments/environment';
27+
28+
const cubejsOptions = {
29+
token: environment.CUBEJS_API_TOKEN,
30+
options: { apiUrl: environment.CUBEJS_API_URL }
31+
};
32+
33+
@NgModule({
34+
declarations: [
35+
...
36+
],
37+
imports: [
38+
...,
39+
CubejsClientModule.forRoot(cubejsOptions)
40+
],
41+
providers: [...],
42+
bootstrap: [...]
43+
})
44+
export class AppModule { }
45+
```
46+
47+
The `options` object is passed directly to [@cubejs-client/core](/@cubejs-client-core).
48+
49+
`CubejsClientModule` provides `CubejsClient`, which you can inject into your components or services:
50+
51+
```typescript
52+
import { CubejsClient } from '@cubejs-client/ngx';
53+
54+
export class AppComponent {
55+
constructor(private cubejs:CubejsClient){}
56+
57+
ngOnInit(){
58+
this.cubejs.load({
59+
measures: ["some_measure"]
60+
}).subscribe(
61+
resultSet => {
62+
this.data = resultSet.chartPivot();
63+
},
64+
err => console.log('HTTP Error', err)
65+
);
66+
}
67+
}
68+
```
69+
70+
## API
71+
72+
`CubejsClient` provides the same API methods as [@cubejs-client/core](/@cubejs-client-core#cubejs-api).
73+
The difference is that instead of Promise it returns an [Observable](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html),
74+
which passes [resultSet](/@cubejs-client-core#result-set) into callback function.
75+
76+
Also you can use [RxJS Subject](https://rxjs-dev.firebaseapp.com/guide/subject) with a query using `watch` method:
77+
78+
```typescript
79+
private query;
80+
81+
ngOnInit() {
82+
this.query = new Subject();
83+
this.cubejs.watch(this.query).subscribe(
84+
resultSet => {
85+
console.log(resultSet.chartPivot()[0].x);
86+
console.log(resultSet.seriesNames()[0]);
87+
},
88+
err => console.log('HTTP Error', err)
89+
);
90+
}
91+
92+
button1ClickHandler() {
93+
this.query.next({ query_1 });
94+
}
95+
96+
button2ClickHandler() {
97+
this.query.next({ query_2 });
98+
}
99+
```
100+

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@
3030
"babelrc-rollup": "^3.0.0",
3131
"http-server": "^0.11.1",
3232
"lerna": "^3.13.1",
33-
"rollup": "^0.65.2",
33+
"rollup": "^0.68",
3434
"rollup-plugin-alias": "^1.4.0",
3535
"rollup-plugin-babel": "^4.0.3",
3636
"rollup-plugin-commonjs": "^9.1.6",
3737
"rollup-plugin-node-resolve": "^4.2.3",
3838
"rollup-plugin-replace": "^2.0.0",
39-
"rollup-plugin-uglify": "^5.0.2"
39+
"rollup-plugin-typescript": "^1.0.1",
40+
"rollup-plugin-uglify": "^5.0.2",
41+
"tslib": "^1.9.3",
42+
"typescript": "^3.4.5"
4043
},
4144
"repository": {
42-
"type" : "git",
43-
"url" : "https://github.com/statsbotco/cube.js.git"
45+
"type": "git",
46+
"url": "https://github.com/statsbotco/cube.js.git"
4447
},
4548
"license": "MIT"
4649
}

packages/cubejs-client-ngx/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Statsbot, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Cube.js Angular Client
2+
3+
Cube.js Angular is an Angular Module for Angular 6+.
4+
5+
[Learn more](https://github.com/statsbotco/cube.js#getting-started)
6+
7+
### License
8+
9+
Cube.js React is [MIT licensed](./LICENSE).
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { Injectable, Inject, NgModule } from '@angular/core';
2+
import { from, Observable } from 'rxjs';
3+
import cubejs from '@cubejs-client/core';
4+
5+
/*! *****************************************************************************
6+
Copyright (c) Microsoft Corporation. All rights reserved.
7+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
8+
this file except in compliance with the License. You may obtain a copy of the
9+
License at http://www.apache.org/licenses/LICENSE-2.0
10+
11+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
14+
MERCHANTABLITY OR NON-INFRINGEMENT.
15+
16+
See the Apache Version 2.0 License for specific language governing permissions
17+
and limitations under the License.
18+
***************************************************************************** */
19+
20+
function __decorate(decorators, target, key, desc) {
21+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
22+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
23+
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;
24+
return c > 3 && r && Object.defineProperty(target, key, r), r;
25+
}
26+
27+
function __param(paramIndex, decorator) {
28+
return function (target, key) { decorator(target, key, paramIndex); }
29+
}
30+
31+
function __metadata(metadataKey, metadataValue) {
32+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
33+
}
34+
35+
function __awaiter(thisArg, _arguments, P, generator) {
36+
return new (P || (P = Promise))(function (resolve, reject) {
37+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
40+
step((generator = generator.apply(thisArg, _arguments || [])).next());
41+
});
42+
}
43+
44+
let CubejsClient = class CubejsClient {
45+
constructor(config) {
46+
this.config = config;
47+
}
48+
apiInstace() {
49+
if (!this.cubeJsApi) {
50+
this.cubeJsApi = cubejs(this.config.token, this.config.options);
51+
}
52+
return this.cubeJsApi;
53+
}
54+
load(...params) {
55+
return from(this.apiInstace().load(...params));
56+
}
57+
sql(...params) {
58+
return from(this.apiInstace().sql(...params));
59+
}
60+
meta(...params) {
61+
return from(this.apiInstace().meta(...params));
62+
}
63+
watch(query, params = {}) {
64+
return Observable.create(observer => query.subscribe({
65+
next: (query) => __awaiter(this, void 0, void 0, function* () {
66+
const resultSet = yield this.apiInstace().load(query, params);
67+
observer.next(resultSet);
68+
})
69+
}));
70+
}
71+
};
72+
CubejsClient = __decorate([
73+
Injectable(),
74+
__param(0, Inject('config')),
75+
__metadata("design:paramtypes", [Object])
76+
], CubejsClient);
77+
78+
var CubejsClientModule_1;
79+
let CubejsClientModule = CubejsClientModule_1 = class CubejsClientModule {
80+
static forRoot(config) {
81+
return {
82+
ngModule: CubejsClientModule_1,
83+
providers: [
84+
CubejsClient,
85+
{
86+
provide: 'config',
87+
useValue: config
88+
}
89+
]
90+
};
91+
}
92+
};
93+
CubejsClientModule = CubejsClientModule_1 = __decorate([
94+
NgModule({
95+
providers: [CubejsClient]
96+
})
97+
], CubejsClientModule);
98+
99+
/*
100+
* Public API Surface of cubejs-client-ngx
101+
*/
102+
103+
// This file is not used to build this module. It is only used during editing
104+
105+
export { CubejsClientModule, CubejsClient };
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, '__esModule', { value: true });
4+
5+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6+
7+
var core = require('@angular/core');
8+
var rxjs = require('rxjs');
9+
var cubejs = _interopDefault(require('@cubejs-client/core'));
10+
11+
/*! *****************************************************************************
12+
Copyright (c) Microsoft Corporation. All rights reserved.
13+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
14+
this file except in compliance with the License. You may obtain a copy of the
15+
License at http://www.apache.org/licenses/LICENSE-2.0
16+
17+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
19+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
20+
MERCHANTABLITY OR NON-INFRINGEMENT.
21+
22+
See the Apache Version 2.0 License for specific language governing permissions
23+
and limitations under the License.
24+
***************************************************************************** */
25+
26+
function __decorate(decorators, target, key, desc) {
27+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29+
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;
30+
return c > 3 && r && Object.defineProperty(target, key, r), r;
31+
}
32+
33+
function __param(paramIndex, decorator) {
34+
return function (target, key) { decorator(target, key, paramIndex); }
35+
}
36+
37+
function __metadata(metadataKey, metadataValue) {
38+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
39+
}
40+
41+
function __awaiter(thisArg, _arguments, P, generator) {
42+
return new (P || (P = Promise))(function (resolve, reject) {
43+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
46+
step((generator = generator.apply(thisArg, _arguments || [])).next());
47+
});
48+
}
49+
50+
exports.CubejsClient = class CubejsClient {
51+
constructor(config) {
52+
this.config = config;
53+
}
54+
apiInstace() {
55+
if (!this.cubeJsApi) {
56+
this.cubeJsApi = cubejs(this.config.token, this.config.options);
57+
}
58+
return this.cubeJsApi;
59+
}
60+
load(...params) {
61+
return rxjs.from(this.apiInstace().load(...params));
62+
}
63+
sql(...params) {
64+
return rxjs.from(this.apiInstace().sql(...params));
65+
}
66+
meta(...params) {
67+
return rxjs.from(this.apiInstace().meta(...params));
68+
}
69+
watch(query, params = {}) {
70+
return rxjs.Observable.create(observer => query.subscribe({
71+
next: (query) => __awaiter(this, void 0, void 0, function* () {
72+
const resultSet = yield this.apiInstace().load(query, params);
73+
observer.next(resultSet);
74+
})
75+
}));
76+
}
77+
};
78+
exports.CubejsClient = __decorate([
79+
core.Injectable(),
80+
__param(0, core.Inject('config')),
81+
__metadata("design:paramtypes", [Object])
82+
], exports.CubejsClient);
83+
84+
var CubejsClientModule_1;
85+
exports.CubejsClientModule = CubejsClientModule_1 = class CubejsClientModule {
86+
static forRoot(config) {
87+
return {
88+
ngModule: CubejsClientModule_1,
89+
providers: [
90+
exports.CubejsClient,
91+
{
92+
provide: 'config',
93+
useValue: config
94+
}
95+
]
96+
};
97+
}
98+
};
99+
exports.CubejsClientModule = CubejsClientModule_1 = __decorate([
100+
core.NgModule({
101+
providers: [exports.CubejsClient]
102+
})
103+
], exports.CubejsClientModule);
104+
105+
/*
106+
* Public API Surface of cubejs-client-ngx
107+
*/
108+
109+
// This file is not used to build this module. It is only used during editing

0 commit comments

Comments
 (0)