mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-05 23:13:07 +00:00
Fix documentation and types
This commit is contained in:
parent
19d798e7dc
commit
fca1bd7259
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
*.tgz
|
||||||
91
README.md
91
README.md
@ -139,8 +139,8 @@ const reservations = await marketplace.reservations("Ox...");
|
|||||||
|
|
||||||
Creates a new Request for storage
|
Creates a new Request for storage
|
||||||
|
|
||||||
- input ([CodexCreateStorageRequestInput](./src/marketplace/types.ts#L186), required)
|
- input ([CodexCreateStorageRequestInput](./src/marketplace/types.ts#L188), required)
|
||||||
- returns Promise<[CodexCreateStorageRequestResponse](./src/marketplace/types.ts#L201)[]>
|
- returns Promise<string>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@ -181,3 +181,90 @@ Example:
|
|||||||
const purchaseId = "Ox........";
|
const purchaseId = "Ox........";
|
||||||
const purchase = await marketplace.purchaseDetail(purchaseId);
|
const purchase = await marketplace.purchaseDetail(purchaseId);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Data
|
||||||
|
|
||||||
|
The following API assume that you have already a data module loaded, example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const codex = new Codex("http://localhost:3000");
|
||||||
|
const data = await codex.data();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### cids
|
||||||
|
|
||||||
|
Returns the manifest stored locally in node.
|
||||||
|
|
||||||
|
- returns Promise<[CodexDataResponse](./src/data/types.ts#L57)[]>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const cids = await data.cids();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### space
|
||||||
|
|
||||||
|
Returns a summary of the storage space allocation of the node
|
||||||
|
|
||||||
|
- returns Promise<[CodexNodeSpace](./src/data/types.ts#61)[]>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const space = await data.space();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### upload
|
||||||
|
|
||||||
|
Upload a file in a streaming manner
|
||||||
|
|
||||||
|
- file (File, require)
|
||||||
|
- onProgress (onProgress: (loaded: number, total: number) => void, optional)
|
||||||
|
- returns Promise<[UploadResponse](./src/data/types.ts#85)[]>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Get file from previous event
|
||||||
|
const [file] = e.target.files
|
||||||
|
|
||||||
|
const upload = await data.upload(file, (loaded: number, total: number) => {
|
||||||
|
// Use loaded and total so update a progress bar for example
|
||||||
|
});
|
||||||
|
await upload.result();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Node
|
||||||
|
|
||||||
|
The following API assume that you have already a node module loaded, example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const codex = new Codex("http://localhost:3000");
|
||||||
|
const data = await codex.node();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### setLogLevel
|
||||||
|
|
||||||
|
Set log level at run time.
|
||||||
|
|
||||||
|
- level ([CodexLogLevel](./src/debug/types.ts#L3), required)
|
||||||
|
- returns Promise<string>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
await debug.setLogLevel("DEBUG");
|
||||||
|
```
|
||||||
|
|
||||||
|
#### info
|
||||||
|
|
||||||
|
Gets node information
|
||||||
|
|
||||||
|
- returns Promise<[CodexDebugInfo](./src/debug/types.ts#L15)>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const info = await debug.info();
|
||||||
|
```
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@codex/sdk-js",
|
"name": "@codex-storage/sdk-js",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Codex SDK to interact with the Codex decentralized storage network.",
|
"description": "Codex SDK to interact with the Codex decentralized storage network.",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -7,9 +7,9 @@
|
|||||||
"url": "https://github.com/codex-storage/codex-js"
|
"url": "https://github.com/codex-storage/codex-js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepack": "tsup tsup src/index.ts --format esm,cjs --dts",
|
"prepack": "npm run buid",
|
||||||
"prebuild": "rm -Rf dist/*",
|
"prebuild": "rm -Rf dist/*",
|
||||||
"build": "tsc --p tsconfig.json",
|
"build": "tsup tsup src/index.ts --format esm,cjs --dts --sourcemap",
|
||||||
"compile": "tsc --noEmit",
|
"compile": "tsc --noEmit",
|
||||||
"pretest": "npm run build",
|
"pretest": "npm run build",
|
||||||
"pretest:only": "npm run build",
|
"pretest:only": "npm run build",
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
import { Api } from "../api/config";
|
import { Api } from "../api/config";
|
||||||
import { Fetch } from "../fetch-safe/fetch-safe";
|
import { Fetch } from "../fetch-safe/fetch-safe";
|
||||||
import type { SafeValue } from "../values/values";
|
import type { SafeValue } from "../values/values";
|
||||||
import type { CodexDataResponse, CodexNodeSpace } from "./types";
|
import type {
|
||||||
|
CodexDataResponse,
|
||||||
export type UploadResponse = {
|
CodexNodeSpace,
|
||||||
result: Promise<SafeValue<string>>;
|
UploadResponse,
|
||||||
abort: () => void;
|
} from "./types";
|
||||||
};
|
|
||||||
|
|
||||||
export class CodexData {
|
export class CodexData {
|
||||||
readonly url: string;
|
readonly url: string;
|
||||||
@ -98,20 +97,6 @@ export class CodexData {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// const promise = Fetch.safe(url, {
|
|
||||||
// method: "POST",
|
|
||||||
// headers: { "Content-Type": "text/plain" },
|
|
||||||
// body: file.stream(),
|
|
||||||
// // @ts-ignore
|
|
||||||
// duplex: "half",
|
|
||||||
// })
|
|
||||||
// .then(async (res) => {
|
|
||||||
// console.info(res);
|
|
||||||
// return res.error
|
|
||||||
// ? res
|
|
||||||
// : { error: false as false, data: await res.data.text() };
|
|
||||||
// })
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: promise,
|
result: promise,
|
||||||
abort: () => {
|
abort: () => {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import type { SafeValue } from "../values/values";
|
||||||
|
|
||||||
export type CodexManifest = {
|
export type CodexManifest = {
|
||||||
/**
|
/**
|
||||||
* "Root hash of the content"
|
* "Root hash of the content"
|
||||||
@ -79,3 +81,8 @@ export type CodexNodeSpace = {
|
|||||||
*/
|
*/
|
||||||
quotaReservedBytes: number;
|
quotaReservedBytes: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type UploadResponse = {
|
||||||
|
result: Promise<SafeValue<string>>;
|
||||||
|
abort: () => void;
|
||||||
|
};
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Api } from "../api/config";
|
import { Api } from "../api/config";
|
||||||
import { CodexValibotIssuesMap } from "../errors/errors";
|
import { CodexValibotIssuesMap } from "../errors/errors";
|
||||||
import { Fetch } from "../fetch-safe/fetch-safe";
|
import { Fetch } from "../fetch-safe/fetch-safe";
|
||||||
|
import type { SafeValue } from "../values/values";
|
||||||
import { CodexLogLevel, type CodexDebugInfo } from "./types";
|
import { CodexLogLevel, type CodexDebugInfo } from "./types";
|
||||||
import * as v from "valibot";
|
import * as v from "valibot";
|
||||||
|
|
||||||
@ -14,17 +15,17 @@ export class Debug {
|
|||||||
/**
|
/**
|
||||||
* Set log level at run time
|
* Set log level at run time
|
||||||
*/
|
*/
|
||||||
setLogLevel(level: CodexLogLevel) {
|
setLogLevel(level: CodexLogLevel): Promise<SafeValue<Response>> {
|
||||||
const result = v.safeParse(CodexLogLevel, level);
|
const result = v.safeParse(CodexLogLevel, level);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return {
|
return Promise.resolve({
|
||||||
error: true,
|
error: true,
|
||||||
data: {
|
data: {
|
||||||
message: "Cannot validate the input",
|
message: "Cannot validate the input",
|
||||||
errors: CodexValibotIssuesMap(result.issues),
|
errors: CodexValibotIssuesMap(result.issues),
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const url =
|
const url =
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export * from "./data/types";
|
|||||||
export * from "./values/values";
|
export * from "./values/values";
|
||||||
export * from "./errors/errors";
|
export * from "./errors/errors";
|
||||||
|
|
||||||
export { type CodexData, type UploadResponse } from "./data/data";
|
export { type CodexData } from "./data/data";
|
||||||
|
|
||||||
export class Codex {
|
export class Codex {
|
||||||
readonly url: string;
|
readonly url: string;
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Bundler",
|
"moduleResolution": "Bundler",
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"sourceMap": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user