@sentio/cli 3.6.0-rc.3 → 3.6.0-rc.4

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/lib/index.js CHANGED
@@ -141137,6 +141137,59 @@ function formatDebugBody(body) {
141137
141137
 
141138
141138
  // src/commands/data.ts
141139
141139
  var DEFAULT_RANGE_STEP = 3600;
141140
+ var VALID_METRIC_FUNCTIONS = /* @__PURE__ */ new Set([
141141
+ // Math
141142
+ "abs",
141143
+ "ceil",
141144
+ "floor",
141145
+ "round",
141146
+ "log2",
141147
+ "log10",
141148
+ "ln",
141149
+ // Rollup
141150
+ "rollup_avg",
141151
+ "rollup_count",
141152
+ "rollup_last",
141153
+ "rollup_max",
141154
+ "rollup_min",
141155
+ "rollup_sum",
141156
+ "rollup_delta",
141157
+ // Aggregate Over Time
141158
+ "avg_over_time",
141159
+ "count_over_time",
141160
+ "last_over_time",
141161
+ "max_over_time",
141162
+ "min_over_time",
141163
+ "sum_over_time",
141164
+ "delta_over_time",
141165
+ // Rate
141166
+ "rate",
141167
+ "irate",
141168
+ "delta",
141169
+ "moving_delta",
141170
+ // Rank
141171
+ "topk",
141172
+ "bottomk",
141173
+ // Time
141174
+ "timestamp",
141175
+ "day_of_year",
141176
+ "day_of_month",
141177
+ "day_of_week",
141178
+ "year",
141179
+ "month",
141180
+ "hour",
141181
+ "minute",
141182
+ // TimeShift
141183
+ "before",
141184
+ "after"
141185
+ ]);
141186
+ var VALID_EVENT_FUNCTIONS = /* @__PURE__ */ new Set([
141187
+ // Rank
141188
+ "topk",
141189
+ "bottomk",
141190
+ // Delta
141191
+ "delta"
141192
+ ]);
141140
141193
  function createDataCommand() {
141141
141194
  const dataCommand = new Command("data").description("Retrieve data from Sentio");
141142
141195
  dataCommand.addCommand(createDataQueryCommand());
@@ -141173,7 +141226,7 @@ function buildEventsInsightQueryBody(search, options) {
141173
141226
  aggregation: buildEventAggregation(options.aggr),
141174
141227
  selectorExpr: buildSelectorExpr(options.filter),
141175
141228
  groupBy: normalizeListOption(options.groupBy),
141176
- functions: buildFunctions(options.func),
141229
+ functions: buildFunctions(options.func, VALID_EVENT_FUNCTIONS),
141177
141230
  disabled: false
141178
141231
  }
141179
141232
  }
@@ -141197,7 +141250,7 @@ function buildMetricsInsightQueryBody(query, options) {
141197
141250
  query,
141198
141251
  labelSelector: buildMetricLabelSelector(options.filter),
141199
141252
  aggregate: buildMetricAggregate(options.aggr, options.groupBy),
141200
- functions: buildFunctions(options.func),
141253
+ functions: buildFunctions(options.func, VALID_METRIC_FUNCTIONS),
141201
141254
  disabled: false
141202
141255
  }
141203
141256
  }
@@ -141504,7 +141557,7 @@ function handleDataCommandError(error, command) {
141504
141557
  function shouldShowHelpForDataCommandError(error) {
141505
141558
  return error.message.startsWith("Project is required.") || error.message.startsWith(
141506
141559
  "Provide --file, --stdin, or exactly one of --event, --metric, or --price for data query"
141507
- ) || error.message.startsWith("Use exactly one of --event, --metric, or --price for data query.") || error.message.startsWith("Price queries only support --price") || error.message.startsWith("Provide --query, --result, --file, or --stdin.") || error.message.startsWith("Use only one of --query or --result.") || error.message.startsWith("--async only works with --query.") || error.message.startsWith("Execution id is required.");
141560
+ ) || error.message.startsWith("Use exactly one of --event, --metric, or --price for data query.") || error.message.startsWith("Price queries only support --price") || error.message.startsWith("Provide --query, --result, --file, or --stdin.") || error.message.startsWith("Use only one of --query or --result.") || error.message.startsWith("--async only works with --query.") || error.message.startsWith("Execution id is required.") || error.message.startsWith('Unknown function "');
141508
141561
  }
141509
141562
  function buildEventAggregation(aggregationName = "total") {
141510
141563
  switch (aggregationName.toUpperCase()) {
@@ -141633,8 +141686,14 @@ function parseAnyValue(rawValue) {
141633
141686
  }
141634
141687
  return { stringValue: unquotedValue };
141635
141688
  }
141636
- function buildFunctions(functions) {
141637
- return normalizeListOption(functions).map(parseFunctionCall);
141689
+ function buildFunctions(functions, validNames) {
141690
+ return normalizeListOption(functions).map((f14) => {
141691
+ const parsed = parseFunctionCall(f14);
141692
+ if (validNames && !validNames.has(parsed.name)) {
141693
+ throw new CliError(`Unknown function "${parsed.name}". Valid functions: ${[...validNames].sort().join(", ")}.`);
141694
+ }
141695
+ return parsed;
141696
+ });
141638
141697
  }
141639
141698
  function parseFunctionCall(value) {
141640
141699
  const trimmed = value.trim();
@@ -142476,7 +142535,11 @@ function createProcessorCommand() {
142476
142535
  function createProcessorStatusCommand() {
142477
142536
  return withOutputOptions3(
142478
142537
  withSharedProjectOptions3(withAuthOptions3(new Command("status").description("Get processor status")))
142479
- ).showHelpAfterError().option("--version <selector>", "Version selector: active, pending, or all").action(async (options, command) => {
142538
+ ).showHelpAfterError().option(
142539
+ "--version <selector>",
142540
+ "Version selector: active, pending, all, or a numeric version number",
142541
+ parseVersionSelector
142542
+ ).action(async (options, command) => {
142480
142543
  try {
142481
142544
  await runProcessorStatus(options);
142482
142545
  } catch (error) {
@@ -142556,22 +142619,19 @@ async function runProcessorStatus(options) {
142556
142619
  const context = createApiContext(options);
142557
142620
  const project = await resolveProjectRef(options, context, { ownerSlug: true });
142558
142621
  const requestedVersion = normalizeVersionSelector(options.version);
142622
+ const apiVersion = typeof requestedVersion === "number" ? "ALL" : requestedVersion ?? "ALL";
142559
142623
  const response = await import_api5.ProcessorService.getProcessorStatusV2({
142560
142624
  path: {
142561
142625
  owner: project.owner,
142562
142626
  slug: project.slug
142563
142627
  },
142564
142628
  query: {
142565
- version: requestedVersion ?? "ALL"
142629
+ version: apiVersion
142566
142630
  },
142567
142631
  headers: context.headers
142568
142632
  });
142569
142633
  const data4 = unwrapApiResult(response);
142570
- if (!options.json) {
142571
- printOutput3(options, shapeProcessorStatusOutput(data4, requestedVersion));
142572
- return;
142573
- }
142574
- printOutput3(options, data4);
142634
+ printOutput3(options, shapeProcessorStatusOutput(data4, requestedVersion));
142575
142635
  }
142576
142636
  async function runProcessorSource(options) {
142577
142637
  const context = createApiContext(options);
@@ -142810,7 +142870,7 @@ function withOutputOptions3(command) {
142810
142870
  return command.option("--json", "Print raw JSON response").option("--yaml", "Print raw YAML response");
142811
142871
  }
142812
142872
  function handleProcessorCommandError(error, command) {
142813
- if (error instanceof CliError && (error.message.startsWith("Project is required.") || error.message.startsWith("Invalid project ") || error.message.startsWith("Invalid version selector ") || error.message.startsWith("Source file not found:"))) {
142873
+ if (error instanceof CliError && (error.message.startsWith("Project is required.") || error.message.startsWith("Invalid project ") || error.message.startsWith("Invalid version selector") || error.message.startsWith("Source file not found:"))) {
142814
142874
  console.error(error.message);
142815
142875
  if (command) {
142816
142876
  console.error();
@@ -142904,14 +142964,24 @@ function formatOutput2(data4) {
142904
142964
  return JSON.stringify(data4, null, 2);
142905
142965
  }
142906
142966
  function normalizeVersionSelector(value) {
142907
- if (!value) {
142967
+ if (value === void 0) {
142908
142968
  return void 0;
142909
142969
  }
142970
+ if (typeof value === "number") {
142971
+ return value;
142972
+ }
142910
142973
  const normalized = value.toUpperCase();
142911
142974
  if (normalized === "ACTIVE" || normalized === "PENDING" || normalized === "ALL") {
142912
142975
  return normalized;
142913
142976
  }
142914
- throw new CliError(`Invalid version selector "${value}". Use active, pending, or all.`);
142977
+ throw new CliError(`Invalid version selector "${value}". Use active, pending, all, or a version number.`);
142978
+ }
142979
+ function parseVersionSelector(value) {
142980
+ const num = Number.parseInt(value, 10);
142981
+ if (!Number.isNaN(num) && String(num) === value) {
142982
+ return num;
142983
+ }
142984
+ return value;
142915
142985
  }
142916
142986
  function parseInteger2(value) {
142917
142987
  const parsedValue = Number.parseInt(value, 10);
@@ -142937,6 +143007,12 @@ function shapeProcessorStatusOutput(data4, versionSelector) {
142937
143007
  processors: processors.filter((processor) => asString3(processor.versionState) === versionSelector)
142938
143008
  };
142939
143009
  }
143010
+ if (typeof versionSelector === "number") {
143011
+ return {
143012
+ ...data4,
143013
+ processors: processors.filter((processor) => asNumber(processor.version) === versionSelector)
143014
+ };
143015
+ }
142940
143016
  return {
142941
143017
  ...data4,
142942
143018
  processors: processors.filter((processor) => {
@@ -145201,7 +145277,7 @@ function withOutputOptions8(command) {
145201
145277
  return command.option("--json", "Print raw JSON response").option("--yaml", "Print raw YAML response");
145202
145278
  }
145203
145279
  function handleDashboardCommandError(error, command) {
145204
- if (error instanceof CliError && (error.message.startsWith("Project is required.") || error.message.startsWith("Invalid project ") || error.message.startsWith("Dashboard ") || error.message.startsWith("Provide --file or --stdin") || error.message.startsWith("Use either --file or --stdin") || error.message.startsWith("Expected JSON or YAML") || error.message.startsWith("Invalid JSON or YAML") || error.message.startsWith("Dashboard initialization data") || error.message.startsWith("Provide exactly one data source") || error.message.startsWith("Use exactly one of --sql") || error.message.startsWith("Invalid chart type") || error.message.startsWith("Invalid aggregation") || error.message.startsWith("Invalid metric aggregation") || error.message.startsWith("Invalid filter") || error.message.startsWith("Invalid metric selector") || error.message.startsWith("Invalid time range value"))) {
145280
+ if (error instanceof CliError && (error.message.startsWith("Project is required.") || error.message.startsWith("Invalid project ") || error.message.startsWith("Dashboard ") || error.message.startsWith("Provide --file or --stdin") || error.message.startsWith("Use either --file or --stdin") || error.message.startsWith("Expected JSON or YAML") || error.message.startsWith("Invalid JSON or YAML") || error.message.startsWith("Dashboard initialization data") || error.message.startsWith("Provide exactly one data source") || error.message.startsWith("Use exactly one of --sql") || error.message.startsWith("Invalid chart type") || error.message.startsWith("Invalid aggregation") || error.message.startsWith("Invalid metric aggregation") || error.message.startsWith("Invalid filter") || error.message.startsWith("Invalid metric selector") || error.message.startsWith("Invalid time range value") || error.message.startsWith('Unknown function "'))) {
145205
145281
  console.error(error.message);
145206
145282
  if (command) {
145207
145283
  console.error();
@@ -145299,6 +145375,10 @@ await printVersions();
145299
145375
  if (process.argv.includes("--debug")) {
145300
145376
  enableApiDebug();
145301
145377
  }
145378
+ if (process.argv.length === 3 && process.argv[2] === "--version") {
145379
+ version();
145380
+ process.exit(0);
145381
+ }
145302
145382
  program2.addCommand(createLoginCommand());
145303
145383
  program2.addCommand(createCreateCommand());
145304
145384
  program2.addCommand(createVersionCommand());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/cli",
3
- "version": "3.6.0-rc.3",
3
+ "version": "3.6.0-rc.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -559,7 +559,8 @@ function handleDashboardCommandError(error: unknown, command?: Command) {
559
559
  error.message.startsWith('Invalid metric aggregation') ||
560
560
  error.message.startsWith('Invalid filter') ||
561
561
  error.message.startsWith('Invalid metric selector') ||
562
- error.message.startsWith('Invalid time range value'))
562
+ error.message.startsWith('Invalid time range value') ||
563
+ error.message.startsWith('Unknown function "'))
563
564
  ) {
564
565
  console.error(error.message)
565
566
  if (command) {
@@ -16,6 +16,62 @@ import {
16
16
  } from '../api.js'
17
17
 
18
18
  const DEFAULT_RANGE_STEP = 3600
19
+
20
+ // Valid function names sourced from sentio/app/lib/functions.ts
21
+ const VALID_METRIC_FUNCTIONS: ReadonlySet<string> = new Set([
22
+ // Math
23
+ 'abs',
24
+ 'ceil',
25
+ 'floor',
26
+ 'round',
27
+ 'log2',
28
+ 'log10',
29
+ 'ln',
30
+ // Rollup
31
+ 'rollup_avg',
32
+ 'rollup_count',
33
+ 'rollup_last',
34
+ 'rollup_max',
35
+ 'rollup_min',
36
+ 'rollup_sum',
37
+ 'rollup_delta',
38
+ // Aggregate Over Time
39
+ 'avg_over_time',
40
+ 'count_over_time',
41
+ 'last_over_time',
42
+ 'max_over_time',
43
+ 'min_over_time',
44
+ 'sum_over_time',
45
+ 'delta_over_time',
46
+ // Rate
47
+ 'rate',
48
+ 'irate',
49
+ 'delta',
50
+ 'moving_delta',
51
+ // Rank
52
+ 'topk',
53
+ 'bottomk',
54
+ // Time
55
+ 'timestamp',
56
+ 'day_of_year',
57
+ 'day_of_month',
58
+ 'day_of_week',
59
+ 'year',
60
+ 'month',
61
+ 'hour',
62
+ 'minute',
63
+ // TimeShift
64
+ 'before',
65
+ 'after'
66
+ ])
67
+
68
+ const VALID_EVENT_FUNCTIONS: ReadonlySet<string> = new Set([
69
+ // Rank
70
+ 'topk',
71
+ 'bottomk',
72
+ // Delta
73
+ 'delta'
74
+ ])
19
75
  interface CommonDataOptions {
20
76
  host?: string
21
77
  apiKey?: string
@@ -113,7 +169,7 @@ export function buildEventsInsightQueryBody(
113
169
  aggregation: buildEventAggregation(options.aggr),
114
170
  selectorExpr: buildSelectorExpr(options.filter),
115
171
  groupBy: normalizeListOption(options.groupBy),
116
- functions: buildFunctions(options.func),
172
+ functions: buildFunctions(options.func, VALID_EVENT_FUNCTIONS),
117
173
  disabled: false
118
174
  }
119
175
  }
@@ -148,7 +204,7 @@ export function buildMetricsInsightQueryBody(
148
204
  query,
149
205
  labelSelector: buildMetricLabelSelector(options.filter),
150
206
  aggregate: buildMetricAggregate(options.aggr, options.groupBy),
151
- functions: buildFunctions(options.func),
207
+ functions: buildFunctions(options.func, VALID_METRIC_FUNCTIONS),
152
208
  disabled: false
153
209
  }
154
210
  }
@@ -584,7 +640,8 @@ function shouldShowHelpForDataCommandError(error: CliError) {
584
640
  error.message.startsWith('Provide --query, --result, --file, or --stdin.') ||
585
641
  error.message.startsWith('Use only one of --query or --result.') ||
586
642
  error.message.startsWith('--async only works with --query.') ||
587
- error.message.startsWith('Execution id is required.')
643
+ error.message.startsWith('Execution id is required.') ||
644
+ error.message.startsWith('Unknown function "')
588
645
  )
589
646
  }
590
647
 
@@ -730,8 +787,14 @@ function parseAnyValue(rawValue: string) {
730
787
  return { stringValue: unquotedValue }
731
788
  }
732
789
 
733
- function buildFunctions(functions?: string[]) {
734
- return normalizeListOption(functions).map(parseFunctionCall)
790
+ function buildFunctions(functions?: string[], validNames?: ReadonlySet<string>) {
791
+ return normalizeListOption(functions).map((f) => {
792
+ const parsed = parseFunctionCall(f)
793
+ if (validNames && !validNames.has(parsed.name)) {
794
+ throw new CliError(`Unknown function "${parsed.name}". Valid functions: ${[...validNames].sort().join(', ')}.`)
795
+ }
796
+ return parsed
797
+ })
735
798
  }
736
799
 
737
800
  function parseFunctionCall(value: string) {
@@ -27,7 +27,7 @@ interface ProcessorOptions {
27
27
  }
28
28
 
29
29
  interface ProcessorStatusOptions extends ProcessorOptions {
30
- version?: string
30
+ version?: string | number
31
31
  }
32
32
 
33
33
  interface ProcessorSourceOptions extends ProcessorOptions {
@@ -60,7 +60,11 @@ function createProcessorStatusCommand() {
60
60
  withSharedProjectOptions(withAuthOptions(new Command('status').description('Get processor status')))
61
61
  )
62
62
  .showHelpAfterError()
63
- .option('--version <selector>', 'Version selector: active, pending, or all')
63
+ .option(
64
+ '--version <selector>',
65
+ 'Version selector: active, pending, all, or a numeric version number',
66
+ parseVersionSelector
67
+ )
64
68
  .action(async (options, command) => {
65
69
  try {
66
70
  await runProcessorStatus(options)
@@ -176,22 +180,19 @@ async function runProcessorStatus(options: ProcessorStatusOptions) {
176
180
  const context = createApiContext(options)
177
181
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
178
182
  const requestedVersion = normalizeVersionSelector(options.version)
183
+ const apiVersion = typeof requestedVersion === 'number' ? 'ALL' : (requestedVersion ?? 'ALL')
179
184
  const response = await ProcessorService.getProcessorStatusV2({
180
185
  path: {
181
186
  owner: project.owner,
182
187
  slug: project.slug
183
188
  },
184
189
  query: {
185
- version: requestedVersion ?? 'ALL'
190
+ version: apiVersion
186
191
  },
187
192
  headers: context.headers
188
193
  })
189
194
  const data = unwrapApiResult(response)
190
- if (!options.json) {
191
- printOutput(options, shapeProcessorStatusOutput(data, requestedVersion))
192
- return
193
- }
194
- printOutput(options, data)
195
+ printOutput(options, shapeProcessorStatusOutput(data, requestedVersion))
195
196
  }
196
197
 
197
198
  async function runProcessorSource(options: ProcessorSourceOptions) {
@@ -501,7 +502,7 @@ function handleProcessorCommandError(error: unknown, command?: Command) {
501
502
  error instanceof CliError &&
502
503
  (error.message.startsWith('Project is required.') ||
503
504
  error.message.startsWith('Invalid project ') ||
504
- error.message.startsWith('Invalid version selector ') ||
505
+ error.message.startsWith('Invalid version selector') ||
505
506
  error.message.startsWith('Source file not found:'))
506
507
  ) {
507
508
  console.error(error.message)
@@ -610,15 +611,26 @@ function formatOutput(data: unknown) {
610
611
  return JSON.stringify(data, null, 2)
611
612
  }
612
613
 
613
- function normalizeVersionSelector(value?: string): 'ACTIVE' | 'PENDING' | 'ALL' | undefined {
614
- if (!value) {
614
+ function normalizeVersionSelector(value?: string | number): 'ACTIVE' | 'PENDING' | 'ALL' | number | undefined {
615
+ if (value === undefined) {
615
616
  return undefined
616
617
  }
618
+ if (typeof value === 'number') {
619
+ return value
620
+ }
617
621
  const normalized = value.toUpperCase()
618
622
  if (normalized === 'ACTIVE' || normalized === 'PENDING' || normalized === 'ALL') {
619
623
  return normalized
620
624
  }
621
- throw new CliError(`Invalid version selector "${value}". Use active, pending, or all.`)
625
+ throw new CliError(`Invalid version selector "${value}". Use active, pending, all, or a version number.`)
626
+ }
627
+
628
+ function parseVersionSelector(value: string): string | number {
629
+ const num = Number.parseInt(value, 10)
630
+ if (!Number.isNaN(num) && String(num) === value) {
631
+ return num
632
+ }
633
+ return value
622
634
  }
623
635
 
624
636
  function parseInteger(value: string) {
@@ -639,7 +651,7 @@ function asNumber(value: unknown) {
639
651
 
640
652
  function shapeProcessorStatusOutput(
641
653
  data: { processors?: Array<Record<string, unknown>> },
642
- versionSelector?: 'ACTIVE' | 'PENDING' | 'ALL'
654
+ versionSelector?: 'ACTIVE' | 'PENDING' | 'ALL' | number
643
655
  ) {
644
656
  const processors = Array.isArray(data.processors) ? data.processors : []
645
657
  if (versionSelector === 'ALL') {
@@ -651,6 +663,12 @@ function shapeProcessorStatusOutput(
651
663
  processors: processors.filter((processor) => asString(processor.versionState) === versionSelector)
652
664
  }
653
665
  }
666
+ if (typeof versionSelector === 'number') {
667
+ return {
668
+ ...data,
669
+ processors: processors.filter((processor) => asNumber(processor.version) === versionSelector)
670
+ }
671
+ }
654
672
  return {
655
673
  ...data,
656
674
  processors: processors.filter((processor) => {
@@ -7,7 +7,7 @@ export function createVersionCommand() {
7
7
  })
8
8
  }
9
9
 
10
- function version() {
10
+ export function version() {
11
11
  console.log('CLI Version: ', getCliVersion())
12
12
  const sdkVersion = getSdkVersion()
13
13
  if (sdkVersion) {
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import { Command } from '@commander-js/extra-typings'
4
4
  import { createLoginCommand } from './commands/login.js'
5
5
  import { createCreateCommand } from './commands/create.js'
6
- import { createVersionCommand } from './commands/version.js'
6
+ import { createVersionCommand, version } from './commands/version.js'
7
7
  import { createTestCommand } from './commands/test.js'
8
8
  import { createAddCommand } from './commands/add.js'
9
9
  import { createCompileCommand } from './commands/compile.js'
@@ -34,6 +34,11 @@ if (process.argv.includes('--debug')) {
34
34
  enableApiDebug()
35
35
  }
36
36
 
37
+ if (process.argv.length === 3 && process.argv[2] === '--version') {
38
+ version()
39
+ process.exit(0)
40
+ }
41
+
37
42
  program.addCommand(createLoginCommand())
38
43
  program.addCommand(createCreateCommand())
39
44
  program.addCommand(createVersionCommand())