Skip to content

Commit 6e37d29

Browse files
committed
feat: renterd-js library
1 parent 443c8fb commit 6e37d29

16 files changed

+921
-0
lines changed

.changeset/calm-sloths-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@siafoundation/renterd-js': minor
3+
---
4+
5+
Introduced a new renterd-js library.

libs/renterd-js/.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/react/babel",
5+
{
6+
"runtime": "automatic",
7+
"useBuiltIns": "usage"
8+
}
9+
]
10+
],
11+
"plugins": []
12+
}

libs/renterd-js/.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"rules": {
5+
"@nx/dependency-checks": [
6+
"error",
7+
{
8+
"ignoredFiles": ["libs/renterd-js/rollup.config.js"]
9+
}
10+
]
11+
},
12+
"overrides": [
13+
{
14+
"files": ["*.json"],
15+
"parser": "jsonc-eslint-parser",
16+
"rules": {
17+
"@nx/dependency-checks": "error"
18+
}
19+
}
20+
]
21+
}

libs/renterd-js/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# renterd-js
2+
3+
SDK for interacting with `renterd`.

libs/renterd-js/jest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'renterd-js',
4+
preset: '../../jest.preset.js',
5+
transform: {
6+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
7+
'^.+\\.[tj]sx?$': [
8+
'babel-jest',
9+
{
10+
presets: ['@nx/next/babel'],
11+
plugins: ['@babel/plugin-transform-private-methods'],
12+
},
13+
],
14+
},
15+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16+
coverageDirectory: '../../coverage/libs/renterd-js',
17+
}

libs/renterd-js/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@siafoundation/renterd-js",
3+
"description": "SDK for interacting with `renterd`.",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@siafoundation/renterd-types": "0.0.0",
8+
"@siafoundation/request": "0.0.0",
9+
"axios": "^0.27.2"
10+
},
11+
"types": "./src/index.d.ts"
12+
}

libs/renterd-js/project.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "renterd-js",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/renterd-js/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/rollup:rollup",
10+
"outputs": ["{options.outputPath}"],
11+
"options": {
12+
"outputPath": "dist/libs/renterd-js",
13+
"tsConfig": "libs/renterd-js/tsconfig.lib.json",
14+
"project": "libs/renterd-js/package.json",
15+
"entryFile": "libs/renterd-js/src/index.ts",
16+
"external": ["react/jsx-runtime"],
17+
"compiler": "tsc",
18+
"outputFileName": "index.js",
19+
"rollupConfig": "libs/renterd-js/rollup.config.js",
20+
"assets": [
21+
{
22+
"glob": "libs/renterd-js/*.md",
23+
"input": ".",
24+
"output": "."
25+
}
26+
]
27+
},
28+
"configurations": {}
29+
},
30+
"lint": {
31+
"executor": "@nx/eslint:lint",
32+
"outputs": ["{options.outputFile}"]
33+
},
34+
"test": {
35+
"executor": "@nx/jest:jest",
36+
"outputs": ["{workspaceRoot}/coverage/libs/renterd-js"],
37+
"options": {
38+
"jestConfig": "libs/renterd-js/jest.config.ts"
39+
}
40+
}
41+
}
42+
}

libs/renterd-js/rollup.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const preserveDirectives = require('rollup-plugin-preserve-directives')
3+
4+
// https://github.com/rollup/rollup/issues/4699#issuecomment-1465302665
5+
function getRollupOptions(options) {
6+
return {
7+
...options,
8+
output: {
9+
...options.output,
10+
preserveModules: true,
11+
format: 'esm',
12+
sourcemap: true,
13+
},
14+
plugins: options.plugins.concat(preserveDirectives.default()),
15+
}
16+
}
17+
18+
module.exports = getRollupOptions

libs/renterd-js/src/autopilot.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
AutopilotConfigParams,
3+
AutopilotConfigPayload,
4+
AutopilotConfigResponse,
5+
AutopilotConfigUpdateParams,
6+
AutopilotConfigUpdatePayload,
7+
AutopilotConfigUpdateResponse,
8+
AutopilotHostsSearchParams,
9+
AutopilotHostsSearchPayload,
10+
AutopilotHostsSearchResponse,
11+
AutopilotStateParams,
12+
AutopilotStatePayload,
13+
AutopilotStateResponse,
14+
AutopilotTriggerParams,
15+
AutopilotTriggerPayload,
16+
AutopilotTriggerResponse,
17+
autopilotConfigKey,
18+
autopilotHostsKey,
19+
autopilotStateKey,
20+
autopilotTriggerKey,
21+
} from '@siafoundation/renterd-types'
22+
import { buildRequestHandler } from '@siafoundation/request'
23+
import { Axios } from 'axios'
24+
25+
export function Autopilot(api?: string) {
26+
const axios = new Axios({ baseURL: api })
27+
return {
28+
state: buildRequestHandler<
29+
AutopilotStateParams,
30+
AutopilotStatePayload,
31+
AutopilotStateResponse
32+
>(axios, 'get', autopilotStateKey),
33+
confg: buildRequestHandler<
34+
AutopilotConfigParams,
35+
AutopilotConfigPayload,
36+
AutopilotConfigResponse
37+
>(axios, 'get', autopilotConfigKey),
38+
configUpdate: buildRequestHandler<
39+
AutopilotConfigUpdateParams,
40+
AutopilotConfigUpdatePayload,
41+
AutopilotConfigUpdateResponse
42+
>(axios, 'put', autopilotConfigKey),
43+
hostsSearch: buildRequestHandler<
44+
AutopilotHostsSearchParams,
45+
AutopilotHostsSearchPayload,
46+
AutopilotHostsSearchResponse
47+
>(axios, 'post', autopilotHostsKey),
48+
trigger: buildRequestHandler<
49+
AutopilotTriggerParams,
50+
AutopilotTriggerPayload,
51+
AutopilotTriggerResponse
52+
>(axios, 'post', autopilotTriggerKey),
53+
}
54+
}

0 commit comments

Comments
 (0)