Skip to content

Commit

Permalink
fix(ecp): commands type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dlenroc authored Dec 10, 2023
1 parent 25ea516 commit a0a488c
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 76 deletions.
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/input.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { Executor } from '../Executor.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import type { Params } from '../types/Params.ts';

export async function input<Context extends Executor>(
ctx: Context,
params: Params,
payload: Record<string, unknown>,
config?: Config<Context>
): Promise<void> {
await execute(ctx, 'input', params, config);
await execute(ctx, 'input', payload, config);
}
6 changes: 2 additions & 4 deletions packages/ecp/src/commands/keydown.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Executor } from '../Executor.ts';
import { execute } from '../internal/execute.js';
import { toKey } from '../internal/toKey.js';
import type { Config } from '../internal/types.d.ts';
import type { Key } from '../types/Key.ts';

export async function keydown<Context extends Executor>(
ctx: Context,
params: { key: Key },
payload: { key: string },
config?: Config<Context>
): Promise<void> {
await execute(ctx, `keydown/${toKey(params.key)}`, undefined, config);
await execute(ctx, `keydown/${payload.key}`, undefined, config);
}
6 changes: 2 additions & 4 deletions packages/ecp/src/commands/keypress.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Executor } from '../Executor.ts';
import { execute } from '../internal/execute.js';
import { toKey } from '../internal/toKey.js';
import type { Config } from '../internal/types.d.ts';
import type { Key } from '../types/Key.ts';

export async function keypress<Context extends Executor>(
ctx: Context,
params: { key: Key },
payload: { key: string },
config?: Config<Context>
): Promise<void> {
await execute(ctx, `keypress/${toKey(params.key)}`, undefined, config);
await execute(ctx, `keypress/${payload.key}`, undefined, config);
}
6 changes: 2 additions & 4 deletions packages/ecp/src/commands/keyup.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Executor } from '../Executor.ts';
import { execute } from '../internal/execute.js';
import { toKey } from '../internal/toKey.js';
import type { Config } from '../internal/types.d.ts';
import type { Key } from '../types/Key.ts';

export async function keyup<Context extends Executor>(
ctx: Context,
params: { key: Key },
payload: { key: string },
config?: Config<Context>
): Promise<void> {
await execute(ctx, `keyup/${toKey(params.key)}`, undefined, config);
await execute(ctx, `keyup/${payload.key}`, undefined, config);
}
6 changes: 2 additions & 4 deletions packages/ecp/src/commands/launch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import type { AppId } from '../types/AppId.ts';
import type { Params } from '../types/Params.ts';

export async function launch<Context extends Executor>(
ctx: Context,
params: { id: AppId; params?: Nullable<Params> },
payload: { appId: AppId; params?: Record<string, unknown> },
config?: Config<Context>
): Promise<void> {
await execute(ctx, `launch/${params.id}`, params.params, config);
await execute(ctx, `launch/${payload.appId}`, payload.params, config);
}
8 changes: 3 additions & 5 deletions packages/ecp/src/commands/queryChannelPerformance.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import parse from '../internal/xml.js';
import type { AppId } from '../types/AppId.ts';
import type { ChannelPerformance } from '../types/ChannelPerformance.ts';
import type { Failure } from '../types/Failure.ts';
import type { Params } from '../types/Params.ts';

export async function queryChannelPerformance<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId>; params?: Nullable<Params> }>,
payload?: { appId?: AppId; params?: Record<string, unknown> },
config?: Config<Context>
): Promise<Failure | ChannelPerformance> {
const response = await execute(
ctx,
`query/chanperf${params?.id ? `/${params.id}` : ''}`,
params,
`query/chanperf${payload?.appId ? `/${payload.appId}` : ''}`,
payload?.params,
config
);
return parse(await response.text());
Expand Down
4 changes: 2 additions & 2 deletions packages/ecp/src/commands/queryIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type { AppId } from '../types/AppId.ts';

export async function queryIcon<Context extends Executor>(
ctx: Context,
params: { id: AppId },
payload: { appId: AppId },
config?: Config<Context>
): Promise<ArrayBuffer> {
const response = await execute(
ctx,
`query/icon/${params.id}`,
`query/icon/${payload.appId}`,
undefined,
config
);
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/queryR2D2Bitmaps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import parse from '../internal/xml.js';
Expand All @@ -9,12 +8,12 @@ import type { R2D2Bitmaps } from '../types/R2D2Bitmaps.ts';

export async function queryR2D2Bitmaps<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<Failure | R2D2Bitmaps> {
const response = await execute(
ctx,
`query/r2d2-bitmaps${params?.id ? `/${params.id}` : ''}`,
`query/r2d2-bitmaps${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
4 changes: 2 additions & 2 deletions packages/ecp/src/commands/queryRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type { Registry } from '../types/Registry.ts';

export async function queryRegistry<Context extends Executor>(
ctx: Context,
params: { id: AppId },
payload: { appId: AppId },
config?: Config<Context>
): Promise<Failure | Registry> {
const response = await execute(
ctx,
`query/registry/${params.id}`,
`query/registry/${payload.appId}`,
undefined,
config
);
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/querySGNodesAll.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import type { AppId } from '../types/AppId.ts';

export async function querySGNodesAll<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<string> {
const response = await execute(
ctx,
`query/sgnodes/all${params?.id ? `/${params.id}` : ''}`,
`query/sgnodes/all${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
7 changes: 3 additions & 4 deletions packages/ecp/src/commands/querySGNodesNodes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import type { AppId } from '../types/AppId.ts';

export async function querySGNodesNodes<Context extends Executor>(
ctx: Context,
params: { id?: Nullable<AppId>; nodeId: string },
payload: { appId?: AppId; nodeId: string },
config?: Config<Context>
): Promise<string> {
const response = await execute(
ctx,
`query/sgnodes/nodes${params?.id ? `/${params.id}` : ''}?node-id=${
params.nodeId
`query/sgnodes/nodes${payload?.appId ? `/${payload.appId}` : ''}?node-id=${
payload.nodeId
}`,
undefined,
config
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/querySGNodesRoots.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import type { AppId } from '../types/AppId.ts';

export async function querySGNodesRoots<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<string> {
const response = await execute(
ctx,
`query/sgnodes/roots${params?.id ? `/${params.id}` : ''}`,
`query/sgnodes/roots${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/search.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { Executor } from '../Executor.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import type { Params } from '../types/Params.ts';

export async function search<Context extends Executor>(
ctx: Context,
params: Params,
payload: Record<string, unknown>,
config?: Config<Context>
): Promise<void> {
await execute(ctx, 'search/browse', params, config);
await execute(ctx, 'search/browse', payload, config);
}
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/trackFWBeacons.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import parse from '../internal/xml.js';
Expand All @@ -9,12 +8,12 @@ import type { Failure } from '../types/Failure.ts';

export async function trackFWBeacons<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<Failure | FWBeaconsStatus> {
const response = await execute(
ctx,
`fwbeacons/track${params?.id ? `/${params.id}` : ''}`,
`fwbeacons/track${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/trackSGRendezvous.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import parse from '../internal/xml.js';
Expand All @@ -9,12 +8,12 @@ import type { SGRendezvousStatus } from '../types/SGRendezvousStatus.ts';

export async function trackSGRendezvous<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<Failure | SGRendezvousStatus> {
const response = await execute(
ctx,
`sgrendezvous/track${params?.id ? `/${params.id}` : ''}`,
`sgrendezvous/track${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/untrackFWBeacons.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import parse from '../internal/xml.js';
Expand All @@ -9,12 +8,12 @@ import type { Failure } from '../types/Failure.ts';

export async function untrackFWBeacons<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<Failure | FWBeaconsStatus> {
const response = await execute(
ctx,
`fwbeacons/untrack${params?.id ? `/${params.id}` : ''}`,
`fwbeacons/untrack${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
5 changes: 2 additions & 3 deletions packages/ecp/src/commands/untrackSGRendezvous.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Executor } from '../Executor.ts';
import type { Nullable } from '../internal/Nullable.ts';
import { execute } from '../internal/execute.js';
import type { Config } from '../internal/types.d.ts';
import parse from '../internal/xml.js';
Expand All @@ -9,12 +8,12 @@ import type { SGRendezvousStatus } from '../types/SGRendezvousStatus.ts';

export async function untrackSGRendezvous<Context extends Executor>(
ctx: Context,
params?: Nullable<{ id?: Nullable<AppId> }>,
payload?: { appId?: AppId },
config?: Config<Context>
): Promise<Failure | SGRendezvousStatus> {
const response = await execute(
ctx,
`sgrendezvous/untrack${params?.id ? `/${params.id}` : ''}`,
`sgrendezvous/untrack${payload?.appId ? `/${payload.appId}` : ''}`,
undefined,
config
);
Expand Down
1 change: 0 additions & 1 deletion packages/ecp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export type * from './types/Failure.ts';
export type * from './types/GraphicsFrameRate.ts';
export type * from './types/Key.ts';
export type * from './types/MediaInfo.ts';
export type * from './types/Params.ts';
export type * from './types/R2D2Bitmaps.ts';
export type * from './types/Registry.ts';
export type * from './types/SGRendezvous.ts';
Expand Down
1 change: 0 additions & 1 deletion packages/ecp/src/internal/Nullable.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/ecp/src/internal/execute.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ECPError } from '../ECPError.js';
import type { Executor } from '../Executor.ts';
import type { Nullable } from './Nullable.ts';
import type { Config } from './types.d.ts';

export async function execute<Context extends Executor>(
ctx: Context,
path: string,
params?: Nullable<Record<string, unknown>>,
params?: Record<string, unknown>,
config?: Config<Context>
): Promise<Response> {
if (params && Object.keys(params).length) {
Expand Down
13 changes: 0 additions & 13 deletions packages/ecp/src/internal/toKey.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/ecp/src/internal/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ export type Mixed<A, B> =
| (A & B)
| (Omit<A, keyof B> &
Omit<B, keyof A> & { [K in keyof (A | B)]: (A | B)[K] });

export type Nullable<T> = T | undefined | null;
1 change: 0 additions & 1 deletion packages/ecp/src/types/Params.ts

This file was deleted.

0 comments on commit a0a488c

Please sign in to comment.