yeow-api 0.1.1 → 0.1.3

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,11 +1,12 @@
1
1
  {
2
2
  "name": "yeow-api",
3
- "version": "0.1.1",
4
- "description": "Yeow API �?TypeScript OOP wrappers over the task protocol",
3
+ "version": "0.1.3",
4
+ "description": "Yeow API �?TypeScript OOP wrappers over the task protocol",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "types": "./src/index.ts",
8
- "files": ["src/"],
8
+ "files": [
9
+ "src/"
10
+ ],
9
11
  "license": "MIT"
10
- }
11
-
12
+ }
package/src/index.ts CHANGED
@@ -12,4 +12,4 @@ export type { CommandOptions, CommandPayload } from './command.js';
12
12
  export { eventOn, eventOnce, eventOff } from './event.js';
13
13
  export { listen, respond, close } from './http.js';
14
14
  export type { HttpRequest } from './http.js';
15
- export { broadcast, broadcastSync, getMotd, getVersion } from './server.js';
15
+ export { broadcast, broadcastSync, dispatchCommand, dispatchCommandSync, getMotd, getMaxPlayers, getVersion } from './server.js';
package/src/server.ts CHANGED
@@ -15,3 +15,15 @@ export function getMotd(): string {
15
15
  export function getVersion(): string {
16
16
  return call('server.getVersion', {}) as string;
17
17
  }
18
+
19
+ export function getMaxPlayers(): number {
20
+ return call('server.getMaxPlayers', {}) as number;
21
+ }
22
+
23
+ export function dispatchCommand(cmd: string): Promise<void> {
24
+ return call('server.dispatchCommand', { command: cmd }) as Promise<void>;
25
+ }
26
+
27
+ export function dispatchCommandSync(cmd: string): void {
28
+ call('server.dispatchCommand', { command: cmd });
29
+ }
package/src/task.ts CHANGED
@@ -1,17 +1,19 @@
1
- export function call(type: string, params: Record<string, unknown> = {}): unknown {
2
- const raw = (globalThis as any).$submitSync(type, JSON.stringify(params));
3
- if (typeof raw !== 'string') return raw;
1
+ export function call(type: string, params?: Record<string, unknown>): unknown {
2
+ const json = typeof params === 'object' && params !== null ? JSON.stringify(params) : '{}';
3
+ const raw = (globalThis as any).$submitSync(type, json);
4
+ if (typeof raw !== 'string') return undefined;
4
5
  const result = JSON.parse(raw);
5
- if (result.err) throw new Error(result.err);
6
+ if (result && result.err) throw new Error(result.err);
6
7
  return result;
7
8
  }
8
9
 
9
- export function post(type: string, params: Record<string, unknown> = {}): Promise<unknown> {
10
+ export function post(type: string, params?: Record<string, unknown>): Promise<unknown> {
10
11
  return new Promise((resolve, reject) => {
12
+ const json = typeof params === 'object' && params !== null ? JSON.stringify(params) : '{}';
11
13
  const cbId = (globalThis as any)._registerCallback((result: any) => {
12
14
  if (result?.err) reject(new Error(result.err));
13
15
  else resolve(result);
14
16
  });
15
- (globalThis as any).$submitAsync(type, JSON.stringify(params), cbId);
17
+ (globalThis as any).$submitAsync(type, json, cbId);
16
18
  });
17
19
  }