@formant/formant-cli 0.4.3 → 0.4.5
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/README.md +46 -7
- package/dist/commands/query/index.d.ts +7 -5
- package/dist/commands/query/index.js +96 -24
- package/dist/commands/query/index.js.map +1 -1
- package/dist/help.js +1 -1
- package/oclif.manifest.json +1070 -1139
- package/package.json +1 -1
- package/dist/commands/query/latest-values.d.ts +0 -15
- package/dist/commands/query/latest-values.js +0 -128
- package/dist/commands/query/latest-values.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '../../base-command.js';
|
|
2
|
-
export default class QueryLatestValues extends BaseCommand<typeof QueryLatestValues> {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
'all-streams': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
-
days: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
-
device: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
-
stream: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
};
|
|
11
|
-
static summary: string;
|
|
12
|
-
run(): Promise<{
|
|
13
|
-
items: unknown[];
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { Flags } from '@oclif/core';
|
|
2
|
-
import { BaseCommand } from '../../base-command.js';
|
|
3
|
-
import { formatTable } from '../../lib/formatters.js';
|
|
4
|
-
export default class QueryLatestValues extends BaseCommand {
|
|
5
|
-
static description = `Get the latest values for streams across devices.
|
|
6
|
-
|
|
7
|
-
Returns the most recent value for specified streams without needing to specify
|
|
8
|
-
a time range. Useful for checking current sensor readings.
|
|
9
|
-
|
|
10
|
-
Use --all-streams with a single device to automatically discover and query all
|
|
11
|
-
streams — both from the device configuration and from actual ingested data
|
|
12
|
-
(unconfigured streams included).`;
|
|
13
|
-
static examples = [
|
|
14
|
-
'<%= config.bin %> query latest-values --device <id> --stream battery_level',
|
|
15
|
-
'<%= config.bin %> query latest-values --device <id> --stream temperature --stream humidity',
|
|
16
|
-
'<%= config.bin %> query latest-values --device <id> --all-streams',
|
|
17
|
-
'<%= config.bin %> query latest-values --device <id> --all-streams --json',
|
|
18
|
-
];
|
|
19
|
-
static flags = {
|
|
20
|
-
'all-streams': Flags.boolean({
|
|
21
|
-
description: 'Query all streams for the device — from config and from ingested data (requires single --device)',
|
|
22
|
-
}),
|
|
23
|
-
days: Flags.integer({
|
|
24
|
-
default: 14,
|
|
25
|
-
description: 'How many days back to look for unconfigured streams when using --all-streams',
|
|
26
|
-
}),
|
|
27
|
-
device: Flags.string({
|
|
28
|
-
char: 'd',
|
|
29
|
-
description: 'Device ID (UUID)',
|
|
30
|
-
multiple: true,
|
|
31
|
-
required: true,
|
|
32
|
-
}),
|
|
33
|
-
stream: Flags.string({
|
|
34
|
-
char: 's',
|
|
35
|
-
description: 'Stream name(s), can be specified multiple times',
|
|
36
|
-
multiple: true,
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
static summary = 'Get latest stream values';
|
|
40
|
-
async run() {
|
|
41
|
-
let streamNames = this.flags.stream ?? [];
|
|
42
|
-
// If --all-streams, discover streams from both config and ingested data
|
|
43
|
-
if (this.flags['all-streams']) {
|
|
44
|
-
if (this.flags.device.length !== 1) {
|
|
45
|
-
this.error('--all-streams requires exactly one --device');
|
|
46
|
-
}
|
|
47
|
-
const deviceId = this.flags.device[0];
|
|
48
|
-
const discovered = new Set();
|
|
49
|
-
// ── Config-based discovery ──────────────────────────────────────────────
|
|
50
|
-
const device = await this.api('admin', `devices/${deviceId}`, {
|
|
51
|
-
method: 'GET',
|
|
52
|
-
});
|
|
53
|
-
const configVersion = device.desiredConfigurationVersion;
|
|
54
|
-
if (configVersion) {
|
|
55
|
-
const config = await this.api('admin', `devices/${deviceId}/configurations/${configVersion}`, { method: 'GET' });
|
|
56
|
-
const doc = config.document;
|
|
57
|
-
const telemetry = doc?.telemetry;
|
|
58
|
-
const configStreams = telemetry?.streams || [];
|
|
59
|
-
for (const s of configStreams) {
|
|
60
|
-
const name = s.name;
|
|
61
|
-
if (name)
|
|
62
|
-
discovered.add(name);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// ── Data-based discovery (metadata endpoint) ───────────────────────────
|
|
66
|
-
const since = new Date();
|
|
67
|
-
since.setDate(since.getDate() - this.flags.days);
|
|
68
|
-
try {
|
|
69
|
-
const metaResult = await this.api('query', 'metadata', {
|
|
70
|
-
body: {
|
|
71
|
-
deviceIds: [deviceId],
|
|
72
|
-
start: since.toISOString(),
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
for (const item of metaResult?.items ?? []) {
|
|
76
|
-
if (item.name)
|
|
77
|
-
discovered.add(item.name);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// metadata endpoint failure is non-fatal
|
|
82
|
-
}
|
|
83
|
-
streamNames = [...discovered];
|
|
84
|
-
if (streamNames.length === 0) {
|
|
85
|
-
this.error('No streams found for this device (neither configured nor in ingested data)');
|
|
86
|
-
}
|
|
87
|
-
if (!this.jsonEnabled()) {
|
|
88
|
-
this.log(`\nDiscovered ${streamNames.length} streams (config + data, last ${this.flags.days}d).\n`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (streamNames.length === 0) {
|
|
92
|
-
this.error('Specify --stream names or use --all-streams with a single device');
|
|
93
|
-
}
|
|
94
|
-
const result = await this.api('query', 'stream-current-value', {
|
|
95
|
-
body: {
|
|
96
|
-
deviceIds: this.flags.device,
|
|
97
|
-
names: streamNames,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
if (!this.jsonEnabled()) {
|
|
101
|
-
const columns = [
|
|
102
|
-
{ key: 'stream', label: 'STREAM', width: 30 },
|
|
103
|
-
{ key: 'value', label: 'VALUE', width: 40 },
|
|
104
|
-
{ key: 'type', label: 'TYPE', width: 14 },
|
|
105
|
-
{ key: 'time', label: 'TIME', width: 26 },
|
|
106
|
-
];
|
|
107
|
-
// Only show device column for multi-device queries
|
|
108
|
-
if (this.flags.device.length > 1) {
|
|
109
|
-
columns.unshift({ key: 'deviceId', label: 'DEVICE ID', width: 40 });
|
|
110
|
-
}
|
|
111
|
-
const rows = (result.items ?? []).map((item) => {
|
|
112
|
-
const val = item.currentValue ?? item.value;
|
|
113
|
-
return {
|
|
114
|
-
deviceId: item.deviceId,
|
|
115
|
-
stream: item.streamName ?? item.name ?? '—',
|
|
116
|
-
type: item.streamType ?? item.type ?? '—',
|
|
117
|
-
value: typeof val === 'object' ? JSON.stringify(val) : String(val ?? '—'),
|
|
118
|
-
time: item.currentValueTime ?? item.time ?? '—',
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
this.log(`\nLatest Stream Values (${this.env}):\n`);
|
|
122
|
-
this.log(formatTable(rows, columns));
|
|
123
|
-
this.log('');
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=latest-values.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"latest-values.js","sourceRoot":"","sources":["../../../src/commands/query/latest-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAEjC,OAAO,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAc,WAAW,EAAC,MAAM,yBAAyB,CAAA;AAShE,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,WAAqC;IAClF,MAAM,CAAU,WAAW,GAAG;;;;;;;iCAOC,CAAA;IAE/B,MAAM,CAAU,QAAQ,GAAG;QACzB,4EAA4E;QAC5E,4FAA4F;QAC5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