-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
e026560
commit 640e6de
Showing
18 changed files
with
37,611 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ package-lock.json | |
examples/examples-gallery/build | ||
yarn-error.log | ||
.gh-token | ||
.serverless/ | ||
.serverless/ | ||
.rpt2_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
105
packages/cubejs-client-ngx/dist/cubejs-client-ngx.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.