-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 434b3c3
Showing
128 changed files
with
9,296 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
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 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 |
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,165 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"mocha": true, | ||
"es6": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-duplicate-case": 2, | ||
"no-undef": 2, | ||
"no-unused-vars": [ | ||
2, | ||
{ | ||
"vars": "all", | ||
"args": "after-used" | ||
} | ||
], | ||
"no-empty": [ | ||
2, | ||
{ | ||
"allowEmptyCatch": true | ||
} | ||
], | ||
"no-implicit-coercion": [ | ||
2, | ||
{ | ||
"boolean": true, | ||
"string": true, | ||
"number": true | ||
} | ||
], | ||
"no-with": 2, | ||
"brace-style": 2, | ||
"no-mixed-spaces-and-tabs": 2, | ||
"no-multiple-empty-lines": 2, | ||
"no-multi-str": 2, | ||
"dot-location": [ | ||
2, | ||
"property" | ||
], | ||
"operator-linebreak": [ | ||
2, | ||
"after", | ||
{ | ||
"overrides": { | ||
"?": "before", | ||
":": "before" | ||
} | ||
} | ||
], | ||
"key-spacing": [ | ||
2, | ||
{ | ||
"beforeColon": false, | ||
"afterColon": true | ||
} | ||
], | ||
"space-unary-ops": [ | ||
2, | ||
{ | ||
"words": false, | ||
"nonwords": false | ||
} | ||
], | ||
"no-spaced-func": 2, | ||
"space-before-function-paren": [ | ||
2, | ||
{ | ||
"anonymous": "ignore", | ||
"named": "never" | ||
} | ||
], | ||
"array-bracket-spacing": [ | ||
2, | ||
"never" | ||
], | ||
"space-in-parens": [ | ||
2, | ||
"never" | ||
], | ||
"comma-dangle": [ | ||
2, | ||
"never" | ||
], | ||
"no-trailing-spaces": 2, | ||
"yoda": [ | ||
2, | ||
"never" | ||
], | ||
"camelcase": [ | ||
2, | ||
{ | ||
"properties": "never" | ||
} | ||
], | ||
"comma-style": [ | ||
2, | ||
"last" | ||
], | ||
"curly": [ | ||
2, | ||
"all" | ||
], | ||
"dot-notation": 2, | ||
"eol-last": 2, | ||
"one-var": [ | ||
2, | ||
"never" | ||
], | ||
"wrap-iife": 2, | ||
"space-infix-ops": 2, | ||
"keyword-spacing": [ | ||
2, | ||
{ | ||
"overrides": { | ||
"else": { | ||
"before": true | ||
}, | ||
"while": { | ||
"before": true | ||
}, | ||
"catch": { | ||
"before": true | ||
}, | ||
"finally": { | ||
"before": true | ||
} | ||
} | ||
} | ||
], | ||
"spaced-comment": [ | ||
2, | ||
"always" | ||
], | ||
"space-before-blocks": [ | ||
2, | ||
"always" | ||
], | ||
"semi": [ | ||
2, | ||
"always" | ||
], | ||
"indent": [ | ||
2, | ||
4, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"linebreak-style": [ | ||
2, | ||
"unix" | ||
], | ||
"quotes": [ | ||
2, | ||
"single", | ||
{ | ||
"avoidEscape": true | ||
} | ||
] | ||
} | ||
} |
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,6 @@ | ||
/node_modules/ | ||
/.vscode/ | ||
/.idea/ | ||
/tmp/ | ||
/build/ | ||
/coverage/ |
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,3 @@ | ||
## 1.0.0-beta.1 (25-11-2018) | ||
|
||
- First public release |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Avito Technology | ||
|
||
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,162 @@ | ||
# Discovery | ||
|
||
Hackable graph discovery tool | ||
|
||
## Install | ||
|
||
``` | ||
> npm install @avito/discovery | ||
``` | ||
|
||
## How to run | ||
|
||
``` | ||
> node node_modules/.bin/discovery | ||
``` | ||
|
||
Or add to your `package.json`: | ||
|
||
```json | ||
"scripts": { | ||
"discovery": "discovery" | ||
} | ||
``` | ||
|
||
After that `discovery` command will be available inside a project folder: | ||
|
||
``` | ||
> discovery | ||
``` | ||
|
||
## Modes | ||
|
||
Discovery can work in three modes: | ||
|
||
* Model-free | ||
* Multiple models | ||
* Single model | ||
|
||
### Model-free | ||
|
||
In this mode you can upload any data by clicking "Load data" button, or drag'n'drop file right into the browser, | ||
|
||
### Multiple models | ||
|
||
In this mode discovery will start with model selection page. Every model will have own route namespace, and you can switch models and reports at any time. | ||
|
||
### Single model | ||
|
||
If you want only one model, you should start discovery with `--model %modelName%`. In this mode index page will represent your model default page. | ||
|
||
## Define models | ||
|
||
To configure discovery you should specify one of config files: | ||
|
||
* `.discoveryrc.js` | ||
* `.discoveryrc.json` | ||
|
||
Or you can use `discovery` key in your `package.json` file. | ||
|
||
### Config structure | ||
|
||
Config should provide JSON or export js-object with following properties: | ||
|
||
* `name` - name of discovery instance (used in title) | ||
* `models` - object with model configuration, where key used as model slug and value - model config | ||
|
||
Example: | ||
```js | ||
module.exports = { | ||
name: 'discovery', | ||
models: { | ||
one: { ...modelConfig... }, | ||
two: { ...modelConfig... } | ||
} | ||
}; | ||
``` | ||
|
||
## Define model | ||
|
||
Model config consists of the following fields: | ||
|
||
* `name` - name of model (used in title) | ||
* `data` - function which returns `any|Promise<any>`. Result of this function must be JSON serializable | ||
* `prepare` - path to a file with additional initialization logic. (eg. add cyclic links and relations. extensions for query engine) | ||
* `ui` object with following fields: | ||
* `basedir` - directory to resolve relative path in `assets` | ||
* `assets` - path to `.js` and `.css` files | ||
> js files has own scope (as modules) which have reference to `discovery` instance | ||
* `extendRouter` - `function(router, modelConfig, options)` | ||
|
||
## Base concepts | ||
|
||
**Model** goes through `data->prepare->render` chain. Data can be modified with prepare function and rendered by various views and its combinations. | ||
|
||
**View** is a function(el, config, data, context) where: | ||
|
||
* `el` - DOM-element in which view will be rendered | ||
* `config` - configuration of view | ||
* `data` - data to render | ||
* `context` - contains of model data, metaifo (createdAt, etc), router (optional), any user defined or view defined additional data | ||
|
||
**Page** is a root view function(el, data, context). Similar to view it has all of its arguments except config. | ||
|
||
### Page | ||
|
||
To define page you should call `discovery.page.define(pageId, render(el, data, context), options)` where: | ||
|
||
* `pageId` - unique page identifier | ||
* `render` - page render function described above | ||
* `options` - object with options: | ||
* `reuseEl` - do not clear container before render page (skiped for first render or pageId change) | ||
* `init` - invokes on first page render or pageId change | ||
* `keepScrollOffset` - dont scroll to page top if `pageId` didn't changed since last page render | ||
|
||
Other handy methods for working with page: | ||
|
||
* `discovery.renderPage()` `renderId, renderRef, renderParams` | ||
* `setPage(pageId, pageRef, renderParams)` or `setPageParams(renderParams)` triggers `renderPage()` | ||
* `discovery.getPageContext()` gets context of page | ||
|
||
### Special pages | ||
|
||
There are some built-in special pages: | ||
|
||
* `default` | ||
* `report` | ||
* `not-found` | ||
|
||
you can override this pages with `definePage` | ||
|
||
### View | ||
|
||
To define new view just call `discovery.view.define(viewId, render, options)` where: | ||
* `viewId` - unique view identifier | ||
|
||
* `render` - function(el, config, data, context) or view definition object | ||
* `options` - object with following fields: | ||
`tag` - container element. if `false|null` view will return `documentFragment` | ||
|
||
You can render your view with `discovery.view.render(el, view, data, context)` where: | ||
|
||
* `view` can be string `viewId`, `ViewDefinition` or `Array<ViewDefinition>` viewId will expand to `{ view: viewId }`. | ||
> Also you can specify `view` as `viewId:query`, that will give you handy shortcut to `{ view: viewId, data: query }` | ||
* `viewDefinition` object with view definition settings: | ||
* `view`: string `viewId` | ||
* `when`: query, will be coerced to Boolean (but empty arrays and objects will coerce to `false`) | ||
* `data`: query (will be described later) | ||
* Also there can be view specific additional fields | ||
|
||
### Special views | ||
|
||
Also specail built-in `sidebar` view is available you can override this view with `view.define` | ||
|
||
### Queries | ||
|
||
As a query you can specify string which will be processed by jora so your data will be a result of following flow: | ||
|
||
``` | ||
jora(value) -> function(data, context) -> data | ||
``` | ||
|
||
Or you can use `function(data, context)` as query as well. Aslo you can use any data as query right away. |
Oops, something went wrong.