Skip to content

Commit

Permalink
feat: renterd-js library
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 15, 2024
1 parent 2cf79e3 commit d9ecf44
Show file tree
Hide file tree
Showing 15 changed files with 917 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libs/renterd-js/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
21 changes: 21 additions & 0 deletions libs/renterd-js/.eslintrc.json
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"
}
}
]
}
3 changes: 3 additions & 0 deletions libs/renterd-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# renterd-js

SDK for interacting with `renterd`.
17 changes: 17 additions & 0 deletions libs/renterd-js/jest.config.ts
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',
}
12 changes: 12 additions & 0 deletions libs/renterd-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"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",
"axios": "^0.27.2"
},
"types": "./src/index.d.ts"
}
42 changes: 42 additions & 0 deletions libs/renterd-js/project.json
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"
}
}
}
}
18 changes: 18 additions & 0 deletions libs/renterd-js/rollup.config.js
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
54 changes: 54 additions & 0 deletions libs/renterd-js/src/autopilot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse,
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
AutopilotHostsSearchResponse,
AutopilotStateParams,
AutopilotStatePayload,
AutopilotStateResponse,
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse,
autopilotConfigKey,
autopilotHostsKey,
autopilotStateKey,
autopilotTriggerKey,
} from '@siafoundation/renterd-types'
import { buildRequestHandler } from '@siafoundation/request'
import { Axios } from 'axios'

export function Autopilot(api?: string) {
const axios = new Axios({ baseURL: api })
return {
state: buildRequestHandler<
AutopilotStateParams,
AutopilotStatePayload,
AutopilotStateResponse
>(axios, 'get', autopilotStateKey),
confg: buildRequestHandler<
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse
>(axios, 'get', autopilotConfigKey),
configUpdate: buildRequestHandler<
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>(axios, 'put', autopilotConfigKey),
hostsSearch: buildRequestHandler<
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
AutopilotHostsSearchResponse
>(axios, 'post', autopilotHostsKey),
trigger: buildRequestHandler<
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse
>(axios, 'post', autopilotTriggerKey),
}
}
Loading

0 comments on commit d9ecf44

Please sign in to comment.