Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

fix: typedef resolution & add examples that use types #3359

Merged
merged 6 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions examples/ipfs-from-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ipfs-from-ts",
"private": true,
"dependencies": {
"ipfs": "^0.50.1"
},
"scripts": {
"test": "npx typescript --noEmit"
}
}
29 changes: 29 additions & 0 deletions examples/ipfs-from-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import IPFS from 'ipfs'

export default async function main () {
const node = await IPFS.create()
const version = await node.version()

console.log('Version:', version.version)

const file = await node.add({
path: 'hello.txt',
content: new TextEncoder().encode('Hello World 101')
})

console.log('Added file:', file.path, file.cid.toString())
try {
// @ts-expect-error - CID is not a string
file.cid.toUpperCase()
} catch(error) {

}

const decoder = new TextDecoder()
let content = ''
for await (const chunk of node.cat(file.cid)) {
content += decoder.decode(chunk)
}

console.log('Added file contents:', content)
}
13 changes: 13 additions & 0 deletions examples/ipfs-from-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"noImplicitAny": false,
"esModuleInterop": true,
"moduleResolution": "Node",
"noEmit": true
},
"include": [
"src"
]
}
10 changes: 10 additions & 0 deletions examples/ipfs-from-typed-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ipfs-from-ts",
"private": true,
"dependencies": {
"ipfs": "^0.50.1"
},
"scripts": {
"test": "npx typescript --noEmit"
}
}
31 changes: 31 additions & 0 deletions examples/ipfs-from-typed-js/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const IPFS = require('ipfs')

async function main () {
const node = await IPFS.create()
const version = await node.version()

console.log('Version:', version.version)

const file = await node.add({
path: 'hello.txt',
content: new TextEncoder().encode('Hello World 101')
})

console.log('Added file:', file.path, file.cid.toString())
try {
// @ts-expect-error - CID is not a string
file.cid.toUpperCase()
} catch(error) {

}

const decoder = new TextDecoder()
let content = ''
for await (const chunk of node.cat(file.cid)) {
content += decoder.decode(chunk)
}

console.log('Added file contents:', content)
}

main()
15 changes: 15 additions & 0 deletions examples/ipfs-from-typed-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"strict": true,
"skipLibCheck": true,
"noImplicitAny": false,
"esModuleInterop": true,
"moduleResolution": "Node",
"noEmit": true
},
"include": [
"src"
]
}
3 changes: 2 additions & 1 deletion packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"typesVersions": {
"*": {
"*": [
"dist/*"
"dist/*",
"dist/*/index"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"typesVersions": {
"*": {
"*": [
"dist/*"
"dist/*",
"dist/*/index"
]
}
},
Expand Down
22 changes: 11 additions & 11 deletions packages/ipfs-core/src/components/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const isIpfs = require('is-ipfs')

/**
* @typedef {Object} MFS
* @property {ReturnType<import('./stat')>} stat
* @property {ReturnType<import('./chmod')>} chmod
* @property {ReturnType<import('./cp')>} cp
* @property {ReturnType<import('./flush')>} flush
* @property {ReturnType<import('./mkdir')>} mkdir
* @property {ReturnType<import('./mv')>} mv
* @property {ReturnType<import('./rm')>} rm
* @property {ReturnType<import('./touch')>} touch
* @property {ReturnType<import('./write')>} write
* @property {ReturnType<import('./read')>} read
* @property {ReturnType<import('./ls')>} ls
* @property {ReturnType<typeof import('./stat')>} stat
* @property {ReturnType<typeof import('./chmod')>} chmod
* @property {ReturnType<typeof import('./cp')>} cp
* @property {ReturnType<typeof import('./flush')>} flush
* @property {ReturnType<typeof import('./mkdir')>} mkdir
* @property {ReturnType<typeof import('./mv')>} mv
* @property {ReturnType<typeof import('./rm')>} rm
* @property {ReturnType<typeof import('./touch')>} touch
* @property {ReturnType<typeof import('./write')>} write
* @property {ReturnType<typeof import('./read')>} read
* @property {ReturnType<typeof import('./ls')>} ls
*/

// These operations are read-locked at the function level and will execute simultaneously
Expand Down
Loading