@shirokasoke/webapi-sdk 2.9.0-beta3-0.14-pre → 2.9.0-beta3-0.17-pre

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.
Files changed (62) hide show
  1. package/README.md +95 -0
  2. package/package.json +2 -2
  3. package/dist/client.d.ts +0 -617
  4. package/dist/client.js +0 -736
  5. package/dist/index.d.ts +0 -3
  6. package/dist/index.js +0 -22
  7. package/dist/types/ae2.d.ts +0 -162
  8. package/dist/types/ae2.js +0 -2
  9. package/dist/types/block.d.ts +0 -97
  10. package/dist/types/block.js +0 -2
  11. package/dist/types/chunk.d.ts +0 -57
  12. package/dist/types/chunk.js +0 -2
  13. package/dist/types/common.d.ts +0 -27
  14. package/dist/types/common.js +0 -2
  15. package/dist/types/entity.d.ts +0 -132
  16. package/dist/types/entity.js +0 -2
  17. package/dist/types/fluid.d.ts +0 -34
  18. package/dist/types/fluid.js +0 -2
  19. package/dist/types/fmp.d.ts +0 -33
  20. package/dist/types/fmp.js +0 -2
  21. package/dist/types/gt5.d.ts +0 -216
  22. package/dist/types/gt5.js +0 -2
  23. package/dist/types/index.d.ts +0 -13
  24. package/dist/types/index.js +0 -29
  25. package/dist/types/item.d.ts +0 -45
  26. package/dist/types/item.js +0 -2
  27. package/dist/types/rawInfo.d.ts +0 -25
  28. package/dist/types/rawInfo.js +0 -2
  29. package/dist/types/recipe.d.ts +0 -114
  30. package/dist/types/recipe.js +0 -2
  31. package/dist/types/threeD.d.ts +0 -43
  32. package/dist/types/threeD.js +0 -2
  33. package/dist/types/world.d.ts +0 -58
  34. package/dist/types/world.js +0 -2
  35. package/dist/validators/ae2.d.ts +0 -63
  36. package/dist/validators/ae2.js +0 -169
  37. package/dist/validators/block.d.ts +0 -12
  38. package/dist/validators/block.js +0 -101
  39. package/dist/validators/chunk.d.ts +0 -9
  40. package/dist/validators/chunk.js +0 -64
  41. package/dist/validators/common.d.ts +0 -8
  42. package/dist/validators/common.js +0 -36
  43. package/dist/validators/entity.d.ts +0 -10
  44. package/dist/validators/entity.js +0 -133
  45. package/dist/validators/fluid.d.ts +0 -6
  46. package/dist/validators/fluid.js +0 -36
  47. package/dist/validators/fmp.d.ts +0 -4
  48. package/dist/validators/fmp.js +0 -40
  49. package/dist/validators/gt5.d.ts +0 -26
  50. package/dist/validators/gt5.js +0 -197
  51. package/dist/validators/index.d.ts +0 -13
  52. package/dist/validators/index.js +0 -29
  53. package/dist/validators/item.d.ts +0 -14
  54. package/dist/validators/item.js +0 -39
  55. package/dist/validators/rawInfo.d.ts +0 -6
  56. package/dist/validators/rawInfo.js +0 -31
  57. package/dist/validators/recipe.d.ts +0 -30
  58. package/dist/validators/recipe.js +0 -83
  59. package/dist/validators/threeD.d.ts +0 -8
  60. package/dist/validators/threeD.js +0 -40
  61. package/dist/validators/world.d.ts +0 -5
  62. package/dist/validators/world.js +0 -65
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
+ [![最新构建(java)](https://img.shields.io/github/actions/workflow/status/Rcrwrate/McWebAPI/build-and-test.yml?logo=github&label=Build%20and%20test)](https://github.com/Rcrwrate/McWebAPI/actions/workflows/build-and-test.yml)
6
+ [![最新发布](https://img.shields.io/github/v/release/Rcrwrate/MCWebAPI)](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` |
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shirokasoke/webapi-sdk",
3
- "version": "2.9.0-beta3-0.14-pre",
3
+ "version": "2.9.0-beta3-0.17-pre",
4
4
  "private": false,
5
5
  "description": "TypeScript SDK for the love.shirokasoke.WebAPI Minecraft Mod",
6
6
  "main": "./dist/index.js",
@@ -36,6 +36,6 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@microsoft/fetch-event-source": "^2.0.1",
39
- "joi": "^18.2.9"
39
+ "joi": "^18.3.0"
40
40
  }
41
41
  }