@jsonbored/metagraphed 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/index.cjs +39 -0
- package/dist/index.d.cts +5906 -0
- package/dist/index.d.ts +5906 -0
- package/dist/index.js +37 -0
- package/package.json +47 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/metagraphed-client.ts
|
|
2
|
+
async function metagraphedFetch(path, options = {}) {
|
|
3
|
+
const { baseUrl = "https://api.metagraph.sh", pathParams, query, ...init } = options;
|
|
4
|
+
const resolvedPath = interpolatePath(
|
|
5
|
+
String(path),
|
|
6
|
+
pathParams
|
|
7
|
+
);
|
|
8
|
+
const url = new URL(resolvedPath, baseUrl);
|
|
9
|
+
for (const [key, value] of Object.entries(query || {})) {
|
|
10
|
+
if (value !== void 0 && value !== null) {
|
|
11
|
+
url.searchParams.set(key, String(value));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const response = await fetch(url, {
|
|
15
|
+
...init,
|
|
16
|
+
method: "GET",
|
|
17
|
+
headers: {
|
|
18
|
+
accept: "application/json",
|
|
19
|
+
...init.headers || {}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return await response.json();
|
|
23
|
+
}
|
|
24
|
+
function interpolatePath(path, params) {
|
|
25
|
+
if (!params) {
|
|
26
|
+
return path;
|
|
27
|
+
}
|
|
28
|
+
return path.replace(/\{([^}]+)\}/g, (_match, key) => {
|
|
29
|
+
const value = params[key];
|
|
30
|
+
if (value === void 0 || value === null) {
|
|
31
|
+
throw new Error(`Missing path parameter: ${key}`);
|
|
32
|
+
}
|
|
33
|
+
return encodeURIComponent(String(value));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { metagraphedFetch };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsonbored/metagraphed",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed TypeScript client for the metagraph.sh backend API — operational metadata, health, schemas, and interface discovery for Bittensor subnets.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://metagraph.sh",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/JSONbored/metagraphed.git",
|
|
11
|
+
"directory": "packages/client"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"bittensor",
|
|
15
|
+
"metagraph",
|
|
16
|
+
"subnet",
|
|
17
|
+
"registry",
|
|
18
|
+
"api-client"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"sync": "node scripts/sync-generated.mjs",
|
|
40
|
+
"build": "npm run sync && tsup src/index.ts --format esm,cjs --dts --clean --treeshake",
|
|
41
|
+
"prepublishOnly": "npm run build"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
|
+
"typescript": "^5.9.0"
|
|
46
|
+
}
|
|
47
|
+
}
|