Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

[SIP-4] add lerna monorepo and@superset-ui/core package with SupersetClient #1

Merged
merged 11 commits into from
Sep 8, 2018
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
💔 Breaking Changes

🏆 Enhancements

📜 Documentation

🐛 Bug Fix

🏠 Internal
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.babelrc
.eslintcache
.eslintignore
.eslintrc.js
.idea
.npm
.prettierignore
.yarnclean

*.log
*.map
*.min.js

build/
coverage/
esm/
jest.config.js
lib/
logs/
node_modules/
prettier.config.js
Empty file added CHANGELOG.md
Empty file.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# `@superset-ui`

Collection of packages that power the Apache Superset UI, and can be used to craft custom data
applications that leverage a Superset backend :chart_with_upwards_trend:

## Packages

[@superset-ui/core](https://github.com/apache-superset/superset-ui/tree/master/packages/superset-ui-core)
[![Version](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat)

#### Coming :soon:

- Data providers
- Embeddable charts
- Chart collections
- Demo storybook package

### Development

[lerna](https://github.com/lerna/lerna/) is used to manage versions and dependencies between
packages in this monorepo.

```
superset-ui/
lerna.json
package.json
...
packages/
package1/
package.json
...
src/
test/
...
lib/
esm/
...
...
```

For easiest development

1. clone this repo
2. install the root npm modules including lerna and yarn
3. have lerna install package dependencies and manage the symlinking between packages for you

```sh
git clone ...superset-ui && cd superset-ui
npm install
lerna bootstrap
```

### Builds, linting, and testing

Each package defines its own build config, linting, and testing. You can have lerna run commands
across all packages using the syntax `lerna exec test` from the root `@superset/monorepo` root
directory.

### License

Apache-2.0
5 changes: 5 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lerna": "3.2.1",
"packages": ["packages/*"],
"version": "0.0.0"
}
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@superset-ui/monorepo",
"version": "0.0.0",
"description": "Superset UI",
"private": true,
"scripts": {
"build": "lerna run build",
"jest": "lerna run test",
"lint": "lerna run lint",
"prerelease": "yarn run build",
"prepare-release": "git checkout master && git pull --rebase origin master && yarn run test",
"release": "yarn run prepare-release && lerna publish && lerna run gh-pages",
"test": "lerna bootstrap && yarn run lint && yarn run jest"
},
"repository": "https://github.com/apache-superset/superset-ui.git",
"keywords": [
"apache",
"superset",
"data",
"analytics",
"analysis",
"visualization",
"react",
"d3",
"data-ui",
"vx"
],
"license": "Apache-2.0",
"devDependencies": {
"lerna": "^3.2.1",
"yarn": "^1.9.4"
},
"engines": {
"node": ">=8.10.0"
},
"publishConfig": {
"access": "public"
}
}
90 changes: 90 additions & 0 deletions packages/superset-ui-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
## `@superset-ui/core`

[![Version](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat)

Core modules for Superset:

- `SupersetClient` requests and authentication
- (future) `i18n` locales and translation

### SupersetClient

The `SupersetClient` handles all client-side requests to the Superset backend. It can be configured
for use within the Superset application, or used to issue `CORS` requests in other applications. At
a high-level it supports:

- `CSRF` token authentication
- queues requests in the case that another request is made before the token is received
- it checks for a token before every request, an external app that uses this can detect this by
catching errors, or explicitly checking `SupersetClient.isAuthorized()`
- supports `GET` and `POST` requests (no `PUT` or `DELETE`)
- timeouts
- query aborts through the `AbortController` API

#### Example usage

```javascript
// appSetup.js
import { SupersetClient } from `@superset-ui/core`;
// or import SupersetClient from `@superset-ui/core/lib|esm/SupersetClient`;

SupersetClient.configure(...clientConfig);
SupersetClient.init(); // CSRF auth, can also chain `.configure().init();

// anotherFile.js
import { SupersetClient } from `@superset-ui/core`;

SupersetClient.post(...requestConfig)
.then(({ request, json }) => ...)
.catch((error) => ...);
```

#### API

##### Client Configuration

The following flags can be passed in the client config call
`SupersetClient.configure(...clientConfig);`

- `protocol = 'http'`
- `host`
- `headers`
- `credentials = 'same-origin'` (set to `include` for non-Superset apps)
- `mode = 'same-origin'` (set to `cors` for non-Superset apps)
- `timeout`

##### Per-request Configuration

The following flags can be passed on a per-request call `SupersetClient.get/post(...requestConfig);`

- `url` or `endpoint`
- `headers`
- `body`
- `timeout`
- `signal` (for aborting, from `const { signal } = (new AbortController())`)
- for `POST` requests
- `postPayload` (key values are added to a `new FormData()`)
- `stringify` whether to call `JSON.stringify` on `postPayload` values

##### Request aborting

Per-request aborting is implemented through the `AbortController` API:

```javascript
import { SupersetClient } from '@superset-ui/core';
import AbortController from 'abortcontroller-polyfill';

const controller = new AbortController();
const { signal } = controller;

SupersetClient.get({ ..., signal }).then(...).catch(...);

if (IWantToCancelForSomeReason) {
signal.abort(); // Promise is rejected, request `catch` is invoked
}
```

### Development

`@data-ui/build-config` is used to manage the build configuration for this package including babel
builds, jest testing, eslint, and prettier.
73 changes: 73 additions & 0 deletions packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"name": "@superset-ui/core",
"version": "0.0.0",
"description": "Superset UI core 🤖",
"sideEffects": false,
"main": "lib/index.js",
"module": "esm/index.js",
"files": [
"esm",
"lib"
],
"scripts": {
"build:cjs": "beemo babel ./src --out-dir lib/ --minify",
"build:esm": "beemo babel ./src --out-dir esm/ --esm --minify",
"build": "yarn run build:cjs && yarn run build:esm",
"dev": "beemo babel --watch ./src --out-dir esm/ --esm",
"jest": "beemo jest --color --coverage",
"eslint": "beemo eslint \"./{src,test}/**/*.{js,jsx,json,md}\"",
"lint": "yarn run prettier --write && yarn run eslint --fix",
"test": "yarn run jest",
"prettier": "beemo prettier \"./{src,test}/**/*.{js,jsx,json,md}\"",
"sync:gitignore": "beemo sync-dotfiles --filter=gitignore",
"prepublish": "yarn run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/apache-superset/superset-ui.git"
},
"keywords": [
"superset",
"client",
"core",
"data"
],
"author": "",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/apache-superset/superset-ui/issues"
},
"homepage": "https://github.com/apache-superset/superset-ui#readme",
"devDependencies": {
"@data-ui/build-config": "0.0.10",
"fetch-mock": "^6.5.2"
},
"dependencies": {
"url-search-params-polyfill": "^4.0.1",
"whatwg-fetch": "^2.0.4"
},
"beemo": {
"module": "@data-ui/build-config",
"drivers": [
"babel",
"eslint",
{
"driver": "jest",
"env": {
"NODE_ENV": "test"
}
},
"prettier"
],
"eslint": {
"rules": {
"prefer-promise-reject-errors": "off"
}
},
"jest": {
"testPathIgnorePatterns": [
"node_modules"
]
}
}
}
Loading