From a0a488cad6ef9a6e7793ee25f24ea77b3da98229 Mon Sep 17 00:00:00 2001 From: Corneliu Duplachi Date: Sun, 10 Dec 2023 14:17:53 +0200 Subject: [PATCH] fix(ecp): commands type definition --- packages/ecp/src/commands/input.ts | 5 ++--- packages/ecp/src/commands/keydown.ts | 6 ++---- packages/ecp/src/commands/keypress.ts | 6 ++---- packages/ecp/src/commands/keyup.ts | 6 ++---- packages/ecp/src/commands/launch.ts | 6 ++---- .../ecp/src/commands/queryChannelPerformance.ts | 8 +++----- packages/ecp/src/commands/queryIcon.ts | 4 ++-- packages/ecp/src/commands/queryR2D2Bitmaps.ts | 5 ++--- packages/ecp/src/commands/queryRegistry.ts | 4 ++-- packages/ecp/src/commands/querySGNodesAll.ts | 5 ++--- packages/ecp/src/commands/querySGNodesNodes.ts | 7 +++---- packages/ecp/src/commands/querySGNodesRoots.ts | 5 ++--- packages/ecp/src/commands/search.ts | 5 ++--- packages/ecp/src/commands/trackFWBeacons.ts | 5 ++--- packages/ecp/src/commands/trackSGRendezvous.ts | 5 ++--- packages/ecp/src/commands/untrackFWBeacons.ts | 5 ++--- packages/ecp/src/commands/untrackSGRendezvous.ts | 5 ++--- packages/ecp/src/index.ts | 1 - packages/ecp/src/internal/Nullable.ts | 1 - packages/ecp/src/internal/execute.ts | 3 +-- packages/ecp/src/internal/toKey.ts | 13 ------------- packages/ecp/src/internal/types.d.ts | 2 -- packages/ecp/src/types/Params.ts | 1 - 23 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 packages/ecp/src/internal/Nullable.ts delete mode 100644 packages/ecp/src/internal/toKey.ts delete mode 100644 packages/ecp/src/types/Params.ts diff --git a/packages/ecp/src/commands/input.ts b/packages/ecp/src/commands/input.ts index 3d5b946..5aefc1b 100644 --- a/packages/ecp/src/commands/input.ts +++ b/packages/ecp/src/commands/input.ts @@ -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( ctx: Context, - params: Params, + payload: Record, config?: Config ): Promise { - await execute(ctx, 'input', params, config); + await execute(ctx, 'input', payload, config); } diff --git a/packages/ecp/src/commands/keydown.ts b/packages/ecp/src/commands/keydown.ts index c0d0955..e4f8cba 100644 --- a/packages/ecp/src/commands/keydown.ts +++ b/packages/ecp/src/commands/keydown.ts @@ -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( ctx: Context, - params: { key: Key }, + payload: { key: string }, config?: Config ): Promise { - await execute(ctx, `keydown/${toKey(params.key)}`, undefined, config); + await execute(ctx, `keydown/${payload.key}`, undefined, config); } diff --git a/packages/ecp/src/commands/keypress.ts b/packages/ecp/src/commands/keypress.ts index 136a097..980cb59 100644 --- a/packages/ecp/src/commands/keypress.ts +++ b/packages/ecp/src/commands/keypress.ts @@ -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( ctx: Context, - params: { key: Key }, + payload: { key: string }, config?: Config ): Promise { - await execute(ctx, `keypress/${toKey(params.key)}`, undefined, config); + await execute(ctx, `keypress/${payload.key}`, undefined, config); } diff --git a/packages/ecp/src/commands/keyup.ts b/packages/ecp/src/commands/keyup.ts index 2b05cfa..d0bb50a 100644 --- a/packages/ecp/src/commands/keyup.ts +++ b/packages/ecp/src/commands/keyup.ts @@ -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( ctx: Context, - params: { key: Key }, + payload: { key: string }, config?: Config ): Promise { - await execute(ctx, `keyup/${toKey(params.key)}`, undefined, config); + await execute(ctx, `keyup/${payload.key}`, undefined, config); } diff --git a/packages/ecp/src/commands/launch.ts b/packages/ecp/src/commands/launch.ts index b4ad38b..38bde8f 100644 --- a/packages/ecp/src/commands/launch.ts +++ b/packages/ecp/src/commands/launch.ts @@ -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( ctx: Context, - params: { id: AppId; params?: Nullable }, + payload: { appId: AppId; params?: Record }, config?: Config ): Promise { - await execute(ctx, `launch/${params.id}`, params.params, config); + await execute(ctx, `launch/${payload.appId}`, payload.params, config); } diff --git a/packages/ecp/src/commands/queryChannelPerformance.ts b/packages/ecp/src/commands/queryChannelPerformance.ts index 55d5f70..6e66be1 100644 --- a/packages/ecp/src/commands/queryChannelPerformance.ts +++ b/packages/ecp/src/commands/queryChannelPerformance.ts @@ -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( ctx: Context, - params?: Nullable<{ id?: Nullable; params?: Nullable }>, + payload?: { appId?: AppId; params?: Record }, config?: Config ): Promise { 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()); diff --git a/packages/ecp/src/commands/queryIcon.ts b/packages/ecp/src/commands/queryIcon.ts index d5285e5..6e646d6 100644 --- a/packages/ecp/src/commands/queryIcon.ts +++ b/packages/ecp/src/commands/queryIcon.ts @@ -5,12 +5,12 @@ import type { AppId } from '../types/AppId.ts'; export async function queryIcon( ctx: Context, - params: { id: AppId }, + payload: { appId: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `query/icon/${params.id}`, + `query/icon/${payload.appId}`, undefined, config ); diff --git a/packages/ecp/src/commands/queryR2D2Bitmaps.ts b/packages/ecp/src/commands/queryR2D2Bitmaps.ts index 17f460b..cdd6a66 100644 --- a/packages/ecp/src/commands/queryR2D2Bitmaps.ts +++ b/packages/ecp/src/commands/queryR2D2Bitmaps.ts @@ -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'; @@ -9,12 +8,12 @@ import type { R2D2Bitmaps } from '../types/R2D2Bitmaps.ts'; export async function queryR2D2Bitmaps( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `query/r2d2-bitmaps${params?.id ? `/${params.id}` : ''}`, + `query/r2d2-bitmaps${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/commands/queryRegistry.ts b/packages/ecp/src/commands/queryRegistry.ts index cb1d052..eab0d98 100644 --- a/packages/ecp/src/commands/queryRegistry.ts +++ b/packages/ecp/src/commands/queryRegistry.ts @@ -8,12 +8,12 @@ import type { Registry } from '../types/Registry.ts'; export async function queryRegistry( ctx: Context, - params: { id: AppId }, + payload: { appId: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `query/registry/${params.id}`, + `query/registry/${payload.appId}`, undefined, config ); diff --git a/packages/ecp/src/commands/querySGNodesAll.ts b/packages/ecp/src/commands/querySGNodesAll.ts index 063179e..0d9d493 100644 --- a/packages/ecp/src/commands/querySGNodesAll.ts +++ b/packages/ecp/src/commands/querySGNodesAll.ts @@ -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( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `query/sgnodes/all${params?.id ? `/${params.id}` : ''}`, + `query/sgnodes/all${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/commands/querySGNodesNodes.ts b/packages/ecp/src/commands/querySGNodesNodes.ts index 546c349..a10cd21 100644 --- a/packages/ecp/src/commands/querySGNodesNodes.ts +++ b/packages/ecp/src/commands/querySGNodesNodes.ts @@ -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( ctx: Context, - params: { id?: Nullable; nodeId: string }, + payload: { appId?: AppId; nodeId: string }, config?: Config ): Promise { 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 diff --git a/packages/ecp/src/commands/querySGNodesRoots.ts b/packages/ecp/src/commands/querySGNodesRoots.ts index 72d2ef5..d6f2156 100644 --- a/packages/ecp/src/commands/querySGNodesRoots.ts +++ b/packages/ecp/src/commands/querySGNodesRoots.ts @@ -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( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `query/sgnodes/roots${params?.id ? `/${params.id}` : ''}`, + `query/sgnodes/roots${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/commands/search.ts b/packages/ecp/src/commands/search.ts index ce89724..59a984b 100644 --- a/packages/ecp/src/commands/search.ts +++ b/packages/ecp/src/commands/search.ts @@ -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( ctx: Context, - params: Params, + payload: Record, config?: Config ): Promise { - await execute(ctx, 'search/browse', params, config); + await execute(ctx, 'search/browse', payload, config); } diff --git a/packages/ecp/src/commands/trackFWBeacons.ts b/packages/ecp/src/commands/trackFWBeacons.ts index 10f41e0..cc24947 100644 --- a/packages/ecp/src/commands/trackFWBeacons.ts +++ b/packages/ecp/src/commands/trackFWBeacons.ts @@ -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'; @@ -9,12 +8,12 @@ import type { Failure } from '../types/Failure.ts'; export async function trackFWBeacons( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `fwbeacons/track${params?.id ? `/${params.id}` : ''}`, + `fwbeacons/track${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/commands/trackSGRendezvous.ts b/packages/ecp/src/commands/trackSGRendezvous.ts index bf76d11..6c29e11 100644 --- a/packages/ecp/src/commands/trackSGRendezvous.ts +++ b/packages/ecp/src/commands/trackSGRendezvous.ts @@ -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'; @@ -9,12 +8,12 @@ import type { SGRendezvousStatus } from '../types/SGRendezvousStatus.ts'; export async function trackSGRendezvous( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `sgrendezvous/track${params?.id ? `/${params.id}` : ''}`, + `sgrendezvous/track${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/commands/untrackFWBeacons.ts b/packages/ecp/src/commands/untrackFWBeacons.ts index d988fa8..9cdbdc1 100644 --- a/packages/ecp/src/commands/untrackFWBeacons.ts +++ b/packages/ecp/src/commands/untrackFWBeacons.ts @@ -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'; @@ -9,12 +8,12 @@ import type { Failure } from '../types/Failure.ts'; export async function untrackFWBeacons( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `fwbeacons/untrack${params?.id ? `/${params.id}` : ''}`, + `fwbeacons/untrack${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/commands/untrackSGRendezvous.ts b/packages/ecp/src/commands/untrackSGRendezvous.ts index 8c0b7f0..f140292 100644 --- a/packages/ecp/src/commands/untrackSGRendezvous.ts +++ b/packages/ecp/src/commands/untrackSGRendezvous.ts @@ -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'; @@ -9,12 +8,12 @@ import type { SGRendezvousStatus } from '../types/SGRendezvousStatus.ts'; export async function untrackSGRendezvous( ctx: Context, - params?: Nullable<{ id?: Nullable }>, + payload?: { appId?: AppId }, config?: Config ): Promise { const response = await execute( ctx, - `sgrendezvous/untrack${params?.id ? `/${params.id}` : ''}`, + `sgrendezvous/untrack${payload?.appId ? `/${payload.appId}` : ''}`, undefined, config ); diff --git a/packages/ecp/src/index.ts b/packages/ecp/src/index.ts index 8906b6a..7c4c52a 100644 --- a/packages/ecp/src/index.ts +++ b/packages/ecp/src/index.ts @@ -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'; diff --git a/packages/ecp/src/internal/Nullable.ts b/packages/ecp/src/internal/Nullable.ts deleted file mode 100644 index 6d89395..0000000 --- a/packages/ecp/src/internal/Nullable.ts +++ /dev/null @@ -1 +0,0 @@ -export type Nullable = T | undefined | null; diff --git a/packages/ecp/src/internal/execute.ts b/packages/ecp/src/internal/execute.ts index 95cdc57..dc524b4 100644 --- a/packages/ecp/src/internal/execute.ts +++ b/packages/ecp/src/internal/execute.ts @@ -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( ctx: Context, path: string, - params?: Nullable>, + params?: Record, config?: Config ): Promise { if (params && Object.keys(params).length) { diff --git a/packages/ecp/src/internal/toKey.ts b/packages/ecp/src/internal/toKey.ts deleted file mode 100644 index 1123d2e..0000000 --- a/packages/ecp/src/internal/toKey.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ECPError } from '../ECPError.js'; - -export function toKey(key: string): string { - if (!key) { - throw new ECPError('key is required'); - } - - if (key.length === 1) { - key = `LIT_${encodeURIComponent(key)}`; - } - - return key; -} diff --git a/packages/ecp/src/internal/types.d.ts b/packages/ecp/src/internal/types.d.ts index 38b1d75..dec233d 100644 --- a/packages/ecp/src/internal/types.d.ts +++ b/packages/ecp/src/internal/types.d.ts @@ -4,5 +4,3 @@ export type Mixed = | (A & B) | (Omit & Omit & { [K in keyof (A | B)]: (A | B)[K] }); - -export type Nullable = T | undefined | null; diff --git a/packages/ecp/src/types/Params.ts b/packages/ecp/src/types/Params.ts deleted file mode 100644 index fa4ebf6..0000000 --- a/packages/ecp/src/types/Params.ts +++ /dev/null @@ -1 +0,0 @@ -export type Params = Record;