mooncakes-protocol
v0.1.0
Published
Protocol library for accessing mooncakes.io content and package data
Maintainers
Readme
Mooncakes Protocol
TypeScript protocol library for accessing mooncakes.io website content and package data.
Installation
npm install mooncakes-protocolFeatures
- Get module list and statistics
- Get module/package details
- Parse package documentation data (types, traits, functions, etc.)
- Support nested module structures
- Batch fetch multiple packages
- Download full module data recursively
- Complete TypeScript type definitions
Data Structures
Resource Types
Resource- Resource info, contains three kinds:Module- Module (root of package, contains metadata)Package- Sub-package (contains code documentation)RootPackage- Both module and package
Module Index
ModuleIndex- Tree-like index structure of modulePackageIndex- Package index containing types, traits, values, etc.
Package Data
PackageData- Complete package documentation dataTypeDoc- Type documentationTraitDoc- Trait documentationValueDoc- Value/function documentationImplDoc- Implementation documentation
Usage
import {
MooncakesClient,
getAllPackagePaths,
getDescendantPackages,
findNodeByPath,
} from 'mooncakes-protocol';
// Create client
const client = new MooncakesClient();
// Get recently updated modules
const recent = await client.getRecentModules(20);
// Get module resource info
const resource = await client.getResource('moonbitlang/core');
// Get package documentation data
const pkgData = await client.getPackageData('moonbitlang/core/array');
// Get module index
const index = await client.getModuleIndex('moonbitlang/core');
// Get all package paths from index
const paths = getAllPackagePaths(index);
// Find nested package node
const node = findNodeByPath(index, 'moonbitlang/core/immut/list');
// Get all descendant packages of a node
const packages = getDescendantPackages(node);
// Batch fetch multiple packages
const packageDataMap = await client.getPackageDataBatch(paths, (done, total) => {
console.log(`Progress: ${done}/${total}`);
});
// Download full module data (resource + index + all packages)
const fullData = await client.getFullModuleData('moonbitlang/core', (done, total, path) => {
console.log(`Fetching ${path} (${done}/${total})`);
});API Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| getRecentModules | /api/v0/modules/recent | Get recently updated modules |
| getAllModules | /api/v0/modules/all | Get all modules |
| getStatistics | /api/v0/modules/statistics | Get statistics |
| getUser | /api/v0/user/{username} | Get user info |
| getResource | /assets/{path}/resource.json | Get resource info |
| getPackageData | /assets/{path}/package_data.json | Get package data |
| getModuleIndex | /assets/{path}/module_index.json | Get module index |
Batch Operations
| Method | Description |
|--------|-------------|
| getPackageDataBatch | Fetch multiple packages concurrently |
| getFullModuleData | Download complete module with all packages |
Utility Functions
| Function | Description |
|----------|-------------|
| traverseModuleIndex | Iterate all nodes in module index |
| getPackageNodes | Get all nodes with package data |
| getAllPackagePaths | Get all package paths from index |
| findNodeByPath | Find node by path |
| getDescendantPackages | Get all descendant packages |
| getChildPackages | Get direct child packages |
| buildSearchEntries | Build search entries from index |
| fuzzySearch | Fuzzy search in entries |
