Skip to content

Commit f12538a

Browse files
author
Developer
committed
feat: implement Phase 6.5 - Advanced CID API with comprehensive test suite
Adds optional CID-aware API for advanced users without affecting path-based API simplicity: - CID utilities (formatCID, parseCID, verifyCID, cidToString) with 38 tests - FS5Advanced class (pathToCID, cidToPath, getByCID, putByCID, putWithCID) with 36 tests - Advanced export package (s5/advanced) separate from main API - Bundle analysis: 59.53 KB compressed (well under 450 KB target) - Total: 74 tests passing, grant compliant (60.09 KB full bundle)
1 parent 3648464 commit f12538a

File tree

10 files changed

+1696
-2
lines changed

10 files changed

+1696
-2
lines changed

docs/BUNDLE_ANALYSIS.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# S5.js Bundle Analysis Report
22

3-
**Generated:** 2025-10-17T21:36:18.716Z
3+
**Generated:** 2025-10-17T22:26:16.143Z
44

55
## Executive Summary
66

@@ -12,6 +12,7 @@ This report analyzes bundle sizes for different entry points of the S5.js librar
1212
|--------|-----|------|--------|--------|
1313
| Core | 214.72 KB | 71.75 KB | 59.61 KB | ✅ Pass |
1414
| Media | 35.98 KB | 11.03 KB | 9.79 KB | ✅ Pass |
15+
| Advanced | 214.92 KB | 71.35 KB | 59.53 KB | ✅ Pass |
1516
| Full | 217.15 KB | 72.37 KB | 60.09 KB | ✅ Pass |
1617

1718
## Tree-Shaking Analysis
@@ -56,6 +57,21 @@ The modular export structure enables consumers to import only what they need:
5657
- Input files: 9
5758
- Output modules: 1
5859

60+
### Advanced
61+
62+
**Description:** Advanced CID-aware API with core functionality
63+
64+
**Entry Point:** `dist/src/exports/advanced.js`
65+
66+
**Sizes:**
67+
- Raw: 214.92 KB
68+
- Gzipped: 71.35 KB (33.2% of raw)
69+
- Brotli: 59.53 KB (27.7% of raw)
70+
71+
**Metadata:**
72+
- Input files: 295
73+
- Output modules: 1
74+
5975
### Full
6076

6177
**Description:** Complete SDK with all features
@@ -112,6 +128,7 @@ The library uses a modular export structure with separate entry points:
112128
1. **Main export** (`s5`): Full SDK with all features
113129
2. **Core export** (`s5/core`): File system operations only
114130
3. **Media export** (`s5/media`): Media processing with lazy loading
131+
4. **Advanced export** (`s5/advanced`): CID-aware API for power users
115132

116133
### Lazy Loading
117134

docs/IMPLEMENTATION.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,59 @@
332332
- [x] Verify bundle size ≤ 700KB compressed (60.09 KB brotli - 10x under limit!) ✅
333333
- [x] Create bundle analysis report (docs/BUNDLE_ANALYSIS.md, bundle-analysis.json)
334334

335+
### Phase 6.5: Advanced CID API (Optional Enhancement)
336+
337+
**Goal**: Provide CID-level access for advanced developers without affecting path-based API simplicity
338+
339+
- [x] **6.5.1 Test Suite First (TDD)** ✅ COMPLETE
340+
- [x] Create test/fs/fs5-advanced.test.ts (~40 tests)
341+
- [x] Write tests for CID extraction (pathToCID)
342+
- [x] Write tests for CID lookup (cidToPath)
343+
- [x] Write tests for direct CID operations (getByCID, putByCID)
344+
- [x] Write tests for combined operations (putWithCID)
345+
- [x] Create test/fs/cid-utils.test.ts (~50 tests)
346+
- [x] Write tests for CID utilities (format, parse, verify)
347+
348+
- [x] **6.5.2 CID Utilities** ✅ COMPLETE
349+
- [x] Create src/fs/cid-utils.ts
350+
- [x] Implement formatCID(cid, encoding) - multibase formatting
351+
- [x] Implement parseCID(cidString) - parse various formats
352+
- [x] Implement verifyCID(cid, data) - verify CID matches data
353+
- [x] Implement cidToString(cid) - human-readable format
354+
- [x] Add comprehensive unit tests (38/38 tests passing)
355+
356+
- [x] **6.5.3 FS5Advanced Class** ✅ COMPLETE
357+
- [x] Create src/fs/fs5-advanced.ts
358+
- [x] Implement constructor(fs5: FS5)
359+
- [x] Implement async pathToCID(path: string): Promise<Uint8Array>
360+
- [x] Implement async cidToPath(cid: Uint8Array): Promise<string | null>
361+
- [x] Implement async getByCID(cid: Uint8Array): Promise<any>
362+
- [x] Implement async putByCID(data: any): Promise<Uint8Array>
363+
- [x] Implement async putWithCID(path: string, data: any, options?): Promise<{ path: string, cid: Uint8Array }>
364+
- [x] Implement async getMetadataWithCID(path: string): Promise<{ metadata: any, cid: Uint8Array }>
365+
- [x] All 36 tests passing
366+
367+
- [x] **6.5.4 Advanced Export Package** ✅ COMPLETE
368+
- [x] Create src/exports/advanced.ts
369+
- [x] Export FS5Advanced class
370+
- [x] Export CID utility functions
371+
- [x] Export FileRef, DirRef, DirLink types
372+
- [x] Export BlobLocation types
373+
- [x] Add to package.json exports: `"./advanced": "./dist/src/exports/advanced.js"`
374+
375+
- [x] **6.5.5 Bundle Verification** ✅ COMPLETE
376+
- [x] Run bundle analysis with advanced export
377+
- [x] Verify tree-shaking works (advanced similar to core)
378+
- [x] Advanced export is 59.53 KB compressed (similar to core)
379+
- [x] Update BUNDLE_ANALYSIS.md with advanced bundle stats
380+
381+
- [ ] **6.5.6 Documentation**
382+
- [ ] Add Advanced API section to docs/API.md
383+
- [ ] Create examples for CID operations
384+
- [ ] Document when to use advanced vs. path-based API
385+
- [ ] Add JSDoc comments to all public methods
386+
- [ ] Update README with advanced import example
387+
335388
### Phase 7: Testing & Performance (Grant Month 7)
336389

337390
- [ ] **7.1 Comprehensive Test Suite**

docs/bundle-analysis.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"timestamp": "2025-10-17T21:36:18.718Z",
2+
"timestamp": "2025-10-17T22:26:16.144Z",
33
"bundles": [
44
{
55
"name": "Core",
@@ -29,6 +29,20 @@
2929
"modules": 1
3030
}
3131
},
32+
{
33+
"name": "Advanced",
34+
"description": "Advanced CID-aware API with core functionality",
35+
"entryPoint": "dist/src/exports/advanced.js",
36+
"sizes": {
37+
"raw": 220078,
38+
"gzipped": 73067,
39+
"brotli": 60954
40+
},
41+
"metadata": {
42+
"inputs": 295,
43+
"modules": 1
44+
}
45+
},
3246
{
3347
"name": "Full",
3448
"description": "Complete SDK with all features",

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"import": "./dist/src/exports/media.js",
2424
"default": "./dist/src/exports/media.js"
2525
},
26+
"./advanced": {
27+
"types": "./dist/src/exports/advanced.d.ts",
28+
"import": "./dist/src/exports/advanced.js",
29+
"default": "./dist/src/exports/advanced.js"
30+
},
2631
"./dist/*": "./dist/*"
2732
},
2833
"scripts": {

scripts/analyze-bundle.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const bundles = [
4545
description: 'Media processing modules only',
4646
expectedMaxSizeKB: 300, // Media processing
4747
},
48+
{
49+
name: 'Advanced',
50+
entryPoint: 'dist/src/exports/advanced.js',
51+
description: 'Advanced CID-aware API with core functionality',
52+
expectedMaxSizeKB: 450, // Core + CID utilities
53+
},
4854
{
4955
name: 'Full',
5056
entryPoint: 'dist/src/index.js',
@@ -315,6 +321,7 @@ The library uses a modular export structure with separate entry points:
315321
1. **Main export** (\`s5\`): Full SDK with all features
316322
2. **Core export** (\`s5/core\`): File system operations only
317323
3. **Media export** (\`s5/media\`): Media processing with lazy loading
324+
4. **Advanced export** (\`s5/advanced\`): CID-aware API for power users
318325
319326
### Lazy Loading
320327

src/exports/advanced.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Advanced S5.js API - CID-aware operations for power users
3+
*
4+
* This module provides low-level CID (Content Identifier) operations for advanced
5+
* developers who need content-addressed storage capabilities.
6+
*
7+
* @example
8+
* ```typescript
9+
* import { S5 } from 's5';
10+
* import { FS5Advanced, formatCID, parseCID } from 's5/advanced';
11+
*
12+
* const s5 = await S5.create();
13+
* await s5.recoverIdentityFromSeedPhrase(seedPhrase);
14+
*
15+
* // Create advanced API instance
16+
* const advanced = new FS5Advanced(s5.fs);
17+
*
18+
* // Extract CID from path
19+
* const cid = await advanced.pathToCID('home/data.txt');
20+
*
21+
* // Format CID for display
22+
* const formatted = formatCID(cid, 'base32');
23+
* console.log(formatted);
24+
*
25+
* // Parse CID from string
26+
* const parsed = parseCID(formatted);
27+
*
28+
* // Retrieve data by CID
29+
* const data = await advanced.getByCID(cid);
30+
* ```
31+
*/
32+
33+
// Core advanced API class
34+
export { FS5Advanced } from '../fs/fs5-advanced.js';
35+
export type { PutWithCIDResult, MetadataWithCIDResult } from '../fs/fs5-advanced.js';
36+
37+
// CID utility functions
38+
export {
39+
formatCID,
40+
parseCID,
41+
verifyCID,
42+
cidToString,
43+
} from '../fs/cid-utils.js';
44+
45+
// DirV1 types for advanced users
46+
export type {
47+
DirV1,
48+
FileRef,
49+
DirRef,
50+
DirLink,
51+
BlobLocation,
52+
HAMTShardingConfig,
53+
PutOptions,
54+
ListOptions,
55+
GetOptions,
56+
ListResult,
57+
} from '../fs/dirv1/types.js';
58+
59+
// Re-export core S5 for convenience
60+
export { S5 } from '../s5.js';
61+
export { FS5 } from '../fs/fs5.js';

0 commit comments

Comments
 (0)