UNPKG

@tak-ps/node-tak

Version:

Lightweight JavaScript library for communicating with TAK Server

68 lines 2.03 kB
import { Type } from '@sinclair/typebox'; import { TAKList } from './types.js'; import Commands, { CommandOutputFormat } from '../commands.js'; export const Group = Type.Object({ name: Type.String(), direction: Type.String(), created: Type.String(), type: Type.String(), bitpos: Type.Number(), active: Type.Boolean(), description: Type.Optional(Type.String()) }); export const GroupListInput = Type.Object({ useCache: Type.Optional(Type.Boolean()) }); export const TAKList_Group = TAKList(Group); export default class GroupCommands extends Commands { schema = { list: { description: 'List Missions', params: Type.Object({}), query: Type.Object({}), formats: [CommandOutputFormat.JSON] } }; async cli(args) { if (args._[3] === 'list') { const list = await this.list(); if (args.format === 'json') { return list; } else { return list.data.map((channel) => { return `${channel.name} - ${channel.description}`; }).join('\n'); } } else { throw new Error('Unsupported Subcommand'); } } async list(query = {}) { const url = new URL(`/Marti/api/groups/all`, this.api.url); let q; for (q in query) { if (query[q] !== undefined) { url.searchParams.append(q, String(query[q])); } } return await this.api.fetch(url, { method: 'GET' }); } async update(body, query = {}) { const url = new URL(`/Marti/api/groups/active`, this.api.url); let q; for (q in query) { if (query[q] !== undefined) { url.searchParams.append(q, String(query[q])); } } await this.api.fetch(url, { method: 'PUT', body }); } } //# sourceMappingURL=groups.js.map