diff --git a/examples/audio/src/fs.ts b/examples/audio/src/fs.ts index 5a87464..ce9c008 100644 --- a/examples/audio/src/fs.ts +++ b/examples/audio/src/fs.ts @@ -32,7 +32,7 @@ export async function load({ capsuleKey: Uint8Arr.fromString(storedKey, 'base64'), }) } else { - const { capsuleKey } = await fs.mountPrivateNode({ + const { capsuleKey } = await fs.createPrivateNode({ path: Path.root(), }) diff --git a/examples/audio/src/index.ts b/examples/audio/src/index.ts index a4214bc..c1c4336 100644 --- a/examples/audio/src/index.ts +++ b/examples/audio/src/index.ts @@ -68,7 +68,7 @@ async function createAudio( // File note('Adding file to WNFS') - const path = Path.file('private', fileName) + const path = Path.priv(fileName) if (!(await fs.exists(path))) { const { dataRoot } = await fs.write(path, 'bytes', new Uint8Array(fileData)) @@ -201,7 +201,7 @@ function createMediaSource({ fileSize: number metadataSize: number mimeType: string - path: Path.File> + path: Path.PartitionedNonEmpty }): { supported: boolean } { if (window.MediaSource === undefined) { return { supported: false } @@ -406,7 +406,7 @@ async function createWebAudio({ mediainfo: MediaInfoType metadataSize: number mimeType: string - path: Path.File> + path: Path.PartitionedNonEmpty }): Promise<{ supported: boolean }> { const audioContext = new AudioContext() diff --git a/examples/demo/src/main.ts b/examples/demo/src/main.ts index 290b898..e0b3684 100644 --- a/examples/demo/src/main.ts +++ b/examples/demo/src/main.ts @@ -30,28 +30,29 @@ globalThis._fs = fs globalThis._Path = Path // Create new private directory at the root -const { capsuleKey } = await fs.mountPrivateNode({ - path: Path.root(), - capsuleKey: - storedKey === null - ? undefined - : uint8arrays.fromString(storedKey, 'base64'), -}) +storedKey === null + ? await fs.createPrivateNode({ path: Path.root() }) + : await fs.mountPrivateNode({ + path: Path.root(), + capsuleKey: uint8arrays.fromString(storedKey, 'base64'), + }) // Read from or write to the file system -const filePath = Path.file('private', 'init') +const filePath = Path.priv('init') if (await fs.exists(filePath)) { h1.textContent = 'Time first seen: ' + (await fs.read(filePath, 'utf8')) } else { const dateTime = new Date().toString() const result = await fs.write(filePath, 'utf8', dateTime) + const capsuleKey = await fs.capsuleKey(Path.priv()) localStorage.setItem('fs-pointer', result.dataRoot.toString()) - localStorage.setItem( - 'capsule-key', - uint8arrays.toString(capsuleKey, 'base64') - ) + if (capsuleKey !== undefined) + localStorage.setItem( + 'capsule-key', + uint8arrays.toString(capsuleKey, 'base64') + ) h1.textContent = 'Time first seen: ' + dateTime } diff --git a/examples/web3storage/src/app.ts b/examples/web3storage/src/app.ts index 76fcff6..6146eb5 100644 --- a/examples/web3storage/src/app.ts +++ b/examples/web3storage/src/app.ts @@ -16,7 +16,7 @@ import { type Tracker } from './tracker' // 🏔️ -const TODOS_DIRECTORY = Path.directory('private', 'todos') +const TODOS_DIRECTORY = Path.priv('todos') const TRANSPORT_HOST = 'radical-party.icidasset.partykit.dev' let todos: DirectoryItem[] = [] @@ -82,8 +82,6 @@ async function initAuthed({ /** * - * @param root0 - * @param root0.isAuthenticated * @param state */ function setAuthedState( @@ -163,7 +161,7 @@ async function initDelete(fs: FileSystem): Promise { if (todo === undefined) throw new Error("Couldn't find associated todo") - await fs.remove(Path.combine(TODOS_DIRECTORY, Path.file(todo))) + await fs.remove([...TODOS_DIRECTORY, todo]) await loadAndRender(fs) } } @@ -233,7 +231,7 @@ async function initInput(fs: FileSystem): Promise { button.setAttribute('disabled', '') const todo = input.value - const todoPath = Path.combine(TODOS_DIRECTORY, Path.file(todo)) + const todoPath = Path.combine(TODOS_DIRECTORY, [todo]) await fs.write(todoPath, 'json', {}) await loadAndRender(fs) @@ -250,9 +248,9 @@ type Payload = Uint8Array /** * - * @param fs.client - * @param fs - * @param fs.fs + * @param root0 + * @param root0.client + * @param root0.fs */ async function initLink({ client, @@ -287,11 +285,10 @@ async function initLink({ /** * - * @param challenge.challenge - * @param challenge - * @param publicKey - * @param challenge.client - * @param challenge.publicKey + * @param root0 + * @param root0.challenge + * @param root0.client + * @param root0.publicKey */ async function initConsumer({ challenge, @@ -364,9 +361,9 @@ async function initConsumer({ /** * - * @param fs.client - * @param fs - * @param fs.fs + * @param root0 + * @param root0.client + * @param root0.fs */ async function initProvider({ client, @@ -420,7 +417,7 @@ async function initProvider({ await Promise.all(promises) - const key = await fs.capsuleKey(Path.directory('private')) + const key = await fs.capsuleKey(Path.priv()) if (key === undefined) throw new Error("Couldn't resolve access key") await consumers[did]?.send('key', key) }) diff --git a/examples/web3storage/src/fs.ts b/examples/web3storage/src/fs.ts index af67799..b7c1418 100644 --- a/examples/web3storage/src/fs.ts +++ b/examples/web3storage/src/fs.ts @@ -41,7 +41,7 @@ export async function load({ // Create new or load existing private directory at the root if (storedKey === undefined) { - const { capsuleKey } = await fs.mountPrivateNode({ + const { capsuleKey } = await fs.createPrivateNode({ path: Path.root(), }) @@ -61,7 +61,7 @@ export async function load({ // 💁 MANAGEMENT export const Identity = { - PATH: Path.file('public', '.well-known', 'did'), + PATH: Path.pub('.well-known', 'did'), async assign({ did, fs }: { did: string; fs: FileSystem }): Promise { await fs.write(this.PATH, 'utf8', did) @@ -79,7 +79,7 @@ export const Keys = { async lookup({ path, }: { - path: Path.Directory + path: Path.Segments }): Promise { return await IDB.get(`fs.keys.path:/${Path.toPosix(path)}`) }, @@ -89,7 +89,7 @@ export const Keys = { path, }: { key: Uint8Array - path: Path.Directory + path: Path.Segments }): Promise { await IDB.set(`fs.keys.path:/${Path.toPosix(path)}`, key) }, diff --git a/examples/web3storage/src/index.ts b/examples/web3storage/src/index.ts index 076fdbb..5b901ed 100644 --- a/examples/web3storage/src/index.ts +++ b/examples/web3storage/src/index.ts @@ -93,6 +93,5 @@ async function setup(): Promise<{ const components = await setup() await App.init(components) -// Debug - +// @ts-expect-error Debug globalThis.fs = components.fs diff --git a/examples/web3storage/tsconfig.json b/examples/web3storage/tsconfig.json index a56f0b3..a4b60f8 100644 --- a/examples/web3storage/tsconfig.json +++ b/examples/web3storage/tsconfig.json @@ -5,7 +5,6 @@ "moduleDetection": "force", "module": "ESNext", "moduleResolution": "Bundler", - "types": ["vite/client"], "allowImportingTsExtensions": true, "resolveJsonModule": true, "outDir": "dist",