0.0.13 • Published 8 months ago

@daggle/bacalhau-js v0.0.13

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Bacalhau JS🟨

const { submit } = require('@daggle/bacalhau-js')
const { Payload } =  require("@daggle/bacalhau-js/models");

let data = new Payload({
	ClientID: ...,
	spec: ...
})

submit(data)

Check examples↗️

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm install @daggle/bacalhau-js

Example

const { submit } =  require("@daggle/bacalhau-js");

const {
Payload,
Spec,
PublisherSpec,
StorageSpec,
Deal,
JobSpecDocker,
} =  require("@daggle/bacalhau-js/models");

async function submitJob() {
	let data = new Payload({
	ClientID: getClientId(),
	spec: new Spec({
	deal: new Deal(),
	docker: new JobSpecDocker({
			image: "ubuntu",
			entrypoint: ["echo", "Hello World!"],
		}),
		engine: "Docker",
		publisher_spec: new PublisherSpec({ type:  "Estuary" }),
		timeout: 1800,
		verifier: "Noop",
		outputs: [
			new  StorageSpec({
				path: "/outputs",
				storage_source: "IPFS",
				name: "outputs",
			}),
		],
		}),
	});

	const  response = await submit(data);
	console.log(response);
}
submitJob()

Check complete example↗️

Local Testing

Follow the below steps to run it locally.

Clone repo⚙️

  1. Clone Repo.

    $ git clone https://github.com/dagglexyz/bacalhau-js bacalhau-js

    Change Host Initialize the SDK by passing in the host URL as parameter. ./src/sdk/config.js

    ...
    } = require("./config");
    // Change host here
    const  config = initializeSDK("http://127.0.0.1:1234");
    const  jobApi = new  JobApi(config);
    
    async  function  submit(data  =  new  Payload()) {
    ...
  2. Create a simple node project

    $ mkdir example-project
    $ cd example-project
    $ npm init
  3. Install package
    $ npm install ../bacalhau-js
  4. Testing, create a file at root, index.js.

    const { list} =  require("@daggle/bacalhau-js");
    
    async function listJobs() {
    	const response = await list();
    	console.log(response.jobs);
    }
    listJobs()

Note⚠️

This is not a production ready SDK, this repo will be moved to Bacalhau organization's GitHub and maintained by Bacalhau in the future.

0.0.13

8 months ago

0.0.12

8 months ago

0.0.11

9 months ago

0.0.1

9 months ago