Fix minor issues

This commit is contained in:
Arnaud 2024-08-29 19:41:28 +02:00
parent 7e1b0792d3
commit 19d798e7dc
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
3 changed files with 67 additions and 94 deletions

View File

@ -1,61 +1,61 @@
{
"name": "@codex/sdk-js",
"version": "0.0.1",
"description": "Codex SDK to interact with the Codex decentralized storage network.",
"repository": {
"type": "git",
"url": "https://github.com/codex-storage/codex-js"
},
"scripts": {
"prepack": "tsup tsup src/index.ts --format esm,cjs --dts",
"prebuild": "rm -Rf dist/*",
"build": "tsc --p tsconfig.test.json",
"compile": "tsc --noEmit",
"pretest": "npm run build",
"pretest:only": "npm run build",
"test": "node --test",
"test:only": "node --test --test-only",
"watch": "tsc --watch",
"format": "prettier --write ./src"
},
"keywords": [
"Codex",
"Javascript",
"SDK",
"storage"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.js"
}
}
},
"sideEffects": false,
"files": [
"dist"
],
"author": "Codex team",
"readme": "README.md",
"license": "MIT",
"engines": {
"node": ">=20"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@tsconfig/strictest": "^2.0.5",
"prettier": "^3.3.3",
"tsup": "^8.2.3",
"typescript": "^5.5.4"
},
"dependencies": {
"valibot": "^0.36.0"
}
"name": "@codex/sdk-js",
"version": "0.0.1",
"description": "Codex SDK to interact with the Codex decentralized storage network.",
"repository": {
"type": "git",
"url": "https://github.com/codex-storage/codex-js"
},
"scripts": {
"prepack": "tsup tsup src/index.ts --format esm,cjs --dts",
"prebuild": "rm -Rf dist/*",
"build": "tsc --p tsconfig.json",
"compile": "tsc --noEmit",
"pretest": "npm run build",
"pretest:only": "npm run build",
"test": "node --test",
"test:only": "node --test --test-only",
"watch": "tsc --watch",
"format": "prettier --write ./src"
},
"keywords": [
"Codex",
"Javascript",
"SDK",
"storage"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.js"
}
}
},
"sideEffects": false,
"files": [
"dist"
],
"author": "Codex team",
"readme": "README.md",
"license": "MIT",
"engines": {
"node": ">=20"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@tsconfig/strictest": "^2.0.5",
"prettier": "^3.3.3",
"tsup": "^8.2.3",
"typescript": "^5.5.4"
},
"dependencies": {
"valibot": "^0.36.0"
}
}

View File

@ -3,12 +3,12 @@ import { Fetch } from "../fetch-safe/fetch-safe";
import type { SafeValue } from "../values/values";
import type { CodexDataResponse, CodexNodeSpace } from "./types";
type UploadResponse = {
export type UploadResponse = {
result: Promise<SafeValue<string>>;
abort: () => void;
};
export class Data {
export class CodexData {
readonly url: string;
constructor(url: string) {
@ -29,39 +29,10 @@ export class Data {
return data;
}
const mimetypes = [
"image/png",
"image/jpg",
"image/jpeg",
"audio/mp3",
"video/mp4",
"application/pdf",
"application/msdoc",
"text/plain",
];
return {
error: false,
data: {
content: data.data.content.map((content) => {
const random = Math.trunc(Math.random() * (mimetypes.length - 1));
const mimetype = mimetypes[random];
const [, extension] = mimetype?.split("/") || [];
const filename = Array(5)
.fill("")
.map((_) => ((Math.random() * 36) | 0).toString(36))
.join("");
return {
cid: content.cid,
manifest: {
...content.manifest,
filename: `${filename}.${extension}`,
mimetype: mimetype || "",
uploadedAt: new Date().toJSON(),
},
};
}),
content: data.data.content,
},
};
});

View File

@ -1,4 +1,4 @@
import type { Data } from "./data/data";
import type { CodexData } from "./data/data";
import type { Node } from "./node/node";
import { Marketplace } from "./marketplace/marketplace";
import type { Debug } from "./debug/debug";
@ -10,10 +10,12 @@ export * from "./data/types";
export * from "./values/values";
export * from "./errors/errors";
export { type CodexData, type UploadResponse } from "./data/data";
export class Codex {
readonly url: string;
private _marketplace: Marketplace | null;
private _data: Data | null;
private _data: CodexData | null;
private _node: Node | null;
private _debug: Debug | null;
@ -44,7 +46,7 @@ export class Codex {
const module = await import("./data/data");
this._data = new module.Data(this.url);
this._data = new module.CodexData(this.url);
return this._data;
}