Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
fix: workshop flow #128
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala authored Oct 28, 2022
2 parents 6098bce + 6d6b073 commit 53520ca
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ module.exports = {
tabWidth: 2,
semi: false,
singleQuote: true,
importOrder: ['^[./]'],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
}
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@
"test:dev": "vitest"
},
"dependencies": {
"@ucanto/interface": "^1.0.0",
"@ipld/unixfs": "^1.1.0-dev",
"@ucanto/server": "^1.0.2",
"@ucanto/transport": "^1.0.1",
"@ucanto/core": "^1.0.1",
"uint8arrays": "^3.1.0",
"@ipld/dag-cbor": "^8.0.0",
"@ipld/dag-json": "^8.0.11",
"@ipld/dag-pb": "^2.1.18",
"@ucanto/principal": "^1.0.1",
"@web-std/stream": "^1.0.1",
"@web3-storage/w3up-client": "3.0.2",
"@web3-storage/w3up-client": "^3.0.4",
"multiformats": "^9.9.0",
"@ipld/car": "^4.1.6",
"archy": "^1.0.0",
"cli-table": "^0.3.11",
"conf": "^10.2.0",
Expand All @@ -41,7 +51,6 @@
"yargs": "^17.5.1"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
"@types/inquirer": "^9.0.1",
"@types/yargs": "^17.0.11",
"chai": "^4.3.6",
Expand Down
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export function getClient(profile = 'main') {
const settings = getProfileSettings(profile)

const client = new W3Client({
serviceDID: cliSettings.W3_STORE_DID,
serviceDID: /** @type {`did:${string}`} */ (cliSettings.W3_STORE_DID),
serviceURL: cliSettings.SERVICE_URL,
accessDID: cliSettings.ACCESS_DID,
accessDID: /** @type {`did:${string}`} */ (cliSettings.ACCESS_DID),
accessURL: cliSettings.ACCESS_URL,
settings,
})
Expand Down
2 changes: 1 addition & 1 deletion src/commands/delegations/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const handler = async ({ profile }) => {
const client = getClient(profile)
const id = await client.account()
const settings = await client.settings
const selected = settings.get('delegation')
const selected = settings.get('account')
const delegations = settings.get('delegations')

const table = buildSimpleConsoleTable(['selected', 'alias', 'did'])
Expand Down
6 changes: 3 additions & 3 deletions src/commands/delegations/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const handler = async ({ did, alias, profile }) => {
const found = choices.find((x) => x.alias == alias)
if (found) {
const del = found.value
settings.set('delegation', del)
settings.set('account', del)
console.log(`now using account: ${del}`)
} else {
console.log(
Expand Down Expand Up @@ -68,12 +68,12 @@ async function inquirerPick(choices, client) {
type: 'list',
name: 'Choose an account',
choices,
default: settings.get('delegation'),
default: settings.get('account'),
},
])
.then((answers) => {
const del = answers['Choose an account']
settings.set('delegation', del)
settings.set('account', del)
console.log(`now using account: ${del}`)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/settings/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const handler = async ({ filename, profile, stdout = false, yes = false }) => {
const client = getClient(profile)

if (stdout) {
const store = await exportSettings(client.settings)
const store = await exportSettings(await client.settings)
process.stdout.write(JSON.stringify(store))
return
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/settings/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ const handler = async ({ fileName, profile, yes = false }) => {

if (show && fileName) {
try {
client.settings.clear()
const settings = await client.settings
settings.clear()
const json = fs.readFileSync(fileName, { encoding: 'utf-8' })
const imported = await importSettings(json)

for (const [key, value] of imported.entries()) {
client.settings.set(key, value)
settings.set(key, value)
}

await client.identity()
Expand Down
6 changes: 3 additions & 3 deletions src/commands/uploadCars.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-expect-error
import * as CAR from '@ipld/car'
import { CarReader } from '@ipld/car/reader'
import fs from 'fs'
import ora from 'ora'
import path from 'path'
// @ts-ignore
import toIterator from 'stream-to-it'
import { TransformStream } from '@web-std/stream'

import { getClient } from '../client.js'
import { getAllFiles, isDirectory } from '../lib/car/file.js'
Expand Down Expand Up @@ -103,7 +103,7 @@ const handler = async (argv) => {
uploadExistingCar(car, client, view).then(async (buffer) => {
if (buffer) {
const bytes = Uint8Array.from(buffer)
const reader = await CAR.CarReader.fromBytes(bytes)
const reader = await CarReader.fromBytes(bytes)
const roots = await reader.getRoots()
const cid = await bytesToCarCID(bytes)
for (const root of roots) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/car/buildCar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import * as CAR from '@ipld/car'
import * as UnixFS from '@ipld/unixfs'
import fs from 'fs'
import path from 'path'
import 'web-streams-polyfill'

import { isDirectory } from '../../utils.js'
import { walkDir, wrapFilesWithDir } from './dir.js'
import { streamFileToBlock } from './file.js'

import { TransformStream } from '@web-std/stream'
// Internal unixfs read stream capacity that can hold around 32 blocks
const CAPACITY = UnixFS.BLOCK_SIZE_LIMIT * 32
const MAX_CARS_AT_ONCE = 8
Expand Down
7 changes: 3 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import whoami from './commands/whoami.js'
import printQuickstart from './quickstart.js'

/**
* @type {import('yargs').Argv<{}>} yargs
* @param {string[]} args
*/
const yargs = _yargs(hideBin(process.argv))

export const main = async () => {
export const main = async (args = hideBin(process.argv)) => {
const yargs = _yargs(args)
const argv = await yargs
.scriptName('w3up')
// .usage('Usage:\n $0 <cmd> [options]')
Expand Down
6 changes: 3 additions & 3 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ export const hasEmail = ({ profile }) => {
export const hasOtherDelegation = ({ profile }) => {
const settings = getProfileSettings(profile)

if (!settings.has('delegation')) {
if (!settings.has('account')) {
return false
}

const delegations = settings.get('delegations')
const delegation = settings.get('delegation')
const account = settings.get('account')

if (delegations[delegation].alias != 'self') {
if (delegations[account].alias != 'self') {
return true
} else {
return false
Expand Down

0 comments on commit 53520ca

Please sign in to comment.