-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
833c8f9
commit 5288041
Showing
18 changed files
with
1,100 additions
and
2 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,5 @@ | ||
--- | ||
'@siafoundation/renterd-js': minor | ||
--- | ||
|
||
Introduced a new renterd-js library. Closes https://github.com/SiaFoundation/web/issues/585 |
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,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nx/react/babel", | ||
{ | ||
"runtime": "automatic", | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
], | ||
"plugins": [] | ||
} |
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 @@ | ||
{ | ||
"extends": ["plugin:@nx/react", "../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"rules": { | ||
"@nx/dependency-checks": [ | ||
"error", | ||
{ | ||
"ignoredFiles": ["libs/renterd-js/rollup.config.js"] | ||
} | ||
] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
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,93 @@ | ||
# renterd-js | ||
|
||
SDK for interacting with `renterd`. | ||
|
||
## installation | ||
|
||
```sh | ||
npm install @siafoundation/renterd-js | ||
``` | ||
|
||
## usage | ||
|
||
```js | ||
import { Bus } from './bus' | ||
import { Autopilot } from './autopilot' | ||
import { Worker } from './worker' | ||
|
||
export async function example() { | ||
const bus = Bus({ | ||
api: 'http://localhost:9980', | ||
password: 'password1337', | ||
}) | ||
const autopilot = Autopilot({ | ||
api: 'http://localhost:9980', | ||
password: 'password1337', | ||
}) | ||
const worker = Worker({ | ||
api: 'http://worker:4444', | ||
password: 'password1337', | ||
}) | ||
|
||
const buckets = await bus.buckets() | ||
|
||
buckets.data.forEach((bucket) => { | ||
console.log(bucket.name, bucket.createdAt, bucket.policy) | ||
}) | ||
|
||
bus.bucketCreate({ | ||
data: { name: 'my-bucket' }, | ||
}) | ||
|
||
bus.bucketPolicyUpdate({ | ||
params: { | ||
name: 'my-bucket', | ||
}, | ||
data: { | ||
policy: { | ||
publicReadAccess: true, | ||
}, | ||
}, | ||
}) | ||
|
||
const hosts = await autopilot.hostsSearch({ | ||
data: { | ||
filterMode: 'allowed', | ||
usabilityMode: 'usable', | ||
addressContains: 'example.com', | ||
keyIn: ['key1', 'key2'], | ||
offset: 0, | ||
limit: 50, | ||
}, | ||
}) | ||
|
||
hosts.data.forEach((host) => { | ||
console.log(host.host.publicKey, host.host.priceTable) | ||
}) | ||
|
||
worker.objectUpload({ | ||
params: { | ||
key: 'path/to/file.txt', | ||
bucket: 'my-bucket', | ||
}, | ||
data: new File(['file contents'], 'file.txt'), | ||
config: { | ||
onUploadProgress: (progress) => { | ||
console.log(progress.loaded / progress.total) | ||
}, | ||
}, | ||
}) | ||
|
||
worker.objectDownload({ | ||
params: { | ||
key: 'path/to/file.txt', | ||
bucket: 'my-bucket', | ||
}, | ||
config: { | ||
onDownloadProgress: (progress) => { | ||
console.log(progress.loaded / progress.total) | ||
}, | ||
}, | ||
}) | ||
} | ||
``` |
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,17 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'renterd-js', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest', | ||
'^.+\\.[tj]sx?$': [ | ||
'babel-jest', | ||
{ | ||
presets: ['@nx/next/babel'], | ||
plugins: ['@babel/plugin-transform-private-methods'], | ||
}, | ||
], | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/libs/renterd-js', | ||
} |
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,11 @@ | ||
{ | ||
"name": "@siafoundation/renterd-js", | ||
"description": "SDK for interacting with `renterd`.", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@siafoundation/renterd-types": "0.0.0", | ||
"@siafoundation/request": "0.0.0" | ||
}, | ||
"types": "./src/index.d.ts" | ||
} |
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,42 @@ | ||
{ | ||
"name": "renterd-js", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/renterd-js/src", | ||
"projectType": "library", | ||
"tags": [], | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/rollup:rollup", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/libs/renterd-js", | ||
"tsConfig": "libs/renterd-js/tsconfig.lib.json", | ||
"project": "libs/renterd-js/package.json", | ||
"entryFile": "libs/renterd-js/src/index.ts", | ||
"external": ["react/jsx-runtime"], | ||
"compiler": "tsc", | ||
"outputFileName": "index.js", | ||
"rollupConfig": "libs/renterd-js/rollup.config.js", | ||
"assets": [ | ||
{ | ||
"glob": "libs/renterd-js/*.md", | ||
"input": ".", | ||
"output": "." | ||
} | ||
] | ||
}, | ||
"configurations": {} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": ["{options.outputFile}"] | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/libs/renterd-js"], | ||
"options": { | ||
"jestConfig": "libs/renterd-js/jest.config.ts" | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const preserveDirectives = require('rollup-plugin-preserve-directives') | ||
|
||
// https://github.com/rollup/rollup/issues/4699#issuecomment-1465302665 | ||
function getRollupOptions(options) { | ||
return { | ||
...options, | ||
output: { | ||
...options.output, | ||
preserveModules: true, | ||
format: 'esm', | ||
sourcemap: true, | ||
}, | ||
plugins: options.plugins.concat(preserveDirectives.default()), | ||
} | ||
} | ||
|
||
module.exports = getRollupOptions |
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,59 @@ | ||
import { | ||
AutopilotConfigParams, | ||
AutopilotConfigPayload, | ||
AutopilotConfigResponse, | ||
AutopilotConfigUpdateParams, | ||
AutopilotConfigUpdatePayload, | ||
AutopilotConfigUpdateResponse, | ||
AutopilotHostsSearchParams, | ||
AutopilotHostsSearchPayload, | ||
AutopilotHostsSearchResponse, | ||
AutopilotStateParams, | ||
AutopilotStatePayload, | ||
AutopilotStateResponse, | ||
AutopilotTriggerParams, | ||
AutopilotTriggerPayload, | ||
AutopilotTriggerResponse, | ||
autopilotConfigRoute, | ||
autopilotHostsRoute, | ||
autopilotStateRoute, | ||
autopilotTriggerRoute, | ||
} from '@siafoundation/renterd-types' | ||
import { buildRequestHandler, initAxios } from '@siafoundation/request' | ||
|
||
export function Autopilot({ | ||
api, | ||
password, | ||
}: { | ||
api: string | ||
password?: string | ||
}) { | ||
const axios = initAxios(api, password) | ||
return { | ||
state: buildRequestHandler< | ||
AutopilotStateParams, | ||
AutopilotStatePayload, | ||
AutopilotStateResponse | ||
>(axios, 'get', autopilotStateRoute), | ||
confg: buildRequestHandler< | ||
AutopilotConfigParams, | ||
AutopilotConfigPayload, | ||
AutopilotConfigResponse | ||
>(axios, 'get', autopilotConfigRoute), | ||
configUpdate: buildRequestHandler< | ||
AutopilotConfigUpdateParams, | ||
AutopilotConfigUpdatePayload, | ||
AutopilotConfigUpdateResponse | ||
>(axios, 'put', autopilotConfigRoute), | ||
hostsSearch: buildRequestHandler< | ||
AutopilotHostsSearchParams, | ||
AutopilotHostsSearchPayload, | ||
AutopilotHostsSearchResponse | ||
>(axios, 'post', autopilotHostsRoute), | ||
trigger: buildRequestHandler< | ||
AutopilotTriggerParams, | ||
AutopilotTriggerPayload, | ||
AutopilotTriggerResponse | ||
>(axios, 'post', autopilotTriggerRoute), | ||
} | ||
} |
Oops, something went wrong.