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
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would just enumurate these in a single alphabetical list as it’s easier to process and maintain.

logs/
*.log

# Cache
.eslintcache
.idea
.npm
.yarnclean

# Directories
coverage/
esm/
lib/
build/
node_modules/
_gh-pages/

# Custom
*.min.js
*.map

# Configs, these are auto-generated by beemo and should therefore be ignored
.babelrc
.eslintignore
.eslintrc.js
.prettierignore
jest.config.js
prettier.config.js
# @TODO webpack.config.js when this driver is added
Empty file added CHANGELOG.md
Empty file.
9 changes: 9 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
💔 Breaking Changes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be added to the .github folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe! I'll give it a shot


🏆 Enhancements

📜 Documentation

🐛 Bug Fix

🏠 Internal
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

##### Query aborting

Query 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({}).then(...).catch(...);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it cancel every outgoing request? Is there a way to cancel just one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops I forgot an important part of this usage (I'll update), you pass the signal to the request, so it's per-request aborting.

see here for an example in superset.

}
```

### 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