fission-sdk
Advanced tools
Comparing version 0.3.1-alpha.5 to 0.3.1-alpha.6
import PublicTree from './public'; | ||
import PrivateTree from './private'; | ||
import { Tree, FullLinks } from './types'; | ||
import { Tree, File, Links } from './types'; | ||
import { CID, FileContent } from '../ipfs'; | ||
@@ -14,7 +14,7 @@ export declare class FileSystem { | ||
static upgradePublicCID(cid: CID, keyName?: string): Promise<FileSystem>; | ||
ls(path: string): Promise<FullLinks>; | ||
ls(path: string): Promise<Links>; | ||
mkdir(path: string): Promise<CID>; | ||
add(path: string, content: FileContent): Promise<CID>; | ||
cat(path: string): Promise<FileContent | null>; | ||
getTree(path: string): Promise<Tree | null>; | ||
get(path: string): Promise<Tree | File | null>; | ||
sync(): Promise<CID>; | ||
@@ -21,0 +21,0 @@ runOnTree<a>(path: string, updateTree: boolean, fn: (tree: Tree, relPath: string) => Promise<a>): Promise<a>; |
@@ -40,2 +40,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import pathUtil from './path'; | ||
import link from './link'; | ||
import keystore from '../keystore'; | ||
@@ -176,7 +177,7 @@ var FileSystem = /** @class */ (function () { | ||
}; | ||
FileSystem.prototype.getTree = function (path) { | ||
FileSystem.prototype.get = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, this.runOnTree(path, false, function (tree, relPath) { | ||
return tree.getTree(relPath); | ||
return tree.get(relPath); | ||
})]; | ||
@@ -197,7 +198,7 @@ }); | ||
privCID = _a.sent(); | ||
pubLink = { name: 'public', cid: pubCID }; | ||
privLink = { name: 'private', cid: privCID }; | ||
pubLink = link.make('public', pubCID, false); | ||
privLink = link.make('private', privCID, false); | ||
this.root = this.root | ||
.replaceLink(pubLink) | ||
.replaceLink(privLink); | ||
.updateLink(pubLink) | ||
.updateLink(privLink); | ||
return [2 /*return*/, this.root.put()]; | ||
@@ -204,0 +205,0 @@ } |
import { DAGLink, UnixFSFile } from '../ipfs'; | ||
import { Tree, Link, FullLink, FullLinks } from './types'; | ||
import { Link } from './types'; | ||
export declare const toDAGLink: (link: Link) => DAGLink; | ||
export declare const fromFSFile: (fsObj: UnixFSFile) => Link; | ||
export declare const make: (name: string, cid: string, size?: number | undefined) => Link; | ||
export declare const upgradeLink: (tree: Tree, link: Link) => Promise<FullLink>; | ||
export declare const upgradeLinks: (tree: Tree) => Promise<FullLinks>; | ||
export declare const make: (name: string, cid: string, isFile: boolean, size?: number | undefined) => Link; | ||
declare const _default: { | ||
toDAGLink: (link: Link) => DAGLink; | ||
fromFSFile: (fsObj: UnixFSFile) => Link; | ||
make: (name: string, cid: string, size?: number | undefined) => Link; | ||
upgradeLink: (tree: Tree, link: Link) => Promise<FullLink>; | ||
upgradeLinks: (tree: Tree) => Promise<FullLinks>; | ||
make: (name: string, cid: string, isFile: boolean, size?: number | undefined) => Link; | ||
}; | ||
export default _default; |
@@ -1,48 +0,1 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import dagPB from 'ipld-dag-pb'; | ||
@@ -54,3 +7,3 @@ export var toDAGLink = function (link) { | ||
export var fromFSFile = function (fsObj) { | ||
var _a = fsObj.name, name = _a === void 0 ? '' : _a, cid = fsObj.cid, size = fsObj.size, mtime = fsObj.mtime; | ||
var _a = fsObj.name, name = _a === void 0 ? '' : _a, cid = fsObj.cid, size = fsObj.size, mtime = fsObj.mtime, type = fsObj.type; | ||
return { | ||
@@ -60,6 +13,7 @@ name: name, | ||
size: size, | ||
mtime: mtime | ||
mtime: mtime, | ||
isFile: type !== "dir" | ||
}; | ||
}; | ||
export var make = function (name, cid, size) { | ||
export var make = function (name, cid, isFile, size) { | ||
return { | ||
@@ -69,30 +23,6 @@ name: name, | ||
size: size, | ||
isFile: isFile, | ||
mtime: Date.now() | ||
}; | ||
}; | ||
export var upgradeLink = function (tree, link) { return __awaiter(void 0, void 0, void 0, function () { | ||
var child; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, tree.getDirectChild(link.name)]; | ||
case 1: | ||
child = _a.sent(); | ||
return [2 /*return*/, __assign(__assign({}, link), { isFile: (child === null || child === void 0 ? void 0 : child.isFile()) || false })]; | ||
} | ||
}); | ||
}); }; | ||
export var upgradeLinks = function (tree) { return __awaiter(void 0, void 0, void 0, function () { | ||
var upgraded; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(Object.values(tree.links).map(function (l) { return upgradeLink(tree, l); }))]; | ||
case 1: | ||
upgraded = _a.sent(); | ||
return [2 /*return*/, upgraded.reduce(function (acc, cur) { | ||
acc[cur.name] = cur; | ||
return acc; | ||
}, {})]; | ||
} | ||
}); | ||
}); }; | ||
export default { | ||
@@ -102,5 +32,3 @@ toDAGLink: toDAGLink, | ||
make: make, | ||
upgradeLink: upgradeLink, | ||
upgradeLinks: upgradeLinks, | ||
}; | ||
//# sourceMappingURL=link.js.map |
@@ -1,18 +0,20 @@ | ||
import { PrivateTreeData, Tree, Links, PrivateTreeStatic } from '../types'; | ||
import { CID, FileContent } from '../../ipfs'; | ||
import { PrivateTreeData, Tree, Links, File, PrivateTreeStatic, PrivateFileStatic } from '../types'; | ||
import { CID } from '../../ipfs'; | ||
import PublicTree from '../public/tree'; | ||
import PrivateFile from './file'; | ||
export declare class PrivateTree extends PublicTree { | ||
private key; | ||
static: PrivateTreeStatic; | ||
static: { | ||
tree: PrivateTreeStatic; | ||
file: PrivateFileStatic; | ||
}; | ||
constructor(links: Links, key: string); | ||
static instanceOf(obj: any): obj is PrivateTree; | ||
static empty(key?: string): Promise<PrivateTree>; | ||
static fromCID(_cid: CID): Promise<Tree>; | ||
static fromCID(_cid: CID): Promise<PublicTree>; | ||
static fromCIDWithKey(cid: CID, keyStr: string): Promise<PrivateTree>; | ||
static fromContent(content: FileContent, key?: string): Promise<Tree>; | ||
put(): Promise<CID>; | ||
putEncrypted(key: string): Promise<CID>; | ||
updateDirectChild(child: PrivateTree, name: string): Promise<Tree>; | ||
getDirectChild(name: string): Promise<Tree | null>; | ||
getOwnContent(): Promise<FileContent | null>; | ||
updateDirectChild(child: PrivateTree | PrivateFile, name: string): Promise<Tree>; | ||
getDirectChild(name: string): Promise<Tree | File | null>; | ||
data(): PrivateTreeData; | ||
@@ -19,0 +21,0 @@ copyWithLinks(links: Links): Tree; |
@@ -54,2 +54,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import PublicTree from '../public/tree'; | ||
import PrivateFile from './file'; | ||
var PrivateTree = /** @class */ (function (_super) { | ||
@@ -60,3 +61,6 @@ __extends(PrivateTree, _super); | ||
_this.key = key; | ||
_this.static = PrivateTree; | ||
_this.static = { | ||
tree: PrivateTree, | ||
file: PrivateFile | ||
}; | ||
return _this; | ||
@@ -110,31 +114,2 @@ } | ||
}; | ||
PrivateTree.fromContent = function (content, key) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var keyStr, _a, encrypted, cid, dir; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!key) return [3 /*break*/, 1]; | ||
_a = key; | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, util.genKeyStr()]; | ||
case 2: | ||
_a = _b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
keyStr = _a; | ||
return [4 /*yield*/, util.encryptContent(content, keyStr)]; | ||
case 4: | ||
encrypted = _b.sent(); | ||
return [4 /*yield*/, ipfs.add(encrypted)]; | ||
case 5: | ||
cid = _b.sent(); | ||
return [4 /*yield*/, PrivateTree.empty(keyStr)]; | ||
case 6: | ||
dir = _b.sent(); | ||
return [2 /*return*/, dir.addLink({ name: 'index', cid: cid })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PrivateTree.prototype.put = function () { | ||
@@ -162,9 +137,17 @@ return __awaiter(this, void 0, void 0, function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cid; | ||
var cid, isFile, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, child.putEncrypted(this.key)]; | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, child.putEncrypted(this.key)]; | ||
case 1: | ||
cid = _a.sent(); | ||
return [2 /*return*/, this.replaceLink(link.make(name, cid))]; | ||
isFile = util.isFile(child); | ||
return [2 /*return*/, this.updateLink(link.make(name, cid, isFile))]; | ||
case 2: | ||
err_1 = _a.sent(); | ||
console.log(child); | ||
throw err_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
@@ -179,21 +162,8 @@ }); | ||
link = this.findLink(name); | ||
return [2 /*return*/, link ? this.static.fromCIDWithKey(link.cid, this.key) : null]; | ||
}); | ||
}); | ||
}; | ||
PrivateTree.prototype.getOwnContent = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var link, encrypted; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
link = this.findLink('index'); | ||
if (link === null) { | ||
return [2 /*return*/, null]; | ||
} | ||
return [4 /*yield*/, ipfs.catBuf(link.cid)]; | ||
case 1: | ||
encrypted = _a.sent(); | ||
return [2 /*return*/, util.decryptContent(encrypted, this.key)]; | ||
if (link === null) { | ||
return [2 /*return*/, null]; | ||
} | ||
return [2 /*return*/, link.isFile | ||
? this.static.file.fromCIDWithKey(link.cid, this.key) | ||
: this.static.tree.fromCIDWithKey(link.cid, this.key)]; | ||
}); | ||
@@ -200,0 +170,0 @@ }); |
@@ -20,3 +20,8 @@ import { PrivateTreeData } from '../types'; | ||
decryptContent: (encrypted: Uint8Array, keyStr: string) => Promise<FileContent>; | ||
linksFromCID: (cid: string) => Promise<import("../types").Links>; | ||
putLinks: (links: import("../types").Links) => Promise<string>; | ||
isFile: (obj: any) => obj is import("../types").File; | ||
addRecurse: (tree: import("../types").Tree, path: import("../types").NonEmptyPath, child: import("../types").File | import("../types").Tree) => Promise<import("../types").Tree>; | ||
getRecurse: (tree: import("../types").Tree, path: string[]) => Promise<import("../types").File | import("../types").Tree>; | ||
}; | ||
export default _default; |
@@ -0,1 +1,12 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,2 +48,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import publicUtil from '../public/util'; | ||
import cbor from 'borc'; | ||
@@ -163,4 +175,3 @@ import aes from 'keystore-idb/aes'; | ||
}; | ||
export default { | ||
genKeyStr: genKeyStr, | ||
export default __assign(__assign({}, publicUtil), { genKeyStr: genKeyStr, | ||
emptyDir: emptyDir, | ||
@@ -172,4 +183,3 @@ encrypt: encrypt, | ||
decryptNode: decryptNode, | ||
decryptContent: decryptContent, | ||
}; | ||
decryptContent: decryptContent }); | ||
//# sourceMappingURL=util.js.map |
@@ -1,6 +0,10 @@ | ||
import { Link, Links, FullLinks, Tree, TreeStatic } from '../types'; | ||
import { Link, Links, Tree, TreeStatic, FileStatic, File } from '../types'; | ||
import { CID, FileContent } from '../../ipfs'; | ||
declare class PublicTree implements Tree { | ||
links: Links; | ||
static: TreeStatic; | ||
isFile: boolean; | ||
static: { | ||
tree: TreeStatic; | ||
file: FileStatic; | ||
}; | ||
constructor(links: Links); | ||
@@ -10,23 +14,18 @@ static instanceOf(obj: any): obj is PublicTree; | ||
static fromCID(cid: CID): Promise<PublicTree>; | ||
static fromContent(content: FileContent): Promise<Tree>; | ||
ls(path: string): Promise<FullLinks>; | ||
ls(path: string): Promise<Links>; | ||
mkdir(path: string): Promise<Tree>; | ||
cat(path: string): Promise<FileContent | null>; | ||
cat(path: string): Promise<FileContent>; | ||
add(path: string, content: FileContent): Promise<Tree>; | ||
pathExists(path: string): Promise<boolean>; | ||
getTree(path: string): Promise<Tree | null>; | ||
addChild(path: string, toAdd: Tree): Promise<Tree>; | ||
get(path: string): Promise<Tree | File>; | ||
addChild(path: string, toAdd: Tree | File): Promise<Tree>; | ||
put(): Promise<CID>; | ||
updateDirectChild(child: PublicTree, name: string): Promise<Tree>; | ||
getDirectChild(name: string): Promise<Tree | null>; | ||
getOrCreateDirectChild(name: string): Promise<Tree>; | ||
getOwnContent(): Promise<FileContent | null>; | ||
fullLinks(): Promise<FullLinks>; | ||
isFile(): boolean; | ||
updateDirectChild(child: Tree | File, name: string): Promise<Tree>; | ||
getDirectChild(name: string): Promise<Tree | File | null>; | ||
getOrCreateDirectChild(name: string): Promise<Tree | File>; | ||
findLink(name: string): Link | null; | ||
addLink(link: Link): Tree; | ||
updateLink(link: Link): Tree; | ||
rmLink(name: string): Tree; | ||
replaceLink(link: Link): Tree; | ||
copyWithLinks(links: Links): Tree; | ||
} | ||
export default PublicTree; |
@@ -51,7 +51,11 @@ var __assign = (this && this.__assign) || function () { | ||
import link from '../link'; | ||
import ipfs from '../../ipfs'; | ||
import PublicFile from './file'; | ||
var PublicTree = /** @class */ (function () { | ||
function PublicTree(links) { | ||
this.isFile = false; | ||
this.links = links; | ||
this.static = PublicTree; | ||
this.static = { | ||
tree: PublicTree, | ||
file: PublicFile | ||
}; | ||
} | ||
@@ -81,18 +85,2 @@ PublicTree.instanceOf = function (obj) { | ||
}; | ||
PublicTree.fromContent = function (content) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cid, dir; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, ipfs.add(content)]; | ||
case 1: | ||
cid = _a.sent(); | ||
return [4 /*yield*/, PublicTree.empty()]; | ||
case 2: | ||
dir = _a.sent(); | ||
return [2 /*return*/, dir.addLink({ name: 'index', cid: cid })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PublicTree.prototype.ls = function (path) { | ||
@@ -103,6 +91,9 @@ return __awaiter(this, void 0, void 0, function () { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getTree(path)]; | ||
case 0: return [4 /*yield*/, this.get(path)]; | ||
case 1: | ||
tree = _a.sent(); | ||
return [2 /*return*/, tree ? tree.fullLinks() : {}]; | ||
if (util.isFile(tree)) { | ||
throw new Error('Can not `ls` a file'); | ||
} | ||
return [2 /*return*/, tree.links]; | ||
} | ||
@@ -123,3 +114,3 @@ }); | ||
} | ||
return [4 /*yield*/, this.static.empty()]; | ||
return [4 /*yield*/, this.static.tree.empty()]; | ||
case 2: | ||
@@ -134,9 +125,12 @@ toAdd = _a.sent(); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tree; | ||
var file; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getTree(path)]; | ||
case 0: return [4 /*yield*/, this.get(path)]; | ||
case 1: | ||
tree = _a.sent(); | ||
return [2 /*return*/, tree ? tree.getOwnContent() : null]; | ||
file = _a.sent(); | ||
if (!util.isFile(file)) { | ||
throw new Error('Can not `cat` a directory'); | ||
} | ||
return [2 /*return*/, file.content]; | ||
} | ||
@@ -148,10 +142,6 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var toAdd; | ||
var file; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.static.fromContent(content)]; | ||
case 1: | ||
toAdd = _a.sent(); | ||
return [2 /*return*/, this.addChild(path, toAdd)]; | ||
} | ||
file = this.static.file.create(content); | ||
return [2 /*return*/, this.addChild(path, file)]; | ||
}); | ||
@@ -162,9 +152,15 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tree; | ||
var _err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getTree(path)]; | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.get(path)]; | ||
case 1: | ||
tree = _a.sent(); | ||
return [2 /*return*/, tree !== null]; | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
case 2: | ||
_err_1 = _a.sent(); | ||
return [2 /*return*/, false]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
@@ -174,3 +170,3 @@ }); | ||
}; | ||
PublicTree.prototype.getTree = function (path) { | ||
PublicTree.prototype.get = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -200,3 +196,3 @@ return __generator(this, function (_a) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cid; | ||
var cid, isFile; | ||
return __generator(this, function (_a) { | ||
@@ -207,3 +203,4 @@ switch (_a.label) { | ||
cid = _a.sent(); | ||
return [2 /*return*/, this.replaceLink(link.make(name, cid))]; | ||
isFile = util.isFile(child); | ||
return [2 /*return*/, this.updateLink(link.make(name, cid, isFile))]; | ||
} | ||
@@ -218,3 +215,6 @@ }); | ||
link = this.findLink(name); | ||
return [2 /*return*/, link ? this.static.fromCID(link.cid) : null]; | ||
if (link === null) { | ||
return [2 /*return*/, null]; | ||
} | ||
return [2 /*return*/, link.isFile ? this.static.file.fromCID(link.cid) : this.static.tree.fromCID(link.cid)]; | ||
}); | ||
@@ -231,3 +231,3 @@ }); | ||
child = _a.sent(); | ||
return [2 /*return*/, child ? child : this.static.empty()]; | ||
return [2 /*return*/, child ? child : this.static.tree.empty()]; | ||
} | ||
@@ -237,25 +237,6 @@ }); | ||
}; | ||
PublicTree.prototype.getOwnContent = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var link; | ||
return __generator(this, function (_a) { | ||
link = this.findLink('index'); | ||
return [2 /*return*/, link ? ipfs.catBuf(link.cid) : null]; | ||
}); | ||
}); | ||
}; | ||
PublicTree.prototype.fullLinks = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, link.upgradeLinks(this)]; | ||
}); | ||
}); | ||
}; | ||
PublicTree.prototype.isFile = function () { | ||
return this.findLink('index') !== null; | ||
}; | ||
PublicTree.prototype.findLink = function (name) { | ||
return this.links[name] || null; | ||
}; | ||
PublicTree.prototype.addLink = function (link) { | ||
PublicTree.prototype.updateLink = function (link) { | ||
var _a; | ||
@@ -268,5 +249,2 @@ return this.copyWithLinks(__assign(__assign({}, this.links), (_a = {}, _a[link.name] = link, _a))); | ||
}; | ||
PublicTree.prototype.replaceLink = function (link) { | ||
return this.rmLink(link.name).addLink(link); | ||
}; | ||
PublicTree.prototype.copyWithLinks = function (links) { | ||
@@ -273,0 +251,0 @@ return new PublicTree(links); |
/// <reference types="node" /> | ||
import { NonEmptyPath, Tree, Links } from '../types'; | ||
import { NonEmptyPath, Tree, Links, File } from '../types'; | ||
export declare const dagNodeData: Buffer; | ||
export declare const linksFromCID: (cid: string) => Promise<Links>; | ||
export declare const putLinks: (links: Links) => Promise<string>; | ||
export declare const addRecurse: (tree: Tree, path: NonEmptyPath, child: Tree) => Promise<Tree>; | ||
export declare const getRecurse: (tree: Tree, path: string[]) => Promise<Tree | null>; | ||
export declare const isFile: (obj: any) => obj is File; | ||
export declare const addRecurse: (tree: Tree, path: NonEmptyPath, child: File | Tree) => Promise<Tree>; | ||
export declare const getRecurse: (tree: Tree, path: string[]) => Promise<File | Tree>; | ||
declare const _default: { | ||
linksFromCID: (cid: string) => Promise<Links>; | ||
putLinks: (links: Links) => Promise<string>; | ||
addRecurse: (tree: Tree, path: NonEmptyPath, child: Tree) => Promise<Tree>; | ||
getRecurse: (tree: Tree, path: string[]) => Promise<Tree | null>; | ||
isFile: (obj: any) => obj is File; | ||
addRecurse: (tree: Tree, path: NonEmptyPath, child: File | Tree) => Promise<Tree>; | ||
getRecurse: (tree: Tree, path: string[]) => Promise<File | Tree>; | ||
}; | ||
export default _default; |
@@ -64,2 +64,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}); }; | ||
export var isFile = function (obj) { | ||
return obj.isFile; | ||
}; | ||
export var addRecurse = function (tree, path, child) { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -78,2 +81,5 @@ var name, nextPath, toAdd, nextTree; | ||
nextTree = _a.sent(); | ||
if (isFile(nextTree)) { | ||
throw new Error("Attempted to add a child to a File"); | ||
} | ||
return [4 /*yield*/, addRecurse(nextTree, nextPath, child)]; | ||
@@ -91,12 +97,11 @@ case 3: | ||
switch (_a.label) { | ||
case 0: | ||
if (path.length === 0) { | ||
return [2 /*return*/, tree]; | ||
} | ||
return [4 /*yield*/, tree.getDirectChild(path[0])]; | ||
case 0: return [4 /*yield*/, tree.getDirectChild(path[0])]; | ||
case 1: | ||
nextTree = _a.sent(); | ||
if (nextTree === null) { | ||
return [2 /*return*/, null]; | ||
if (path.length <= 1 && nextTree !== null) { | ||
return [2 /*return*/, nextTree]; | ||
} | ||
if (nextTree === null || isFile(nextTree)) { | ||
throw new Error("Path does not exist"); | ||
} | ||
return [2 /*return*/, getRecurse(nextTree, path.slice(1))]; | ||
@@ -109,5 +114,6 @@ } | ||
putLinks: putLinks, | ||
isFile: isFile, | ||
addRecurse: addRecurse, | ||
getRecurse: getRecurse | ||
getRecurse: getRecurse, | ||
}; | ||
//# sourceMappingURL=util.js.map |
@@ -15,4 +15,2 @@ import { FileContent, CID } from '../ipfs'; | ||
mtime?: number; | ||
}; | ||
export declare type FullLink = Link & { | ||
isFile: boolean; | ||
@@ -23,35 +21,42 @@ }; | ||
}; | ||
export declare type FullLinks = { | ||
[name: string]: FullLink; | ||
}; | ||
export interface PrivateTreeStatic extends TreeStatic { | ||
fromCIDWithKey: (cid: CID, keyStr: string) => Promise<Tree>; | ||
export interface FileStatic { | ||
create: (content: FileContent) => File; | ||
fromCID: (cid: CID) => Promise<File>; | ||
} | ||
export interface PrivateFileStatic extends FileStatic { | ||
fromCIDWithKey: (cid: CID, key: string) => Promise<File>; | ||
} | ||
export interface File { | ||
content: FileContent; | ||
put(): Promise<CID>; | ||
} | ||
export interface TreeStatic { | ||
empty: () => Promise<Tree>; | ||
fromCID: (cid: CID) => Promise<Tree>; | ||
fromContent: (content: FileContent) => Promise<Tree>; | ||
} | ||
export interface PrivateTreeStatic extends TreeStatic { | ||
fromCIDWithKey: (cid: CID, key: string) => Promise<Tree>; | ||
} | ||
export interface Tree { | ||
static: TreeStatic; | ||
links: Links; | ||
ls(path: string): Promise<FullLinks>; | ||
isFile: boolean; | ||
static: { | ||
tree: TreeStatic; | ||
file: FileStatic; | ||
}; | ||
ls(path: string): Promise<Links>; | ||
mkdir(path: string): Promise<Tree>; | ||
cat(path: string): Promise<FileContent | null>; | ||
cat(path: string): Promise<FileContent>; | ||
add(path: string, content: FileContent): Promise<Tree>; | ||
getTree(path: string): Promise<Tree | null>; | ||
get(path: string): Promise<Tree | File>; | ||
pathExists(path: string): Promise<boolean>; | ||
addChild(path: string, toAdd: Tree): Promise<Tree>; | ||
addChild(path: string, toAdd: Tree | File): Promise<Tree>; | ||
put(): Promise<CID>; | ||
updateDirectChild(child: Tree, name: string): Promise<Tree>; | ||
getDirectChild(name: string): Promise<Tree | null>; | ||
getOrCreateDirectChild(name: string): Promise<Tree>; | ||
getOwnContent(): Promise<FileContent | null>; | ||
fullLinks(): Promise<FullLinks>; | ||
isFile(): boolean; | ||
updateDirectChild(child: Tree | File, name: string): Promise<Tree>; | ||
getDirectChild(name: string): Promise<Tree | File | null>; | ||
getOrCreateDirectChild(name: string): Promise<Tree | File>; | ||
findLink(name: string): Link | null; | ||
addLink(link: Link): Tree; | ||
updateLink(link: Link): Tree; | ||
rmLink(name: string): Tree; | ||
replaceLink(link: Link): Tree; | ||
copyWithLinks(links: Links): Tree; | ||
} |
@@ -69,2 +69,3 @@ /// <reference types="node" /> | ||
name?: string; | ||
type?: string; | ||
}; | ||
@@ -71,0 +72,0 @@ export declare type ObjStat = { |
{ | ||
"name": "fission-sdk", | ||
"version": "0.3.1-alpha.5", | ||
"version": "0.3.1-alpha.6", | ||
"description": "Fission Typescript SDK", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
7899690
84
75985