@shirokasoke/webapi-sdk 2.9.0-1.2
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 +95 -0
- package/dist/client.d.ts +682 -0
- package/dist/client.js +793 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +23 -0
- package/dist/types/ae2.d.ts +241 -0
- package/dist/types/ae2.js +2 -0
- package/dist/types/block.d.ts +97 -0
- package/dist/types/block.js +2 -0
- package/dist/types/chunk.d.ts +58 -0
- package/dist/types/chunk.js +2 -0
- package/dist/types/common.d.ts +33 -0
- package/dist/types/common.js +2 -0
- package/dist/types/entity.d.ts +132 -0
- package/dist/types/entity.js +2 -0
- package/dist/types/fluid.d.ts +34 -0
- package/dist/types/fluid.js +2 -0
- package/dist/types/fmp.d.ts +33 -0
- package/dist/types/fmp.js +2 -0
- package/dist/types/gt5.d.ts +306 -0
- package/dist/types/gt5.js +2 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +29 -0
- package/dist/types/item.d.ts +45 -0
- package/dist/types/item.js +2 -0
- package/dist/types/rawInfo.d.ts +25 -0
- package/dist/types/rawInfo.js +2 -0
- package/dist/types/recipe.d.ts +114 -0
- package/dist/types/recipe.js +2 -0
- package/dist/types/threeD.d.ts +43 -0
- package/dist/types/threeD.js +2 -0
- package/dist/types/world.d.ts +58 -0
- package/dist/types/world.js +2 -0
- package/dist/utils/ae2.d.ts +42 -0
- package/dist/utils/ae2.js +89 -0
- package/dist/validators/ae2.d.ts +85 -0
- package/dist/validators/ae2.js +234 -0
- package/dist/validators/block.d.ts +12 -0
- package/dist/validators/block.js +101 -0
- package/dist/validators/chunk.d.ts +9 -0
- package/dist/validators/chunk.js +65 -0
- package/dist/validators/common.d.ts +8 -0
- package/dist/validators/common.js +38 -0
- package/dist/validators/entity.d.ts +10 -0
- package/dist/validators/entity.js +133 -0
- package/dist/validators/fluid.d.ts +6 -0
- package/dist/validators/fluid.js +36 -0
- package/dist/validators/fmp.d.ts +4 -0
- package/dist/validators/fmp.js +40 -0
- package/dist/validators/gt5.d.ts +35 -0
- package/dist/validators/gt5.js +259 -0
- package/dist/validators/index.d.ts +13 -0
- package/dist/validators/index.js +29 -0
- package/dist/validators/item.d.ts +14 -0
- package/dist/validators/item.js +39 -0
- package/dist/validators/rawInfo.d.ts +6 -0
- package/dist/validators/rawInfo.js +31 -0
- package/dist/validators/recipe.d.ts +30 -0
- package/dist/validators/recipe.js +83 -0
- package/dist/validators/threeD.d.ts +8 -0
- package/dist/validators/threeD.js +40 -0
- package/dist/validators/world.d.ts +5 -0
- package/dist/validators/world.js +65 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @shirokasoke/webapi-sdk
|
|
2
|
+
|
|
3
|
+
[MC WebAPI](https://github.com/Rcrwrate/McWebAPI) 的 TypeScript SDK
|
|
4
|
+
|
|
5
|
+
[](https://github.com/Rcrwrate/McWebAPI/actions/workflows/build-and-test.yml)
|
|
6
|
+
[](https://github.com/Rcrwrate/McWebAPI/releases/latest)
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @shirokasoke/webapi-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 快速开始
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { WebApiClient, WebApiError } from "@shirokasoke/webapi-sdk";
|
|
18
|
+
|
|
19
|
+
const client = new WebApiClient({
|
|
20
|
+
baseUrl: "http://localhost:40002",
|
|
21
|
+
authToken: "xxx", // 可选,原值作为 Authorization 头发送
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const tps = await client.getTPS(); // Record<string, TPSInfo>
|
|
25
|
+
const block = await client.getBlock({ x: 64, y: 64, z: 64, dim: 0 });
|
|
26
|
+
const icon = await client.getItemIcon({ id: 4 }); // ArrayBuffer
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- 所有方法返回 `ApiResponse<T>` 解包后的 `data`;HTTP 错误或业务失败(`success=false`)抛出 `WebApiError`(含 `message` / `status` / `body`)
|
|
30
|
+
- 图片、贴图等二进制接口返回 `ArrayBuffer`
|
|
31
|
+
- 依赖全局 `fetch`(Node 18+),或通过 `options.fetch` 注入实现
|
|
32
|
+
|
|
33
|
+
## API 一览
|
|
34
|
+
|
|
35
|
+
| 分组 | 方法 |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| 状态 | `getRoot` `getTPS` `getProfiler` `getLagAnalyzer` `getWorldInfo` `checkSSE` |
|
|
38
|
+
| 物品 | `getItems` `getItem` `getItemIcon` `getAEItemsDef` |
|
|
39
|
+
| 方块 | `getBlocks` `getBlock` `setBlock` `batchSetBlock` `getBatchSetBlockJob` `waitForBatchSetBlockJob` `getBlockFMP` `getBlockTile` |
|
|
40
|
+
| 区块 | `getChunks` `getChunk` `getChunkMap` `getChunkForceList` `loadChunk` `unloadChunk` |
|
|
41
|
+
| 实体 | `getEntities` `getEntity` |
|
|
42
|
+
| 流体 | `getFluids` `getFluidContainers` `getFluidIcon` |
|
|
43
|
+
| GT5 | `getGT5Machine` `setGT5MachineStatus` `submitGT5Batch` `getGT5BatchJob` `rerunGT5Batch` `waitForGT5BatchJob` `submitGT5ChunkScan` `getGT5ScanJob` `waitForGT5ScanJob` `getGT5Vein` `getGT5Veins` `getGT5VeinDefs` |
|
|
44
|
+
| AE2 | `aeHit` `aeNodes` `aeCPUs` `aeME` `aeMEs` `aeMESupport` `aeItems` `aeCraft` `aeCancel` `aeSuspend` |
|
|
45
|
+
| 配方 | `getCraftingRecipes` `getFurnaceRecipes` `getGTRecipes` `getGTRecipeMaps` |
|
|
46
|
+
| 3D 打印 | `printToPlayer` `submitWorldPrint` `getWorldPrintJob` `waitForWorldPrintJob` `getPrintSize` |
|
|
47
|
+
|
|
48
|
+
每个方法都有对应的类型(`src/types`)与 Joi 校验 Schema(`src/validators`)一并导出,详见源码 JSDoc
|
|
49
|
+
|
|
50
|
+
## SSE 订阅
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const ctrl = client.aeCpuSseCallback(
|
|
54
|
+
{ x: 64, y: 64, z: 64 },
|
|
55
|
+
cpus => console.log(cpus),
|
|
56
|
+
err => console.error(err),
|
|
57
|
+
);
|
|
58
|
+
ctrl.abort(); // 停止订阅
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
基于 `@microsoft/fetch-event-source`,可携带 `Authorization` 头。相关路由仅在服务端启用虚拟线程(`useVirtualThreads`)时注册,使用前可 `await client.checkSSE()` 探测。
|
|
62
|
+
|
|
63
|
+
## AE 合成与合成树分析
|
|
64
|
+
|
|
65
|
+
`aeCraft` 的 `detail` 参数控制合成树输出:`"all"` 始终返回、`"fail"`(默认)仅在失败时随错误 `body` 返回、`"none"` 不返回。
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { analyzeAECraftingJobTree, type AECraftingTaskErrorBody } from "@shirokasoke/webapi-sdk";
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const result = await client.aeCraft({ x: 64, y: 64, z: 64 }, { id: 1234, Count: 1 });
|
|
72
|
+
if (result.job) {
|
|
73
|
+
const analysis = analyzeAECraftingJobTree(result.job);
|
|
74
|
+
console.log(analysis);
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (e instanceof WebApiError && e.body) {
|
|
78
|
+
// 模拟失败(材料不足)时,错误 body 中携带失败时的合成树
|
|
79
|
+
const tree = (e.body as AECraftingTaskErrorBody).body;
|
|
80
|
+
console.log(analyzeAECraftingJobTree(tree));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 开发
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run build # tsc 构建到 dist/
|
|
89
|
+
tsx --test test/singlefile # 运行测试每次一个,勿并行
|
|
90
|
+
# npm run web # 构建并同步到 web/node_modules/@shirokasoke/webapi-sdk/
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|