Skip to content

Commit 3bf517d

Browse files
authored
chore: generate types from open api (#14)
* Generate types from the open api file * Update dependencies * Update dependencies * Update the openapi schema * Fix merge * Fix doc reference
1 parent 921bb61 commit 3bf517d

19 files changed

+4022
-457
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
dist
3-
*.tgz
3+
*.tgz
4+
index.bundle.js

README.md

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ The SDK is currently under early development and the API can change at any time.
1010

1111
- Version 0.1.0 introduces [upload strategy](#upload) to support browser and Node JS.
1212

13+
## Types generation
14+
15+
The types are generated from the openapi.yaml using the commande:
16+
17+
```bash
18+
npx openapi-typescript ./openapi.yaml -o src/openapi.ts --default-non-nullable false
19+
```
20+
1321
## How to use
1422

1523
### Sync api
@@ -126,7 +134,7 @@ const marketplace = codex.marketplace;
126134

127135
Returns active slots.
128136

129-
- returns Promise<[CodexSlot](./src/marketplace/types.ts#L85)[]>
137+
- returns Promise<[CodexSlot](./src/marketplace/types.ts#L7)[]>
130138

131139
Example:
132140

@@ -139,7 +147,7 @@ const slots = await marketplace.activeSlots();
139147
Returns active slot with id {slotId} for the host.
140148

141149
- slotId (string, required)
142-
- returns Promise<[CodexSlot](./src/marketplace/types.ts#L85)[]>
150+
- returns Promise<[CodexSlotAgent](./src/marketplace/types.ts#L12)[]>
143151

144152
Example:
145153

@@ -152,7 +160,7 @@ const slot = await marketplace.activeSlot(slotId);
152160

153161
Returns storage that is for sale.
154162

155-
- returns Promise<[CodexAvailability](./src/marketplace/types.ts#L99)>
163+
- returns Promise<[CodexAvailability](./src/marketplace/types.ts#L20)>
156164

157165
Example:
158166

@@ -164,8 +172,8 @@ const availabilities = await marketplace.availabilities();
164172

165173
Offers storage for sale.
166174

167-
- input ([CodexCreateAvailabilityInput](./src/marketplace/types.ts#L175), required)
168-
- returns Promise<[CodexAvailabilityCreateResponse](./src/marketplace/types.ts#L186)[]>
175+
- input ([CodexCreateAvailabilityInput](./src/marketplace/types.ts#L45), required)
176+
- returns Promise<[CodexAvailability](./src/marketplace/types.ts#L20)[]>
169177

170178
Example:
171179

@@ -182,7 +190,7 @@ const response = await marketplace.createAvailability({
182190

183191
Updates availability.
184192

185-
- input ([CodexUpdateAvailabilityInput](./src/marketplace/types.ts#L186), required)
193+
- input ([CodexAvailabilityPatchInput](./src/marketplace/types.ts#L66), required)
186194
- returns Promise<"">
187195

188196
Example:
@@ -202,7 +210,7 @@ const response = await marketplace.updateAvailability({
202210
Return list of reservations for ongoing Storage Requests that the node hosts.
203211

204212
- availabilityId (string, required)
205-
- returns Promise<[CodexReservation](./src/marketplace/types.ts#L198)[]>
213+
- returns Promise<[CodexReservation](./src/marketplace/types.ts#L83)[]>
206214

207215
Example:
208216

@@ -214,7 +222,7 @@ const reservations = await marketplace.reservations("Ox...");
214222

215223
Creates a new Request for storage
216224

217-
- input ([CodexCreateStorageRequestInput](./src/marketplace/types.ts#L230), required)
225+
- input ([CodexCreateStorageRequestInput](./src/marketplace/types.ts#L120), required)
218226
- returns Promise<string>
219227

220228
Example:
@@ -248,7 +256,7 @@ const ids = await marketplace.purchaseIds();
248256
Returns purchase details
249257

250258
- purchaseId (string, required)
251-
- returns Promise<[CodexPurchase](./src/marketplace/types.ts#L214)[]>
259+
- returns Promise<[CodexPurchase](./src/marketplace/types.ts#L103)[]>
252260

253261
Example:
254262

@@ -274,7 +282,7 @@ const data = codex.data;
274282

275283
Returns the manifest stored locally in node.
276284

277-
- returns Promise<[CodexDataResponse](./src/data/types.ts#L54)[]>
285+
- returns Promise<[CodexDataItem](./src/data/types.ts#L8)[]>
278286

279287
Example:
280288

@@ -286,7 +294,7 @@ const cids = await data.cids();
286294

287295
Returns a summary of the storage space allocation of the node
288296

289-
- returns Promise<[CodexNodeSpace](./src/data/types.ts#L56)[]>
297+
- returns Promise<[CodexNodeSpace](./src/data/types.ts#L15)[]>
290298

291299
Example:
292300

@@ -301,7 +309,7 @@ Upload a file in a streaming manner
301309
#### Browser
302310

303311
- stategy [BrowserUploadStategy](./src/data/browser-upload.ts#L5)
304-
- returns [UploadResponse](./src/data/types.ts#L80)
312+
- returns [UploadResponse](./src/data/types.ts#L17)
305313

306314
Example:
307315

@@ -330,8 +338,8 @@ console.info("CID is", res.data);
330338

331339
#### Node
332340

333-
- stategy [NodeUploadStategy](./src/data/node-download.ts#L8)
334-
- returns [UploadResponse](./src/data/types.ts#L80)
341+
- stategy [NodeUploadStategy](./src/data/node-upload.ts#L9)
342+
- returns [UploadResponse](./src/data/types.ts#L17)
335343

336344
Example:
337345

@@ -354,7 +362,7 @@ console.info("CID is", res.data);
354362
Download only the dataset manifest from the network to the local node if it's not available locally.
355363

356364
- cid (string, required)
357-
- returns [CodexManifest](./src/data/types.ts#L3)
365+
- returns [CodexManifest](./src/data/types.ts#L30)
358366

359367
Example:
360368

@@ -410,7 +418,7 @@ const data = codex.debug;
410418

411419
Set log level at run time.
412420

413-
- level ([CodexLogLevel](./src/debug/types.ts#L3), required)
421+
- level ([CodexLogLevel](./src/debug/types.ts#L7), required)
414422
- returns Promise<"">
415423

416424
Example:
@@ -423,7 +431,7 @@ await debug.setLogLevel("DEBUG");
423431

424432
Gets node information
425433

426-
- returns Promise<[CodexDebugInfo](./src/debug/types.ts#L15)>
434+
- returns Promise<[CodexDebugInfo](./src/debug/types.ts#L23)>
427435

428436
Example:
429437

@@ -448,10 +456,44 @@ const node = codex.node;
448456

449457
Get Node's SPR
450458

451-
- returns Promise<[CodexSpr](./src/node/types.ts#L1)>
459+
- returns Promise<[CodexSpr](./src/node/types.ts#L11)>
452460

453461
Example:
454462

455463
```js
456464
const spr = await node.spr();
457465
```
466+
467+
By default, the response will be a json. You can use `text` option to get the string:
468+
469+
#### peeriD
470+
471+
Get Node's peer id
472+
473+
- returns Promise<[CodexPeerId](./src/node/types.ts#L25)>
474+
475+
Example:
476+
477+
```js
478+
const peerId = await node.peerId();
479+
```
480+
481+
By default, the response will be a json. You can use `text` option to get the string:
482+
483+
```js
484+
const peerId = await node.peerId("text");
485+
```
486+
487+
#### connect
488+
489+
Connect to a peer
490+
491+
- returns Promise<string>
492+
493+
Example:
494+
495+
```js
496+
const peerId = "..."
497+
const addrs = [...]
498+
const spr = await node.connect(peerId, addrs);
499+
```

examples/upload-node/package-lock.json

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/upload-node/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
"name": "@codex-storage/sdk-js-update-node-example",
33
"version": "1.0.0",
44
"main": "index.js",
5-
"scripts": {
6-
"build": "node esbuild.js"
7-
},
5+
"scripts": {},
86
"author": "",
97
"license": "ISC",
108
"description": "",
119
"dependencies": {
1210
"@codex-storage/sdk-js": "../..",
13-
"undici": "^7.6.0"
11+
"undici": "^7.7.0"
1412
},
1513
"devDependencies": {
1614
"prettier": "^3.5.3"
1715
}
18-
}
16+
}

0 commit comments

Comments
 (0)