Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Dec 12, 2023
1 parent 04c30eb commit 1be57eb
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 187 deletions.
2 changes: 1 addition & 1 deletion packages/nest/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ export class FileSystem {
this.#blockStore,
{ ...this.#privateNodes },
this.#rng,
{ ...this.#rootTree }
this.#rootTree.clone()
)
}

Expand Down
60 changes: 30 additions & 30 deletions packages/nest/src/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { BlockStore } from 'wnfs'
import type { Blockstore } from 'interface-blockstore'

import type * as Path from './path.js'

// TODO: import * as Unix from "./unix.js"

import { searchLatest } from './common.js'
import type { Rng } from './rng.js'
import type { RootTree } from './root-tree.js'
import type { MutationType } from './types.js'
Expand All @@ -15,6 +11,11 @@ import type {
WnfsPublicResult,
} from './types/internal.js'

import * as Store from './store.js'
import * as Unix from './unix.js'

import { searchLatest } from './common.js'

// 🏔️

export const TYPES: Record<string, MutationType> = {
Expand All @@ -25,7 +26,7 @@ export const TYPES: Record<string, MutationType> = {
// PUBLIC

export interface PublicParams {
blockStore: BlockStore
blockstore: Blockstore
pathSegments: Path.Segments
rootTree: RootTree
}
Expand All @@ -34,40 +35,39 @@ export type Public = (params: PublicParams) => Promise<WnfsPublicResult>

export const publicCreateDirectory = () => {
return async (params: PublicParams): Promise<WnfsPublicResult> => {
return await params.rootTree.publicRoot.mkdir(
params.pathSegments,
new Date(),
params.blockStore
)
return await params.rootTree
.publicRoot()
.mkdir(params.pathSegments, new Date(), Store.wnfs(params.blockstore))
}
}

export const publicRemove = () => {
return async (params: PublicParams): Promise<WnfsPublicResult> => {
return await params.rootTree.publicRoot.rm(
params.pathSegments,
params.blockStore
)
return await params.rootTree
.publicRoot()
.rm(params.pathSegments, Store.wnfs(params.blockstore))
}
}

export const publicWrite = (bytes: Uint8Array) => {
return async (params: PublicParams): Promise<WnfsPublicResult> => {
const cid = await Unix.importFile(bytes, params.dependencies.depot)

return await params.rootTree.publicRoot.write(
params.pathSegments,
cid.bytes,
new Date(),
params.blockStore
)
const cid = await Unix.importFile(bytes, params.blockstore)

return await params.rootTree
.publicRoot()
.write(
params.pathSegments,
cid.bytes,
new Date(),
Store.wnfs(params.blockstore)
)
}
}

// PRIVATE

export type PrivateParams = {
blockStore: BlockStore
blockstore: Blockstore
privateNodes: MountedPrivateNodes
rng: Rng
rootTree: RootTree
Expand All @@ -86,8 +86,8 @@ export const privateCreateDirectory = () => {
params.remainder,
searchLatest(),
new Date(),
params.rootTree.privateForest,
params.blockStore,
params.rootTree.privateForest(),
Store.wnfs(params.blockstore),
params.rng
)
}
Expand All @@ -104,8 +104,8 @@ export const privateRemove = () => {
.rm(
params.remainder,
searchLatest(),
params.rootTree.privateForest,
params.blockStore
params.rootTree.privateForest(),
Store.wnfs(params.blockstore)
)
}
}
Expand All @@ -123,8 +123,8 @@ export const privateWrite = (bytes: Uint8Array) => {
searchLatest(),
bytes,
new Date(),
params.rootTree.privateForest,
params.blockStore,
params.rootTree.privateForest(),
Store.wnfs(params.blockstore),
params.rng
)
}
Expand Down
Loading

0 comments on commit 1be57eb

Please sign in to comment.