Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions bin/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const commands = require('../commands')
const Sentry = require('@sentry/node')
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const { Core } = require('..')
// We must not require('..') as that confuses TypeScript compiler.
// The compiler will look at our package.json, find that the types are in `dist/index.d.ts`
// and load that output file instead of the actual input `index.js`.
const { Core } = require('../index')
const pkg = require('../package.json')

Sentry.init({
Expand Down Expand Up @@ -41,23 +44,23 @@ const main = async () => {
'metrics [module]',
'Show metrics',
() => {},
args => commands.metrics({ ...args, core })
({ follow, module }) => commands.metrics({ core, follow, module })
)
.commands(
.command(
'activity',
'Show activity log',
yargs => yargs.option('json', {
alias: 'j',
type: 'boolean',
description: 'Output JSON'
}),
args => commands.activity({ ...args, core })
({ follow, json }) => commands.activity({ core, follow, json })
)
.command(
'logs [module]',
'Show module logs',
() => {},
args => commands.logs({ ...args, core })
({ module, follow }) => commands.logs({ core, module, follow })
)
.choices('module', core.modules)
.version(`${pkg.name}: ${pkg.version}`)
Expand Down
2 changes: 1 addition & 1 deletion commands/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const activity = async ({ core, follow, json }) => {
} else {
const activity = await core.activity.get()
if (json) {
console.log(JSON.stringify(activity, 0, 2))
console.log(JSON.stringify(activity, null, 2))
} else {
process.stdout.write(
activity
Expand Down
4 changes: 2 additions & 2 deletions commands/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const metrics = async ({ core, follow, module }) => {
if (follow) {
for await (const obj of core.metrics.follow({ module })) {
console.log(JSON.stringify(obj, 0, 2))
console.log(JSON.stringify(obj, null, 2))
}
} else {
console.log(JSON.stringify(await core.metrics.getLatest(module), 0, 2))
console.log(JSON.stringify(await core.metrics.getLatest(module), null, 2))
}
}

Expand Down
2 changes: 1 addition & 1 deletion commands/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const station = async ({ core, json, experimental }) => {
total: metrics.totalJobsCompleted
}))
} else {
console.log(JSON.stringify(metrics, 0, 2))
console.log(JSON.stringify(metrics, null, 2))
}
}
})(),
Expand Down
6 changes: 5 additions & 1 deletion lib/bacalhau.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ function handleActivityLogs (activityStream, text) {
})
}

/** @typedef {{
* jobsCompleted: number
* }?} BacalhauStats */

async function updateStats ({ metricsStream, apiUrl }) {
const res = await fetch(apiUrl)
if (!res.ok) {
Expand All @@ -154,7 +158,7 @@ async function updateStats ({ metricsStream, apiUrl }) {
throw new Error(msg)
}

const stats = await res.json()
const stats = /** @type {BacalhauStats} */ (await res.json())

const totalJobsCompleted = stats?.jobsCompleted
if (typeof totalJobsCompleted !== 'number') {
Expand Down
2 changes: 2 additions & 0 deletions lib/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const { once } = require('node:events')
const { createWriteStream } = require('node:fs')
const { moduleBinaries } = require('./paths')

/** @typedef {import('unzip-stream').UnzipStreamEntry} UnzipStreamEntry */

const { GITHUB_TOKEN } = process.env
const authorization = GITHUB_TOKEN ? `Bearer ${GITHUB_TOKEN}` : undefined

Expand Down
17 changes: 16 additions & 1 deletion lib/saturn-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { fetch } = require('undici')
const Sentry = require('@sentry/node')
const { installBinaryModule, getBinaryModuleExecutable } = require('./modules')

/** @typedef {import('node:stream').Writable} Writable */

const DIST_TAG = 'v0.5.1'

async function install () {
Expand All @@ -26,6 +28,15 @@ async function install () {
})
}

/**
* @param {Object} options
* @param {String} options.FIL_WALLET_ADDRESS
* @param {String} [options.MAX_DISK_SPACE]
* @param {String} options.storagePath
* @param {Writable} options.metricsStream
* @param {Writable} options.activityStream
* @param {Writable} options.logStream
*/
async function start ({
FIL_WALLET_ADDRESS,
MAX_DISK_SPACE,
Expand Down Expand Up @@ -132,6 +143,10 @@ function handleActivityLogs (activityStream, text) {
})
}

/** @typedef {{
* NSuccessfulRetrievals: number
* }?} SaturnStats */

async function updateStats ({ metricsStream, apiUrl }) {
const res = await fetch(apiUrl.replace('localhost', '127.0.0.1') + 'stats')
if (!res.ok) {
Expand All @@ -140,7 +155,7 @@ async function updateStats ({ metricsStream, apiUrl }) {
throw new Error(msg)
}

const stats = await res.json()
const stats = /** @type {SaturnStats} */ (await res.json())

const totalJobsCompleted = stats?.NSuccessfulRetrievals
if (typeof totalJobsCompleted !== 'number') {
Expand Down
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Filecoin Station Core",
"license": "(Apache-2.0 AND MIT)",
"repository": "filecoin-station/core",
"main": "index.js",
"types": "dist/index.d.ts",
"bin": {
"station": "./bin/station.js"
Expand All @@ -12,7 +13,7 @@
"node": ">=16"
},
"scripts": {
"build": "tsc",
"build": "tsc -p .",
"format": "prettier --write .",
"start": "node ./bin/station.js",
"test": "npm run build && npm run test:lint && npm run test:unit",
Expand All @@ -29,6 +30,7 @@
]
},
"devDependencies": {
"@types/yargs": "^17.0.24",
"get-stream": "^6.0.1",
"mocha": "^10.2.0",
"np": "^7.6.3",
Expand Down
2 changes: 1 addition & 1 deletion scripts/post-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const main = async () => {
pkg.sentryEnvironment = 'development'
await fs.writeFile(
join(__dirname, '..', 'package.json'),
JSON.stringify(pkg, 0, 2) + '\n'
JSON.stringify(pkg, null, 2) + '\n'
)
await execa('git', ['add', 'package.json'])
await execa('git', ['commit', '-m', 'chore: set sentry environment to development'])
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const main = async () => {
pkg.sentryEnvironment = 'production'
await fs.writeFile(
join(__dirname, '..', 'package.json'),
JSON.stringify(pkg, 0, 2) + '\n'
JSON.stringify(pkg, null, 2) + '\n'
)
await execa('git', ['add', 'package.json'])
}
Expand Down
14 changes: 12 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"include": ["index.js"],
"compilerOptions": {
"allowJs": true,
"checkJs": true,
Expand All @@ -18,5 +17,16 @@
"outDir": "dist",
"declarationMap": true,
"resolveJsonModule": true
}
},
"include": [
"index.js",
"bin",
"commands",
"lib",
"scripts",
"tests"
],
"exclude": [
"dist/**/*"
]
Comment on lines +29 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exclude block is probably not needed; feel free to remove it.

}