yeow-api 0.2.40 → 0.2.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeow-api",
3
- "version": "0.2.40",
3
+ "version": "0.2.42",
4
4
  "description": "Yeow API �?TypeScript OOP wrappers over the task protocol",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/assets.ts CHANGED
@@ -5,39 +5,37 @@ function _sendAssets(payload: Record<string, unknown>): unknown {
5
5
  return r;
6
6
  }
7
7
 
8
- export function read(path: string): Promise<string> {
8
+ function _sendAssetsAsync(payload: Record<string, unknown>): Promise<unknown> {
9
9
  return new Promise((resolve, reject) => {
10
- try {
11
- const r = _sendAssets({ t: 'read', p: { path } }) as { data: string };
12
- resolve(r.data);
13
- } catch (e) { reject(e); }
10
+ const cbId = _registerCallback((result: unknown) => {
11
+ if ((result as any)?.err) reject(new Error((result as any).err));
12
+ else resolve(result);
13
+ });
14
+ $send('assets', { ...payload, cb: cbId });
14
15
  });
15
16
  }
17
+
18
+ export async function read(path: string): Promise<string> {
19
+ const r = await _sendAssetsAsync({ t: 'read', p: { path } }) as { data: string };
20
+ return r.data;
21
+ }
16
22
  export function readSync(path: string): string {
17
23
  return (_sendAssets({ t: 'read', p: { path } }) as { data: string }).data;
18
24
  }
19
25
 
20
- export function readBase64(path: string): Promise<string> {
21
- return new Promise((resolve, reject) => {
22
- try {
23
- const r = _sendAssets({ t: 'readBase64', p: { path } }) as { data: string };
24
- resolve(r.data);
25
- } catch (e) { reject(e); }
26
- });
26
+ export async function readBase64(path: string): Promise<string> {
27
+ const r = await _sendAssetsAsync({ t: 'readBase64', p: { path } }) as { data: string };
28
+ return r.data;
27
29
  }
28
30
  export function readBase64Sync(path: string): string {
29
31
  return (_sendAssets({ t: 'readBase64', p: { path } }) as { data: string }).data;
30
32
  }
31
33
 
32
- export function extract(path: string, dest?: string): Promise<string> {
33
- return new Promise((resolve, reject) => {
34
- try {
35
- const p: Record<string, unknown> = { path };
36
- if (dest) p.dest = dest;
37
- const r = _sendAssets({ t: 'extract', p }) as { path: string };
38
- resolve(r.path);
39
- } catch (e) { reject(e); }
40
- });
34
+ export async function extract(path: string, dest?: string): Promise<string> {
35
+ const p: Record<string, unknown> = { path };
36
+ if (dest) p.dest = dest;
37
+ const r = await _sendAssetsAsync({ t: 'extract', p }) as { path: string };
38
+ return r.path;
41
39
  }
42
40
  export function extractSync(path: string, dest?: string): string {
43
41
  const p: Record<string, unknown> = { path };
package/src/fs.ts CHANGED
@@ -5,116 +5,89 @@ function _sendFs(payload: Record<string, unknown>): unknown {
5
5
  return r;
6
6
  }
7
7
 
8
- export function readFile(path: string): Promise<string> {
8
+ function _sendFsAsync(payload: Record<string, unknown>): Promise<unknown> {
9
9
  return new Promise((resolve, reject) => {
10
- try {
11
- const r = _sendFs({ t: 'readFile', p: { path } }) as { data: string };
12
- resolve(r.data);
13
- } catch (e) { reject(e); }
10
+ const cbId = _registerCallback((result: unknown) => {
11
+ if ((result as any)?.err) reject(new Error((result as any).err));
12
+ else resolve(result);
13
+ });
14
+ $send('fs', { ...payload, cb: cbId });
14
15
  });
15
16
  }
17
+
18
+ export async function readFile(path: string): Promise<string> {
19
+ const r = await _sendFsAsync({ t: 'readFile', p: { path } }) as { data: string };
20
+ return r.data;
21
+ }
16
22
  export function readFileSync(path: string): string {
17
23
  return (_sendFs({ t: 'readFile', p: { path } }) as { data: string }).data;
18
24
  }
19
25
 
20
- export function readFileBase64(path: string): Promise<string> {
21
- return new Promise((resolve, reject) => {
22
- try {
23
- const r = _sendFs({ t: 'readBase64', p: { path } }) as { data: string };
24
- resolve(r.data);
25
- } catch (e) { reject(e); }
26
- });
26
+ export async function readFileBase64(path: string): Promise<string> {
27
+ const r = await _sendFsAsync({ t: 'readBase64', p: { path } }) as { data: string };
28
+ return r.data;
27
29
  }
28
30
  export function readFileBase64Sync(path: string): string {
29
31
  return (_sendFs({ t: 'readBase64', p: { path } }) as { data: string }).data;
30
32
  }
31
33
 
32
- export function writeFile(path: string, data: string): Promise<void> {
33
- return new Promise((resolve, reject) => {
34
- try { _sendFs({ t: 'writeFile', p: { path, data } }); resolve(); }
35
- catch (e) { reject(e); }
36
- });
34
+ export async function writeFile(path: string, data: string): Promise<void> {
35
+ await _sendFsAsync({ t: 'writeFile', p: { path, data } });
37
36
  }
38
37
  export function writeFileSync(path: string, data: string): void {
39
38
  _sendFs({ t: 'writeFile', p: { path, data } });
40
39
  }
41
40
 
42
- export function writeFileBase64(path: string, data: string): Promise<void> {
43
- return new Promise((resolve, reject) => {
44
- try { _sendFs({ t: 'writeBase64', p: { path, data } }); resolve(); }
45
- catch (e) { reject(e); }
46
- });
41
+ export async function writeFileBase64(path: string, data: string): Promise<void> {
42
+ await _sendFsAsync({ t: 'writeBase64', p: { path, data } });
47
43
  }
48
44
  export function writeFileBase64Sync(path: string, data: string): void {
49
45
  _sendFs({ t: 'writeBase64', p: { path, data } });
50
46
  }
51
47
 
52
- export function appendFile(path: string, data: string): Promise<void> {
53
- return new Promise((resolve, reject) => {
54
- try { _sendFs({ t: 'appendFile', p: { path, data } }); resolve(); }
55
- catch (e) { reject(e); }
56
- });
48
+ export async function appendFile(path: string, data: string): Promise<void> {
49
+ await _sendFsAsync({ t: 'appendFile', p: { path, data } });
57
50
  }
58
51
  export function appendFileSync(path: string, data: string): void {
59
52
  _sendFs({ t: 'appendFile', p: { path, data } });
60
53
  }
61
54
 
62
- export function exists(path: string): Promise<boolean> {
63
- return new Promise((resolve, reject) => {
64
- try {
65
- const r = _sendFs({ t: 'exists', p: { path } });
66
- resolve(r === true || String(r) === 'true');
67
- } catch (e) { reject(e); }
68
- });
55
+ export async function exists(path: string): Promise<boolean> {
56
+ const r = await _sendFsAsync({ t: 'exists', p: { path } });
57
+ return r === true || String(r) === 'true';
69
58
  }
70
59
  export function existsSync(path: string): boolean {
71
60
  const r = _sendFs({ t: 'exists', p: { path } });
72
61
  return r === true || String(r) === 'true';
73
62
  }
74
63
 
75
- export function isDirectory(path: string): Promise<boolean> {
76
- return new Promise((resolve, reject) => {
77
- try {
78
- const r = _sendFs({ t: 'isDirectory', p: { path } });
79
- resolve(r === true || String(r) === 'true');
80
- } catch (e) { reject(e); }
81
- });
64
+ export async function isDirectory(path: string): Promise<boolean> {
65
+ const r = await _sendFsAsync({ t: 'isDirectory', p: { path } });
66
+ return r === true || String(r) === 'true';
82
67
  }
83
68
  export function isDirectorySync(path: string): boolean {
84
69
  const r = _sendFs({ t: 'isDirectory', p: { path } });
85
70
  return r === true || String(r) === 'true';
86
71
  }
87
72
 
88
- export function deleteFile(path: string): Promise<boolean> {
89
- return new Promise((resolve, reject) => {
90
- try {
91
- const r = _sendFs({ t: 'delete', p: { path } });
92
- resolve(r === true || String(r) === 'true');
93
- } catch (e) { reject(e); }
94
- });
73
+ export async function deleteFile(path: string): Promise<boolean> {
74
+ const r = await _sendFsAsync({ t: 'delete', p: { path } });
75
+ return r === true || String(r) === 'true';
95
76
  }
96
77
  export function deleteFileSync(path: string): boolean {
97
78
  const r = _sendFs({ t: 'delete', p: { path } });
98
79
  return r === true || String(r) === 'true';
99
80
  }
100
81
 
101
- export function mkdir(path: string): Promise<void> {
102
- return new Promise((resolve, reject) => {
103
- try { _sendFs({ t: 'mkdir', p: { path } }); resolve(); }
104
- catch (e) { reject(e); }
105
- });
82
+ export async function mkdir(path: string): Promise<void> {
83
+ await _sendFsAsync({ t: 'mkdir', p: { path } });
106
84
  }
107
85
  export function mkdirSync(path: string): void {
108
86
  _sendFs({ t: 'mkdir', p: { path } });
109
87
  }
110
88
 
111
- export function list(path: string): Promise<string[]> {
112
- return new Promise((resolve, reject) => {
113
- try {
114
- const r = _sendFs({ t: 'list', p: { path } });
115
- resolve(r as string[]);
116
- } catch (e) { reject(e); }
117
- });
89
+ export async function list(path: string): Promise<string[]> {
90
+ return await _sendFsAsync({ t: 'list', p: { path } }) as string[];
118
91
  }
119
92
  export function listSync(path: string): string[] {
120
93
  return _sendFs({ t: 'list', p: { path } }) as string[];
package/src/index.ts CHANGED
@@ -69,10 +69,13 @@ export { add as addRecipe, remove as removeRecipe, getForItem as getRecipesForIt
69
69
  export type {
70
70
  ObjectiveInfo, TeamInfo,
71
71
  } from './scoreboard.js';
72
- export { createObjective, deleteObjective, getObjectives,
72
+ export { createBoard as createScoreboard, deleteBoard as deleteScoreboard,
73
+ createObjective, deleteObjective, getObjectives,
73
74
  setObjectiveDisplay, getScore, setScore, resetScore,
74
75
  createTeam, deleteTeam, getTeam, getTeams,
75
76
  setTeamDisplayName, setTeamPrefix, setTeamSuffix, setTeamColor,
76
77
  setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
77
78
  teamAddEntry, teamRemoveEntry, teamGetEntries,
78
79
  setPlayerBoard } from './scoreboard.js';
80
+ export { getMaterials, getBlocks, getItems } from './material.js';
81
+ export type { MaterialInfo } from './material.js';
@@ -0,0 +1,19 @@
1
+ import { post } from './task.js';
2
+
3
+ export interface MaterialInfo {
4
+ key: string;
5
+ isBlock: boolean;
6
+ isItem: boolean;
7
+ }
8
+
9
+ export function getMaterials(): Promise<MaterialInfo[]> {
10
+ return post<MaterialInfo[]>('server.getMaterials', {});
11
+ }
12
+
13
+ export function getBlocks(): Promise<string[]> {
14
+ return post<string[]>('server.getBlocks', {});
15
+ }
16
+
17
+ export function getItems(): Promise<string[]> {
18
+ return post<string[]>('server.getItems', {});
19
+ }
package/src/recipe.ts CHANGED
@@ -54,7 +54,7 @@ interface CampfireRecipe {
54
54
  }
55
55
 
56
56
  export function add(recipe: RecipeDefinition): Promise<boolean> {
57
- return post<boolean>('recipe.add', recipe as Record<string, unknown>);
57
+ return post<boolean>('recipe.add', recipe as unknown as Record<string, unknown>);
58
58
  }
59
59
 
60
60
  export function remove(key: string): Promise<void> {
package/src/scoreboard.ts CHANGED
@@ -22,94 +22,108 @@ export interface TeamInfo {
22
22
  };
23
23
  }
24
24
 
25
+ function boardParam(board?: string): Record<string, unknown> {
26
+ return board ? { board } : {};
27
+ }
28
+
29
+ // ── Board ──
30
+
31
+ export function createBoard(id: string): Promise<string> {
32
+ return post<string>('scoreboard.createBoard', { id });
33
+ }
34
+
35
+ export function deleteBoard(id: string): Promise<void> {
36
+ return post('scoreboard.deleteBoard', { id });
37
+ }
38
+
25
39
  // ── Objectives ──
26
40
 
27
- export function createObjective(name: string, criteria: string, displayName: string): Promise<ObjectiveInfo> {
28
- return post<ObjectiveInfo>('scoreboard.createObjective', { name, criteria, displayName });
41
+ export function createObjective(name: string, criteria: string, displayName: string, board?: string): Promise<ObjectiveInfo> {
42
+ return post<ObjectiveInfo>('scoreboard.createObjective', { name, criteria, displayName, ...boardParam(board) });
29
43
  }
30
44
 
31
- export function deleteObjective(name: string): Promise<void> {
32
- return post('scoreboard.deleteObjective', { name });
45
+ export function deleteObjective(name: string, board?: string): Promise<void> {
46
+ return post('scoreboard.deleteObjective', { name, ...boardParam(board) });
33
47
  }
34
48
 
35
- export function getObjectives(): Promise<ObjectiveInfo[]> {
36
- return post<ObjectiveInfo[]>('scoreboard.getObjectives', {});
49
+ export function getObjectives(board?: string): Promise<ObjectiveInfo[]> {
50
+ return post<ObjectiveInfo[]>('scoreboard.getObjectives', { ...boardParam(board) });
37
51
  }
38
52
 
39
- export function setObjectiveDisplay(name: string, slot: string | null): Promise<boolean> {
40
- return post<boolean>('scoreboard.setObjectiveDisplay', { name, slot });
53
+ export function setObjectiveDisplay(name: string, slot: string | null, board?: string): Promise<boolean> {
54
+ return post<boolean>('scoreboard.setObjectiveDisplay', { name, slot, ...boardParam(board) });
41
55
  }
42
56
 
43
- export function getScore(objective: string, entry: string): Promise<number | null> {
44
- return post<number | null>('scoreboard.getScore', { objective, entry });
57
+ export function getScore(objective: string, entry: string, board?: string): Promise<number | null> {
58
+ return post<number | null>('scoreboard.getScore', { objective, entry, ...boardParam(board) });
45
59
  }
46
60
 
47
- export function setScore(objective: string, entry: string, value: number): Promise<void> {
48
- return post('scoreboard.setScore', { objective, entry, value });
61
+ export function setScore(objective: string, entry: string, value: number, board?: string): Promise<void> {
62
+ return post('scoreboard.setScore', { objective, entry, value, ...boardParam(board) });
49
63
  }
50
64
 
51
- export function resetScore(objective: string, entry: string): Promise<void> {
52
- return post('scoreboard.resetScore', { objective, entry });
65
+ export function resetScore(objective: string, entry: string, board?: string): Promise<void> {
66
+ return post('scoreboard.resetScore', { objective, entry, ...boardParam(board) });
53
67
  }
54
68
 
55
69
  // ── Teams ──
56
70
 
57
- export function createTeam(name: string): Promise<void> {
58
- return post('scoreboard.createTeam', { name });
71
+ export function createTeam(name: string, board?: string): Promise<void> {
72
+ return post('scoreboard.createTeam', { name, ...boardParam(board) });
59
73
  }
60
74
 
61
- export function deleteTeam(name: string): Promise<void> {
62
- return post('scoreboard.deleteTeam', { name });
75
+ export function deleteTeam(name: string, board?: string): Promise<void> {
76
+ return post('scoreboard.deleteTeam', { name, ...boardParam(board) });
63
77
  }
64
78
 
65
- export function getTeam(name: string): Promise<TeamInfo | null> {
66
- return post<TeamInfo | null>('scoreboard.getTeam', { name });
79
+ export function getTeam(name: string, board?: string): Promise<TeamInfo | null> {
80
+ return post<TeamInfo | null>('scoreboard.getTeam', { name, ...boardParam(board) });
67
81
  }
68
82
 
69
- export function getTeams(): Promise<TeamInfo[]> {
70
- return post<TeamInfo[]>('scoreboard.getTeams', {});
83
+ export function getTeams(board?: string): Promise<TeamInfo[]> {
84
+ return post<TeamInfo[]>('scoreboard.getTeams', { ...boardParam(board) });
71
85
  }
72
86
 
73
- export function setTeamDisplayName(name: string, displayName: string): Promise<void> {
74
- return post('scoreboard.setTeamDisplayName', { name, displayName });
87
+ export function setTeamDisplayName(name: string, displayName: string, board?: string): Promise<void> {
88
+ return post('scoreboard.setTeamDisplayName', { name, displayName, ...boardParam(board) });
75
89
  }
76
90
 
77
- export function setTeamPrefix(name: string, prefix: string): Promise<void> {
78
- return post('scoreboard.setTeamPrefix', { name, prefix });
91
+ export function setTeamPrefix(name: string, prefix: string, board?: string): Promise<void> {
92
+ return post('scoreboard.setTeamPrefix', { name, prefix, ...boardParam(board) });
79
93
  }
80
94
 
81
- export function setTeamSuffix(name: string, suffix: string): Promise<void> {
82
- return post('scoreboard.setTeamSuffix', { name, suffix });
95
+ export function setTeamSuffix(name: string, suffix: string, board?: string): Promise<void> {
96
+ return post('scoreboard.setTeamSuffix', { name, suffix, ...boardParam(board) });
83
97
  }
84
98
 
85
- export function setTeamColor(name: string, color: string): Promise<void> {
86
- return post('scoreboard.setTeamColor', { name, color });
99
+ export function setTeamColor(name: string, color: string, board?: string): Promise<void> {
100
+ return post('scoreboard.setTeamColor', { name, color, ...boardParam(board) });
87
101
  }
88
102
 
89
- export function setTeamFriendlyFire(name: string, allow: boolean): Promise<void> {
90
- return post('scoreboard.setTeamFriendlyFire', { name, allow });
103
+ export function setTeamFriendlyFire(name: string, allow: boolean, board?: string): Promise<void> {
104
+ return post('scoreboard.setTeamFriendlyFire', { name, allow, ...boardParam(board) });
91
105
  }
92
106
 
93
- export function setTeamSeeInvisible(name: string, canSee: boolean): Promise<void> {
94
- return post('scoreboard.setTeamSeeInvisible', { name, canSee });
107
+ export function setTeamSeeInvisible(name: string, canSee: boolean, board?: string): Promise<void> {
108
+ return post('scoreboard.setTeamSeeInvisible', { name, canSee, ...boardParam(board) });
95
109
  }
96
110
 
97
- export function setTeamOption(name: string, option: string, value: string): Promise<void> {
98
- return post('scoreboard.setTeamOption', { name, option, value });
111
+ export function setTeamOption(name: string, option: string, value: string, board?: string): Promise<void> {
112
+ return post('scoreboard.setTeamOption', { name, option, value, ...boardParam(board) });
99
113
  }
100
114
 
101
- export function teamAddEntry(name: string, entry: string): Promise<void> {
102
- return post('scoreboard.teamAddEntry', { name, entry });
115
+ export function teamAddEntry(name: string, entry: string, board?: string): Promise<void> {
116
+ return post('scoreboard.teamAddEntry', { name, entry, ...boardParam(board) });
103
117
  }
104
118
 
105
- export function teamRemoveEntry(name: string, entry: string): Promise<void> {
106
- return post('scoreboard.teamRemoveEntry', { name, entry });
119
+ export function teamRemoveEntry(name: string, entry: string, board?: string): Promise<void> {
120
+ return post('scoreboard.teamRemoveEntry', { name, entry, ...boardParam(board) });
107
121
  }
108
122
 
109
- export function teamGetEntries(name: string): Promise<string[]> {
110
- return post<string[]>('scoreboard.teamGetEntries', { name });
123
+ export function teamGetEntries(name: string, board?: string): Promise<string[]> {
124
+ return post<string[]>('scoreboard.teamGetEntries', { name, ...boardParam(board) });
111
125
  }
112
126
 
113
- export function setPlayerBoard(uuid: string): Promise<void> {
114
- return post('scoreboard.setPlayerBoard', { uuid });
127
+ export function setPlayerBoard(uuid: string, board?: string): Promise<void> {
128
+ return post('scoreboard.setPlayerBoard', { uuid, ...boardParam(board) });
115
129
  }