Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datastore): shorten version hash length
- Loading branch information
1 parent
e56a24d
commit 0e36ead
Showing
19 changed files
with
196 additions
and
80 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
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 |
---|---|---|
@@ -1,68 +1,72 @@ | ||
# Datastore | ||
# Introduction | ||
|
||
Datastore is a simple wrapper for your scraper script that converts it into a discrete, composable, and deployable unit. | ||
> Datastores are deployable "databases" that have functions and tables, support native payment, and can be cloned and expanded as you see fit. Datastore Functions contain data retrieval functions, like Hero scraper scripts, with structured input and output. Deploying a Datastore provides you with a structured Data API that can be privately consumed, or sold "out of the box". | ||
- [x] **Production Proof Your Script** - Production proof your script a thousand different ways. | ||
- [x] **Breaking Notifications** - Get notified when your scripts break. | ||
- [x] **Runs Anywhere** - Containerize your scripts to run everywhere. | ||
- [x] **Works with Chrome Alive!** - Progressively build your scripts with Chrome Alive! | ||
- [x] **Easy Management** - Manage your datastores like a boss. | ||
## What is a Datastore? | ||
|
||
## Installation | ||
Datastores create databases of specialized data structures - for instance, a Travel database, or a Jobs database. They're a combination of static metadata tables, dynamically retrieved web data and cached aggregated data that make up a data category. They support payment out of the box, so a client can pay per query without any setup or contracts. Datastores also support PostgreSQL natively (including payment), so can be tested out and integrated across programming languages. | ||
|
||
```shell script | ||
npm install @ulixee/datastore-plugins-hero | ||
``` | ||
## Datastore Functions | ||
|
||
or | ||
Datastore Functions create structure -- boundaries -- around a single "scrape", which make your scripts are far easier to test, re-try, scale and compose. It allows us to do things like: | ||
|
||
```shell script | ||
yarn add @ulixee/datastore-plugins-hero | ||
``` | ||
- Restart a script during development as you change it. | ||
- Rotate inputs to try out a variety of IPs, parameters, and more to make sure you can handle edge cases. | ||
- Test the extraction of 100s of different potential results pages and ensure your Output follows the same structure. | ||
- Spawn new Functions from the current one if you need to parallelize following links. | ||
|
||
## Usage | ||
## Datastore Crawlers | ||
|
||
Wrapping your script in a Datastore gives it instant access to the input and output objects, along with a Hero instance: | ||
Datastore Crawlers allow you to write specialized Functions that only output a "cached" scrape. It comes with built-in caching, so you can automatically re-use results that have been recently recorded. | ||
|
||
script.ts | ||
## Datastore Tables | ||
|
||
```js | ||
const { Function, HeroFunctionPlugin } = require('@ulixee/datastore-plugins-hero'); | ||
|
||
new Function(async context => { | ||
const { input, Output, Hero } = context; | ||
const hero = new Hero(); | ||
await hero.goto('https://example.org'); | ||
Output.emit({ text: `I went to example.org. Your input was: ${input.name}` }); | ||
}, HeroFunctionPlugin); | ||
``` | ||
Datastore Tables allow you to manage and deploy database tables as part of your "api". This can be useful to enhance your functions with metadata or cached data. | ||
|
||
## How Datastores Work | ||
|
||
Each Datastore is a wrapper for defining a composable scraper script. You can run datastores directly from the command line or upload them to a [Miner](https://ulixee.org/docs/miner). | ||
|
||
You can call your script in several ways. | ||
## Installation | ||
|
||
1. Directly from the command line: | ||
To get started using Datastore in your project, use the following commands: | ||
|
||
```shell script | ||
% node script.js --input.name=Alfonso | ||
```bash | ||
npm i --save @ulixee/datastore | ||
``` | ||
|
||
2. Through Stream: | ||
or | ||
|
||
**COMING SOON** | ||
```bash | ||
yarn add @ulixee/datastore | ||
``` | ||
|
||
```js | ||
import Stream from '@ulixee/stream'; | ||
It's your responsibility to ensure your Ulixee development environment is setup, such as installing and running [`@ulixee/miner`](https://ulixee.org/docs/miner). | ||
|
||
const stream = new Stream(''); | ||
## Usage Example | ||
|
||
const output = await stream.query({ input: { name: 'Alfonso' } }); | ||
The simplest Datastore is initialized with a single Function: | ||
|
||
```js | ||
export default new Datastore({ | ||
functions: { | ||
default: new Function(ctx => { | ||
ctx.output = `Hello ${ctx.input.firstName}`; | ||
}), | ||
}, | ||
}); | ||
``` | ||
|
||
Browse the [full API docs](https://docs.ulixee.org/datastore). | ||
Save that script to your filesystem (i.e., simple.js), and run it as a regular node script: | ||
|
||
## Contributing | ||
```bash | ||
node ./simple.js --input.firstName=Me | ||
``` | ||
|
||
We'd love your help making `Datastore for Hero` a better tool. Please don't hesitate to send a pull request. | ||
However, this Datastore structure also allows us to load it onto a Miner and run it on demand: | ||
|
||
## License | ||
```bash | ||
npx @ulixee/datastore deploy ./simple.js | ||
npx @ulixee/datastore run simple.js --input.firstName=Me | ||
|
||
[MIT](LICENSE.md) | ||
``` |
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
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
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
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
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
Oops, something went wrong.