yeow-api 0.2.40 → 0.2.41
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 +1 -1
- package/src/assets.ts +19 -21
- package/src/fs.ts +33 -60
- package/src/index.ts +2 -0
- package/src/material.ts +19 -0
- package/src/recipe.ts +1 -1
package/package.json
CHANGED
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
|
-
|
|
8
|
+
function _sendAssetsAsync(payload: Record<string, unknown>): Promise<unknown> {
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
resolve(
|
|
13
|
-
}
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
8
|
+
function _sendFsAsync(payload: Record<string, unknown>): Promise<unknown> {
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
resolve(
|
|
13
|
-
}
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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
|
|
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
|
@@ -76,3 +76,5 @@ export { createObjective, deleteObjective, getObjectives,
|
|
|
76
76
|
setTeamFriendlyFire, setTeamSeeInvisible, setTeamOption,
|
|
77
77
|
teamAddEntry, teamRemoveEntry, teamGetEntries,
|
|
78
78
|
setPlayerBoard } from './scoreboard.js';
|
|
79
|
+
export { getMaterials, getBlocks, getItems } from './material.js';
|
|
80
|
+
export type { MaterialInfo } from './material.js';
|
package/src/material.ts
ADDED
|
@@ -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> {
|